]> Creatis software - clitk.git/commitdiff
Create the line iterator
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 23 Dec 2015 14:43:47 +0000 (15:43 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 23 Dec 2015 14:43:47 +0000 (15:43 +0100)
tools/clitkProfileImage.ggo
tools/clitkProfileImageGenericFilter.cxx
vv/qt_ui/vvToolProfile.ui
vv/vvToolProfile.cxx
vv/vvToolProfile.h

index 1894af6c7c659e806fe7dbe9386be3853ea9f0f3..7714e1833d82356fbb0325f7183dd9b6e728c6f1 100644 (file)
@@ -1,19 +1,16 @@
 #File clitkProfileImage.ggo
 package "clitkProfileImage"
 version "1.0"
-purpose ""
+purpose "Save the profile between 2 points of the input image in the output text file"
 
-option "config"                -       "Config file"                     string        no
-option "verbose"       v       "Verbose"                         flag          off
-option "imagetypes"    -       "Display allowed image types"     flag          off
+option "config"                -       "Config file"                           string  no
+option "verbose"       v       "Verbose"                                   flag        off
+option "imagetypes" -   "Display allowed image types"   flag   off
 
-option "input"         i       "Input image filename"            string        yes
-option "output"        o       "Output image filename"           string        yes
-option "lower"         l       "Lower intensity (default=min), fg is greater than this value"    double        no
-option "upper"         u       "Upper intensity (default=max), fg is lower than this value"      double        no
+option "input"      i   "Input image filename"          string  yes
+option "output"     o   "Output texte filename"         string  yes
+option "point1"     f   "First point (mm)"              int     yes multiple(-4)
+option "point2"     s   "Second point (mm)"             int     yes multiple(-4)
 
-option "fg"                    -       "Foreground (FG) or 'inside' value"               double        no      default="1"
-option "bg"                    -       "Background (BG) or 'ouside' value"               double        no      default="0"
-option "mode"          -       "Use FG and/or BG values (if FG, the BG is replaced by the input image values)" values="FG","BG","both"  no default="both"
 
 
index 82298151116fc67a2505603e01d5b4dedfd11829..3c6d6b79ff1f1d4084ddf5cb46a1639b77d73819 100644 (file)
@@ -30,9 +30,7 @@
 #include "clitkProfileImageGenericFilter.h"
 
 // itk include
-#include "itkBinaryThresholdImageFilter.h"
-#include "itkMaskImageFilter.h"
-#include "itkMaskNegatedImageFilter.h"
+#include <itkLineIterator.h>
 
 #include <clitkCommon.h>
 
@@ -88,25 +86,40 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
 
   // Reading input
   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
-
-  // Main filter
   typedef typename InputImageType::PixelType PixelType;
+  typedef typename InputImageType::IndexType IndexType;
   typedef itk::Image<uchar, InputImageType::ImageDimension> OutputImageType;
+  
+  //Iterator
+  IndexType pointBegin, pointEnd;
+  
+  for (int i = 0; i < mArgsInfo.point1_given; ++i) {
+    pointBegin[i] = mArgsInfo.point1_arg[i];
+    pointEnd[i] = mArgsInfo.point2_arg[i];
+  }
+  
+  itk::LineConstIterator<InputImageType> itProfile(input, pointBegin, pointEnd);
+  itProfile.GoToBegin();
+  while (!itProfile.IsAtEnd())
+  {
+    
+    ++itProfile;
+  }
 
   // Filter
-  typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
-  typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
-  thresholdFilter->SetInput(input);
-  thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
+  //typedef itk::BinaryThresholdImageFilter<InputImageType, OutputImageType> BinaryThresholdImageFilterType;
+  //typename BinaryThresholdImageFilterType::Pointer thresholdFilter=BinaryThresholdImageFilterType::New();
+  //thresholdFilter->SetInput(input);
+  /*thresholdFilter->SetInsideValue(mArgsInfo.fg_arg);
 
   if (mArgsInfo.lower_given) thresholdFilter->SetLowerThreshold(static_cast<PixelType>(mArgsInfo.lower_arg));
   if (mArgsInfo.upper_given) thresholdFilter->SetUpperThreshold(static_cast<PixelType>(mArgsInfo.upper_arg));
 
-  /* Three modes :
+   Three modes :
      - FG -> only use FG value for pixel in the Foreground (or Inside), keep input values for outside
      - BG -> only use BG value for pixel in the Background (or Outside), keep input values for inside
      - both -> use FG and BG (real binary image)
-  */
+  
   if (mArgsInfo.mode_arg == std::string("both")) {
     thresholdFilter->SetOutsideValue(mArgsInfo.bg_arg);
     thresholdFilter->Update();
@@ -134,7 +147,7 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
     }
     // Write/Save results
     this->template SetNextOutput<InputImageType>(outputImage);
-  }
+  }*/
 }
 //--------------------------------------------------------------------
 
