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 auto ntg = tg[ i ].GetNorm( );
54 if( double( ntg ) > double( 0 ) )
57 _TScalar ct = prev_tg * tg[ i ];
58 TVector a = itk::CrossProduct( prev_tg, tg[ i ] );
59 _TScalar st = a.GetNorm( );
60 if( st > _TScalar( 0 ) )
65 ( itk::CrossProduct( a, prev_no ) * st ) +
66 ( a * ( ( a * prev_no ) * ( _TScalar( 1 ) - ct ) ) );
67 auto nno = no[ i ].GetNorm( );
68 if( double( nno ) > double( 0 ) )
71 bn[ i ] = itk::CrossProduct( tg[ i ], no[ i ] );
78 this->m_Frames.clear( );
79 for( unsigned int i = 0; i < N; ++i )
82 for( unsigned int d = 0; d < 3; ++d )
84 m[ d ][ 0 ] = tg[ i ][ d ];
85 m[ d ][ 1 ] = no[ i ][ d ];
86 m[ d ][ 2 ] = bn[ i ][ d ];
89 this->m_Frames.push_back( m );
93 this->m_FramesUpdated = true;
96 return( this->m_Frames[ id ] );
99 // -------------------------------------------------------------------------
100 template< class _TScalar >
101 const typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
102 TPoint& cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
103 GetPoint( unsigned int id ) const
105 return( this->m_Points[ id ] );
108 // -------------------------------------------------------------------------
109 template< class _TScalar >
110 typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
111 TVector cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
112 GetVector( unsigned int id ) const
114 return( this->m_Points[ id ].GetVectorFromOrigin( ) );
117 // -------------------------------------------------------------------------
118 template< class _TScalar >
119 cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
122 m_FramesUpdated( false )
126 // -------------------------------------------------------------------------
127 template< class _TScalar >
128 cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
133 // -------------------------------------------------------------------------
134 template class cpExtensions::DataStructures::Simple3DCurve< float >;
135 template class cpExtensions::DataStructures::Simple3DCurve< double >;