]> Creatis software - clitk.git/commitdiff
Creation of the Profile Tool
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 22 Dec 2015 14:07:01 +0000 (15:07 +0100)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Tue, 22 Dec 2015 14:07:01 +0000 (15:07 +0100)
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/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..1894af6
--- /dev/null
@@ -0,0 +1,19 @@
+#File clitkProfileImage.ggo
+package "clitkProfileImage"
+version "1.0"
+purpose ""
+
+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 "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"
+
+
diff --git a/tools/clitkProfileImageGenericFilter.cxx b/tools/clitkProfileImageGenericFilter.cxx
new file mode 100644 (file)
index 0000000..8229815
--- /dev/null
@@ -0,0 +1,144 @@
+/*=========================================================================
+  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 "itkBinaryThresholdImageFilter.h"
+#include "itkMaskImageFilter.h"
+#include "itkMaskNegatedImageFilter.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);
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+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);
+
+  // Main filter
+  typedef typename InputImageType::PixelType PixelType;
+  typedef itk::Image<uchar, InputImageType::ImageDimension> OutputImageType;
+
+  // 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);
+  }
+}
+//--------------------------------------------------------------------
+
+
+}//end clitk
+
+#endif  //#define clitkProfileImageGenericFilter_cxx
diff --git a/tools/clitkProfileImageGenericFilter.h b/tools/clitkProfileImageGenericFilter.h
new file mode 100644 (file)
index 0000000..e251ff5
--- /dev/null
@@ -0,0 +1,66 @@
+/*=========================================================================
+  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"
+
+//--------------------------------------------------------------------
+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();
+
+  protected:
+    ProfileImageGenericFilter();
+    template<unsigned int Dim> void InitializeImageType();
+    args_info_type mArgsInfo;
+    
+  }; // 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..b4cdb44
--- /dev/null
@@ -0,0 +1,189 @@
+<?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>433</width>
+    <height>222</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">
+       <item row="2" column="2">
+        <widget class="vvIntensityValueSlider" name="mThresholdSlider2" native="true">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QLabel" name="label_2">
+         <property name="text">
+          <string>Foreground (FG) is greater than : </string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="2">
+        <widget class="vvIntensityValueSlider" name="mThresholdSlider1" native="true"/>
+       </item>
+       <item row="2" column="1">
+        <widget class="QRadioButton" name="mRadioButtonLowerThan">
+         <property name="text">
+          <string>and lower than</string>
+         </property>
+         <property name="autoExclusive">
+          <bool>false</bool>
+         </property>
+        </widget>
+       </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="QLabel" name="label">
+       <property name="text">
+        <string>Resulting binary image:</string>
+       </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>
+   <extends>QWidget</extends>
+   <header>vvIntensityValueSlider.h</header>
+   <container>1</container>
+  </customwidget>
+ </customwidgets>
+ <resources/>
+ <connections>
+  <connection>
+   <sender>mRadioButtonLowerThan</sender>
+   <signal>toggled(bool)</signal>
+   <receiver>mThresholdSlider2</receiver>
+   <slot>setEnabled(bool)</slot>
+   <hints>
+    <hint type="sourcelabel">
+     <x>85</x>
+     <y>129</y>
+    </hint>
+    <hint type="destinationlabel">
+     <x>305</x>
+     <y>129</y>
+    </hint>
+   </hints>
+  </connection>
+  <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>
+</ui>
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..164b992
--- /dev/null
@@ -0,0 +1,388 @@
+/*=========================================================================
+  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"
+
+// clitk
+#include "clitkProfileImageGenericFilter.h"
+
+// vtk
+#include <vtkImageActor.h>
+#include <vtkCamera.h>
+#include <vtkImageClip.h>
+#include <vtkRenderWindow.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);
+  mInteractiveDisplayIsEnabled = mCheckBoxInteractiveDisplay->isChecked();
+
+  // Connect signals & slots
+  connect(mRadioButtonLowerThan, SIGNAL(toggled(bool)), this, SLOT(enableLowerThan(bool)));
+  connect(mCheckBoxUseFG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool)));
+  connect(mCheckBoxUseBG, SIGNAL(toggled(bool)), this, SLOT(useFGBGtoggled(bool)));
+  connect(mCheckBoxInteractiveDisplay, SIGNAL(toggled(bool)), this, SLOT(InteractiveDisplayToggled(bool)));
+
+  // Initialize some widget
+  mThresholdSlider1->SetText("");
+  mThresholdSlider2->SetText("");
+  mFGSlider->SetText("Foreground value");
+  mBGSlider->SetText("Background value");
+
+  // Main filter
+  mFilter = clitk::ProfileImageGenericFilter::New();
+
+  // Set how many inputs are needed for this tool
+  AddInputSelector("Select one image", mFilter);
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+vvToolProfile::~vvToolProfile()
+{ 
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+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();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+bool vvToolProfile::close()
+{ 
+  // RemoveVTKObjects();
+  return vvToolWidgetBase::close();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::closeEvent(QCloseEvent *event)
+{ 
+  RemoveVTKObjects();
+  event->accept();
+}
+//------------------------------------------------------------------------------
+
+
+//------------------------------------------------------------------------------
+void vvToolProfile::reject()
+{ 
+  // DD("vvToolProfile::reject");
+  RemoveVTKObjects();
+  return vvToolWidgetBase::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;
+
+  // 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()
+{ 
+
+  /* //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
+  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;
+
+  // // 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) close();
+  QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
+  GetArgsInfoFromGUI();  
+  
+  // Main filter
+  clitk::ProfileImageGenericFilter::Pointer filter =
+    clitk::ProfileImageGenericFilter::New();
+  filter->SetInputVVImage(mCurrentImage);
+  filter->SetArgsInfo(mArgsInfo);
+  filter->Update();
+
+
+  // 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();
+}
+//------------------------------------------------------------------------------
diff --git a/vv/vvToolProfile.h b/vv/vvToolProfile.h
new file mode 100644 (file)
index 0000000..baaf4a9
--- /dev/null
@@ -0,0 +1,75 @@
+/*=========================================================================
+  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"
+
+//------------------------------------------------------------------------------
+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);
+
+  //-----------------------------------------------------
+  public slots:
+  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);
+
+ protected:
+  void RemoveVTKObjects();
+  virtual void closeEvent(QCloseEvent *event);
+  Ui::vvToolProfile ui;
+  args_info_clitkProfileImage mArgsInfo;
+  std::vector<vvImageContour::Pointer> mImageContour;
+  std::vector<vvImageContour::Pointer> mImageContourLower;
+  bool mInteractiveDisplayIsEnabled;
+  
+  void Update(int slicer);
+
+}; // end class vvToolProfile
+//------------------------------------------------------------------------------
+
+#endif
+