]> Creatis software - clitk.git/commitdiff
Remove clitkDVH tool and add --dvhistogram option to clitkImageStatistics.
authorAgata Krason <agatakrason@gmail.com>
Thu, 12 Jun 2014 18:37:32 +0000 (20:37 +0200)
committerAgata Krason <agatakrason@gmail.com>
Thu, 12 Jun 2014 18:37:32 +0000 (20:37 +0200)
tools/CMakeLists.txt
tools/clitkDVH.cxx [deleted file]
tools/clitkDVH.ggo [deleted file]
tools/clitkDVHGenericFilter.cxx [deleted file]
tools/clitkDVHGenericFilter.h [deleted file]
tools/clitkDVHGenericFilter.txx [deleted file]
tools/clitkImageStatistics.ggo
tools/clitkImageStatisticsGenericFilter.txx

index 107aafac0e936da62c8bae6ca472821916f33297..6bd72a3e62b55397fbaa4fb98de1aa2ce9e9a0a2 100644 (file)
@@ -232,11 +232,6 @@ if(CLITK_BUILD_TOOLS)
   target_link_libraries(clitkImageStatistics clitkCommon)
   set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkImageStatistics)
 
-  WRAP_GGO(clitkDVH_GGO_C clitkDVH.ggo)
-  add_executable(clitkDVH clitkDVH.cxx clitkDVHGenericFilter.cxx ${clitkDVH_GGO_C})
-  target_link_libraries(clitkDVH clitkVectorArithmLib clitkCommon)
-  set(TOOLS_INSTALL ${TOOLS_INSTALL} clitkDVH)
-
   WRAP_GGO(clitkVFConvert_GGO_C clitkVFConvert.ggo)
   add_executable(clitkVFConvert clitkVFConvert.cxx clitkVFConvertGenericFilter.cxx ${clitkVFConvert_GGO_C})
   target_link_libraries(clitkVFConvert clitkCommon )
