]> Creatis software - bbtk.git/blobdiff - packages/itk/src/bbitkExtractImageFilter.h
*** empty log message ***
[bbtk.git] / packages / itk / src / bbitkExtractImageFilter.h
index 8906085d7dd744ee2ec207c5748f0d315db2e36a..e7c0cdd237f2e1278628d71cf8ae4fd27e349ad9 100644 (file)
@@ -2,8 +2,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbitkExtractImageFilter.h,v $
   Language:  C++
-  Date:      $Date: 2008/11/12 12:47:03 $
-  Version:   $Revision: 1.9 $
+  Date:      $Date: 2009/05/18 10:45:43 $
+  Version:   $Revision: 1.10 $
 =========================================================================*/
 
 /* ---------------------------------------------------------------------
@@ -40,7 +40,8 @@
 namespace bbitk
 {
 
-  
+  //===================================================
+  /// Template filter
   template <class T>
   class /*BBTK_EXPORT*/ ExtractImageFilter
     : 
@@ -59,8 +60,11 @@ namespace bbitk
     BBTK_ITK_PROCESS();
     BBTK_ITK_DELETE();
   };
+  //===================================================
 
 
+  //===================================================
+  // Descriptor of template filter 
   BBTK_BEGIN_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter,
                                      bbtk::AtomicBlackBox);
   BBTK_NAME("ExtractImageFilter<"+bbtk::TypeName<T>()+">");
@@ -70,7 +74,22 @@ namespace bbitk
   BBTK_TEMPLATE_INPUT(ExtractImageFilter,ExtractionRegion,"Extraction region",typename T::RegionType);
   BBTK_TEMPLATE_OUTPUT(ExtractImageFilter,Out,"Output image",T*);
   BBTK_END_DESCRIBE_TEMPLATE_BLACK_BOX(ExtractImageFilter);
+  //===================================================
+
+  //===================================================
+  template <class T> void ExtractImageFilter<T>::bbUserSetDefaultValues() {}
+  template <class T> void ExtractImageFilter<T>::bbUserInitializeProcessing(){}
+  template <class T> void ExtractImageFilter<T>::bbUserFinalizeProcessing() {}
+  //===================================================
   
+
+
+
+
+
+
+
+
   //===================================================
   // Generic "untemplatized" filter
   //===================================================
@@ -84,10 +103,13 @@ namespace bbitk
     BBTK_DECLARE_OUTPUT(Out,anyImagePointer);
     BBTK_PROCESS(ProcessSwitch);
   private :
-    inline void ProcessSwitch();
+    void ProcessSwitch();
     template <class T> void Process();
   };
+  //===================================================
   
+  //===================================================
+  // Descriptor of generic filter
   BBTK_BEGIN_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric,
                                bbtk::AtomicBlackBox);
   BBTK_NAME("ExtractImageFilter");
@@ -98,30 +120,55 @@ namespace bbitk
   BBTK_INPUT(ExtractImageFilterGeneric,Region,"Extraction region",anyImageRegion,"");
   BBTK_OUTPUT(ExtractImageFilterGeneric,Out,"Output image",anyImagePointer,"");
   BBTK_END_DESCRIBE_BLACK_BOX(ExtractImageFilterGeneric);
-  void ExtractImageFilterGeneric::ProcessSwitch()
-  {
-     BBTK_TEMPLATE_ITK_IMAGE_SWITCH(bbGetInputIn().type(), this->Process);
-  }
+  //===================================================
+
 
+  //===================================================
+  // The main processing method is template on the itk image type 
+  // which was set to the input. 
+  // It is called by the ProcessSwitch method which checks the input In type
+  // and calls Process<T> where T is the right type.
   template <class T>
   void ExtractImageFilterGeneric::Process()
   {
     bbtkDebugMessageInc("Core",9,
                        "bbitk::ExtractImageFilterGeneric::Process<"
                        <<bbtk::TypeName<T>()<<">()"<<std::endl);
+    // T is the type of input image
     typedef T ImageType;
+    // We define the type of the filter to use which is template 
+    // on the image type
     typedef ExtractImageFilter<ImageType> FilterType;
+    // Allocate the filter
     typename FilterType::Pointer f = FilterType::New("Temp");
-         typedef ImageType* ImageTypePointer; 
-    f->bbSetInputIn( this->bbGetInputIn().unsafe_get<ImageTypePointer>() );
+
+    // Set the input In of the filter
+    // Here we :
+    // 1) Get **OUR** input 'In' by bbGetInputIn()
+    //    It is a anyImagePointer
+    // 2) We **KNOW** that the actual type stored by the anyImagePointer
+    //    is ImageType* hence we get the value stored using the 
+    //    unsafe_get method (which is a template method on the return type)
+    f->bbSetInputIn( this->bbGetInputIn().unsafe_get<ImageType*>() );
+    
+    // The same for the ImageRegion except that we use 'get' and not 
+    // 'unsafe get' because the region dimension passed by the user may not be 
+    // compatible with the image dimension.
+    // If get fails it throws an exception which must be caught outside 
     f->bbSetInputExtractionRegion ( this->bbGetInputRegion().get<typename T::RegionType>() );
+
+    // Execute the filter
     f->bbExecute();
+    // Register its output or it will be deleted we delete the filter
     f->bbGetOutputOut()->Register();
+    // Set OUR output
     this->bbSetOutputOut( f->bbGetOutputOut() );
-    //  f->bbDelete();
+    // Delete the temporary filter
+    f->bbDelete();
 
     bbtkDebugDecTab("Core",9);
   }
+  //===================================================
 
 }
 // EO namespace bbitk