From e0e42a310ba4609bd4b1ace42683941a329e51ca Mon Sep 17 00:00:00 2001 From: sono Date: Sun, 15 Mar 2020 18:19:31 +0330 Subject: [PATCH] Add Rejection --- KernelTester.pro | 4 +- MainWindow.cpp | 9 ++- header/ScenarioParams.h | 1 + header/strategies/Rejection.h | 32 +++++++++ .../ScanConversion.h | 0 source/strategies/Rejection.cpp | 69 +++++++++++++++++++ source/strategies/ScanConversion.cpp | 2 +- 7 files changed, 111 insertions(+), 6 deletions(-) create mode 100644 header/strategies/Rejection.h rename header/{Strategies => strategies}/ScanConversion.h (100%) create mode 100644 source/strategies/Rejection.cpp diff --git a/KernelTester.pro b/KernelTester.pro index 4938c34..1a6e396 100644 --- a/KernelTester.pro +++ b/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 \ diff --git a/MainWindow.cpp b/MainWindow.cpp index b034272..becda78 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -4,7 +4,8 @@ #include #include -#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++) diff --git a/header/ScenarioParams.h b/header/ScenarioParams.h index 9b7a41e..1ad13af 100644 --- a/header/ScenarioParams.h +++ b/header/ScenarioParams.h @@ -25,6 +25,7 @@ typedef struct ScenGenOutput_t field_t steering; field_t outputWidth; field_t outputHeight; + field_t rejectThreshold; }ScenGenOutput_t; template diff --git a/header/strategies/Rejection.h b/header/strategies/Rejection.h new file mode 100644 index 0000000..f5fd01e --- /dev/null +++ b/header/strategies/Rejection.h @@ -0,0 +1,32 @@ +#ifndef REJECTION_H +#define REJECTION_H + +#include +#include +#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 _kernelFunctor; + virtual Image* processKernel(Image *frames) override; + Rejection_t _kernelParameters; + + double _rejectionThr; +}; + +#endif // REJECTION_H diff --git a/header/Strategies/ScanConversion.h b/header/strategies/ScanConversion.h similarity index 100% rename from header/Strategies/ScanConversion.h rename to header/strategies/ScanConversion.h diff --git a/source/strategies/Rejection.cpp b/source/strategies/Rejection.cpp new file mode 100644 index 0000000..0ea26e4 --- /dev/null +++ b/source/strategies/Rejection.cpp @@ -0,0 +1,69 @@ +#include "header/strategies/Rejection.h" +#include "MainWindow.h" +#include +#include + +Rejection::Rejection(const Context context, + const QString kernelPath) : + IProcessStrategy(context, kernelPath, "Rejection"), + _kernelFunctor(KernelFunctor(_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(¶ms->rejectThreshold, INP2MYFLT(temp)); + /***End of scenario specific code***/ +} + + +Image* Rejection::processKernel(Image *frames) +{ + Context context = _openCLHelper.getContext(); + auto format = frames->getImageInfo(); + auto width = frames->getImageInfo(); + auto height = frames->getImageInfo(); + 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(_kernelFunctor, + eargs, + *static_cast(frames), + *imageOutput, + _kernelParameters); + delete frames; + + return imageOutput; +} + + diff --git a/source/strategies/ScanConversion.cpp b/source/strategies/ScanConversion.cpp index ea5f1c4..8841feb 100644 --- a/source/strategies/ScanConversion.cpp +++ b/source/strategies/ScanConversion.cpp @@ -1,4 +1,4 @@ -#include "header/Strategies/ScanConversion.h" +#include "header/strategies/ScanConversion.h" #include "MainWindow.h" #include #include