]> Creatis software - clitk.git/commitdiff
Add the profile display and the saving a text file
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 30 Dec 2015 14:00:48 +0000 (15:00 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Wed, 30 Dec 2015 14:00:48 +0000 (15:00 +0100)
tools/clitkProfileImageGenericFilter.cxx
tools/clitkProfileImageGenericFilter.h
vv/qt_ui/vvToolProfile.ui
vv/qt_ui/vvToolWidgetBase.ui
vv/vvToolProfile.cxx
vv/vvToolProfile.h

index 3c6d6b79ff1f1d4084ddf5cb46a1639b77d73819..1eb58c28ffd93f95775ff3a5d2b8d9eb3fb14923 100644 (file)
@@ -34,6 +34,8 @@
 
 #include <clitkCommon.h>
 
+
+
 namespace clitk
 {
 
@@ -57,6 +59,30 @@ void ProfileImageGenericFilter::InitializeImageType()
 //--------------------------------------------------------------------
 
 
+//--------------------------------------------------------------------
+vtkFloatArray* ProfileImageGenericFilter::GetArrayX()
+{
+  return(mArrayX);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+vtkFloatArray* ProfileImageGenericFilter::GetArrayY()
+{
+  return(mArrayY);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+vtkFloatArray* ProfileImageGenericFilter::GetCoord()
+{
+  return(mCoord);
+}
+//--------------------------------------------------------------------
+
+
 //--------------------------------------------------------------------
 void ProfileImageGenericFilter::SetArgsInfo(const args_info_type & a)
 {
@@ -88,7 +114,11 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
   typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
   typedef typename InputImageType::PixelType PixelType;
   typedef typename InputImageType::IndexType IndexType;
-  typedef itk::Image<uchar, InputImageType::ImageDimension> OutputImageType;
+
+  mArrayX = vtkSmartPointer<vtkFloatArray>::New();
+  mArrayY = vtkSmartPointer<vtkFloatArray>::New();
+  mCoord = vtkSmartPointer<vtkFloatArray>::New();
+  mCoord->SetNumberOfComponents(InputImageType::ImageDimension);
   
   //Iterator
   IndexType pointBegin, pointEnd;
@@ -100,54 +130,26 @@ ProfileImageGenericFilter::UpdateWithInputImageType()
   
   itk::LineConstIterator<InputImageType> itProfile(input, pointBegin, pointEnd);
   itProfile.GoToBegin();
+  int lineNumber(1);
+  double *tuple;
+  tuple = new double[InputImageType::ImageDimension];
+  
   while (!itProfile.IsAtEnd())
-  {
+  {    
+    // Fill in the table
+    mArrayX->InsertNextTuple1(lineNumber);
+    mArrayY->InsertNextTuple1(itProfile.Get());
+        
+    for (int i=0; i<InputImageType::ImageDimension; ++i) {
+        tuple[i] = itProfile.GetIndex()[i];
+    }
     
+    mCoord->InsertNextTuple(tuple);
+    ++lineNumber;
     ++itProfile;
   }
-
-  // Filter
-  //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 :
-     - 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();
-    typename OutputImageType::Pointer outputImage = thresholdFilter->GetOutput();
-    this->template SetNextOutput<OutputImageType>(outputImage);
-  } else {
-    typename InputImageType::Pointer outputImage;
-    thresholdFilter->SetOutsideValue(0);
-    if (mArgsInfo.mode_arg == std::string("BG")) {
-      typedef itk::MaskImageFilter<InputImageType,OutputImageType> maskFilterType;
-      typename maskFilterType::Pointer maskFilter = maskFilterType::New();
-      maskFilter->SetInput1(input);
-      maskFilter->SetInput2(thresholdFilter->GetOutput());
-      maskFilter->SetOutsideValue(mArgsInfo.bg_arg);
-      maskFilter->Update();
-      outputImage = maskFilter->GetOutput();
-    } else {
-      typedef itk::MaskNegatedImageFilter<InputImageType,OutputImageType> maskFilterType;
-      typename maskFilterType::Pointer maskFilter = maskFilterType::New();
-      maskFilter->SetInput1(input);
-      maskFilter->SetInput2(thresholdFilter->GetOutput());
-      maskFilter->SetOutsideValue(mArgsInfo.fg_arg);
-      maskFilter->Update();
-      outputImage = maskFilter->GetOutput();
-    }
-    // Write/Save results
-    this->template SetNextOutput<InputImageType>(outputImage);
-  }*/
+  delete [] tuple;
 }
 //--------------------------------------------------------------------
 
index e251ff586495c8709faf1c3a5d33f6e0fae0bb4d..573a41ca62b2a487908565ec9069f51574d1de0b 100644 (file)
@@ -23,6 +23,9 @@
 #include "clitkImageToImageGenericFilter.h"
 #include "clitkProfileImage_ggo.h"
 
+#include <vtkIntArray.h>
+#include <vtkFloatArray.h>
+
 //--------------------------------------------------------------------
 namespace clitk 
 {
@@ -34,8 +37,8 @@ namespace clitk
   public:
     //--------------------------------------------------------------------
     typedef ProfileImageGenericFilter         Self;
-    typedef itk::SmartPointer<Self>            Pointer;
-    typedef itk::SmartPointer<const Self>      ConstPointer;
+    typedef itk::SmartPointer<Self>           Pointer;
+    typedef itk::SmartPointer<const Self>     ConstPointer;
     typedef args_info_clitkProfileImage       args_info_type;
    
     //--------------------------------------------------------------------
@@ -51,12 +54,22 @@ namespace clitk
     // Main function called each time the filter is updated
     template<class InputImageType>  
     void UpdateWithInputImageType();
+    
+    vtkFloatArray* GetArrayX();
+    vtkFloatArray* GetArrayY();
+    vtkFloatArray* GetCoord();
 
   protected:
     ProfileImageGenericFilter();
     template<unsigned int Dim> void InitializeImageType();
     args_info_type mArgsInfo;
     
+  
+    vtkSmartPointer<vtkFloatArray> mArrayX;
+    vtkSmartPointer<vtkFloatArray> mArrayY;
+    vtkSmartPointer<vtkFloatArray> mCoord;
+    
+    
   }; // end class
   //--------------------------------------------------------------------
     
index 3d6af50529e6bdd86738cfd38c38f888f2e105ba..f9edb6df0a60e3b80805d0933ca428243f0bdea9 100644 (file)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>433</width>
-    <height>222</height>
+    <width>437</width>
+    <height>452</height>
    </rect>
   </property>
   <property name="windowTitle">
        <property name="horizontalSpacing">
         <number>6</number>
        </property>
-       <item row="1" column="1">
-        <widget class="QToolButton" name="mSelectPoint1Button">
-         <property name="text">
-          <string>Select point 1</string>
-         </property>
-        </widget>
-       </item>
-       <item row="2" column="2">
-        <layout class="QHBoxLayout" name="horizontalLayout_2">
+       <item row="2" column="1">
+        <layout class="QHBoxLayout" name="horizontalLayout_3">
+         <item>
+          <widget class="QPushButton" name="mSelectPoint2Button">
+           <property name="text">
+            <string>Select point 2</string>
+           </property>
+          </widget>
+         </item>
          <item>
           <widget class="QLabel" name="Point2">
            <property name="text">
            </property>
           </widget>
          </item>
+        </layout>
+       </item>
+       <item row="2" column="3">
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
          <item>
           <widget class="QLabel" name="mPosPoint2Label">
            <property name="text">
          </item>
         </layout>
        </item>
-       <item row="2" column="1">
-        <widget class="QPushButton" name="mSelectPoint2Button">
-         <property name="text">
-          <string>Select point 2</string>
-         </property>
-        </widget>
-       </item>
-       <item row="3" column="2">
+       <item row="3" column="3">
         <layout class="QHBoxLayout" name="horizontalLayout_6">
          <item>
           <widget class="QToolButton" name="mCancelPointsButton">
          </item>
         </layout>
        </item>
-       <item row="1" column="2">
-        <layout class="QHBoxLayout" name="horizontalLayout">
+       <item row="1" column="1">
+        <layout class="QHBoxLayout" name="horizontalLayout_7">
+         <item>
+          <widget class="QPushButton" name="mSelectPoint1Button">
+           <property name="text">
+            <string>Select point 1</string>
+           </property>
+          </widget>
+         </item>
          <item>
           <widget class="QLabel" name="Point1">
            <property name="text">
            </property>
           </widget>
          </item>
+        </layout>
+       </item>
+       <item row="1" column="3">
+        <layout class="QHBoxLayout" name="horizontalLayout">
          <item>
           <widget class="QLabel" name="mPosPoint1Label">
            <property name="text">
       </widget>
      </item>
      <item>
-      <widget class="QLabel" name="label">
-       <property name="text">
-        <string>Resulting binary image:</string>
+      <widget class="QVTKWidget" name="ProfileWidget" native="true">
+       <property name="minimumSize">
+        <size>
+         <width>0</width>
+         <height>300</height>
+        </size>
+       </property>
+       <property name="mouseTracking">
+        <bool>true</bool>
        </property>
       </widget>
      </item>
-     <item>
-      <layout class="QHBoxLayout" name="horizontalLayout_4">
-       <item>
-        <widget class="QCheckBox" name="mCheckBoxUseFG">
-         <property name="text">
-          <string>Use FG</string>
-         </property>
-         <property name="checked">
-          <bool>false</bool>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="vvIntensityValueSlider" name="mFGSlider" native="true">
-         <property name="enabled">
-          <bool>false</bool>
-         </property>
-        </widget>
-       </item>
-      </layout>
-     </item>
-     <item>
-      <layout class="QHBoxLayout" name="horizontalLayout_5">
-       <item>
-        <widget class="QCheckBox" name="mCheckBoxUseBG">
-         <property name="text">
-          <string>Use BG</string>
-         </property>
-         <property name="checked">
-          <bool>true</bool>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="vvIntensityValueSlider" name="mBGSlider" native="true"/>
-       </item>
-      </layout>
-     </item>
     </layout>
    </item>
-   <item>
-    <widget class="Line" name="line_3">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-    </widget>
-   </item>
-   <item>
-    <widget class="QCheckBox" name="mCheckBoxInteractiveDisplay">
-     <property name="enabled">
-      <bool>true</bool>
-     </property>
-     <property name="text">
-      <string>Interactive (unchek to disable on the fly contours drawing)</string>
-     </property>
-     <property name="checked">
-      <bool>true</bool>
-     </property>
-    </widget>
-   </item>
   </layout>
  </widget>
  <customwidgets>
   <customwidget>
-   <class>vvIntensityValueSlider</class>
+   <class>QVTKWidget</class>
    <extends>QWidget</extends>
-   <header>vvIntensityValueSlider.h</header>
-   <container>1</container>
+   <header>QVTKWidget.h</header>
   </customwidget>
  </customwidgets>
  <resources/>
- <connections>
-  <connection>
-   <sender>mCheckBoxUseBG</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>mBGSlider</receiver>
-   <slot>setEnabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>79</x>
-     <y>203</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>395</x>
-     <y>225</y>
-    </hint>
-   </hints>
-  </connection>
-  <connection>
-   <sender>mCheckBoxUseFG</sender>
-   <signal>toggled(bool)</signal>
-   <receiver>mFGSlider</receiver>
-   <slot>setEnabled(bool)</slot>
-   <hints>
-    <hint type="sourcelabel">
-     <x>63</x>
-     <y>177</y>
-    </hint>
-    <hint type="destinationlabel">
-     <x>242</x>
-     <y>177</y>
-    </hint>
-   </hints>
-  </connection>
- </connections>
+ <connections/>
 </ui>
index 944fea4a290d3255b532f947624187311cac05f9..69a68967b6209f21416124f0f2b02ba4cd769af0 100644 (file)
@@ -6,7 +6,7 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>179</width>
+    <width>194</width>
     <height>62</height>
    </rect>
   </property>
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
-     <widget class="vvToolInputSelectorWidget" name="mToolInputSelectionWidget" native="true"/>
+     <widget class="vvToolInputSelectorWidget" name="mToolInputSelectionWidget" native="true">
+      <property name="maximumSize">
+       <size>
+        <width>16777215</width>
+        <height>200</height>
+       </size>
+      </property>
+     </widget>
      <widget class="QWidget" name="mToolWidget" native="true">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Minimum" vsizetype="Minimum">
index b9c34c9df672aa01fbc0999263112b85120b786c..2e07d61eb6a30cd4c19c5f87b26474585f049fb1 100644 (file)
 #include "vvSlicer.h"
 #include "vvToolInputSelectorWidget.h"
 
-// clitk
-#include "clitkProfileImageGenericFilter.h"
-
 // vtk
 #include <vtkImageActor.h>
 #include <vtkCamera.h>
 #include <vtkImageClip.h>
 #include <vtkRenderWindow.h>
+#include <vtkChartXY.h>
+#include <vtkPlot.h>
+#include <vtkRendererCollection.h>
+#include <vtkRenderer.h>
 
 
 //------------------------------------------------------------------------------
@@ -59,7 +60,6 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
 { 
   // GUI Initialization
   Ui_vvToolProfile::setupUi(mToolWidget);
-  //mInteractiveDisplayIsEnabled = mCheckBoxInteractiveDisplay->isChecked();
 
   // Connect signals & slots
   connect(mSelectPoint1Button, SIGNAL(clicked()), this, SLOT(selectPoint1()));
@@ -68,16 +68,21 @@ vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
   connect(mComputeProfileButton, SIGNAL(clicked()), this, SLOT(computeProfile()));
 
   // Initialize some widget
-  //mThresholdSlider1->SetText("");
-  //mThresholdSlider2->SetText("");
-  //mFGSlider->SetText("Foreground value");
-  //mBGSlider->SetText("Background value");
-  
+  ProfileWidget->hide();
   mPoint1 = NULL;
   mPoint2 = NULL;
   
-  point1Selected = false;
-  point2Selected = false;
+  mPoint1Selected = false;
+  mPoint2Selected = false;
+    
+  mView = vtkSmartPointer<vtkContextView>::New();
+  vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
+  chart->SetAutoSize(false);
+  chart->SetRenderEmpty(true);
+  mView->GetScene()->AddItem(chart);
+  this->ProfileWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems();
+  this->ProfileWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
+  ProfileWidget->show();
 
   // Main filter
   mFilter = clitk::ProfileImageGenericFilter::New();
@@ -99,7 +104,20 @@ vvToolProfile::~vvToolProfile()
 void vvToolProfile::selectPoint1()
 {
   QString position = "";
-  point1Selected = false;
+  
+    if (mPoint1Selected) {
+      ProfileWidget->hide();
+      vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
+      chart->SetAutoSize(false);
+      chart->SetRenderEmpty(true);
+      mView->GetScene()->ClearItems();
+      mView->GetScene()->AddItem(chart);
+      this->ProfileWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems();
+      this->ProfileWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
+      ProfileWidget->show();
+  }
+  
+  mPoint1Selected = false;
   if(mCurrentSlicerManager) {
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
           double *pos;
@@ -114,7 +132,7 @@ void vvToolProfile::selectPoint1()
             position += QString::number(pos[i],'f',1) + " ";
             mPoint1[i] = index[i];
           }
-          point1Selected = true;
+          mPoint1Selected = true;
       }
   }
   mPosPoint1Label->setText(position);
@@ -127,7 +145,20 @@ void vvToolProfile::selectPoint1()
 void vvToolProfile::selectPoint2()
 {
   QString position = "";
-  point2Selected = false;
+  
+  if (mPoint2Selected) {
+      ProfileWidget->hide();
+      vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
+      chart->SetAutoSize(false);
+      chart->SetRenderEmpty(true);
+      mView->GetScene()->ClearItems();
+      mView->GetScene()->AddItem(chart);
+      this->ProfileWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems();
+      this->ProfileWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
+      ProfileWidget->show();
+  }
+  
+  mPoint2Selected = false;
   if(mCurrentSlicerManager) {
       if(mCurrentSlicerManager->GetSelectedSlicer() != -1) {
           double *pos;
@@ -142,7 +173,7 @@ void vvToolProfile::selectPoint2()
             position += QString::number(pos[i],'f',1) + " ";
             mPoint2[i] = index[i];
           }
-          point2Selected = true;
+          mPoint2Selected = true;
       }
   }
   mPosPoint2Label->setText(position);
@@ -153,12 +184,12 @@ void vvToolProfile::selectPoint2()
 //------------------------------------------------------------------------------
 bool vvToolProfile::isPointsSelected()
 {
-  if (point1Selected && point2Selected)
+  if (mPoint1Selected && mPoint2Selected)
       mComputeProfileButton->setEnabled(true);
   else
       mComputeProfileButton->setEnabled(false);
   
-  return (point1Selected && point2Selected);
+  return (mPoint1Selected && mPoint2Selected);
 }
 //------------------------------------------------------------------------------
 
@@ -170,15 +201,43 @@ void vvToolProfile::computeProfile()
 
     QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
     GetArgsInfoFromGUI();
+    ProfileWidget->hide();
     
     // Main filter
-    clitk::ProfileImageGenericFilter::Pointer filter = clitk::ProfileImageGenericFilter::New();
-    filter->SetInputVVImage(mCurrentImage);
-    filter->SetArgsInfo(mArgsInfo);
-    filter->Update();
+    mFilter->SetInputVVImage(mCurrentImage);
+    mFilter->SetArgsInfo(mArgsInfo);
+    mFilter->Update();
     
-    QApplication::restoreOverrideCursor();
+    vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
+    vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
+    vtkSmartPointer<vtkFloatArray> arrY = vtkSmartPointer<vtkFloatArray>::New();
+    arrX = mFilter->GetArrayX();
+    arrY = mFilter->GetArrayY();
+    arrX->SetName("Voxel");
+    arrY->SetName("Intensity");
+    table->AddColumn(arrX);
+    table->AddColumn(arrY);
+    
+    mView->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
  
+    vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
+    chart->SetAutoSize(true);
+    mView->GetScene()->ClearItems();
+    mView->GetScene()->AddItem(chart);
+    vtkPlot *line = chart->AddPlot(vtkChart::LINE);
+#if VTK_MAJOR_VERSION <= 5
+    line->SetInput(table, 0, 1);
+#else
+    line->SetInputData(table, 0, 1);
+#endif
+    line->SetColor(0, 255, 0, 255);
+    line->SetWidth(1.0);
+    
+    this->ProfileWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems();
+    this->ProfileWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
+    ProfileWidget->show();
+    
+    QApplication::restoreOverrideCursor();
 }
 //------------------------------------------------------------------------------
 
@@ -186,43 +245,30 @@ void vvToolProfile::computeProfile()
 //------------------------------------------------------------------------------
 void vvToolProfile::cancelPoints()
 { 
+  ProfileWidget->hide();
+  vtkSmartPointer<vtkChartXY> chart = vtkSmartPointer<vtkChartXY>::New();
+  chart->SetAutoSize(false);
+  chart->SetRenderEmpty(true);
+  mView->GetScene()->ClearItems();
+  mView->GetScene()->AddItem(chart);
+  this->ProfileWidget->GetRenderWindow()->GetRenderers()->RemoveAllItems();
+  this->ProfileWidget->GetRenderWindow()->AddRenderer(mView->GetRenderer());
+  ProfileWidget->show();
+  
   QString position = "";
   mPosPoint1Label->setText(position);
   mPosPoint2Label->setText(position);
-  point1Selected = false;
-  point2Selected = false;
+  mPoint1Selected = false;
+  mPoint2Selected = false;
   mComputeProfileButton->setEnabled(false);
   isPointsSelected();
 }
 //------------------------------------------------------------------------------
 
 
-//------------------------------------------------------------------------------
-void vvToolProfile::InteractiveDisplayToggled(bool b)
-{ 
-  /*mInteractiveDisplayIsEnabled = b;
-  if (!mInteractiveDisplayIsEnabled) {
-    RemoveVTKObjects();
-  } else {
-    for(unsigned int i=0; i<mImageContour.size(); i++) {
-      mImageContour[i]->ShowActors();
-      if (mRadioButtonLowerThan->isChecked())
-        mImageContourLower[i]->ShowActors();
-    }
-    if (mCurrentSlicerManager)
-      mCurrentSlicerManager->Render();
-  }*/  
-}
-//------------------------------------------------------------------------------
-
-
 //------------------------------------------------------------------------------
 void vvToolProfile::RemoveVTKObjects()
 { 
-  for(unsigned int i=0; i<mImageContour.size(); i++) {
-    mImageContour[i]->HideActors();
-    mImageContourLower[i]->HideActors();    
-  }
   if (mCurrentSlicerManager)
     mCurrentSlicerManager->Render();
 }
@@ -260,40 +306,6 @@ void vvToolProfile::reject()
 
 
 //------------------------------------------------------------------------------
-void vvToolProfile::enableLowerThan(bool b)
-{ 
-  /*if (!b) {
-    mThresholdSlider1->resetMaximum();
-    for(unsigned int i=0; i<mImageContour.size(); i++) {
-      mImageContourLower[i]->HideActors();    
-    }
-    mCurrentSlicerManager->Render();
-  } else {
-    valueChangedT1(mThresholdSlider1->GetValue());
-    valueChangedT2(mThresholdSlider2->GetValue());
-    for(unsigned int i=0; i<mImageContour.size(); i++) {
-      mImageContourLower[i]->ShowActors();    
-    }
-    mCurrentSlicerManager->Render();
-  }*/
-}
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-void vvToolProfile::useFGBGtoggled(bool)
-{ 
-  if (!mCheckBoxUseBG->isChecked() && !mCheckBoxUseFG->isChecked())
-    mCheckBoxUseBG->toggle();
-}
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-// void vvToolProfile::InputIsSelected(std::vector<vvSlicerManager *> & m) {
-//   DD("vvToolProfile::InputIsSelected vector in Profile");
-//   DD(m.size());
-// }
 void vvToolProfile::InputIsSelected(vvSlicerManager * m)
 { 
   mCurrentSlicerManager = m;
@@ -302,93 +314,9 @@ void vvToolProfile::InputIsSelected(vvSlicerManager * m)
   mPoint2 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
   
   mComputeProfileButton->setEnabled(false);
-
-  // Specific for this gui
-  //mThresholdSlider1->SetValue(0);
-  //mThresholdSlider2->SetValue(0);
-  //mThresholdSlider1->SetImage(mCurrentImage);
-  //mThresholdSlider2->SetImage(mCurrentImage);
-  //mFGSlider->SetImage(mCurrentImage);
-  //mBGSlider->SetImage(mCurrentImage);
-  //  DD(mCurrentSlicerManager->GetFileName().c_str());
-  //  mFGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
-  //   mFGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
-  //   mBGSlider->SetMaximum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMax());
-  //   mBGSlider->SetMinimum(mCurrentImage->GetFirstVTKImageData()->GetScalarTypeMin());
-
-  // Output is uchar ...
-  /*mFGSlider->SetMaximum(255);
-  mFGSlider->SetMinimum(0);
-  mBGSlider->SetMaximum(255);
-  mBGSlider->SetMinimum(0);
-
-  mFGSlider->SetValue(1);
-  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());
-    mImageContour[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
-    mImageContour[i]->SetColor(1.0, 0.0, 0.0);
-    mImageContour[i]->SetDepth(0); // to be in front of (whe used with ROI tool)
-    mImageContourLower.push_back(vvImageContour::New());
-    mImageContourLower[i]->SetSlicer(mCurrentSlicerManager->GetSlicer(i));
-    mImageContourLower[i]->SetColor(0.0, 0.0, 1.0);
-    mImageContourLower[i]->SetDepth(100); // to be in front of (whe used with ROI tool)
-  }
-  //valueChangedT1(mThresholdSlider1->GetValue());
-
-  //connect(mThresholdSlider1, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT1(double)));
-  //connect(mThresholdSlider2, SIGNAL(valueChanged(double)), this, SLOT(valueChangedT2(double)));
-
-  //connect(mCurrentSlicerManager,SIGNAL(UpdateSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
-  //connect(mCurrentSlicerManager,SIGNAL(UpdateTSlice(int,int)),this,SLOT(UpdateSlice(int, int)));
-  
-  //connect(mCurrentSlicerManager,SIGNAL(UpdateOrientation(int,int)),this,SLOT(UpdateOrientation(int, int)));
-
-  //  connect(mCurrentSlicerManager, SIGNAL(LeftButtonReleaseSignal(int)), SLOT(LeftButtonReleaseEvent(int)));
-  InteractiveDisplayToggled(mInteractiveDisplayIsEnabled); */
-}
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-// void vvToolProfile::LeftButtonReleaseEvent(int slicer) {
-//   DD("LeftButtonReleaseEvent");
-//   for(int i=0; i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
-//     if (i == slicer);
-//     mCurrentSlicerManager->GetSlicer(i)->GetRenderWindow()->Render();
-//   }
-// }
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-void vvToolProfile::UpdateOrientation(int slicer,int orientation)
-{ 
-  Update(slicer);
-}
-//------------------------------------------------------------------------------
-
-//------------------------------------------------------------------------------
-void vvToolProfile::UpdateSlice(int slicer,int slices)
-{ 
-  Update(slicer);
 }
 //------------------------------------------------------------------------------
 
-//------------------------------------------------------------------------------
-void vvToolProfile::Update(int slicer)
-{ 
-  //if (!mInteractiveDisplayIsEnabled) return;
-  if (!mCurrentSlicerManager) close();
-  //mImageContour[slicer]->Update(mThresholdSlider1->GetValue());
-  //if (mRadioButtonLowerThan->isChecked()) 
-  //  mImageContourLower[slicer]->Update(mThresholdSlider2->GetValue());
-}
-//------------------------------------------------------------------------------
 
 //------------------------------------------------------------------------------
 void vvToolProfile::GetArgsInfoFromGUI()
@@ -405,34 +333,7 @@ void vvToolProfile::GetArgsInfoFromGUI()
      DD(good);
   */
   cmdline_parser_clitkProfileImage_init(&mArgsInfo); // Initialisation to default
-  //bool inverseBGandFG = false;
-
-  //mArgsInfo.lower_given = 1;
-  /*mArgsInfo.lower_arg = mThresholdSlider1->GetValue();
-  if (mRadioButtonLowerThan->isChecked()) {
-    mArgsInfo.upper_given = 1;
-    mArgsInfo.upper_arg = mThresholdSlider2->GetValue();
-    if (mArgsInfo.upper_arg<mArgsInfo.lower_arg) {
-      mArgsInfo.upper_given = 0;
-      DD("TODO : lower thres greater than greater thres ! Ignoring ");
-    }
-  }
-
-  mArgsInfo.fg_arg = mFGSlider->GetValue();
-  mArgsInfo.bg_arg = mBGSlider->GetValue();
 
-  if (inverseBGandFG) {
-    mArgsInfo.fg_arg = mFGSlider->GetValue();
-    mArgsInfo.bg_arg = mBGSlider->GetValue();
-  }
-  mArgsInfo.fg_given = 1;
-  mArgsInfo.bg_given = 1;
-
-  if (mCheckBoxUseBG->isChecked()) {
-    if (mCheckBoxUseFG->isChecked()) mArgsInfo.mode_arg = (char*)"both";
-    else mArgsInfo.mode_arg = (char*)"BG";
-  } else mArgsInfo.mode_arg = (char*)"FG";
-*/
   mArgsInfo.verbose_flag = false;
   
   mArgsInfo.point1_arg = mPoint1;
@@ -453,56 +354,52 @@ void vvToolProfile::GetArgsInfoFromGUI()
 //------------------------------------------------------------------------------
 void vvToolProfile::apply()
 { 
-  if (!mCurrentSlicerManager) close();
+  if (!mCurrentSlicerManager || !isPointsSelected()) {
+      close();
+      return;
+  }
+  
   QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
-  GetArgsInfoFromGUI();  
+
+  // Output
+  std::string fileName = "Profiled_" + mCurrentSlicerManager->GetSlicer(0)->GetFileName() + ".txt";
+  ofstream fileOpen(fileName.c_str(), std::ofstream::trunc);
   
-  // Main filter
-  clitk::ProfileImageGenericFilter::Pointer filter =
-    clitk::ProfileImageGenericFilter::New();
-  filter->SetInputVVImage(mCurrentImage);
-  filter->SetArgsInfo(mArgsInfo);
-  filter->Update();
+  if(!fileOpen) {
+    cerr << "Error during saving" << endl;
+    QApplication::restoreOverrideCursor();
+    close();
+    
+    return;
+  }
+  vtkSmartPointer<vtkFloatArray> arrX = vtkSmartPointer<vtkFloatArray>::New();
+  vtkSmartPointer<vtkFloatArray> arrY = vtkSmartPointer<vtkFloatArray>::New();
+  vtkSmartPointer<vtkFloatArray> coords = vtkSmartPointer<vtkFloatArray>::New();
+  arrX = mFilter->GetArrayX();
+  arrY = mFilter->GetArrayY();
+  coords = mFilter->GetCoord();
+  double *tuple;
+  tuple = new double[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+  int i(0);
+   
+  while (i<arrX->GetNumberOfTuples()) {
+      fileOpen << arrX->GetTuple(i)[0] << "\t" << arrY->GetTuple(i)[0] << "\t" ;
+      
+      coords->GetTuple(i, tuple);
+      for (int j=0; j<mCurrentSlicerManager->GetImage()->GetNumberOfDimensions() ; ++j) {
+          fileOpen << tuple[j] << "\t" ;
+      }
+      fileOpen << endl;
+      ++i;
+  }
+  
+  delete [] tuple;
 
+  fileOpen.close();
 
-  // Output
-  vvImage::Pointer output = filter->GetOutputVVImage();  
-  std::ostringstream osstream;
-  osstream << "Profiled_" << mCurrentSlicerManager->GetSlicer(0)->GetFileName() << ".mhd";
-  AddImage(output,osstream.str());
   QApplication::restoreOverrideCursor();
   close();
 }
 //------------------------------------------------------------------------------
 
 
-//------------------------------------------------------------------------------
-void vvToolProfile::valueChangedT2(double v)
-{ 
-  /*//  DD("valueChangedT2");
-  if (mRadioButtonLowerThan->isChecked()) {
-    mThresholdSlider1->SetMaximum(v);
-    if (!mInteractiveDisplayIsEnabled) return;
-    for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
-      mImageContourLower[i]->Update(v);
-    }
-    mCurrentSlicerManager->Render();
-  }*/
-}
-//------------------------------------------------------------------------------
-
-
-//------------------------------------------------------------------------------
-void vvToolProfile::valueChangedT1(double v)
-{ 
-  /*//  DD("valueChangedT1");
-  if (!mCurrentSlicerManager) close();
-  mThresholdSlider2->SetMinimum(v);
-  //  int m1 = (int)lrint(v);
-  if (!mInteractiveDisplayIsEnabled) return;
-  for(int i=0;i<mCurrentSlicerManager->GetNumberOfSlicers(); i++) {
-    mImageContour[i]->Update(v);
-  }
-  mCurrentSlicerManager->Render();*/
-}
-//------------------------------------------------------------------------------
index ecccf06f5abe4737c8a280af93f666762b9f9377..072dc3aafcc2175d91ada9bd72d8e86028eb8a14 100644 (file)
 #include "ui_vvToolProfile.h"
 
 #include "clitkProfileImage_ggo.h"
+#include "clitkProfileImageGenericFilter.h"
+#include <vtkTable.h>
+#include <vtkContextView.h>
+#include <vtkContextScene.h>
 
 //------------------------------------------------------------------------------
 class vvToolProfile:
@@ -50,14 +54,6 @@ class vvToolProfile:
   virtual void apply();
   virtual bool close();
   virtual void reject();
-  void valueChangedT1(double v);
-  void valueChangedT2(double v);
-  void UpdateOrientation(int slicer, int orientation);
-  void UpdateSlice(int slicer,int slices);
-  void enableLowerThan(bool b);
-  void useFGBGtoggled(bool);
-  void InteractiveDisplayToggled(bool b);
-  //  void LeftButtonReleaseEvent(int slicer);
   
   void selectPoint1();
   void selectPoint2();
@@ -69,16 +65,14 @@ class vvToolProfile:
   virtual void closeEvent(QCloseEvent *event);
   Ui::vvToolProfile ui;
   args_info_clitkProfileImage mArgsInfo;
-  std::vector<vvImageContour::Pointer> mImageContour;
-  std::vector<vvImageContour::Pointer> mImageContourLower;
-  bool mInteractiveDisplayIsEnabled;
   
   int* mPoint1;
   int* mPoint2;
-  bool point1Selected;
-  bool point2Selected;
-  
-  void Update(int slicer);
+  bool mPoint1Selected;
+  bool mPoint2Selected;
+  vtkSmartPointer<vtkContextView> mView;
+  clitk::ProfileImageGenericFilter::Pointer mFilter;
+
 
 }; // end class vvToolProfile
 //------------------------------------------------------------------------------