]> Creatis software - clitk.git/blobdiff - segmentation/clitkExtractLungFilter.h
add lib dependence to some tools
[clitk.git] / segmentation / clitkExtractLungFilter.h
index 6a316d2c81f9d219f8a30187c10c1da5f108dc6c..3183457dde0a6eb7ff06d445670cb132523a2ae8 100644 (file)
@@ -24,6 +24,7 @@
 #include "clitkDecomposeAndReconstructImageFilter.h"
 #include "clitkExplosionControlledThresholdConnectedImageFilter.h"
 #include "clitkSegmentationUtils.h"
+#include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
 
 // itk
 #include "itkStatisticsImageFilter.h"
@@ -54,36 +55,18 @@ namespace clitk {
   */
   //--------------------------------------------------------------------
   
-
-  //--------------------------------------------------------------------
-template<class IndexType, class PixelType>
-class Bifurcation
-{
-public:
-  Bifurcation(IndexType _index, PixelType _l, PixelType _l1, PixelType _l2) {
-    index = _index;
-    _l = l;
-    _l1 = l1;
-    _l2 = l2;
-  }
-  IndexType index;
-  PixelType l;
-  PixelType l1;
-  PixelType l2;
-};
-  //--------------------------------------------------------------------
-
-
   //--------------------------------------------------------------------
-  template <class TImageType, class TMaskImageType>
+  template <class TImageType>
   class ITK_EXPORT ExtractLungFilter: 
-    public clitk::FilterBase, 
-    public itk::ImageToImageFilter<TImageType, TMaskImageType> 
+    public virtual clitk::FilterBase, 
+    public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
+    public itk::ImageToImageFilter<TImageType, itk::Image<uchar, TImageType::ImageDimension> > 
   {
     
   public:
     /** Standard class typedefs. */
-    typedef itk::ImageToImageFilter<TImageType, TMaskImageType> Superclass;
+    typedef itk::Image<uchar, TImageType::ImageDimension> MaskImageType;
+    typedef itk::ImageToImageFilter<TImageType, MaskImageType> Superclass;
     typedef ExtractLungFilter              Self;
     typedef itk::SmartPointer<Self>        Pointer;
     typedef itk::SmartPointer<const Self>  ConstPointer;
@@ -103,14 +86,15 @@ public:
     typedef typename ImageType::PixelType    InputImagePixelType; 
     typedef typename ImageType::SizeType     InputImageSizeType; 
     typedef typename ImageType::IndexType    InputImageIndexType; 
+    typedef typename ImageType::PointType    InputImagePointType; 
         
-    typedef TMaskImageType                       MaskImageType;
     typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
     typedef typename MaskImageType::Pointer      MaskImagePointer;
     typedef typename MaskImageType::RegionType   MaskImageRegionType; 
     typedef typename MaskImageType::PixelType    MaskImagePixelType; 
     typedef typename MaskImageType::SizeType     MaskImageSizeType; 
     typedef typename MaskImageType::IndexType    MaskImageIndexType; 
+    typedef typename MaskImageType::PointType    MaskImagePointType; 
 
     itkStaticConstMacro(ImageDimension, unsigned int, ImageType::ImageDimension);
     typedef int InternalPixelType;
@@ -121,11 +105,19 @@ public:
     
     /** Connect inputs */
     void SetInput(const ImageType * image);
-    void SetInputPatientMask(MaskImageType * mask, MaskImagePixelType BG);
     itkSetMacro(PatientMaskBackgroundValue, MaskImagePixelType);
     itkGetConstMacro(PatientMaskBackgroundValue, MaskImagePixelType);
     GGO_DefineOption(patientBG, SetPatientMaskBackgroundValue, MaskImagePixelType);
 
+    // Output filename  (for AFBD)
+    itkSetMacro(OutputLungFilename, std::string);
+    itkGetMacro(OutputLungFilename, std::string);
+    GGO_DefineOption(output, SetOutputLungFilename, std::string);
+
+    itkSetMacro(OutputTracheaFilename, std::string);
+    itkGetMacro(OutputTracheaFilename, std::string);
+    GGO_DefineOption(outputTrachea, SetOutputTracheaFilename, std::string);
+
     // Set all options at a time
     template<class ArgsInfoType>
       void SetArgsInfo(ArgsInfoType arg);
@@ -197,15 +189,21 @@ public:
     itkGetConstMacro(LabelizeParameters3, LabelParamType*);
     GGO_DefineOption_LabelParam(3, SetLabelizeParameters3, LabelParamType);
 
-    // Step 5 options LungSeparation
-    //     itkSetMacro(FinalOpenClose, bool);
-    //     itkGetConstMacro(FinalOpenClose, bool);
-    //     itkBooleanMacro(FinalOpenClose);
+    // Step 5 final openclose
+    itkSetMacro(OpenClose, bool);
+    itkGetConstMacro(OpenClose, bool);
+    itkBooleanMacro(OpenClose);
+    GGO_DefineOption_Flag(openclose, SetOpenClose);
 
-    // Bronchial bifurcations
-    itkSetMacro(FindBronchialBifurcations, bool);
-    itkGetConstMacro(FindBronchialBifurcations, bool);
-    itkBooleanMacro(FindBronchialBifurcations);
+    itkSetMacro(OpenCloseRadius, int);
+    itkGetConstMacro(OpenCloseRadius, int);
+    GGO_DefineOption(opencloseRadius, SetOpenCloseRadius, int);
+    
+    // Step 6 fill holes
+    itkSetMacro(FillHoles, bool);
+    itkGetConstMacro(FillHoles, bool);
+    itkBooleanMacro(FillHoles);
+    GGO_DefineOption_Flag(doNotFillHoles, SetFillHoles);
 
   protected:
     ExtractLungFilter();
@@ -215,6 +213,8 @@ public:
     InputImageConstPointer input;
     MaskImageConstPointer patient;
     InputImagePointer working_input;
+    std::string m_OutputLungFilename;
+    std::string m_OutputTracheaFilename;
     typename InternalImageType::Pointer working_image;  
     typename InternalImageType::Pointer trachea_tmp;
     MaskImagePointer trachea;
@@ -251,20 +251,18 @@ public:
     LabelParamType* m_LabelizeParameters3;
 
     // Step 5
-    //     bool m_FinalOpenClose;
-    
-    bool m_FindBronchialBifurcations;
-    
-    virtual void GenerateOutputInformation();
-    virtual void GenerateData();
+    bool m_OpenClose;    
+    int m_OpenCloseRadius;
 
-    typedef Bifurcation<MaskImageIndexType,MaskImagePixelType> BifurcationType;
-    void TrackFromThisIndex(std::vector<BifurcationType> & listOfBifurcations, 
-                            MaskImagePointer skeleton, 
-                            MaskImageIndexType index,
-                            MaskImagePixelType label);
-        
+    // Step 6
+    bool m_FillHoles;    
+    InputImageSizeType m_FillHolesDirections;
 
+    // Main functions
+    virtual void GenerateOutputInformation();
+    virtual void GenerateData();
+    
+    // Functions for trachea extraction
     bool SearchForTracheaSeed(int skip);
     void SearchForTrachea();
     void TracheaRegionGrowing();