1 #include <cpExtensions/QT/RendererWidget.h>
3 #ifdef cpExtensions_QT4
5 #include <vtkAxesActor.h>
7 #include <vtkInteractorStyle.h>
8 #include <vtkOrientationMarkerWidget.h>
9 #include <vtkRenderer.h>
10 #include <vtkRenderWindow.h>
12 // -------------------------------------------------------------------------
13 cpExtensions::QT::RendererWidget::
14 RendererWidget( QWidget* parent, Qt::WindowFlags f )
15 : Superclass( parent, f )
17 this->m_Renderer = vtkSmartPointer< vtkRenderer >::New( );
18 this->GetRenderWindow( )->AddRenderer( this->m_Renderer );
20 vtkAxesActor* axes = vtkAxesActor::New( );
21 axes->AxisLabelsOff( );
22 this->m_Marker = vtkSmartPointer< vtkOrientationMarkerWidget >::New( );
23 this->m_Marker->SetOutlineColor( 1, 1, 1 );
24 this->m_Marker->SetOrientationMarker( axes );
25 this->m_Marker->SetInteractor( this->GetRenderWindow( )->GetInteractor( ) );
26 this->m_Marker->EnabledOn( );
27 this->m_Marker->InteractiveOff( );
29 this->SetQuadrant( 0 );
32 // -------------------------------------------------------------------------
33 cpExtensions::QT::RendererWidget::
38 // -------------------------------------------------------------------------
39 int cpExtensions::QT::RendererWidget::
42 return( this->m_Quadrant );
45 // -------------------------------------------------------------------------
46 void cpExtensions::QT::RendererWidget::
49 this->m_Quadrant = ( q - 1 ) % 4;
50 if( this->m_Quadrant == 0 )
51 this->m_Marker->SetViewport( 0.85, 0.00, 1.00, 0.15 );
52 else if( this->m_Quadrant == 1 )
53 this->m_Marker->SetViewport( 0.00, 0.00, 0.15, 0.15 );
54 else if( this->m_Quadrant == 2 )
55 this->m_Marker->SetViewport( 0.00, 0.85, 0.15, 1.00 );
56 else if( this->m_Quadrant == 3 )
57 this->m_Marker->SetViewport( 0.85, 0.85, 1.00, 1.00 );
60 // -------------------------------------------------------------------------
61 vtkRenderer* cpExtensions::QT::RendererWidget::
64 return( this->m_Renderer );
67 // -------------------------------------------------------------------------
68 const vtkRenderer* cpExtensions::QT::RendererWidget::
71 return( this->m_Renderer );
74 // -------------------------------------------------------------------------
75 vtkInteractorStyle* cpExtensions::QT::RendererWidget::
78 auto iren = this->GetInteractor( );
81 dynamic_cast< vtkInteractorStyle* >( iren->GetInteractorStyle( ) )
87 // -------------------------------------------------------------------------
88 const vtkInteractorStyle* cpExtensions::QT::RendererWidget::
91 // Ugly, but necessary :-(
92 Self* self = const_cast< Self* >( this );
95 auto iren = self->GetInteractor( );
98 dynamic_cast< const vtkInteractorStyle* >(
99 iren->GetInteractorStyle( )
109 // -------------------------------------------------------------------------
110 void cpExtensions::QT::RendererWidget::
111 SetStyle( vtkInteractorStyle* style )
113 this->GetInteractor( )->SetInteractorStyle( style );
116 // -------------------------------------------------------------------------
117 vtkCamera* cpExtensions::QT::RendererWidget::
120 return( this->m_Renderer->GetActiveCamera( ) );
123 // -------------------------------------------------------------------------
124 const vtkCamera* cpExtensions::QT::RendererWidget::
125 GetActiveCamera( ) const
127 return( this->m_Renderer->GetActiveCamera( ) );
130 // -------------------------------------------------------------------------
131 void cpExtensions::QT::RendererWidget::
132 AddViewProp( vtkProp* prop, const std::string& name )
136 auto i = this->m_ViewProps.find( name );
137 if( i == this->m_ViewProps.end( ) )
139 this->m_ViewProps.insert(
140 TPropCollection::value_type( name, TProps( ) )
142 i->second.insert( prop );
143 this->m_Renderer->AddViewProp( prop );
148 // -------------------------------------------------------------------------
149 void cpExtensions::QT::RendererWidget::
150 AddViewProps( vtkPropCollection* props, const std::string& name )
154 auto i = this->m_ViewProps.find( name );
155 if( i == this->m_ViewProps.end( ) )
157 this->m_ViewProps.insert(
158 TPropCollection::value_type( name, TProps( ) )
160 props->InitTraversal( );
161 while( vtkProp* prop = props->GetNextProp( ) )
163 i->second.insert( prop );
164 this->m_Renderer->AddViewProp( prop );
171 // -------------------------------------------------------------------------
172 void cpExtensions::QT::RendererWidget::
173 AddAuxViewProp( vtkProp* prop, const std::string& name )
177 auto i = this->m_AuxViewProps.find( name );
178 if( i == this->m_AuxViewProps.end( ) )
180 this->m_AuxViewProps.insert(
181 TPropCollection::value_type( name, TProps( ) )
183 i->second.insert( prop );
184 this->m_Renderer->AddViewProp( prop );
189 // -------------------------------------------------------------------------
190 void cpExtensions::QT::RendererWidget::
191 AddAuxViewProps( vtkPropCollection* props, const std::string& name )
195 auto i = this->m_AuxViewProps.find( name );
196 if( i == this->m_AuxViewProps.end( ) )
198 this->m_AuxViewProps.insert(
199 TPropCollection::value_type( name, TProps( ) )
201 props->InitTraversal( );
202 while( vtkProp* prop = props->GetNextProp( ) )
204 i->second.insert( prop );
205 this->m_Renderer->AddViewProp( prop );
212 // -------------------------------------------------------------------------
213 cpExtensions::QT::RendererWidget::
214 TProps& cpExtensions::QT::RendererWidget::
215 GetViewProps( const std::string& name )
218 auto i = this->m_ViewProps.find( name );
219 if( i == this->m_ViewProps.end( ) )
228 // -------------------------------------------------------------------------
229 const cpExtensions::QT::RendererWidget::
230 TProps& cpExtensions::QT::RendererWidget::
231 GetViewProps( const std::string& name ) const
233 static const TProps zero;
234 auto i = this->m_ViewProps.find( name );
235 if( i == this->m_ViewProps.end( ) )
241 // -------------------------------------------------------------------------
242 cpExtensions::QT::RendererWidget::
243 TProps& cpExtensions::QT::RendererWidget::
244 GetAuxViewProps( const std::string& name )
247 auto i = this->m_AuxViewProps.find( name );
248 if( i == this->m_AuxViewProps.end( ) )
257 // -------------------------------------------------------------------------
258 const cpExtensions::QT::RendererWidget::
259 TProps& cpExtensions::QT::RendererWidget::
260 GetAuxViewProps( const std::string& name ) const
262 static const TProps zero;
263 auto i = this->m_AuxViewProps.find( name );
264 if( i == this->m_AuxViewProps.end( ) )
270 // -------------------------------------------------------------------------
271 void cpExtensions::QT::RendererWidget::
272 RemoveViewProps( const std::string& name )
274 auto i = this->m_ViewProps.find( name );
275 if( i != this->m_ViewProps.end( ) )
277 for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
278 this->m_Renderer->RemoveViewProp( *p );
279 this->m_ViewProps.erase( i );
283 i = this->m_AuxViewProps.find( name );
284 if( i != this->m_AuxViewProps.end( ) )
286 for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
287 this->m_Renderer->RemoveViewProp( *p );
288 this->m_AuxViewProps.erase( i );
293 // -------------------------------------------------------------------------
294 void cpExtensions::QT::RendererWidget::
297 this->m_Renderer->RemoveAllViewProps( );
298 this->m_ViewProps.clear( );
299 this->m_AuxViewProps.clear( );
302 // -------------------------------------------------------------------------
303 void cpExtensions::QT::RendererWidget::
304 HideViewProps( const std::string& name )
306 auto i = this->m_ViewProps.find( name );
307 if( i != this->m_ViewProps.end( ) )
308 for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
309 ( *p )->VisibilityOff( );
310 i = this->m_AuxViewProps.find( name );
311 if( i != this->m_AuxViewProps.end( ) )
312 for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
313 ( *p )->VisibilityOff( );
316 // -------------------------------------------------------------------------
317 void cpExtensions::QT::RendererWidget::
318 ShowViewProps( const std::string& name )
320 auto i = this->m_ViewProps.find( name );
321 if( i != this->m_ViewProps.end( ) )
322 for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
323 ( *p )->VisibilityOn( );
324 i = this->m_AuxViewProps.find( name );
325 if( i != this->m_AuxViewProps.end( ) )
326 for( auto p = i->second.begin( ); p != i->second.end( ); ++p )
327 ( *p )->VisibilityOn( );
330 // -------------------------------------------------------------------------
331 void cpExtensions::QT::RendererWidget::
334 this->m_Renderer->ResetCamera( );
337 // -------------------------------------------------------------------------
338 void cpExtensions::QT::RendererWidget::
341 this->GetRenderWindow( )->Render( );
344 #endif // cpExtensions_QT4