Browse Source

Add Rejection

test-kernel
sono 5 years ago
parent
commit
e0e42a310b
  1. 4
      KernelTester.pro
  2. 9
      MainWindow.cpp
  3. 1
      header/ScenarioParams.h
  4. 32
      header/strategies/Rejection.h
  5. 0
      header/strategies/ScanConversion.h
  6. 69
      source/strategies/Rejection.cpp
  7. 2
      source/strategies/ScanConversion.cpp

4
KernelTester.pro

@ -17,7 +17,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
SOURCES += $$files(source/*.cpp, true) \
main.cpp \
MainWindow.cpp
MainWindow.cpp \
LIBS+= -L"$$PWD/header/CL" -lOpenCL
LIBS += -lmatio
@ -40,7 +40,7 @@ HEADERS += $$files(header/*.h, true) \
header/CL/cl_gl_ext.h \
header/CL/cl_platform.h \
header/CL/cl2.hpp \
header/CL/opencl.h
header/CL/opencl.h \

9
MainWindow.cpp

@ -4,7 +4,8 @@
#include <QFileDialog>
#include <QFile>
#include "header/Strategies/ScanConversion.h"
#include "header/strategies/ScanConversion.h"
#include "header/strategies/Rejection.h"
#include "header/FileHelper.h"
#define OUT_WIDTH 1000
@ -27,6 +28,7 @@ MainWindow::MainWindow(QWidget *parent)
_CLContext)[0]);
registerStrategies();
_strategy = Q_NULLPTR;
}
MainWindow::~MainWindow()
@ -70,6 +72,7 @@ bool MainWindow::checkPath(QString path, QString pathName)
void MainWindow::registerStrategies()
{
REGISTER_STRATEGY(ScanConversion)
REGISTER_STRATEGY(Rejection)
}
void MainWindow::pushBackStrategy(const QString strategyName, const QString kernelFolder)
@ -222,7 +225,7 @@ void MainWindow::on_btn_compare_clicked()
QDir matlabDir(ui->tb_matlabOutp->text());
QDir outputDir(ui->tb_outpDir->text());
auto totalMax = 0;
auto totalMax = 0U;
auto outputs = outputDir.entryList(QStringList() << "*.csv", QDir::Files);
foreach(QString filename, outputs)
{
@ -252,7 +255,7 @@ void MainWindow::on_btn_compare_clicked()
continue;
}
int max = 0;
uint max = 0;
for(int i = 0; i < w1; i++)
{
for(int j = 0; j < h1; j++)

1
header/ScenarioParams.h

@ -25,6 +25,7 @@ typedef struct ScenGenOutput_t
field_t<double> steering;
field_t<int> outputWidth;
field_t<int> outputHeight;
field_t<double> rejectThreshold;
}ScenGenOutput_t;
template<typename T>

32
header/strategies/Rejection.h

@ -0,0 +1,32 @@
#ifndef REJECTION_H
#define REJECTION_H
#include <QObject>
#include <QMetaType>
#include "header/IProcessStrategy.h"
#include "header/OpenCLHelper.h"
typedef struct Rejection_t
{
cl_int rejectThr;
}Rejection_t;
class Rejection : public IProcessStrategy
{
Q_OBJECT
public:
Q_INVOKABLE Rejection(const Context context, const QString kernelPath);
virtual void cpuProcess(ScenGenOutput_t parameters) override;
virtual void finalize() override;
virtual void ReadParams(QString path, ScenGenOutput_t *params) override;
private:
KernelFunctor<Image2D, Image2D, Rejection_t> _kernelFunctor;
virtual Image* processKernel(Image *frames) override;
Rejection_t _kernelParameters;
double _rejectionThr;
};
#endif // REJECTION_H

0
header/Strategies/ScanConversion.h → header/strategies/ScanConversion.h

69
source/strategies/Rejection.cpp

@ -0,0 +1,69 @@
#include "header/strategies/Rejection.h"
#include "MainWindow.h"
#include <QPixmap>
#include <QImage>
Rejection::Rejection(const Context context,
const QString kernelPath) :
IProcessStrategy(context, kernelPath, "Rejection"),
_kernelFunctor(KernelFunctor<Image2D, Image2D,
Rejection_t>(_kernel))
{
}
void Rejection::cpuProcess(ScenGenOutput_t parameters)
{
_rejectionThr = parameters.rejectThreshold.value;
}
void Rejection::finalize()
{
}
void Rejection::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->rejectThreshold, INP2MYFLT(temp));
/***End of scenario specific code***/
}
Image* Rejection::processKernel(Image *frames)
{
Context context = _openCLHelper.getContext();
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(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, Rejection_t>(_kernelFunctor,
eargs,
*static_cast<Image2D*>(frames),
*imageOutput,
_kernelParameters);
delete frames;
return imageOutput;
}

2
source/strategies/ScanConversion.cpp

@ -1,4 +1,4 @@
#include "header/Strategies/ScanConversion.h"
#include "header/strategies/ScanConversion.h"
#include "MainWindow.h"
#include <QPixmap>
#include <QImage>

Loading…
Cancel
Save