]> Creatis software - cpPlugins.git/blob - lib/cpExtensions/DataStructures/PolyLineParametricPath.hxx
306ab79fe41fda72fa44de5d1f36043fc100e5c2
[cpPlugins.git] / lib / cpExtensions / DataStructures / PolyLineParametricPath.hxx
1 #ifndef __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
2 #define __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
3
4 #include <itkMath.h>
5 #include <itkNumericTraits.h>
6
7 // -------------------------------------------------------------------------
8 template< unsigned int _VDim >
9 unsigned long cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
10 GetSize( ) const
11 {
12   return( this->GetVertexList( )->Size( ) );
13 }
14
15 // -------------------------------------------------------------------------
16 template< unsigned int _VDim >
17 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
18 TContinuousIndex
19 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
20 GetVertex( unsigned long i ) const
21 {
22   return( this->GetVertexList( )->GetElement( i ) );
23 }
24
25 // -------------------------------------------------------------------------
26 template< unsigned int _VDim >
27 typename cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
28 TPoint cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
29 GetPoint( unsigned long i ) const
30 {
31   typedef typename TPoint::CoordRepType _TCoordRep;
32   TPoint pnt;
33   TContinuousIndex idx = this->GetVertex( i );
34   for( unsigned int r = 0; r < _VDim; ++r )
35   {
36     _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
37     for( unsigned int c = 0; c < _VDim; ++c )
38       sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
39     pnt[ r ] = sum + this->m_Origin[ r ];
40
41   } // rof
42   return( pnt );
43 }
44
45 // -------------------------------------------------------------------------
46 template< unsigned int _VDim >
47 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
48 SetSpacing( const TSpacing& spac )
49 {
50   if( this->m_Spacing != spac )
51   {
52     this->m_Spacing = spac;
53     this->_ComputeIndexToPhysicalPointMatrices( );
54     this->Modified( );
55
56   } // fi
57 }
58
59 // -------------------------------------------------------------------------
60 template< unsigned int _VDim >
61 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
62 SetSpacing( const double spac[ _VDim ] )
63 {
64   this->SetSpacing( TSpacing( spac ) );
65 }
66
67 // -------------------------------------------------------------------------
68 template< unsigned int _VDim >
69 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
70 SetSpacing( const float spac[ _VDim ] )
71 {
72   TSpacing s;
73   for( unsigned int d = 0; d < _VDim; ++d )
74     s[ d ] = spac[ d ];
75   this->SetSpacing( s );
76 }
77
78 // -------------------------------------------------------------------------
79 template< unsigned int _VDim >
80 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
81 SetOrigin( const double ori[ _VDim ] )
82 {
83   this->SetOrigin( TPoint( ori ) );
84 }
85
86 // -------------------------------------------------------------------------
87 template< unsigned int _VDim >
88 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
89 SetOrigin( const float ori[ _VDim ] )
90 {
91   this->SetOrigin( TPoint( ori ) );
92 }
93
94 // -------------------------------------------------------------------------
95 template< unsigned int _VDim >
96 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
97 SetDirection( const TDirection& dir )
98 {
99   bool modified = false;
100   for( unsigned int r = 0; r < _VDim; r++ )
101   {
102     for( unsigned int c = 0; c < _VDim; c++ )
103     {
104       if(
105         itk::Math::NotExactlyEquals(
106           this->m_Direction[ r ][ c ], dir[ r ][ c ]
107           )
108         )
109       {
110         this->m_Direction[ r ][ c ] = dir[ r ][ c ];
111         modified = true;
112       } // fi
113
114     } // rof
115
116   } // rof
117   if( modified )
118   {
119     this->_ComputeIndexToPhysicalPointMatrices( );
120     this->m_InverseDirection = this->m_Direction.GetInverse( );
121     this->Modified( );
122
123   } // fi
124 }
125
126 // -------------------------------------------------------------------------
127 template< unsigned int _VDim >
128 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
129 PolyLineParametricPath( )
130   : Superclass( )
131 {
132   this->m_Spacing.Fill( 1.0 );
133   this->m_Origin.Fill( 0.0 );
134   this->m_Direction.SetIdentity( );
135   this->m_InverseDirection.SetIdentity( );
136   this->m_IndexToPhysicalPoint.SetIdentity( );
137   this->m_PhysicalPointToIndex.SetIdentity( );
138 }
139
140 // -------------------------------------------------------------------------
141 template< unsigned int _VDim >
142 cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
143 ~PolyLineParametricPath( )
144 {
145 }
146
147 // -------------------------------------------------------------------------
148 template< unsigned int _VDim >
149 void cpExtensions::DataStructures::PolyLineParametricPath< _VDim >::
150 _ComputeIndexToPhysicalPointMatrices( )
151 {
152   TDirection scale;
153   scale.Fill( 0.0 );
154   for( unsigned int i = 0; i < _VDim; i++ )
155   {
156     if( this->m_Spacing[ i ] == 0.0 )
157       itkExceptionMacro(
158         "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
159         );
160     scale[ i ][ i ] = this->m_Spacing[ i ];
161
162   } // rof
163
164   if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
165     itkExceptionMacro(
166       << "Bad direction, determinant is 0. Direction is "
167       << this->m_Direction
168       );
169   this->m_IndexToPhysicalPoint = this->m_Direction * scale;
170   this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
171   this->Modified( );
172 }
173
174 #endif // __cpExtensions__DataStructures__PolyLineParametricPath__hxx__
175
176 // eof - $RCSfile$