Skip to content

Commit

Permalink
connection_to_ccta
Browse files Browse the repository at this point in the history
  • Loading branch information
sagebei committed Aug 16, 2024
1 parent 32bb404 commit fdabe8c
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 20 deletions.
2 changes: 2 additions & 0 deletions CemrgApp/Modules/CemrgAppModule/include/CemrgCommandLine.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ class MITKCEMRGAPPMODULE_EXPORT CemrgCommandLine: public QObject {
std::string PrintFullCommand(QString command, QStringList arguments);
bool ExecuteCommand(QString executableName, QStringList arguments, QString outputPath, bool isOutputFile = true);

QString DockerCctaMultilabelSegmentation(QString dir, QString path_to_f, bool saveas_nifti);

protected slots:

void UpdateStdText();
Expand Down
29 changes: 29 additions & 0 deletions CemrgApp/Modules/CemrgAppModule/src/CemrgCommandLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1413,3 +1413,32 @@ void CemrgCommandLine::FinishedAlert() {
QString data = process->program() + " Completed!";
panel->append(data);
}

QString CemrgCommandLine::DockerCctaMultilabelSegmentation(QString dir, QString path_to_f, bool saveas_nifti) {
SetDockerImage("cemrg/ccta:latest");
QString executablePath = "";
#if defined(__APPLE__)
executablePath = "/usr/local/bin/";
#endif
QString executableName = executablePath + "docker";
QDir home(dir);
QFileInfo fi(path_to_f);
QString outname = fi.baseName();
outname += "_label_maps.nii.gz";
QStringList arguments = GetDockerArguments(home.absolutePath());
arguments << "--filename" << home.relativeFilePath(path_to_f);
arguments << "--device" << "cpu";
if (saveas_nifti) {
arguments << "--saveas-nifti";
}
QString outPath = home.absolutePath() + "/" + outname;
bool successful = ExecuteCommand(executableName, arguments, outPath);
QString res="";
if (successful) {
MITK_INFO << "Successful mutilabel segmentation";
res = outPath;
} else {
MITK_WARN << "Unsuccessful multilabel segmentation";
}
return res;
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,34 +41,95 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
=========================================================================*/


#include "kcl_cemrgapp_atrialstrainmotion_Activator.h"
#include "AtrialStrainMotionView.h"

// Blueberry
#include <berryISelectionService.h>
#include <berryIWorkbenchWindow.h>

// Qmitk
#include "kcl_cemrgapp_atrialstrainmotion_Activator.h"
#include "AtrialStrainMotionView.h"
//Micro services
#include <usModuleRegistry.h>
#ifdef _WIN32
// _WIN32 = we're in windows
#include <winsock2.h>
#else
// or linux/mac
#include <arpa/inet.h>
#endif

//VTK
#include <vtkFieldData.h>
#include <vtkCleanPolyData.h>
#include <vtkPolyDataNormals.h>
#include <vtkPolyDataConnectivityFilter.h>
#include <vtkWindowedSincPolyDataFilter.h>
#include <vtkImplicitPolyDataDistance.h>
#include <vtkBooleanOperationPolyDataFilter.h>
#include <vtkClipPolyData.h>
#include <vtkDecimatePro.h>

//ITK
#include <itkAddImageFilter.h>
#include <itkRelabelComponentImageFilter.h>
#include <itkConnectedComponentImageFilter.h>
#include <itkImageRegionIteratorWithIndex.h>
#include "itkLabelObject.h"
#include "itkLabelMap.h"
#include "itkLabelImageToLabelMapFilter.h"
#include "itkLabelMapToLabelImageFilter.h"
#include "itkLabelSelectionLabelMapFilter.h"

// Qt
#include <QMessageBox>
#include <QFileDialog>
#include <QInputDialog>
#include <QDirIterator>
#include <QDate>
#include <QFile>

// mitk image
// mitk
#include <QmitkIOUtil.h>
#include <mitkImage.h>
#include <mitkLog.h>
#include <mitkProgressBar.h>
#include <mitkIDataStorageService.h>
#include <mitkNodePredicateNot.h>
#include <mitkNodePredicateProperty.h>
#include <mitkDataStorageEditorInput.h>
#include <mitkImageCast.h>
#include <mitkITKImageImport.h>
#include <mitkBoundingObject.h>
#include <mitkCuboid.h>
#include <mitkAffineImageCropperInteractor.h>
#include <mitkImagePixelReadAccessor.h>
#include <mitkUnstructuredGrid.h>
#include <mitkManualSegmentationToSurfaceFilter.h>

//CemrgAppModule
#include <CemrgCommonUtils.h>
#include <CemrgCommandLine.h>
#include <CemrgMeasure.h>
#include <CemrgScar3D.h>


const std::string AtrialStrainMotionView::VIEW_ID = "org.mitk.views.atrialstrainmotionview";

void AtrialStrainMotionView::SetFocus()
{
m_Controls.button_step_1->setFocus();
m_Controls.segment_extract->setFocus();
}

void AtrialStrainMotionView::CreateQtPartControl(QWidget *parent)
{
// create GUI widgets from the Qt Designer's .ui file
m_Controls.setupUi(parent);
connect(m_Controls.button_step_1, &QPushButton::clicked, this, &AtrialStrainMotionView::DoImageProcessing);
// Step 1: Segment and Extract
connect(m_Controls.segment_extract, SIGNAL(clicked()), this, SLOT(SegmentExtract()));


// Set default variables
atrium = std::unique_ptr<CemrgAtrialTools>(new CemrgAtrialTools());
}

void AtrialStrainMotionView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*source*/,
Expand All @@ -80,13 +141,13 @@ void AtrialStrainMotionView::OnSelectionChanged(berry::IWorkbenchPart::Pointer /
if (node.IsNotNull() && dynamic_cast<mitk::Image *>(node->GetData()))
{
m_Controls.labelWarning->setVisible(false);
m_Controls.button_step_1->setEnabled(true);
m_Controls.segment_extract->setEnabled(true);
return;
}
}

m_Controls.labelWarning->setVisible(true);
m_Controls.button_step_1->setEnabled(false);
m_Controls.segment_extract->setEnabled(false);
}

void AtrialStrainMotionView::DoImageProcessing()
Expand Down Expand Up @@ -129,3 +190,70 @@ void AtrialStrainMotionView::DoImageProcessing()
}
}
}

