]> Creatis software - FrontAlgorithms.git/blob - lib/fpa/Base/PolyLineParametricPath.hxx
...
[FrontAlgorithms.git] / lib / fpa / Base / PolyLineParametricPath.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5
6 #ifndef __fpa__Base__PolyLineParametricPath__hxx__
7 #define __fpa__Base__PolyLineParametricPath__hxx__
8
9 #include <itkMath.h>
10 #include <itkNumericTraits.h>
11
12 // -------------------------------------------------------------------------
13 template< unsigned int _VDim >
14 unsigned long fpa::Base::PolyLineParametricPath< _VDim >::
15 GetSize( ) const
16 {
17   return( this->GetVertexList( )->Size( ) );
18 }
19
20 // -------------------------------------------------------------------------
21 template< unsigned int _VDim >
22 typename fpa::Base::PolyLineParametricPath< _VDim >::
23 TContinuousIndex
24 fpa::Base::PolyLineParametricPath< _VDim >::
25 GetContinuousVertex( unsigned long i ) const
26 {
27   return( this->GetVertexList( )->GetElement( i ) );
28 }
29
30 // -------------------------------------------------------------------------
31 template< unsigned int _VDim >
32 typename fpa::Base::PolyLineParametricPath< _VDim >::
33 TIndex fpa::Base::PolyLineParametricPath< _VDim >::
34 GetVertex( unsigned long i ) const
35 {
36   TContinuousIndex cidx = this->GetContinuousVertex( i );
37   TIndex idx;
38   for( unsigned int d = 0; d < _VDim; ++d )
39     idx[ d ] = cidx[ d ];
40   return( idx );
41 }
42
43 // -------------------------------------------------------------------------
44 template< unsigned int _VDim >
45 typename fpa::Base::PolyLineParametricPath< _VDim >::
46 TPoint fpa::Base::PolyLineParametricPath< _VDim >::
47 GetPoint( unsigned long i ) const
48 {
49   typedef typename TPoint::CoordRepType _TCoordRep;
50   TPoint pnt;
51   TContinuousIndex idx = this->GetVertex( i );
52   for( unsigned int r = 0; r < _VDim; ++r )
53   {
54     _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
55     for( unsigned int c = 0; c < _VDim; ++c )
56       sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
57     pnt[ r ] = sum + this->m_Origin[ r ];
58
59   } // rof
60   return( pnt );
61 }
62
63 // -------------------------------------------------------------------------
64 template< unsigned int _VDim >
65 void fpa::Base::PolyLineParametricPath< _VDim >::
66 SetSpacing( const TSpacing& spac )
67 {
68   if( this->m_Spacing != spac )
69   {
70     this->m_Spacing = spac;
71     this->_ComputeIndexToPhysicalPointMatrices( );
72     this->Modified( );
73
74   } // fi
75 }
76
77 // -------------------------------------------------------------------------
78 template< unsigned int _VDim >
79 void fpa::Base::PolyLineParametricPath< _VDim >::
80 SetSpacing( const double spac[ _VDim ] )
81 {
82   this->SetSpacing( TSpacing( spac ) );
83 }
84
85 // -------------------------------------------------------------------------
86 template< unsigned int _VDim >
87 void fpa::Base::PolyLineParametricPath< _VDim >::
88 SetSpacing( const float spac[ _VDim ] )
89 {
90   TSpacing s;
91   for( unsigned int d = 0; d < _VDim; ++d )
92     s[ d ] = spac[ d ];
93   this->SetSpacing( s );
94 }
95
96 // -------------------------------------------------------------------------
97 template< unsigned int _VDim >
98 void fpa::Base::PolyLineParametricPath< _VDim >::
99 SetOrigin( const double ori[ _VDim ] )
100 {
101   this->SetOrigin( TPoint( ori ) );
102 }
103
104 // -------------------------------------------------------------------------
105 template< unsigned int _VDim >
106 void fpa::Base::PolyLineParametricPath< _VDim >::
107 SetOrigin( const float ori[ _VDim ] )
108 {
109   this->SetOrigin( TPoint( ori ) );
110 }
111
112 // -------------------------------------------------------------------------
113 template< unsigned int _VDim >
114 void fpa::Base::PolyLineParametricPath< _VDim >::
115 SetDirection( const TDirection& dir )
116 {
117   bool modified = false;
118   for( unsigned int r = 0; r < _VDim; r++ )
119   {
120     for( unsigned int c = 0; c < _VDim; c++ )
121     {
122       if(
123         itk::Math::NotExactlyEquals(
124           this->m_Direction[ r ][ c ], dir[ r ][ c ]
125           )
126         )
127       {
128         this->m_Direction[ r ][ c ] = dir[ r ][ c ];
129         modified = true;
130       } // fi
131
132     } // rof
133
134   } // rof
135   if( modified )
136   {
137     this->_ComputeIndexToPhysicalPointMatrices( );
138     this->m_InverseDirection = this->m_Direction.GetInverse( );
139     this->Modified( );
140
141   } // fi
142 }
143
144 // -------------------------------------------------------------------------
145 template< unsigned int _VDim >
146 fpa::Base::PolyLineParametricPath< _VDim >::
147 PolyLineParametricPath( )
148   : Superclass( )
149 {
150   this->m_Spacing.Fill( 1.0 );
151   this->m_Origin.Fill( 0.0 );
152   this->m_Direction.SetIdentity( );
153   this->m_InverseDirection.SetIdentity( );
154   this->m_IndexToPhysicalPoint.SetIdentity( );
155   this->m_PhysicalPointToIndex.SetIdentity( );
156 }
157
158 // -------------------------------------------------------------------------
159 template< unsigned int _VDim >
160 fpa::Base::PolyLineParametricPath< _VDim >::
161 ~PolyLineParametricPath( )
162 {
163 }
164
165 // -------------------------------------------------------------------------
166 template< unsigned int _VDim >
167 void fpa::Base::PolyLineParametricPath< _VDim >::
168 _ComputeIndexToPhysicalPointMatrices( )
169 {
170   TDirection scale;
171   scale.Fill( 0.0 );
172   for( unsigned int i = 0; i < _VDim; i++ )
173   {
174     if( this->m_Spacing[ i ] == 0.0 )
175       itkExceptionMacro(
176         "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
177         );
178     scale[ i ][ i ] = this->m_Spacing[ i ];
179
180   } // rof
181
182   if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
183     itkExceptionMacro(
184       << "Bad direction, determinant is 0. Direction is "
185       << this->m_Direction
186       );
187   this->m_IndexToPhysicalPoint = this->m_Direction * scale;
188   this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
189   this->Modified( );
190 }
191
192 #endif // __fpa__Base__PolyLineParametricPath__hxx__
193
194 // eof - $RCSfile$