]> Creatis software - clitk.git/blobdiff - vv/vvImageReader.txx
Removed unused vvs.cxx
[clitk.git] / vv / vvImageReader.txx
index a22c5b73f46ee9495f77c941c5d07b1ce1834d2c..3c5e1545878b27511d100c559db30a1c2f473dbf 100644 (file)
@@ -1,7 +1,7 @@
 /*=========================================================================
   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
 
-  Authors belong to: 
+  Authors belong to:
   - University of LYON              http://www.universite-lyon.fr/
   - Léon Bérard cancer center       http://oncora1.lyon.fnclcc.fr
   - CREATIS CNRS laboratory         http://www.creatis.insa-lyon.fr
 
   - BSD        See included LICENSE.txt file
   - CeCILL-B   http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
-======================================================================-====*/
-#ifndef vvImageReader_TXX
-#define vvImageReader_TXX
-#include<string>
+  ======================================================================-====*/
 
+#ifndef VVIMAGEREADER_TXX
+#define VVIMAGEREADER_TXX
+
+#include <string>
 #include <itkImageFileReader.h>
 #include <itkImageSeriesReader.h>
+#include <itkImageToVTKImageFilter.h>
+
+#include <vtkTransform.h>
 
 #include "clitkCommon.h"
-#include "itkImageToVTKImageFilter.h"
+#include "clitkConfiguration.h"
 #include "vvFromITK.h"
 #include "vvConstants.h"
 
+//----------------------------------------------------------------------------
 template<unsigned int VImageDimension>
 void vvImageReader::UpdateWithDim(std::string InputPixelType)
 {
-    if (mType == VECTORFIELD)
-        UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
-    else if (InputPixelType == "short")
-        UpdateWithDimAndInputPixelType<short,VImageDimension>();
-    else if (InputPixelType == "unsigned_short")
-        UpdateWithDimAndInputPixelType<unsigned short,VImageDimension>();
-    else if (InputPixelType == "char")
-        UpdateWithDimAndInputPixelType<char,VImageDimension>();
-    else if (InputPixelType == "unsigned_char")
-        UpdateWithDimAndInputPixelType<unsigned char,VImageDimension>();
-    else if (InputPixelType == "int")
-        UpdateWithDimAndInputPixelType<int,VImageDimension>();
-    else if (InputPixelType == "double")
-        UpdateWithDimAndInputPixelType<double,VImageDimension>();
-    else if (InputPixelType == "float")
-        UpdateWithDimAndInputPixelType<float,VImageDimension>();
-    else
-        std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
+  if (mType == VECTORFIELD)
+    UpdateWithDimAndInputPixelType<itk::Vector<float,3>,VImageDimension>();
+  else if (InputPixelType == "short")
+    UpdateWithDimAndInputPixelType<short,VImageDimension>();
+  else if (InputPixelType == "unsigned_short")
+    UpdateWithDimAndInputPixelType<unsigned short,VImageDimension>();
+  else if (InputPixelType == "char")
+    UpdateWithDimAndInputPixelType<char,VImageDimension>();
+  else if (InputPixelType == "unsigned_char")
+    UpdateWithDimAndInputPixelType<unsigned char,VImageDimension>();
+  else if (InputPixelType == "int")
+    UpdateWithDimAndInputPixelType<int,VImageDimension>();
+  else if (InputPixelType == "unsigned_int")
+    UpdateWithDimAndInputPixelType<unsigned int,VImageDimension>();
+  else if (InputPixelType == "double")
+    UpdateWithDimAndInputPixelType<double,VImageDimension>();
+  else if (InputPixelType == "float")
+    UpdateWithDimAndInputPixelType<float,VImageDimension>();
+  else
+    std::cerr << "Error, input pixel type : " << InputPixelType << " unknown !" << std::endl;
+
+  if (CLITK_EXPERIMENTAL && mLastError.size()==0) {
+    //ReadNkiImageTransform();
+    ReadMatImageTransform();
+  }
 }
-//====================================================================
+//----------------------------------------------------------------------------
+
 