bool AtrialStrainMotionView::RequestProjectDirectoryFromUser() {

bool succesfulAssignment = true;

//Ask the user for a dir to store data
if (directory.isEmpty()) {

MITK_INFO << "Directory is empty. Requesting user for directory.";
directory = QFileDialog::getExistingDirectory( NULL, "Open Project Directory",
mitk::IOUtil::GetProgramPath().c_str(),QFileDialog::ShowDirsOnly|QFileDialog::DontUseNativeDialog);

MITK_INFO << ("Directory selected:" + directory).toStdString();
atrium->SetWorkingDirectory(directory);

if (directory.isEmpty() || directory.simplified().contains(" ")) {
MITK_WARN << "Please select a project directory with no spaces in the path!";
QMessageBox::warning(NULL, "Attention", "Please select a project directory with no spaces in the path!");
directory = QString();
succesfulAssignment = false;
}//_if

if (succesfulAssignment){
QString now = QDate::currentDate().toString(Qt::ISODate);
QString logfilename = directory + "/afib_log" + now + ".log";
std::string logfname_str = logfilename.toStdString();

mitk::LoggingBackend::SetLogFile(logfname_str.c_str());
MITK_INFO << ("Changed logfile location to: " + logfilename).toStdString();
}

} else {
MITK_INFO << ("Project directory already set: " + directory).toStdString();
}//_if


return succesfulAssignment;
}

void AtrialStrainMotionView::SegmentExtract() {

MITK_INFO << "[AnalysisChoice]";
bool testRpdfu = RequestProjectDirectoryFromUser();
MITK_INFO(testRpdfu) << "Should continue";
if (!RequestProjectDirectoryFromUser()) return; // if the path was chosen incorrectly -> returns.
MITK_INFO << "After directory selection checkup";

// TODO: select the first image and segment it
QString nifti_dir = directory + "/nifti/";
QString input_file = nifti_dir + "dcm-0.nii";
std::unique_ptr<CemrgCommandLine> cmd(new CemrgCommandLine());

MITK_INFO(QFile::copy(input_file, directory + "/dcm-0.nii")) << "QFile::Copy successful";
// MITK_INFO << successful;

// get pathToNifti file!
QFileInfo file(input_file);

cmd->SetUseDockerContainers(true);
QString pathToSegmentation = cmd->DockerCctaMultilabelSegmentation(directory, directory + "/dcm-0.nii", false);
MITK_INFO << pathToSegmentation;
// TODO: build a docker image for extracting LA




}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include "ui_AtrialStrainMotionViewControls.h"


#include "CemrgAtrialTools.h"
/**
\brief AtrialStrainMotionView
Expand All @@ -67,6 +69,8 @@ class AtrialStrainMotionView : public QmitkAbstractView {

public:
static const std::string VIEW_ID;
bool RequestProjectDirectoryFromUser();


protected:
virtual void CreateQtPartControl(QWidget *parent) override;
Expand All @@ -77,11 +81,19 @@ class AtrialStrainMotionView : public QmitkAbstractView {
virtual void OnSelectionChanged(berry::IWorkbenchPart::Pointer source,
const QList<mitk::DataNode::Pointer> &nodes) override;

Ui::AtrialStrainMotionViewControls m_Controls;

/// \brief Called when the user clicks the GUI button


protected slots:
void DoImageProcessing();
void SegmentExtract();

Ui::AtrialStrainMotionViewControls m_Controls;

private:
QString directory;
std::unique_ptr<CemrgAtrialTools> atrium;
};

#endif // AtrialStrainMotionView_h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>222</width>
<height>161</height>
<height>555</height>
</rect>
</property>
<property name="minimumSize">
Expand All @@ -26,20 +26,14 @@
<string notr="true">QLabel { color: rgb(255, 0, 0) }</string>
</property>
<property name="text">
<string>Please select an image!</string>
<string>Model Creation Pipeline</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="button_step_1">
<property name="toolTip">
<string>Do image processing</string>
</property>
<property name="styleSheet">
<string notr="true">text-align: left;</string>
</property>
<widget class="QPushButton" name="segment_extract">
<property name="text">
<string> Step 1: Do Something </string>
<string>Segment and Extract</string>
</property>
</widget>
</item>
Expand Down

0 comments on commit fdabe8c

Please sign in to comment.