1 #include <cpPlugins/BoundingBox.h>
3 #include <vtkDataSet.h>
5 // -------------------------------------------------------------------------
6 void cpPlugins::BoundingBox::
7 SetDataObject( DataObject* o )
9 auto i = o->GetITK< itk::LightObject >( );
10 auto v = o->GetVTK< vtkObjectBase >( );
11 if( v != NULL ) this->SetVTK( v );
12 else if( i != NULL ) this->SetITK( i );
15 // -------------------------------------------------------------------------
16 void cpPlugins::BoundingBox::
17 SetITK( itk::LightObject* o )
19 bool r = this->_ITKImage< 1 >( o );
20 if( !r ) r = this->_ITKImage< 2 >( o );
21 if( !r ) r = this->_ITKImage< 3 >( o );
22 if( !r ) r = this->_ITKImage< 4 >( o );
23 if( !r ) r = this->_ITKPointSet< float, 2 >( o );
24 if( !r ) r = this->_ITKPointSet< double, 2 >( o );
25 if( !r ) r = this->_ITKPointSet< float, 3 >( o );
26 if( !r ) r = this->_ITKPointSet< double, 3 >( o );
29 // -------------------------------------------------------------------------
30 void cpPlugins::BoundingBox::
31 SetVTK( vtkObjectBase* o )
33 auto ds = dynamic_cast< vtkDataSet* >( o );
37 ds->GetBounds( bounds );
38 this->m_Points[ 0 ].clear( );
39 this->m_Points[ 1 ].clear( );
40 this->m_Points[ 0 ].push_back( bounds[ 0 ] );
41 this->m_Points[ 1 ].push_back( bounds[ 1 ] );
42 this->m_Points[ 0 ].push_back( bounds[ 2 ] );
43 this->m_Points[ 1 ].push_back( bounds[ 3 ] );
44 this->m_Points[ 0 ].push_back( bounds[ 4 ] );
45 this->m_Points[ 1 ].push_back( bounds[ 5 ] );
50 // -------------------------------------------------------------------------
51 void cpPlugins::BoundingBox::
54 this->m_Points[ 0 ] = other->m_Points[ 0 ];
55 this->m_Points[ 1 ] = other->m_Points[ 1 ];
59 // -------------------------------------------------------------------------
60 void cpPlugins::BoundingBox::
63 if( this->m_Points[ 0 ].size( ) < other->m_Points[ 0 ].size( ) )
64 this->m_Points[ 0 ].resize(
65 other->m_Points[ 0 ].size( ),
66 std::numeric_limits< double >::max( )
68 if( this->m_Points[ 1 ].size( ) < other->m_Points[ 1 ].size( ) )
69 this->m_Points[ 1 ].resize(
70 other->m_Points[ 1 ].size( ),
71 -std::numeric_limits< double >::max( )
73 for( unsigned int d = 0; d < this->m_Points[ 0 ].size( ); ++d )
74 if( other->m_Points[ 0 ][ d ] < this->m_Points[ 0 ][ d ] )
75 this->m_Points[ 0 ][ d ] = other->m_Points[ 0 ][ d ];
76 for( unsigned int d = 0; d < this->m_Points[ 1 ].size( ); ++d )
77 if( other->m_Points[ 1 ][ d ] > this->m_Points[ 1 ][ d ] )
78 this->m_Points[ 1 ][ d ] = other->m_Points[ 1 ][ d ];
82 // -------------------------------------------------------------------------
83 cpPlugins::BoundingBox::
87 this->m_Points[ 0 ].push_back( double( 0 ) );
88 this->m_Points[ 1 ].push_back( double( 0 ) );
91 // -------------------------------------------------------------------------
92 cpPlugins::BoundingBox::