]> Creatis software - clitk.git/commitdiff
add extract patient tool
authordsarrut <dsarrut>
Fri, 23 Jul 2010 14:24:14 +0000 (14:24 +0000)
committerdsarrut <dsarrut>
Fri, 23 Jul 2010 14:24:14 +0000 (14:24 +0000)
vv/CMakeLists.txt
vv/qt_ui/vvToolExtractPatient.ui [new file with mode: 0644]
vv/vvToolExtractPatient.cxx [new file with mode: 0644]
vv/vvToolExtractPatient.h [new file with mode: 0644]

index 7e004ae9fc879514253ccfd988f2fa01db9e08d6..41f3b649abe1e2caf34b085ae5db2a3bfd10c617 100644 (file)
@@ -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 (file)
index 0000000..75d134f
--- /dev/null
@@ -0,0 +1,107 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>vvToolExtractPatient</class>
+ <widget class="QWidget" name="vvToolExtractPatient">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>249</width>
+    <height>199</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Form</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QLabel" name="mLabelInput">
+     <property name="sizePolicy">
+      <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+       <horstretch>0</horstretch>
+       <verstretch>0</verstretch>
+      </sizepolicy>
+     </property>
+     <property name="font">
+      <font>
+       <pointsize>11</pointsize>
+       <weight>75</weight>
+       <bold>true</bold>
+      </font>
+     </property>
+     <property name="frameShape">
+      <enum>QFrame::NoFrame</enum>
+     </property>
+     <property name="text">
+      <string>No selected image</string>
+     </property>
+     <property name="alignment">
+      <set>Qt::AlignCenter</set>
+     </property>
+    </widget>
+   </item>
+   <item>
+    <widget class="QGroupBox" name="mOptionsBox">
+     <property name="title">
+      <string>Extract Patient Options</string>
+     </property>
+     <layout class="QVBoxLayout" name="verticalLayout_3">
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout_2">
+        <item>
+         <widget class="vvIntensityValueSlider" name="mAirUpperThresholdSlider" native="true"/>
+        </item>
+        <item>
+         <widget class="QRadioButton" name="mRadioButtonLowerThan">
+          <property name="text">
+           <string>use lower</string>
+          </property>
+          <property name="autoExclusive">
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="vvIntensityValueSlider" name="mAirLowerThresholdSlider" native="true">
+          <property name="enabled">
+           <bool>false</bool>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+     </layout>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>vvIntensityValueSlider</class>
+   <extends>QWidget</extends>
+   <header>vvIntensityValueSlider.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources>
+  <include location="../vvIcons.qrc"/>
+ </resources>
+ <connections>
+  <connection>
+   <sender>mRadioButtonLowerThan</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>mAirLowerThresholdSlider</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>64</x>
+     <y>275</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>79</x>
+     <y>299</y>
+    </hint>
+   </hints>
+  </connection>
+ </connections>
+</ui>
diff --git a/vv/vvToolExtractPatient.cxx b/vv/vvToolExtractPatient.cxx
new file mode 100644 (file)
index 0000000..c38dde5
--- /dev/null
@@ -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 <QMessageBox>
+
+//------------------------------------------------------------------------------
+// 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<vvToolExtractPatient>(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<vvImage::Pointer> 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 (file)
index 0000000..1c8565e
--- /dev/null
@@ -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 <QtDesigner/QDesignerExportWidget>
+
+//------------------------------------------------------------------------------
+class vvToolExtractPatient:
+  public vvToolWidgetBase,
+  public vvToolBase<vvToolExtractPatient>, 
+  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<ArgsInfoType> FilterType;
+  FilterType * mFilter;
+  vvImage::Pointer mPatient;
+  double mPatientBackgroundValue;
+  bool m_IsThreadInterrupted;
+
+}; // end class vvToolExtractPatient
+//------------------------------------------------------------------------------
+
+#endif
+