]> Creatis software - clitk.git/commitdiff
Merge branch 'VTK6_Qt5_Profile' into VTK6_Qt5
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 4 Jan 2016 07:51:54 +0000 (08:51 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 4 Jan 2016 07:51:54 +0000 (08:51 +0100)
12 files changed:
tools/CMakeLists.txt
tools/clitkProfileImage.cxx [new file with mode: 0644]
tools/clitkProfileImage.ggo [new file with mode: 0644]
tools/clitkProfileImageGenericFilter.cxx [new file with mode: 0644]
tools/clitkProfileImageGenericFilter.h [new file with mode: 0644]
vv/CMakeLists.txt
vv/icons/profile.png [new file with mode: 0644]
vv/qt_ui/vvToolProfile.ui [new file with mode: 0644]
vv/qt_ui/vvToolWidgetBase.ui
vv/vvIcons.qrc
vv/vvToolProfile.cxx [new file with mode: 0644]
vv/vvToolProfile.h [new file with mode: 0644]

index 3bf89482b7c98064a3fc9a5ba1f975f2009f7806..fbab5f54cfd300f8eb61f1780f30565328020af9 100644 (file)
@@ -9,6 +9,9 @@ add_library(clitkImageConvertLib clitkImageConvertGenericFilter.cxx ${clitkImage
 WRAP_GGO(clitkBinarizeImage_GGO_C clitkBinarizeImage.ggo)
 add_library(clitkBinarizeImageLib clitkBinarizeImageGenericFilter.cxx ${clitkBinarizeImage_GGO_C})
 
+WRAP_GGO(clitkProfileImage_GGO_C clitkProfileImage.ggo)
+add_library(clitkProfileImageLib clitkProfileImageGenericFilter.cxx ${clitkProfileImage_GGO_C})
+
 WRAP_GGO(clitkImageArithm_GGO_C clitkImageArithm.ggo)
 add_library(clitkImageArithmImageLib clitkImageArithmGenericFilter.cxx ${clitkImageArithm_GGO_C})
 
@@ -58,6 +61,10 @@ if(CLITK_BUILD_TOOLS)
   add_executable(clitkBinarizeImage clitkBinarizeImage.cxx)
   target_link_libraries(clitkBinarizeImage clitkBinarizeImageLib clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkBinarizeImage)
+  
+  add_executable(clitkProfileImage clitkProfileImage.cxx)
+  target_link_libraries(clitkProfileImage clitkProfileImageLib clitkCommon)
+  set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkProfileImage)
 
   WRAP_GGO(clitkVFResample_GGO_C clitkVFResample.ggo)
   add_executable(clitkVFResample clitkVFResample.cxx clitkVFResampleGenericFilter.cxx ${clitkVFResample_GGO_C})
diff --git a/tools/clitkProfileImage.cxx b/tools/clitkProfileImage.cxx
new file mode 100644 (file)
index 0000000..c8332c9
--- /dev/null
@@ -0,0 +1,41 @@
+/*=========================================================================
+  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://www.centreleonberard.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
+===========================================================================**/
+
+// clitk
+#include "clitkProfileImage_ggo.h"
+#include "clitkProfileImageGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[])
+{
+
+  // Init command line
+  GGO(clitkProfileImage, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::ProfileImageGenericFilter FilterType;
+  FilterType::Pointer filter = FilterType::New();
+
+  filter->SetArgsInfo(args_info);
+
+  CLITK_TRY_CATCH_EXIT(filter->Update());
+
+  return EXIT_SUCCESS;
+} // This is the end, my friend
+//--------------------------------------------------------------------
diff --git a/tools/clitkProfileImage.ggo b/tools/clitkProfileImage.ggo
new file mode 100644 (file)
index 0000000..7714e18
--- /dev/null
@@ -0,0 +1,16 @@
+#File clitkProfileImage.ggo
+package "clitkProfileImage"
+version "1.0"
+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 "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)
+
+
+
diff --git a/tools/clitkProfileImageGenericFilter.cxx b/tools/clitkProfileImageGenericFilter.cxx
new file mode 100644 (file)
index 0000000..1eb58c2
--- /dev/null
@@ -0,0 +1,159 @@
+/*=========================================================================
+  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://www.centreleonberard.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 clitkProfileImageGenericFilter_cxx
+#define clitkProfileImageGenericFilter_cxx
+
+/* =================================================
+ * @file   clitkProfileImageGenericFilter.cxx
+ * @author Thomas Baudier <thomas.baudier@creatis.insa-lyon.fr>
+ * @date   22 dec 2015
+ *
+ * @brief
+ *
+ ===================================================*/
+
+#include "clitkProfileImageGenericFilter.h"
+
+// itk include
+#include <itkLineIterator.h>
+
+#include <clitkCommon.h>
+
+
+
+namespace clitk
+{
+
+//--------------------------------------------------------------------
+ProfileImageGenericFilter::ProfileImageGenericFilter():
+  ImageToImageGenericFilter<Self>("ProfileImage")
+{
+  InitializeImageType<2>();
+  InitializeImageType<3>();
+  InitializeImageType<4>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<unsigned int Dim>
+void ProfileImageGenericFilter::InitializeImageType()
+{
+  ADD_DEFAULT_IMAGE_TYPES(Dim);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+vtkFloatArray* ProfileImageGenericFilter::GetArrayX()
+{
+  return(mArrayX);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+vtkFloatArray* ProfileImageGenericFilter::GetArrayY()
+{
+  return(mArrayY);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+vtkFloatArray* ProfileImageGenericFilter::GetCoord()
+{
+  return(mCoord);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+void ProfileImageGenericFilter::SetArgsInfo(const args_info_type & a)
+{
+  mArgsInfo=a;
+  if (mArgsInfo.verbose_given)
+    SetIOVerbose(mArgsInfo.verbose_flag);
+  if (mArgsInfo.imagetypes_given && mArgsInfo.imagetypes_flag)
+    this->PrintAvailableImageTypes();
+
+  if (mArgsInfo.input_given) {
+    SetInputFilename(mArgsInfo.input_arg);
+  }
+  if (mArgsInfo.output_given) {
+    SetOutputFilename(mArgsInfo.output_arg);
+  }
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class InputImageType>
+void
+ProfileImageGenericFilter::UpdateWithInputImageType()
+{
+
+  // Reading input
+  typename InputImageType::Pointer input = this->template GetInput<InputImageType>(0);
+  typedef typename InputImageType::PixelType PixelType;
+  typedef typename InputImageType::IndexType IndexType;
+
+  mArrayX = vtkSmartPointer<vtkFloatArray>::New();
+  mArrayY = vtkSmartPointer<vtkFloatArray>::New();
+  mCoord = vtkSmartPointer<vtkFloatArray>::New();
+  mCoord->SetNumberOfComponents(InputImageType::ImageDimension);
+  
+  //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();
+  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;
+  }
+  
+  delete [] tuple;
+}
+//--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif  //#define clitkProfileImageGenericFilter_cxx
diff --git a/tools/clitkProfileImageGenericFilter.h b/tools/clitkProfileImageGenericFilter.h
new file mode 100644 (file)
index 0000000..573a41c
--- /dev/null
@@ -0,0 +1,79 @@
+/*=========================================================================
+  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://www.centreleonberard.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 clitkProfileImageGenericFilter_h
+#define clitkProfileImageGenericFilter_h
+
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+#include "clitkProfileImage_ggo.h"
+
+#include <vtkIntArray.h>
+#include <vtkFloatArray.h>
+
+//--------------------------------------------------------------------
+namespace clitk 
+{
+  
+  class ITK_EXPORT ProfileImageGenericFilter: 
+    public ImageToImageGenericFilter<ProfileImageGenericFilter>
+  {
+    
+  public:
+    //--------------------------------------------------------------------
+    typedef ProfileImageGenericFilter         Self;
+    typedef itk::SmartPointer<Self>           Pointer;
+    typedef itk::SmartPointer<const Self>     ConstPointer;
+    typedef args_info_clitkProfileImage       args_info_type;
+   
+    //--------------------------------------------------------------------
+    // Method for creation through the object factory
+    // and Run-time type information (and related methods)
+    itkNewMacro(Self);  
+    itkTypeMacro(ProfileImageGenericFilter, LightObject);
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const args_info_type & a);
+
+    //--------------------------------------------------------------------
+    // 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
+  //--------------------------------------------------------------------
+    
+} // end namespace clitk
+//--------------------------------------------------------------------
+
+#endif // #define clitkProfileImageGenericFilter_h
index 5b849910908a215da9e0057fd69f645f3138e21a..4b0932de656d8fd004d1df5edc918fec74851d67 100644 (file)
@@ -21,6 +21,7 @@ set(vv_TOOLS
   vvToolConvert ## with dummy vvToolConvert.ui
   vvToolROIManager
   vvToolSegmentation
+  vvToolProfile
   ## these ones are for tests (not working)
   # vvToolTest
   # vvToolFoo
@@ -36,6 +37,7 @@ set(vv_TOOLS
 # Future issues : when tool depend on other tools ... how to manage that ?
 #  >> add the relevant $_LIBS variable to the tool that has dependencies?
 set(vvToolBinarize_LIBS clitkBinarizeImageLib)
+set(vvToolProfile_LIBS clitkProfileImageLib)
 set(vvToolResample_LIBS clitkResampleImageLib)
 set(vvToolConvert_LIBS clitkImageConvertLib)
 set(vvToolExtractPatient_LIBS clitkSegmentationGgoLib)
diff --git a/vv/icons/profile.png b/vv/icons/profile.png
new file mode 100644 (file)
index 0000000..656113a
Binary files /dev/null and b/vv/icons/profile.png differ
diff --git a/vv/qt_ui/vvToolProfile.ui b/vv/qt_ui/vvToolProfile.ui
new file mode 100644 (file)
index 0000000..f9edb6d
--- /dev/null
@@ -0,0 +1,145 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>vvToolProfile</class>
+ <widget class="QWidget" name="vvToolProfile">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>437</width>
+    <height>452</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Profile image</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout_3">
+     <item>
+      <layout class="QGridLayout" name="gridLayout_2">
+       <property name="horizontalSpacing">
+        <number>6</number>
+       </property>
+       <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">
+            <string>Point2 (mm): </string>
+           </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">
+            <string/>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item row="3" column="3">
+        <layout class="QHBoxLayout" name="horizontalLayout_6">
+         <item>
+          <widget class="QToolButton" name="mCancelPointsButton">
+           <property name="text">
+            <string>Cancel</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <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>Compute Profile</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <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">
+            <string>Point1 (mm): </string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item row="1" column="3">
+        <layout class="QHBoxLayout" name="horizontalLayout">
+         <item>
+          <widget class="QLabel" name="mPosPoint1Label">
+           <property name="text">
+            <string/>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </item>
+    </layout>
+   </item>
+   <item>
+    <layout class="QVBoxLayout" name="verticalLayout_2">
+     <item>
+      <widget class="Line" name="line_2">
+       <property name="orientation">
+        <enum>Qt::Horizontal</enum>
+       </property>
+      </widget>
+     </item>
+     <item>
+      <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>
+    </layout>
+   </item>
+  </layout>
+ </widget>
+ <customwidgets>
+  <customwidget>
+   <class>QVTKWidget</class>
+   <extends>QWidget</extends>
+   <header>QVTKWidget.h</header>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <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 15a864843ba26c5767d6a665b72bd65063f245ca..e1604607aa8af0e2f57effbd728d23a04408047c 100644 (file)
@@ -12,6 +12,7 @@
     <file>icons/8b.png</file>
     <file>icons/1b.png</file>
     <file>icons/binarize.png</file>
+    <file>icons/profile.png</file>
     <file>icons/resample.png</file>
     <file>icons/crop.png</file>
     <file>icons/splashscreen2.png</file>
diff --git a/vv/vvToolProfile.cxx b/vv/vvToolProfile.cxx
new file mode 100644 (file)
index 0000000..2e07d61
--- /dev/null
@@ -0,0 +1,405 @@
+/*=========================================================================
+  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://www.centreleonberard.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 "vvToolProfile.h"
+#include "vvSlicerManager.h"
+#include "vvSlicer.h"
+#include "vvToolInputSelectorWidget.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>
+
+
+//------------------------------------------------------------------------------
+// Create the tool and automagically (I like this word) insert it in
+// the main window menu.
+ADD_TOOL(vvToolProfile);
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::Initialize()
+{ 
+  SetToolName("Profile");
+  SetToolMenuName("Intensity Profile");
+  SetToolIconFilename(":/common/icons/profile.png");
+  SetToolTip("Display the intensity profile between 2 points of the image.");
+  SetToolExperimental(false);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolProfile::vvToolProfile(vvMainWindowBase * parent, Qt::WindowFlags f)
+  :vvToolWidgetBase(parent,f),
+   vvToolBase<vvToolProfile>(parent),
+   Ui::vvToolProfile()
+{ 
+  // GUI Initialization
+  Ui_vvToolProfile::setupUi(mToolWidget);
+
+  // Connect signals & slots
+  connect(mSelectPoint1Button, SIGNAL(clicked()), this, SLOT(selectPoint1()));
+  connect(mSelectPoint2Button, SIGNAL(clicked()), this, SLOT(selectPoint2()));
+  connect(mCancelPointsButton, SIGNAL(clicked()), this, SLOT(cancelPoints()));
+  connect(mComputeProfileButton, SIGNAL(clicked()), this, SLOT(computeProfile()));
+
+  // Initialize some widget
+  ProfileWidget->hide();
+  mPoint1 = NULL;
+  mPoint2 = NULL;
+  
+  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();
+
+  // Set how many inputs are needed for this tool
+  AddInputSelector("Select one image", mFilter);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolProfile::~vvToolProfile()
+{ 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::selectPoint1()
+{
+  QString position = "";
+  
+    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;
+          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];
+            
+            position += QString::number(pos[i],'f',1) + " ";
+            mPoint1[i] = index[i];
+          }
+          mPoint1Selected = true;
+      }
+  }
+  mPosPoint1Label->setText(position);
+  isPointsSelected();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::selectPoint2()
+{
+  QString position = "";
+  
+  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;
+          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];
+            
+            position += QString::number(pos[i],'f',1) + " ";
+            mPoint2[i] = index[i];
+          }
+          mPoint2Selected = true;
+      }
+  }
+  mPosPoint2Label->setText(position);
+  isPointsSelected();
+}
+//------------------------------------------------------------------------------
+
+//------------------------------------------------------------------------------
+bool vvToolProfile::isPointsSelected()
+{
+  if (mPoint1Selected && mPoint2Selected)
+      mComputeProfileButton->setEnabled(true);
+  else
+      mComputeProfileButton->setEnabled(false);
+  
+  return (mPoint1Selected && mPoint2Selected);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::computeProfile()
+{
+    if (!mCurrentSlicerManager) close();
+
+    QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+    GetArgsInfoFromGUI();
+    ProfileWidget->hide();
+    
+    // Main filter
+    mFilter->SetInputVVImage(mCurrentImage);
+    mFilter->SetArgsInfo(mArgsInfo);
+    mFilter->Update();
+    
+    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();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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);
+  mPoint1Selected = false;
+  mPoint2Selected = false;
+  mComputeProfileButton->setEnabled(false);
+  isPointsSelected();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::RemoveVTKObjects()
+{ 
+  if (mCurrentSlicerManager)
+    mCurrentSlicerManager->Render();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+bool vvToolProfile::close()
+{ 
+  // RemoveVTKObjects();
+  return vvToolWidgetBase::close();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::closeEvent(QCloseEvent *event)
+{ 
+  RemoveVTKObjects();
+  event->accept();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::reject()
+{ 
+  // DD("vvToolProfile::reject");
+  RemoveVTKObjects();
+  delete [] mPoint1;
+  delete [] mPoint2;
+  return vvToolWidgetBase::reject();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::InputIsSelected(vvSlicerManager * m)
+{ 
+  mCurrentSlicerManager = m;
+
+  mPoint1 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+  mPoint2 = new int[mCurrentSlicerManager->GetImage()->GetNumberOfDimensions()];
+  
+  mComputeProfileButton->setEnabled(false);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::GetArgsInfoFromGUI()
+{ 
+
+  /* //KEEP THIS FOR READING GGO FROM FILE
+     int argc=1;
+     std::string a = "toto";
+     char * const* argv = new char*;
+     //a.c_str();
+     struct cmdline_parser_params p;
+     p.check_required = 0;
+     int good = cmdline_parser_ext(argc, argv, &args_info, &p);
+     DD(good);
+  */
+  cmdline_parser_clitkProfileImage_init(&mArgsInfo); // Initialisation to default
+
+  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;
+
+  mArgsInfo.input_arg = new char;
+  mArgsInfo.output_arg = new char;
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::apply()
+{ 
+  if (!mCurrentSlicerManager || !isPointsSelected()) {
+      close();
+      return;
+  }
+  
+  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+
+  // Output
+  std::string fileName = "Profiled_" + mCurrentSlicerManager->GetSlicer(0)->GetFileName() + ".txt";
+  ofstream fileOpen(fileName.c_str(), std::ofstream::trunc);
+  
+  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();
+
+  QApplication::restoreOverrideCursor();
+  close();
+}
+//------------------------------------------------------------------------------
+
+
diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h
new file mode 100644 (file)
index 0000000..072dc3a
--- /dev/null
@@ -0,0 +1,81 @@
+/*=========================================================================
+  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://www.centreleonberard.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 VVTOOLPROFILE_H
+#define VVTOOLPROFILE_H
+
+#include <QtUiPlugin/QDesignerExportWidget>
+
+#include "vvToolBase.h"
+#include "vvToolWidgetBase.h"
+#include "vvImageContour.h"
+#include "ui_vvToolProfile.h"
+
+#include "clitkProfileImage_ggo.h"
+#include "clitkProfileImageGenericFilter.h"
+#include <vtkTable.h>
+#include <vtkContextView.h>
+#include <vtkContextScene.h>
+
+//------------------------------------------------------------------------------
+class vvToolProfile:
+  public vvToolWidgetBase,
+  public vvToolBase<vvToolProfile>, 
+  private Ui::vvToolProfile
+{
+  Q_OBJECT
+    public:
+  vvToolProfile(vvMainWindowBase * parent=0, Qt::WindowFlags f=0);
+  ~vvToolProfile();
+
+  //-----------------------------------------------------
+  static void Initialize();
+  void GetArgsInfoFromGUI();
+  virtual void InputIsSelected(vvSlicerManager * m);
+
+  bool isPointsSelected();
+
+  //-----------------------------------------------------
+  public slots:
+  virtual void apply();
+  virtual bool close();
+  virtual void reject();
+  
+  void selectPoint1();
+  void selectPoint2();
+  void cancelPoints();
+  void computeProfile();
+
+ protected:
+  void RemoveVTKObjects();
+  virtual void closeEvent(QCloseEvent *event);
+  Ui::vvToolProfile ui;
+  args_info_clitkProfileImage mArgsInfo;
+  
+  int* mPoint1;
+  int* mPoint2;
+  bool mPoint1Selected;
+  bool mPoint2Selected;
+  vtkSmartPointer<vtkContextView> mView;
+  clitk::ProfileImageGenericFilter::Pointer mFilter;
+
+
+}; // end class vvToolProfile
+//------------------------------------------------------------------------------
+
+#endif
+