X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FvvImage.txx;h=14da10a227f7d825cde021a143b8c2f84a74d7bb;hb=d2d75b63a31a4bfbbed0c22333e34dba688e6503;hp=1561a13d447a52256d0f02c02b323a63a4aeffe3;hpb=25e6b21607eea7d39428c109e4bc0ebe00f54ed9;p=clitk.git diff --git a/common/vvImage.txx b/common/vvImage.txx old mode 100755 new mode 100644 index 1561a13..14da10a --- a/common/vvImage.txx +++ b/common/vvImage.txx @@ -1,32 +1,56 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.fr/ + - Léon Bérard cancer center http://www.centreleonberard.fr + - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================*/ #include //-------------------------------------------------------------------- template void vvImage::AddItkImage(TItkImageType *input) { - mImageDimension = TItkImageType::ImageDimension; + // Update input before conversion to enable exceptions thrown by the ITK pipeline. + // Otherwise, vtkImageImport catches the exception for us. + input->Update(); + + // Convert from ITK object to VTK object + mImageDimension = TItkImageType::ImageDimension; typedef itk::ImageToVTKImageFilter ConverterType; typename ConverterType::Pointer converter = ConverterType::New(); + mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer())); converter->SetInput(input); + converter->Update(); + mVtkImages.push_back( converter->GetOutput() ); - try { - converter->Update(); - } - catch ( itk::ExceptionObject & err ) { - std::cerr << "Error while setting vvImage from ITK" - << " " << err << std::endl; + // Account for direction in transform. The offset is already accounted for + // in the VTK image coordinates, no need to put it in the transform. + vtkSmartPointer matrix = vtkSmartPointer::New(); + matrix->Identity(); + for(unsigned int i=0; iGetImageDimension(); i++) { + for(unsigned int j=0; jGetImageDimension(); j++) { + (*matrix)[i][j] = input->GetDirection()[i][j]; + // Direction is used around the image origin in ITK + (*matrix)[i][3] -= (*matrix)[i][j] * input->GetOrigin()[j]; + } + (*matrix)[i][3] += input->GetOrigin()[i]; } - mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer())); - mVtkImages.push_back(converter->GetOutput()); - - //mVtkImageReslice.push_back(vtkSmartPointer::New()); - //mVtkImageReslice.back()->SetInterpolationModeToLinear(); - //mVtkImageReslice.back()->AutoCropOutputOn(); - //mVtkImageReslice.back()->SetBackgroundColor(-1000,-1000,-1000,1); - //mVtkImageReslice.back()->SetResliceTransform(mTransform); - //mVtkImageReslice.back()->SetInput(0, image); - //mVtkImageReslice.back()->Update(); - //mVtkImages.push_back( mVtkImageReslice.back()->GetOutput(0) ); + + // GetDirection provides the forward transform, vtkImageReslice wants the inverse + matrix->Invert(); + + mTransform->SetMatrix(matrix); } //--------------------------------------------------------------------