1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__Base__PolyLineParametricPath__hxx__
7 #define __fpa__Base__PolyLineParametricPath__hxx__
10 #include <itkNumericTraits.h>
12 // -------------------------------------------------------------------------
13 template< unsigned int _VDim >
14 unsigned long fpa::Base::PolyLineParametricPath< _VDim >::
17 return( this->GetVertexList( )->Size( ) );
20 // -------------------------------------------------------------------------
21 template< unsigned int _VDim >
22 typename fpa::Base::PolyLineParametricPath< _VDim >::
24 fpa::Base::PolyLineParametricPath< _VDim >::
25 GetContinuousVertex( unsigned long i ) const
27 return( this->GetVertexList( )->GetElement( i ) );
30 // -------------------------------------------------------------------------
31 template< unsigned int _VDim >
32 typename fpa::Base::PolyLineParametricPath< _VDim >::
33 TIndex fpa::Base::PolyLineParametricPath< _VDim >::
34 GetVertex( unsigned long i ) const
36 TContinuousIndex cidx = this->GetContinuousVertex( i );
38 for( unsigned int d = 0; d < _VDim; ++d )
43 // -------------------------------------------------------------------------
44 template< unsigned int _VDim >
45 typename fpa::Base::PolyLineParametricPath< _VDim >::
46 TPoint fpa::Base::PolyLineParametricPath< _VDim >::
47 GetPoint( unsigned long i ) const
49 typedef typename TPoint::CoordRepType _TCoordRep;
51 TContinuousIndex idx = this->GetVertex( i );
52 for( unsigned int r = 0; r < _VDim; ++r )
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 ];
63 // -------------------------------------------------------------------------
64 template< unsigned int _VDim >
65 void fpa::Base::PolyLineParametricPath< _VDim >::
66 SetSpacing( const TSpacing& spac )
68 if( this->m_Spacing != spac )
70 this->m_Spacing = spac;
71 this->_ComputeIndexToPhysicalPointMatrices( );
77 // -------------------------------------------------------------------------
78 template< unsigned int _VDim >
79 void fpa::Base::PolyLineParametricPath< _VDim >::
80 SetSpacing( const double spac[ _VDim ] )
82 this->SetSpacing( TSpacing( spac ) );
85 // -------------------------------------------------------------------------
86 template< unsigned int _VDim >
87 void fpa::Base::PolyLineParametricPath< _VDim >::
88 SetSpacing( const float spac[ _VDim ] )
91 for( unsigned int d = 0; d < _VDim; ++d )
93 this->SetSpacing( s );
96 // -------------------------------------------------------------------------
97 template< unsigned int _VDim >
98 void fpa::Base::PolyLineParametricPath< _VDim >::
99 SetOrigin( const double ori[ _VDim ] )
101 this->SetOrigin( TPoint( ori ) );
104 // -------------------------------------------------------------------------
105 template< unsigned int _VDim >
106 void fpa::Base::PolyLineParametricPath< _VDim >::
107 SetOrigin( const float ori[ _VDim ] )
109 this->SetOrigin( TPoint( ori ) );
112 // -------------------------------------------------------------------------
113 template< unsigned int _VDim >
114 void fpa::Base::PolyLineParametricPath< _VDim >::
115 SetDirection( const TDirection& dir )
117 bool modified = false;
118 for( unsigned int r = 0; r < _VDim; r++ )
120 for( unsigned int c = 0; c < _VDim; c++ )
123 itk::Math::NotExactlyEquals(
124 this->m_Direction[ r ][ c ], dir[ r ][ c ]
128 this->m_Direction[ r ][ c ] = dir[ r ][ c ];
137 this->_ComputeIndexToPhysicalPointMatrices( );
138 this->m_InverseDirection = this->m_Direction.GetInverse( );
144 // -------------------------------------------------------------------------
145 template< unsigned int _VDim >
146 fpa::Base::PolyLineParametricPath< _VDim >::
147 PolyLineParametricPath( )
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( );
158 // -------------------------------------------------------------------------
159 template< unsigned int _VDim >
160 fpa::Base::PolyLineParametricPath< _VDim >::
161 ~PolyLineParametricPath( )
165 // -------------------------------------------------------------------------
166 template< unsigned int _VDim >
167 void fpa::Base::PolyLineParametricPath< _VDim >::
168 _ComputeIndexToPhysicalPointMatrices( )
172 for( unsigned int i = 0; i < _VDim; i++ )
174 if( this->m_Spacing[ i ] == 0.0 )
176 "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
178 scale[ i ][ i ] = this->m_Spacing[ i ];
182 if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
184 << "Bad direction, determinant is 0. Direction is "
187 this->m_IndexToPhysicalPoint = this->m_Direction * scale;
188 this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
192 #endif // __fpa__Base__PolyLineParametricPath__hxx__