X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FDataObjects%2FBoundingBox.cxx;h=6ecf3f224d83c9ad9b2f41a6676875a2e6f5874e;hb=d8ebffc6ece697ddf7b358946ef5d9c9cd7191fe;hp=0a0480c3dab4f2792c83af00de90b8772d72850b;hpb=3393941bf8f26babc7b592db434b40c1b747a687;p=cpPlugins.git diff --git a/lib/cpPlugins/DataObjects/BoundingBox.cxx b/lib/cpPlugins/DataObjects/BoundingBox.cxx index 0a0480c..6ecf3f2 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:: @@ -80,6 +82,7 @@ Blend( Self* other ) if( other->m_Points[ 1 ][ d ] > this->m_Points[ 1 ][ d ] ) this->m_Points[ 1 ][ d ] = other->m_Points[ 1 ][ d ]; this->Modified( ); + this->_UpdateVTK( ); } // ------------------------------------------------------------------------- @@ -121,4 +124,67 @@ _UpdateVTK( ) this->m_VTK = this->m_Outline->GetOutput( ); } +// ------------------------------------------------------------------------- +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$