]> Creatis software - clitk.git/commitdiff
still on bug 375
authorRomulo Pinho <pinho@lyon.fnclcc.fr>
Thu, 9 Jun 2011 09:52:31 +0000 (11:52 +0200)
committerRomulo Pinho <pinho@lyon.fnclcc.fr>
Thu, 9 Jun 2011 09:52:31 +0000 (11:52 +0200)
- image origin is now also updated to cope with crop

tools/clitkCropImageGenericFilter.cxx

index 5c78d4ea436355e1d8e459ba8a69e9eac3f5d36d..aeae1f988806c100c6198f407f59baefc5134222 100644 (file)
@@ -165,14 +165,21 @@ namespace clitk
       output->SetOrigin(origin);
     }
     
-    // force index to zero
-    typename ImageType::RegionType region;
-    region = output->GetLargestPossibleRegion();
-    typename ImageType::IndexType index;
+    // adjust image origin and force index to zero 
+    typename ImageType::RegionType region = output->GetLargestPossibleRegion();
+    typename ImageType::IndexType index = region.GetIndex();
+    typename ImageType::PointType origin = output->GetOrigin();
+    typename ImageType::SpacingType spacing = output->GetSpacing();
+    if (mArgsInfo.verbose_flag) std::cout << "origin before crop " << origin << std::endl;
+    for (unsigned int i = 0; i < output->GetImageDimension(); i++)
+      origin[i] += index[i]*spacing[i];
+    if (mArgsInfo.verbose_flag) std::cout << "origin after crop " << origin << std::endl;
+    output->SetOrigin(origin);
+
     index.Fill(itk::NumericTraits<double>::Zero);
     region.SetIndex(index);
     output->SetRegions(region);
-
+    
     // Write/Save results
     this->template SetNextOutput<ImageType>(output); 
   }