+//----------------------------------------------------------------------------
 template<class InputPixelType, unsigned int VImageDimension>
 void vvImageReader::UpdateWithDimAndInputPixelType()
 {
-    if (mType == MERGEDWITHTIME)   // In this case we can load the images
-                                   // one at the time to avoid excessive
-                                   // memory use
-    {
-        typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType;
-        typedef itk::ImageFileReader<InputImageType> ReaderType;
-        typename ReaderType::Pointer reader = ReaderType::New();
-        typedef itk::ImageToVTKImageFilter <InputImageType> ConnectorType;
-        typename ConnectorType::Pointer connector = ConnectorType::New();
-        connector->SetInput(reader->GetOutput());
-        mImage=vvImage::New();
-        for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
-        {
-            std::cout << (*i) << std::endl;
-            reader->SetFileName(*i);
-            try {
-                reader->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while reading " << mInputFilenames[0].c_str()
-                    << " " << err << std::endl;
-                std::stringstream error;
-                error << err;
-                mLastError = error.str();
-                return;
-            }
-            try {
-                connector->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while setting vvImage from ITK (MERGEDWITHTIME)"
-                    << " " << err << std::endl;
-            }
-            vtkImageData *image = vtkImageData::New();
-            image->DeepCopy(connector->GetOutput());
-            mImage->AddImage(image);
-        }
+  if (mType == MERGEDWITHTIME)   // In this case we can load the images
+    // one at the time to avoid excessive
+    // memory use
+  {
+    mImage=vvImage::New();
+
+    for (std::vector<std::string>::const_iterator i=mInputFilenames.begin(); i!=mInputFilenames.end(); i++) {
+      typedef itk::Image< InputPixelType, VImageDimension-1 > InputImageType;
+      typedef itk::ImageFileReader<InputImageType> ReaderType;
+      typename ReaderType::Pointer reader = ReaderType::New();
+      reader->ReleaseDataFlagOn();
+      reader->SetFileName(*i);
+      try {
+        mImage->AddItkImage<InputImageType>(reader->GetOutput());
+      } catch ( itk::ExceptionObject & err ) {
+        std::cerr << "Error while reading " << mInputFilenames[0].c_str()
+                  << " " << err << std::endl;
+        std::stringstream error;
+        error << err;
+        mLastError = error.str();
+        return;
+      }
     }
-    else
-    {
-        if (mInputFilenames.size() > 1)
-        {
-            typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
-            typedef itk::ImageSeriesReader<InputImageType> ReaderType;
-            typename ReaderType::Pointer reader = ReaderType::New();
-            for (std::vector<std::string>::const_iterator i=mInputFilenames.begin();i!=mInputFilenames.end();i++)
-                std::cout << (*i) << std::endl;
-            reader->SetFileNames(mInputFilenames);
-            //if (mUseAnObserver) {
-                //reader->AddObserver(itk::ProgressEvent(), mObserver);
-            //}
-            try {
-                reader->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while reading image series:" << err << std::endl;
-                std::stringstream error;
-                error << err;
-                mLastError = error.str();
-                return;
-            }
-            if (mType == IMAGEWITHTIME)
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
-            else
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
-        }
+  } else if (mType == SLICED) {
+    mImage=vvImage::New();
+    typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
+    typedef itk::ImageFileReader<InputImageType> ReaderType;
+    typename ReaderType::Pointer reader = ReaderType::New();
+    reader->SetFileName(mInputFilenames[0]);
+    reader->UpdateOutputInformation();
+
+    typedef itk::Image< InputPixelType, VImageDimension-1 > SlicedImageType;
+    typedef itk::ExtractImageFilter<InputImageType, SlicedImageType> FilterType;
+
+    typename InputImageType::RegionType inputRegion = reader->GetOutput()->GetLargestPossibleRegion();
+    typename InputImageType::SizeType inputSize = inputRegion.GetSize();
+    typename InputImageType::IndexType start = inputRegion.GetIndex();
+    typename InputImageType::SizeType extractedRegionSize = inputSize;
+    typename InputImageType::RegionType extractedRegion;
+    extractedRegionSize[VImageDimension - 1] = 0;
+    extractedRegion.SetSize(extractedRegionSize);
+    start[VImageDimension - 1] = mSlice;
+    extractedRegion.SetIndex(start);
+
+    typename FilterType::Pointer filter = FilterType::New();
+    filter->SetExtractionRegion(extractedRegion);
+    filter->SetInput(reader->GetOutput());
+    filter->ReleaseDataFlagOn();
+    try {
+      mImage->AddItkImage<SlicedImageType>(filter->GetOutput());
+    }
+    catch ( itk::ExceptionObject & err ) {
+      std::cerr << "Error while slicing " << mInputFilenames[0].c_str()
+                << "(slice #" << mSlice << ") " << err << std::endl;
+      return;
+    }
+  } else {
+    if (mInputFilenames.size() > 1) {
+      typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
+      typedef itk::ImageSeriesReader<InputImageType> ReaderType;
+      typename ReaderType::Pointer reader = ReaderType::New();
+      reader->SetFileNames(mInputFilenames);
+      reader->ReleaseDataFlagOn();
+
+      try {
+        if (mType == IMAGEWITHTIME)
+          mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
+        else
+          mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
+      } catch ( itk::ExceptionObject & err ) {
+        std::cerr << "Error while reading image series:" << err << std::endl;
+        std::stringstream error;
+        error << err;
+        mLastError = error.str();
+        return;
+      }
+    } else {
+      typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
+      typedef itk::ImageFileReader<InputImageType> ReaderType;
+      typename ReaderType::Pointer reader = ReaderType::New();
+      reader->SetFileName(mInputFilenames[0]);
+      reader->ReleaseDataFlagOn();
+
+      try {
+        if (mType == IMAGEWITHTIME)
+          mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
         else
-        {
-            typedef itk::Image< InputPixelType, VImageDimension > InputImageType;
-            typedef itk::ImageFileReader<InputImageType> ReaderType;
-            typename ReaderType::Pointer reader = ReaderType::New();
-            reader->SetFileName(mInputFilenames[0]);
-            //if (mUseAnObserver) {
-                //reader->AddObserver(itk::ProgressEvent(), mObserver);
-            //}
-            try {
-                reader->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while reading " << mInputFilenames[0].c_str()
-                    << " " << err << std::endl;
-                std::stringstream error;
-                error << err;
-                mLastError = error.str();
-                return;
-            }
-            if (mType == IMAGEWITHTIME)
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
-            else
-                mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
-        }
+          mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
+      } catch ( itk::ExceptionObject & err ) {
+        std::cerr << "Error while reading " << mInputFilenames[0].c_str()
+                  << " " << err << std::endl;
+        std::stringstream error;
+        error << err;
+        mLastError = error.str();
+        return;
+      }
     }
+  }
 }
-//====================================================================
+//----------------------------------------------------------------------------
 
 
 #endif /* end #define vvImageReader_TXX */