diff --git a/tools/clitkDVH.cxx b/tools/clitkDVH.cxx
deleted file mode 100644 (file)
index bf069f4..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*=========================================================================
-  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
-===========================================================================**/
-
-/* =================================================
- * @file   clitkHGenericFilter.txx
- * @author Agata Krason <agata.krason@creatis.insa-lyon.fr>
- * @date   19 November 2013
- *
- * @brief Dose Histogram
- *
- ===================================================*/
-
-// clitk
-#include "clitkDVH_ggo.h"
-#include "clitkIO.h"
-#include "clitkDVHGenericFilter.h"
-
-//--------------------------------------------------------------------
-int main(int argc, char * argv[])
-{
-
-  // Init command line
-  GGO(clitkDVH, args_info);
-  CLITK_INIT;
-
-  // Filter
-  clitk::DVHGenericFilter::Pointer genericFilter=clitk::DVHGenericFilter::New();
-  genericFilter->SetArgsInfo(args_info);
-  CLITK_TRY_CATCH_EXIT(genericFilter->Update());
-
-  return EXIT_SUCCESS;
-}// end main
diff --git a/tools/clitkDVH.ggo b/tools/clitkDVH.ggo
deleted file mode 100644 (file)
index cc439fc..0000000
+++ /dev/null
@@ -1,22 +0,0 @@
-#File clitkDVH.ggo
-package "clitkDVH"
-version "2.0"
-purpose "Dose volume histogram"
-
-
-option "config"                -       "Config file"                     string        no
-option "verbose"       v       "Verbose"                         flag          off
-
-option "input"         i       "Input image filename"            string        yes multiple
-option "channel"    c "Image channel to be used in statistics (-1 to process all channels)"  int no default="-1"
-option "mask"          m       "Mask image filename (uchar)"             string        yes
-option "label"         l       "Label(s) in the mask image to consider"        int     no      multiple        default="1"
-option "histogram"     -       "Compute histogram, allows median calculation"  string  no
-option "dvhistogram" - "Compute dose volume histogram "        string  no
-option "bins"          -       "Number of histogram bins"                      int     no      default="80"
-option "lower"         -       "Lower histogram bound" double  no default="0"
-option "upper"         -       "Upper histogram bound" double  no default="80"
-option "allow_resize"          r       "Resize mask if different from input"                     flag          off
-
-
-
diff --git a/tools/clitkDVHGenericFilter.cxx b/tools/clitkDVHGenericFilter.cxx
deleted file mode 100644 (file)
index f781c49..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-/*=========================================================================
-  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 clitkDVHGenericFilter_cxx
-#define clitkDVHGenericFilter_cxx
-
-#include "clitkDVHGenericFilter.h"
-
-namespace clitk
-{
-
-  //-----------------------------------------------------------
-  // Constructor
-  //-----------------------------------------------------------
-  DVHGenericFilter::DVHGenericFilter()
-  {
-    m_Verbose=false;
-    m_InputFileName="";
-  }
-  //-----------------------------------------------------------
-  
-  //-----------------------------------------------------------
-  // Update
-  //-----------------------------------------------------------
-  void DVHGenericFilter::Update()
-  {
-    // Read the Dimension and PixelType
-    int Dimension, Components;
-    std::string PixelType;
-    ReadImageDimensionAndPixelType(m_InputFileName, Dimension, PixelType, Components);
-    
-    if (m_ArgsInfo.channel_arg < -1 || m_ArgsInfo.channel_arg >= Components) {
-      std::cout << "Invalid image channel" << std::endl;
-      return;
-    }
-    
-    if (m_ArgsInfo.mask_given) {
-      int maskDimension, maskComponents;
-      std::string maskPixelType;
-      ReadImageDimensionAndPixelType(m_ArgsInfo.mask_arg, maskDimension, maskPixelType, maskComponents);
-      if (!(maskDimension == Dimension || maskDimension == (Dimension - 1))) {
-        std::cout << "Dimension of label mask must be equal to the (d)imension of the input image or d-1." << std::endl;
-        return;
-      }
-    }
-
-    
-    // Call UpdateWithDim
-    if (Dimension==2) {
-      switch (Components) {
-        case 1: 
-          UpdateWithDim<2,1>(PixelType);
-          break;
-        case 2: 
-          UpdateWithDim<2,2>(PixelType);
-          break;
-        case 3: 
-          UpdateWithDim<2,3>(PixelType);
-          break;
-        default:
-          std::cout << "Unsupported number of channels" << std::endl;
-          break;
-      }
-    }
-    else if (Dimension==3) {
-      switch (Components) {
-        case 1: 
-          UpdateWithDim<3,1>(PixelType);
-          break;
-        case 2: 
-          UpdateWithDim<3,2>(PixelType);
-          break;
-        case 3: 
-          UpdateWithDim<3,3>(PixelType);
-          break;
-        default:
-          std::cout << "Unsupported number of channels" << std::endl;
-          break;
-      }
-    }
-    else if (Dimension==4) {
-      switch (Components) {
-        case 1: 
-          UpdateWithDim<4,1>(PixelType);
-          break;
-        case 2: 
-          UpdateWithDim<4,2>(PixelType);
-          break;
-        case 3: 
-          UpdateWithDim<4,3>(PixelType);
-          break;
-        default:
-          std::cout << "Unsupported number of channels" << std::endl;
-          break;
-      }
-    }
-    else {
-      std::cout<<"Error, Only for 2 or 3  Dimensions!!!"<<std::endl ;
-      return;
-    }
-  }
-
-
-} //end clitk
-
-#endif  //#define clitkDVHGenericFilter_cxx
diff --git a/tools/clitkDVHGenericFilter.h b/tools/clitkDVHGenericFilter.h
deleted file mode 100644 (file)
index 07b4d4c..0000000
+++ /dev/null
@@ -1,136 +0,0 @@
-/*=========================================================================
-  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 CLITKDVHGENERICFILTER_H
-#define CLITKDVHGENERICFILTER_H
-
-// clitk include
-#include "clitkIO.h"
-#include "clitkCommon.h"
-#include "clitkImageCommon.h" 
-#include "clitkImageToImageGenericFilter.h"
-#include "clitkDVH_ggo.h"
-
-// itk include
-#include "itkImage.h"
-#include "itkImageIOBase.h"
-#include "itkImageRegionIterator.h"
-#include "itkImageRegionConstIterator.h"
-#include "itkLightObject.h"
-#include "itkLabelStatisticsImageFilter.h"
-#include "itkLabelGeometryImageFilter.h"
-
-//--------------------------------------------------------------------
-namespace clitk
-{
-
-//template<class args_info_type>
-class ITK_EXPORT DVHGenericFilter: public itk::LightObject
-{
-
-public:
-
-
-    //--------------------------------------------------------------------
-    typedef DVHGenericFilter         Self;
-    typedef itk::LightObject               Superclass;
-    typedef itk::SmartPointer<Self>            Pointer;
-    typedef itk::SmartPointer<const Self>      ConstPointer;
-
-    //--------------------------------------------------------------------
-    // Method for creation through the object factory
-    // and Run-time type information (and related methods)
-    itkNewMacro(Self);
-    itkTypeMacro(DVHGenericFilter, LightObject);
-
-    //--------------------------------------------------------------------
-    void SetArgsInfo(const args_info_clitkDVH & a)
-    {
-     m_ArgsInfo=a;
-     m_Verbose=m_ArgsInfo.verbose_flag;
-
-     if(m_ArgsInfo.input_given)
-      m_InputFileName=m_ArgsInfo.input_arg[0];
-     else if(m_ArgsInfo.inputs_num>0)
-     m_InputFileName=m_ArgsInfo.inputs[0];
-     else {
-     std::cerr << "You must give an input file name" << std::endl;
-     exit(1);
-      }
-    }
-    //--------------------------------------------------------------------
-    // Main function called each time the filter is updated
-    //template<class InputImageType>
-    //void UpdateWithInputImageType();
-    void Update();
-
-    // Set methods
-    void SetDefaultPixelValue (double value) {  mDefaultPixelValue = value ;}
-    void SetTypeOfOperation (int value) {  mTypeOfOperation = value ;}
-    void SetScalar (double value) {  mScalar = value ;}
-    void EnableOverwriteInputImage(bool b);
-
-    // Get methods
-    double GetDefaultPixelValue () { return  mDefaultPixelValue ;}
-    int GetTypeOfOperation () { return  mTypeOfOperation ;}
-    double GetScalar () { return  mScalar ;}
-
-protected:
-
-   //--------------------------------------------------------------------
-   // Constructor & Destructor
-   DVHGenericFilter();
-   ~DVHGenericFilter() {};
-   // template<unsigned int Dim> void InitializeImageType();
-   // args_info_type mArgsInfo;
-
-   //--------------------------------------------------------------------
-   // Tempated members
-   //--------------------------------------------------------------------
-   template<unsigned int Dimension, unsigned int Components> void UpdateWithDim(std::string PixelType);
-   template <unsigned int Dimension, class PixelType, unsigned int Components> void UpdateWithDimAndPixelType();
-
-   //--------------------------------------------------------------------
-   // Data members
-   //--------------------------------------------------------------------
-   args_info_clitkDVH m_ArgsInfo;
-   bool m_Verbose;
-   std::string m_InputFileName;
-
-   template<unsigned int Dim> void InitializeImageType();
-   bool mIsOperationUseASecondImage;
-   double mScalar;
-   double mDefaultPixelValue;
-   int mTypeOfOperation;
-   bool mOverwriteInputImage;
-   bool mOutputIsFloat;
-
-   template<class Iter1, class Iter2> void ComputeImage(Iter1 it, Iter2 ito);
-
-   template<class Iter1, class Iter2, class Iter3> void ComputeImage(Iter1 it1, Iter2 it2, Iter3 ito);
-
-
-}; // end class
-//--------------------------------------------------------------------
-
-} // end namespace clitk
-
-#ifndef ITK_MANUAL_INSTANTIATION
-#include "clitkDVHGenericFilter.txx"
-#endif
-
-#endif // #define clitkDVHGenericFilter_h
diff --git a/tools/clitkDVHGenericFilter.txx b/tools/clitkDVHGenericFilter.txx
deleted file mode 100644 (file)
index bd17a94..0000000
+++ /dev/null
@@ -1,338 +0,0 @@
-/*=========================================================================
-  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 clitkDVHGenericFilter_txx
-#define clitkDVHGenericFilter_txx
-
-/* =================================================
- * @file   clitkDVHGenericFilter.txx
- * @author Agata Krason <agata.krason@creatis.insa-lyon.fr>
- * @date   20 November 2013
- *
- * @brief Dose volume and image histogram
- *
- ===================================================*/
-
-// itk include
-#include "itkBinaryThresholdImageFilter.h"
-#include "itkMaskImageFilter.h"
-#include "itkMaskNegatedImageFilter.h"
-#include "itkNthElementImageAdaptor.h"
-#include "itkJoinSeriesImageFilter.h"
-#include "itkMinimumMaximumImageCalculator.h"
-
-// clitk include
-#include <clitkCommon.h>
-#include "clitkImageCommon.h"
-#include "clitkDVHGenericFilter.h"
-#include "clitkCropLikeImageFilter.h"
-#include "clitkResampleImageWithOptionsFilter.h"
-
-//-------------------------------------------------------------------
-//
-namespace clitk
-{
-
-//-------------------------------------------------------------------
-template<unsigned int Dimension, unsigned int Components>
-void
-DVHGenericFilter::UpdateWithDim(std::string PixelType)
-{
-  if (m_Verbose) std::cout << "Image was detected to be "<<Dimension<<"D and "<< PixelType<<" with " << Components << " channel(s)..."<<std::endl;
-
-  if(PixelType == "short"){  
-    if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl;
-    UpdateWithDimAndPixelType<Dimension, signed short, Components>(); 
-  }
-  else if(PixelType == "unsigned_short"){  
-    if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl;
-    UpdateWithDimAndPixelType<Dimension, unsigned short, Components>(); 
-  }
-  
-  else if (PixelType == "unsigned_char"){ 
-    if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl;
-    UpdateWithDimAndPixelType<Dimension, unsigned char, Components>();
-  }
-      
-  else if(PixelType == "double"){  
-    if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and double..." << std::endl;
-    UpdateWithDimAndPixelType<Dimension, double, Components>(); 
-  }
-  else {
-    if (m_Verbose) std::cout  << "Launching filter in "<< Dimension <<"D and float..." << std::endl;
-    UpdateWithDimAndPixelType<Dimension, float, Components>();
-  }
-}
-
-
-//-------------------------------------------------------------------
-// Update with the number of dimensions and the pixeltype
-//-------------------------------------------------------------------
-template <unsigned int Dimension, class  PixelType, unsigned int Components> 
-void 
-DVHGenericFilter::UpdateWithDimAndPixelType()
-{
-
-  // ImageTypes
-  typedef unsigned char LabelPixelType;
-  typedef itk::Image<itk::Vector<PixelType, Components>, Dimension> InputImageType;
-  typedef itk::Image<LabelPixelType, Dimension> LabelImageType;
-  
-  // Read the input
-  typedef itk::ImageFileReader<InputImageType> InputReaderType;
-  typename InputReaderType::Pointer reader = InputReaderType::New();
-  reader->SetFileName( m_InputFileName);
-  reader->Update();
-  typename InputImageType::Pointer input= reader->GetOutput();
-  
-  typedef itk::NthElementImageAdaptor<InputImageType, PixelType> InputImageAdaptorType;
-  typedef itk::Image<PixelType, Dimension> OutputImageType;
-
-  typename InputImageAdaptorType::Pointer input_adaptor = InputImageAdaptorType::New();
-  input_adaptor->SetImage(input);
-  
-  // Filter
-  typedef itk::LabelStatisticsImageFilter<InputImageAdaptorType, LabelImageType> StatisticsImageFilterType;
-  typename StatisticsImageFilterType::Pointer statisticsFilter=StatisticsImageFilterType::New();
-  statisticsFilter->SetInput(input_adaptor);
-
-  // Label image
-  typename LabelImageType::Pointer labelImage;
-  if (m_ArgsInfo.mask_given) {
-    int maskDimension, maskComponents;
-    std::string maskPixelType;
-    ReadImageDimensionAndPixelType(m_ArgsInfo.mask_arg, maskDimension, maskPixelType, maskComponents);
-
-    if (maskDimension == Dimension - 1) {
-      // Due to a limitation of filter itk::LabelStatisticsImageFilter, InputImageType and LabelImageType
-      // must have the same image dimension. However, we want to support label images with Dl = Di - 1,
-      // so we need to replicate the label image as many times as the size along dimension Di.
-      if (m_Verbose) 
-        std::cout << "Replicating label image to match input image's dimension... " << std::endl;
-      
-      typedef itk::Image<LabelPixelType, Dimension - 1> ReducedLabelImageType;
-      typedef itk::ImageFileReader<ReducedLabelImageType> LabelImageReaderType;
-      typedef itk::JoinSeriesImageFilter<ReducedLabelImageType, LabelImageType> JoinImageFilterType;
-
-      
-      typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New();
-      labelImageReader->SetFileName(m_ArgsInfo.mask_arg);
-      labelImageReader->Update();
-
-      typename JoinImageFilterType::Pointer joinFilter = JoinImageFilterType::New();
-      typename InputImageType::SizeType size = input->GetLargestPossibleRegion().GetSize();
-      for (unsigned int i = 0; i < size[Dimension - 1]; i++)
-        joinFilter->PushBackInput(labelImageReader->GetOutput());
-      
-      joinFilter->Update();
-      labelImage = joinFilter->GetOutput();
-    }
-    else {
-      typedef itk::ImageFileReader<LabelImageType> LabelImageReaderType;
-      typename LabelImageReaderType::Pointer labelImageReader=LabelImageReaderType::New();
-      labelImageReader->SetFileName(m_ArgsInfo.mask_arg);
-      labelImageReader->Update();
-      labelImage= labelImageReader->GetOutput();
-
-      // Check mask sampling/size
-      if (!HaveSameSizeAndSpacing<LabelImageType, InputImageType>(labelImage, input)) {
-        if (m_ArgsInfo.allow_resize_flag) {
-          if (m_ArgsInfo.verbose_flag) {
-            std::cout << "Resize mask image like input" << std::endl;
-          }
-
-          typedef clitk::ResampleImageWithOptionsFilter<LabelImageType> ResamplerType;
-          typename ResamplerType::Pointer resampler = ResamplerType::New();
-          resampler->SetInput(labelImage);
-          resampler->SetOutputSpacing(input->GetSpacing());
-          resampler->SetGaussianFilteringEnabled(false);
-          resampler->Update();
-          labelImage = resampler->GetOutput();
-          labelImage->GetSpacing();
-          typedef clitk::CropLikeImageFilter<LabelImageType> FilterType;
-          typename FilterType::Pointer crop = FilterType::New();
-          crop->SetInput(labelImage);
-          crop->SetCropLikeImage(input);
-          crop->Update();
-          labelImage = crop->GetOutput();                        
-          //writeImage<LabelImageType>(labelImage, "test2.mha");
-
-        }
-        else {
-          std::cerr << "Mask image has a different size/spacing than input. Abort" << std::endl;
-          exit(-1);
-        }
-      }
-
-    }
-
-  }
-  else { 
-    labelImage=LabelImageType::New();
-    labelImage->SetRegions(input->GetLargestPossibleRegion());
-    labelImage->SetOrigin(input->GetOrigin());
-    labelImage->SetSpacing(input->GetSpacing());
-    labelImage->Allocate();
-    labelImage->FillBuffer(m_ArgsInfo.label_arg[0]);
-  }
-  statisticsFilter->SetLabelInput(labelImage);
-
-  // Check/compute spacing
-  const typename LabelImageType::SpacingType& spacing = input->GetSpacing();
-  double spacing_cc = (spacing[0]*spacing[1]*spacing[2])/1000;
-  // std::cout<<"Spacing x : "<<spacing[0]<<std::endl;
-  // std::cout<<"Spacing y :  "<< spacing[1]<<std::endl;
-  // std::cout<<"Spacing z :  "<< spacing[2]<<std::endl;
-  // std::cout <<"spacing_cc : "<< spacing_cc << std::endl;
-
-  // For each Label
-  typename LabelImageType::PixelType label;
-  unsigned int numberOfLabels;
-  if (m_ArgsInfo.label_given)
-    numberOfLabels=m_ArgsInfo.label_given;
-  else
-    numberOfLabels=1;
-
-  unsigned int firstComponent = 0, lastComponent = 0;
-  if (m_ArgsInfo.channel_arg == -1) {
-    firstComponent = 0; 
-    lastComponent = Components - 1;
-  }
-  else {
-    firstComponent = m_ArgsInfo.channel_arg;
-    lastComponent = m_ArgsInfo.channel_arg;
-  }
-  
-  for (unsigned int c=firstComponent; c<=lastComponent; c++) {
-    if (m_Verbose) std::cout << std::endl << "Processing channel " << c << std::endl;
-    
-    input_adaptor->SelectNthElement(c);
-    input_adaptor->Update();
-    
-    for (unsigned int k=0; k< numberOfLabels; k++) {
-      label=m_ArgsInfo.label_arg[k];
-      // Histogram
-      if (m_ArgsInfo.histogram_given)
-      {
-          std::cout<<"--------------"<<std::endl;
-          std::cout<<"| Label:   |"<<label<<" |"<<std::endl;
-          std::cout<<"--------------"<<std::endl;
-
-        statisticsFilter->SetUseHistograms(true);
-        statisticsFilter->SetHistogramParameters(m_ArgsInfo.bins_arg, m_ArgsInfo.lower_arg, m_ArgsInfo.upper_arg);
-      }
-
-      // DVHistogram
-         if(m_ArgsInfo.dvhistogram_given)
-         {
-        statisticsFilter->SetUseHistograms(true);
-        statisticsFilter->SetHistogramParameters(m_ArgsInfo.bins_arg, m_ArgsInfo.lower_arg, m_ArgsInfo.upper_arg);
-      }
-
-      statisticsFilter->Update();
-
-      // Histogram
-      if (m_ArgsInfo.histogram_given)
-      {
-          if (m_Verbose) std::cout<<"Median: ";
-          std::cout<<statisticsFilter->GetMedian(label)<<std::endl;
-
-        typename StatisticsImageFilterType::HistogramPointer histogram =statisticsFilter->GetHistogram(label);
-
-        // Screen
-        if (m_Verbose) std::cout<<"Histogram: "<<std::endl;
-          std::cout<<"# MinBin\tMidBin\tMaxBin\tFrequency"<<std::endl;
-        for( int i =0; i <m_ArgsInfo.bins_arg; i++)
-          std::cout<<histogram->GetBinMin(0,i)<<"\t"<<histogram->GetMeasurement(i,0)<<"\t"<<histogram->GetBinMax(0,i)<<"\t"<<histogram->GetFrequency(i)<<std::endl;
-        // Add to the file
-        std::ofstream histogramFile(m_ArgsInfo.histogram_arg);
-        histogramFile<<"#Histogram: "<<std::endl;
-        histogramFile<<"#MinBin\tMidBin\tMaxBin\tFrequency"<<std::endl;
-        for( int i =0; i <m_ArgsInfo.bins_arg; i++)
-          histogramFile<<histogram->GetBinMin(0,i)<<"\t"<<histogram->GetMeasurement(i,0)<<"\t"<<histogram->GetBinMax(0,i)<<"\t"<<histogram->GetFrequency(i)<<std::endl;
-      }
-
-      // DVH
-         if(m_ArgsInfo.dvhistogram_given)
-         {
-          typename StatisticsImageFilterType::HistogramPointer dvhistogram = statisticsFilter->GetHistogram(label);
-
-          // Screen
-          std::cout<<"Total volume : ";
-          std::cout<<statisticsFilter->GetCount(label)<<" [No. of voxels]"<<std::endl;
-          std::cout<<"Total volume : ";
-          std::cout<<((statisticsFilter->GetCount(label))*spacing_cc)<<" [cc]"<<std::endl;
-          std::cout<<"Dose mean: ";
-          std::cout<<statisticsFilter->GetMean(label)<<" [Gy]"<<std::endl;
-          std::cout<<"Dose min: ";
-          std::cout<<statisticsFilter->GetMinimum(label)<<" [Gy]"<<std::endl;
-          std::cout<<"Dose max: ";
-          std::cout<<statisticsFilter->GetMaximum(label)<<" [Gy]"<<std::endl;
-          std::cout<<" "<<std::endl;
-          std::cout<<"#Dose[Gy] Volume_diff[No. of voxels]] Volume_cumul[No. of voxels] Volume_diff[%] Volume_cumul[%] Volume_diff[cc] Volume_cumul[cc]"<<std::endl;
-          for( int i =0; i <m_ArgsInfo.bins_arg; i++)
-          {
-            double percentDiffVolume = ((dvhistogram->GetFrequency(i))*100)/(statisticsFilter->GetCount(label));
-            double popCumulativeVolume = 0;
-            for(int j=0; j<i; j++)
-            {
-                popCumulativeVolume+=(dvhistogram->GetFrequency(j));
-            }
-            double cumulativeVolume = popCumulativeVolume + (dvhistogram->GetFrequency(i));
-            double percentCumulativeVolume =(cumulativeVolume*100)/(statisticsFilter->GetCount(label)) ;
-            double ccCumulativeVolume = (popCumulativeVolume + (dvhistogram->GetFrequency(i)))*spacing_cc;
-            std::cout<<dvhistogram->GetBinMax(0,i)<<"\t   "<<dvhistogram->GetFrequency(i)<<"\t  "<<cumulativeVolume<<"\t  "<<percentDiffVolume<<"\t "<<percentCumulativeVolume<<"\t  "<<((dvhistogram->GetFrequency(i))*spacing_cc)<<"\t  "<<ccCumulativeVolume<<std::endl;
-          }
-
-          // Add to the file
-          std::ofstream dvhistogramFile(m_ArgsInfo.dvhistogram_arg);
-          dvhistogramFile<<"Total volume : ";
-          dvhistogramFile<<statisticsFilter->GetCount(label)<<" [No. of voxels]"<<std::endl;
-          dvhistogramFile<<"Total volume : ";
-          dvhistogramFile<<((statisticsFilter->GetCount(label))*spacing_cc)<<" [cc]"<<std::endl;
-          dvhistogramFile<<"Dose mean: ";
-          dvhistogramFile<<statisticsFilter->GetMean(label)<<" [Gy]"<<std::endl;
-          dvhistogramFile<<"Dose min: ";
-          dvhistogramFile<<statisticsFilter->GetMinimum(label)<<" [Gy]"<<std::endl;
-          dvhistogramFile<<"Dose max: ";
-          dvhistogramFile<<statisticsFilter->GetMaximum(label)<<" [Gy]"<<std::endl;
-          dvhistogramFile<<"  "<<std::endl;
-          dvhistogramFile<<"#Dose[Gy] Volume_diff[No. of voxels]] Volume_cumul[No. of voxels] Volume_diff[%] Volume_cumul[%] Volume_diff[cc] Volume_cumul[cc]"<<std::endl;
-          for( int i =0; i <m_ArgsInfo.bins_arg; i++)
-          {
-             double percentDiffVolume = ((dvhistogram->GetFrequency(i))*100)/(statisticsFilter->GetCount(label));
-             double popCumulativeVolume = 0;
-             for(int j=0; j<i; j++)
-             {
-                 popCumulativeVolume+=(dvhistogram->GetFrequency(j));
-             }
-             double cumulativeVolume = popCumulativeVolume + (dvhistogram->GetFrequency(i));
-             double percentCumulativeVolume =(cumulativeVolume*100)/(statisticsFilter->GetCount(label)) ;
-             double ccCumulativeVolume = (popCumulativeVolume + (dvhistogram->GetFrequency(i)))*spacing_cc;
-             dvhistogramFile<<dvhistogram->GetBinMax(0,i)<<"\t "<<dvhistogram->GetFrequency(i)<<"\t "<<cumulativeVolume<<"\t "<<percentDiffVolume<<"\t "<<percentCumulativeVolume<<"\t "<<((dvhistogram->GetFrequency(i))*spacing_cc)<<"\t "<<ccCumulativeVolume<<std::endl;
-         }
-         }
-    }
-  }
-
-  return;
-
-}
-
-}//end clitk
-
-#endif //#define clitkDVHGenericFilter_txx
index bc7998bf2be05d2ce65a84d23444f4e9c65e4327..7e28e42c6a0f73c280cafcfc21f9ff9afc449298 100644 (file)
@@ -12,6 +12,7 @@ option "channel"    c "Image channel to be used in statistics (-1 to process all
 option "mask"          m       "Mask image filename (uchar)"             string        no
 option "label"         l       "Label(s) in the mask image to consider"        int     no      multiple        default="1"
 option "histogram"     -       "Compute histogram, allows median calculation"  string  no
