1 #include <cpExtensions/DataStructures/Simple3DCurve.h>
3 // -------------------------------------------------------------------------
4 template< class _TScalar >
5 void cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
8 this->Superclass::Modified( );
9 this->m_FramesUpdated = false;
12 // -------------------------------------------------------------------------
13 template< class _TScalar >
14 void cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
17 this->m_Points.clear( );
18 this->m_Frames.clear( );
22 // -------------------------------------------------------------------------
23 template< class _TScalar >
24 unsigned long cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
25 GetNumberOfPoints( ) const
27 return( this->m_Points.size( ) );
30 // -------------------------------------------------------------------------
31 template< class _TScalar >
32 const typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
33 TMatrix& cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
34 GetFrame( unsigned int id ) const
36 if( !( this->m_FramesUpdated ) )
38 unsigned long N = this->m_Points.size( );
40 std::vector< TVector > tg( N );
41 tg[ 0 ] = this->m_Points[ 1 ] - this->m_Points[ 0 ];
42 tg[ N - 1 ] = this->m_Points[ N - 1 ] - this->m_Points[ N - 2 ];
43 for( unsigned int i = 1; i < N - 1; ++i )
44 tg[ i ] = this->m_Points[ i + 1 ] - this->m_Points[ i - 1 ];
46 std::vector< TVector > no( N );
47 std::vector< TVector > bn( N );
48 TVector prev_tg( _TScalar( 0 ) ), prev_no( _TScalar( 0 ) );
49 prev_tg[ 0 ] = _TScalar( 1 );
50 prev_no[ 1 ] = _TScalar( 1 );
51 for( unsigned int i = 0; i < N; ++i )
53 _TScalar ct = prev_tg * tg[ i ];
54 TVector a = itk::CrossProduct( prev_tg, tg[ i ] );
55 _TScalar st = a.GetNorm( );
56 if( st > _TScalar( 0 ) )
61 ( itk::CrossProduct( a, prev_no ) * st ) +
62 ( a * ( ( a * prev_no ) * ( _TScalar( 1 ) - ct ) ) );
63 bn[ i ] = itk::CrossProduct( tg[ i ], no[ i ] );
70 this->m_Frames.clear( );
71 for( unsigned int i = 0; i < N; ++i )
74 for( unsigned int d = 0; d < 3; ++d )
76 m[ d ][ 0 ] = tg[ i ][ d ];
77 m[ d ][ 1 ] = no[ i ][ d ];
78 m[ d ][ 2 ] = bn[ i ][ d ];
81 this->m_Frames.push_back( m );
86 this->m_FramesUpdated = true;
89 return( this->m_Frames[ id ] );
92 // -------------------------------------------------------------------------
93 template< class _TScalar >
94 const typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
95 TPoint& cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
96 GetPoint( unsigned int id ) const
98 return( this->m_Points[ id ] );
101 // -------------------------------------------------------------------------
102 template< class _TScalar >
103 typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
104 TVector cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
105 GetVector( unsigned int id ) const
107 return( this->m_Points[ id ].GetVectorFromOrigin( ) );
110 // -------------------------------------------------------------------------
111 template< class _TScalar >
112 cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
115 m_FramesUpdated( false )
119 // -------------------------------------------------------------------------
120 template< class _TScalar >
121 cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
126 // -------------------------------------------------------------------------
127 template class cpExtensions::DataStructures::Simple3DCurve< float >;
128 template class cpExtensions::DataStructures::Simple3DCurve< double >;