]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/DataStructures/Simple3DCurve.cxx
...
[cpPlugins.git] / lib / cpExtensions / DataStructures / Simple3DCurve.cxx
1 #include <cpExtensions/DataStructures/Simple3DCurve.h>
2
3 // -------------------------------------------------------------------------
4 template< class _TScalar >
5 void cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
6 Modified( ) const
7 {
8   this->Superclass::Modified( );
9   this->m_FramesUpdated = false;
10 }
11
12 // -------------------------------------------------------------------------
13 template< class _TScalar >
14 void cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
15 Clear( )
16 {
17   this->m_Points.clear( );
18   this->m_Frames.clear( );
19   this->Modified( );
20 }
21
22 // -------------------------------------------------------------------------
23 template< class _TScalar >
24 unsigned long cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
25 GetNumberOfPoints( ) const
26 {
27   return( this->m_Points.size( ) );
28 }
29
30 // -------------------------------------------------------------------------
31 template< class _TScalar >
32 const typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
33 TMatrix& cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
34 GetFrame( unsigned int id ) const
35 {
36   if( !( this->m_FramesUpdated ) )
37   {
38     unsigned long N = this->m_Points.size( );
39
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 ];
45
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 )
52     {
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 ) )
57         a /= st;
58
59       no[ i ] =
60         ( prev_no * ct ) +
61         ( itk::CrossProduct( a, prev_no ) * st ) +
62         ( a * ( ( a * prev_no ) * ( _TScalar( 1 ) - ct ) ) );
63       bn[ i ] = itk::CrossProduct( tg[ i ], no[ i ] );
64
65       prev_tg = tg[ i ];
66       prev_no = no[ i ];
67
68     } // rof
69
70     this->m_Frames.clear( );
71     for( unsigned int i = 0; i < N; ++i )
72     {
73       TMatrix m;
74       for( unsigned int d = 0; d < 3; ++d )
75       {
76         m[ d ][ 0 ] = tg[ i ][ d ];
77         m[ d ][ 1 ] = no[ i ][ d ];
78         m[ d ][ 2 ] = bn[ i ][ d ];
79
80       } // rof
81       this->m_Frames.push_back( m );
82
83
84     } // rof
85
86     this->m_FramesUpdated = true;
87
88   } // fi
89   return( this->m_Frames[ id ] );
90 }
91
92 // -------------------------------------------------------------------------
93 template< class _TScalar >
94 const typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
95 TPoint& cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
96 GetPoint( unsigned int id ) const
97 {
98   return( this->m_Points[ id ] );
99 }
100
101 // -------------------------------------------------------------------------
102 template< class _TScalar >
103 typename cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
104 TVector cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
105 GetVector( unsigned int id ) const
106 {
107   return( this->m_Points[ id ].GetVectorFromOrigin( ) );
108 }
109
110 // -------------------------------------------------------------------------
111 template< class _TScalar >
112 cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
113 Simple3DCurve( )
114   : Superclass( ),
115     m_FramesUpdated( false )
116 {
117 }
118
119 // -------------------------------------------------------------------------
120 template< class _TScalar >
121 cpExtensions::DataStructures::Simple3DCurve< _TScalar >::
122 ~Simple3DCurve( )
123 {
124 }
125
126 // -------------------------------------------------------------------------
127 template class cpExtensions::DataStructures::Simple3DCurve< float >;
128 template class cpExtensions::DataStructures::Simple3DCurve< double >;
129
130 // eof - $RCSfile$