+option "dvhistogram" - "Compute dose volume histogram" string  no
 option "bins"          -       "Number of histogram bins"                      int     no      default="100"
 option "lower"         -       "Lower histogram bound" double  no default="-1000"      
 option "upper"         -       "Upper histogram bound" double  no default="1000"               
index 1995198234be2f07e4db47f3921dd9338e97482a..8bc99d0e423831da2245968635cd766c64c2aab1 100644 (file)
@@ -174,6 +174,15 @@ namespace clitk
     }
     statisticsFilter->SetLabelInput(labelImage);
 
+    // Check/compute spacing
+    const typename LabelImageType::SpacingType& spacing = input->GetSpacing();
+    double spacing_cc = (spacing[0]*spacing[1]*spacing[2])/1000;
+    // std::cout<<"Spacing x : " << spacing[0]<<std::endl;
+    // std::cout<<"Spacing y :  " << spacing[1]<<std::endl;
+    // std::cout<<"Spacing z :  " << spacing[2]<<std::endl;
+    // std::cout <<"spacing_cc : " << spacing_cc << std::endl;
+
+
     // For each Label
     typename LabelImageType::PixelType label;
     unsigned int numberOfLabels;
@@ -211,34 +220,34 @@ namespace clitk
           statisticsFilter->SetUseHistograms(true);
           statisticsFilter->SetHistogramParameters(m_ArgsInfo.bins_arg, m_ArgsInfo.lower_arg, m_ArgsInfo.upper_arg);
         }
