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 #ifndef __clitkPointListTransform_txx
19 #define __clitkPointListTransform_txx
20 #include "clitkPointListTransform.h"
27 template<class TScalarType, unsigned int NDimensions, unsigned int NOutputDimensions>
28 PointListTransform<TScalarType, NDimensions, NOutputDimensions>::PointListTransform():Superclass(1)
30 m_PointLists.resize(0);
31 m_PointList.resize(1);
34 // Find the point list in the lists
35 template<class TScalarType, unsigned int NDimensions,unsigned int NOutputDimensions>
36 typename PointListTransform<TScalarType, NDimensions, NOutputDimensions>::PointListType
37 PointListTransform<TScalarType, NDimensions,NOutputDimensions>::
38 GetCorrespondingPointList(const InputPointType &inputPoint) const
41 for(unsigned int j=0; j< SpaceDimension;j++)
42 point[j]=inputPoint[j];
44 if(m_PointList[0]==point) return m_PointList;
47 for (unsigned int i=0; i< m_PointLists.size();i++)
48 if(m_PointLists[i][0]==point) return m_PointLists[i];
51 itkExceptionMacro(<<"Point List not found");
56 template<class TScalarType, unsigned int NDimensions,unsigned int NOutputDimensions>
57 typename PointListTransform<TScalarType, NDimensions,NOutputDimensions>::OutputPointType
58 PointListTransform<TScalarType, NDimensions,NOutputDimensions>::
59 TransformPoint(const InputPointType &inputPoint) const
62 // -------------------------------
63 // Get the corresponding point list
64 m_PointList = this->GetCorrespondingPointList(inputPoint);
66 // -------------------------------
67 // Create 1D vector image
68 typename PointListImageType::Pointer pointListImage=PointListImageType::New();
69 typename PointListImageType::RegionType region;
70 region.SetSize(0,m_PointList.size()+6);
71 pointListImage->SetRegions(region);
72 pointListImage->Allocate();
73 typename PointListImageType::SpacingType spacing;
75 pointListImage->SetSpacing(spacing);
76 typename PointListImageType::PointType origin;
78 pointListImage->SetOrigin(origin);
81 // -------------------------------
82 // Copy Point list to image
83 typedef itk::ImageRegionIterator<PointListImageType> IteratorType;
84 IteratorType it(pointListImage, pointListImage->GetLargestPossibleRegion());
86 // First points are the last
87 PointListImagePixelType pixel;
88 for (unsigned int j=0; j<2;j++)
90 for (unsigned int i=0; i <SpaceDimension; i++)
91 pixel[i]=m_PointList[m_PointList.size()-2+j][i];
97 unsigned int position=0;
98 while(position< m_PointList.size())
100 for (unsigned int i=0; i <SpaceDimension; i++)
101 pixel[i]=m_PointList[position][i];
107 // last points are the first
108 for (unsigned int j=0; j<4;j++)
110 for (unsigned int i=0; i <SpaceDimension; i++)
111 pixel[i]=m_PointList[j][i];
116 // -------------------------------
117 // Set 1D image to vectorInterpolator
118 m_Interpolator->SetInputImage(pointListImage);
121 // -------------------------------
122 // Evaluate at phase value
123 typename PointListImageType::PointType t;
124 t[0]=inputPoint[ImageDimension-1];
126 // Inside valid region?
128 (t[0] < m_PointList.size()) )
130 pixel= m_Interpolator->Evaluate(t);
131 OutputPointType outputPoint;
132 for (unsigned int i=0; i < SpaceDimension; i++)
133 outputPoint[i]=pixel[i];
134 outputPoint[ImageDimension-1]=t[0];
138 else return inputPoint;