1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__DataStructures__Image__PolyLineParametricPath__hxx__
7 #define __fpa__DataStructures__Image__PolyLineParametricPath__hxx__
10 #include <itkNumericTraits.h>
12 // -------------------------------------------------------------------------
13 template< unsigned int _VDim >
14 unsigned long fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
17 return( this->GetVertexList( )->Size( ) );
20 // -------------------------------------------------------------------------
21 template< unsigned int _VDim >
22 typename fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
24 fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
25 GetContinuousVertex( unsigned long i ) const
27 return( this->GetVertexList( )->GetElement( i ) );
30 // -------------------------------------------------------------------------
31 template< unsigned int _VDim >
32 typename fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
33 TIndex fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
34 GetVertex( unsigned long i ) const
36 TContinuousIndex cidx = this->GetContinuousVertex( i );
38 for( unsigned int d = 0; d < _VDim; ++d )
43 // -------------------------------------------------------------------------
44 template< unsigned int _VDim >
45 typename fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
46 TPoint fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
47 GetPoint( unsigned long i ) const
49 typedef typename TPoint::CoordRepType _TCoordRep;
51 TContinuousIndex idx = this->GetVertex( i );
52 for( unsigned int r = 0; r < _VDim; ++r )
54 _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
55 for( unsigned int c = 0; c < _VDim; ++c )
56 sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
57 pnt[ r ] = sum + this->m_Origin[ r ];
63 // -------------------------------------------------------------------------
64 template< unsigned int _VDim >
65 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
66 SetSpacing( const TSpacing& spac )
68 if( this->m_Spacing != spac )
70 this->m_Spacing = spac;
71 this->_ComputeIndexToPhysicalPointMatrices( );
77 // -------------------------------------------------------------------------
78 template< unsigned int _VDim >
79 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
80 SetSpacing( const double spac[ _VDim ] )
82 this->SetSpacing( TSpacing( spac ) );
85 // -------------------------------------------------------------------------
86 template< unsigned int _VDim >
87 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
88 SetSpacing( const float spac[ _VDim ] )
91 for( unsigned int d = 0; d < _VDim; ++d )
93 this->SetSpacing( s );
96 // -------------------------------------------------------------------------
97 template< unsigned int _VDim >
98 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
99 SetOrigin( const double ori[ _VDim ] )
101 this->SetOrigin( TPoint( ori ) );
104 // -------------------------------------------------------------------------
105 template< unsigned int _VDim >
106 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
107 SetOrigin( const float ori[ _VDim ] )
109 this->SetOrigin( TPoint( ori ) );
112 // -------------------------------------------------------------------------
113 template< unsigned int _VDim >
114 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
115 SetDirection( const TDirection& dir )
117 bool modified = false;
118 for( unsigned int r = 0; r < _VDim; r++ )
120 for( unsigned int c = 0; c < _VDim; c++ )
123 itk::Math::NotExactlyEquals(
124 this->m_Direction[ r ][ c ], dir[ r ][ c ]
128 this->m_Direction[ r ][ c ] = dir[ r ][ c ];
137 this->_ComputeIndexToPhysicalPointMatrices( );
138 this->m_InverseDirection = this->m_Direction.GetInverse( );
144 // -------------------------------------------------------------------------
145 template< unsigned int _VDim >
146 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
147 Graft( itk::DataObject* o )
149 this->Superclass::Graft( o );
150 Self* other = dynamic_cast< Self* >( o );
153 this->m_DefaultInputStepSize = other->m_DefaultInputStepSize;
155 for( unsigned long i = 0; i < other->GetSize( ); ++i )
156 this->AddVertex( other->GetContinuousVertex( i ) );
157 this->m_Spacing = other->m_Spacing;
158 this->m_Origin = other->m_Origin;
159 this->m_Direction = other->m_Direction;
160 this->m_InverseDirection = other->m_InverseDirection;
161 this->m_IndexToPhysicalPoint = other->m_IndexToPhysicalPoint;
162 this->m_PhysicalPointToIndex = other->m_PhysicalPointToIndex;
167 // -------------------------------------------------------------------------
168 template< unsigned int _VDim >
169 fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
170 PolyLineParametricPath( )
173 this->m_Spacing.Fill( 1.0 );
174 this->m_Origin.Fill( 0.0 );
175 this->m_Direction.SetIdentity( );
176 this->m_InverseDirection.SetIdentity( );
177 this->m_IndexToPhysicalPoint.SetIdentity( );
178 this->m_PhysicalPointToIndex.SetIdentity( );
181 // -------------------------------------------------------------------------
182 template< unsigned int _VDim >
183 fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
184 ~PolyLineParametricPath( )
188 // -------------------------------------------------------------------------
189 template< unsigned int _VDim >
190 void fpa::DataStructures::Image::PolyLineParametricPath< _VDim >::
191 _ComputeIndexToPhysicalPointMatrices( )
195 for( unsigned int i = 0; i < _VDim; i++ )
197 if( this->m_Spacing[ i ] == 0.0 )
199 "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
201 scale[ i ][ i ] = this->m_Spacing[ i ];
205 if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
207 << "Bad direction, determinant is 0. Direction is "
210 this->m_IndexToPhysicalPoint = this->m_Direction * scale;
211 this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
215 #endif // __fpa__DataStructures__Image__PolyLineParametricPath__hxx__