You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

255 lines
7.1 KiB

#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 = 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] = minZ + 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(&params->linear, INP2MYFLT(temp) == 0);
temp = sl[index++].PARSE;
update_field(&params->depth, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->probeRadius, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->fieldOfView, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->startDepth, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->steering, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field<int>(&params->rxLineNo, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field<int>(&params->rxFocusPointNo, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->rxLineDaz, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->rxPointDax, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->virtualConvex, INP2MYFLT(temp) != 0);
temp = sl[index++].PARSE;
update_field(&params->vcMaxTheta, INP2MYFLT(temp));
temp = sl[index++].PARSE;
update_field(&params->angle, INP2MYFLT(temp));
/***End of scenario specific code***/
}
Image* ScanConversion::processKernel(Image *frames)
{
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;
}