]> Creatis software - clitk.git/blob - segmentation/clitkExtractAirwaysTreeInfoFilter.h
changes in license header
[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://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 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
57     IndexType index;
58     PointType point;
59     double weight;
60     PixelType l;
61     PixelType l1;
62     PixelType l2;
63     typedef itk::Index<3> NodeType;
64     typedef tree<NodeType> TreeType;
65     typedef TreeType::iterator TreeIterator;
66     TreeIterator treeIter;
67   };
68   //--------------------------------------------------------------------
69
70
71   //--------------------------------------------------------------------
72   template <class TImageType>
73   class ITK_EXPORT ExtractAirwaysTreeInfoFilter: 
74     public virtual clitk::FilterBase, 
75     public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
76     public itk::ImageToImageFilter<TImageType, TImageType> 
77   {
78     
79   public:
80     /** Standard class typedefs. */
81     typedef itk::ImageToImageFilter<TImageType, TImageType> Superclass;
82     typedef ExtractAirwaysTreeInfoFilter         Self;
83     typedef itk::SmartPointer<Self>             Pointer;
84     typedef itk::SmartPointer<const Self>       ConstPointer;
85     
86     /** Method for creation through the object factory. */
87     itkNewMacro(Self);  
88     
89     /** Run-time type information (and related methods). */
90     itkTypeMacro(ExtractAirwaysTreeInfoFilter, ImageToImageFilter);
91     FILTERBASE_INIT;
92
93     /** Some convenient typedefs */
94     typedef TImageType                       ImageType;
95     typedef typename ImageType::ConstPointer ImageConstPointer;
96     typedef typename ImageType::Pointer      ImagePointer;
97     typedef typename ImageType::RegionType   ImageRegionType; 
98     typedef typename ImageType::PixelType    ImagePixelType; 
99     typedef typename ImageType::SizeType     ImageSizeType; 
100     typedef typename ImageType::IndexType    ImageIndexType; 
101     typedef typename ImageType::PointType    ImagePointType; 
102         
103     typedef Bifurcation BifurcationType;
104     typedef ImageIndexType NodeType;
105     typedef tree<NodeType> TreeType;
106     typedef typename TreeType::iterator TreeIterator;
107
108     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
109     typedef int InternalPixelType;
110     typedef itk::Image<InternalPixelType, ImageType::ImageDimension> InternalImageType;
111     typedef typename InternalImageType::Pointer                      InternalImagePointer;
112     typedef typename InternalImageType::IndexType                    InternalIndexType;
113     typedef LabelizeParameters<InternalPixelType>                    LabelParamType;
114
115     // Data Structures for trees 
116     struct FullTreeNodeType {
117       ImageIndexType index;
118       ImagePointType point;
119       double weight;
120     };
121     struct StructuralTreeNodeType {
122       ImageIndexType index;
123       ImagePointType point;
124       double weight;
125     };
126     typedef tree<FullTreeNodeType> FullTreeType;
127     typedef tree<StructuralTreeNodeType> StructuralTreeType;
128     FullTreeType mFullSkeletonTree; 
129     StructuralTreeType mStructuralSkeletonTree;
130
131     /** Connect inputs */
132     void SetInput(const ImageType * image);
133
134     // Background / Foreground
135     itkGetConstMacro(BackgroundValue, ImagePixelType);
136     itkGetConstMacro(ForegroundValue, ImagePixelType);
137     
138     // Get results
139     itkGetConstMacro(FirstTracheaPoint, ImagePointType);
140     itkGetConstMacro(CarinaPoint, ImagePointType);
141
142   protected:
143     ExtractAirwaysTreeInfoFilter();
144     virtual ~ExtractAirwaysTreeInfoFilter() {}
145
146     // Main members
147     ImageConstPointer input;
148     ImagePointer skeleton;
149     ImagePointer working_input;
150
151     // Global options
152     itkSetMacro(BackgroundValue, ImagePixelType);
153     itkSetMacro(ForegroundValue, ImagePixelType);
154     ImagePixelType m_BackgroundValue;
155     ImagePixelType m_ForegroundValue;
156
157     // Results
158     ImagePointType m_FirstTracheaPoint;
159     ImagePointType m_CarinaPoint;
160     
161     virtual void GenerateOutputInformation();
162     virtual void GenerateData();
163
164     TreeType m_SkeletonTree;
165     void TrackFromThisIndex2(ImageIndexType index, ImagePointer skeleton, 
166                              ImagePixelType label, 
167                              typename FullTreeType::iterator currentNode, 
168                              typename StructuralTreeType::iterator currentSNode);
169     void TrackFromThisIndex(std::vector<BifurcationType> & listOfBifurcations, 
170                             ImagePointer skeleton, 
171                             ImageIndexType index,
172                             ImagePixelType label, 
173                             TreeIterator currentNode);
174   private:
175     ExtractAirwaysTreeInfoFilter(const Self&); //purposely not implemented
176     void operator=(const Self&); //purposely not implemented
177     
178   }; // end class
179   //--------------------------------------------------------------------
180
181 } // end namespace clitk
182 //--------------------------------------------------------------------
183
184 #ifndef ITK_MANUAL_INSTANTIATION
185 #include "clitkExtractAirwaysTreeInfoFilter.txx"
186 #endif
187
188 #endif