]> Creatis software - clitk.git/blobdiff - itk/clitkSegmentationUtils.txx
corrections...
[clitk.git] / itk / clitkSegmentationUtils.txx
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