]> Creatis software - clitk.git/blob - segmentation/clitkExtractAirwaysTreeInfoFilter.h
new Airway filter (experimental)
[clitk.git] / segmentation / clitkExtractAirwaysTreeInfoFilter.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://oncora1.lyon.fnclcc.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 CLITKEXTRACTAIRWAYTREEINFOSFILTER_H
20 #define CLITKEXTRACTAIRWAYTREEINFOSFILTER_H
21
22 // clitk 
23 #include "clitkFilterBase.h"
24 #include "clitkDecomposeAndReconstructImageFilter.h"
25 #include "clitkExplosionControlledThresholdConnectedImageFilter.h"
26 #include "clitkSegmentationUtils.h"
27 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
28 #include "tree.hh"
29
30 // itk
31 #include "itkStatisticsImageFilter.h"
32
33 namespace clitk {
34   
35   //--------------------------------------------------------------------
36   /*
37     From a trachea binary image, compute the skeleton and track the
38     path to find the carena.
39   */
40   //--------------------------------------------------------------------
41   
42
43
44   class Bifurcation
45   {
46   public:
47     typedef itk::Index<3> IndexType;
48     typedef itk::Point<double, 3> PointType;
49     typedef double PixelType;
50     Bifurcation(IndexType _index, PixelType _l, PixelType _l1, PixelType _l2) {
51       index = _index;
52       _l = l;
53       _l1 = l1;
54       _l2 = l2;
55     }
56     IndexType index;
57     PointType point;
58     PixelType l;
59     PixelType l1;
60     PixelType l2;
61     typedef itk::Index<3> NodeType;
62     typedef tree<NodeType> TreeType;
63     typedef TreeType::iterator TreeIterator;
64     TreeIterator treeIter;
65   };
66   //--------------------------------------------------------------------
67
68
69   //--------------------------------------------------------------------
70   template <class TImageType>
71   class ITK_EXPORT ExtractAirwaysTreeInfoFilter: 
72     public virtual clitk::FilterBase, 
73     public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
74     public itk::ImageToImageFilter<TImageType, TImageType> 
75   {
76     
77   public:
78     /** Standard class typedefs. */
79     typedef itk::ImageToImageFilter<TImageType, TImageType> Superclass;
80     typedef ExtractAirwaysTreeInfoFilter         Self;
81     typedef itk::SmartPointer<Self>             Pointer;
82     typedef itk::SmartPointer<const Self>       ConstPointer;
83     
84     /** Method for creation through the object factory. */
85     itkNewMacro(Self);  
86     
87     /** Run-time type information (and related methods). */
88     itkTypeMacro(ExtractAirwaysTreeInfoFilter, ImageToImageFilter);
89     FILTERBASE_INIT;
90
91     /** Some convenient typedefs */
92     typedef TImageType                       ImageType;
93     typedef typename ImageType::ConstPointer ImageConstPointer;
94     typedef typename ImageType::Pointer      ImagePointer;
95     typedef typename ImageType::RegionType   ImageRegionType; 
96     typedef typename ImageType::PixelType    ImagePixelType; 
97     typedef typename ImageType::SizeType     ImageSizeType; 
98     typedef typename ImageType::IndexType    ImageIndexType; 
99     typedef typename ImageType::PointType    ImagePointType; 
100         
101     typedef Bifurcation BifurcationType;
102     typedef ImageIndexType NodeType;
103     typedef tree<NodeType> TreeType;
104     typedef typename TreeType::iterator TreeIterator;
105
106     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
107     typedef int InternalPixelType;
108     typedef itk::Image<InternalPixelType, ImageType::ImageDimension> InternalImageType;
109     typedef typename InternalImageType::Pointer                      InternalImagePointer;
110     typedef typename InternalImageType::IndexType                    InternalIndexType;
111     typedef LabelizeParameters<InternalPixelType>                    LabelParamType;
112     
113     /** Connect inputs */
114     void SetInput(const ImageType * image);
115
116     // Set all options at a time
117     template<class ArgsInfoType>
118       void SetArgsInfo(ArgsInfoType arg);
119
120     // Background / Foreground
121     itkGetConstMacro(BackgroundValue, ImagePixelType);
122     itkGetConstMacro(ForegroundValue, ImagePixelType);
123     
124     // Get results
125     itkGetConstMacro(FirstTracheaPoint, ImagePointType);
126     itkGetConstMacro(CarinaPoint, ImagePointType);
127
128   protected:
129     ExtractAirwaysTreeInfoFilter();
130     virtual ~ExtractAirwaysTreeInfoFilter() {}
131
132     // Main members
133     ImageConstPointer input;
134     ImagePointer skeleton;
135     ImagePointer working_input;
136
137     // Global options
138     itkSetMacro(BackgroundValue, ImagePixelType);
139     itkSetMacro(ForegroundValue, ImagePixelType);
140     ImagePixelType m_BackgroundValue;
141     ImagePixelType m_ForegroundValue;
142
143     // Results
144     ImagePointType m_FirstTracheaPoint;
145     ImagePointType m_CarinaPoint;
146     
147     virtual void GenerateOutputInformation();
148     virtual void GenerateData();
149
150     TreeType m_SkeletonTree;
151     void TrackFromThisIndex(std::vector<BifurcationType> & listOfBifurcations, 
152                             ImagePointer skeleton, 
153                             ImageIndexType index,
154                             ImagePixelType label, 
155                             TreeIterator currentNode);
156   private:
157     ExtractAirwaysTreeInfoFilter(const Self&); //purposely not implemented
158     void operator=(const Self&); //purposely not implemented
159     
160   }; // end class
161   //--------------------------------------------------------------------
162
163 } // end namespace clitk
164 //--------------------------------------------------------------------
165
166 #ifndef ITK_MANUAL_INSTANTIATION
167 #include "clitkExtractAirwaysTreeInfoFilter.txx"
168 #endif
169
170 #endif