]> Creatis software - clitk.git/blob - common/vvImage.txx
Debug vf display
[clitk.git] / common / vvImage.txx
1 /*=========================================================================
2   Program:   vv                     http://www.creatis.insa-lyon.fr/rio/vv
3
4   Authors belong to:
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
8
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.
12
13   It is distributed under dual licence
14
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>
20
21 //--------------------------------------------------------------------
22 template<class TItkImageType>
23 void vvImage::AddItkImage(TItkImageType *input)
24 {
25   // Update input before conversion to enable exceptions thrown by the ITK pipeline.
26   // Otherwise, vtkImageImport catches the exception for us.
27   input->Update();
28   
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);
35   converter->Update();
36   mVtkImages.push_back( converter->GetOutput() );
37
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();
41   matrix->Identity();
42   for(unsigned int i=0; i<input->GetImageDimension(); i++) {
43     for(unsigned int j=0; j<input->GetImageDimension(); j++) {
44 #if VTK_MAJOR_VERSION <= 6
45       (*matrix)[i][j] = input->GetDirection()[i][j];
46       // Direction is used around the image origin in ITK
47       (*matrix)[i][3] -= (*matrix)[i][j] * input->GetOrigin()[j];
48 #else
49       (*matrix).SetElement(i, j, input->GetDirection()[i][j]);
50       // Direction is used around the image origin in ITK
51       (*matrix).SetElement(i, 3, (*matrix).GetElement(i,3) - (*matrix).GetElement(i,j) * input->GetOrigin()[j]);
52 #endif
53     }
54 #if VTK_MAJOR_VERSION <= 6
55     (*matrix)[i][3] += input->GetOrigin()[i];
56 #else
57     (*matrix).SetElement(i, 3, (*matrix).GetElement(i,3) + input->GetOrigin()[i]);
58 #endif
59   }
60
61   // GetDirection provides the forward transform, vtkImageReslice wants the inverse
62   matrix->Invert();
63
64   mTransform.push_back(vtkSmartPointer<vtkTransform>::New());
65   mTransform.back()->SetMatrix(matrix);
66   //META DATA
67   mDictionary.push_back(&(input->GetMetaDataDictionary()));
68 }
69 //--------------------------------------------------------------------
70  
71 /** Dispatch the computation of scalar range between vector and scalar image */
72 template<class TPixelType, unsigned int VImageDimension>
73 void vvImage::ComputeScalarRangeBase(itk::Image<TPixelType,VImageDimension> *input)
74
75  itkStaticConstMacro(Dimension1, unsigned int, itk::PixelTraits< TPixelType >::Dimension);
76  ComputeScalarRange(DimensionDispatch< Dimension1 >(), input);
77 }
78
79 //--------------------------------------------------------------------
80 /** Compute the scalar range for a vector pixel type */
81 /** TO DO*/
82 template<class TPixelType, unsigned int VImageDimension>
83 void vvImage::ComputeScalarRange(DimensionDispatchBase, itk::Image<TPixelType,VImageDimension> *input)
84 {
85 }
86
87 //--------------------------------------------------------------------
88 /** Compute the scalar range for a scalar pixel type */
89 template<class TPixelType, unsigned int VImageDimension>
90 void vvImage::ComputeScalarRange(DimensionDispatch< 1 >, itk::Image<TPixelType,VImageDimension> *input)
91 {  
92   typedef typename itk::Image<TPixelType,VImageDimension> TItkImageType;
93   typedef itk::MinimumMaximumImageCalculator <TItkImageType> ImageCalculatorFilterType;
94   
95   typename ImageCalculatorFilterType::Pointer imageCalculatorFilter = ImageCalculatorFilterType::New ();
96   TPixelType tempMin, tempMax;
97   double tempRange[2];
98   imageCalculatorFilter->SetImage(input);
99   imageCalculatorFilter->Compute();
100   tempMin= imageCalculatorFilter->GetMinimum();
101   tempMax= imageCalculatorFilter->GetMaximum();
102
103   tempRange[0] = (double) tempMin;
104   tempRange[1] = (double) tempMax;
105
106   if (tempRange[0] < mrange[0]) mrange[0]=tempRange[0];
107   if (tempRange[1] > mrange[1]) mrange[1]=tempRange[1];
108 }
109 //--------------------------------------------------------------------
110