]> Creatis software - cpPlugins.git/blobdiff - lib/cpExtensions/QT/RendererWidget.cxx
Start contour tracer widget debugging: change interactor style.
[cpPlugins.git] / lib / cpExtensions / QT / RendererWidget.cxx
index 5d44fcdad65aac0ebb7e96da5ee9011641e723c5..251ecea5cb82ebe6cc4e84e03e80f4dfe8b019ed 100644 (file)
@@ -3,6 +3,7 @@
 #ifdef cpExtensions_QT4
 
 #include <vtkAxesActor.h>
+#include <vtkCamera.h>
 #include <vtkInteractorStyle.h>
 #include <vtkOrientationMarkerWidget.h>
 #include <vtkRenderer.h>
@@ -74,11 +75,13 @@ GetRenderer( ) const
 vtkInteractorStyle* cpExtensions::QT::RendererWidget::
 GetStyle( )
 {
-  return(
-    dynamic_cast< vtkInteractorStyle* >(
-      this->GetInteractor( )->GetInteractorStyle( )
-      )
-    );
+  auto iren = this->GetInteractor( );
+  if( iren != NULL )
+    return(
+      dynamic_cast< vtkInteractorStyle* >( iren->GetInteractorStyle( ) )
+      );
+  else
+    return( NULL );
 }
 
 // -------------------------------------------------------------------------
@@ -88,11 +91,17 @@ GetStyle( ) const
   // Ugly, but necessary :-(
   Self* self = const_cast< Self* >( this );
   if( self != NULL )
-    return(
-      dynamic_cast< const vtkInteractorStyle* >(
-        self->GetInteractor( )->GetInteractorStyle( )
-        )
-      );
+  {
+    auto iren = self->GetInteractor( );
+    if( iren != NULL )
+      return(
+        dynamic_cast< const vtkInteractorStyle* >(
+          iren->GetInteractorStyle( )
+          )
+        );
+    else
+      return( NULL );
+  }
   else
     return( NULL );
 }
@@ -124,15 +133,14 @@ AddViewProp( vtkProp* prop, const std::string& name )
 {
   if( prop != NULL )
   {
-    if( this->m_ViewProps.find( name ) == this->m_ViewProps.end( ) )
-    {
-      vtkSmartPointer< vtkPropCollection > coll =
-        vtkSmartPointer< vtkPropCollection >::New( );
-      coll->AddItem( prop );
-      this->m_ViewProps[ name ] = coll;
-      this->m_Renderer->AddViewProp( prop );
-
-    } // fi
+    auto i = this->m_ViewProps.find( name );
+    if( i == this->m_ViewProps.end( ) )
+      i =
+        this->m_ViewProps.insert(
+          TPropCollection::value_type( name, TProps( ) )
+          ).first;
+    i->second.insert( prop );
+    this->m_Renderer->AddViewProp( prop );
 
   } // fi
 }
@@ -143,14 +151,19 @@ AddViewProps( vtkPropCollection* props, const std::string& name )
 {
   if( props != NULL )
   {
-    if( this->m_ViewProps.find( name ) == this->m_ViewProps.end( ) )
+    auto i = this->m_ViewProps.find( name );
+    if( i == this->m_ViewProps.end( ) )
+      i =
+        this->m_ViewProps.insert(
+          TPropCollection::value_type( name, TProps( ) )
+          ).first;
+    props->InitTraversal( );
+    while( vtkProp* prop = props->GetNextProp( ) )
     {
-      this->m_ViewProps[ name ] = props;
-      props->InitTraversal( );
-      while( vtkProp* p = props->GetNextProp( ) )
-        this->m_Renderer->AddViewProp( p );
+      i->second.insert( prop );
+      this->m_Renderer->AddViewProp( prop );
 
-    } // fi
+    } // elihw
 
   } // fi
 }
