]> Creatis software - clitk.git/commitdiff
Removed exception handling at a low level, let them be handled at a higher, e.g....
authorsrit <srit>
Sun, 24 Oct 2010 18:49:45 +0000 (18:49 +0000)
committersrit <srit>
Sun, 24 Oct 2010 18:49:45 +0000 (18:49 +0000)
common/vvFromITK.h
common/vvImage.h
common/vvImage.txx
vv/vvImageReader.txx
vv/vvLabelImageLoaderWidget.cxx

index c7178fe3e36c417cb85d37182c6edbea2840a1a0..d44cf728e84a91df68605f0028e3318bc76732a1 100644 (file)
@@ -32,7 +32,6 @@ template<unsigned int Dim, class PixelType> vvImage::Pointer vvImageFromITK(type
 {
     assert(Dim < 5 && Dim > 0); // We don't handle anything higher than 4-dimensional (for the moment :-p)
     vvImage::Pointer vv_image=vvImage::New();
-    vv_image->Init(); //Delete any existing images
     typedef itk::Image< PixelType, Dim > InputImageType;
 
     if (Dim == 4 || time_sequence) //The time sequence case: create a series of VTK images
@@ -41,6 +40,7 @@ template<unsigned int Dim, class PixelType> vvImage::Pointer vvImageFromITK(type
         typedef itk::ExtractImageFilter<InputImageType, ItkImageType> FilterType;
 
         //extract the 3D slices and put them in a std::vector<vtkImageData*>
+        input->UpdateOutputInformation();
         typename InputImageType::RegionType inputRegion = input->GetLargestPossibleRegion();
         typename InputImageType::SizeType inputSize = inputRegion.GetSize();
         typename InputImageType::IndexType start = inputRegion.GetIndex();
@@ -57,15 +57,6 @@ template<unsigned int Dim, class PixelType> vvImage::Pointer vvImageFromITK(type
             filter->SetExtractionRegion(extractedRegion);
             filter->SetInput(input);
             filter->ReleaseDataFlagOn();
-
-            try {
-                filter->Update();
-            }
-            catch ( itk::ExceptionObject & err ) {
-                std::cerr << "Error while setting vvImage from ITK (Dim==4) [Extract phase]"
-                          << " " << err << std::endl;
-                return vv_image;
-            }
             vv_image->AddItkImage<ItkImageType>(filter->GetOutput());
         }
         vv_image->SetTimeSpacing(input->GetSpacing()[Dim-1]);
index 2d4776d728cb9707a70ae2dc22c7a34ba27e810e..f76d2a1321d8c28849d3cd15d49b92b2382e8bd2 100644 (file)
 #include <vector>
 #include <itkObjectFactory.h>
 #include <itkProcessObject.h>
+
+#include <vtkImageReslice.h>
 #include <vtkSmartPointer.h>
+#include <vtkTransform.h>
 
 class vtkImageData;
-class vtkImageReslice;
-class vtkTransform;
 
 //------------------------------------------------------------------------------
 class vvImage : public itk::LightObject
index 1561a13d447a52256d0f02c02b323a63a4aeffe3..e73cd27fc4d22153365031d6654c897011b1296e 100755 (executable)
@@ -8,14 +8,8 @@ void vvImage::AddItkImage(TItkImageType *input)
   typedef itk::ImageToVTKImageFilter <TItkImageType> ConverterType;
   typename ConverterType::Pointer converter = ConverterType::New();
   converter->SetInput(input);
+  converter->Update();
 
-  try {
-      converter->Update();
-  }
-  catch ( itk::ExceptionObject & err ) {
-      std::cerr << "Error while setting vvImage from ITK"
-                << " " << err << std::endl;
-  }
   mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer()));
   mVtkImages.push_back(converter->GetOutput());
  
index 31937bfbc229fe83919f721cbeeb4dce6f772c1e..2ebec0e44579193b53521b18bcad0827aa2b5056 100644 (file)
@@ -83,7 +83,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
       reader->ReleaseDataFlagOn();
       reader->SetFileName(*i);
       try {
-        reader->Update();
+        mImage->AddItkImage<InputImageType>(reader->GetOutput());
       } catch ( itk::ExceptionObject & err ) {
         std::cerr << "Error while reading " << mInputFilenames[0].c_str()
                   << " " << err << std::endl;
@@ -92,7 +92,6 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
         mLastError = error.str();
         return;
       }
-      mImage->AddItkImage<InputImageType>(reader->GetOutput());
     }
   } else if (mType == SLICED) {
     mImage=vvImage::New();
@@ -120,27 +119,26 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
     filter->SetInput(reader->GetOutput());
     filter->ReleaseDataFlagOn();
     try {
-      filter->Update();
+      mImage->AddItkImage<SlicedImageType>(filter->GetOutput());
     }
     catch ( itk::ExceptionObject & err ) {
       std::cerr << "Error while slicing " << mInputFilenames[0].c_str()
                 << "(slice #" << mSlice << ") " << err << std::endl;
       return;
     }
-    mImage->AddItkImage<SlicedImageType>(filter->GetOutput());
   } 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);
-      //}
+      reader->ReleaseDataFlagOn();
+
       try {
-        reader->Update();
+        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;
@@ -148,27 +146,18 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
         mLastError = error.str();
         return;
       }
-
-      // DD(reader->GetOutput()->GetImageDimension());
-      //           DD(reader->GetOutput()->GetNumberOfComponentsPerPixel());
-      //           for(unsigned int i=0; i <reader->GetOutput()->GetImageDimension(); i++) {
-      //             DD(reader->GetOutput()->GetSpacing()[i]);
-      //           }
-
-      if (mType == IMAGEWITHTIME)
-        mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
-      else
-        mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
     } 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);
-      //}
+      reader->ReleaseDataFlagOn();
+
       try {
-        reader->Update();
+        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 " << mInputFilenames[0].c_str()
                   << " " << err << std::endl;
@@ -177,19 +166,6 @@ void vvImageReader::UpdateWithDimAndInputPixelType()
         mLastError = error.str();
         return;
       }
-
-      // DD(reader->GetOutput()->GetImageDimension());
-      //           DD(reader->GetOutput()->GetNumberOfComponentsPerPixel());
-      //           for(unsigned int i=0; i <reader->GetOutput()->GetImageDimension(); i++) {
-      //             DD(reader->GetOutput()->GetSpacing()[i]);
-      //             DD(reader->GetOutput()->GetOrigin()[i]);
-      //           }
-
-
-      if (mType == IMAGEWITHTIME)
-        mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput(),true);
-      else
-        mImage=vvImageFromITK<VImageDimension,InputPixelType>(reader->GetOutput());
     }
   }
 }
index 99b8a2ff835359b86a8516432f7b29cad6e1cdb2..96636fa35b03940c1cc71e4b2e907a7f7fc68105 100644 (file)
@@ -110,7 +110,16 @@ void vvLabelImageLoaderWidget::OpenImage()
 
   // Create vv image
   m_Output = vvImage::New();
-  m_Output->AddItkImage( reader->GetOutput() );
+  try {
+    m_Output->AddItkImage( reader->GetOutput() );
+  }
+  catch ( itk::ExceptionObject & err ) {
+    std::cerr << "Error while reading " << filename.toStdString() << std::endl;
+    QString error;
+    error = QString("Cannot open file %1\n").arg(filename);
+    QMessageBox::information(this,tr("Reading problem"),error);
+    return;
+  }
 
   // Set GUI
   mLabelInputInfo->setText(vtksys::SystemTools::GetFilenameName(filename.toStdString()).c_str());