]> Creatis software - cpPlugins.git/blob - lib/cpInstances/BoundingBox.cxx
7a467daf97549ca1f1e4e326aa26f9b888e56654
[cpPlugins.git] / lib / cpInstances / BoundingBox.cxx
1 #include <cpInstances/BoundingBox.h>
2 #include <limits>
3 #include <vtkDataSet.h>
4
5 // -------------------------------------------------------------------------
6 void cpInstances::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   this->_UpdateVTK( );
14 }
15
16 // -------------------------------------------------------------------------
17 void cpInstances::BoundingBox::
18 Copy( Self* other )
19 {
20   this->m_Points[ 0 ] = other->m_Points[ 0 ];
21   this->m_Points[ 1 ] = other->m_Points[ 1 ];
22   this->Modified( );
23 }
24
25 // -------------------------------------------------------------------------
26 void cpInstances::BoundingBox::
27 Blend( Self* other )
28 {
29   if( this->m_Points[ 0 ].size( ) < other->m_Points[ 0 ].size( ) )
30     this->m_Points[ 0 ].resize(
31       other->m_Points[ 0 ].size( ),
32       std::numeric_limits< double >::max( )
33       );
34   if( this->m_Points[ 1 ].size( ) < other->m_Points[ 1 ].size( ) )
35     this->m_Points[ 1 ].resize(
36       other->m_Points[ 1 ].size( ),
37       -std::numeric_limits< double >::max( )
38       );
39   for( unsigned int d = 0; d < this->m_Points[ 0 ].size( ); ++d )
40     if( other->m_Points[ 0 ][ d ] < this->m_Points[ 0 ][ d ] )
41       this->m_Points[ 0 ][ d ] = other->m_Points[ 0 ][ d ];
42   for( unsigned int d = 0; d < this->m_Points[ 1 ].size( ); ++d )
43     if( other->m_Points[ 1 ][ d ] > this->m_Points[ 1 ][ d ] )
44       this->m_Points[ 1 ][ d ] = other->m_Points[ 1 ][ d ];
45   this->Modified( );
46   this->_UpdateVTK( );
47 }
48
49 // -------------------------------------------------------------------------
50 cpInstances::BoundingBox::
51 BoundingBox( )
52   : Superclass( )
53 {
54   this->m_Points[ 0 ].push_back( double( 0 ) );
55   this->m_Points[ 1 ].push_back( double( 0 ) );
56   this->m_Outline = vtkSmartPointer< vtkOutlineSource >::New( );
57   this->_UpdateVTK( );
58 }
59
60 // -------------------------------------------------------------------------
61 cpInstances::BoundingBox::
62 ~BoundingBox( )
63 {
64 }
65
66 // -------------------------------------------------------------------------
67 void cpInstances::BoundingBox::
68 _UpdateVTK( )
69 {
70   auto dobj = this->GetVTK< vtkDataSet >( );
71   if( dobj == NULL )
72     return;
73
74   // Get bounds
75   double bounds[ 6 ];
76   dobj->GetBounds( bounds );
77
78   this->m_Points[ 0 ].clear( );
79   this->m_Points[ 1 ].clear( );
80   this->m_Points[ 0 ].push_back( bounds[ 0 ] );
81   this->m_Points[ 0 ].push_back( bounds[ 2 ] );
82   this->m_Points[ 0 ].push_back( bounds[ 4 ] );
83   this->m_Points[ 1 ].push_back( bounds[ 1 ] );
84   this->m_Points[ 1 ].push_back( bounds[ 3 ] );
85   this->m_Points[ 1 ].push_back( bounds[ 5 ] );
86
87   // Update vtk objects
88   this->m_Outline->SetBounds( bounds );
89   this->m_Outline->Update( );
90   this->m_VTK = this->m_Outline->GetOutput( );
91 }
92
93 // eof - $RCSfile$