]> Creatis software - clitk.git/commitdiff
Set Directions to CropImage Like
authortbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 30 Sep 2019 14:54:54 +0000 (16:54 +0200)
committertbaudier <thomas.baudier@creatis.insa-lyon.fr>
Mon, 30 Sep 2019 14:54:54 +0000 (16:54 +0200)
itk/clitkCropLikeImageFilter.txx

index 6399ec6ac7e5419ca870e6e7cd61bf6b072810ef..e7e342fce498464947a9dd841aad4cb54da0cf29 100644 (file)
@@ -103,12 +103,17 @@ GenerateOutputInformation() {
   typename ImageType::IndexType likeStart;
   typename ImageType::PointType likeOrigin;  
   typename ImageType::SpacingType likeSpacing;  
+  typename ImageType::DirectionType likeDirection;
+  typename ImageType::DirectionType like_invDirection;
   if (m_LikeImage) {   
     likeSize = m_LikeImage->GetLargestPossibleRegion().GetSize();
     likeStart = m_LikeImage->GetLargestPossibleRegion().GetIndex();
     likeOrigin = m_LikeImage->GetOrigin();
     likeSpacing = m_LikeImage->GetSpacing();
-    output->CopyInformation(m_LikeImage);
+    likeDirection = m_LikeImage->GetDirection();
+    //I don't know really why I need the inverse...
+    like_invDirection = likeDirection.GetInverse();
+    //output->CopyInformation(m_LikeImage);
   }
   else {
     // Only load the header (allows to use 'like' with any image type)
@@ -119,8 +124,12 @@ GenerateOutputInformation() {
         likeStart[i] = 0;//header->GetIORegion().GetIndex()[i];
         likeOrigin[i] = header->GetOrigin(i);
         likeSpacing[i] = header->GetSpacing(i);
+        for(unsigned int j=0; j<ImageType::ImageDimension; j++)
+            likeDirection[i][j] = header->GetDirection(i)[j];
+       }
+      //I don't know really why I need the inverse...
+      like_invDirection = likeDirection.GetInverse();
       }
-    }
     else {
       clitkExceptionMacro("You should provide SetCropLikeFilename or SetCropLike to CropLikeImageFilter");
     }
@@ -152,6 +161,7 @@ GenerateOutputInformation() {
   output->SetBufferedRegion(m_OutputRegion);
   output->SetSpacing(likeSpacing);  
   output->SetOrigin(likeOrigin);
+  output->SetDirection(like_invDirection);
   output->Allocate(); // Needed ?
 
   // get startpoint source/dest