]> Creatis software - clitk.git/blob - itk/clitkRelativePositionAnalyzerFilter.h
GateAsciiImageIO is now cross-platform using itksys::RegularExpression
[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 itk::ImageToImageFilter<ImageType, ImageType>
47   {
48
49   public:
50     /** Standard class typedefs. */
51     typedef itk::ImageToImageFilter<ImageType, ImageType>      Superclass;
52     typedef RelativePositionAnalyzerFilter<ImageType>          Self;
53     typedef itk::SmartPointer<Self>                            Pointer;
54     typedef itk::SmartPointer<const Self>                      ConstPointer;
55        
56     /** Method for creation through the object factory. */
57     itkNewMacro(Self);
58     
59     /** Run-time type information (and related methods). */
60     itkTypeMacro(RelativePositionAnalyzerFilter, ImageToImageFilter);
61
62     /** Some convenient typedefs. */
63     typedef typename ImageType::ConstPointer ImageConstPointer;
64     typedef typename ImageType::Pointer      ImagePointer;
65     typedef typename ImageType::RegionType   RegionType; 
66     typedef typename ImageType::PixelType    PixelType;
67     typedef typename ImageType::SpacingType  SpacingType;
68     typedef typename ImageType::SizeType     SizeType;
69     typedef typename ImageType::IndexType    IndexType;
70     typedef typename ImageType::PointType    PointType;
71     
72     /** ImageDimension constants */
73     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
74     FILTERBASE_INIT;
75     typedef itk::Image<float, ImageDimension> FloatImageType;
76
77      /** Input : initial image and object */
78     void SetInputSupport(const ImageType * image);
79     void SetInputObject(const ImageType * image);
80     void SetInputTarget(const ImageType * image);
81     
82     // Input
83     // supportname, objectname multiple targetname
84     
85     // Options
86     itkGetConstMacro(BackgroundValue, PixelType);
87     itkSetMacro(BackgroundValue, PixelType);
88
89     itkGetConstMacro(ForegroundValue, PixelType);
90     itkSetMacro(ForegroundValue, PixelType);
91
92     clitk::RelativePositionDirectionType & GetDirection() { return m_Direction; }
93     void SetDirection(clitk::RelativePositionDirectionType & d) { m_Direction = d; }
94
95     itkGetConstMacro(NumberOfBins, int);
96     itkSetMacro(NumberOfBins, int);
97
98     itkGetConstMacro(AreaLossTolerance, double);
99     itkSetMacro(AreaLossTolerance, double);
100
101     itkGetConstMacro(SupportSize, int);
102     itkGetConstMacro(TargetSize, int);
103     itkGetConstMacro(SizeWithThreshold, int);
104     itkGetConstMacro(SizeWithReverseThreshold, int);
105
106     itkGetConstMacro(Info, clitk::RelativePositionInformationType);
107     itkGetConstMacro(InfoReverse, clitk::RelativePositionInformationType);
108
109     // For debug
110     void PrintOptions();
111     
112     // Print output
113     void Print(std::ostream & os=std::cout);
114
115     // I dont want to verify inputs information
116     virtual void VerifyInputInformation() { }
117     
118    protected:
119     RelativePositionAnalyzerFilter();
120     virtual ~RelativePositionAnalyzerFilter() {}
121     
122     itkSetMacro(SupportSize, int);
123     itkSetMacro(TargetSize, int);
124     itkSetMacro(SizeWithThreshold, int);
125     itkSetMacro(SizeWithReverseThreshold, int);
126
127     PixelType m_BackgroundValue;
128     PixelType m_ForegroundValue;
129     ImagePointer m_Support;
130     ImagePointer m_Object;
131     ImagePointer m_Target;
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     clitk::RelativePositionDirectionType m_Direction;
139     clitk::RelativePositionInformationType m_Info;
140     clitk::RelativePositionInformationType m_InfoReverse;
141     
142     virtual void GenerateOutputInformation();
143     virtual void GenerateData();
144
145     typename FloatImageType::Pointer
146     ComputeFuzzyMap(ImageType * object, ImageType * target, ImageType * support, 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