1 #ifndef __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
2 #define __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
5 #include <itkNumericTraits.h>
7 // -------------------------------------------------------------------------
8 template< unsigned int _VDim >
9 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
10 AddVertex( const TContinuousIndex& vertex )
12 this->Superclass::AddVertex( vertex );
13 this->m_Bezier->AddPoint(
14 this->GetPoint( this->GetSize( ) - 1 ).GetVectorFromOrigin( )
19 // -------------------------------------------------------------------------
20 template< unsigned int _VDim >
21 unsigned long cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
24 return( this->GetVertexList( )->Size( ) );
27 // -------------------------------------------------------------------------
28 template< unsigned int _VDim >
29 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
31 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
32 GetContinuousVertex( unsigned long i ) const
34 return( this->GetVertexList( )->GetElement( i ) );
37 // -------------------------------------------------------------------------
38 template< unsigned int _VDim >
39 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
40 TIndex cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
41 GetVertex( unsigned long i ) const
43 TContinuousIndex cidx = this->GetContinuousVertex( i );
45 for( unsigned int d = 0; d < _VDim; ++d )
50 // -------------------------------------------------------------------------
51 template< unsigned int _VDim >
52 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
53 TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
54 GetPoint( unsigned long i ) const
56 typedef typename TPoint::CoordRepType _TCoordRep;
58 TContinuousIndex idx = this->GetVertex( i );
59 for( unsigned int r = 0; r < _VDim; ++r )
61 _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
62 for( unsigned int c = 0; c < _VDim; ++c )
63 sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
64 pnt[ r ] = sum + this->m_Origin[ r ];
70 // -------------------------------------------------------------------------
71 template< unsigned int _VDim >
72 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
73 TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
74 GetSmoothPoint( double u ) const
78 p += this->m_Bezier->Evaluate( u );
82 // -------------------------------------------------------------------------
83 template< unsigned int _VDim >
84 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
85 SetSpacing( const TSpacing& spac )
87 if( this->m_Spacing != spac )
89 this->m_Spacing = spac;
90 this->_ComputeIndexToPhysicalPointMatrices( );
96 // -------------------------------------------------------------------------
97 template< unsigned int _VDim >
98 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
99 SetSpacing( const double spac[ _VDim ] )
101 this->SetSpacing( TSpacing( spac ) );
104 // -------------------------------------------------------------------------
105 template< unsigned int _VDim >
106 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
107 SetSpacing( const float spac[ _VDim ] )
110 for( unsigned int d = 0; d < _VDim; ++d )
112 this->SetSpacing( s );
115 // -------------------------------------------------------------------------
116 template< unsigned int _VDim >
117 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
118 SetOrigin( const double ori[ _VDim ] )
120 this->SetOrigin( TPoint( ori ) );
123 // -------------------------------------------------------------------------
124 template< unsigned int _VDim >
125 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
126 SetOrigin( const float ori[ _VDim ] )
128 this->SetOrigin( TPoint( ori ) );
131 // -------------------------------------------------------------------------
132 template< unsigned int _VDim >
133 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
134 SetDirection( const TDirection& dir )
136 bool modified = false;
137 for( unsigned int r = 0; r < _VDim; r++ )
139 for( unsigned int c = 0; c < _VDim; c++ )
142 itk::Math::NotExactlyEquals(
143 this->m_Direction[ r ][ c ], dir[ r ][ c ]
147 this->m_Direction[ r ][ c ] = dir[ r ][ c ];
156 this->_ComputeIndexToPhysicalPointMatrices( );
157 this->m_InverseDirection = this->m_Direction.GetInverse( );
163 // -------------------------------------------------------------------------
164 template< unsigned int _VDim >
165 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
166 PolyLineParametricPath( )
169 this->m_Bezier = TBezier::New( );
171 this->m_Spacing.Fill( 1.0 );
172 this->m_Origin.Fill( 0.0 );
173 this->m_Direction.SetIdentity( );
174 this->m_InverseDirection.SetIdentity( );
175 this->m_IndexToPhysicalPoint.SetIdentity( );
176 this->m_PhysicalPointToIndex.SetIdentity( );
179 // -------------------------------------------------------------------------
180 template< unsigned int _VDim >
181 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
182 ~PolyLineParametricPath( )
186 // -------------------------------------------------------------------------
187 template< unsigned int _VDim >
188 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
189 _ComputeIndexToPhysicalPointMatrices( )
193 for( unsigned int i = 0; i < _VDim; i++ )
195 if( this->m_Spacing[ i ] == 0.0 )
197 "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
199 scale[ i ][ i ] = this->m_Spacing[ i ];
203 if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
205 << "Bad direction, determinant is 0. Direction is "
208 this->m_IndexToPhysicalPoint = this->m_Direction * scale;
209 this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
213 #endif // __cpExtensions__DataStructures__PolyLineParametricPath__hxx__