1 #ifndef __cpPlugins__DataObjects__BoundingBox__hxx__
2 #define __cpPlugins__DataObjects__BoundingBox__hxx__
4 #include <cpPlugins/DataObjects/Image.h>
5 #include <cpPlugins/DataObjects/Mesh.h>
6 #include <itkBoundingBox.h>
7 #include <itkPointSet.h>
9 // -------------------------------------------------------------------------
10 template< class _TPoint >
11 void cpPlugins::DataObjects::BoundingBox::
12 SetMinimum( const _TPoint& p )
14 this->_SetPoint( 0, p );
17 // -------------------------------------------------------------------------
18 template< class _TPoint >
19 void cpPlugins::DataObjects::BoundingBox::
20 SetMaximum( const _TPoint& p )
22 this->_SetPoint( 1, p );
25 // -------------------------------------------------------------------------
26 template< class _TPoint >
27 _TPoint cpPlugins::DataObjects::BoundingBox::
30 return( this->_GetPoint< _TPoint >( 0 ) );
33 // -------------------------------------------------------------------------
34 template< class _TPoint >
35 _TPoint cpPlugins::DataObjects::BoundingBox::
38 return( this->_GetPoint< _TPoint >( 1 ) );
41 // -------------------------------------------------------------------------
42 template< class _TPoint >
43 void cpPlugins::DataObjects::BoundingBox::
44 _SetPoint( unsigned int m, const _TPoint& p )
46 this->m_Points[ m ].clear( );
47 for( unsigned int d = 0; d < _TPoint::PointDimension; ++d )
48 this->m_Points[ m ].push_back( double( p[ d ] ) );
53 // -------------------------------------------------------------------------
54 template< class _TPoint >
55 _TPoint cpPlugins::DataObjects::BoundingBox::
56 _GetPoint( unsigned int m ) const
58 unsigned int dim = this->m_Points[ m ].size( );
59 dim = ( _TPoint::PointDimension < dim )? _TPoint::PointDimension: dim;
62 for( unsigned int d = 0; d < dim; ++d )
63 p[ d ] = this->m_Points[ m ][ d ];
67 // -------------------------------------------------------------------------
68 template< unsigned int _NDim >
69 bool cpPlugins::DataObjects::BoundingBox::
70 _ITKImage( itk::LightObject* o )
72 auto image = dynamic_cast< itk::ImageBase< _NDim >* >( o );
76 auto region = image->GetLargestPossibleRegion( );
77 auto i0 = region.GetIndex( );
78 auto i1 = i0 + region.GetSize( );
80 typename itk::ImageBase< _NDim >::PointType p0, p1;
81 image->TransformIndexToPhysicalPoint( i0, p0 );
82 image->TransformIndexToPhysicalPoint( i1, p1 );
83 this->m_Points[ 0 ].clear( );
84 this->m_Points[ 1 ].clear( );
86 for( unsigned int d = 0; d < _NDim; ++d )
88 this->m_Points[ 0 ].push_back( double( p0[ d ] ) );
89 this->m_Points[ 1 ].push_back( double( p1[ d ] ) );
96 // -------------------------------------------------------------------------
97 template< class _TScalar, unsigned int _NDim >
98 bool cpPlugins::DataObjects::BoundingBox::
99 _ITKPointSet( itk::LightObject* o )
101 typedef itk::PointSet< _TScalar, _NDim > _TPointSet;
102 typedef itk::BoundingBox< typename _TPointSet::PointIdentifier, _NDim, _TScalar, typename _TPointSet::PointsContainer > _TBBox;
104 auto ps = dynamic_cast< _TPointSet* >( o );
108 this->m_Points[ 0 ].clear( );
109 this->m_Points[ 1 ].clear( );
111 typename _TBBox::Pointer bb = _TBBox::New( );
112 bb->SetPoints( ps->GetPoints( ) );
113 if( bb->ComputeBoundingBox( ) )
115 auto p0 = bb->GetMinimum( );
116 auto p1 = bb->GetMaximum( );
117 for( unsigned int d = 0; d < _NDim; ++d )
119 this->m_Points[ 0 ].push_back( double( p0[ d ] ) );
120 this->m_Points[ 1 ].push_back( double( p1[ d ] ) );
130 #endif // __cpPlugins__DataObjects__BoundingBox__hxx__