1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
5 - University of LYON http://www.universite-lyon.fr/
6 - Léon Bérard cancer center http://www.centreleonberard.fr
7 - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr
9 This software is distributed WITHOUT ANY WARRANTY; without even
10 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11 PURPOSE. See the copyright notices for more information.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ===========================================================================*/
18 #include <itkImageToVTKImageFilter.h>
19 #include <itkPixelTraits.h>
21 //--------------------------------------------------------------------
22 template<class TItkImageType>
23 void vvImage::AddItkImage(TItkImageType *input)
25 // Update input before conversion to enable exceptions thrown by the ITK pipeline.
26 // Otherwise, vtkImageImport catches the exception for us.
29 // Convert from ITK object to VTK object
30 mImageDimension = TItkImageType::ImageDimension;
31 typedef itk::ImageToVTKImageFilter <TItkImageType> ConverterType;
32 typename ConverterType::Pointer converter = ConverterType::New();
33 mItkToVtkConverters.push_back(dynamic_cast< itk::ProcessObject *>(converter.GetPointer()));
34 converter->SetInput(input);
36 mVtkImages.push_back( converter->GetOutput() );
38 // Account for direction in transform. The offset is already accounted for
39 // in the VTK image coordinates, no need to put it in the transform.
40 vtkSmartPointer<vtkMatrix4x4> matrix = vtkSmartPointer<vtkMatrix4x4>::New();
42 for(unsigned int i=0; i<input->GetImageDimension(); i++) {
43 for(unsigned int j=0; j<input->GetImageDimension(); j++) {
44 (*matrix)[i][j] = input->GetDirection()[i][j];
45 // Direction is used around the image origin in ITK
46 (*matrix)[i][3] -= (*matrix)[i][j] * input->GetOrigin()[j];
48 (*matrix)[i][3] += input->GetOrigin()[i];
51 // GetDirection provides the forward transform, vtkImageReslice wants the inverse
54 mTransform.push_back(vtkSmartPointer<vtkTransform>::New());
55 mTransform.back()->SetMatrix(matrix);
57 mDictionary.push_back(&(input->GetMetaDataDictionary()));
59 //--------------------------------------------------------------------
61 /** Dispatch the computation of scalar range between vector and scalar image */
62 template<class TPixelType, unsigned int VImageDimension>
63 void vvImage::ComputeScalarRangeBase(itk::Image<TPixelType,VImageDimension> *input)
65 itkStaticConstMacro(Dimension1, unsigned int, itk::PixelTraits< TPixelType >::Dimension);
66 ComputeScalarRange(DimensionDispatch< Dimension1 >(), input);
69 //--------------------------------------------------------------------
70 /** Compute the scalar range for a vector pixel type */
72 template<class TPixelType, unsigned int VImageDimension>
73 void vvImage::ComputeScalarRange(DimensionDispatchBase, itk::Image<TPixelType,VImageDimension> *input)
75 cout << "try" << endl;
78 //--------------------------------------------------------------------
79 /** Compute the scalar range for a scalar pixel type */
80 template<class TPixelType, unsigned int VImageDimension>
81 void vvImage::ComputeScalarRange(DimensionDispatch< 1 >, itk::Image<TPixelType,VImageDimension> *input)
83 typedef typename itk::Image<TPixelType,VImageDimension> TItkImageType;
84 typedef itk::MinimumMaximumImageCalculator <TItkImageType> ImageCalculatorFilterType;
86 typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New ();
87 TPixelType tempMin, tempMax;
89 imageCalculatorFilter->SetImage(input);
90 imageCalculatorFilter->Compute();
91 tempMin= imageCalculatorFilter->GetMinimum();
92 tempMax= imageCalculatorFilter->GetMaximum();
94 tempRange[0] = (double) tempMin;
95 tempRange[1] = (double) tempMax;
97 if (tempRange[0] < mrange[0]) mrange[0]=tempRange[0];
98 if (tempRange[1] > mrange[1]) mrange[1]=tempRange[1];
100 //--------------------------------------------------------------------