1 #ifndef __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
2 #define __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
5 #include <itkNumericTraits.h>
7 // -------------------------------------------------------------------------
8 template< unsigned int _VDim >
9 unsigned long cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
12 return( this->GetVertexList( )->Size( ) );
15 // -------------------------------------------------------------------------
16 template< unsigned int _VDim >
17 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
19 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
20 GetVertex( unsigned long i ) const
22 return( this->GetVertexList( )->GetElement( i ) );
25 // -------------------------------------------------------------------------
26 template< unsigned int _VDim >
27 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
28 TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
29 GetPoint( unsigned long i ) const
31 typedef typename TPoint::CoordRepType _TCoordRep;
33 TContinuousIndex idx = this->GetVertex( i );
34 for( unsigned int r = 0; r < _VDim; ++r )
36 _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
37 for( unsigned int c = 0; c < _VDim; ++c )
38 sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
39 pnt[ r ] = sum + this->m_Origin[ r ];
45 // -------------------------------------------------------------------------
46 template< unsigned int _VDim >
47 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
48 SetSpacing( const TSpacing& spac )
50 if( this->m_Spacing != spac )
52 this->m_Spacing = spac;
53 this->_ComputeIndexToPhysicalPointMatrices( );
59 // -------------------------------------------------------------------------
60 template< unsigned int _VDim >
61 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
62 SetSpacing( const double spac[ _VDim ] )
64 this->SetSpacing( TSpacing( spac ) );
67 // -------------------------------------------------------------------------
68 template< unsigned int _VDim >
69 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
70 SetSpacing( const float spac[ _VDim ] )
73 for( unsigned int d = 0; d < _VDim; ++d )
75 this->SetSpacing( s );
78 // -------------------------------------------------------------------------
79 template< unsigned int _VDim >
80 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
81 SetOrigin( const double ori[ _VDim ] )
83 this->SetOrigin( TPoint( ori ) );
86 // -------------------------------------------------------------------------
87 template< unsigned int _VDim >
88 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
89 SetOrigin( const float ori[ _VDim ] )
91 this->SetOrigin( TPoint( ori ) );
94 // -------------------------------------------------------------------------
95 template< unsigned int _VDim >
96 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
97 SetDirection( const TDirection& dir )
99 bool modified = false;
100 for( unsigned int r = 0; r < _VDim; r++ )
102 for( unsigned int c = 0; c < _VDim; c++ )
105 itk::Math::NotExactlyEquals(
106 this->m_Direction[ r ][ c ], dir[ r ][ c ]
110 this->m_Direction[ r ][ c ] = dir[ r ][ c ];
119 this->_ComputeIndexToPhysicalPointMatrices( );
120 this->m_InverseDirection = this->m_Direction.GetInverse( );
126 // -------------------------------------------------------------------------
127 template< unsigned int _VDim >
128 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
129 PolyLineParametricPath( )
132 this->m_Spacing.Fill( 1.0 );
133 this->m_Origin.Fill( 0.0 );
134 this->m_Direction.SetIdentity( );
135 this->m_InverseDirection.SetIdentity( );
136 this->m_IndexToPhysicalPoint.SetIdentity( );
137 this->m_PhysicalPointToIndex.SetIdentity( );
140 // -------------------------------------------------------------------------
141 template< unsigned int _VDim >
142 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
143 ~PolyLineParametricPath( )
147 // -------------------------------------------------------------------------
148 template< unsigned int _VDim >
149 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
150 _ComputeIndexToPhysicalPointMatrices( )
154 for( unsigned int i = 0; i < _VDim; i++ )
156 if( this->m_Spacing[ i ] == 0.0 )
158 "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
160 scale[ i ][ i ] = this->m_Spacing[ i ];
164 if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
166 << "Bad direction, determinant is 0. Direction is "
169 this->m_IndexToPhysicalPoint = this->m_Direction * scale;
170 this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
174 #endif // __cpExtensions__DataStructures__PolyLineParametricPath__hxx__