31 changed files with 1808 additions and 373 deletions
@ -0,0 +1,22 @@ |
|||||
|
#ifndef BIP_H |
||||
|
#define BIP_H |
||||
|
|
||||
|
#include "utils/OpenCLHelper.h" |
||||
|
|
||||
|
#define SCRATCH_PAD_SIZE 2000 |
||||
|
|
||||
|
class BIP |
||||
|
{ |
||||
|
public: |
||||
|
BIP(); |
||||
|
static BIP* getInstance(); |
||||
|
|
||||
|
cl::CommandQueue CLQueue; |
||||
|
|
||||
|
void init(cl::Context &context, OpenCLHelper &openCLHelper); |
||||
|
|
||||
|
private: |
||||
|
static BIP* _instance; |
||||
|
}; |
||||
|
|
||||
|
#endif // BIP_H
|
@ -0,0 +1,32 @@ |
|||||
|
#ifndef DYNCONT_H |
||||
|
#define DYNCONT_H |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QMetaType> |
||||
|
#include "model/processor/IProcessStrategy.h" |
||||
|
#include "utils/OpenCLHelper.h" |
||||
|
|
||||
|
typedef struct DynCont_t |
||||
|
{ |
||||
|
cl_int state; |
||||
|
cl_int gain; |
||||
|
cl_int dynContSelector; |
||||
|
cl_int compressionType; |
||||
|
}DynCont_t; |
||||
|
|
||||
|
|
||||
|
class DynCont : public IProcessStrategy |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
Q_INVOKABLE DynCont(const Context context, const QString kernelPath, const QObject *parent); |
||||
|
virtual void cpuProcess(ScenGenOutput_t parameters) override; |
||||
|
virtual void finalize() override; |
||||
|
|
||||
|
private: |
||||
|
KernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t> _kernelFunctor; |
||||
|
virtual Image* processKernel(Image *frames, Buffer* scratchPad) override; |
||||
|
DynCont_t _kernelParameters; |
||||
|
}; |
||||
|
|
||||
|
#endif // DYNCONT_H
|
@ -0,0 +1,29 @@ |
|||||
|
#ifndef GRAYMAP_H |
||||
|
#define GRAYMAP_H |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QMetaType> |
||||
|
#include "model/processor/IProcessStrategy.h" |
||||
|
#include "utils/OpenCLHelper.h" |
||||
|
|
||||
|
typedef struct GrayMap_t |
||||
|
{ |
||||
|
cl_int grayMapSelector; |
||||
|
}GrayMap_t; |
||||
|
|
||||
|
|
||||
|
class GrayMap : public IProcessStrategy |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
Q_INVOKABLE GrayMap(const Context context, const QString kernelPath, const QObject *parent); |
||||
|
virtual void cpuProcess(ScenGenOutput_t parameters) override; |
||||
|
virtual void finalize() override; |
||||
|
|
||||
|
private: |
||||
|
KernelFunctor<Image2D, Image2D, GrayMap_t> _kernelFunctor; |
||||
|
virtual Image* processKernel(Image *frames, Buffer* scratchPad) override; |
||||
|
GrayMap_t _kernelParameters; |
||||
|
}; |
||||
|
|
||||
|
#endif // GRAYMAP_H
|
@ -0,0 +1,32 @@ |
|||||
|
#ifndef SRI_H |
||||
|
#define SRI_H |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QMetaType> |
||||
|
#include "model/processor/IProcessStrategy.h" |
||||
|
#include "utils/OpenCLHelper.h" |
||||
|
|
||||
|
typedef struct Sri_t |
||||
|
{ |
||||
|
cl_int state; |
||||
|
cl_int sri; |
||||
|
cl_int width; |
||||
|
cl_int height; |
||||
|
}Sri_t; |
||||
|
|
||||
|
|
||||
|
class Sri : public IProcessStrategy |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
Q_INVOKABLE Sri(const Context context, const QString kernelPath, const QObject *parent); |
||||
|
virtual void cpuProcess(ScenGenOutput_t parameters) override; |
||||
|
virtual void finalize() override; |
||||
|
|
||||
|
private: |
||||
|
KernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t> _kernelFunctor; |
||||
|
virtual Image* processKernel(Image *frames, Buffer* scratchPad) override; |
||||
|
Sri_t _kernelParameters; |
||||
|
}; |
||||
|
|
||||
|
#endif // SRI_H
|
@ -0,0 +1,28 @@ |
|||||
|
#ifndef TINTMAP_H |
||||
|
#define TINTMAP_H |
||||
|
|
||||
|
#include <QObject> |
||||
|
#include <QMetaType> |
||||
|
#include "model/processor/IProcessStrategy.h" |
||||
|
#include "utils/OpenCLHelper.h" |
||||
|
|
||||
|
typedef struct TintMap_t |
||||
|
{ |
||||
|
cl_int tintMapSelector; |
||||
|
}TintMap_t; |
||||
|
|
||||
|
|
||||
|
class TintMap : public IProcessStrategy |
||||
|
{ |
||||
|
Q_OBJECT |
||||
|
public: |
||||
|
Q_INVOKABLE TintMap(const Context context, const QString kernelPath, const QObject *parent); |
||||
|
virtual void cpuProcess(ScenGenOutput_t parameters) override; |
||||
|
virtual void finalize() override; |
||||
|
|
||||
|
private: |
||||
|
KernelFunctor<Image2D, Image2D, TintMap_t> _kernelFunctor; |
||||
|
virtual Image* processKernel(Image *frames, Buffer* scratchPad) override; |
||||
|
TintMap_t _kernelParameters; |
||||
|
}; |
||||
|
#endif // TINTMAP_H
|
@ -0,0 +1,170 @@ |
|||||
|
// #define TEST |
||||
|
#define X 100 |
||||
|
#define Y 100 |
||||
|
|
||||
|
//#define USE_DBL |
||||
|
#ifdef USE_DBL |
||||
|
#define TYPE_FLT double |
||||
|
#define TYPE_INT long |
||||
|
#define MASK 0xFFFF |
||||
|
#define SHIFT 16 |
||||
|
#define EPSILSON 4.94065645841247E-324 |
||||
|
#else |
||||
|
#define TYPE_FLT float |
||||
|
#define TYPE_INT int |
||||
|
#define MASK 0x00FF |
||||
|
#define SHIFT 8 |
||||
|
#define EPSILSON 1.401298E-45 |
||||
|
#endif |
||||
|
|
||||
|
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | |
||||
|
CLK_ADDRESS_CLAMP_TO_EDGE | |
||||
|
CLK_FILTER_LINEAR; |
||||
|
|
||||
|
|
||||
|
struct input { |
||||
|
int state; |
||||
|
int gain; |
||||
|
int dyn_cont_selector; |
||||
|
int compression_type; |
||||
|
}; |
||||
|
|
||||
|
TYPE_FLT read_data(image2d_t input_frame, int x, int z) |
||||
|
{ |
||||
|
int2 gid = (int2)(x, z); |
||||
|
uint4 pixel = read_imageui(input_frame, sampler, gid); |
||||
|
TYPE_INT temp = (TYPE_INT)((TYPE_INT)pixel.x & MASK) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.y & MASK) << SHIFT) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.z & MASK) << (SHIFT * 2)) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.w & MASK) << (SHIFT * 3)); |
||||
|
TYPE_FLT raw_data = *((TYPE_FLT*)(&temp)); |
||||
|
return raw_data; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
kernel void DynCont(read_only image2d_t input_frame, read_write image2d_t output_frame, local TYPE_FLT* max, global TYPE_FLT* scratch_pad, struct input params) |
||||
|
{ |
||||
|
int2 gid = (int2)(get_global_id(0), get_global_id(1)); |
||||
|
TYPE_FLT input = read_data(input_frame, gid.x, gid.y); |
||||
|
|
||||
|
if(params.state == 1) |
||||
|
{ |
||||
|
uint local_id = get_local_id(0); |
||||
|
uint group_size = get_local_size(0); |
||||
|
max[local_id] = input; |
||||
|
|
||||
|
uint is_odd = group_size % 2; |
||||
|
// Loop for computing localMaxes : divide WorkGroup into 2 parts |
||||
|
for (uint stride = group_size / 2; stride > 0; stride /= 2) |
||||
|
{ |
||||
|
// Waiting |
||||
|
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
|
||||
|
if (local_id < stride) |
||||
|
max[local_id] = max[local_id] > max[local_id + stride] ? max[local_id] : max[local_id + stride]; |
||||
|
|
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
if(is_odd) |
||||
|
max[local_id] = max[local_id] > max[2 * stride] ? max[local_id] : max[2 * stride]; |
||||
|
is_odd = stride % 2; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Write result into scratchPad[nWorkGroups] |
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
scratch_pad[get_group_id(1)] = max[0]; |
||||
|
} |
||||
|
} |
||||
|
else if(params.state == 2) |
||||
|
{ |
||||
|
uint local_id = get_local_id(0); |
||||
|
uint group_size = get_local_size(0); |
||||
|
max[local_id] = scratch_pad[gid.x]; |
||||
|
|
||||
|
uint is_odd = group_size % 2; |
||||
|
// Loop for computing localMaxes : divide WorkGroup into 2 parts |
||||
|
for (uint stride = group_size / 2; stride > 0; stride /= 2) |
||||
|
{ |
||||
|
// Waiting |
||||
|
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
|
||||
|
if (local_id < stride) |
||||
|
max[local_id] = max[local_id] > max[local_id + stride] ? max[local_id] : max[local_id + stride]; |
||||
|
|
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
if(is_odd) |
||||
|
max[local_id] = max[local_id] > max[2 * stride] ? max[local_id] : max[2 * stride]; |
||||
|
is_odd = stride % 2; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Write result into scratchPad[nWorkGroups] |
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
scratch_pad[0] = max[0]; |
||||
|
} |
||||
|
} |
||||
|
else if(params.state == 3) |
||||
|
{ |
||||
|
int dynamic_range = 60 + params.dyn_cont_selector; |
||||
|
TYPE_FLT max = scratch_pad[0]; |
||||
|
TYPE_FLT output_data = 0; |
||||
|
//log compress |
||||
|
if(params.compression_type == 1) |
||||
|
{ |
||||
|
output_data = 20 * log10(input / max); |
||||
|
|
||||
|
if(output_data < -dynamic_range) |
||||
|
output_data = -dynamic_range; |
||||
|
|
||||
|
output_data += params.gain; |
||||
|
|
||||
|
if(output_data > 0) |
||||
|
output_data = 0; |
||||
|
|
||||
|
if(output_data < -dynamic_range) |
||||
|
output_data = -dynamic_range; |
||||
|
|
||||
|
output_data = 255 * (output_data + dynamic_range) / dynamic_range; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
output_data = input / max; |
||||
|
|
||||
|
if(output_data < pow(10, (-dynamic_range / 20.0))) |
||||
|
{ |
||||
|
output_data = 0; |
||||
|
} |
||||
|
|
||||
|
output_data *= pow(10, (params.gain / 20.0)); |
||||
|
|
||||
|
if(output_data < 0) |
||||
|
{ |
||||
|
output_data = 0; |
||||
|
} |
||||
|
|
||||
|
if(output_data > 1) |
||||
|
output_data = 1; |
||||
|
|
||||
|
output_data *= 255; |
||||
|
|
||||
|
#ifdef TEST |
||||
|
if(gid.x == X && gid.y == Y) |
||||
|
printf("%.6f %.6f %.6f ----", output_data, input, max); |
||||
|
#endif |
||||
|
} |
||||
|
|
||||
|
TYPE_INT out = *((TYPE_INT*)(&output_data)); |
||||
|
uint4 pixel; |
||||
|
pixel.x = (TYPE_INT)(out & MASK); |
||||
|
pixel.y = (TYPE_INT)((out >> SHIFT) & MASK); |
||||
|
pixel.z = (TYPE_INT)((out >> (SHIFT *2)) & MASK); |
||||
|
pixel.w = (TYPE_INT)((out >> (SHIFT * 3)) & MASK); |
||||
|
|
||||
|
write_imageui(output_frame, gid, pixel); |
||||
|
} |
||||
|
} |
||||
|
|
@ -0,0 +1,74 @@ |
|||||
|
// #define TEST |
||||
|
#define X 100 |
||||
|
#define Y 100 |
||||
|
|
||||
|
//#define USE_DBL |
||||
|
#ifdef USE_DBL |
||||
|
#define TYPE_FLT double |
||||
|
#define TYPE_INT long |
||||
|
#define MASK 0xFFFF |
||||
|
#define SHIFT 16 |
||||
|
#define EPSILSON 4.94065645841247E-324 |
||||
|
#else |
||||
|
#define TYPE_FLT float |
||||
|
#define TYPE_INT int |
||||
|
#define MASK 0x00FF |
||||
|
#define SHIFT 8 |
||||
|
#define EPSILSON 1.401298E-45 |
||||
|
#endif |
||||
|
|
||||
|
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | |
||||
|
CLK_ADDRESS_CLAMP_TO_EDGE | |
||||
|
CLK_FILTER_LINEAR; |
||||
|
|
||||
|
|
||||
|
struct input { |
||||
|
int gray_map_selector; |
||||
|
}; |
||||
|
|
||||
|
TYPE_FLT read_data(image2d_t input_frame, int x, int z) |
||||
|
{ |
||||
|
int2 gid = (int2)(x, z); |
||||
|
uint4 pixel = read_imageui(input_frame, sampler, gid); |
||||
|
TYPE_INT temp = (TYPE_INT)((TYPE_INT)pixel.x & MASK) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.y & MASK) << SHIFT) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.z & MASK) << (SHIFT * 2)) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.w & MASK) << (SHIFT * 3)); |
||||
|
TYPE_FLT raw_data = *((TYPE_FLT*)(&temp)); |
||||
|
return raw_data; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
kernel void GrayMap(read_only image2d_t input_frame, read_write image2d_t output_frame, struct input params) |
||||
|
{ |
||||
|
int2 gid = (int2)(get_global_id(0), get_global_id(1)); |
||||
|
TYPE_FLT input = read_data(input_frame, gid.x, gid.y); |
||||
|
TYPE_FLT output_data = 0; |
||||
|
|
||||
|
double gama[17] = {0.05, 0.1, 0.2, 0.3, 0.4, 0.5, 0.67, 0.75, 1, 1.33, 1.5, 2, 2.5, 3.33, 5, 10, 20}; |
||||
|
|
||||
|
if(params.gray_map_selector == 17) |
||||
|
{ |
||||
|
output_data = 255 * log2(input / 255 + 1); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
output_data = 255 * pow((input / 255.0), gama[params.gray_map_selector]); |
||||
|
} |
||||
|
|
||||
|
uchar out = (uchar)output_data; |
||||
|
|
||||
|
#ifdef TEST |
||||
|
if(gid.x == X && gid.y == Y) |
||||
|
printf("%u ---", out); |
||||
|
#endif |
||||
|
|
||||
|
uint4 pixel; |
||||
|
pixel.x = out; |
||||
|
pixel.y = out; |
||||
|
pixel.z = out; |
||||
|
pixel.w = 255; |
||||
|
|
||||
|
write_imageui(output_frame, gid, pixel); |
||||
|
} |
||||
|
|
@ -0,0 +1,92 @@ |
|||||
|
#define TEST |
||||
|
#define X 0 |
||||
|
#define Y 26 |
||||
|
|
||||
|
#define USE_DBL |
||||
|
#ifdef USE_DBL |
||||
|
#define TYPE_FLT double |
||||
|
#define TYPE_INT long |
||||
|
#define MASK 0xFFFF |
||||
|
#define SHIFT 16 |
||||
|
#define EPSILSON 4.94065645841247E-324 |
||||
|
#else |
||||
|
#define TYPE_FLT float |
||||
|
#define TYPE_INT int |
||||
|
#define MASK 0x00FF |
||||
|
#define SHIFT 8 |
||||
|
#define EPSILSON 1.401298E-45 |
||||
|
#endif |
||||
|
|
||||
|
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | |
||||
|
CLK_ADDRESS_CLAMP_TO_EDGE | |
||||
|
CLK_FILTER_LINEAR; |
||||
|
|
||||
|
TYPE_FLT read_data(image2d_t input_frame, int x, int z) |
||||
|
{ |
||||
|
int2 gid = (int2)(x, z); |
||||
|
uint4 pixel = read_imageui(input_frame, sampler, gid); |
||||
|
TYPE_INT temp = (TYPE_INT)((TYPE_INT)pixel.x & MASK) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.y & MASK) << SHIFT) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.z & MASK) << (SHIFT * 2)) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.w & MASK) << (SHIFT * 3)); |
||||
|
TYPE_FLT raw_data = *((TYPE_FLT*)(&temp)); |
||||
|
return raw_data; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
kernel void Max(read_only image2d_t input_frame, read_write image2d_t output_frame, local double* max, global double* scratch_pad) { |
||||
|
int2 gid = (int2)(get_global_id(0), get_global_id(1)); |
||||
|
|
||||
|
TYPE_FLT output_data = 0; |
||||
|
TYPE_FLT input = read_data(input_frame, gid.x, gid.y); |
||||
|
output_data = input; |
||||
|
|
||||
|
uint local_id = get_local_id(0); |
||||
|
uint group_size = get_local_size(0); |
||||
|
max[local_id] = input; |
||||
|
|
||||
|
if(gid.x == 0 && gid.y == 0) |
||||
|
{ |
||||
|
printf("gid [%d] ", get_group_id(0)); |
||||
|
printf("lid0 [%d] ", get_local_id(0)); |
||||
|
printf("lid1 [%d] ", get_local_id(1)); |
||||
|
printf("lis0 [%d] ", get_local_size(0)); |
||||
|
printf("lis1 [%d] ", get_local_size(1)); |
||||
|
} |
||||
|
uint is_odd = 0; |
||||
|
// Loop for computing localMaxes : divide WorkGroup into 2 parts |
||||
|
for (uint stride = group_size / 2; stride > 0; stride /= 2) |
||||
|
{ |
||||
|
// Waiting for each 2x2 max into given workgroup |
||||
|
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
|
||||
|
// max elements 2 by 2 between local_id and local_id + stride |
||||
|
if (local_id < stride) |
||||
|
max[local_id] = max[local_id] > max[local_id + stride] ? max[local_id] : max[local_id + stride]; |
||||
|
|
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
if(is_odd) |
||||
|
max[local_id] = max[local_id] > max[2 * stride] ? max[local_id] : max[2 * stride]; |
||||
|
is_odd = stride % 2; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Write result into scratchPad[nWorkGroups] |
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
scratch_pad[get_group_id(1)] = max[0]; |
||||
|
printf("out[%d]: %.15f | ", get_group_id(1), scratch_pad[get_group_id(1)]); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
TYPE_INT out = *((TYPE_INT*)(&output_data)); |
||||
|
uint4 pixel; |
||||
|
pixel.x = (TYPE_INT)(out & MASK); |
||||
|
pixel.y = (TYPE_INT)((out >> SHIFT) & MASK); |
||||
|
pixel.z = (TYPE_INT)((out >> (SHIFT *2)) & MASK); |
||||
|
pixel.w = (TYPE_INT)((out >> (SHIFT * 3)) & MASK); |
||||
|
|
||||
|
write_imageui(output_frame, gid, pixel); |
||||
|
} |
||||
|
|
@ -0,0 +1,199 @@ |
|||||
|
// #define TEST |
||||
|
#define X 95 |
||||
|
#define Y 22 |
||||
|
|
||||
|
//#define USE_DBL |
||||
|
#ifdef USE_DBL |
||||
|
#define TYPE_FLT double |
||||
|
#define TYPE_INT long |
||||
|
#define MASK 0xFFFF |
||||
|
#define SHIFT 16 |
||||
|
#define EPSILSON 4.94065645841247E-324 |
||||
|
#else |
||||
|
#define TYPE_FLT float |
||||
|
#define TYPE_INT int |
||||
|
#define MASK 0x00FF |
||||
|
#define SHIFT 8 |
||||
|
#define EPSILSON 1.401298E-45 |
||||
|
#endif |
||||
|
|
||||
|
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | |
||||
|
CLK_ADDRESS_CLAMP_TO_EDGE | |
||||
|
CLK_FILTER_LINEAR; |
||||
|
|
||||
|
|
||||
|
struct input { |
||||
|
int state; |
||||
|
int sri; |
||||
|
int width; |
||||
|
int height; |
||||
|
}; |
||||
|
|
||||
|
TYPE_FLT read_data(image2d_t input_frame, int x, int z) |
||||
|
{ |
||||
|
int2 gid = (int2)(x, z); |
||||
|
uint4 pixel = read_imageui(input_frame, sampler, gid); |
||||
|
TYPE_INT temp = (TYPE_INT)((TYPE_INT)pixel.x & MASK) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.y & MASK) << SHIFT) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.z & MASK) << (SHIFT * 2)) | |
||||
|
(TYPE_INT)(((TYPE_INT)pixel.w & MASK) << (SHIFT * 3)); |
||||
|
TYPE_FLT raw_data = *((TYPE_FLT*)(&temp)); |
||||
|
return raw_data; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
kernel void Sri(read_only image2d_t input_frame, read_write image2d_t output_frame, local TYPE_FLT* sum, global TYPE_FLT* scratch_pad, struct input params) |
||||
|
{ |
||||
|
int2 gid = (int2)(get_global_id(0), get_global_id(1)); |
||||
|
TYPE_FLT input = read_data(input_frame, gid.x, gid.y); |
||||
|
TYPE_FLT output_data = 0; |
||||
|
|
||||
|
if(params.sri == 0) |
||||
|
{ |
||||
|
output_data = input; |
||||
|
} |
||||
|
else if(params.state == 1 || params.state == 4) |
||||
|
{ |
||||
|
uint local_id = get_local_id(0); |
||||
|
uint group_size = get_local_size(0); |
||||
|
sum[local_id] = input; |
||||
|
|
||||
|
uint is_odd = group_size % 2; |
||||
|
// Loop for computing localMaxes : divide WorkGroup into 2 parts |
||||
|
for (uint stride = group_size / 2; stride > 0; stride /= 2) |
||||
|
{ |
||||
|
// Waiting |
||||
|
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
|
||||
|
if (local_id < stride) |
||||
|
sum[local_id] += sum[local_id + stride]; |
||||
|
|
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
if(is_odd) |
||||
|
sum[local_id] += sum[2 * stride]; |
||||
|
is_odd = stride % 2; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Write result into scratchPad[nWorkGroups] |
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
scratch_pad[get_group_id(1)] = sum[0]; |
||||
|
} |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
else if(params.state == 2 || params.state == 5) |
||||
|
{ |
||||
|
uint local_id = get_local_id(0); |
||||
|
uint group_size = get_local_size(0); |
||||
|
sum[local_id] = scratch_pad[gid.x]; |
||||
|
|
||||
|
uint is_odd = group_size % 2; |
||||
|
// Loop for computing localMaxes : divide WorkGroup into 2 parts |
||||
|
for (uint stride = group_size / 2; stride > 0; stride /= 2) |
||||
|
{ |
||||
|
// Waiting |
||||
|
barrier(CLK_LOCAL_MEM_FENCE); |
||||
|
|
||||
|
if (local_id < stride) |
||||
|
sum[local_id] += sum[local_id + stride]; |
||||
|
|
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
if(is_odd) |
||||
|
sum[local_id] += sum[2 * stride]; |
||||
|
is_odd = stride % 2; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
// Write result into scratchPad[nWorkGroups] |
||||
|
if (local_id == 0) |
||||
|
{ |
||||
|
scratch_pad[0] = sum[0] / (params.width * params.height); |
||||
|
} |
||||
|
|
||||
|
return; |
||||
|
} |
||||
|
else if(params.state == 3) |
||||
|
{ |
||||
|
TYPE_FLT mean = scratch_pad[0]; |
||||
|
output_data = pow((input - mean), 2); |
||||
|
} |
||||
|
else if(params.state == 6) |
||||
|
{ |
||||
|
int temp[5] = {3, 3, 5, 7, 7}; |
||||
|
int p = temp[params.sri - 1]; |
||||
|
int q = params.width > 1 ? p : 1; |
||||
|
|
||||
|
float alpha = 1 - 0.25 * (params.sri - 1); |
||||
|
TYPE_FLT rho2 = scratch_pad[0]; |
||||
|
|
||||
|
int lag1 = (p - 1) / 2; |
||||
|
int lag2 = (q - 1) / 2; |
||||
|
|
||||
|
float window[49]; |
||||
|
|
||||
|
int window_size = p * q; |
||||
|
for(int i = 0; i < window_size; i++) |
||||
|
window[i] = 0; |
||||
|
if(gid.x >= lag2 && gid.x < params.width - lag2 && gid.y >= lag1 && gid.y < params.height - lag1) |
||||
|
{ |
||||
|
for(int i = -lag1; i <= lag1 ; i++) |
||||
|
{ |
||||
|
for(int j = -lag2; j <= lag2 ; j++) |
||||
|
{ |
||||
|
window[(i + lag1) * q + (j + lag2)] = read_data(input_frame, gid.x + j, gid.y + i); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
#ifdef TEST |
||||
|
if(gid.x == X && gid.y == Y) |
||||
|
{ |
||||
|
for(int i = 0; i < window_size; i++) |
||||
|
printf("[%d] > %f; ", i, window[i]); |
||||
|
} |
||||
|
#endif |
||||
|
|
||||
|
|
||||
|
float mean = 0; |
||||
|
for(int i = 0; i < window_size; i++) |
||||
|
{ |
||||
|
mean += window[i]; |
||||
|
} |
||||
|
mean /= window_size; |
||||
|
|
||||
|
for(int i = 0; i < window_size; i++) |
||||
|
{ |
||||
|
window[i] = pow((window[i] - mean), 2); |
||||
|
} |
||||
|
|
||||
|
float sigma2 = 0; |
||||
|
for(int i = 0; i < window_size; i++) |
||||
|
{ |
||||
|
sigma2 += window[i]; |
||||
|
} |
||||
|
sigma2 /= window_size; |
||||
|
|
||||
|
output_data = mean + alpha * (sigma2 / (sigma2 + rho2)) * (input - mean); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
output_data = input; |
||||
|
} |
||||
|
|
||||
|
if(output_data < 0) |
||||
|
output_data = 0; |
||||
|
} |
||||
|
|
||||
|
TYPE_INT out = *((TYPE_INT*)(&output_data)); |
||||
|
uint4 pixel; |
||||
|
pixel.x = (TYPE_INT)(out & MASK); |
||||
|
pixel.y = (TYPE_INT)((out >> SHIFT) & MASK); |
||||
|
pixel.z = (TYPE_INT)((out >> (SHIFT *2)) & MASK); |
||||
|
pixel.w = (TYPE_INT)((out >> (SHIFT * 3)) & MASK); |
||||
|
|
||||
|
write_imageui(output_frame, gid, pixel); |
||||
|
} |
||||
|
|
@ -0,0 +1,100 @@ |
|||||
|
// #define TEST |
||||
|
#define X 100 |
||||
|
#define Y 100 |
||||
|
|
||||
|
//#define USE_DBL |
||||
|
#ifdef USE_DBL |
||||
|
#define TYPE_FLT double |
||||
|
#define TYPE_INT long |
||||
|
#define MASK 0xFFFF |
||||
|
#define SHIFT 16 |
||||
|
#define EPSILSON 4.94065645841247E-324 |
||||
|
#else |
||||
|
#define TYPE_FLT float |
||||
|
#define TYPE_INT int |
||||
|
#define MASK 0x00FF |
||||
|
#define SHIFT 8 |
||||
|
#define EPSILSON 1.401298E-45 |
||||
|
#endif |
||||
|
|
||||
|
constant sampler_t sampler = CLK_NORMALIZED_COORDS_FALSE | |
||||
|
CLK_ADDRESS_CLAMP_TO_EDGE | |
||||
|
CLK_FILTER_LINEAR; |
||||
|
|
||||
|
|
||||
|
struct input { |
||||
|
int tint_map_selector; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
kernel void TintMap(read_only image2d_t input_frame, read_write image2d_t output_frame, struct input params) |
||||
|
{ |
||||
|
int2 gid = (int2)(get_global_id(0), get_global_id(1)); |
||||
|
uint4 pixel = read_imageui(input_frame, sampler, gid); |
||||
|
|
||||
|
private float r_step, g_step, b_step; |
||||
|
private int r_base, g_base, b_base; |
||||
|
|
||||
|
switch(params.tint_map_selector) |
||||
|
{ |
||||
|
//gray |
||||
|
case 0: |
||||
|
r_base = g_base = b_base = 0; |
||||
|
r_step = g_step = b_step = 1.0; |
||||
|
break; |
||||
|
//blue |
||||
|
case 1: |
||||
|
r_base = g_base = b_base = 0; |
||||
|
r_step = g_step = 0 ; |
||||
|
b_step = 1.0f; |
||||
|
break; |
||||
|
//cool blue |
||||
|
case 2: |
||||
|
r_base = 0; |
||||
|
g_base = b_base = 255; |
||||
|
r_step = 1.0f; |
||||
|
g_step = -1.0f; |
||||
|
b_step = 0; |
||||
|
break; |
||||
|
//copper |
||||
|
case 3: |
||||
|
r_base = g_base = b_base = 0; |
||||
|
r_step = 1.0f; |
||||
|
g_step = 0.7812f; |
||||
|
b_step = 0.4975f; |
||||
|
break; |
||||
|
//otherwise |
||||
|
case 4: |
||||
|
r_base = g_base = b_base = 0; |
||||
|
r_step = g_step = b_step = 1.0f; |
||||
|
break; |
||||
|
} |
||||
|
|
||||
|
uchar data = pixel.x; |
||||
|
if(data > 0) |
||||
|
{ |
||||
|
float r = r_base + data * r_step; |
||||
|
if(r < 0) r = 0; |
||||
|
if(r > 255) r = 255; |
||||
|
|
||||
|
float g = g_base + data * g_step; |
||||
|
if(g < 0) g = 0; |
||||
|
if(g > 255) g = 255; |
||||
|
|
||||
|
float b = b_base + data * b_step; |
||||
|
if(b < 0) b = 0; |
||||
|
if(b > 255) b = 255; |
||||
|
|
||||
|
#ifdef TEST |
||||
|
if(gid.x == X && gid.y == Y) |
||||
|
printf("%u ---", out); |
||||
|
#endif |
||||
|
|
||||
|
pixel.x = (uchar)b; |
||||
|
pixel.y = (uchar)g; |
||||
|
pixel.z = (uchar)r; |
||||
|
} |
||||
|
|
||||
|
write_imageui(output_frame, gid, pixel); |
||||
|
} |
||||
|
|
@ -0,0 +1,24 @@ |
|||||
|
#include "model/processor/BIP.h" |
||||
|
|
||||
|
BIP* BIP::_instance; |
||||
|
|
||||
|
BIP::BIP() |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
|
||||
|
BIP *BIP::getInstance() |
||||
|
{ |
||||
|
if(_instance == Q_NULLPTR) |
||||
|
_instance = new BIP(); |
||||
|
|
||||
|
return _instance; |
||||
|
} |
||||
|
|
||||
|
void BIP::init(cl::Context &context, OpenCLHelper &openCLHelper) |
||||
|
{ |
||||
|
CLQueue = openCLHelper.createCommandQueue(context, |
||||
|
openCLHelper |
||||
|
.getDevicesByContext( |
||||
|
context)[0]); |
||||
|
} |
@ -1,15 +1,11 @@ |
|||||
#include "header/IProcessStrategy.h" |
#include "model/processor/IProcessStrategy.h" |
||||
#include <QImage> |
#include <QImage> |
||||
#include <QPixmap> |
#include <QPixmap> |
||||
|
|
||||
void IProcessStrategy::slt_process(Image* inputFrame, Buffer* scratchPad) |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
IProcessStrategy::IProcessStrategy(const Context context, |
IProcessStrategy::IProcessStrategy(const Context context, |
||||
const QString kernelPath, |
const QString kernelPath, |
||||
const QString kernelName) |
const QString kernelName, |
||||
|
const QObject* parent) |
||||
{ |
{ |
||||
try |
try |
||||
{ |
{ |
@ -0,0 +1,88 @@ |
|||||
|
#include "model/processor/strategies/DynCont.h" |
||||
|
#include "model/processor/BIP.h" |
||||
|
#include <QPixmap> |
||||
|
#include <QImage> |
||||
|
|
||||
|
DynCont::DynCont(const Context context, |
||||
|
const QString kernelPath, |
||||
|
const QObject *parent = Q_NULLPTR) : |
||||
|
IProcessStrategy(context, kernelPath, "DynCont", parent), |
||||
|
_kernelFunctor(KernelFunctor<Image2D, Image2D, |
||||
|
LocalSpaceArg, Buffer, DynCont_t>(_kernel)) |
||||
|
{ |
||||
|
memset(&_kernelParameters, 0, sizeof (DynCont_t)); |
||||
|
} |
||||
|
|
||||
|
void DynCont::cpuProcess(ScenGenOutput_t parameters) |
||||
|
{ |
||||
|
if(parameters.dynContGain.isUpdated) |
||||
|
{ |
||||
|
_kernelParameters.gain = parameters.dynContGain.value; |
||||
|
} |
||||
|
|
||||
|
if(parameters.dynContSelector.isUpdated) |
||||
|
{ |
||||
|
_kernelParameters.dynContSelector = parameters.dynContSelector.value; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
if(parameters.compressionType.isUpdated) |
||||
|
{ |
||||
|
_kernelParameters.compressionType = parameters.compressionType.value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void DynCont::finalize() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Image* DynCont::processKernel(Image *frames, Buffer* scratchPad) |
||||
|
{ |
||||
|
auto format = frames->getImageInfo<CL_IMAGE_FORMAT>(); |
||||
|
auto width = frames->getImageInfo<CL_IMAGE_WIDTH>(); |
||||
|
auto height = frames->getImageInfo<CL_IMAGE_HEIGHT>(); |
||||
|
|
||||
|
auto imageOutput = new Image2D(_CLContext, |
||||
|
CL_MEM_READ_WRITE, |
||||
|
ImageFormat(format.image_channel_order, format.image_channel_data_type), |
||||
|
width, |
||||
|
height); |
||||
|
//width should be lass than CL_DEVICE_MAX_WORK_GROUP_SIZE(1024 for current machine) or this will break
|
||||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height), cl::NDRange(width, 1)); |
||||
|
|
||||
|
_kernelParameters.state = 1; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(width * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
|
||||
|
cl::EnqueueArgs eargs2(BIP::getInstance()->CLQueue, cl::NDRange(height, 1), cl::NDRange(height, 1)); |
||||
|
|
||||
|
_kernelParameters.state = 2; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t>(_kernelFunctor, |
||||
|
eargs2, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(height * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
|
||||
|
_kernelParameters.state = 3; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, DynCont_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(1), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
delete frames; |
||||
|
|
||||
|
return imageOutput; |
||||
|
} |
@ -0,0 +1,57 @@ |
|||||
|
#include "model/processor/strategies/GrayMap.h" |
||||
|
#include "model/processor/BIP.h" |
||||
|
#include <QPixmap> |
||||
|
#include <QImage> |
||||
|
|
||||
|
GrayMap::GrayMap(const Context context, |
||||
|
const QString kernelPath, |
||||
|
const QObject *parent = Q_NULLPTR) : |
||||
|
IProcessStrategy(context, kernelPath, "GrayMap", parent), |
||||
|
_kernelFunctor(KernelFunctor<Image2D, Image2D, |
||||
|
GrayMap_t>(_kernel)) |
||||
|
{ |
||||
|
memset(&_kernelParameters, 0, sizeof (GrayMap_t)); |
||||
|
} |
||||
|
|
||||
|
void GrayMap::cpuProcess(ScenGenOutput_t parameters) |
||||
|
{ |
||||
|
if(parameters.grayMapSelector.isUpdated) |
||||
|
{ |
||||
|
_kernelParameters.grayMapSelector = parameters.grayMapSelector.value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void GrayMap::finalize() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Image* GrayMap::processKernel(Image *frames, Buffer* scratchPad) |
||||
|
{ |
||||
|
auto width = frames->getImageInfo<CL_IMAGE_WIDTH>(); |
||||
|
auto height = frames->getImageInfo<CL_IMAGE_HEIGHT>(); |
||||
|
|
||||
|
ImageFormat format; |
||||
|
format.image_channel_order = CL_RGBA; |
||||
|
format.image_channel_data_type = CL_UNSIGNED_INT8; |
||||
|
|
||||
|
auto imageOutput = new Image2D(_CLContext, |
||||
|
CL_MEM_READ_WRITE, |
||||
|
format, |
||||
|
width, |
||||
|
height); |
||||
|
//width should be lass than CL_DEVICE_MAX_WORK_GROUP_SIZE(1024 for current machine) or this will break
|
||||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height)); |
||||
|
|
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, GrayMap_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
delete frames; |
||||
|
|
||||
|
return imageOutput; |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,424 @@ |
|||||
|
#include "model/processor/strategies/ScanConversion.h" |
||||
|
#include <QPixmap> |
||||
|
#include <QImage> |
||||
|
#include "model/processor/BIP.h" |
||||
|
|
||||
|
ScanConversion::ScanConversion(const Context context, |
||||
|
const QString kernelPath, |
||||
|
const QObject *parent = Q_NULLPTR) : |
||||
|
IProcessStrategy(context, kernelPath, "ScanConversion", parent), |
||||
|
_kernelFunctor(KernelFunctor<Image2D, Image2D, |
||||
|
Buffer, Buffer, Buffer, Buffer, ScanConversion_t>(_kernel)) |
||||
|
{ |
||||
|
_gridPixelXPos = Q_NULLPTR; |
||||
|
_gridPixelZPos = Q_NULLPTR; |
||||
|
_scanXPos = Q_NULLPTR; |
||||
|
_scanZPos = Q_NULLPTR; |
||||
|
|
||||
|
_gridX = Q_NULLPTR; |
||||
|
_gridZ = Q_NULLPTR; |
||||
|
_queryX = Q_NULLPTR; |
||||
|
_queryZ = Q_NULLPTR; |
||||
|
|
||||
|
_gridPixelR = Q_NULLPTR; |
||||
|
_gridPixelTheta = Q_NULLPTR; |
||||
|
} |
||||
|
|
||||
|
void ScanConversion::cpuProcess(ScenGenOutput_t params) |
||||
|
{ |
||||
|
auto context = _openCLHelper.getContext(); |
||||
|
auto queue = BIP::getInstance()->CLQueue; |
||||
|
//virtual convex
|
||||
|
if(params.virtualConvex.value) |
||||
|
{ |
||||
|
if(params.outputWidth.isUpdated|| params.outputHeight.isUpdated) |
||||
|
{ |
||||
|
if(_gridPixelXPos) |
||||
|
delete[] _gridPixelXPos; |
||||
|
|
||||
|
if(_gridPixelZPos) |
||||
|
delete[] _gridPixelZPos; |
||||
|
|
||||
|
_gridPixelXPos = new myflt[params.outputWidth.value * |
||||
|
params.outputHeight.value]; |
||||
|
_gridPixelZPos = new myflt[params.outputWidth.value * |
||||
|
params.outputHeight.value]; |
||||
|
|
||||
|
_width = params.outputWidth.value; |
||||
|
_height = params.outputHeight.value; |
||||
|
|
||||
|
_kernelParameters.width = _width; |
||||
|
} |
||||
|
|
||||
|
if(params.depth.isUpdated || params.startDepth.isUpdated || |
||||
|
params.fieldOfView.isUpdated || params.vcMaxTheta.isUpdated || |
||||
|
params.outputWidth.isUpdated || params.outputHeight.isUpdated) |
||||
|
{ |
||||
|
auto maxZ = params.depth.value; |
||||
|
auto minZ = params.startDepth.value * cosf(params.vcMaxTheta.value); |
||||
|
auto maxX = params.fieldOfView.value / 2 + maxZ * sinf(params.vcMaxTheta.value); |
||||
|
auto minX = -1 * maxX; |
||||
|
|
||||
|
auto baseZ = (maxZ - minZ) / (params.outputHeight.value - 1); |
||||
|
auto baseX = (maxX - minX) / (params.outputWidth.value - 1); |
||||
|
|
||||
|
for(auto i = 0; i < params.outputHeight.value; i++) |
||||
|
{ |
||||
|
auto temp = i * baseZ; |
||||
|
for(auto j = 0; j < params.outputWidth.value; j++) |
||||
|
{ |
||||
|
_gridPixelZPos[i * params.outputHeight.value + j] = minZ + temp; |
||||
|
_gridPixelXPos[i * params.outputHeight.value + j] = minX + (baseX * j); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
auto virtualOriginZ = params.fieldOfView.value / 2 / tanf(params.vcMaxTheta.value); |
||||
|
|
||||
|
if(_gridPixelR) |
||||
|
delete[] _gridPixelR; |
||||
|
|
||||
|
if(_gridPixelTheta) |
||||
|
delete[] _gridPixelTheta; |
||||
|
|
||||
|
_gridPixelR = new myflt[params.outputWidth.value * |
||||
|
params.outputHeight.value]; |
||||
|
_gridPixelTheta = new myflt[params.outputWidth.value * |
||||
|
params.outputHeight.value]; |
||||
|
|
||||
|
auto strTan = tanf(params.steering.value); |
||||
|
|
||||
|
for(auto i = 0; i < params.outputWidth.value * |
||||
|
params.outputHeight.value; i++) |
||||
|
{ |
||||
|
auto x = _gridPixelXPos[i]; |
||||
|
auto z = _gridPixelZPos[i]; |
||||
|
|
||||
|
auto pixelTheta = atanf(x / (z + virtualOriginZ)); |
||||
|
|
||||
|
if(pixelTheta >= -params.vcMaxTheta.value - abs(params.steering.value) && |
||||
|
pixelTheta <= params.vcMaxTheta.value + abs(params.steering.value)) |
||||
|
{ |
||||
|
if(params.steering.value == 0) |
||||
|
{ |
||||
|
auto gridPixelAx = sqrtf(powf(x - virtualOriginZ * tanf(pixelTheta), 2) + powf(z, 2)); |
||||
|
if(gridPixelAx >= params.startDepth.value && |
||||
|
gridPixelAx <= params.depth.value) |
||||
|
{ |
||||
|
_gridPixelR[i] = gridPixelAx; |
||||
|
_gridPixelTheta[i] = pixelTheta; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_gridPixelR[i] = 0; |
||||
|
_gridPixelTheta[i] = 0; |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
auto a = virtualOriginZ * strTan; |
||||
|
auto b = x * strTan + virtualOriginZ + z; |
||||
|
auto c = x - z * strTan; |
||||
|
auto interceptTheta = atanf((b + sqrtf(powf(b, 2) - 4 * a * c)) / (2 * a)); |
||||
|
if(interceptTheta > params.vcMaxTheta.value || |
||||
|
interceptTheta < -params.vcMaxTheta.value) |
||||
|
{ |
||||
|
interceptTheta = atanf((b - sqrtf(powf(b, 2) - 4 * a * c)) / (2 * a)); |
||||
|
if(interceptTheta > params.vcMaxTheta.value || |
||||
|
interceptTheta < -params.vcMaxTheta.value) |
||||
|
{ |
||||
|
_gridPixelR[i] = 0; |
||||
|
_gridPixelTheta[i] = 0; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
auto gridPixelAx = sqrtf(powf(x - virtualOriginZ * tanf(interceptTheta), 2) + powf(z, 2)); |
||||
|
if(gridPixelAx >= params.startDepth.value && |
||||
|
gridPixelAx <= params.depth.value) |
||||
|
{ |
||||
|
_gridPixelR[i] = gridPixelAx; |
||||
|
_gridPixelTheta[i] = interceptTheta; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_gridPixelR[i] = 0; |
||||
|
_gridPixelTheta[i] = 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
auto gridPixelAx = sqrtf(powf(x - virtualOriginZ * tanf(interceptTheta), 2) + powf(z, 2)); |
||||
|
if(gridPixelAx >= params.startDepth.value && |
||||
|
gridPixelAx <= params.depth.value) |
||||
|
{ |
||||
|
_gridPixelR[i] = gridPixelAx; |
||||
|
_gridPixelTheta[i] = interceptTheta; |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_gridPixelR[i] = 0; |
||||
|
_gridPixelTheta[i] = 0; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
_gridPixelR[i] = 0; |
||||
|
_gridPixelTheta[i] = 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if(_queryX) |
||||
|
delete _queryX; |
||||
|
|
||||
|
if(_queryZ) |
||||
|
delete _queryZ; |
||||
|
_queryX = _openCLHelper.array2CLBuffer(context, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt)); |
||||
|
_queryZ = _openCLHelper.array2CLBuffer(context, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt)); |
||||
|
|
||||
|
BIP::getInstance()->CLQueue.enqueueWriteBuffer(*_queryZ, CL_TRUE, 0, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt), |
||||
|
_gridPixelR); |
||||
|
queue.enqueueWriteBuffer(*_queryX, CL_TRUE, 0, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt), |
||||
|
_gridPixelTheta); |
||||
|
} |
||||
|
|
||||
|
if(params.minScanAz.isUpdated || params.rxLineNo.isUpdated || |
||||
|
params.rxLineDaz.isUpdated) |
||||
|
{ |
||||
|
if(_scanXPos) |
||||
|
delete [] _scanXPos; |
||||
|
|
||||
|
if(_gridX) |
||||
|
delete _gridX; |
||||
|
|
||||
|
_scanXPos = new myflt[params.rxLineNo.value]; |
||||
|
for(auto i = 0; i < params.rxLineNo.value; i++) |
||||
|
{ |
||||
|
_scanXPos[i] = params.minScanAz.value + i * params.rxLineDaz.value; |
||||
|
} |
||||
|
|
||||
|
_gridX = _openCLHelper.array2CLBuffer(context, |
||||
|
static_cast<quint64>(params.rxLineNo.value) |
||||
|
* sizeof (myflt)); |
||||
|
|
||||
|
queue.enqueueWriteBuffer(*_gridX, CL_TRUE, 0, |
||||
|
static_cast<unsigned long>(params.rxLineNo.value) * sizeof (myflt), |
||||
|
_scanXPos); |
||||
|
|
||||
|
_kernelParameters.gridXSize = params.rxLineNo.value; |
||||
|
} |
||||
|
|
||||
|
if(params.rxFocusPointNo.isUpdated || params.minScanAx.isUpdated || |
||||
|
params.rxPointDax.isUpdated) |
||||
|
{ |
||||
|
if(_scanZPos) |
||||
|
delete[] _scanZPos; |
||||
|
|
||||
|
if(_gridZ) |
||||
|
delete _gridZ; |
||||
|
|
||||
|
_scanZPos = new myflt [params.rxFocusPointNo.value]; |
||||
|
for(auto i = 0; i < params.rxFocusPointNo.value; i++) |
||||
|
{ |
||||
|
_scanZPos[i] = params.minScanAx.value + i * params.rxPointDax.value; |
||||
|
} |
||||
|
|
||||
|
_gridZ = _openCLHelper.array2CLBuffer(context, |
||||
|
static_cast<quint64>(params.rxFocusPointNo.value) |
||||
|
* sizeof (myflt)); |
||||
|
|
||||
|
queue.enqueueWriteBuffer(*_gridZ, CL_TRUE, 0, |
||||
|
static_cast<unsigned long>(params.rxFocusPointNo.value) * sizeof (myflt), |
||||
|
_scanZPos); |
||||
|
|
||||
|
_kernelParameters.gridZSize = params.rxFocusPointNo.value; |
||||
|
} |
||||
|
} |
||||
|
//linear non convex
|
||||
|
else |
||||
|
{ |
||||
|
if(params.outputWidth.isUpdated || params.outputHeight.isUpdated) |
||||
|
{ |
||||
|
if(_gridPixelXPos) |
||||
|
delete[] _gridPixelXPos; |
||||
|
|
||||
|
if(_gridPixelZPos) |
||||
|
delete[] _gridPixelZPos; |
||||
|
|
||||
|
_gridPixelXPos = new myflt[params.outputWidth.value * |
||||
|
params.outputHeight.value]; |
||||
|
_gridPixelZPos = new myflt[params.outputWidth.value * |
||||
|
params.outputHeight.value]; |
||||
|
|
||||
|
if(_queryX) |
||||
|
delete _queryX; |
||||
|
|
||||
|
if(_queryZ) |
||||
|
delete _queryZ; |
||||
|
|
||||
|
_queryX = _openCLHelper.array2CLBuffer(context, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt)); |
||||
|
_queryZ = _openCLHelper.array2CLBuffer(context, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt)); |
||||
|
|
||||
|
_width = params.outputWidth.value; |
||||
|
_height = params.outputHeight.value; |
||||
|
|
||||
|
_kernelParameters.width = _width; |
||||
|
} |
||||
|
|
||||
|
if(params.depth.isUpdated || params.startDepth.isUpdated || |
||||
|
params.fieldOfView.isUpdated || params.steering.isUpdated || |
||||
|
params.outputWidth.isUpdated || params.outputHeight.isUpdated) |
||||
|
{ |
||||
|
auto maxZ = params.depth.value; |
||||
|
auto minZ = params.startDepth.value; |
||||
|
auto maxX = params.fieldOfView.value / 2; |
||||
|
auto minX = -1 * maxX; |
||||
|
|
||||
|
auto baseZ = (maxZ - minZ) / (params.outputHeight.value - 1); |
||||
|
auto baseX = (maxX - minX) / (params.outputWidth.value - 1); |
||||
|
|
||||
|
for(auto i = 0; i < params.outputHeight.value; i++) |
||||
|
{ |
||||
|
auto temp = i * baseZ; |
||||
|
auto tan_result = temp * tanf(params.steering.value); |
||||
|
for(auto j = 0; j < params.outputWidth.value; j++) |
||||
|
{ |
||||
|
_gridPixelZPos[i * params.outputHeight.value + j] = minZ + temp; |
||||
|
_gridPixelXPos[i * params.outputHeight.value + j] = minX + (baseX * j) - tan_result; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
BIP::getInstance()->CLQueue.enqueueWriteBuffer(*_queryX, CL_TRUE, 0, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt), |
||||
|
_gridPixelXPos); |
||||
|
queue.enqueueWriteBuffer(*_queryZ, CL_TRUE, 0, |
||||
|
params.outputWidth.value * |
||||
|
params.outputHeight.value * |
||||
|
sizeof (myflt), |
||||
|
_gridPixelZPos); |
||||
|
} |
||||
|
|
||||
|
if(params.fieldOfView.isUpdated || params.rxLineNo.isUpdated || |
||||
|
params.rxLineDaz.isUpdated) |
||||
|
{ |
||||
|
if(_scanXPos) |
||||
|
delete [] _scanXPos; |
||||
|
|
||||
|
if(_gridX) |
||||
|
delete _gridX; |
||||
|
|
||||
|
_scanXPos = new myflt[params.rxLineNo.value]; |
||||
|
for(auto i = 0; i < params.rxLineNo.value; i++) |
||||
|
{ |
||||
|
_scanXPos[i] = -params.fieldOfView.value / 2 + i * params.rxLineDaz.value; |
||||
|
} |
||||
|
|
||||
|
_gridX = _openCLHelper.array2CLBuffer(context, |
||||
|
static_cast<quint64>(params.rxLineNo.value) |
||||
|
* sizeof (myflt)); |
||||
|
|
||||
|
queue.enqueueWriteBuffer(*_gridX, CL_TRUE, 0, |
||||
|
static_cast<unsigned long>(params.rxLineNo.value) * sizeof (myflt), |
||||
|
_scanXPos); |
||||
|
|
||||
|
_kernelParameters.gridXSize = params.rxLineNo.value; |
||||
|
} |
||||
|
|
||||
|
if(params.rxFocusPointNo.isUpdated || params.rxPointDax.isUpdated) |
||||
|
{ |
||||
|
if(_scanZPos) |
||||
|
delete[] _scanZPos; |
||||
|
|
||||
|
if(_gridZ) |
||||
|
delete _gridZ; |
||||
|
|
||||
|
_scanZPos = new myflt [params.rxFocusPointNo.value]; |
||||
|
for(auto i = 0; i < params.rxFocusPointNo.value; i++) |
||||
|
{ |
||||
|
_scanZPos[i] = params.startDepth.value + i * params.rxPointDax.value; |
||||
|
} |
||||
|
|
||||
|
_gridZ = _openCLHelper.array2CLBuffer(context, |
||||
|
static_cast<quint64>(params.rxFocusPointNo.value) |
||||
|
* sizeof (myflt)); |
||||
|
|
||||
|
queue.enqueueWriteBuffer(*_gridZ, CL_TRUE, 0, |
||||
|
static_cast<unsigned long>(params.rxFocusPointNo.value) * sizeof (myflt), |
||||
|
_scanZPos); |
||||
|
|
||||
|
_kernelParameters.gridZSize = params.rxFocusPointNo.value; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void ScanConversion::finalize() |
||||
|
{ |
||||
|
delete _gridPixelXPos; |
||||
|
delete _gridPixelZPos; |
||||
|
delete _scanXPos; |
||||
|
delete _scanZPos; |
||||
|
|
||||
|
delete _gridX; |
||||
|
delete _gridZ; |
||||
|
delete _queryX; |
||||
|
delete _queryZ; |
||||
|
|
||||
|
_gridPixelXPos = Q_NULLPTR; |
||||
|
_gridPixelZPos = Q_NULLPTR; |
||||
|
_scanXPos = Q_NULLPTR; |
||||
|
_scanZPos = Q_NULLPTR; |
||||
|
|
||||
|
_gridX = Q_NULLPTR; |
||||
|
_gridZ = Q_NULLPTR; |
||||
|
_queryX = Q_NULLPTR; |
||||
|
_queryZ = Q_NULLPTR; |
||||
|
} |
||||
|
|
||||
|
Image* ScanConversion::processKernel(Image *frames, Buffer* scrathPad) |
||||
|
{ |
||||
|
Context context = _openCLHelper.getContext(); |
||||
|
auto format = frames->getImageInfo<CL_IMAGE_FORMAT>(); |
||||
|
auto imageOutput = new Image2D(context, |
||||
|
CL_MEM_READ_WRITE, |
||||
|
ImageFormat(format.image_channel_order, format.image_channel_data_type), |
||||
|
_width, |
||||
|
_height); |
||||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(_width, _height)); |
||||
|
|
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, Buffer, Buffer, Buffer, |
||||
|
Buffer, ScanConversion_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*(Image2D*)(frames), |
||||
|
*imageOutput, |
||||
|
*_gridX, |
||||
|
*_gridZ, |
||||
|
*_queryX, |
||||
|
*_queryZ, |
||||
|
_kernelParameters); |
||||
|
delete frames; |
||||
|
|
||||
|
return imageOutput; |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,126 @@ |
|||||
|
#include "model/processor/strategies/Sri.h" |
||||
|
#include "model/processor/BIP.h" |
||||
|
#include <QPixmap> |
||||
|
#include <QImage> |
||||
|
|
||||
|
Sri::Sri(const Context context, |
||||
|
const QString kernelPath, |
||||
|
const QObject *parent = Q_NULLPTR) : |
||||
|
IProcessStrategy(context, kernelPath, "Sri", parent), |
||||
|
_kernelFunctor(KernelFunctor<Image2D, Image2D, |
||||
|
LocalSpaceArg, Buffer, Sri_t>(_kernel)) |
||||
|
{ |
||||
|
memset(&_kernelParameters, 0, sizeof (Sri_t)); |
||||
|
} |
||||
|
|
||||
|
void Sri::cpuProcess(ScenGenOutput_t parameters) |
||||
|
{ |
||||
|
if(parameters.sri.isUpdated) |
||||
|
{ |
||||
|
_kernelParameters.sri = parameters.sri.value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void Sri::finalize() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Image* Sri::processKernel(Image *frames, Buffer* scratchPad) |
||||
|
{ |
||||
|
auto format = frames->getImageInfo<CL_IMAGE_FORMAT>(); |
||||
|
auto width = frames->getImageInfo<CL_IMAGE_WIDTH>(); |
||||
|
auto height = frames->getImageInfo<CL_IMAGE_HEIGHT>(); |
||||
|
|
||||
|
_kernelParameters.width = width; |
||||
|
_kernelParameters.height = height; |
||||
|
|
||||
|
auto imageOutput = new Image2D(_CLContext, |
||||
|
CL_MEM_READ_WRITE, |
||||
|
ImageFormat(format.image_channel_order, format.image_channel_data_type), |
||||
|
width, |
||||
|
height); |
||||
|
if(_kernelParameters.sri != 0) |
||||
|
{ |
||||
|
//width should be lass than CL_DEVICE_MAX_WORK_GROUP_SIZE(1024 for current machine) or this will break
|
||||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height), cl::NDRange(width, 1)); |
||||
|
|
||||
|
_kernelParameters.state = 1; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(width * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
cl::EnqueueArgs eargs2(BIP::getInstance()->CLQueue, cl::NDRange(height, 1), cl::NDRange(height, 1)); |
||||
|
|
||||
|
_kernelParameters.state = 2; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs2, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(height * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
|
||||
|
_kernelParameters.state = 3; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(1), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
|
||||
|
_kernelParameters.state = 4; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(imageOutput), |
||||
|
*imageOutput, |
||||
|
Local(width * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
|
||||
|
_kernelParameters.state = 5; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs2, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(height * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
cl::EnqueueArgs eargs3(BIP::getInstance()->CLQueue, cl::NDRange(width, height)); |
||||
|
_kernelParameters.state = 6; |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs3, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(1), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height)); |
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, LocalSpaceArg, Buffer, Sri_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
Local(49 * sizeof (myflt)), |
||||
|
*scratchPad, |
||||
|
_kernelParameters); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
delete frames; |
||||
|
return imageOutput; |
||||
|
} |
||||
|
|
||||
|
|
@ -0,0 +1,57 @@ |
|||||
|
#include "model/processor/strategies/TintMap.h" |
||||
|
#include "model/processor/BIP.h" |
||||
|
#include <QPixmap> |
||||
|
#include <QImage> |
||||
|
|
||||
|
TintMap::TintMap(const Context context, |
||||
|
const QString kernelPath, |
||||
|
const QObject *parent = Q_NULLPTR) : |
||||
|
IProcessStrategy(context, kernelPath, "TintMap", parent), |
||||
|
_kernelFunctor(KernelFunctor<Image2D, Image2D, |
||||
|
TintMap_t>(_kernel)) |
||||
|
{ |
||||
|
memset(&_kernelParameters, 0, sizeof (TintMap_t)); |
||||
|
} |
||||
|
|
||||
|
void TintMap::cpuProcess(ScenGenOutput_t parameters) |
||||
|
{ |
||||
|
if(parameters.tintMapSelector.isUpdated) |
||||
|
{ |
||||
|
_kernelParameters.tintMapSelector = parameters.tintMapSelector.value; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
void TintMap::finalize() |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
|
||||
|
Image* TintMap::processKernel(Image *frames, Buffer* scratchPad) |
||||
|
{ |
||||
|
auto width = frames->getImageInfo<CL_IMAGE_WIDTH>(); |
||||
|
auto height = frames->getImageInfo<CL_IMAGE_HEIGHT>(); |
||||
|
|
||||
|
ImageFormat format; |
||||
|
format.image_channel_order = CL_RGBA; |
||||
|
format.image_channel_data_type = CL_UNSIGNED_INT8; |
||||
|
|
||||
|
auto imageOutput = new Image2D(_CLContext, |
||||
|
CL_MEM_READ_WRITE, |
||||
|
format, |
||||
|
width, |
||||
|
height); |
||||
|
//width should be lass than CL_DEVICE_MAX_WORK_GROUP_SIZE(1024 for current machine) or this will break
|
||||
|
cl::EnqueueArgs eargs(BIP::getInstance()->CLQueue, cl::NDRange(width, height)); |
||||
|
|
||||
|
_openCLHelper.runKernelFunctor<Image2D, Image2D, TintMap_t>(_kernelFunctor, |
||||
|
eargs, |
||||
|
*static_cast<Image2D*>(frames), |
||||
|
*imageOutput, |
||||
|
_kernelParameters); |
||||
|
|
||||
|
delete frames; |
||||
|
|
||||
|
return imageOutput; |
||||
|
} |
||||
|
|
||||
|
|
@ -1,255 +0,0 @@ |
|||||
#include "header/strategies/ScanConversion.h" |
|
||||
#include "MainWindow.h" |
|
||||
#include <QPixmap> |
|
||||
#include <QImage> |
|
||||
|
|
||||
ScanConversion::ScanConversion(const Context context, |
|
||||
const QString kernelPath) : |
|
||||
IProcessStrategy(context, kernelPath, "ScanConversion"), |
|
||||
_kernelFunctor(KernelFunctor<Image2D, Image2D, |
|
||||
Buffer, Buffer, Buffer, Buffer, ScanConversion_t>(_kernel)) |
|
||||
{ |
|
||||
_gridPixelXPos = Q_NULLPTR; |
|
||||
_gridPixelZPos = Q_NULLPTR; |
|
||||
_scanXPos = Q_NULLPTR; |
|
||||
_scanZPos = Q_NULLPTR; |
|
||||
|
|
||||
_gridX = Q_NULLPTR; |
|
||||
_gridZ = Q_NULLPTR; |
|
||||
_queryX = Q_NULLPTR; |
|
||||
_queryZ = Q_NULLPTR; |
|
||||
} |
|
||||
|
|
||||
void ScanConversion::cpuProcess(ScenGenOutput_t parameters) |
|
||||
{ |
|
||||
auto context = _CLContext; |
|
||||
auto queue = MainWindow::getInstance()->CLQueue; |
|
||||
|
|
||||
if(parameters.outputWidth.isUpdated || parameters.outputHeight.isUpdated) |
|
||||
{ |
|
||||
if(_gridPixelXPos) |
|
||||
delete[] _gridPixelXPos; |
|
||||
|
|
||||
if(_gridPixelZPos) |
|
||||
delete[] _gridPixelZPos; |
|
||||
|
|
||||
_gridPixelXPos = new myflt[parameters.outputWidth.value * |
|
||||
parameters.outputHeight.value]; |
|
||||
_gridPixelZPos = new myflt[parameters.outputWidth.value * |
|
||||
parameters.outputHeight.value]; |
|
||||
|
|
||||
if(_queryX) |
|
||||
delete _queryX; |
|
||||
|
|
||||
if(_queryZ) |
|
||||
delete _queryZ; |
|
||||
|
|
||||
_queryX = _openCLHelper.array2CLBuffer(context, |
|
||||
parameters.outputWidth.value * |
|
||||
parameters.outputHeight.value * |
|
||||
sizeof (myflt)); |
|
||||
_queryZ = _openCLHelper.array2CLBuffer(context, |
|
||||
parameters.outputWidth.value * |
|
||||
parameters.outputHeight.value * |
|
||||
sizeof (myflt)); |
|
||||
|
|
||||
_width = parameters.outputWidth.value; |
|
||||
_height = parameters.outputHeight.value; |
|
||||
|
|
||||
_kernelParameters.width = _width; |
|
||||
} |
|
||||
|
|
||||
if(parameters.depth.isUpdated || parameters.startDepth.isUpdated || |
|
||||
parameters.fieldOfView.isUpdated || parameters.steering.isUpdated || |
|
||||
parameters.outputWidth.isUpdated || parameters.outputHeight.isUpdated) |
|
||||
{ |
|
||||
auto maxZ = parameters.depth.value; |
|
||||
auto minZ = parameters.startDepth.value; |
|
||||
auto maxX = parameters.fieldOfView.value / 2; |
|
||||
auto minX = -1 * maxX; |
|
||||
|
|
||||
auto baseZ = (maxZ - minZ) / (parameters.outputHeight.value - 1); |
|
||||
auto baseX = (maxX - minX) / (parameters.outputWidth.value - 1); |
|
||||
|
|
||||
for(auto i = 0; i < parameters.outputHeight.value; i++) |
|
||||
{ |
|
||||
auto temp = minZ + i * baseZ; |
|
||||
auto tan_result = temp * tan(parameters.steering.value); |
|
||||
for(auto j = 0; j < parameters.outputWidth.value; j++) |
|
||||
{ |
|
||||
_gridPixelZPos[i * parameters.outputHeight.value + j] = temp; |
|
||||
_gridPixelXPos[i * parameters.outputHeight.value + j] = minX + (baseX * j) - tan_result; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
queue.enqueueWriteBuffer(*_queryX, CL_TRUE, 0, |
|
||||
parameters.outputWidth.value * |
|
||||
parameters.outputHeight.value * |
|
||||
sizeof (myflt), |
|
||||
_gridPixelXPos); |
|
||||
queue.enqueueWriteBuffer(*_queryZ, CL_TRUE, 0, |
|
||||
parameters.outputWidth.value * |
|
||||
parameters.outputHeight.value * |
|
||||
sizeof (myflt), |
|
||||
_gridPixelZPos); |
|
||||
} |
|
||||
|
|
||||
if(parameters.fieldOfView.isUpdated || parameters.rxLineNo.isUpdated || |
|
||||
parameters.rxLineDaz.isUpdated) |
|
||||
{ |
|
||||
if(_scanXPos) |
|
||||
delete [] _scanXPos; |
|
||||
|
|
||||
if(_gridX) |
|
||||
delete _gridX; |
|
||||
|
|
||||
_scanXPos = new myflt[parameters.rxLineNo.value]; |
|
||||
for(auto i = 0; i < parameters.rxLineNo.value; i++) |
|
||||
{ |
|
||||
_scanXPos[i] = -parameters.fieldOfView.value / 2 + i * parameters.rxLineDaz.value; |
|
||||
} |
|
||||
|
|
||||
_gridX = _openCLHelper.array2CLBuffer(context, |
|
||||
static_cast<quint64>(parameters.rxLineNo.value) |
|
||||
* sizeof (myflt)); |
|
||||
|
|
||||
queue.enqueueWriteBuffer(*_gridX, CL_TRUE, 0, |
|
||||
static_cast<unsigned long>(parameters.rxLineNo.value) * sizeof (myflt), |
|
||||
_scanXPos); |
|
||||
|
|
||||
_kernelParameters.gridXSize = parameters.rxLineNo.value; |
|
||||
} |
|
||||
|
|
||||
if(parameters.rxFocusPointNo.isUpdated || parameters.rxPointDax.isUpdated) |
|
||||
{ |
|
||||
if(_scanZPos) |
|
||||
delete[] _scanZPos; |
|
||||
|
|
||||
if(_gridZ) |
|
||||
delete _gridZ; |
|
||||
|
|
||||
_scanZPos = new myflt [parameters.rxFocusPointNo.value]; |
|
||||
for(auto i = 0; i < parameters.rxFocusPointNo.value; i++) |
|
||||
{ |
|
||||
_scanZPos[i] = parameters.startDepth.value + i * parameters.rxPointDax.value; |
|
||||
} |
|
||||
|
|
||||
_gridZ = _openCLHelper.array2CLBuffer(context, |
|
||||
static_cast<quint64>(parameters.rxFocusPointNo.value) |
|
||||
* sizeof (myflt)); |
|
||||
|
|
||||
queue.enqueueWriteBuffer(*_gridZ, CL_TRUE, 0, |
|
||||
static_cast<unsigned long>(parameters.rxFocusPointNo.value) * sizeof (myflt), |
|
||||
_scanZPos); |
|
||||
|
|
||||
_kernelParameters.gridZSize = parameters.rxFocusPointNo.value; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
void ScanConversion::finalize() |
|
||||
{ |
|
||||
delete _gridPixelXPos; |
|
||||
delete _gridPixelZPos; |
|
||||
delete _scanXPos; |
|
||||
delete _scanZPos; |
|
||||
|
|
||||
delete _gridX; |
|
||||
delete _gridZ; |
|
||||
delete _queryX; |
|
||||
delete _queryZ; |
|
||||
|
|
||||
_gridPixelXPos = Q_NULLPTR; |
|
||||
_gridPixelZPos = Q_NULLPTR; |
|
||||
_scanXPos = Q_NULLPTR; |
|
||||
_scanZPos = Q_NULLPTR; |
|
||||
|
|
||||
_gridX = Q_NULLPTR; |
|
||||
_gridZ = Q_NULLPTR; |
|
||||
_queryX = Q_NULLPTR; |
|
||||
_queryZ = Q_NULLPTR; |
|
||||
} |
|
||||
|
|
||||
void ScanConversion::ReadParams(QString path, ScenGenOutput_t *params) |
|
||||
{ |
|
||||
QFile file(path); |
|
||||
file.open(QIODevice::ReadOnly); |
|
||||
|
|
||||
char data[8192]; |
|
||||
//first line is extra
|
|
||||
file.readLine(data, 8192); |
|
||||
QString str(data); |
|
||||
str = str.remove(str.length() - 1, 1); |
|
||||
auto sl = str.split(","); |
|
||||
|
|
||||
//decode here
|
|
||||
/***scenario specific code***/ |
|
||||
int index = 0; |
|
||||
auto temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->linear, INP2MYFLT(temp) == 0); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->depth, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->probeRadius, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->fieldOfView, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->startDepth, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->steering, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field<int>(¶ms->rxLineNo, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field<int>(¶ms->rxFocusPointNo, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->rxLineDaz, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->rxPointDax, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->virtualConvex, INP2MYFLT(temp) != 0); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->vcMaxTheta, INP2MYFLT(temp)); |
|
||||
|
|
||||
temp = sl[index++].PARSE; |
|
||||
update_field(¶ms->angle, INP2MYFLT(temp)); |
|
||||
/***End of scenario specific code***/ |
|
||||
} |
|
||||
|
|
||||
|
|
||||
Image* ScanConversion::processKernel(Image *frames, Buffer* scratchPad) |
|
||||
{ |
|
||||
Context context = _openCLHelper.getContext(); |
|
||||
auto format = frames->getImageInfo<CL_IMAGE_FORMAT>(); |
|
||||
auto imageOutput = new Image2D(context, |
|
||||
CL_MEM_READ_WRITE, |
|
||||
ImageFormat(format.image_channel_order, format.image_channel_data_type), |
|
||||
_width, |
|
||||
_height); |
|
||||
cl::EnqueueArgs eargs(MainWindow::getInstance()->CLQueue, cl::NDRange(_width, _height)); |
|
||||
|
|
||||
_openCLHelper.runKernelFunctor<Image2D, Image2D, Buffer, Buffer, Buffer, |
|
||||
Buffer, ScanConversion_t>(_kernelFunctor, |
|
||||
eargs, |
|
||||
*static_cast<Image2D*>(frames), |
|
||||
*imageOutput, |
|
||||
*_gridX, |
|
||||
*_gridZ, |
|
||||
*_queryX, |
|
||||
*_queryZ, |
|
||||
_kernelParameters); |
|
||||
delete frames; |
|
||||
|
|
||||
return imageOutput; |
|
||||
} |
|
||||
|
|
||||
|
|
Loading…
Reference in new issue