]> Creatis software - clitk.git/blobdiff - segmentation/clitkExtractBonesFilter.txx
correct options scheme
[clitk.git] / segmentation / clitkExtractBonesFilter.txx
index ef3f9445ad171b4970d2aa8faf4cae1d87231daf..baa8fe8707aa8ea42fa8bc41790becf63668d39e 100644 (file)
@@ -24,6 +24,7 @@
 #include "clitkSetBackgroundImageFilter.h"
 #include "clitkSegmentationUtils.h"
 #include "clitkAutoCropFilter.h"
+#include "clitkFillMaskFilter.h"
 
 // itk
 #include "itkBinaryThresholdImageFilter.h"
 #include "itkCurvatureAnisotropicDiffusionImageFilter.h"
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-clitk::ExtractBonesFilter<TInputImageType, TOutputImageType>::
+template <class TInputImageType>
+clitk::ExtractBonesFilter<TInputImageType>::
 ExtractBonesFilter():
   clitk::FilterBase(),
-  itk::ImageToImageFilter<TInputImageType, TOutputImageType>()
+  clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
+  itk::ImageToImageFilter<TInputImageType, MaskImageType>()
 {
   // Default global options
   this->SetNumberOfRequiredInputs(1);
@@ -61,15 +63,16 @@ ExtractBonesFilter():
   s.Fill(1);
   SetRadius2(s);
   SetSampleRate2(0);
-  AutoCropOff();
+  AutoCropOn();
+  FillHolesOn();
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
 void 
-clitk::ExtractBonesFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractBonesFilter<TInputImageType>::
 SetInput(const TInputImageType * image) 
 {
   this->SetNthInput(0, const_cast<TInputImageType *>(image));
@@ -77,58 +80,30 @@ SetInput(const TInputImageType * image)
 //--------------------------------------------------------------------
 
 
-//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-template<class ArgsInfoType>
-void 
-clitk::ExtractBonesFilter<TInputImageType, TOutputImageType>::
-SetArgsInfo(ArgsInfoType mArgsInfo)
-{
-  SetVerboseOption_GGO(mArgsInfo);
-  SetVerboseStep_GGO(mArgsInfo);
-  SetWriteStep_GGO(mArgsInfo);
-  SetVerboseWarningOff_GGO(mArgsInfo);
-  
-  SetInitialSmoothing_GGO(mArgsInfo);
-  SetSmoothingConductanceParameter_GGO(mArgsInfo);
-  SetSmoothingNumberOfIterations_GGO(mArgsInfo);
-  SetSmoothingTimeStep_GGO(mArgsInfo);
-  SetSmoothingUseImageSpacing_GGO(mArgsInfo);
-
-  SetMinimalComponentSize_GGO(mArgsInfo);
-  SetUpperThreshold1_GGO(mArgsInfo);
-  SetLowerThreshold1_GGO(mArgsInfo);
-  SetFullConnectivity_GGO(mArgsInfo);
-
-  SetUpperThreshold2_GGO(mArgsInfo);
-  SetLowerThreshold2_GGO(mArgsInfo);
-  SetRadius2_GGO(mArgsInfo);
-  SetSampleRate2_GGO(mArgsInfo);
-  SetAutoCrop_GGO(mArgsInfo);
-}
-//--------------------------------------------------------------------
-
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
 void 
-clitk::ExtractBonesFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractBonesFilter<TInputImageType>::
 GenerateOutputInformation() { 
+
   // Get input pointers
   InputImagePointer input   = dynamic_cast<TInputImageType*>(itk::ProcessObject::GetInput(0));
-  //  InputImagePointer input = dynamic_cast<TInputImageType*>(itk::ProcessObject::GetInput(0));
   Superclass::GenerateOutputInformation();
-  OutputImagePointer outputImage = this->GetOutput(0);
+  MaskImagePointer outputImage = this->GetOutput(0);
   outputImage->SetRegions(input->GetLargestPossibleRegion());
 
+  // Read DB
+  LoadAFDB();
+
   // typedefs
   typedef itk::BinaryThresholdImageFilter<InputImageType, InternalImageType> InputBinarizeFilterType;
   typedef itk::BinaryThresholdImageFilter<InternalImageType, InternalImageType> BinarizeFilterType;
   typedef itk::ConnectedComponentImageFilter<InternalImageType, InternalImageType> ConnectFilterType;
   typedef itk::RelabelComponentImageFilter<InternalImageType, InternalImageType> RelabelFilterType;
   typedef clitk::SetBackgroundImageFilter<InternalImageType,InternalImageType, InternalImageType> SetBackgroundFilterType; 
-  typedef itk::CastImageFilter<InternalImageType,OutputImageType> CastImageFilterType; 
-  typedef itk::ImageFileWriter<OutputImageType> WriterType; 
+  typedef itk::CastImageFilter<InternalImageType,MaskImageType> CastImageFilterType; 
+  typedef itk::ImageFileWriter<MaskImageType> WriterType; 
 
   //---------------------------------
   // Smoothing [Optional]
@@ -254,6 +229,20 @@ GenerateOutputInformation() {
 
   output = setBackgroundFilter->GetOutput();
 
+  //--------------------------------------------------------------------
+  //--------------------------------------------------------------------
+  // Fill Bones
+  if (GetFillHoles()) {
+    StartNewStep("Fill Holes");
+    typedef clitk::FillMaskFilter<InternalImageType> FillMaskFilterType;
+    typename FillMaskFilterType::Pointer fillMaskFilter = FillMaskFilterType::New();
+    fillMaskFilter->SetInput(output);
+    fillMaskFilter->AddDirection(2);
+    fillMaskFilter->Update();   
+    output = fillMaskFilter->GetOutput();
+    StopCurrentStep<InternalImageType>(output);
+  }
+
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
   // [Optional]
@@ -274,20 +263,23 @@ GenerateOutputInformation() {
 
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
 void 
-clitk::ExtractBonesFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractBonesFilter<TInputImageType>::
 GenerateData() {
 
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
   // Final Cast 
-  typedef itk::CastImageFilter<InternalImageType, OutputImageType> CastImageFilterType;
+  typedef itk::CastImageFilter<InternalImageType, MaskImageType> CastImageFilterType;
   typename CastImageFilterType::Pointer caster= CastImageFilterType::New();
   caster->SetInput(output);
   caster->Update();
-  //this->SetNthOutput(0, caster->GetOutput());
   this->GraftOutput(caster->GetOutput());
+
+  // Store image filenames into AFDB 
+  GetAFDB()->SetImageFilename("Bones", this->GetOutputBonesFilename());  
+  WriteAFDB();
   return;
 }
 //--------------------------------------------------------------------