Skip to content

Commit 2d54320

Browse files
committed
add ExecuteSurf variant that returns surface immediately
Skip round trip to disk for simplicity and performance.
1 parent dcef980 commit 2d54320

4 files changed

Lines changed: 18 additions & 15 deletions

File tree

CemrgApp/Modules/CemrgAppModule/include/CemrgCommandLine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ PURPOSE. See the above copyright notices for more information.
2929
#ifndef CemrgCommandLine_h
3030
#define CemrgCommandLine_h
3131

32+
#include <mitkSurface.h>
33+
3234
// Qt
3335
#include <memory>
3436
#include <QProcess>
@@ -50,6 +52,7 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgCommandLine: public QObject {
5052

5153
//Execute Plugin Specific Functions
5254
QString ExecuteSurf(QString dir, QString segPath, float th = 0.5, int blur = 0, int smth = 10);
55+
mitk::Surface::Pointer ExecuteSurf_new(QString dir, QString segPath, float th = 0.5, int blur = 0, int smth = 10);
5356
QString ExecuteCreateCGALMesh(QString dir, QString outputName, QString paramsFullPath, QString segmentationName = "converted.inr");
5457
void ExecuteTracking(QString dir, QString imgTimes, QString param, QString output = "tsffd.dof");
5558
void ExecuteApplying(QString dir, QString inputMesh, double iniTime, QString dofin, int noFrames, int smooth);

CemrgApp/Modules/CemrgAppModule/src/CemrgCommandLine.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ QDialog* CemrgCommandLine::GetDialog() {
9494
***************************************************************************/
9595

9696
QString CemrgCommandLine::ExecuteSurf(QString dir, QString segPath, float thresh, int blur, int smooth) {
97+
// Calling code expects a QString of the file path as return value, not the Surface pointer itself.
98+
mitk::Surface::Pointer surface = CemrgCommandLine::ExecuteSurf_new(dir, segPath, thresh, blur, smooth);
99+
QString outAbsolutePath = dir + "/segmentation.vtk";
100+
mitk::IOUtil::Save(surface, outAbsolutePath.toStdString());
101+
return outAbsolutePath;
102+
}
103+
104+
mitk::Surface::Pointer CemrgCommandLine::ExecuteSurf_new(QString dir, QString segPath, float thresh, int blur, int smooth) {
97105
MITK_INFO << "[ATTENTION] SURFACE CREATION: Surface -> Smooth";
98106

99107
// Load input image into memory
@@ -105,12 +113,8 @@ QString CemrgCommandLine::ExecuteSurf(QString dir, QString segPath, float thresh
105113
mitk::Surface::Pointer smoothedSurface = CemrgCommonUtils::ExtractSurfaceFromSegmentation(inputImage, (double)thresh, (double)blur, (double)smooth);
106114
CemrgCommonUtils::FlipXYPlane(smoothedSurface, "", "");
107115

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());
111116
mitk::ProgressBar::GetInstance()->Progress(2);
112-
113-
return outAbsolutePath;
117+
return smoothedSurface;
114118
}
115119

116120
QString CemrgCommandLine::ExecuteCreateCGALMesh(QString dir, QString outputName, QString paramsFullPath, QString segmentationName) {

CemrgApp/Plugins/kcl.cemrgapp.scar/src/internal/AtrialScarClipperView.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,11 @@ void AtrialScarClipperView::iniPreSurf() {
209209
mitk::IOUtil::Save(image, path.toStdString());
210210
mitk::ProgressBar::GetInstance()->AddStepsToDo(3);
211211
std::unique_ptr<CemrgCommandLine> cmd(new CemrgCommandLine());
212-
QString output = cmd->ExecuteSurf(directory, path, th, blur, smth);
212+
mitk::Surface::Pointer shell = cmd->ExecuteSurf_new(directory, path, th, blur, smth);
213213
QMessageBox::information(NULL, "Attention", "Command Line Operations Finished!");
214214
this->BusyCursorOff();
215215

216216
//Decimate the mesh to visualise
217-
mitk::Surface::Pointer shell = mitk::IOUtil::Load<mitk::Surface>(output.toStdString());
218217
vtkSmartPointer<vtkDecimatePro> deci = vtkSmartPointer<vtkDecimatePro>::New();
219218
deci->SetInputData(shell->GetVtkPolyData());
220219
deci->SetTargetReduction(ds);

CemrgApp/Plugins/kcl.cemrgapp.scar/src/internal/AtrialScarView.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,7 @@ void AtrialScarView::AutomaticAnalysis() {
540540
MITK_INFO << ("[...][3.1] Saved file: " + segCleanPath).toStdString();
541541

542542
MITK_INFO << "[AUTOMATIC_ANALYSIS][4] Vein clipping mesh";
543-
QString output1 = cmd->ExecuteSurf(direct, segCleanPath, .5, 0, 10);
544-
mitk::Surface::Pointer shell = mitk::IOUtil::Load<mitk::Surface>(output1.toStdString());
543+
mitk::Surface::Pointer shell = cmd->ExecuteSurf_new(direct, segCleanPath, .5, 0, 10);
545544
vtkSmartPointer<vtkDecimatePro> deci = vtkSmartPointer<vtkDecimatePro>::New();
546545
deci->SetInputData(shell->GetVtkPolyData());
547546
deci->SetTargetReduction(0.1);
@@ -662,8 +661,7 @@ void AtrialScarView::AutomaticAnalysis() {
662661
MITK_INFO << "[...][7.3] ClipVeinsImage finished .";
663662

664663
MITK_INFO << "[AUTOMATIC_ANALYSIS][8] Create a mesh from clipped segmentation of veins";
665-
QString output2 = cmd->ExecuteSurf(direct, (direct + "/PVeinsCroppedImage.nii"), .5, 0, 10);
666-
mitk::Surface::Pointer LAShell = mitk::IOUtil::Load<mitk::Surface>(output2.toStdString());
664+
mitk::Surface::Pointer LAShell = cmd->ExecuteSurf_new(direct, "PVeinsCroppedImage.nii", .5, 0, 10);
667665

668666
MITK_INFO << "[AUTOMATIC_ANALYSIS][9] Clip the mitral valve";
669667
ImageTypeCHAR::Pointer mvImage = ImageTypeCHAR::New();
@@ -693,9 +691,8 @@ void AtrialScarView::AutomaticAnalysis() {
693691
mitk::IOUtil::Save(mitk::ImportItkImage(mvImage), (direct + "/prodMVI.nii").toStdString());
694692

695693
// Make vtk of prodMVI
696-
QString mviShellPath = cmd->ExecuteSurf(direct, "prodMVI.nii", 0.5, 0, 10);
694+
mitk::Surface::Pointer ClipperSurface = cmd->ExecuteSurf_new(direct, "prodMVI.nii", 0.5, 0, 10);
697695
// Implement code from command line tool
698-
mitk::Surface::Pointer ClipperSurface = mitk::IOUtil::Load<mitk::Surface>(mviShellPath.toStdString());
699696
vtkSmartPointer<vtkImplicitPolyDataDistance> implicitFn = vtkSmartPointer<vtkImplicitPolyDataDistance>::New();
700697
implicitFn->SetInput(ClipperSurface->GetVtkPolyData());
701698
vtkMTimeType mtime = implicitFn->GetMTime();
@@ -725,9 +722,9 @@ void AtrialScarView::AutomaticAnalysis() {
725722
clean->SetInputConnection(lrgRegion->GetOutputPort());
726723
clean->Update();
727724

728-
MITK_INFO << ("[...][9.4] Saving to file: " + output2).toStdString();
725+
MITK_INFO << ("[...][9.4] Saving to file: " + direct + "/segmentation.vtk").toStdString();
729726
LAShell->SetVtkPolyData(clean->GetOutput());
730-
mitk::IOUtil::Save(LAShell, output2.toStdString());
727+
mitk::IOUtil::Save(LAShell, (direct + "/segmentation.vtk").toStdString());
731728

732729
MITK_INFO << "[AUTOMATIC_ANALYSIS][10] Scar projection";
733730
int minStep = minStep_UI;

0 commit comments

Comments
 (0)