index 6366b497c24960de02b1d75105e4ca1cd635134c..3d6af50529e6bdd86738cfd38c38f888f2e105ba 100644 (file)
          </property>
         </widget>
        </item>
+       <item row="2" column="2">
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
+         <item>
+          <widget class="QLabel" name="Point2">
+           <property name="text">
+            <string>Point2 (mm): </string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QLabel" name="mPosPoint2Label">
+           <property name="text">
+            <string/>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
        <item row="2" column="1">
         <widget class="QPushButton" name="mSelectPoint2Button">
          <property name="text">
          </property>
         </widget>
        </item>
-       <item row="3" column="1">
-        <widget class="QToolButton" name="mCancelPoints">
-         <property name="text">
-          <string>Cancel</string>
-         </property>
-        </widget>
-       </item>
-       <item row="1" column="2">
-        <layout class="QHBoxLayout" name="horizontalLayout">
+       <item row="3" column="2">
+        <layout class="QHBoxLayout" name="horizontalLayout_6">
          <item>
-          <widget class="QLabel" name="Point1">
+          <widget class="QToolButton" name="mCancelPointsButton">
            <property name="text">
-            <string>Point1 (mm): </string>
+            <string>Cancel</string>
            </property>
           </widget>
          </item>
          <item>
-          <widget class="QLabel" name="mPosPoint1Label">
+          <widget class="QPushButton" name="mComputeProfileButton">
+           <property name="sizePolicy">
+            <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+             <horstretch>0</horstretch>
+             <verstretch>0</verstretch>
+            </sizepolicy>
+           </property>
            <property name="text">
-            <string/>
+            <string>Compute Profile</string>
            </property>
           </widget>
          </item>
         </layout>
        </item>
-       <item row="2" column="2">
-        <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item row="1" column="2">
+        <layout class="QHBoxLayout" name="horizontalLayout">
          <item>
-          <widget class="QLabel" name="Point2">
+          <widget class="QLabel" name="Point1">
            <property name="text">
-            <string>Point2 (mm): </string>
+            <string>Point1 (mm): </string>
            </property>
           </widget>
          </item>
          <item>
-          <widget class="QLabel" name="mPosPoint2Label">
+          <widget class="QLabel" name="mPosPoint1Label">
            <property name="text">
             <string/>
            </property>
index 54eafd8d04ec6664da1c15509afc95b5269cf8cf..b9c34c9df672aa01fbc0999263112b85120b786c 100644 (file)
@@ -64,7 +64,8 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
   // Connect signals & slots
   connect(mSelectPoint1Button, SIGNAL(clicked()), this, SLOT(selectPoint1()));
   connect(mSelectPoint2Button, SIGNAL(clicked()), this, SLOT(selectPoint2()));
-  connect(mCancelPoints, SIGNAL(clicked()), this, SLOT(cancelPoints()));
+  connect(mCancelPointsButton, SIGNAL(clicked()), this, SLOT(cancelPoints()));
+  connect(mComputeProfileButton, SIGNAL(clicked()), this, SLOT(computeProfile()));
 
   // Initialize some widget
   //mThresholdSlider1->SetText("");
