From: srit Date: Sun, 24 Oct 2010 18:49:45 +0000 (+0000) Subject: Removed exception handling at a low level, let them be handled at a higher, e.g.... X-Git-Tag: v1.2.0~310 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=97e94d6d86e558d1d377486bf2db1549c06f4fd1;p=clitk.git Removed exception handling at a low level, let them be handled at a higher, e.g. with qt errors. Only update itk pipeline for reading in vvImage to avoid reading unnecessary parts of the image. --- diff --git a/common/vvFromITK.h b/common/vvFromITK.h index c7178fe..d44cf72 100644 --- a/common/vvFromITK.h +++ b/common/vvFromITK.h @@ -32,7 +32,6 @@ template 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 vvImage::Pointer vvImageFromITK(type typedef itk::ExtractImageFilter FilterType; //extract the 3D slices and put them in a std::vector + 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 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(filter->GetOutput()); } vv_image->SetTimeSpacing(input->GetSpacing()[Dim-1]); diff --git a/common/vvImage.h b/common/vvImage.h index 2d4776d..f76d2a1 100644 --- a/common/vvImage.h +++ b/common/vvImage.h @@ -22,11 +22,12 @@ #include #include #include + +#include #include +#include class vtkImageData; -class vtkImageReslice; -class vtkTransform; //------------------------------------------------------------------------------ class vvImage : public itk::LightObject diff --git a/common/vvImage.txx b/common/vvImage.txx index 1561a13..e73cd27 100755 --- a/common/vvImage.txx +++ b/common/vvImage.txx @@ -8,14 +8,8 @@ void vvImage::AddItkImage(TItkImageType *input) typedef itk::ImageToVTKImageFilter 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()); diff --git a/vv/vvImageReader.txx b/vv/vvImageReader.txx index 31937bf..2ebec0e 100644 --- a/vv/vvImageReader.txx +++ b/vv/vvImageReader.txx @@ -83,7 +83,7 @@ void vvImageReader::UpdateWithDimAndInputPixelType() reader->ReleaseDataFlagOn(); reader->SetFileName(*i); try { - reader->Update(); + mImage->AddItkImage(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(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(filter->GetOutput()); } catch ( itk::ExceptionObject & err ) { std::cerr << "Error while slicing " << mInputFilenames[0].c_str() << "(slice #" << mSlice << ") " << err << std::endl; return; } - mImage->AddItkImage(filter->GetOutput()); } else { if (mInputFilenames.size() > 1) { typedef itk::Image< InputPixelType, VImageDimension > InputImageType; typedef itk::ImageSeriesReader ReaderType; typename ReaderType::Pointer reader = ReaderType::New(); - for (std::vector::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(reader->GetOutput(),true); + else + mImage=vvImageFromITK(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 GetOutput()->GetImageDimension(); i++) { - // DD(reader->GetOutput()->GetSpacing()[i]); - // } - - if (mType == IMAGEWITHTIME) - mImage=vvImageFromITK(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); } else { typedef itk::Image< InputPixelType, VImageDimension > InputImageType; typedef itk::ImageFileReader 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(reader->GetOutput(),true); + else + mImage=vvImageFromITK(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 GetOutput()->GetImageDimension(); i++) { - // DD(reader->GetOutput()->GetSpacing()[i]); - // DD(reader->GetOutput()->GetOrigin()[i]); - // } - - - if (mType == IMAGEWITHTIME) - mImage=vvImageFromITK(reader->GetOutput(),true); - else - mImage=vvImageFromITK(reader->GetOutput()); } } } diff --git a/vv/vvLabelImageLoaderWidget.cxx b/vv/vvLabelImageLoaderWidget.cxx index 99b8a2f..96636fa 100644 --- a/vv/vvLabelImageLoaderWidget.cxx +++ b/vv/vvLabelImageLoaderWidget.cxx @@ -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());