@@ -161,21 +174,14 @@ AddAuxViewProp( vtkProp* prop, const std::string& name )
 {
   if( prop != NULL )
   {
-    if( this->m_ViewProps.find( name ) != this->m_ViewProps.end( ) )
-    {
-      auto a = this->m_AuxViewProps.find( name );
-      vtkSmartPointer< vtkPropCollection > coll;
-      if( a == this->m_AuxViewProps.end( ) )
-      {
-        coll = vtkSmartPointer< vtkPropCollection >::New( );
-        this->m_AuxViewProps[ name ] = coll;
-      }
-      else
-        coll = a->second;
-      coll->AddItem( prop );
-      this->m_Renderer->AddViewProp( prop );
-
-    } // fi
+    auto i = this->m_AuxViewProps.find( name );
+    if( i == this->m_AuxViewProps.end( ) )
+      i =
+        this->m_AuxViewProps.insert(
+          TPropCollection::value_type( name, TProps( ) )
+          ).first;
+    i->second.insert( prop );
+    this->m_Renderer->AddViewProp( prop );
 
   } // fi
 }
@@ -184,53 +190,81 @@ AddAuxViewProp( vtkProp* prop, const std::string& name )
 void cpExtensions::QT::RendererWidget::
 AddAuxViewProps( vtkPropCollection* props, const std::string& name )
 {
-  props->InitTraversal( );
-  while( auto p = props->GetNextProp( ) )
-    this->AddAuxViewProp( p, name );
+  if( props != NULL )
+  {
+    auto i = this->m_AuxViewProps.find( name );
+    if( i == this->m_AuxViewProps.end( ) )
+      i =
+        this->m_AuxViewProps.insert(
+          TPropCollection::value_type( name, TProps( ) )
+          ).first;
+    props->InitTraversal( );
+    while( vtkProp* prop = props->GetNextProp( ) )
+    {
+      i->second.insert( prop );
+      this->m_Renderer->AddViewProp( prop );
+
+    } // elhiw
+
+  } // fi
 }
 
 // -------------------------------------------------------------------------
-vtkPropCollection* cpExtensions::QT::RendererWidget::
+cpExtensions::QT::RendererWidget::
+TProps& cpExtensions::QT::RendererWidget::
 GetViewProps( const std::string& name )
 {
+  static TProps zero;
   auto i = this->m_ViewProps.find( name );
-  if( i != this->m_ViewProps.end( ) )
-    return( i->second );
+  if( i == this->m_ViewProps.end( ) )
+  {
+    zero.clear( );
+    return( zero );
+  }
   else
-    return( NULL );
+    return( i->second );
 }
 
 // -------------------------------------------------------------------------
-const vtkPropCollection* cpExtensions::QT::RendererWidget::
+const cpExtensions::QT::RendererWidget::
+TProps& cpExtensions::QT::RendererWidget::
 GetViewProps( const std::string& name ) const
 {
+  static const TProps zero;
   auto i = this->m_ViewProps.find( name );
-  if( i != this->m_ViewProps.end( ) )
-    return( i->second );
+  if( i == this->m_ViewProps.end( ) )
+    return( zero );
   else
-    return( NULL );
+    return( i->second );
 }
 
 // -------------------------------------------------------------------------
-vtkPropCollection* cpExtensions::QT::RendererWidget::
+cpExtensions::QT::RendererWidget::
+TProps& cpExtensions::QT::RendererWidget::
 GetAuxViewProps( const std::string& name )
 {
+  static TProps zero;
   auto i = this->m_AuxViewProps.find( name );
-  if( i != this->m_AuxViewProps.end( ) )
-    return( i->second );
+  if( i == this->m_AuxViewProps.end( ) )
+  {
+    zero.clear( );
+    return( zero );
+  }
   else
-    return( NULL );
+    return( i->second );
 }
 
 // -------------------------------------------------------------------------
-const vtkPropCollection* cpExtensions::QT::RendererWidget::
+const cpExtensions::QT::RendererWidget::
+TProps& cpExtensions::QT::RendererWidget::
 GetAuxViewProps( const std::string& name ) const
 {
+  static const TProps zero;
   auto i = this->m_AuxViewProps.find( name );
-  if( i != this->m_AuxViewProps.end( ) )
-    return( i->second );
+  if( i == this->m_AuxViewProps.end( ) )
+    return( zero );
   else
-    return( NULL );
+    return( i->second );
 }
 
 // -------------------------------------------------------------------------