@@ -74,6 +75,9 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
   
   mPoint1 = NULL;
   mPoint2 = NULL;
+  
+  point1Selected = false;
+  point2Selected = false;
 
   // Main filter
   mFilter = clitk::ProfileImageGenericFilter::New();
@@ -98,17 +102,18 @@ void vvToolProfile::selectPoint1()
   point1Selected = false;
   if(mCurrentSlicerManager) {
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
-          double x = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[0];
-          double y = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[1];
-          double z = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[2];
-          position += QString::number(x,'f',1) + " ";
-          position += QString::number(y,'f',1) + " ";
-          position += QString::number(z,'f',1) + " ";
+          double *pos;
+          int *index;
+          pos = new double [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+          index = new int [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+          
+          for (int i=0; i<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions(); ++i) {
+            pos[i] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[i];
+            index[i] = (int) (pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i];
             
-          mPoint1[0] = x;
-          mPoint1[1] = y;
-          mPoint1[2] = z;
-           
+            position += QString::number(pos[i],'f',1) + " ";
+            mPoint1[i] = index[i];
+          }
           point1Selected = true;
       }
   }
@@ -125,17 +130,18 @@ void vvToolProfile::selectPoint2()
   point2Selected = false;
   if(mCurrentSlicerManager) {
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
-          double x = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[0];
-          double y = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[1];
-          double z = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[2];
-          position += QString::number(x,'f',1) + " ";
-          position += QString::number(y,'f',1) + " ";
-          position += QString::number(z,'f',1) + " ";
+          double *pos;
+          int *index;
+          pos = new double [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+          index = new int [mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+          
+          for (int i=0; i<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions(); ++i) {
+            pos[i] = mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetCursorPosition()[i];
+            index[i] = (int) (pos[i] - mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetOrigin()[i])/mCurrentSlicerManager->GetSlicer(mCurrentSlicerManager->GetSelectedSlicer())->GetInput()->GetSpacing()[i];
             
-          mPoint2[0] = x;
-          mPoint2[1] = y;
-          mPoint2[2] = z;
-           
+            position += QString::number(pos[i],'f',1) + " ";
+            mPoint2[i] = index[i];
+          }
           point2Selected = true;
       }
   }
@@ -147,15 +153,36 @@ void vvToolProfile::selectPoint2()
 //------------------------------------------------------------------------------
 bool vvToolProfile::isPointsSelected()
 {
-  if (point1Selected && point2Selected) {
-  //Lancer le calcule du profil
-  }
+  if (point1Selected && point2Selected)
+      mComputeProfileButton->setEnabled(true);
+  else
+      mComputeProfileButton->setEnabled(false);
   
   return (point1Selected && point2Selected);
 }
 //------------------------------------------------------------------------------
 
 
+//------------------------------------------------------------------------------
+void vvToolProfile::computeProfile()
+{
+    if (!mCurrentSlicerManager) close();
+
+    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+    GetArgsInfoFromGUI();
+    
+    // Main filter
+    clitk::ProfileImageGenericFilter::Pointer filter = clitk::ProfileImageGenericFilter::New();
+    filter->SetInputVVImage(mCurrentImage);
+    filter->SetArgsInfo(mArgsInfo);
+    filter->Update();
+    
+    QApplication::restoreOverrideCursor();
+}
+//------------------------------------------------------------------------------
+
+
 //------------------------------------------------------------------------------
 void vvToolProfile::cancelPoints()
 { 
@@ -164,6 +191,7 @@ void vvToolProfile::cancelPoints()
   mPosPoint2Label->setText(position);
   point1Selected = false;
   point2Selected = false;
+  mComputeProfileButton->setEnabled(false);
   isPointsSelected();
 }
 //------------------------------------------------------------------------------
@@ -270,10 +298,10 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m)
 { 
   mCurrentSlicerManager = m;
 
-  mPoint1 = new double[3];
-  mPoint2 = new double[3];
-  //mPoint1 = new double[m->GetImage()->GetNumberOfSpatialDimensions()];
-  //mPoint2 = new double[m->GetImage()->GetNumberOfSpatialDimensions()];
+  mPoint1 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+  mPoint2 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+  
+  mComputeProfileButton->setEnabled(false);
 
   // Specific for this gui
   //mThresholdSlider1->SetValue(0);
@@ -298,7 +326,7 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m)
   mBGSlider->SetValue(0);
   mFGSlider->SetSingleStep(1);
   mBGSlider->SetSingleStep(1);
-*/
+
   // VTK objects for interactive display
   for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
     mImageContour.push_back(vvImageContour::New());
@@ -321,7 +349,7 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m)
   //connect(mCurrentSlicerManager,SIGNAL(UpdateOrientation(int,int)),this,SLOT(UpdateOrientation(int, int)));
 
   //  connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int)));
