From: dsarrut Date: Fri, 23 Jul 2010 14:24:14 +0000 (+0000) Subject: add extract patient tool X-Git-Tag: v1.2.0~483 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;ds=sidebyside;h=83dbd9493090be7eba90abb649b562ade6adc576;p=clitk.git add extract patient tool --- diff --git a/vv/CMakeLists.txt b/vv/CMakeLists.txt index 7e004ae..41f3b64 100644 --- a/vv/CMakeLists.txt +++ b/vv/CMakeLists.txt @@ -70,6 +70,7 @@ SET(vv_SRCS vvToolResample.cxx vvBlendImageActor.cxx vvLabelImageLoaderWidget.cxx + vvToolExtractPatient.cxx vvToolExtractLung.cxx vvToolPlastimatch.cxx # vvToolConnectedComponentLabeling.cxx @@ -117,6 +118,7 @@ QT4_WRAP_CPP(vv_SRCS vvROIActor.h vvToolResample.h vvLabelImageLoaderWidget.h + vvToolExtractPatient.h vvToolExtractLung.h vvToolPlastimatch.h # vvToolConnectedComponentLabeling.h @@ -151,6 +153,7 @@ QT4_WRAP_UI(vv_UI_CXX qt_ui/vvToolStructureSetManager.ui qt_ui/vvToolResample.ui qt_ui/vvLabelImageLoaderWidget.ui + qt_ui/vvToolExtractPatient.ui qt_ui/vvToolExtractLung.ui qt_ui/vvToolPlastimatch.ui # qt_ui/vvToolConnectedComponentLabeling.ui diff --git a/vv/qt_ui/vvToolExtractPatient.ui b/vv/qt_ui/vvToolExtractPatient.ui new file mode 100644 index 0000000..75d134f --- /dev/null +++ b/vv/qt_ui/vvToolExtractPatient.ui @@ -0,0 +1,107 @@ + + + vvToolExtractPatient + + + + 0 + 0 + 249 + 199 + + + + Form + + + + + + + 0 + 0 + + + + + 11 + 75 + true + + + + QFrame::NoFrame + + + No selected image + + + Qt::AlignCenter + + + + + + + Extract Patient Options + + + + + + + + + + + use lower + + + false + + + + + + + false + + + + + + + + + + + + + vvIntensityValueSlider + QWidget +
vvIntensityValueSlider.h
+ 1 +
+
+ + + + + + mRadioButtonLowerThan + toggled(bool) + mAirLowerThresholdSlider + setEnabled(bool) + + + 64 + 275 + + + 79 + 299 + + + + +
diff --git a/vv/vvToolExtractPatient.cxx b/vv/vvToolExtractPatient.cxx new file mode 100644 index 0000000..c38dde5 --- /dev/null +++ b/vv/vvToolExtractPatient.cxx @@ -0,0 +1,254 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html + ======================================================================-====*/ + +// vv +#include "vvToolExtractPatient.h" +#include "vvToolStructureSetManager.h" +#include "vvSlicer.h" +#include "vvImageReader.h" +#include "vvImageWriter.h" +#include "vvLabelImageLoaderWidget.h" +#include "vvThreadedFilter.h" + +// Qt +#include + +//------------------------------------------------------------------------------ +// Create the tool and automagically (I like this word) insert it in +// the main window menu. +ADD_TOOL(vvToolExtractPatient); +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolExtractPatient::vvToolExtractPatient(vvMainWindowBase * parent, Qt::WindowFlags f): + vvToolWidgetBase(parent,f), + vvToolBase(parent), + Ui::vvToolExtractPatient() +{ + // GUI + Ui_vvToolExtractPatient::setupUi(mToolWidget); + mOptionsBox->setEnabled(true); + //connect(mPatientMaskInputWidget, SIGNAL(accepted()), this, SLOT(PatientMaskInputIsSelected())); + + // Default values + mArgsInfo = new ArgsInfoType; + cmdline_parser_clitkExtractPatient_init(mArgsInfo); + SetGUIFromArgsInfo(); + m_IsThreadInterrupted = false; + + // Create a new ExtractPatient filter + mFilter = new FilterType; // used in AddInputSelector + + // Add input selector + AddInputSelector("Select CT thorax image", mFilter); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +vvToolExtractPatient::~vvToolExtractPatient() +{ +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolExtractPatient::Initialize() { + SetToolName("ExtractPatient"); + SetToolMenuName("Extract Patient"); + SetToolIconFilename(":/common/icons/Patient-overlay.png"); + SetToolTip("Extract Patient mask from thorax CT."); + // SetToolExperimental(true); + // SetToolInMenu("Segmentation"); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolExtractPatient::InputIsSelected(vvSlicerManager *m) +{ + // Hide selector + HideInputSelector(); // splitter + mToolInputSelectionWidget->hide(); + mCurrentSlicerManager = m; + mCurrentImage = m->GetImage(); + mLabelInput->setText(m->GetFileName().c_str()); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +// void vvToolExtractPatient::PatientMaskInputIsSelected() +// { +// // Get Patient mask and BG value +// mPatient = mPatientMaskInputWidget->GetImage(); +// mPatientBackgroundValue = mPatientMaskInputWidget->GetBackgroundValue(); + +// // Check patient dimension +// if (mPatient->GetNumberOfDimensions() != 3) { +// QMessageBox::information(this,tr("*Error*"), "Mask image must be 3D"); +// return; +// } + +// mMaskLoaderBox->setEnabled(false); +// mOptionsBox->setEnabled(true); +// } +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolExtractPatient::SetGUIFromArgsInfo() +{ + /* + mAirUpperThresholdSlider->SetText("Upper threshold for air"); + mAirUpperThresholdSlider->SetMinimum(-1200); + mAirUpperThresholdSlider->SetMaximum(2000); + DD(mArgsInfo->upper_arg); + mAirUpperThresholdSlider->SetValue(mArgsInfo->upper_arg); + + mAirLowerThresholdSlider->SetText("Lower threshold for air"); + mAirLowerThresholdSlider->SetMinimum(-1200); + mAirLowerThresholdSlider->SetMaximum(2000); + mAirLowerThresholdSlider->SetValue(mArgsInfo->lower_arg); + */ + +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolExtractPatient::GetArgsInfoFromGUI() +{ + //mArgsInfo->patientBG_arg = mPatientMaskInputWidget->GetBackgroundValue(); + mArgsInfo->verboseOption_flag = true; // DEBUG. TO CHANGE + mArgsInfo->verboseStep_flag = true; // DEBUG. TO CHANGE + mArgsInfo->writeStep_flag = false; + mArgsInfo->input_given = 0; + //mArgsInfo->patient_given = 0; + mArgsInfo->output_given = 0; + //mArgsInfo->outputTrachea_given = 0; + //mArgsInfo->remove1_given = 0; + + // mArgsInfo->upper_arg = mAirUpperThresholdSlider->GetValue(); +// mArgsInfo->lower_arg = mAirLowerThresholdSlider->GetValue(); +// if (mRadioButtonLowerThan->isChecked()) mArgsInfo->lower_given = 1; +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolExtractPatient::apply() +{ + // Change cursor to wait + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + + // Read options from GUI and put it in the ArgsInfo struct + GetArgsInfoFromGUI(); + + // Check options + // if (mArgsInfo->lower_given) { +// if (mArgsInfo->lower_arg > mArgsInfo->upper_arg) { +// QApplication::restoreOverrideCursor(); +// QMessageBox::information(this,tr("Error"), "Lower threshold cannot be greater than upper threshold."); +// return; +// } +// } + + // Create new filter + //if (mFilter) delete mFilter; + DD("new filter"); + mFilter = new FilterType; // needed when thread cancel the filter + mFilter->StopOnErrorOff(); + // mFilter->SetIOVerbose(true); + mFilter->AddInputVVImage(mCurrentImage); // CT +// mFilter->AddInputVVImage(mPatient); // patient mask + mFilter->SetArgsInfo(*mArgsInfo); + + // Created threaded execution + DD("thread"); + vvThreadedFilter thread; + connect(&thread, SIGNAL(ThreadInterrupted()), this, SLOT(ThreadInterrupted())); + thread.SetFilter(mFilter); + thread.Update(); + + // Check if the thread has been canceled. In this case, return + if (m_IsThreadInterrupted) { + m_IsThreadInterrupted = false; + QApplication::restoreOverrideCursor(); + return; + } + disconnect(&thread, SIGNAL(ThreadInterrupted()), this, SLOT(ThreadInterrupted())); + + // Check error during filter + if (mFilter->HasError()) { + QApplication::restoreOverrideCursor(); + QMessageBox::information(this,tr("Error"), mFilter->GetLastError().c_str()); + return; + } + + // Get output + std::vector output = mFilter->GetOutputVVImages(); + if (output.size() == 0) { + std::cerr << "Error : no output ?" << std::endl; + QApplication::restoreOverrideCursor(); + close(); + return; + } + + // Set Patient into VV + vvImage::Pointer Patient = output[0]; + std::ostringstream osstream; + osstream << "Patient_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd"; + vvSlicerManager * v = AddImage(Patient,osstream.str()); + v->SetPreset(5); + vvToolStructureSetManager::AddImage(mCurrentSlicerManager, "Right Patient", Patient, 1, false); // Right is greater than Left +// vvToolStructureSetManager::AddImage(mCurrentSlicerManager, "Left Patient", Patient, 2, false); + + // // Set trachea into VV +// if (output.size() == 2) { +// vvImage::Pointer trachea = output[1]; +// std::ostringstream osstream; +// osstream << "Trachea_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd"; +// vvSlicerManager * v = AddImage(trachea,osstream.str()); +// v->SetPreset(5); +// vvToolStructureSetManager::AddImage(mCurrentSlicerManager, "Trachea", trachea, 0); +// } + + // End + QApplication::restoreOverrideCursor(); + close(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +bool vvToolExtractPatient::close() +{ + return vvToolWidgetBase::close(); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ +void vvToolExtractPatient::ThreadInterrupted() +{ + m_IsThreadInterrupted = true; +} +//------------------------------------------------------------------------------ + diff --git a/vv/vvToolExtractPatient.h b/vv/vvToolExtractPatient.h new file mode 100644 index 0000000..1c8565e --- /dev/null +++ b/vv/vvToolExtractPatient.h @@ -0,0 +1,73 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://oncora1.lyon.fnclcc.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +======================================================================-====*/ + +#ifndef VVTOOLEXTRACTPATIENT_H +#define VVTOOLEXTRACTPATIENT_H + +// clitk +#include "clitkExtractPatientGenericFilter.h" +#include "../segmentation/clitkExtractPatient_ggo.h" + +// vv +#include "ui_vvToolExtractPatient.h" +#include "vvToolBase.h" +#include "vvToolWidgetBase.h" +#include "vvROIActor.h" + +// qt +#include + +//------------------------------------------------------------------------------ +class vvToolExtractPatient: + public vvToolWidgetBase, + public vvToolBase, + private Ui::vvToolExtractPatient +{ + Q_OBJECT + public: + vvToolExtractPatient(vvMainWindowBase* parent=0, Qt::WindowFlags f=0); + ~vvToolExtractPatient(); + + //----------------------------------------------------- + static void Initialize(); + virtual void InputIsSelected(vvSlicerManager *m); + void GetArgsInfoFromGUI(); + void SetGUIFromArgsInfo(); + + //----------------------------------------------------- +public slots: + virtual void apply(); + virtual bool close(); + // void PatientMaskInputIsSelected(); + void ThreadInterrupted(); + + //----------------------------------------------------- +protected: + typedef args_info_clitkExtractPatient ArgsInfoType; + ArgsInfoType * mArgsInfo; + typedef clitk::ExtractPatientGenericFilter FilterType; + FilterType * mFilter; + vvImage::Pointer mPatient; + double mPatientBackgroundValue; + bool m_IsThreadInterrupted; + +}; // end class vvToolExtractPatient +//------------------------------------------------------------------------------ + +#endif +