]> Creatis software - cpPlugins.git/blob - lib/cpPlugins/BoundingBox.cxx
...
[cpPlugins.git] / lib / cpPlugins / BoundingBox.cxx
1 #include <cpPlugins/BoundingBox.h>
2 #include <limits>
3 #include <vtkDataSet.h>
4
5 // -------------------------------------------------------------------------
6 void cpPlugins::BoundingBox::
7 SetDataObject( DataObject* o )
8 {
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 );
13 }
14
15 // -------------------------------------------------------------------------
16 void cpPlugins::BoundingBox::
17 SetITK( itk::LightObject* o )
18 {
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 );
27 }
28
29 // -------------------------------------------------------------------------
30 void cpPlugins::BoundingBox::
31 SetVTK( vtkObjectBase* o )
32 {
33   auto ds = dynamic_cast< vtkDataSet* >( o );
34   if( ds != NULL )
35   {
36     double bounds[ 6 ];
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 ] );
46
47   } // fi
48 }
49
50 // -------------------------------------------------------------------------
51 void cpPlugins::BoundingBox::
52 Copy( Self* other )
53 {
54   this->m_Points[ 0 ] = other->m_Points[ 0 ];
55   this->m_Points[ 1 ] = other->m_Points[ 1 ];
56   this->Modified( );
57 }
58
59 // -------------------------------------------------------------------------
60 void cpPlugins::BoundingBox::
61 Blend( Self* other )
62 {
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( )
67       );
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( )
72       );
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 ];
79   this->Modified( );
80 }
81
82 // -------------------------------------------------------------------------
83 cpPlugins::BoundingBox::
84 BoundingBox( )
85   : Superclass( )
86 {
87   this->m_Points[ 0 ].push_back( double( 0 ) );
88   this->m_Points[ 1 ].push_back( double( 0 ) );
89 }
90
91 // -------------------------------------------------------------------------
92 cpPlugins::BoundingBox::
93 ~BoundingBox( )
94 {
95 }
96
97 // eof - $RCSfile$