]> Creatis software - clitk.git/blobdiff - common/vvImageReader.txx
basic GUI state loading/saving functionality
[clitk.git] / common / vvImageReader.txx
index 7607ab3a43cf27fc6b90c06ac926775b3f116e72..2d7d5b573f3c9a2985bfef023c21f4a542c53537 100644 (file)
@@ -34,7 +34,7 @@
 template<unsigned int VImageDimension>
 void vvImageReader::UpdateWithDim(std::string InputPixelType)
 {
-  if (mType == VECTORFIELD)
+  if (mType == VECTORFIELD || mType == VECTORFIELDWITHTIME)
     UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
   else if (InputPixelType == "short")
     UpdateWithDimAndInputPixelType<short,VImageDimension>();
@@ -67,7 +67,7 @@ void vvImageReader::UpdateWithDim(std::string InputPixelType)
 template<class InputPixelType, unsigned int VImageDimension>
 void vvImageReader::UpdateWithDimAndInputPixelType()
 {
-  itk::AnalyzeImageIO *analyzeImageIO;
+  itk::AnalyzeImageIO *analyzeImageIO = NULL;
 
   if (mType == MERGEDWITHTIME)   // In this case we can load the images
     // one at the time to avoid excessive
@@ -118,6 +118,9 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
     filter->SetExtractionRegion(extractedRegion);
     filter->SetInput(reader->GetOutput());
     filter->ReleaseDataFlagOn();
+#if ITK_VERSION_MAJOR == 4
+    filter->SetDirectionCollapseToSubmatrix();
+#endif
     try {
       mImage->AddItkImage<SlicedImageType>(filter->GetOutput());
     } catch ( itk::ExceptionObject & err ) {
@@ -136,7 +139,12 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
 
       try {
         if (mType == IMAGEWITHTIME)
-          mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
+        {
+          std::cerr << "We should never come here:" << std::endl
+            << "  Calling vvImageReader with multiple images and IMAGEWITHTIME is undefined." << std::endl
+            << "  You are probably looking for MERGEDWITHTIME Type." << std::endl;
+          return;
+        }
         else
           mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
       } catch ( itk::ExceptionObject & err ) {
@@ -154,7 +162,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
       reader->ReleaseDataFlagOn();
 
       try {
-        if (mType == IMAGEWITHTIME)
+        if (mType == IMAGEWITHTIME || mType == VECTORFIELDWITHTIME)
           mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
         else
           mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
@@ -172,11 +180,14 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
 
   // For unknown analyze orientations, we set identity
   if(analyzeImageIO) {
-    const double m[16] = {1.,0.,0.,0.,0.,0.,1.,0.,0.,-1.,0.,0.,0.,0.,0.,1.};
+    const double m[16] = {1.,0.,0.,0.,
+                          0.,0.,1.,0.,
+                          0.,-1.,0.,0.,
+                          0.,0.,0.,1.};
     int i;
-    for(i=0; m[i]==mImage->GetTransform()->GetMatrix()->GetElement(i%4, i/4) && i<16; i++);
+    for(i=0; i<16 && m[i]==mImage->GetTransform()->GetMatrix()->GetElement(i%4, i/4); i++);
     if(i==16) {
-      itkWarningMacro(<< "Analyze image file format detected with unknown orientation."
+      itkWarningMacro(<< "Analyze image file format detected with unknown orientation. "
                       << "Forcing identity orientation, use other file format if not ok.");
       mImage->GetTransform()->Identity();
     }