]> Creatis software - clitk.git/blob - segmentation/clitkExtractMediastinumFilter.h
3144c95be73a468f37d27e453342a6e406f73240
[clitk.git] / segmentation / clitkExtractMediastinumFilter.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 CLITKEXTRACTMEDIASTINUMFILTER_H
20 #define CLITKEXTRACTMEDIASTINUMFILTER_H
21
22 #include "clitkStructuresExtractionFilter.h"
23
24 namespace clitk {
25   
26   //--------------------------------------------------------------------
27   /*
28     Try to extract the mediastinum part of a thorax CT.
29     Input masks needed : 
30     - Patient
31     - Lungs 
32     - Bones [Optional]
33     - Trachea
34     - VertebralBody 
35   */
36   //--------------------------------------------------------------------
37   
38   template <class TImageType>
39   class ITK_EXPORT ExtractMediastinumFilter: 
40     public clitk::StructuresExtractionFilter<TImageType>
41   {
42
43   public:
44     /** Some convenient typedefs. */
45     typedef TImageType                       ImageType;
46     typedef typename ImageType::ConstPointer ImageConstPointer;
47     typedef typename ImageType::Pointer      ImagePointer;
48     typedef typename ImageType::RegionType   ImageRegionType; 
49     typedef typename ImageType::PixelType    ImagePixelType; 
50     typedef typename ImageType::SizeType     ImageSizeType; 
51     typedef typename ImageType::IndexType    ImageIndexType; 
52     typedef typename ImageType::PointType    ImagePointType; 
53         
54     /** Some convenient typedefs. */
55     typedef uchar MaskImagePixelType; 
56     typedef itk::Image<MaskImagePixelType, 3>    MaskImageType;
57     typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
58     typedef typename MaskImageType::Pointer      MaskImagePointer;
59     typedef typename MaskImageType::RegionType   MaskImageRegionType; 
60     typedef typename MaskImageType::SizeType     MaskImageSizeType; 
61     typedef typename MaskImageType::IndexType    MaskImageIndexType; 
62     typedef typename MaskImageType::PointType    MaskImagePointType; 
63         
64     typedef itk::Image<MaskImagePixelType, 2>    MaskSliceType;
65     typedef typename MaskSliceType::Pointer      MaskSlicePointer;
66     typedef typename MaskSliceType::PointType    MaskSlicePointType;
67
68     /** Standard class typedefs. */
69     //    typedef itk::ImageToImageFilter<TImageType, MaskImageType> Superclass;
70     typedef clitk::StructuresExtractionFilter<TImageType> Superclass;
71     typedef ExtractMediastinumFilter            Self;
72     typedef itk::SmartPointer<Self>             Pointer;
73     typedef itk::SmartPointer<const Self>       ConstPointer;
74     
75     /** Method for creation through the object factory. */
76     itkNewMacro(Self);
77     
78     /** Run-time type information (and related methods). */
79     itkTypeMacro(ExtractMediastinumFilter, InPlaceImageFilter);
80     FILTERBASE_INIT;
81
82     /** Connect inputs */
83     void SetInput(const ImageType * image);
84     void SetInputPatientLabelImage(const MaskImageType * image, MaskImagePixelType bg=0);
85     void SetInputLungLabelImage(const MaskImageType * image, MaskImagePixelType bg=0, 
86                                 MaskImagePixelType fgLeftLung=1, MaskImagePixelType fgRightLung=2);
87     void SetInputBonesLabelImage(const MaskImageType * image, MaskImagePixelType bg=0);
88     void SetInputTracheaLabelImage(const MaskImageType * image, MaskImagePixelType bg=0);
89
90     // Output filename  (for AFBD)
91     itkSetMacro(OutputMediastinumFilename, std::string);
92     itkGetConstMacro(OutputMediastinumFilename, std::string);
93
94     /** ImageDimension constants */
95     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
96
97     // Background / Foreground
98     itkSetMacro(BackgroundValuePatient, MaskImagePixelType);
99     itkGetConstMacro(BackgroundValuePatient, MaskImagePixelType);
100     
101     itkSetMacro(BackgroundValueLung, MaskImagePixelType);
102     itkGetConstMacro(BackgroundValueLung, MaskImagePixelType);
103     
104     itkSetMacro(BackgroundValueBones, MaskImagePixelType);
105     itkGetConstMacro(BackgroundValueBones, MaskImagePixelType);
106     
107     itkSetMacro(ForegroundValueLeftLung, MaskImagePixelType);
108     itkGetConstMacro(ForegroundValueLeftLung, MaskImagePixelType);
109     
110     itkSetMacro(ForegroundValueRightLung, MaskImagePixelType);
111     itkGetConstMacro(ForegroundValueRightLung, MaskImagePixelType);
112     
113     itkSetMacro(BackgroundValueTrachea, MaskImagePixelType);
114     itkGetConstMacro(BackgroundValueTrachea, MaskImagePixelType);
115     
116     itkSetMacro(IntermediateSpacing, double);
117     itkGetConstMacro(IntermediateSpacing, double);
118
119     itkBooleanMacro(UseBones);
120     itkSetMacro(UseBones, bool);
121     itkGetConstMacro(UseBones, bool);
122
123     itkSetMacro(DistanceMaxToAnteriorPartOfTheVertebralBody, double);
124     itkGetConstMacro(DistanceMaxToAnteriorPartOfTheVertebralBody, double);
125
126     void SetFuzzyThreshold(std::string tag, double value);
127     double GetFuzzyThreshold(std::string tag);
128
129   protected:
130     ExtractMediastinumFilter();
131     virtual ~ExtractMediastinumFilter() {}
132     
133     virtual void GenerateOutputInformation();
134     virtual void GenerateInputRequestedRegion();
135     virtual void GenerateData();
136          
137     MaskImagePixelType m_BackgroundValuePatient;
138     MaskImagePixelType m_BackgroundValueLung;
139     MaskImagePixelType m_BackgroundValueBones;
140     MaskImagePixelType m_BackgroundValueTrachea;
141     MaskImagePixelType m_ForegroundValueLeftLung;
142     MaskImagePixelType m_ForegroundValueRightLung;
143
144     MaskImagePointer output;
145     MaskImagePointer patient;
146     MaskImagePointer lung;
147     MaskImagePointer bones;
148     MaskImagePointer trachea;
149
150     std::map<std::string, double> m_FuzzyThreshold;
151     double m_IntermediateSpacing;
152     bool   m_UseBones;
153     double m_DistanceMaxToAnteriorPartOfTheVertebralBody;
154
155     void RemovePostPartOfVertebralBody();
156     
157     std::string m_OutputMediastinumFilename;
158     
159   private:
160     ExtractMediastinumFilter(const Self&); //purposely not implemented
161     void operator=(const Self&); //purposely not implemented
162     
163   }; // end class
164   //--------------------------------------------------------------------
165
166 } // end namespace clitk
167 //--------------------------------------------------------------------
168
169 #ifndef ITK_MANUAL_INSTANTIATION
170 #include "clitkExtractMediastinumFilter.txx"
171 #endif
172
173 #endif