X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FDataObjects%2FBoundingBox.cxx;h=dfceb29f255081a30e7baac44e0be4e2c06848fa;hb=65e11480407fe343b2b56098257e0bb837f75df3;hp=0a0480c3dab4f2792c83af00de90b8772d72850b;hpb=6a541441b605b00b77d8f8e2b024cc709fda20b9;p=cpPlugins.git diff --git a/lib/cpPlugins/DataObjects/BoundingBox.cxx b/lib/cpPlugins/DataObjects/BoundingBox.cxx index 0a0480c..dfceb29 100644 --- a/lib/cpPlugins/DataObjects/BoundingBox.cxx +++ b/lib/cpPlugins/DataObjects/BoundingBox.cxx @@ -1,6 +1,8 @@ #include #include #include +#include +#include // ------------------------------------------------------------------------- void cpPlugins::DataObjects::BoundingBox:: @@ -82,6 +84,38 @@ Blend( Self* other ) this->Modified( ); } +// ------------------------------------------------------------------------- +template< class _TPoint > +void cpPlugins::DataObjects::BoundingBox:: +SetMinimum( const _TPoint& p ) +{ + this->_SetPoint( 0, p ); +} + +// ------------------------------------------------------------------------- +template< class _TPoint > +void cpPlugins::DataObjects::BoundingBox:: +SetMaximum( const _TPoint& p ) +{ + this->_SetPoint( 1, p ); +} + +// ------------------------------------------------------------------------- +template< class _TPoint > +_TPoint cpPlugins::DataObjects::BoundingBox:: +GetMinimum( ) const +{ + return( this->_GetPoint< _TPoint >( 0 ) ); +} + +// ------------------------------------------------------------------------- +template< class _TPoint > +_TPoint cpPlugins::DataObjects::BoundingBox:: +GetMaximum( ) const +{ + return( this->_GetPoint< _TPoint >( 1 ) ); +} + // ------------------------------------------------------------------------- cpPlugins::DataObjects::BoundingBox:: BoundingBox( ) @@ -121,4 +155,93 @@ _UpdateVTK( ) this->m_VTK = this->m_Outline->GetOutput( ); } +// ------------------------------------------------------------------------- +template< class _TPoint > +void cpPlugins::DataObjects::BoundingBox:: +_SetPoint( unsigned int m, const _TPoint& p ) +{ + this->m_Points[ m ].clear( ); + for( unsigned int d = 0; d < _TPoint::PointDimension; ++d ) + this->m_Points[ m ].push_back( double( p[ d ] ) ); + this->_UpdateVTK( ); + this->Modified( ); +} + +// ------------------------------------------------------------------------- +template< class _TPoint > +_TPoint cpPlugins::DataObjects::BoundingBox:: +_GetPoint( unsigned int m ) const +{ + unsigned int dim = this->m_Points[ m ].size( ); + dim = ( _TPoint::PointDimension < dim )? _TPoint::PointDimension: dim; + _TPoint p; + p.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + p[ d ] = this->m_Points[ m ][ d ]; + return( p ); +} + +// ------------------------------------------------------------------------- +template< unsigned int _NDim > +bool cpPlugins::DataObjects::BoundingBox:: +_ITKImage( itk::LightObject* o ) +{ + auto image = dynamic_cast< itk::ImageBase< _NDim >* >( o ); + if( image == NULL ) + return( false ); + + auto region = image->GetLargestPossibleRegion( ); + auto i0 = region.GetIndex( ); + auto i1 = i0 + region.GetSize( ); + + typename itk::ImageBase< _NDim >::PointType p0, p1; + image->TransformIndexToPhysicalPoint( i0, p0 ); + image->TransformIndexToPhysicalPoint( i1, p1 ); + this->m_Points[ 0 ].clear( ); + this->m_Points[ 1 ].clear( ); + + for( unsigned int d = 0; d < _NDim; ++d ) + { + this->m_Points[ 0 ].push_back( double( p0[ d ] ) ); + this->m_Points[ 1 ].push_back( double( p1[ d ] ) ); + + } // rof + this->Modified( ); + return( true ); +} + +// ------------------------------------------------------------------------- +template< class _TScalar, unsigned int _NDim > +bool cpPlugins::DataObjects::BoundingBox:: +_ITKPointSet( itk::LightObject* o ) +{ + typedef itk::PointSet< _TScalar, _NDim > _TPointSet; + typedef itk::BoundingBox< typename _TPointSet::PointIdentifier, _NDim, _TScalar, typename _TPointSet::PointsContainer > _TBBox; + + auto ps = dynamic_cast< _TPointSet* >( o ); + if( ps == NULL ) + return( false ); + + this->m_Points[ 0 ].clear( ); + this->m_Points[ 1 ].clear( ); + + typename _TBBox::Pointer bb = _TBBox::New( ); + bb->SetPoints( ps->GetPoints( ) ); + if( bb->ComputeBoundingBox( ) ) + { + auto p0 = bb->GetMinimum( ); + auto p1 = bb->GetMaximum( ); + for( unsigned int d = 0; d < _NDim; ++d ) + { + this->m_Points[ 0 ].push_back( double( p0[ d ] ) ); + this->m_Points[ 1 ].push_back( double( p1[ d ] ) ); + + } // rof + this->Modified( ); + return( true ); + } + else + return( false ); +} + // eof - $RCSfile$