1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
6 #ifndef __fpa__DataStructures__Image__Path__hxx__
7 #define __fpa__DataStructures__Image__Path__hxx__
10 #include <itkNumericTraits.h>
12 // -------------------------------------------------------------------------
13 template< unsigned int _VDim >
14 unsigned long fpa::DataStructures::Image::Path< _VDim >::
17 return( this->GetVertexList( )->Size( ) );
20 // -------------------------------------------------------------------------
21 template< unsigned int _VDim >
22 typename fpa::DataStructures::Image::Path< _VDim >::
23 TContinuousIndex fpa::DataStructures::Image::Path< _VDim >::
24 GetContinuousVertex( unsigned long i ) const
26 return( this->GetVertexList( )->GetElement( i ) );
29 // -------------------------------------------------------------------------
30 template< unsigned int _VDim >
31 typename fpa::DataStructures::Image::Path< _VDim >::
32 TIndex fpa::DataStructures::Image::Path< _VDim >::
33 GetVertex( unsigned long i ) const
35 TContinuousIndex cidx = this->GetContinuousVertex( i );
37 for( unsigned int d = 0; d < _VDim; ++d )
42 // -------------------------------------------------------------------------
43 template< unsigned int _VDim >
44 typename fpa::DataStructures::Image::Path< _VDim >::
45 TPoint fpa::DataStructures::Image::Path< _VDim >::
46 GetPoint( unsigned long i ) const
48 typedef typename TPoint::CoordRepType _TCoordRep;
50 TContinuousIndex idx = this->GetVertex( i );
51 for( unsigned int r = 0; r < _VDim; ++r )
53 _TCoordRep sum = itk::NumericTraits< _TCoordRep >::ZeroValue( );
54 for( unsigned int c = 0; c < _VDim; ++c )
55 sum += this->m_IndexToPhysicalPoint( r, c ) * idx[ c ];
56 pnt[ r ] = sum + this->m_Origin[ r ];
62 // -------------------------------------------------------------------------
63 template< unsigned int _VDim >
64 void fpa::DataStructures::Image::Path< _VDim >::
65 SetSpacing( const TSpacing& spac )
67 if( this->m_Spacing != spac )
69 this->m_Spacing = spac;
70 this->_ComputeIndexToPhysicalPointMatrices( );
76 // -------------------------------------------------------------------------
77 template< unsigned int _VDim >
78 void fpa::DataStructures::Image::Path< _VDim >::
79 SetSpacing( const double spac[ _VDim ] )
81 this->SetSpacing( TSpacing( spac ) );
84 // -------------------------------------------------------------------------
85 template< unsigned int _VDim >
86 void fpa::DataStructures::Image::Path< _VDim >::
87 SetSpacing( const float spac[ _VDim ] )
90 for( unsigned int d = 0; d < _VDim; ++d )
92 this->SetSpacing( s );
95 // -------------------------------------------------------------------------
96 template< unsigned int _VDim >
97 void fpa::DataStructures::Image::Path< _VDim >::
98 SetOrigin( const double ori[ _VDim ] )
100 this->SetOrigin( TPoint( ori ) );
103 // -------------------------------------------------------------------------
104 template< unsigned int _VDim >
105 void fpa::DataStructures::Image::Path< _VDim >::
106 SetOrigin( const float ori[ _VDim ] )
108 this->SetOrigin( TPoint( ori ) );
111 // -------------------------------------------------------------------------
112 template< unsigned int _VDim >
113 void fpa::DataStructures::Image::Path< _VDim >::
114 SetDirection( const TDirection& dir )
116 bool modified = false;
117 for( unsigned int r = 0; r < _VDim; r++ )
119 for( unsigned int c = 0; c < _VDim; c++ )
122 itk::Math::NotExactlyEquals(
123 this->m_Direction[ r ][ c ], dir[ r ][ c ]
127 this->m_Direction[ r ][ c ] = dir[ r ][ c ];
136 this->_ComputeIndexToPhysicalPointMatrices( );
137 this->m_InverseDirection = this->m_Direction.GetInverse( );
143 // -------------------------------------------------------------------------
144 template< unsigned int _VDim >
145 void fpa::DataStructures::Image::Path< _VDim >::
146 Graft( itk::DataObject* o )
148 this->Superclass::Graft( o );
149 Self* other = dynamic_cast< Self* >( o );
152 this->m_DefaultInputStepSize = other->m_DefaultInputStepSize;
154 for( unsigned long i = 0; i < other->GetSize( ); ++i )
155 this->AddVertex( other->GetContinuousVertex( i ) );
156 this->m_Spacing = other->m_Spacing;
157 this->m_Origin = other->m_Origin;
158 this->m_Direction = other->m_Direction;
159 this->m_InverseDirection = other->m_InverseDirection;
160 this->m_IndexToPhysicalPoint = other->m_IndexToPhysicalPoint;
161 this->m_PhysicalPointToIndex = other->m_PhysicalPointToIndex;
166 // -------------------------------------------------------------------------
167 template< unsigned int _VDim >
168 fpa::DataStructures::Image::Path< _VDim >::
172 this->m_Spacing.Fill( 1.0 );
173 this->m_Origin.Fill( 0.0 );
174 this->m_Direction.SetIdentity( );
175 this->m_InverseDirection.SetIdentity( );
176 this->m_IndexToPhysicalPoint.SetIdentity( );
177 this->m_PhysicalPointToIndex.SetIdentity( );
180 // -------------------------------------------------------------------------
181 template< unsigned int _VDim >
182 fpa::DataStructures::Image::Path< _VDim >::
187 // -------------------------------------------------------------------------
188 template< unsigned int _VDim >
189 void fpa::DataStructures::Image::Path< _VDim >::
190 _ComputeIndexToPhysicalPointMatrices( )
194 for( unsigned int i = 0; i < _VDim; i++ )
196 if( this->m_Spacing[ i ] == 0.0 )
198 "A spacing of 0 is not allowed: Spacing is " << this->m_Spacing
200 scale[ i ][ i ] = this->m_Spacing[ i ];
204 if( vnl_determinant( this->m_Direction.GetVnlMatrix( ) ) == 0.0 )
206 << "Bad direction, determinant is 0. Direction is "
209 this->m_IndexToPhysicalPoint = this->m_Direction * scale;
210 this->m_PhysicalPointToIndex = this->m_IndexToPhysicalPoint.GetInverse( );
214 #endif // __fpa__DataStructures__Image__Path__hxx__