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 GetVertex( unsigned long i ) const
34 return( this->GetVertexList( )->GetElement( i ) );
37 // -------------------------------------------------------------------------
38 template< unsigned int _VDim >
39 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
40 TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
41 GetPoint( unsigned long i ) const
43 typedef typename TPoint::CoordRepType _TCoordRep;
45 TContinuousIndex idx = this->GetVertex( i );
46 for( unsigned int r = 0; r < _VDim; ++r )
48 _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
49 for( unsigned int c = 0; c < _VDim; ++c )
50 sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
51 pnt[ r ] = sum + this->m_Origin[ r ];
57 // -------------------------------------------------------------------------
58 template< unsigned int _VDim >
59 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
60 TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
61 GetSmoothPoint( double u ) const
65 p += this->m_Bezier->Evaluate( u );
69 // -------------------------------------------------------------------------
70 template< unsigned int _VDim >
71 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
72 SetSpacing( const TSpacing& spac )
74 if( this->m_Spacing != spac )
76 this->m_Spacing = spac;
77 this->_ComputeIndexToPhysicalPointMatrices( );
83 // -------------------------------------------------------------------------
84 template< unsigned int _VDim >
85 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
86 SetSpacing( const double spac[ _VDim ] )
88 this->SetSpacing( TSpacing( spac ) );
91 // -------------------------------------------------------------------------
92 template< unsigned int _VDim >
93 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
94 SetSpacing( const float spac[ _VDim ] )
97 for( unsigned int d = 0; d < _VDim; ++d )
99 this->SetSpacing( s );
102 // -------------------------------------------------------------------------
103 template< unsigned int _VDim >
104 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
105 SetOrigin( const double ori[ _VDim ] )
107 this->SetOrigin( TPoint( ori ) );
110 // -------------------------------------------------------------------------
111 template< unsigned int _VDim >
112 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
113 SetOrigin( const float ori[ _VDim ] )
115 this->SetOrigin( TPoint( ori ) );
118 // -------------------------------------------------------------------------
119 template< unsigned int _VDim >
120 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
121 SetDirection( const TDirection& dir )
123 bool modified = false;
124 for( unsigned int r = 0; r < _VDim; r++ )
126 for( unsigned int c = 0; c < _VDim; c++ )
129 itk::Math::NotExactlyEquals(
130 this->m_Direction[ r ][ c ], dir[ r ][ c ]
134 this->m_Direction[ r ][ c ] = dir[ r ][ c ];
143 this->_ComputeIndexToPhysicalPointMatrices( );
144 this->m_InverseDirection = this->m_Direction.GetInverse( );
150 // -------------------------------------------------------------------------
151 template< unsigned int _VDim >
152 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
153 PolyLineParametricPath( )
156 this->m_Bezier = TBezier::New( );
158 this->m_Spacing.Fill( 1.0 );
159 this->m_Origin.Fill( 0.0 );
160 this->m_Direction.SetIdentity( );
161 this->m_InverseDirection.SetIdentity( );
162 this->m_IndexToPhysicalPoint.SetIdentity( );
163 this->m_PhysicalPointToIndex.SetIdentity( );
166 // -------------------------------------------------------------------------
167 template< unsigned int _VDim >
168 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
169 ~PolyLineParametricPath( )
173 // -------------------------------------------------------------------------
174 template< unsigned int _VDim >
175 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
176 _ComputeIndexToPhysicalPointMatrices( )
180 for( unsigned int i = 0; i < _VDim; i++ )
182 if( this->m_Spacing[ i ] == 0.0 )
184 "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
186 scale[ i ][ i ] = this->m_Spacing[ i ];
190 if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
192 << "Bad direction, determinant is 0. Direction is "
195 this->m_IndexToPhysicalPoint = this->m_Direction * scale;
196 this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
200 #endif // __cpExtensions__DataStructures__PolyLineParametricPath__hxx__