X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FBoundingBox.cxx;fp=lib%2FcpPlugins%2FBoundingBox.cxx;h=14f48f4c4309d9e2a08a5d9cec2a3786873d16fa;hb=e0389395c168c78560e79c92bcd021a09c3daf30;hp=0000000000000000000000000000000000000000;hpb=953b68029bdcc30314b1474a11114291251fa76b;p=cpPlugins.git diff --git a/lib/cpPlugins/BoundingBox.cxx b/lib/cpPlugins/BoundingBox.cxx new file mode 100644 index 0000000..14f48f4 --- /dev/null +++ b/lib/cpPlugins/BoundingBox.cxx @@ -0,0 +1,97 @@ +#include +#include +#include + +// ------------------------------------------------------------------------- +void cpPlugins::BoundingBox:: +SetDataObject( DataObject* o ) +{ + auto i = o->GetITK< itk::LightObject >( ); + auto v = o->GetVTK< vtkObjectBase >( ); + if( v != NULL ) this->SetVTK( v ); + else if( i != NULL ) this->SetITK( i ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::BoundingBox:: +SetITK( itk::LightObject* o ) +{ + bool r = this->_ITKImage< 1 >( o ); + if( !r ) r = this->_ITKImage< 2 >( o ); + if( !r ) r = this->_ITKImage< 3 >( o ); + if( !r ) r = this->_ITKImage< 4 >( o ); + if( !r ) r = this->_ITKPointSet< float, 2 >( o ); + if( !r ) r = this->_ITKPointSet< double, 2 >( o ); + if( !r ) r = this->_ITKPointSet< float, 3 >( o ); + if( !r ) r = this->_ITKPointSet< double, 3 >( o ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::BoundingBox:: +SetVTK( vtkObjectBase* o ) +{ + auto ds = dynamic_cast< vtkDataSet* >( o ); + if( ds != NULL ) + { + double bounds[ 6 ]; + ds->GetBounds( bounds ); + this->m_Points[ 0 ].clear( ); + this->m_Points[ 1 ].clear( ); + this->m_Points[ 0 ].push_back( bounds[ 0 ] ); + this->m_Points[ 1 ].push_back( bounds[ 1 ] ); + this->m_Points[ 0 ].push_back( bounds[ 2 ] ); + this->m_Points[ 1 ].push_back( bounds[ 3 ] ); + this->m_Points[ 0 ].push_back( bounds[ 4 ] ); + this->m_Points[ 1 ].push_back( bounds[ 5 ] ); + + } // fi +} + +// ------------------------------------------------------------------------- +void cpPlugins::BoundingBox:: +Copy( Self* other ) +{ + this->m_Points[ 0 ] = other->m_Points[ 0 ]; + this->m_Points[ 1 ] = other->m_Points[ 1 ]; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +void cpPlugins::BoundingBox:: +Blend( Self* other ) +{ + if( this->m_Points[ 0 ].size( ) < other->m_Points[ 0 ].size( ) ) + this->m_Points[ 0 ].resize( + other->m_Points[ 0 ].size( ), + std::numeric_limits< double >::max( ) + ); + if( this->m_Points[ 1 ].size( ) < other->m_Points[ 1 ].size( ) ) + this->m_Points[ 1 ].resize( + other->m_Points[ 1 ].size( ), + -std::numeric_limits< double >::max( ) + ); + for( unsigned int d = 0; d < this->m_Points[ 0 ].size( ); ++d ) + if( other->m_Points[ 0 ][ d ] < this->m_Points[ 0 ][ d ] ) + this->m_Points[ 0 ][ d ] = other->m_Points[ 0 ][ d ]; + for( unsigned int d = 0; d < this->m_Points[ 1 ].size( ); ++d ) + if( other->m_Points[ 1 ][ d ] > this->m_Points[ 1 ][ d ] ) + this->m_Points[ 1 ][ d ] = other->m_Points[ 1 ][ d ]; + this->Modified( ); +} + +// ------------------------------------------------------------------------- +cpPlugins::BoundingBox:: +BoundingBox( ) + : Superclass( ) +{ + this->m_Points[ 0 ].push_back( double( 0 ) ); + this->m_Points[ 1 ].push_back( double( 0 ) ); +} + +// ------------------------------------------------------------------------- +cpPlugins::BoundingBox:: +~BoundingBox( ) +{ +} + +// eof - $RCSfile$