+
+        // DVH
+        if(m_ArgsInfo.dvhistogram_given)
+        {
+          statisticsFilter->SetUseHistograms(true);
+          statisticsFilter->SetHistogramParameters(m_ArgsInfo.bins_arg, m_ArgsInfo.lower_arg, m_ArgsInfo.upper_arg);
+        }
+
         statisticsFilter->Update();
 
         // Output
-        if (m_Verbose) std::cout<<"N° of pixels: ";
-          std::cout<<statisticsFilter->GetCount(label)<<std::endl;
-
+       if (m_Verbose) std::cout<<"N° of pixels: ";
+        std::cout<<statisticsFilter->GetCount(label)<<std::endl;
         if (m_Verbose) std::cout<<"Mean: ";
-          std::cout<<statisticsFilter->GetMean(label)<<std::endl;
-
+        std::cout<<statisticsFilter->GetMean(label)<<std::endl;
         if (m_Verbose) std::cout<<"SD: ";
-          std::cout<<statisticsFilter->GetSigma(label)<<std::endl;
-
+        std::cout<<statisticsFilter->GetSigma(label)<<std::endl;
         if (m_Verbose) std::cout<<"Variance: ";
-          std::cout<<statisticsFilter->GetVariance(label)<<std::endl;
-
+        std::cout<<statisticsFilter->GetVariance(label)<<std::endl;
         if (m_Verbose) std::cout<<"Min: ";