-  InteractiveDisplayToggled(mInteractiveDisplayIsEnabled);
+  InteractiveDisplayToggled(mInteractiveDisplayIsEnabled); */
 }
 //------------------------------------------------------------------------------
 
@@ -354,7 +382,7 @@ void vvToolProfile::UpdateSlice(int slicer,int slices)
 //------------------------------------------------------------------------------
 void vvToolProfile::Update(int slicer)
 { 
-  if (!mInteractiveDisplayIsEnabled) return;
+  //if (!mInteractiveDisplayIsEnabled) return;
   if (!mCurrentSlicerManager) close();
   //mImageContour[slicer]->Update(mThresholdSlider1->GetValue());
   //if (mRadioButtonLowerThan->isChecked()) 
@@ -377,9 +405,9 @@ void vvToolProfile::GetArgsInfoFromGUI()
      DD(good);
   */
   cmdline_parser_clitkProfileImage_init(&mArgsInfo); // Initialisation to default
-  bool inverseBGandFG = false;
+  //bool inverseBGandFG = false;
 
-  mArgsInfo.lower_given = 1;
+  //mArgsInfo.lower_given = 1;
   /*mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
   if (mRadioButtonLowerThan->isChecked()) {
     mArgsInfo.upper_given = 1;
@@ -406,13 +434,18 @@ void vvToolProfile::GetArgsInfoFromGUI()
   } else mArgsInfo.mode_arg = (char*)"FG";
 */
   mArgsInfo.verbose_flag = false;
+  
+  mArgsInfo.point1_arg = mPoint1;
+  mArgsInfo.point2_arg = mPoint2;
+  mArgsInfo.point1_given = mCurrentSlicerManager->GetImage()->GetNumberOfDimensions();
+  mArgsInfo.point2_given = mCurrentSlicerManager->GetImage()->GetNumberOfDimensions();
+  
+  // Required (even if not used)
+  mArgsInfo.input_given = 0;
+  mArgsInfo.output_given = 0;
 
-  // // Required (even if not used)
-  // mArgsInfo.input_given = 0;
-  // mArgsInfo.output_given = 0;
-
-  // mArgsInfo.input_arg = new char;
-  // mArgsInfo.output_arg = new char;
+  mArgsInfo.input_arg = new char;
+  mArgsInfo.output_arg = new char;
 }
 //------------------------------------------------------------------------------
 
index dd5efbdb61965d398689f2ae36a1a1ec2137ab8d..ecccf06f5abe4737c8a280af93f666762b9f9377 100644 (file)
@@ -62,6 +62,7 @@ class vvToolProfile:
   void selectPoint1();
   void selectPoint2();
   void cancelPoints();
+  void computeProfile();
 
  protected:
   void RemoveVTKObjects();
@@ -72,8 +73,8 @@ class vvToolProfile:
   std::vector<vvImageContour::Pointer> mImageContourLower;
   bool mInteractiveDisplayIsEnabled;
   
-  double* mPoint1;
-  double* mPoint2;
+  int* mPoint1;
+  int* mPoint2;
   bool point1Selected;
   bool point2Selected;