]> Creatis software - clitk.git/blob - itk/clitkRelativePositionAnalyzerFilter.h
Correct angle units
[clitk.git] / itk / clitkRelativePositionAnalyzerFilter.h
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to: 
5   - University of LYON              http://www.universite-lyon.fr/
6   - Léon Bérard cancer center       http://www.centreleonberard.fr
7   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
8
9   This software is distributed WITHOUT ANY WARRANTY; without even
10   the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11   PURPOSE.  See the copyright notices for more information.
12
13   It is distributed under dual licence
14
15   - BSD        See included LICENSE.txt file
16   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17   ===========================================================================**/
18
19 #ifndef CLITKRELATIVEPOSITIONANALYZERFILTER_H
20 #define CLITKRELATIVEPOSITIONANALYZERFILTER_H
21
22 // clitk
23 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
24 #include "clitkFilterBase.h"
25 #include "clitkSliceBySliceRelativePositionFilter.h"
26 #include "clitkRelativePositionDataBase.h"
27
28 // itk
29 #include <itkImageToImageFilter.h>
30 #include <itkLabelStatisticsImageFilter.h>
31
32 namespace clitk {
33   
34   //--------------------------------------------------------------------
35   /*
36     Analyze the relative position of a Target (mask image) according
37     to some Object (mask image), in a given Support (mask
38     image). Compute the optimal threshold allowing to remove the
39     maximal area from the Support without removing area belonging to
40     the Target.
41   */
42   //--------------------------------------------------------------------
43   
44   template <class ImageType>
45   class RelativePositionAnalyzerFilter:
46     // public virtual clitk::FilterBase, 
47     public clitk::FilterWithAnatomicalFeatureDatabaseManagement, 
48     public itk::ImageToImageFilter<ImageType, ImageType>
49   {
50
51   public:
52     /** Standard class typedefs. */
53     typedef itk::ImageToImageFilter<ImageType, ImageType>      Superclass;
54     typedef RelativePositionAnalyzerFilter<ImageType>          Self;
55     typedef itk::SmartPointer<Self>                            Pointer;
56     typedef itk::SmartPointer<const Self>                      ConstPointer;
57        
58     /** Method for creation through the object factory. */
59     itkNewMacro(Self);
60     
61     /** Run-time type information (and related methods). */
62     itkTypeMacro(RelativePositionAnalyzerFilter, ImageToImageFilter);
63
64     /** Some convenient typedefs. */
65     typedef typename ImageType::ConstPointer ImageConstPointer;
66     typedef typename ImageType::Pointer      ImagePointer;
67     typedef typename ImageType::RegionType   RegionType; 
68     typedef typename ImageType::PixelType    PixelType;
69     typedef typename ImageType::SpacingType  SpacingType;
70     typedef typename ImageType::SizeType     SizeType;
71     typedef typename ImageType::IndexType    IndexType;
72     typedef typename ImageType::PointType    PointType;
73     
74     /** ImageDimension constants */
75     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
76     FILTERBASE_INIT;
77     typedef itk::Image<float, ImageDimension> FloatImageType;
78
79      /** Input : initial image and object */
80     void SetInputSupport(const ImageType * image);
81     void SetInputObject(const ImageType * image);
82     void SetInputTarget(const ImageType * image);
83     
84     // Options
85     itkGetConstMacro(BackgroundValue, PixelType);
86     itkSetMacro(BackgroundValue, PixelType);
87
88     itkGetConstMacro(ForegroundValue, PixelType);
89     itkSetMacro(ForegroundValue, PixelType);
90
91     itkGetConstMacro(NumberOfBins, int);
92     itkSetMacro(NumberOfBins, int);
93
94     itkGetConstMacro(NumberOfAngles, int);
95     itkSetMacro(NumberOfAngles, int);
96
97     itkGetConstMacro(AreaLossTolerance, double);
98     itkSetMacro(AreaLossTolerance, double);
99
100     itkGetConstMacro(SupportSize, int);
101     itkGetConstMacro(TargetSize, int);
102     itkGetConstMacro(SizeWithThreshold, int);
103     itkGetConstMacro(SizeWithReverseThreshold, int);
104
105     std::vector<clitk::RelativePositionInformationType> & GetListOfInformation() { return m_ListOfInformation; }
106     std::vector<clitk::RelativePositionOrientationType> & GetListOfOrientation() { return m_ListOfOrientation; }
107
108     // For debug
109     void PrintOptions();
110     
111     // Print output
112     void Print(std::string s=" ", std::ostream & os=std::cout);
113
114     // I dont want to verify inputs information
115     virtual void VerifyInputInformation() { }
116     
117    protected:
118     RelativePositionAnalyzerFilter();
119     virtual ~RelativePositionAnalyzerFilter() {}
120     
121     itkSetMacro(SupportSize, int);
122     itkSetMacro(TargetSize, int);
123     itkSetMacro(SizeWithThreshold, int);
124     itkSetMacro(SizeWithReverseThreshold, int);
125
126     PixelType m_BackgroundValue;
127     PixelType m_ForegroundValue;
128     ImagePointer m_Support;
129     ImagePointer m_Object;
130     ImagePointer m_Target;
131     int m_NumberOfAngles;
132     int m_NumberOfBins;
133     double m_AreaLossTolerance;
134     int m_SupportSize;
135     int m_TargetSize;
136     int m_SizeWithReverseThreshold;
137     int m_SizeWithThreshold;
138     std::vector<double> m_ListOfAngles;
139     std::vector<clitk::RelativePositionInformationType> m_ListOfInformation;
140     std::vector<clitk::RelativePositionOrientationType> m_ListOfOrientation;
141     
142     virtual void GenerateOutputInformation();
143     virtual void GenerateData();
144
145     typename FloatImageType::Pointer
146     ComputeFuzzyMap(ImageType * object, ImageType * target, double angle);
147     
148     void
149     ComputeOptimalThresholds(FloatImageType * map, ImageType * target, int bins, double tolerance, 
150                              double & threshold, double & reverseThreshold);
151   private:
152     RelativePositionAnalyzerFilter(const Self&); //purposely not implemented
153     void operator=(const Self&); //purposely not implemented
154     
155   }; // end class
156   //--------------------------------------------------------------------
157
158 } // end namespace clitk
159 //--------------------------------------------------------------------
160
161 #include "clitkRelativePositionAnalyzerFilter.txx"
162
163 #endif