]> Creatis software - clitk.git/blobdiff - segmentation/clitkExtractPatientFilter.txx
Do not change visilibity of actors when changing renderer drawing action
[clitk.git] / segmentation / clitkExtractPatientFilter.txx
index e9dd6fe57bd8da7f034b7c27634c99376ebbccad..a04232b9d3a72119f973fa784cc9f2011aee6a52 100644 (file)
@@ -3,7 +3,7 @@
 
   Authors belong to: 
   - University of LYON              http://www.universite-lyon.fr/
-  - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
+  - Léon Bérard cancer center       http://www.centreleonberard.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   This software is distributed WITHOUT ANY WARRANTY; without even
@@ -14,7 +14,7 @@
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-  ======================================================================-====*/
+  ===========================================================================**/
 
 #ifndef CLITKEXTRACTPATIENTFILTER_TXX
 #define CLITKEXTRACTPATIENTFILTER_TXX
@@ -24,6 +24,8 @@
 #include "clitkSetBackgroundImageFilter.h"
 #include "clitkDecomposeAndReconstructImageFilter.h"
 #include "clitkAutoCropFilter.h"
+#include "clitkMemoryUsage.h"
+#include "clitkSegmentationUtils.h"
 
 // itk
 #include "itkBinaryThresholdImageFilter.h"
 #include "itkCastImageFilter.h"
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+template <class TInputImageType>
+clitk::ExtractPatientFilter<TInputImageType>::
 ExtractPatientFilter():
   clitk::FilterBase(),
-  itk::ImageToImageFilter<TInputImageType, TOutputImageType>()
+  clitk::FilterWithAnatomicalFeatureDatabaseManagement(),
+  itk::ImageToImageFilter<TInputImageType, MaskImageType>()
 {
   this->SetNumberOfRequiredInputs(1);
   SetBackgroundValue(0); // Must be zero
@@ -71,16 +74,16 @@ ExtractPatientFilter():
   SetLastKeep(1);
   
   // Step 4: OpenClose (option)
-  FinalOpenCloseOn();
-  AutoCropOff();
+  FinalOpenCloseOff();
+  AutoCropOn();
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
 void 
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractPatientFilter<TInputImageType>::
 SetInput(const TInputImageType * image) 
 {
   this->SetNthInput(0, const_cast<TInputImageType *>(image));
@@ -89,49 +92,17 @@ SetInput(const TInputImageType * image)
 
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-template<class ArgsInfoType>
+template <class TInputImageType>
 void 
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
-SetArgsInfo(ArgsInfoType arg)
-{
-  SetVerboseOption_GGO(arg);
-  SetVerboseStep_GGO(arg);
-  SetWriteStep_GGO(arg);
-  SetVerboseWarningOff_GGO(arg);
-
-  SetUpperThreshold_GGO(arg);
-  SetLowerThreshold_GGO(arg);
-
-  SetDecomposeAndReconstructDuringFirstStep_GGO(arg);
-  SetRadius1_GGO(arg);
-  SetMaximumNumberOfLabels1_GGO(arg);
-  SetNumberOfNewLabels1_GGO(arg);
-
-  SetDecomposeAndReconstructDuringSecondStep_GGO(arg);
-  SetRadius2_GGO(arg);
-  SetMaximumNumberOfLabels2_GGO(arg);
-  SetNumberOfNewLabels2_GGO(arg);
-  
-  SetFirstKeep_GGO(arg);
-  SetLastKeep_GGO(arg);
-
-  SetFinalOpenClose_GGO(arg);
-  SetAutoCrop_GGO(arg);
-}
-//--------------------------------------------------------------------
-
-
-//--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
-void 
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractPatientFilter<TInputImageType>::
 GenerateOutputInformation() { 
 
+  clitk::PrintMemory(GetVerboseMemoryFlag(), "Initial memory"); // OK
+
   Superclass::GenerateOutputInformation();
   input = dynamic_cast<const TInputImageType*>(itk::ProcessObject::GetInput(0));
 
-  // OutputImagePointer outputImage = this->GetOutput(0);
+  // MaskImagePointer outputImage = this->GetOutput(0);
 //   outputImage->SetRegions(input->GetLargestPossibleRegion());
 
   // Get input pointers
@@ -209,6 +180,10 @@ GenerateOutputInformation() {
   relabelFilter2->SetInput(connectFilter2->GetOutput());
   relabelFilter2->Update();
   working_image = relabelFilter2->GetOutput();
+  
+  // Keep main label
+  working_image = KeepLabels<InternalImageType>
+    (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true);  
   StopCurrentStep<InternalImageType>(working_image);
 
   //--------------------------------------------------------------------
@@ -263,7 +238,7 @@ GenerateOutputInformation() {
   //--------------------------------------------------------------------
   //--------------------------------------------------------------------
   // Final Cast 
-  typedef itk::CastImageFilter<InternalImageType, OutputImageType> CastImageFilterType;
+  typedef itk::CastImageFilter<InternalImageType, MaskImageType> CastImageFilterType;
   typename CastImageFilterType::Pointer caster= CastImageFilterType::New();
   caster->SetInput(working_image);
   caster->Update();
@@ -274,25 +249,28 @@ GenerateOutputInformation() {
   // [Optional]
   if (GetAutoCrop()) {
   StartNewStep("AutoCrop");
-    typedef clitk::AutoCropFilter<OutputImageType> CropFilterType;
+    typedef clitk::AutoCropFilter<MaskImageType> CropFilterType;
     typename CropFilterType::Pointer cropFilter = CropFilterType::New();
     cropFilter->SetInput(output);
     cropFilter->SetBackgroundValue(GetBackgroundValue());
     cropFilter->Update();   
     output = cropFilter->GetOutput();
-    StopCurrentStep<OutputImageType>(output);
+    StopCurrentStep<MaskImageType>(output);
   }
 }
 //--------------------------------------------------------------------
 
 
 //--------------------------------------------------------------------
-template <class TInputImageType, class TOutputImageType>
+template <class TInputImageType>
 void 
-clitk::ExtractPatientFilter<TInputImageType, TOutputImageType>::
+clitk::ExtractPatientFilter<TInputImageType>::
 GenerateData() {
-  //this->SetNthOutput(0, output); // -> no because redo filter otherwise
+  // Final Graft
   this->GraftOutput(output);
+  // Store image filename into AFDB
+  GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename());  
+  WriteAFDB();
 }
 //--------------------------------------------------------------------