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.

129 lines
3.4 KiB

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