@@ -240,20 +274,18 @@ RemoveViewProps( const std::string& name )
   auto i = this->m_ViewProps.find( name );
   if( i != this->m_ViewProps.end( ) )
   {
-    i->second->InitTraversal( );
-    while( auto p = i->second->GetNextProp( ) )
-      this->m_Renderer->RemoveViewProp( p );
+    for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
+      this->m_Renderer->RemoveViewProp( *p );
     this->m_ViewProps.erase( i );
 
-    i = this->m_AuxViewProps.find( name );
-    if( i != this->m_AuxViewProps.end( ) )
-    {
-      i->second->InitTraversal( );
-      while( auto p = i->second->GetNextProp( ) )
-        this->m_Renderer->RemoveViewProp( p );
-      this->m_AuxViewProps.erase( i );
+  } // fi
 
-    } // fi
+  i = this->m_AuxViewProps.find( name );
+  if( i != this->m_AuxViewProps.end( ) )
+  {
+    for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
+      this->m_Renderer->RemoveViewProp( *p );
+    this->m_AuxViewProps.erase( i );
 
   } // fi
 }
@@ -273,21 +305,12 @@ HideViewProps( const std::string& name )
 {
   auto i = this->m_ViewProps.find( name );
   if( i != this->m_ViewProps.end( ) )
-  {
-    i->second->InitTraversal( );
-    while( auto p = i->second->GetNextProp( ) )
-      p->VisibilityOff( );
-
-    i = this->m_AuxViewProps.find( name );
-    if( i != this->m_AuxViewProps.end( ) )
-    {
-      i->second->InitTraversal( );
-      while( auto p = i->second->GetNextProp( ) )
-        p->VisibilityOff( );
-
-    } // fi
-
-  } // fi
+    for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
+      ( *p )->VisibilityOff( );
+  i = this->m_AuxViewProps.find( name );
+  if( i != this->m_AuxViewProps.end( ) )
+    for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
+      ( *p )->VisibilityOff( );
 }
 
 // -------------------------------------------------------------------------
