]> Creatis software - cpPlugins.git/blobdiff - lib/cpPlugins/BoundingBox.cxx
..
[cpPlugins.git] / lib / cpPlugins / BoundingBox.cxx
diff --git a/lib/cpPlugins/BoundingBox.cxx b/lib/cpPlugins/BoundingBox.cxx
new file mode 100644 (file)
index 0000000..14f48f4
--- /dev/null
@@ -0,0 +1,97 @@
+#include <cpPlugins/BoundingBox.h>
+#include <limits>
+#include <vtkDataSet.h>
+
+// -------------------------------------------------------------------------
+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$