X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=common%2FvvImage.txx;h=cc047bb1caf9c69bb187b52ab94311a14c81751f;hb=d55f025b18f68066a52b8f33c2dc6481e82c2580;hp=c3491f8be4e3d9497528317d107bff9eefbb5858;hpb=d0821fb395eee271db5fe469bb77456e70e3e77f;p=clitk.git diff --git a/common/vvImage.txx b/common/vvImage.txx old mode 100755 new mode 100644 index c3491f8..cc047bb --- a/common/vvImage.txx +++ b/common/vvImage.txx @@ -1,4 +1,22 @@ +/*========================================================================= + 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 +#include //-------------------------------------------------------------------- template @@ -7,34 +25,86 @@ void vvImage::AddItkImage(TItkImageType *input) // 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; + 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() ); - - // Account for direction in transform. The offset is already accounted for + + // 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 j=0; jGetImageDimension(); j++) - for(unsigned int i=0; iGetImageDimension(); i++) + for(unsigned int i=0; iGetImageDimension(); i++) { + for(unsigned int j=0; jGetImageDimension(); j++) { +#if VTK_MAJOR_VERSION <= 6 (*matrix)[i][j] = input->GetDirection()[i][j]; - mTransform->SetMatrix(matrix); - - // Create the corresponding transformed image - 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, converter->GetOutput()); - mVtkImageReslice.back()->UpdateInformation(); - mTransformedVtkImages.push_back( mVtkImageReslice.back()->GetOutput(0) ); + // Direction is used around the image origin in ITK + (*matrix)[i][3] -= (*matrix)[i][j] * input->GetOrigin()[j]; +#else + (*matrix).SetElement(i, j, input->GetDirection()[i][j]); + // Direction is used around the image origin in ITK + (*matrix).SetElement(i, 3, (*matrix).GetElement(i,3) - (*matrix).GetElement(i,j) * input->GetOrigin()[j]); +#endif + } +#if VTK_MAJOR_VERSION <= 6 + (*matrix)[i][3] += input->GetOrigin()[i]; +#else + (*matrix).SetElement(i, 3, (*matrix).GetElement(i,3) + input->GetOrigin()[i]); +#endif + } + + // GetDirection provides the forward transform, vtkImageReslice wants the inverse + matrix->Invert(); + + mTransform.push_back(vtkSmartPointer::New()); + mTransform.back()->SetMatrix(matrix); + //META DATA + mDictionary.push_back(&(input->GetMetaDataDictionary())); +} +//-------------------------------------------------------------------- + +/** Dispatch the computation of scalar range between vector and scalar image */ +template +void vvImage::ComputeScalarRangeBase(itk::Image *input) +{ + itkStaticConstMacro(Dimension1, unsigned int, itk::PixelTraits< TPixelType >::Dimension); + ComputeScalarRange(DimensionDispatch< Dimension1 >(), input); +} + +//-------------------------------------------------------------------- +/** Compute the scalar range for a vector pixel type */ +/** TO DO*/ +template +void vvImage::ComputeScalarRange(DimensionDispatchBase, itk::Image *input) +{ +} + +//-------------------------------------------------------------------- +/** Compute the scalar range for a scalar pixel type */ +template +void vvImage::ComputeScalarRange(DimensionDispatch< 1 >, itk::Image *input) +{ + typedef typename itk::Image TItkImageType; + typedef itk::MinimumMaximumImageCalculator ImageCalculatorFilterType; + + typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New (); + TPixelType tempMin, tempMax; + double tempRange[2]; + imageCalculatorFilter->SetImage(input); + imageCalculatorFilter->Compute(); + tempMin= imageCalculatorFilter->GetMinimum(); + tempMax= imageCalculatorFilter->GetMaximum(); + + tempRange[0] = (double) tempMin; + tempRange[1] = (double) tempMax; + + if (tempRange[0] < mrange[0]) mrange[0]=tempRange[0]; + if (tempRange[1] > mrange[1]) mrange[1]=tempRange[1]; } //--------------------------------------------------------------------