1 #include <cpPlugins/DataObjects/BoundingBox.h>
3 #include <vtkDataSet.h>
5 // -------------------------------------------------------------------------
6 void cpPlugins::DataObjects::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::DataObjects::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 );
31 // -------------------------------------------------------------------------
32 void cpPlugins::DataObjects::BoundingBox::
33 SetVTK( vtkObjectBase* o )
35 auto ds = dynamic_cast< vtkDataSet* >( o );
39 ds->GetBounds( bounds );
40 this->m_Points[ 0 ].clear( );
41 this->m_Points[ 1 ].clear( );
42 this->m_Points[ 0 ].push_back( bounds[ 0 ] );
43 this->m_Points[ 1 ].push_back( bounds[ 1 ] );
44 this->m_Points[ 0 ].push_back( bounds[ 2 ] );
45 this->m_Points[ 1 ].push_back( bounds[ 3 ] );
46 this->m_Points[ 0 ].push_back( bounds[ 4 ] );
47 this->m_Points[ 1 ].push_back( bounds[ 5 ] );
53 // -------------------------------------------------------------------------
54 void cpPlugins::DataObjects::BoundingBox::
57 this->m_Points[ 0 ] = other->m_Points[ 0 ];
58 this->m_Points[ 1 ] = other->m_Points[ 1 ];
62 // -------------------------------------------------------------------------
63 void cpPlugins::DataObjects::BoundingBox::
66 if( this->m_Points[ 0 ].size( ) < other->m_Points[ 0 ].size( ) )
67 this->m_Points[ 0 ].resize(
68 other->m_Points[ 0 ].size( ),
69 std::numeric_limits< double >::max( )
71 if( this->m_Points[ 1 ].size( ) < other->m_Points[ 1 ].size( ) )
72 this->m_Points[ 1 ].resize(
73 other->m_Points[ 1 ].size( ),
74 -std::numeric_limits< double >::max( )
76 for( unsigned int d = 0; d < this->m_Points[ 0 ].size( ); ++d )
77 if( other->m_Points[ 0 ][ d ] < this->m_Points[ 0 ][ d ] )
78 this->m_Points[ 0 ][ d ] = other->m_Points[ 0 ][ d ];
79 for( unsigned int d = 0; d < this->m_Points[ 1 ].size( ); ++d )
80 if( other->m_Points[ 1 ][ d ] > this->m_Points[ 1 ][ d ] )
81 this->m_Points[ 1 ][ d ] = other->m_Points[ 1 ][ d ];
85 // -------------------------------------------------------------------------
86 cpPlugins::DataObjects::BoundingBox::
90 this->m_Points[ 0 ].push_back( double( 0 ) );
91 this->m_Points[ 1 ].push_back( double( 0 ) );
92 this->m_Outline = vtkSmartPointer< vtkOutlineSource >::New( );
96 // -------------------------------------------------------------------------
97 cpPlugins::DataObjects::BoundingBox::
102 // -------------------------------------------------------------------------
103 void cpPlugins::DataObjects::BoundingBox::
107 double bounds[ 6 ] = { 0 };
108 unsigned int dim = this->m_Points[ 0 ].size( );
109 dim = ( this->m_Points[ 1 ].size( ) < dim )? this->m_Points[ 1 ].size( ): dim;
110 dim = ( dim < 3 )? dim: 3;
111 for( unsigned int d = 0; d < dim; ++d )
113 bounds[ d << 1 ] = this->m_Points[ 0 ][ d ];
114 bounds[ ( d << 1 ) + 1 ] = this->m_Points[ 1 ][ d ];
118 // Update vtk objects
119 this->m_Outline->SetBounds( bounds );
120 this->m_Outline->Update( );
121 this->m_VTK = this->m_Outline->GetOutput( );