-          std::cout<<statisticsFilter->GetMinimum(label)<<std::endl;
-
+        std::cout<<statisticsFilter->GetMinimum(label)<<std::endl;
         if (m_Verbose) std::cout<<"Max: ";
-          std::cout<<statisticsFilter->GetMaximum(label)<<std::endl;
-
+        std::cout<<statisticsFilter->GetMaximum(label)<<std::endl;
         if (m_Verbose) std::cout<<"Sum: ";
-          std::cout<<statisticsFilter->GetSum(label)<<std::endl;
-
+        std::cout<<statisticsFilter->GetSum(label)<<std::endl;
         if (m_Verbose) std::cout<<"Bounding box: ";
-
         for(unsigned int i =0; i <statisticsFilter->GetBoundingBox(label).size(); i++)
-          std::cout<<statisticsFilter->GetBoundingBox(label)[i]<<" ";
+            std::cout<<statisticsFilter->GetBoundingBox(label)[i]<<" ";
         std::cout<<std::endl;
 
         // Histogram
@@ -262,6 +271,79 @@ namespace clitk
           for( int i =0; i <m_ArgsInfo.bins_arg; i++)
             histogramFile<<histogram->GetBinMin(0,i)<<"\t"<<histogram->GetMeasurement(i,0)<<"\t"<<histogram->GetBinMax(0,i)<<"\t"<<histogram->GetFrequency(i)<<std::endl;
         }
