]> Creatis software - clitk.git/commitdiff
upport
authorschaerer <schaerer>
Wed, 13 Jan 2010 14:28:24 +0000 (14:28 +0000)
committerschaerer <schaerer>
Wed, 13 Jan 2010 14:28:24 +0000 (14:28 +0000)
common/clitkCommon.h
common/clitkCommon.txx

index 1c5f9a09bf4d6241046e19481b2b267ae644b1df..5831d7b8ec08b514dd59e5ae2a8e8e09b3afa294 100644 (file)
@@ -24,6 +24,8 @@
 
 #include "itkMacro.h"
 #include <itkContinuousIndex.h>
+#include <itkImageRegionConstIterator.h>
+#include <itkImageRegionIterator.h>
 
 //--------------------------------------------------------------------
 namespace clitk {
@@ -41,6 +43,11 @@ namespace clitk {
 #define DD(a) std::cout << #a " = [ " << a << " ]" << std::endl;
 #define DDV(a,n) { std::cout << #a " = [ "; for(unsigned int _i_=0; _i_<n; _i_++) { std::cout << a[_i_] << " "; }; std::cout << " ]" << std::endl;}
 
+  //--------------------------------------------------------------------
+  // when everything goes wrong
+#define WHEREAMI "[ " << __FILE__  << " ] line " << __LINE__
+#define FATAL(a) std::cerr << "ERROR in " << WHEREAMI << ": " << a; exit(0);
+  
   //--------------------------------------------------------------------
   // GGO with modified struct name
 #define GGO(ggo_filename, args_info)                                             \
@@ -194,7 +201,11 @@ namespace clitk {
   //--------------------------------------------------------------------
   void disableStdCerr();
   void enableStdCerr();
-  
+
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output);
+
 #include "clitkCommon.txx"
 
 } // end namespace
index 984ef76adab1ed8bd3a37ace2e753f36adf00e87..4d16648fbc020aa025c70b5c46de41c16b330ab3 100644 (file)
@@ -128,5 +128,25 @@ std::string GetTypeAsString() {
 }
 //--------------------------------------------------------------------
 
+//--------------------------------------------------------------------
+template<class ImageType>
+void CloneImage(const typename ImageType::Pointer & input, typename ImageType::Pointer & output) {
+  output->SetRegions(input->GetLargestPossibleRegion());
+  output->SetSpacing(input->GetSpacing());
+  output->Allocate();
+  typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType; 
+  ConstIteratorType pi(input,input->GetLargestPossibleRegion());
+  pi.GoToBegin();  
+  typedef itk::ImageRegionIterator<ImageType> IteratorType; 
+  IteratorType po(output,input->GetLargestPossibleRegion());
+  po.GoToBegin(); 
+  while (!pi.IsAtEnd()) {
+    po.Set(pi.Get());
+    ++pi;
+    ++po;
+  }
+}
+//--------------------------------------------------------------------
+
 #endif /* end #define CLITKCOMMON_TXX */