#include #ifdef cpExtensions_QT4 #include #include #include #include #include // ------------------------------------------------------------------------- cpExtensions::QT::RendererWidget:: RendererWidget( QWidget* parent, Qt::WindowFlags f ) : Superclass( parent, f ) { this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( ); this->GetRenderWindow( )->AddRenderer( this->m_Renderer ); vtkAxesActor* axes = vtkAxesActor::New( ); axes->AxisLabelsOff( ); this->m_Marker = vtkSmartPointer< vtkOrientationMarkerWidget >::New( ); this->m_Marker->SetOutlineColor( 1, 1, 1 ); this->m_Marker->SetOrientationMarker( axes ); this->m_Marker->SetInteractor( this->GetRenderWindow( )->GetInteractor( ) ); this->m_Marker->EnabledOn( ); this->m_Marker->InteractiveOff( ); axes->Delete( ); this->SetQuadrant( 0 ); } // ------------------------------------------------------------------------- cpExtensions::QT::RendererWidget:: ~RendererWidget( ) { } // ------------------------------------------------------------------------- int cpExtensions::QT::RendererWidget:: GetQuadrant( ) const { return( this->m_Quadrant ); } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: SetQuadrant( int q ) { this->m_Quadrant = ( q - 1 ) % 4; if( this->m_Quadrant == 0 ) this->m_Marker->SetViewport( 0.85, 0.00, 1.00, 0.15 ); else if( this->m_Quadrant == 1 ) this->m_Marker->SetViewport( 0.00, 0.00, 0.15, 0.15 ); else if( this->m_Quadrant == 2 ) this->m_Marker->SetViewport( 0.00, 0.85, 0.15, 1.00 ); else if( this->m_Quadrant == 3 ) this->m_Marker->SetViewport( 0.85, 0.85, 1.00, 1.00 ); } // ------------------------------------------------------------------------- vtkRenderer* cpExtensions::QT::RendererWidget:: GetRenderer( ) { return( this->m_Renderer ); } // ------------------------------------------------------------------------- const vtkRenderer* cpExtensions::QT::RendererWidget:: GetRenderer( ) const { return( this->m_Renderer ); } // ------------------------------------------------------------------------- vtkInteractorStyle* cpExtensions::QT::RendererWidget:: GetStyle( ) { return( dynamic_cast< vtkInteractorStyle* >( this->GetInteractor( )->GetInteractorStyle( ) ) ); } // ------------------------------------------------------------------------- const vtkInteractorStyle* cpExtensions::QT::RendererWidget:: GetStyle( ) const { // Ugly, but necessary :-( Self* self = const_cast< Self* >( this ); if( self != NULL ) return( dynamic_cast< const vtkInteractorStyle* >( self->GetInteractor( )->GetInteractorStyle( ) ) ); else return( NULL ); } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: SetStyle( vtkInteractorStyle* style ) { this->GetInteractor( )->SetInteractorStyle( style ); } // ------------------------------------------------------------------------- vtkCamera* cpExtensions::QT::RendererWidget:: GetActiveCamera( ) { return( this->m_Renderer->GetActiveCamera( ) ); } // ------------------------------------------------------------------------- const vtkCamera* cpExtensions::QT::RendererWidget:: GetActiveCamera( ) const { return( this->m_Renderer->GetActiveCamera( ) ); } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: 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 } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: AddViewProps( vtkPropCollection* props, const std::string& name ) { if( props != NULL ) { if( this->m_ViewProps.find( name ) == this->m_ViewProps.end( ) ) { this->m_ViewProps[ name ] = props; props->InitTraversal( ); while( vtkProp* p = props->GetNextProp( ) ) this->m_Renderer->AddViewProp( p ); } // fi } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: 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 } // fi } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: AddAuxViewProps( vtkPropCollection* props, const std::string& name ) { props->InitTraversal( ); while( auto p = props->GetNextProp( ) ) this->AddAuxViewProp( p, name ); } // ------------------------------------------------------------------------- vtkPropCollection* cpExtensions::QT::RendererWidget:: GetViewProps( const std::string& name ) { auto i = this->m_ViewProps.find( name ); if( i != this->m_ViewProps.end( ) ) return( i->second ); else return( NULL ); } // ------------------------------------------------------------------------- const vtkPropCollection* cpExtensions::QT::RendererWidget:: GetViewProps( const std::string& name ) const { auto i = this->m_ViewProps.find( name ); if( i != this->m_ViewProps.end( ) ) return( i->second ); else return( NULL ); } // ------------------------------------------------------------------------- vtkPropCollection* cpExtensions::QT::RendererWidget:: GetAuxViewProps( const std::string& name ) { auto i = this->m_AuxViewProps.find( name ); if( i != this->m_AuxViewProps.end( ) ) return( i->second ); else return( NULL ); } // ------------------------------------------------------------------------- const vtkPropCollection* cpExtensions::QT::RendererWidget:: GetAuxViewProps( const std::string& name ) const { auto i = this->m_AuxViewProps.find( name ); if( i != this->m_AuxViewProps.end( ) ) return( i->second ); else return( NULL ); } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: 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 ); 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 } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: RemoveViewProps( ) { this->m_Renderer->RemoveAllViewProps( ); this->m_ViewProps.clear( ); this->m_AuxViewProps.clear( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: 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 } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: 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 } */ // ------------------------------------------------------------------------- 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( ); } // ------------------------------------------------------------------------- void cpExtensions::QT::RendererWidget:: Render( ) { this->GetRenderWindow( )->Render( ); } #endif // cpExtensions_QT4 // eof - $RCSfile$