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://oncora1.lyon.fnclcc.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>
29 ::PointListTransform():Superclass(NOutputDimensions,1)
31 m_PointLists.resize(0);
32 m_PointList.resize(1);
35 // Find the point list in the lists
36 template<class TScalarType, unsigned int NDimensions,unsigned int NOutputDimensions>
37 typename PointListTransform<TScalarType, NDimensions, NOutputDimensions>::PointListType
38 PointListTransform<TScalarType, NDimensions,NOutputDimensions>::
39 GetCorrespondingPointList(const InputPointType &inputPoint) const
42 for(unsigned int j=0; j< SpaceDimension;j++)
43 point[j]=inputPoint[j];
45 if(m_PointList[0]==point) return m_PointList;
48 for (unsigned int i=0; i< m_PointLists.size();i++)
49 if(m_PointLists[i][0]==point) return m_PointLists[i];
52 itkExceptionMacro(<<"Point List not found");
57 template<class TScalarType, unsigned int NDimensions,unsigned int NOutputDimensions>
58 typename PointListTransform<TScalarType, NDimensions,NOutputDimensions>::OutputPointType
59 PointListTransform<TScalarType, NDimensions,NOutputDimensions>::
60 TransformPoint(const InputPointType &inputPoint) const
63 // -------------------------------
64 // Get the corresponding point list
65 m_PointList = this->GetCorrespondingPointList(inputPoint);
67 // -------------------------------
68 // Create 1D vector image
69 typename PointListImageType::Pointer pointListImage=PointListImageType::New();
70 typename PointListImageType::RegionType region;
71 region.SetSize(0,m_PointList.size()+6);
72 pointListImage->SetRegions(region);
73 pointListImage->Allocate();
74 typename PointListImageType::SpacingType spacing;
76 pointListImage->SetSpacing(spacing);
77 typename PointListImageType::PointType origin;
79 pointListImage->SetOrigin(origin);
82 // -------------------------------
83 // Copy Point list to image
84 typedef itk::ImageRegionIterator<PointListImageType> IteratorType;
85 IteratorType it(pointListImage, pointListImage->GetLargestPossibleRegion());
87 // First points are the last
88 PointListImagePixelType pixel;
89 for (unsigned int j=0; j<2;j++)
91 for (unsigned int i=0; i <SpaceDimension; i++)
92 pixel[i]=m_PointList[m_PointList.size()-2+j][i];
98 unsigned int position=0;
99 while(position< m_PointList.size())
101 for (unsigned int i=0; i <SpaceDimension; i++)
102 pixel[i]=m_PointList[position][i];
108 // last points are the first
109 for (unsigned int j=0; j<4;j++)
111 for (unsigned int i=0; i <SpaceDimension; i++)
112 pixel[i]=m_PointList[j][i];
117 // -------------------------------
118 // Set 1D image to vectorInterpolator
119 m_Interpolator->SetInputImage(pointListImage);
122 // -------------------------------
123 // Evaluate at phase value
124 typename PointListImageType::PointType t;
125 t[0]=inputPoint[ImageDimension-1];
127 // Inside valid region?
129 (t[0] < m_PointList.size()) )
131 pixel= m_Interpolator->Evaluate(t);
132 OutputPointType outputPoint;
133 for (unsigned int i=0; i < SpaceDimension; i++)
134 outputPoint[i]=pixel[i];
135 outputPoint[ImageDimension-1]=t[0];
139 else return inputPoint;