|
|
|
#include "model/processor/strategies/ScanConversion.h"
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QImage>
|
|
|
|
#include "model/processor/BIP.h"
|
|
|
|
#include "model/algorithms/ScanConversionAlg.h"
|
|
|
|
|
|
|
|
#include <QtMath>
|
|
|
|
|
|
|
|
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))
|
|
|
|
{
|
|
|
|
_gridX = Q_NULLPTR;
|
|
|
|
_gridZ = Q_NULLPTR;
|
|
|
|
_queryX = Q_NULLPTR;
|
|
|
|
_queryZ = Q_NULLPTR;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScanConversion::cpuProcess(Input_t params)
|
|
|
|
{
|
|
|
|
auto context = _openCLHelper.getContext();
|
|
|
|
auto queue = BIP::getInstance()->CLQueue;
|
|
|
|
|
|
|
|
if(_queryX)
|
|
|
|
delete _queryX;
|
|
|
|
|
|
|
|
if(_queryZ)
|
|
|
|
delete _queryZ;
|
|
|
|
|
|
|
|
if(_gridX)
|
|
|
|
delete _gridX;
|
|
|
|
|
|
|
|
if(_gridZ)
|
|
|
|
delete _gridZ;
|
|
|
|
|
|
|
|
_gridPixelXPos.clear();
|
|
|
|
_gridPixelZPos.clear();
|
|
|
|
_scanXPos.clear();
|
|
|
|
_scanZPos.clear();
|
|
|
|
|
|
|
|
_queryX = _openCLHelper.array2CLBuffer(context,
|
|
|
|
params.outputWidth *
|
|
|
|
params.outputHeight *
|
|
|
|
sizeof (myflt));
|
|
|
|
_queryZ = _openCLHelper.array2CLBuffer(context,
|
|
|
|
params.outputWidth *
|
|
|
|
params.outputHeight *
|
|
|
|
sizeof (myflt));
|
|
|
|
|
|
|
|
_gridX = _openCLHelper.array2CLBuffer
|
|
|
|
(context, static_cast<quint64>(params.rxLineNo * sizeof (float)));
|
|
|
|
|
|
|
|
_gridZ = _openCLHelper.array2CLBuffer
|
|
|
|
(context, static_cast<quint64>(params.rxFocusPointNo * sizeof (float)));
|
|
|
|
|
|
|
|
ScanConversionAlg::scanConversion(params, _scanXPos, _scanZPos, _gridPixelXPos, _gridPixelZPos);
|
|
|
|
|
|
|
|
queue.enqueueWriteBuffer(*_queryZ, CL_TRUE, 0,
|
|
|
|
params.outputWidth *
|
|
|
|
params.outputHeight *
|
|
|
|
sizeof (myflt),
|
|
|
|
_gridPixelZPos.data());
|
|
|
|
|
|
|
|
queue.enqueueWriteBuffer(*_queryX, CL_TRUE, 0,
|
|
|
|
params.outputWidth *
|
|
|
|
params.outputHeight *
|
|
|
|
sizeof (myflt),
|
|
|
|
_gridPixelXPos.data());
|
|
|
|
|
|
|
|
queue.enqueueWriteBuffer(*_gridX, CL_TRUE, 0,
|
|
|
|
static_cast<quint64>(params.rxLineNo * sizeof (float)),
|
|
|
|
_scanXPos.data());
|
|
|
|
|
|
|
|
queue.enqueueWriteBuffer(*_gridZ, CL_TRUE, 0,
|
|
|
|
static_cast<quint64>(params.rxFocusPointNo * sizeof (float)),
|
|
|
|
_scanZPos.data());
|
|
|
|
|
|
|
|
_kernelParameters.gridXSize = params.rxLineNo;
|
|
|
|
_kernelParameters.gridZSize = params.rxFocusPointNo;
|
|
|
|
_kernelParameters.width = params.outputWidth;
|
|
|
|
|
|
|
|
_width = params.outputWidth;
|
|
|
|
_height = params.outputHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScanConversion::finalize()
|
|
|
|
{
|
|
|
|
delete _gridX;
|
|
|
|
delete _gridZ;
|
|
|
|
delete _queryX;
|
|
|
|
delete _queryZ;
|
|
|
|
|
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|