]> Creatis software - clitk.git/commitdiff
Add RemoveNegativeIndexFromRegion function
authorDavid Sarrut <david.sarrut@gmail.com>
Thu, 7 Jun 2012 13:47:13 +0000 (15:47 +0200)
committerDavid Sarrut <david.sarrut@gmail.com>
Thu, 7 Jun 2012 13:47:13 +0000 (15:47 +0200)
itk/clitkSegmentationUtils.h
itk/clitkSegmentationUtils.txx

index 6972d154ab8f4436a672247090da66efff9eb331..6389ad135c4c3202701b3eaed5c50729d082d365 100644 (file)
@@ -28,6 +28,7 @@
 // itk
 #include <itkBoundingBox.h>
 #include <itkJoinSeriesImageFilter.h>
+#include <itkChangeInformationImageFilter.h>
 
 /*
   According to 
@@ -486,7 +487,12 @@ namespace clitk {
                       typename ImageType::PixelType & BG);
   //--------------------------------------------------------------------
   
-
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  RemoveNegativeIndexFromRegion(ImageType * input);
+  //--------------------------------------------------------------------
+  
 
 } // end clitk namespace
 
index 6171030d9109807f0c2d2a9cf80782087c7c8279..b7a5de50693c5f078b19ea2245076f3c384c4657 100644 (file)
@@ -1392,6 +1392,30 @@ namespace clitk {
   //--------------------------------------------------------------------
      
 
+  //--------------------------------------------------------------------
+  template<class ImageType>
+  typename ImageType::Pointer
+  RemoveNegativeIndexFromRegion(ImageType * input) {
+    typedef itk::ChangeInformationImageFilter< ImageType > InfoFilterType; 
+    typename InfoFilterType::Pointer indexChangeFilter = InfoFilterType::New(); 
+    indexChangeFilter->ChangeRegionOn(); 
+    // The next line is commented because not exist in itk 3
+    // typename InfoFilterType::OutputImageOffsetValueType indexShift[3];
+    long indexShift[3];
+    typename ImageType::IndexType index = input->GetLargestPossibleRegion().GetIndex();
+    for(uint i=0;i<ImageType::ImageDimension; i++)
+      indexShift[i] = (index[i]<0 ? -index[i]:0);
+    typename ImageType::PointType origin;
+    for(uint i=0;i<ImageType::ImageDimension; i++)
+    origin[i] = input->GetOrigin()[i] - indexShift[i]*input->GetSpacing()[i];
+    indexChangeFilter->SetOutputOffset( indexShift ); 
+    indexChangeFilter->SetInput(input); 
+    indexChangeFilter->SetOutputOrigin(origin);
+    indexChangeFilter->ChangeOriginOn();
+    indexChangeFilter->Update();
+    return indexChangeFilter->GetOutput();
+  }
+  //--------------------------------------------------------------------
 
 
 } // end of namespace