@@ -296,178 +319,18 @@ ShowViewProps( const std::string& name )
 {
   auto i = this->m_ViewProps.find( name );
   if( i != this->m_ViewProps.end( ) )
-  {
-    i->second->InitTraversal( );
-    while( auto p = i->second->GetNextProp( ) )
-      p->VisibilityOn( );
-
-    i = this->m_AuxViewProps.find( name );
-    if( i != this->m_AuxViewProps.end( ) )
-    {
-      i->second->InitTraversal( );
-      while( auto p = i->second->GetNextProp( ) )
-        p->VisibilityOn( );
-
-    } // fi
-
-  } // fi
-}
-
-
-/*
-// -------------------------------------------------------------------------
-const cpExtensions::QT::RendererWidget::
-TNamedActors& cpExtensions::QT::RendererWidget::
-GetNamedActors( ) const
-{
-  return( this->m_NamedActors );
-}
-
-// -------------------------------------------------------------------------
-cpExtensions::QT::RendererWidget::
-TProps& cpExtensions::QT::RendererWidget::
-GetViewProps( const std::string& name )
-{
-  static TProps empty;
-  auto i = this->m_NamedActors.find( name );
-  if( i == this->m_NamedActors.end( ) )
-  {
-    empty = NULL;
-    return( empty );
-  }
-  else
-    return( i->second );
-}
-
-// -------------------------------------------------------------------------
-const cpExtensions::QT::RendererWidget::
-TProps& cpExtensions::QT::RendererWidget::
-GetViewProps( const std::string& name ) const
-{
-  static const TProps empty = NULL;
-  auto i = this->m_NamedActors.find( name );
-  if( i == this->m_NamedActors.end( ) )
-    return( empty );
-  else
-    return( i->second );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::RendererWidget::
-AddViewProp( vtkProp* prop, const std::string& name )
-{
-  if( this->m_NamedActors.find( name ) == this->m_NamedActors.end( ) )
-  {
-    TProps coll = TProps::New( );
-    coll->AddItem( prop );
-    this->m_NamedActors[ name ] = coll;
-    this->m_Renderer->AddViewProp( prop );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::RendererWidget::
-AddViewProps( vtkPropCollection* coll, const std::string& name )
-{
-  if( this->m_NamedActors.find( name ) == this->m_NamedActors.end( ) )
-  {
-    this->m_NamedActors[ name ] = coll;
-    coll->InitTraversal( );
-    while( vtkProp* prop = coll->GetNextProp( ) )
-      this->m_Renderer->AddViewProp( prop );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::RendererWidget::
-RemoveViewProps( )
-{
-  this->m_Renderer->RemoveAllViewProps( );
-  this->m_NamedActors.clear( );
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::RendererWidget::
-RemoveViewProps( const std::string& name )
-{
-  auto a = this->m_NamedActors.find( name );
-  if( a != this->m_NamedActors.end( ) )
-  {
-    a->second->InitTraversal( );
-    while( vtkProp* prop = a->second->GetNextProp( ) )
-      this->m_Renderer->RemoveViewProp( prop );
-    this->m_NamedActors.erase( a );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::RendererWidget::
-HideViewProps( const std::string& name )
-{
-  auto a = this->m_NamedActors.find( name );
-  if( a != this->m_NamedActors.end( ) )
-  {
-    a->second->InitTraversal( );
-    while( vtkProp* prop = a->second->GetNextProp( ) )
-      prop->VisibilityOff( );
-
-  } // fi
-}
-
-// -------------------------------------------------------------------------
-void cpExtensions::QT::RendererWidget::
-ShowViewProps( const std::string& name )
-{
-  auto a = this->m_NamedActors.find( name );
-  if( a != this->m_NamedActors.end( ) )
-  {
-    a->second->InitTraversal( );
-    while( vtkProp* prop = a->second->GetNextProp( ) )
-      prop->VisibilityOn( );
-
-  } // fi
+    for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
+      ( *p )->VisibilityOn( );
+  i = this->m_AuxViewProps.find( name );
+  if( i != this->m_AuxViewProps.end( ) )
+    for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
+      ( *p )->VisibilityOn( );
 }
-*/
 
 // -------------------------------------------------------------------------
 void cpExtensions::QT::RendererWidget::
 ResetCamera( )
 {
-  /* TODO
-     double bounds[ 6 ] = { 0, 1, 0, 1, 0, 1 };
-     double b[ 6 ];
-     bool start = true;
-     for(
-     auto props = this->m_ViewProps.begin( );
-     props != this->m_ViewProps.end( );
-     ++props
-     )
-     {
-     props->second->InitTraversal( );
-     while(
-     auto prop = dynamic_cast< vtkProp3D* >( props->second->GetNextProp( ) )
-     )
-     {
-     if( !start )
-     {
-     prop->GetBounds( b );
-     bounds[ 0 ] = ( b[ 0 ] < bounds[ 0 ] )? b[ 0 ]: bounds[ 0 ];
-     bounds[ 1 ] = ( bounds[ 1 ] < b[ 1 ] )? b[ 1 ]: bounds[ 1 ];
-     bounds[ 2 ] = ( b[ 2 ] < bounds[ 2 ] )? b[ 2 ]: bounds[ 2 ];
-     bounds[ 3 ] = ( bounds[ 3 ] < b[ 3 ] )? b[ 3 ]: bounds[ 3 ];
-     bounds[ 4 ] = ( b[ 4 ] < bounds[ 4 ] )? b[ 4 ]: bounds[ 4 ];
-     bounds[ 5 ] = ( bounds[ 5 ] < b[ 5 ] )? b[ 5 ]: bounds[ 5 ];
-     }
-     else
-     prop->GetBounds( bounds );
-
-     } // elihw
-
-     } // rof
-  */
   this->m_Renderer->ResetCamera( );
 }