]> Creatis software - clitk.git/commitdiff
First version of rel pos database builder
authorDavid Sarrut <david.sarrut@gmail.com>
Fri, 4 Nov 2011 09:23:03 +0000 (10:23 +0100)
committerDavid Sarrut <david.sarrut@gmail.com>
Fri, 4 Nov 2011 09:23:03 +0000 (10:23 +0100)
itk/clitkRelativePositionDataBaseBuilderFilter.txx [new file with mode: 0644]
tools/clitkRelativePositionDataBaseBuilder.cxx [new file with mode: 0644]
tools/clitkRelativePositionDataBaseBuilder.ggo [new file with mode: 0644]
tools/clitkRelativePositionDataBaseBuilderGenericFilter.h [new file with mode: 0644]
tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx [new file with mode: 0644]

diff --git a/itk/clitkRelativePositionDataBaseBuilderFilter.txx b/itk/clitkRelativePositionDataBaseBuilderFilter.txx
new file mode 100644 (file)
index 0000000..af482ca
--- /dev/null
@@ -0,0 +1,160 @@
+/*=========================================================================
+  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
+  ===========================================================================**/
+
+//--------------------------------------------------------------------
+template <class ImageType>
+clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
+RelativePositionDataBaseBuilderFilter():
+  clitk::FilterBase(),
+  clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
+  itk::ImageToImageFilter<ImageType, ImageType>()
+{
+  this->SetNumberOfRequiredInputs(0); // support
+  VerboseFlagOff();
+  SetBackgroundValue(0);
+  SetForegroundValue(1);
+  SetNumberOfBins(100);
+  SetNumberOfAngles(4);
+  SetAreaLossTolerance(0.01);
+  m_ListOfAngles.clear();
+  // SetSupportSize(0);
+  // SetTargetSize(0);
+  // SetSizeWithThreshold(0);
+  // SetSizeWithReverseThreshold(0);  
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
+PrintOptions() 
+{
+  DD("TODO");
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
+GenerateOutputInformation() 
+{ 
+  // ImagePointer input = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  // ImagePointer outputImage = this->GetOutput(0);
+  // outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
+GenerateInputRequestedRegion() 
+{
+  // Call default
+  // itk::ImageToImageFilter<ImageType, ImageType>::GenerateInputRequestedRegion();
+  // // Get input pointers and set requested region to common region
+  // ImagePointer input1 = dynamic_cast<ImageType*>(itk::ProcessObject::GetInput(0));
+  // input1->SetRequestedRegion(input1->GetLargestPossibleRegion());
+}
+//--------------------------------------------------------------------
+
+//--------------------------------------------------------------------
+template <class ImageType>
+void 
+clitk::RelativePositionDataBaseBuilderFilter<ImageType>::
+GenerateData() 
+{
+  // Load database of anatomical elements
+  static const unsigned int dim = ImageType::ImageDimension;
+  this->LoadAFDB();
+
+  // Get some information
+  std::string patient = this->GetAFDB()->GetTagValue("PatientID");
+
+  // Get input pointers
+  m_Support = this->GetAFDB()->template GetImage <ImageType>(GetSupportName());
+  m_Target = this->GetAFDB()->template GetImage <ImageType>(GetTargetName());
+
+  // Build the list of tested directions
+  m_ListOfAngles.clear();
+  for(uint i=0; i<GetNumberOfAngles(); i++) {
+    double a = i*360.0/GetNumberOfAngles();
+    if (a>180) a = 180-a;
+    m_ListOfAngles.push_back(clitk::deg2rad(a));
+    RelativePositionDirectionType r;
+    r.angle1 = clitk::deg2rad(a);
+    r.angle2 = 0;
+    r.notFlag = false;
+    m_ListOfDirections.push_back(r); // only one direction
+  }
+
+
+  // Perform the RelativePositionAnalyzerFilter for each objects
+  typedef typename clitk::RelativePositionAnalyzerFilter<ImageType> FilterType;
+  for (int i=0; i<GetNumberOfObjects(); i++) {
+    m_Object = this->GetAFDB()->template GetImage <ImageType>(GetObjectName(i));
+
+    for (int j=0; j<m_ListOfDirections.size(); j++) {
+      clitk::RelativePositionDirectionType direction = m_ListOfDirections[j];
+      
+      // Create the filter
+      typename FilterType::Pointer filter = FilterType::New();
+      filter->SetInputSupport(m_Support);
+      filter->SetInputTarget(m_Target);
+      filter->SetInputObject(m_Object); // FIXME do AndNot before + only compute supportSize once.
+      filter->SetNumberOfBins(GetNumberOfBins());
+      filter->SetAreaLossTolerance(GetAreaLossTolerance());
+      filter->SetDirection(direction);
+      filter->Update();
+
+      // Results
+      std::ostringstream s;
+      s << patient << " " 
+        << GetSupportName() << " " 
+        // << GetTargetName() << " " // No need
+        << GetObjectName(i) <<" ";
+      // Normal 
+      // if (filter->GetInfo().sizeAfterThreshold != filter->GetInfo().sizeBeforeThreshold) {
+        std::ostringstream os;
+        os << s.str();
+        direction.notFlag = false;
+        direction.Print(os);
+        filter->GetInfo().Print(os);
+        std::cout << os.str() << std::endl;
+      // }
+      // Inverse
+      // if (filter->GetInfoReverse().sizeAfterThreshold != filter->GetInfoReverse().sizeBeforeThreshold) {
+        std::ostringstream oos;
+        oos << s.str();
+        direction.notFlag = true;
+        direction.Print(oos);
+        filter->GetInfoReverse().Print(oos);
+        std::cout << oos.str() << std::endl;
+      // }
+    } // end direction
+
+  } // end object
+}
+//--------------------------------------------------------------------
+
+
diff --git a/tools/clitkRelativePositionDataBaseBuilder.cxx b/tools/clitkRelativePositionDataBaseBuilder.cxx
new file mode 100644 (file)
index 0000000..4c8db03
--- /dev/null
@@ -0,0 +1,52 @@
+/*=========================================================================
+  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 "clitkRelativePositionDataBaseBuilder_ggo.h"
+#include "clitkRelativePositionDataBaseBuilderGenericFilter.h"
+
+//--------------------------------------------------------------------
+int main(int argc, char * argv[]) {
+
+  // Init command line
+  GGO(clitkRelativePositionDataBaseBuilder, args_info);
+  CLITK_INIT;
+
+  // Filter
+  typedef clitk::RelativePositionDataBaseBuilderGenericFilter<args_info_clitkRelativePositionDataBaseBuilder> FilterType;
+  FilterType::Pointer filter = FilterType::New();
+  
+  // Set options
+  filter->SetArgsInfo(args_info);
+  
+  // Add an input to determine the type of image
+  NewAFDB(afdb, args_info.afdb_arg);
+  std::string f = afdb->GetTagValue(args_info.supportName_arg);
+  f = std::string(args_info.afdb_path_arg)+"/"+f;
+  filter->AddInputFilename(f);
+  
+  try {
+    filter->Update();
+  } catch(std::runtime_error e) {
+    std::cout << e.what() << std::endl;
+    return EXIT_FAILURE;
+  }
+
+  return EXIT_SUCCESS;
+} // This is the end, my friend
+//--------------------------------------------------------------------
diff --git a/tools/clitkRelativePositionDataBaseBuilder.ggo b/tools/clitkRelativePositionDataBaseBuilder.ggo
new file mode 100644 (file)
index 0000000..c71c462
--- /dev/null
@@ -0,0 +1,25 @@
+#File clitkRelativePositionDataBaseBuilder.ggo
+package "clitkRelativePositionDataBaseBuilder"
+version "1.0"
+purpose "Analyze relative position of a target according to structures"
+
+section "General options"
+option "config"                -       "Config file"                     string        no
+option "verbose"       v       "Verbose"                         flag          off
+option "imagetypes"     -       "Display allowed image types"     flag          off
+
+section "Input/Output"
+option "afdb"           a       "Input Anatomical Feature DB"           string yes
+option "afdb_path"      -       "Path to search image in afdb"          string no
+
+option "supportName"   i       "Input mask support name in afdb"       string yes
+option "targetName"    t       "Input mask target name in afdb"        string yes
+option "objectName"    j       "Input mask object name in afdb"        string yes multiple
+
+option "output"        o       "Output image "                         string yes
+
+section "Options for building the relative positions"
+option "bins"           b       "Number of histo bins for fuzzy map"      int default="100" no
+option "nb"             n       "Number of angles to test"                int default="4" no
+option "tol"            -       "Target area loss tolerance (|0-1])"      double default="0.01" no
+
diff --git a/tools/clitkRelativePositionDataBaseBuilderGenericFilter.h b/tools/clitkRelativePositionDataBaseBuilderGenericFilter.h
new file mode 100644 (file)
index 0000000..bf88269
--- /dev/null
@@ -0,0 +1,76 @@
+/*=========================================================================
+  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 CLITKRelativePositionDataBaseBuilderGENERICFILTER_H
+#define CLITKRelativePositionDataBaseBuilderGENERICFILTER_H
+
+// clitk 
+#include "clitkIO.h"
+#include "clitkImageToImageGenericFilter.h"
+#include "clitkRelativePositionDataBaseBuilderFilter.h"
+#include "clitkSliceBySliceRelativePositionFilter.h"
+
+//--------------------------------------------------------------------
+namespace clitk 
+{
+
+  template<class ArgsInfoType>
+  class ITK_EXPORT RelativePositionDataBaseBuilderGenericFilter:
+    public ImageToImageGenericFilter<RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType> >
+  {
+  public:
+    //--------------------------------------------------------------------
+    RelativePositionDataBaseBuilderGenericFilter();
+  
+    //--------------------------------------------------------------------
+    typedef ImageToImageGenericFilter<RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType> > Superclass;
+    typedef RelativePositionDataBaseBuilderGenericFilter Self;
+    typedef itk::SmartPointer<Self>       Pointer;
+    typedef itk::SmartPointer<const Self> ConstPointer;
+   
+    //--------------------------------------------------------------------
+    itkNewMacro(Self);  
+    itkTypeMacro(RelativePositionDataBaseBuilderGenericFilter, LightObject);
+
+    //--------------------------------------------------------------------
+    void SetArgsInfo(const ArgsInfoType & a);
+    template<class FilterType> 
+      void SetOptionsFromArgsInfoToFilter(FilterType * f) ;
+
+    //--------------------------------------------------------------------
+    // Main function called each time the filter is updated
+    template<class ImageType>  
+    void UpdateWithInputImageType();
+
+  protected:
+    template<unsigned int Dim> void InitializeImageType();
+      ArgsInfoType mArgsInfo;
+
+  private:
+    RelativePositionDataBaseBuilderGenericFilter(const Self&); //purposely not implemented
+    void operator=(const Self&); //purposely not implemented
+    
+  };// end class
+  //--------------------------------------------------------------------
+} // end namespace clitk
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#include "clitkRelativePositionDataBaseBuilderGenericFilter.txx"
+#endif
+
+#endif // #define CLITKRelativePositionDataBaseBuilderGENERICFILTER_H
diff --git a/tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx b/tools/clitkRelativePositionDataBaseBuilderGenericFilter.txx
new file mode 100644 (file)
index 0000000..6ce6a2a
--- /dev/null
@@ -0,0 +1,101 @@
+/*=========================================================================
+  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
+  ===========================================================================**/
+
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+clitk::RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType>::
+RelativePositionDataBaseBuilderGenericFilter():
+  ImageToImageGenericFilter<Self>("RelativePositionDataBaseBuilder")
+{
+  // Default values
+  cmdline_parser_clitkRelativePositionDataBaseBuilder_init(&mArgsInfo);
+  InitializeImageType<3>();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+template<unsigned int Dim>
+void clitk::RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType>::
+InitializeImageType() 
+{  
+  ADD_IMAGE_TYPE(Dim, uchar);
+}
+//--------------------------------------------------------------------
+  
+
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+void clitk::RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType>::
+SetArgsInfo(const ArgsInfoType & a) 
+{
+  mArgsInfo=a;
+  SetIOVerbose(mArgsInfo.verbose_flag);
+  if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes();
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+template<class FilterType>
+void clitk::RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType>::
+SetOptionsFromArgsInfoToFilter(FilterType * f) 
+{
+  f->SetAFDBFilename(mArgsInfo.afdb_arg);
+  f->SetAFDBPath(mArgsInfo.afdb_path_arg);
+  f->SetNumberOfBins(mArgsInfo.bins_arg);
+  f->SetNumberOfAngles(mArgsInfo.nb_arg);
+  f->SetAreaLossTolerance(mArgsInfo.tol_arg);
+  f->SetSupportName(mArgsInfo.supportName_arg);
+  f->SetTargetName(mArgsInfo.targetName_arg);
+  for(int i=0; i<mArgsInfo.objectName_given; i++)
+    f->AddObjectName(mArgsInfo.objectName_arg[i]);  
+}
+//--------------------------------------------------------------------
+
+
+//--------------------------------------------------------------------
+// Update with the number of dimensions and the pixeltype
+//--------------------------------------------------------------------
+template<class ArgsInfoType>
+template<class ImageType>
+void clitk::RelativePositionDataBaseBuilderGenericFilter<ArgsInfoType>::
+UpdateWithInputImageType() 
+{ 
+  // Create filter
+  typedef clitk::RelativePositionDataBaseBuilderFilter<ImageType> FilterType;
+  typename FilterType::Pointer filter = FilterType::New();
+  
+  // Set global Options 
+  SetOptionsFromArgsInfoToFilter<FilterType>(filter);
+
+  // Go !
+  filter->Update();
+  
+  // Write/Save results
+  //  typename ImageType::Pointer output = filter->GetOutput();
+  //this->template SetNextOutput<ImageType>(output); 
+
+}
+//--------------------------------------------------------------------
+
+