Skip to content

Commit 5b4fb6d

Browse files
authored
Merge 4fc803f into 75afd96
2 parents 75afd96 + 4fc803f commit 5b4fb6d

13 files changed

Lines changed: 68 additions & 266 deletions

File tree

CemrgApp/Modules/CemrgAppModule/include/CemrgCommandLine.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgCommandLine: public QObject {
4949
QDialog* GetDialog();
5050

5151
//Execute Plugin Specific Functions
52-
QString ExecuteSurf(QString dir, QString segPath, QString morphOperation = "close", int iter = 1, float th = 0.5, int blur = 0, int smth = 10);
52+
QString ExecuteSurf(QString dir, QString segPath, float th = 0.5, int blur = 0, int smth = 10);
5353
QString ExecuteCreateCGALMesh(QString dir, QString outputName, QString paramsFullPath, QString segmentationName = "converted.inr");
5454
void ExecuteTracking(QString dir, QString imgTimes, QString param, QString output = "tsffd.dof");
5555
void ExecuteApplying(QString dir, QString inputMesh, double iniTime, QString dofin, int noFrames, int smooth);
@@ -58,9 +58,6 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgCommandLine: public QObject {
5858
void ExecuteSimpleTranslation(QString dir, QString sourceMeshP, QString targetMeshP, QString transformFileName = "init.dof", bool transformThePoints = true);
5959

6060
//Execute MIRTK Specific Functions
61-
QString ExecuteMorphologicalOperation(QString operation, QString dir, QString segPath, QString outputPath = "segmentation.s.nii", int iter = 1);
62-
QString ExecuteExtractSurface(QString dir, QString segPath, QString outputPath = "segmentation.vtk", float th = 0.5, int blur = 0);
63-
QString ExecuteSmoothSurface(QString dir, QString segPath, QString outputPath, int smth = 10);
6461
void ExecuteTransformationOnPoints(QString dir, QString meshFullPath, QString outputMeshFullPath, QString transformFileFullPath, double applyingIniTime = -100);
6562
void ExecuteResamplingOnNifti(QString niiFullPath, QString outputNiiFullPath, int isovalue);
6663

CemrgApp/Modules/CemrgAppModule/include/CemrgCommonUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgCommonUtils {
7171

7272
//Mesh Utils
7373
static mitk::Surface::Pointer LoadVTKMesh(std::string path);
74-
static mitk::Surface::Pointer ExtractSurfaceFromSegmentation(mitk::Image::Pointer image, double thresh=0.5, double blur=0.8, double smoothIterations=3, double decimation=0.5);
74+
static mitk::Surface::Pointer ExtractSurfaceFromSegmentation(mitk::Image::Pointer image, double thresh=0.5, double blur=0.8, double smoothIterations=3, double decimation=0.0);
7575
static mitk::Surface::Pointer ClipWithSphere(mitk::Surface::Pointer surface, double x_c, double y_c, double z_c, double radius, QString saveToPath="");
7676
static void FlipXYPlane(mitk::Surface::Pointer surf, QString dir, QString vtkname="segmentation.vtk");
7777
static QString M3dlibParamFileGenerator(QString dir, QString filename="param-template.par", QString thicknessCalc="0");

CemrgApp/Modules/CemrgAppModule/src/CemrgCommandLine.cpp

Lines changed: 13 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -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

4849
CemrgCommandLine::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-
512358
void CemrgCommandLine::ExecuteTransformationOnPoints(QString dir, QString meshFullPath, QString outputMeshFullPath, QString transformFileFullPath, double applyingIniTime) {
513359

514360
MITK_INFO << "[ATTENTION] Attempting Pointset transformation.";

CemrgApp/Modules/CemrgAppModule/test/CemrgCommandLineTest.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,14 @@ void TestCemrgCommandLine::cleanupTestCase() {
123123

124124
void TestCemrgCommandLine::ExecuteSurf_data() {
125125
QTest::addColumn<QString>("segPath");
126-
QTest::addColumn<QString>("morphOperation");
127-
QTest::addColumn<int>("iterations");
128126
QTest::addColumn<float>("threshold");
129127
QTest::addColumn<int>("blur");
130128
QTest::addColumn<int>("smoothness");
131129
QTest::addColumn<QString>("result");
132130

133-
const array<tuple<QString, QString, int, float, int, int, QString>, 3> surfData { {
134-
{"sphere_initial.nii", "close", 1, 0.5, 0, 10, "/surf_expected_1.vtk"},
135-
{"sphere_shifted.nii", "dilate", 1, 0.5, 0, 10, "/surf_expected_2.vtk"},
136-
{"sphere_initial.nii", "erode", 1, 0.5, 0, 10, "/surf_expected_3.vtk"}
131+
const array<tuple<QString, QString, int, float, int, int, QString>, 2> surfData { {
132+
{"sphere_initial.nii", 0.5, 0, 10, "/surf_expected_1.vtk"},
133+
{"sphere_shifted.nii", 0.5, 0, 10, "/surf_expected_2.vtk"},
137134
} };
138135

139136
for (size_t i = 0; i < surfData.size(); i++)
@@ -142,14 +139,12 @@ void TestCemrgCommandLine::ExecuteSurf_data() {
142139

143140
void TestCemrgCommandLine::ExecuteSurf() {
144141
QFETCH(QString, segPath);
145-
QFETCH(QString, morphOperation);
146-
QFETCH(int, iterations);
147142
QFETCH(float, threshold);
148143
QFETCH(int, blur);
149144
QFETCH(int, smoothness);
150145
QFETCH(QString, result);
151146

152-
QString surfOutput = cemrgCommandLine->ExecuteSurf(dataPath, segPath, morphOperation, iterations, threshold, blur, smoothness);
147+
QString surfOutput = cemrgCommandLine->ExecuteSurf(dataPath, segPath, threshold, blur, smoothness);
153148
QVERIFY2(EqualFiles(surfOutput, dataPath + result), "The function output is different from the expected output!");
154149
}
155150

Binary file not shown.

CemrgApp/Plugins/kcl.cemrgapp.atrialfibres/src/internal/AtrialFibresView.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ void AtrialFibresView::AutomaticAnalysis(){
472472
std::unique_ptr<CemrgCommandLine> cmd(new CemrgCommandLine());
473473
cmd->SetUseDockerContainers(true);
474474

475-
cmd->ExecuteSurf(directory, Path("prodClean.nii"), "close", uiMesh_iter, uiMesh_th, uiMesh_bl, uiMesh_smth);
475+
cmd->ExecuteSurf(directory, Path("prodClean.nii"), uiMesh_th, uiMesh_bl, uiMesh_smth);
476476
atrium->ProjectTagsOnExistingSurface(tagAtriumAuto, directory, tagName+".vtk");
477477

478478
MITK_INFO << "[AUTOMATIC_PIPELINE] Add the mesh to storage";
@@ -673,7 +673,7 @@ void AtrialFibresView::IdentifyPV(){
673673
std::unique_ptr<CemrgCommandLine> cmd(new CemrgCommandLine());
674674
cmd->SetUseDockerContainers(true);
675675

676-
cmd->ExecuteSurf(directory, Path("prodClean.nii"), "close", uiMesh_iter, uiMesh_th, uiMesh_bl, uiMesh_smth);
676+
cmd->ExecuteSurf(directory, Path("prodClean.nii"), uiMesh_th, uiMesh_bl, uiMesh_smth);
677677

678678
//Add the mesh to storage
679679
std::string meshName = segNode->GetName() + "-Mesh";
@@ -728,7 +728,7 @@ void AtrialFibresView::CreateLabelledMesh(){
728728
std::unique_ptr<CemrgCommandLine> cmd(new CemrgCommandLine());
729729
cmd->SetUseDockerContainers(true);
730730

731-
cmd->ExecuteSurf(directory, Path("prodClean.nii"), "close", uiMesh_iter, uiMesh_th, uiMesh_bl, uiMesh_smth);
731+
cmd->ExecuteSurf(directory, Path("prodClean.nii"), uiMesh_th, uiMesh_bl, uiMesh_smth);
732732
atrium->ProjectTagsOnExistingSurface(pveins, directory, tagName+".vtk");
733733

734734
MITK_INFO << "Add the mesh to storage";
@@ -1996,7 +1996,6 @@ bool AtrialFibresView::GetUserMeshingInputs(){
19961996

19971997
if(userHasSetMeshingParams){
19981998
QString msg = "The parameters have been set already, change them?\n";
1999-
msg += "close iter= " + QString::number(uiMesh_iter) + '\n';
20001999
msg += "threshold= " + QString::number(uiMesh_th) + '\n';
20012000
msg += "blur= " + QString::number(uiMesh_bl) + '\n';
20022001
msg += "smooth iter= " + QString::number(uiMesh_smth);
@@ -2017,19 +2016,17 @@ bool AtrialFibresView::GetUserMeshingInputs(){
20172016
//Act on dialog return code
20182017
if (dialogCode == QDialog::Accepted) {
20192018

2020-
bool ok1, ok2, ok3, ok4;
2019+
bool ok1, ok2, ok3;
20212020
uiMesh_th= m_UIMeshing.lineEdit_1->text().toDouble(&ok1);
20222021
uiMesh_bl= m_UIMeshing.lineEdit_2->text().toDouble(&ok2);
20232022
uiMesh_smth= m_UIMeshing.lineEdit_3->text().toDouble(&ok3);
2024-
uiMesh_iter= m_UIMeshing.lineEdit_4->text().toDouble(&ok4);
20252023

20262024
//Set default values
2027-
if (!ok1 || !ok2 || !ok3 || !ok4)
2025+
if (!ok1 || !ok2 || !ok3)
20282026
QMessageBox::warning(NULL, "Attention", "Reverting to default parameters!");
20292027
if (!ok1) uiMesh_th=0.5;
20302028
if (!ok2) uiMesh_bl=0.0;
20312029
if (!ok3) uiMesh_smth=10;
2032-
if (!ok4) uiMesh_iter=0;
20332030

20342031
inputs->deleteLater();
20352032
userInputAccepted=true;

CemrgApp/Plugins/kcl.cemrgapp.atrialfibres/src/internal/AtrialFibresView.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ protected slots:
173173
bool automaticPipeline, analysisOnLge, resurfaceMesh, userHasSetMeshingParams;
174174

175175
// user-defined parameters
176-
double uiMesh_th, uiMesh_bl, uiMesh_smth, uiMesh_iter;
176+
double uiMesh_th, uiMesh_bl, uiMesh_smth;
177177
double uiRemesh_max, uiRemesh_avrg, uiRemesh_min, uiRemesh_surfcorr;
178178
bool uiRemesh_isscalar, uiRemesh_extractParts, uiRemesh_cleanmesh;
179179
int uiScar_minStep, uiScar_maxStep, uiScar_projectionMethod, uiScar_thresholdMethod, uiFormat_scale;

CemrgApp/Plugins/kcl.cemrgapp.atrialfibres/src/internal/AtrialFibresViewUIMeshing.ui

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>222</width>
10-
<height>196</height>
10+
<height>160</height>
1111
</rect>
1212
</property>
1313
<property name="sizePolicy">
@@ -19,13 +19,13 @@
1919
<property name="minimumSize">
2020
<size>
2121
<width>0</width>
22-
<height>196</height>
22+
<height>160</height>
2323
</size>
2424
</property>
2525
<property name="maximumSize">
2626
<size>
2727
<width>16777215</width>
28-
<height>196</height>
28+
<height>160</height>
2929
</size>
3030
</property>
3131
<property name="windowTitle">
@@ -45,13 +45,6 @@
4545
</property>
4646
</widget>
4747
</item>
48-
<item>
49-
<widget class="QLineEdit" name="lineEdit_4">
50-
<property name="placeholderText">
51-
<string>'Close' iterations (default=0)</string>
52-
</property>
53-
</widget>
54-
</item>
5548
<item>
5649
<widget class="QLineEdit" name="lineEdit_1">
5750
<property name="placeholderText">

0 commit comments

Comments
 (0)