1 // Copyright (C) 2005 OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/
19 #include "VTKViewer_ViewWindow.h"
20 #include "VTKViewer_ViewModel.h"
21 #include "VTKViewer_RenderWindow.h"
22 #include "VTKViewer_RenderWindowInteractor.h"
23 #include "VTKViewer_InteractorStyle.h"
24 #include "VTKViewer_Trihedron.h"
25 #include "VTKViewer_Transform.h"
26 #include "VTKViewer_Utilities.h"
28 #include "SUIT_Session.h"
29 #include "SUIT_ToolButton.h"
30 #include "SUIT_MessageBox.h"
32 #include "SUIT_Tools.h"
33 #include "SUIT_ResourceMgr.h"
35 #include <qapplication.h>
38 #include <vtkRenderer.h>
39 #include <vtkCamera.h>
42 VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop,
43 VTKViewer_Viewer* theModel,
44 VTKViewer_InteractorStyle* iStyle,
45 VTKViewer_RenderWindowInteractor* rw )
46 : SUIT_ViewWindow( theDesktop )
50 myTrihedron = VTKViewer_Trihedron::New();
51 myTransform = VTKViewer_Transform::New();
52 myRenderer = vtkRenderer::New() ;
54 myTrihedron->AddToRender( myRenderer );
56 myRenderWindow = new VTKViewer_RenderWindow( this, "RenderWindow" );
57 setCentralWidget(myRenderWindow);
58 myRenderWindow->setFocusPolicy( StrongFocus );
59 myRenderWindow->setFocus();
61 myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
63 myRenderer->GetActiveCamera()->ParallelProjectionOn();
64 myRenderer->LightFollowCameraOn();
65 myRenderer->TwoSidedLightingOn();
67 // Set BackgroundColor
68 QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed");
69 QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen");
70 QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue");
72 if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() )
73 myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
75 myRenderer->SetBackground( 0, 0, 0 );
77 // Create an interactor.
78 myRWInteractor = rw ? rw : VTKViewer_RenderWindowInteractor::New();
79 myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
81 VTKViewer_InteractorStyle* RWS = iStyle ? iStyle : VTKViewer_InteractorStyle::New();
82 RWS->setGUIWindow( myRenderWindow );
83 myRWInteractor->SetInteractorStyle( RWS );
85 myRWInteractor->Initialize();
86 RWS->setTriedron( myTrihedron );
87 RWS->FindPokedRenderer( 0, 0 );
89 setCentralWidget( myRenderWindow );
91 myToolBar = new QToolBar(this);
92 myToolBar->setCloseMode(QDockWindow::Undocked);
93 myToolBar->setLabel(tr("LBL_TOOLBAR_LABEL"));
98 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
99 this, SLOT(onKeyPressed( QKeyEvent* )) );
100 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
101 this, SLOT(onKeyReleased( QKeyEvent* )) );
102 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
103 this, SLOT(onMousePressed( QMouseEvent* )) );
104 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
105 this, SLOT(onMouseReleased( QMouseEvent* )) );
106 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
107 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
108 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
109 this, SLOT(onMouseMoving( QMouseEvent* )) );
110 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
111 myRenderWindow, SLOT(update()) );
113 connect( myRenderWindow, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
114 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
116 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
117 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
124 VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
126 myTransform->Delete();
127 // In order to ensure that the interactor unregisters
128 // this RenderWindow, we assign a NULL RenderWindow to
129 // it before deleting it.
130 myRWInteractor->SetRenderWindow( NULL );
131 myRWInteractor->Delete();
134 myRenderer->RemoveAllProps();
135 //m_Renderer->Delete() ;
136 myTrihedron->Delete();
139 /*!Checks: is trihedron displayed.*/
140 bool VTKViewer_ViewWindow::isTrihedronDisplayed(){
141 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
144 /*!Activates 'zooming' transformation*/
145 void VTKViewer_ViewWindow::activateZoom()
147 myRWInteractor->GetInteractorStyle()->startZoom();
150 /*!Activates 'panning' transformation*/
151 void VTKViewer_ViewWindow::activatePanning()
153 myRWInteractor->GetInteractorStyle()->startPan();
156 /*!Activates 'rotation' transformation*/
157 void VTKViewer_ViewWindow::activateRotation()
159 myRWInteractor->GetInteractorStyle()->startRotate();
162 /*!Activate global panning.*/
163 void VTKViewer_ViewWindow::activateGlobalPanning()
165 //if(myTrihedron->GetVisibleActorCount(myRenderer))
166 myRWInteractor->GetInteractorStyle()->startGlobalPan();
169 /*!Activates 'fit area' transformation*/
170 void VTKViewer_ViewWindow::activateWindowFit()
172 myRWInteractor->GetInteractorStyle()->startFitArea();
176 void VTKViewer_ViewWindow::createActions()
178 if (!myActionsMap.isEmpty()) return;
180 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
185 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
186 tr( "MNU_DUMP_VIEW" ), 0, this);
187 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
188 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
189 myActionsMap[ DumpId ] = aAction;
192 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
193 tr( "MNU_FITALL" ), 0, this);
194 aAction->setStatusTip(tr("DSC_FITALL"));
195 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
196 myActionsMap[ FitAllId ] = aAction;
199 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
200 tr( "MNU_FITRECT" ), 0, this);
201 aAction->setStatusTip(tr("DSC_FITRECT"));
202 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
203 myActionsMap[ FitRectId ] = aAction;
206 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
207 tr( "MNU_ZOOM_VIEW" ), 0, this);
208 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
209 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
210 myActionsMap[ ZoomId ] = aAction;
213 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
214 tr( "MNU_PAN_VIEW" ), 0, this);
215 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
216 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
217 myActionsMap[ PanId ] = aAction;
219 //! \li Global Panning
220 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
221 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
222 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
223 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
224 myActionsMap[ GlobalPanId ] = aAction;
227 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
228 tr( "MNU_ROTATE_VIEW" ), 0, this);
229 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
230 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
231 myActionsMap[ RotationId ] = aAction;
234 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
235 tr( "MNU_FRONT_VIEW" ), 0, this);
236 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
237 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
238 myActionsMap[ FrontId ] = aAction;
241 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
242 tr( "MNU_BACK_VIEW" ), 0, this);
243 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
244 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
245 myActionsMap[ BackId ] = aAction;
248 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
249 tr( "MNU_TOP_VIEW" ), 0, this);
250 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
251 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
252 myActionsMap[ TopId ] = aAction;
255 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
256 tr( "MNU_BOTTOM_VIEW" ), 0, this);
257 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
258 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
259 myActionsMap[ BottomId ] = aAction;
262 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
263 tr( "MNU_LEFT_VIEW" ), 0, this);
264 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
265 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
266 myActionsMap[ LeftId ] = aAction;
269 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
270 tr( "MNU_RIGHT_VIEW" ), 0, this);
271 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
272 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
273 myActionsMap[ RightId ] = aAction;
276 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
277 tr( "MNU_RESET_VIEW" ), 0, this);
278 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
279 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
280 myActionsMap[ ResetId ] = aAction;
282 //! \li Trihedron shown
283 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
284 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
285 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
286 connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
287 myActionsMap[ TrihedronShowId ] = aAction;
290 /*!Create tool bar.*/
291 void VTKViewer_ViewWindow::createToolBar()
293 myActionsMap[DumpId]->addTo(myToolBar);
294 myActionsMap[TrihedronShowId]->addTo(myToolBar);
296 SUIT_ToolButton* aScaleBtn = new SUIT_ToolButton(myToolBar);
297 aScaleBtn->AddAction(myActionsMap[FitAllId]);
298 aScaleBtn->AddAction(myActionsMap[FitRectId]);
299 aScaleBtn->AddAction(myActionsMap[ZoomId]);
301 SUIT_ToolButton* aPanningBtn = new SUIT_ToolButton(myToolBar);
302 aPanningBtn->AddAction(myActionsMap[PanId]);
303 aPanningBtn->AddAction(myActionsMap[GlobalPanId]);
305 myActionsMap[RotationId]->addTo(myToolBar);
307 SUIT_ToolButton* aViewsBtn = new SUIT_ToolButton(myToolBar);
308 aViewsBtn->AddAction(myActionsMap[FrontId]);
309 aViewsBtn->AddAction(myActionsMap[BackId]);
310 aViewsBtn->AddAction(myActionsMap[TopId]);
311 aViewsBtn->AddAction(myActionsMap[BottomId]);
312 aViewsBtn->AddAction(myActionsMap[LeftId]);
313 aViewsBtn->AddAction(myActionsMap[RightId]);
315 myActionsMap[ResetId]->addTo(myToolBar);
318 /*!On front view event.*/
319 void VTKViewer_ViewWindow::onFrontView()
321 vtkCamera* camera = myRenderer->GetActiveCamera();
322 camera->SetPosition(1,0,0);
323 camera->SetViewUp(0,0,1);
324 camera->SetFocalPoint(0,0,0);
328 /*!On back view slot.*/
329 void VTKViewer_ViewWindow::onBackView()
331 vtkCamera* camera = myRenderer->GetActiveCamera();
332 camera->SetPosition(-1,0,0);
333 camera->SetViewUp(0,0,1);
334 camera->SetFocalPoint(0,0,0);
338 /*!On back view slot.*/
339 void VTKViewer_ViewWindow::onTopView()
341 vtkCamera* camera = myRenderer->GetActiveCamera();
342 camera->SetPosition(0,0,1);
343 camera->SetViewUp(0,1,0);
344 camera->SetFocalPoint(0,0,0);
348 /*!On bottom view slot.*/
349 void VTKViewer_ViewWindow::onBottomView()
351 vtkCamera* camera = myRenderer->GetActiveCamera();
352 camera->SetPosition(0,0,-1);
353 camera->SetViewUp(0,1,0);
354 camera->SetFocalPoint(0,0,0);
358 /*!On left view slot.*/
359 void VTKViewer_ViewWindow::onLeftView()
361 vtkCamera* camera = myRenderer->GetActiveCamera();
362 camera->SetPosition(0,-1,0);
363 camera->SetViewUp(0,0,1);
364 camera->SetFocalPoint(0,0,0);
368 /*!On right view slot.*/
369 void VTKViewer_ViewWindow::onRightView()
371 vtkCamera* camera = myRenderer->GetActiveCamera();
372 camera->SetPosition(0,1,0);
373 camera->SetViewUp(0,0,1);
374 camera->SetFocalPoint(0,0,0);
378 /*!On reset view slot.*/
379 void VTKViewer_ViewWindow::onResetView()
381 int aTriedronIsVisible = isTrihedronDisplayed();
382 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
383 ::ResetCamera(myRenderer,true);
384 vtkCamera* aCamera = myRenderer->GetActiveCamera();
385 aCamera->SetPosition(1,-1,1);
386 aCamera->SetViewUp(0,0,1);
387 ::ResetCamera(myRenderer,true);
388 if(aTriedronIsVisible) myTrihedron->VisibilityOn();
389 else myTrihedron->VisibilityOff();
390 static vtkFloatingPointType aCoeff = 3.0;
391 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
395 /*!On fit all slot.*/
396 void VTKViewer_ViewWindow::onFitAll()
398 myRWInteractor->GetInteractorStyle()->ViewFitAll();
402 /*!Set background of the viewport*/
403 void VTKViewer_ViewWindow::setBackgroundColor( const QColor& color )
406 myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. );
409 /*!Returns background of the viewport*/
410 QColor VTKViewer_ViewWindow::backgroundColor() const
412 vtkFloatingPointType backint[3];
414 myRenderer->GetBackground( backint );
415 return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255));
417 return SUIT_ViewWindow::backgroundColor();
420 /*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/
421 void VTKViewer_ViewWindow::Repaint(bool theUpdateTrihedron)
423 if (theUpdateTrihedron) onAdjustTrihedron();
424 myRenderWindow->update();
427 /*!Get scale of transformation filter.*/
428 void VTKViewer_ViewWindow::GetScale( double theScale[3] ) {
429 myTransform->GetScale( theScale );
432 /*!Set scale of transformation filter and repaint window.*/
433 void VTKViewer_ViewWindow::SetScale( double theScale[3] ) {
434 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
435 myRWInteractor->Render();
439 /*!Calculation trihedron size.*/
440 void VTKViewer_ViewWindow::onAdjustTrihedron(){
441 if( !isTrihedronDisplayed() )
443 int aVisibleNum = myTrihedron->GetVisibleActorCount(myRenderer);
445 // calculating diagonal of visible props of the renderer
446 vtkFloatingPointType bnd[6];
447 myTrihedron->VisibilityOff();
448 ::ComputeVisiblePropBounds(myRenderer,bnd);
449 myTrihedron->VisibilityOn();
450 vtkFloatingPointType aLength = 0;
451 static bool CalcByDiag = false;
453 aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
454 (bnd[3]-bnd[2])*(bnd[3]-bnd[2])+
455 (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
457 aLength = bnd[1]-bnd[0];
458 aLength = max((bnd[3]-bnd[2]),aLength);
459 aLength = max((bnd[5]-bnd[4]),aLength);
462 static vtkFloatingPointType aSizeInPercents = 105;
463 QString aSetting;// = SUIT_CONFIG->getSetting("Viewer:TrihedronSize");
464 if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
466 static vtkFloatingPointType EPS_SIZE = 5.0E-3;
467 vtkFloatingPointType aSize = myTrihedron->GetSize();
468 vtkFloatingPointType aNewSize = aLength*aSizeInPercents/100.0;
469 // if the new trihedron size have sufficient difference, then apply the value
470 if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){
471 myTrihedron->SetSize(aNewSize);
474 ::ResetCameraClippingRange(myRenderer);
477 /*!Emit key pressed.*/
478 void VTKViewer_ViewWindow::onKeyPressed(QKeyEvent* event)
480 emit keyPressed( this, event );
483 /*!Emit key released.*/
484 void VTKViewer_ViewWindow::onKeyReleased(QKeyEvent* event)
486 emit keyReleased( this, event );
489 /*!Emit key pressed.*/
490 void VTKViewer_ViewWindow::onMousePressed(QMouseEvent* event)
492 emit mousePressed(this, event);
495 /*!Emit mouse released.*/
496 void VTKViewer_ViewWindow::onMouseReleased(QMouseEvent* event)
498 emit mouseReleased( this, event );
501 /*!Emit mouse moving.*/
502 void VTKViewer_ViewWindow::onMouseMoving(QMouseEvent* event)
504 emit mouseMoving( this, event );
507 /*!Emit mouse double clicked.*/
508 void VTKViewer_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
510 emit mouseDoubleClicked( this, event );
513 /*!Insert actor to renderer and transformation filter.
514 *Move Internal actors, if \a theMoveInternalActors is true.
516 void VTKViewer_ViewWindow::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ){
517 theActor->AddToRender(myRenderer);
518 theActor->SetTransform(myTransform);
519 if(theMoveInternalActors)
520 myRWInteractor->MoveInternalActors();
523 /*!Add actor.Repaint window if \a theUpdate is true.
524 *@see InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors )
526 void VTKViewer_ViewWindow::AddActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
527 InsertActor(theActor);
532 /*!Remove \a theActor from renderer and pepaint, if \a theUpdate is true.*/
533 void VTKViewer_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
534 theActor->RemoveFromRender(myRenderer);
539 /*!@see RemoveActor() and InsertActor().*/
540 void VTKViewer_ViewWindow::MoveActor( VTKViewer_Actor* theActor)
542 RemoveActor(theActor);
543 InsertActor(theActor,true);
546 /*!On trihedron show slot.*/
547 void VTKViewer_ViewWindow::onTrihedronShow()
549 if (isTrihedronDisplayed())
550 myTrihedron->VisibilityOff();
552 myTrihedron->VisibilityOn();
553 myRenderWindow->update();
557 QImage VTKViewer_ViewWindow::dumpView()
559 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
560 return px.convertToImage();
563 /*! The method returns the visual parameters of this view as a formated string
565 QString VTKViewer_ViewWindow::getVisualParameters()
567 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
569 vtkCamera* camera = myRenderer->GetActiveCamera();
570 camera->GetPosition( pos );
571 camera->GetFocalPoint( focalPnt );
572 camera->GetViewUp( viewUp );
573 parScale = camera->GetParallelScale();
577 retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e",
578 pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1],
579 viewUp[2], parScale, scale[0], scale[1], scale[2] );
583 /*! The method restors visual parameters of this view from a formated string
585 void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters )
587 QStringList paramsLst = QStringList::split( '*', parameters, true );
588 if ( paramsLst.size() == 13 ) {
589 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
590 pos[0] = paramsLst[0].toDouble();
591 pos[1] = paramsLst[1].toDouble();
592 pos[2] = paramsLst[2].toDouble();
593 focalPnt[0] = paramsLst[3].toDouble();
594 focalPnt[1] = paramsLst[4].toDouble();
595 focalPnt[2] = paramsLst[5].toDouble();
596 viewUp[0] = paramsLst[6].toDouble();
597 viewUp[1] = paramsLst[7].toDouble();
598 viewUp[2] = paramsLst[8].toDouble();
599 parScale = paramsLst[9].toDouble();
600 scale[0] = paramsLst[10].toDouble();
601 scale[1] = paramsLst[11].toDouble();
602 scale[2] = paramsLst[12].toDouble();
604 vtkCamera* camera = myRenderer->GetActiveCamera();
605 camera->SetPosition( pos );
606 camera->SetFocalPoint( focalPnt );
607 camera->SetViewUp( viewUp );
608 camera->SetParallelScale( parScale );
609 myTransform->SetMatrixScale( scale[0], scale[1], scale[2] );
610 myRWInteractor->Render();