+
+        // DVH
+        if(m_ArgsInfo.dvhistogram_given)
+        {
+            typename StatisticsImageFilterType::HistogramPointer dvhistogram = statisticsFilter->GetHistogram(label);
+
+            // Screen
+            std::cout<<"# Total volume : ";
+            std::cout<<statisticsFilter->GetCount(label)<<" [No. of voxels]"<<std::endl;
+            std::cout<<"# Total volume : ";
+            std::cout<<((statisticsFilter->GetCount(label))*spacing_cc)<<" [cc]"<<std::endl;
+            std::cout<<"# Dose mean: ";
+            std::cout<<statisticsFilter->GetMean(label)<<" [Gy]"<<std::endl;
+            std::cout<<"# Dose min: ";
+            std::cout<<statisticsFilter->GetMinimum(label)<<" [Gy]"<<std::endl;
+            std::cout<<"# Dose max: ";
+            std::cout<<statisticsFilter->GetMaximum(label)<<" [Gy]"<<std::endl;
+            std::cout<<" "<<std::endl;
+            std::cout<<"#Dose_diff[Gy] Volume_diff[No. of voxels] Volume_diff[%] Volume_diff[cc] #Dose_cumul[Gy] Volume_cumul[No. of voxels] Volume_cumul[%] Volume_cumul[cc]"<<std::endl;
+            for( int i =0; i <m_ArgsInfo.bins_arg; i++)
+            {
+              double popCumulativeVolume = 0;
+              for(int j=0; j<=i; j++)
+              {
+                 popCumulativeVolume+=(dvhistogram->GetFrequency(j));
+              }
+              double cumulativeVolume = popCumulativeVolume + (dvhistogram->GetFrequency(i));
+              double percentCumulativeVolume =(cumulativeVolume*100)/(statisticsFilter->GetCount(label)) ;
+              double ccCumulativeVolume = (popCumulativeVolume + (dvhistogram->GetFrequency(i)))*spacing_cc;
+              double percentDiffVolume = dvhistogram->GetFrequency(i)*100/(statisticsFilter->GetCount(label));
+              if(i == 0)
+              {
+                 std::cout<<dvhistogram->GetBinMax(0,i)<<"\t  "<<dvhistogram->GetFrequency(i)<<"\t  "<<percentDiffVolume<<"\t "<<((dvhistogram->GetFrequency(i))*spacing_cc)<<"\t "<<m_ArgsInfo.bins_arg<<"\t "<<cumulativeVolume<<"\t  "<<percentCumulativeVolume<<"\t  "<<ccCumulativeVolume<<"\t "<<std::endl;
+              }else
+              {
+                 std::cout<<dvhistogram->GetBinMax(0,i)<<"\t  "<<dvhistogram->GetFrequency(i)<<"\t  "<<percentDiffVolume<<"\t "<<((dvhistogram->GetFrequency(i))*spacing_cc)<<"\t "<<dvhistogram->GetBinMin(0,m_ArgsInfo.bins_arg-i)<<"\t "<<cumulativeVolume<<"\t  "<<percentCumulativeVolume<<"\t  "<<ccCumulativeVolume<<"\t "<<std::endl;
+              }
+            }
+
+            // Add to the file
+            std::ofstream dvhistogramFile(m_ArgsInfo.dvhistogram_arg);
+            dvhistogramFile<<"# Total volume : ";
+            dvhistogramFile<<statisticsFilter->GetCount(label)<<" [No. of voxels]"<<std::endl;
+            dvhistogramFile<<"# Total volume : ";
+            dvhistogramFile<<((statisticsFilter->GetCount(label))*spacing_cc)<<" [cc]"<<std::endl;
+            dvhistogramFile<<"# Dose mean: ";
+            dvhistogramFile<<statisticsFilter->GetMean(label)<<" [Gy]"<<std::endl;
+            dvhistogramFile<<"# Dose min: ";
+            dvhistogramFile<<statisticsFilter->GetMinimum(label)<<" [Gy]"<<std::endl;
+            dvhistogramFile<<"# Dose max: ";
+            dvhistogramFile<<statisticsFilter->GetMaximum(label)<<" [Gy]"<<std::endl;
+            dvhistogramFile<<"  "<<std::endl;
+            dvhistogramFile<<"#Dose_diff[Gy] Volume_diff[No. of voxels] Volume_diff[%] Volume_diff[cc] #Dose_cumulative[Gy] Volume_cumul[No. of voxels] Volume_cumul[%] Volume_cumul[cc]"<<std::endl;
+            for( int i =0; i <m_ArgsInfo.bins_arg; i++)
+            {
+               double popCumulativeVolume = 0;
+               for(int j=0; j<=i; j++)
+               {
+                 popCumulativeVolume+=(dvhistogram->GetFrequency(j));
+               }
+               double cumulativeVolume = popCumulativeVolume + (dvhistogram->GetFrequency(i));
+               double percentCumulativeVolume =(cumulativeVolume*100)/(statisticsFilter->GetCount(label)) ;
+               double ccCumulativeVolume = (popCumulativeVolume + (dvhistogram->GetFrequency(i)))*spacing_cc;
+               double percentDiffVolume = ((dvhistogram->GetFrequency(i))*100)/(statisticsFilter->GetCount(label));
+               if(i == 0)
+               {
+                 dvhistogramFile<<dvhistogram->GetBinMax(0,i)<<"\t  "<<dvhistogram->GetFrequency(i)<<"\t  "<<percentDiffVolume<<"\t "<<((dvhistogram->GetFrequency(i))*spacing_cc)<<"\t "<<m_ArgsInfo.bins_arg<<"\t "<<cumulativeVolume<<"\t  "<<percentCumulativeVolume<<"\t  "<<ccCumulativeVolume<<std::endl;
+               }else
+               {
+                 dvhistogramFile<<dvhistogram->GetBinMax(0,i)<<"\t  "<<dvhistogram->GetFrequency(i)<<"\t  "<<percentDiffVolume<<"\t "<<((dvhistogram->GetFrequency(i))*spacing_cc)<<"\t "<<dvhistogram->GetBinMin(0,m_ArgsInfo.bins_arg-i)<<"\t "<<cumulativeVolume<<"\t  "<<percentCumulativeVolume<<"\t  "<<ccCumulativeVolume<<std::endl;
+               }
+           }
+        }
       }
     }