#include "MTF.h"
int MaxX = 255;
Chart * chart;
Chart
::Chart(PluginAnalysisIO
* IO
): QObject(IO
){
pluginIO = IO;
// return;
//QWidget * parentWidget = pluginIO->outputWidgets[0];
// QVBoxLayout *layout1 = new QVBoxLayout(parentWidget);
// layout1->addWidget(plot);
// QGridLayout * grid = new QGridLayout(parentWidget);
// layout1->addLayout(grid);
// if(!LibTI_MTFInitializeWithHandlers(DefaultErrorHandler, DefaultPrintHandler)) {
if(!LibTI_MTFInitialize()){
//mclTerminateApplication();
QMessageBox::critical(0,
"Error",
"Error initializing Matlab engine!\nPlease try to restart application.");
//return 2;
} else{
//return 0;
}
}
int main(int a,char** ){ return 0;}
Chart::~Chart(){
LibTI_MTFTerminate();
}
void Chart::showChart(){
QString imageFileName
= pluginIO
->imageFileName.
toLower();
// QString tempPath = tempDir.canonicalPath();
QString tempPath
= tempDir.
absolutePath();
QString outPrefix
= tempPath
+"/MTF_Images_";
QString CoordinatesFile
= outPrefix
+ "coordinates.txt";
#if defined(Q_OS_WIN)
outPrefix.replace("/","\\");
imageFileName.replace("/","\\");
CoordinatesFile.replace("/","\\");
#endif
mxArray * cols = mxCreateDoubleScalar(pluginIO->rawWidth);
mxArray * rows = mxCreateDoubleScalar(pluginIO->rawHeight);
mxArray * phase = mxCreateDoubleScalar(pluginIO->rawColorPattern);
mxArray * dcsub = mxCreateDoubleScalar(0);
mxArray * R = NULL;
mxArray * infilename = mxCreateString(imageFileName.toStdString().c_str());
mxArray * rotate = mxCreateDoubleScalar(0);
mxArray * figurePref = mxCreateString(outPrefix.toStdString().c_str());
mxArray * filename_coords = mxCreateString(CoordinatesFile.toStdString().c_str());
QFile::remove(pluginIO
->fileNames
[0]);
QFile::remove(pluginIO
->fileNames
[1]);
pluginIO->fileNames[0] = "";
pluginIO->fileNames[1] = "";
FILE* coordinates = fopen(CoordinatesFile.toStdString().c_str(),"w");
if (coordinates != NULL){
fprintf(coordinates,"%d, %d, %d, %d\r\n",pluginIO->selectedRect.topLeft().x(), pluginIO->selectedRect.bottomRight().x(),pluginIO->selectedRect.topLeft().y(), pluginIO->selectedRect.bottomRight().y());
fclose(coordinates);
if (imageFileName.endsWith(".raw",Qt::CaseInsensitive)|| imageFileName.endsWith(".rawle",Qt::CaseInsensitive)){
mlfRawmtfse(1, &R, infilename, cols, rows, phase, dcsub, figurePref, filename_coords);
} else
if (imageFileName.endsWith(".jpg",Qt::CaseInsensitive)|| imageFileName.endsWith(".bmp",Qt::CaseInsensitive)||imageFileName.endsWith(".jpeg",Qt::CaseInsensitive)){
mlfImgmtfse(1, &R, infilename, rotate, figurePref, filename_coords);
} else {
QMessageBox::critical(0,
"Error", tr
("Improper image type selected! \nAcceptable file extensions are: \n *.jpg, *.bmp, *.raw, *.rawLE") );
goto end;//-->
}
if (R == NULL){
QString parameters
= "\nFile = " + QString(mxArrayToString
(infilename
));
parameters
+= " \nfigurePref = " + QString(mxArrayToString
(figurePref
));
parameters
+= " \nfilename_coords = " + QString(mxArrayToString
(filename_coords
));
parameters
+= " \ncols = " + QString::number(* mxGetPr
(cols
));
parameters
+= " \nrows = " + QString::number(* mxGetPr
(rows
));
parameters
+= " \nphase = " + QString::number(* mxGetPr
(phase
));
parameters
+= " \ndcsub = " + QString::number(* mxGetPr
(dcsub
));
QFile coordinates_txt
(CoordinatesFile
);
QString coords
(coordinates_txt.
readAll());
coordinates_txt.close();
parameters += "\nRect: "+ coords;
QMessageBox::critical(0,
"Error", tr
("MatLab returned error!") + parameters
);
}else
if (* mxGetPr(R) != -1){
pluginIO->fileNames[0] = outPrefix+"figure_1.jpeg";
pluginIO->fileNames[1] = outPrefix+"figure_2.jpeg";
mxDestroyArray(R);
}
else if (* mxGetPr(R) == -1){
QMessageBox::critical(0,
"Error", tr
("Cannot evaluate function! \nPlease try selecting another area!"));
}
else QMessageBox::critical(0,
"Error", tr
("Unrecognized error!"));
} else {
QMessageBox::critical(0,
"Error",tr
("Error creating coordinates file: ") + CoordinatesFile
);
}
end:
mxDestroyArray(infilename);
mxDestroyArray(rotate);
mxDestroyArray(figurePref);
mxDestroyArray(filename_coords);
}
extern "C"
{
MTFSHARED_EXPORT int init(PluginAnalysisIO * IO){
chart = new Chart(IO);
return 0;
}
MTFSHARED_EXPORT void show(){
chart->showChart();
}
}
int DefaultPrintHandler(const char *s)
{
return strlen(s);//->
return mclWrite(1 /* stdout */, s, sizeof(char)*strlen(s));
}
int DefaultErrorHandler(const char *s)
{
int written = 0;
size_t len = 0;
len = strlen(s);
return len;//->
written = mclWrite(2 /* stderr */, s, sizeof(char)*len);
if (len > 0 && s[ len-1 ] != '\n')
written += mclWrite(2 /* stderr */, "\n", sizeof(char));
return written;
}
#include "MTF.h"
int MaxX = 255;
Chart * chart;
Chart::Chart(PluginAnalysisIO * IO): QObject(IO)
{
pluginIO = IO;
// return;
//QWidget * parentWidget = pluginIO->outputWidgets[0];
// QVBoxLayout *layout1 = new QVBoxLayout(parentWidget);
// layout1->addWidget(plot);
// QGridLayout * grid = new QGridLayout(parentWidget);
// layout1->addLayout(grid);
// if(!LibTI_MTFInitializeWithHandlers(DefaultErrorHandler, DefaultPrintHandler)) {
if(!LibTI_MTFInitialize()){
//mclTerminateApplication();
QMessageBox::critical(0,"Error", "Error initializing Matlab engine!\nPlease try to restart application.");
//return 2;
} else{
//return 0;
}
}
int main(int a,char** ){ return 0;}
Chart::~Chart(){
LibTI_MTFTerminate();
}
void Chart::showChart(){
QString imageFileName = pluginIO->imageFileName.toLower();
QDir tempDir(QDir::tempPath());
// QString tempPath = tempDir.canonicalPath();
QString tempPath = tempDir.absolutePath();
QString outPrefix = tempPath+"/MTF_Images_";
QString CoordinatesFile = outPrefix + "coordinates.txt";
#if defined(Q_OS_WIN)
outPrefix.replace("/","\\");
imageFileName.replace("/","\\");
CoordinatesFile.replace("/","\\");
#endif
mxArray * cols = mxCreateDoubleScalar(pluginIO->rawWidth);
mxArray * rows = mxCreateDoubleScalar(pluginIO->rawHeight);
mxArray * phase = mxCreateDoubleScalar(pluginIO->rawColorPattern);
mxArray * dcsub = mxCreateDoubleScalar(0);
mxArray * R = NULL;
mxArray * infilename = mxCreateString(imageFileName.toStdString().c_str());
mxArray * rotate = mxCreateDoubleScalar(0);
mxArray * figurePref = mxCreateString(outPrefix.toStdString().c_str());
mxArray * filename_coords = mxCreateString(CoordinatesFile.toStdString().c_str());
QFile::remove(pluginIO->fileNames[0]);
QFile::remove(pluginIO->fileNames[1]);
pluginIO->fileNames[0] = "";
pluginIO->fileNames[1] = "";
FILE* coordinates = fopen(CoordinatesFile.toStdString().c_str(),"w");
if (coordinates != NULL){
fprintf(coordinates,"%d, %d, %d, %d\r\n",pluginIO->selectedRect.topLeft().x(), pluginIO->selectedRect.bottomRight().x(),pluginIO->selectedRect.topLeft().y(), pluginIO->selectedRect.bottomRight().y());
fclose(coordinates);
if (imageFileName.endsWith(".raw",Qt::CaseInsensitive)|| imageFileName.endsWith(".rawle",Qt::CaseInsensitive)){
mlfRawmtfse(1, &R, infilename, cols, rows, phase, dcsub, figurePref, filename_coords);
} else
if (imageFileName.endsWith(".jpg",Qt::CaseInsensitive)|| imageFileName.endsWith(".bmp",Qt::CaseInsensitive)||imageFileName.endsWith(".jpeg",Qt::CaseInsensitive)){
mlfImgmtfse(1, &R, infilename, rotate, figurePref, filename_coords);
} else {
QMessageBox::critical(0,"Error", tr("Improper image type selected! \nAcceptable file extensions are: \n *.jpg, *.bmp, *.raw, *.rawLE") );
goto end;//-->
}
if (R == NULL){
QString parameters = "\nFile = " + QString(mxArrayToString(infilename));
parameters += " \nfigurePref = " + QString(mxArrayToString(figurePref));
parameters += " \nfilename_coords = " + QString(mxArrayToString(filename_coords));
parameters += " \ncols = " + QString::number(* mxGetPr(cols));
parameters += " \nrows = " + QString::number(* mxGetPr(rows));
parameters += " \nphase = " + QString::number(* mxGetPr(phase));
parameters += " \ndcsub = " + QString::number(* mxGetPr(dcsub));
QFile coordinates_txt(CoordinatesFile);
coordinates_txt.open(QIODevice::ReadOnly);
QString coords(coordinates_txt.readAll());
coordinates_txt.close();
parameters += "\nRect: "+ coords;
QMessageBox::critical(0,"Error", tr("MatLab returned error!") + parameters);
}else
if (* mxGetPr(R) != -1){
pluginIO->fileNames[0] = outPrefix+"figure_1.jpeg";
pluginIO->fileNames[1] = outPrefix+"figure_2.jpeg";
mxDestroyArray(R);
}
else if (* mxGetPr(R) == -1){
QMessageBox::critical(0,"Error", tr("Cannot evaluate function! \nPlease try selecting another area!"));
}
else QMessageBox::critical(0,"Error", tr("Unrecognized error!"));
} else {
QMessageBox::critical(0,"Error",tr("Error creating coordinates file: ") + CoordinatesFile);
}
end:
mxDestroyArray(infilename);
mxDestroyArray(rotate);
mxDestroyArray(figurePref);
mxDestroyArray(filename_coords);
}
extern "C"
{
MTFSHARED_EXPORT int init(PluginAnalysisIO * IO){
chart = new Chart(IO);
return 0;
}
MTFSHARED_EXPORT void show(){
chart->showChart();
}
}
int DefaultPrintHandler(const char *s)
{
return strlen(s);//->
return mclWrite(1 /* stdout */, s, sizeof(char)*strlen(s));
}
int DefaultErrorHandler(const char *s)
{
int written = 0;
size_t len = 0;
len = strlen(s);
return len;//->
written = mclWrite(2 /* stderr */, s, sizeof(char)*len);
if (len > 0 && s[ len-1 ] != '\n')
written += mclWrite(2 /* stderr */, "\n", sizeof(char));
return written;
}
To copy to clipboard, switch view to plain text mode
Bookmarks