@@ -44,6 +44,7 @@ PURPOSE. See the above copyright notices for more information.
4444#include < chrono>
4545#include < sys/stat.h>
4646#include " CemrgCommandLine.h"
47+ #include " CemrgCommonUtils.h"
4748
4849CemrgCommandLine::CemrgCommandLine () {
4950
@@ -92,32 +93,22 @@ QDialog* CemrgCommandLine::GetDialog() {
9293 ****************** Execute Plugin Specific Functions **********************
9394 ***************************************************************************/
9495
95- QString CemrgCommandLine::ExecuteSurf (QString dir, QString segPath, QString morphOperation, int iter, float th, int blur, int smth) {
96-
97- MITK_INFO << " [ATTENTION] SURFACE CREATION: Close -> Surface -> Smooth" ;
98-
99- QString closeOutputPath, surfOutputPath;
100- QString outAbsolutePath = " ERROR_IN_PROCESSING" ;
101- closeOutputPath = ExecuteMorphologicalOperation (morphOperation, dir, segPath, " segmentation.s.nii" , iter);
96+ QString CemrgCommandLine::ExecuteSurf (QString dir, QString segPath, float thresh, int blur, int smooth) {
97+ MITK_INFO << " [ATTENTION] SURFACE CREATION: Surface -> Smooth" ;
10298
99+ // Load input image into memory
100+ QString inputPath = segPath.contains (dir) ? segPath : dir + " /" + segPath;
103101 mitk::ProgressBar::GetInstance ()->Progress ();
104- if (QString::compare (closeOutputPath, " ERROR_IN_PROCESSING" )!=0 ) {
105-
106- surfOutputPath = ExecuteExtractSurface (dir, closeOutputPath, " segmentation.vtk" , th, blur);
107- mitk::ProgressBar::GetInstance ()->Progress ();
102+ mitk::Image::Pointer inputImage = mitk::IOUtil::Load<mitk::Image>(inputPath.toStdString ());
108103
109- if (QString::compare (surfOutputPath, " ERROR_IN_PROCESSING" )!=0 ) {
104+ // TODO: check semantics of thresh/blur/smooth are identical
105+ mitk::Surface::Pointer smoothedSurface = CemrgCommonUtils::ExtractSurfaceFromSegmentation (inputImage, (double )thresh, (double )blur, (double )smooth);
106+ CemrgCommonUtils::FlipXYPlane (smoothedSurface, " " , " " );
110107
111- outAbsolutePath = ExecuteSmoothSurface (dir, surfOutputPath, surfOutputPath, smth);
112- remove ((dir + " /segmentation.s.nii" ).toStdString ().c_str ());
113- mitk::ProgressBar::GetInstance ()->Progress ();
114-
115- } else {
116- mitk::ProgressBar::GetInstance ()->Progress ();
117- }// _if
118- } else {
119- mitk::ProgressBar::GetInstance ()->Progress (2 );
120- }// _if
108+ // Calling code expects a QString of the file path as return value, not the Surface pointer itself.
109+ QString outAbsolutePath = dir + " /segmentation.vtk" ;
110+ mitk::IOUtil::Save (smoothedSurface, outAbsolutePath.toStdString ());
111+ mitk::ProgressBar::GetInstance ()->Progress (2 );
121112
122113 return outAbsolutePath;
123114}
@@ -364,151 +355,6 @@ void CemrgCommandLine::ExecuteSimpleTranslation(QString dir, QString sourceMeshP
364355 ****************** Execute MIRTK Specific Functions **********************
365356 ***************************************************************************/
366357
367- QString CemrgCommandLine::ExecuteMorphologicalOperation (QString operation, QString dir, QString segPath, QString outputPath, int iter) {
368-
369- MITK_INFO << " [ATTENTION] Attempting Pointset transformation." ;
370-
371- QString commandName;
372-
373- if (QString::compare (operation, " dilate" , Qt::CaseInsensitive)==0 ) {
374- commandName = " dilate-image" ;
375- } else if (QString::compare (operation, " erode" , Qt::CaseInsensitive)==0 ) {
376- commandName = " erode-image" ;
377- } else if (QString::compare (operation, " open" , Qt::CaseInsensitive)==0 ) {
378- commandName = " open-image" ;
379- } else if (QString::compare (operation, " close" , Qt::CaseInsensitive)==0 ) {
380- commandName = " close-image" ;
381- } else {
382- MITK_ERROR << (" Morphological operation: " + operation + " misspelled or not supported." ).toStdString ();
383- return " ERROR_IN_PROCESSING" ;
384- }
385-
386- QString inputImgFullPath, outAbsolutePath;
387- QString prodPath = dir + " /" ;
388-
389- inputImgFullPath = segPath.contains (dir, Qt::CaseSensitive) ? segPath : prodPath + segPath;
390- outAbsolutePath = outputPath.contains (dir, Qt::CaseSensitive) ? outputPath : prodPath + outputPath;
391-
392- MITK_INFO << (" [...] OPERATION: " + operation).toStdString ();
393- MITK_INFO << (" [...] INPUT IMAGE: " + inputImgFullPath).toStdString ();
394- MITK_INFO << (" [...] OUTPUT IMAGE: " + outAbsolutePath).toStdString ();
395-
396- MITK_INFO << " Using static MIRTK libraries." ;
397- QString executablePath = QCoreApplication::applicationDirPath () + " /MLib" ;
398- QString executableName = executablePath + " /" + commandName;
399- QDir apathd (executablePath);
400- QStringList arguments;
401-
402- if (apathd.exists ()) {
403-
404- process->setWorkingDirectory (executablePath);
405- arguments << inputImgFullPath;
406- arguments << outAbsolutePath;
407- arguments << " -iterations" << QString::number (iter);
408-
409- } else {
410- QMessageBox::warning (NULL , " Please check the LOG" , " MIRTK libraries not found" );
411- MITK_WARN << " MIRTK libraries not found. Please make sure the MLib folder is inside the directory;\n\t " +
412- mitk::IOUtil::GetProgramPath ();
413- }// _if
414-
415- bool successful = ExecuteCommand (executableName, arguments, outAbsolutePath);
416- if (!successful) {
417- MITK_WARN << " Local MIRTK libraries did not produce a good outcome." ;
418- return " ERROR_IN_PROCESSING" ;
419- } else {
420- return outAbsolutePath;
421- }
422- }
423-
424- QString CemrgCommandLine::ExecuteExtractSurface (QString dir, QString segPath, QString outputPath,float th, int blur) {
425-
426- MITK_INFO << " [ATTENTION] Attempting Surface extraction." ;
427-
428- QString commandName = " extract-surface" ;
429- QString inputImgFullPath, outAbsolutePath;
430- QString prodPath = dir + " /" ;
431-
432- inputImgFullPath = segPath.contains (dir, Qt::CaseSensitive) ? segPath : prodPath + segPath;
433- outAbsolutePath = outputPath.contains (dir, Qt::CaseSensitive) ? outputPath : prodPath + outputPath;
434-
435- MITK_INFO << (" [...] INPUT IMAGE: " + inputImgFullPath).toStdString ();
436- MITK_INFO << (" [...] OUTPUT MESH: " + outAbsolutePath).toStdString ();
437-
438- MITK_INFO << " Using static MIRTK libraries." ;
439- QString executablePath = QCoreApplication::applicationDirPath () + " /MLib" ;
440- QString executableName = executablePath + " /" + commandName;
441- QDir apathd (executablePath);
442- QStringList arguments;
443-
444- if (apathd.exists ()) {
445-
446- process->setWorkingDirectory (executablePath);
447- arguments << inputImgFullPath;
448- arguments << outAbsolutePath;
449- arguments << " -isovalue" << QString::number (th);
450- arguments << " -blur" << QString::number (blur);
451- arguments << " -ascii" ;
452- arguments << " -verbose" << " 3" ;
453-
454- } else {
455- QMessageBox::warning (NULL , " Please check the LOG" , " MIRTK libraries not found" );
456- MITK_WARN << " MIRTK libraries not found. Please make sure the MLib folder is inside the directory;\n\t " +
457- mitk::IOUtil::GetProgramPath ();
458- }// _if
459-
460- bool successful = ExecuteCommand (executableName, arguments, outAbsolutePath);
461- if (!successful) {
462- MITK_WARN << " Local MIRTK libraries did not produce a good outcome." ;
463- return " ERROR_IN_PROCESSING" ;
464- } else {
465- return outAbsolutePath;
466- }
467- }
468-
469- QString CemrgCommandLine::ExecuteSmoothSurface (QString dir, QString segPath, QString outputPath, int smth) {
470-
471- MITK_INFO << " [ATTENTION] Attempting Surface extraction." ;
472-
473- QString commandName = " smooth-surface" ;
474- QString inputMeshFullPath, outAbsolutePath;
475- QString prodPath = dir + " /" ;
476-
477- inputMeshFullPath = segPath.contains (dir, Qt::CaseSensitive) ? segPath : prodPath + segPath;
478- outAbsolutePath = outputPath.contains (dir, Qt::CaseSensitive) ? outputPath : prodPath + outputPath;
479-
480- MITK_INFO << (" [...] INPUT IMAGE: " + inputMeshFullPath).toStdString ();
481- MITK_INFO << (" [...] OUTPUT MESH: " + outAbsolutePath).toStdString ();
482-
483- MITK_INFO << " Using static MIRTK libraries." ;
484- QString executablePath = QCoreApplication::applicationDirPath () + " /MLib" ;
485- QString executableName = executablePath + " /" + commandName;
486- QDir apathd (executablePath);
487- QStringList arguments;
488-
489- if (apathd.exists ()) {
490-
491- process->setWorkingDirectory (executablePath);
492- arguments << inputMeshFullPath;
493- arguments << outAbsolutePath;
494- arguments << " -iterations" << QString::number (smth);
495- arguments << " -verbose" << " 3" ;
496-
497- } else {
498- QMessageBox::warning (NULL , " Please check the LOG" , " MIRTK libraries not found" );
499- MITK_WARN << " MIRTK libraries not found. Please make sure the MLib folder is inside the directory;\n\t " +
500- mitk::IOUtil::GetProgramPath ();
501- }// _if
502-
503- bool successful = ExecuteCommand (executableName, arguments, outAbsolutePath);
504- if (!successful) {
505- MITK_WARN << " Local MIRTK libraries did not produce a good outcome." ;
506- return " ERROR_IN_PROCESSING" ;
507- } else {
508- return outAbsolutePath;
509- }
510- }
511-
512358void CemrgCommandLine::ExecuteTransformationOnPoints (QString dir, QString meshFullPath, QString outputMeshFullPath, QString transformFileFullPath, double applyingIniTime) {
513359
514360 MITK_INFO << " [ATTENTION] Attempting Pointset transformation." ;
0 commit comments