1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "VTKViewer_ViewWindow.h"
24 #include "VTKViewer_ViewModel.h"
25 #include "VTKViewer_RenderWindow.h"
26 #include "VTKViewer_RenderWindowInteractor.h"
27 #include "VTKViewer_InteractorStyle.h"
28 #include "VTKViewer_Trihedron.h"
29 #include "VTKViewer_Transform.h"
30 #include "VTKViewer_Utilities.h"
31 #include "VTKViewer_Texture.h"
32 #include "VTKViewer_OpenGLRenderer.h"
34 #include <SUIT_Session.h>
35 #include <SUIT_MessageBox.h>
36 #include <SUIT_Tools.h>
37 #include <SUIT_ResourceMgr.h>
42 #include <vtkCamera.h>
43 #include <vtkJPEGReader.h>
44 #include <vtkBMPReader.h>
45 #include <vtkTIFFReader.h>
46 #include <vtkPNGReader.h>
47 #include <vtkMetaImageReader.h>
48 #include <vtkImageMapToColors.h>
49 #include <vtkTexture.h>
51 #include <QtxToolBar.h>
52 #include <QtxMultiAction.h>
55 VTKViewer_ViewWindow::VTKViewer_ViewWindow( SUIT_Desktop* theDesktop,
56 VTKViewer_Viewer* theModel,
57 VTKViewer_InteractorStyle* iStyle,
58 VTKViewer_RenderWindowInteractor* rw )
59 : SUIT_ViewWindow( theDesktop )
63 myTrihedron = VTKViewer_Trihedron::New();
64 myTransform = VTKViewer_Transform::New();
65 myRenderer = VTKViewer_OpenGLRenderer::New() ;
67 myTrihedron->AddToRender( myRenderer );
69 myRenderWindow = new VTKViewer_RenderWindow( this, "RenderWindow" );
70 setCentralWidget(myRenderWindow);
71 myRenderWindow->setFocusPolicy( Qt::StrongFocus );
72 myRenderWindow->setFocus();
74 myRenderWindow->getRenderWindow()->AddRenderer( myRenderer );
76 myRenderer->GetActiveCamera()->ParallelProjectionOn();
77 myRenderer->LightFollowCameraOn();
78 myRenderer->TwoSidedLightingOn();
80 // Create an interactor.
81 myRWInteractor = rw ? rw : VTKViewer_RenderWindowInteractor::New();
82 myRWInteractor->SetRenderWindow( myRenderWindow->getRenderWindow() );
84 VTKViewer_InteractorStyle* RWS = iStyle ? iStyle : VTKViewer_InteractorStyle::New();
85 RWS->setGUIWindow( myRenderWindow );
86 myRWInteractor->SetInteractorStyle( RWS );
88 myRWInteractor->Initialize();
89 RWS->setTriedron( myTrihedron );
90 RWS->FindPokedRenderer( 0, 0 );
92 setCentralWidget( myRenderWindow );
94 myToolBar = new QtxToolBar( true, tr("LBL_TOOLBAR_LABEL"), this );
95 myToolBar->setObjectName( "VTKViewerViewOperations" );
96 myToolBar->setFloatable( false );
101 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
102 this, SLOT(onKeyPressed( QKeyEvent* )) );
103 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
104 this, SLOT(onKeyReleased( QKeyEvent* )) );
105 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
106 this, SLOT(onMousePressed( QMouseEvent* )) );
107 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
108 this, SLOT(onMouseReleased( QMouseEvent* )) );
109 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
110 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
111 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
112 this, SLOT(onMouseMoving( QMouseEvent* )) );
113 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
114 myRenderWindow, SLOT(update()) );
116 connect( myRenderWindow, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
117 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
119 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
120 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
123 // set default background
124 setBackground( Qtx::BackgroundData( Qt::black ) );
130 VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
132 myTransform->Delete();
133 // In order to ensure that the interactor unregisters
134 // this RenderWindow, we assign a NULL RenderWindow to
135 // it before deleting it.
136 myRWInteractor->SetRenderWindow( NULL );
137 myRWInteractor->Delete();
140 myRenderer->RemoveAllViewProps();
141 //m_Renderer->Delete() ;
142 myTrihedron->Delete();
145 /*!Checks: is trihedron displayed.*/
146 bool VTKViewer_ViewWindow::isTrihedronDisplayed(){
147 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
150 /*!Activates 'zooming' transformation*/
151 void VTKViewer_ViewWindow::activateZoom()
153 myRWInteractor->GetInteractorStyle()->startZoom();
156 /*!Activates 'panning' transformation*/
157 void VTKViewer_ViewWindow::activatePanning()
159 myRWInteractor->GetInteractorStyle()->startPan();
162 /*!Activates 'rotation' transformation*/
163 void VTKViewer_ViewWindow::activateRotation()
165 myRWInteractor->GetInteractorStyle()->startRotate();
168 /*!Activate global panning.*/
169 void VTKViewer_ViewWindow::activateGlobalPanning()
171 //if(myTrihedron->GetVisibleActorCount(myRenderer))
172 myRWInteractor->GetInteractorStyle()->startGlobalPan();
175 /*!Activates 'fit area' transformation*/
176 void VTKViewer_ViewWindow::activateWindowFit()
178 myRWInteractor->GetInteractorStyle()->startFitArea();
182 void VTKViewer_ViewWindow::createActions()
184 if (!myActionsMap.isEmpty()) return;
186 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
191 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
192 tr( "MNU_DUMP_VIEW" ), 0, this);
193 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
194 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
195 myActionsMap[ DumpId ] = aAction;
198 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
199 tr( "MNU_FITALL" ), 0, this);
200 aAction->setStatusTip(tr("DSC_FITALL"));
201 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
202 myActionsMap[ FitAllId ] = aAction;
205 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
206 tr( "MNU_FITRECT" ), 0, this);
207 aAction->setStatusTip(tr("DSC_FITRECT"));
208 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
209 myActionsMap[ FitRectId ] = aAction;
212 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
213 tr( "MNU_ZOOM_VIEW" ), 0, this);
214 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
215 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
216 myActionsMap[ ZoomId ] = aAction;
219 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
220 tr( "MNU_PAN_VIEW" ), 0, this);
221 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
222 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
223 myActionsMap[ PanId ] = aAction;
225 //! \li Global Panning
226 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
227 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
228 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
229 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
230 myActionsMap[ GlobalPanId ] = aAction;
233 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
234 tr( "MNU_ROTATE_VIEW" ), 0, this);
235 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
236 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
237 myActionsMap[ RotationId ] = aAction;
240 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
241 tr( "MNU_FRONT_VIEW" ), 0, this);
242 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
243 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
244 myActionsMap[ FrontId ] = aAction;
247 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
248 tr( "MNU_BACK_VIEW" ), 0, this);
249 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
250 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
251 myActionsMap[ BackId ] = aAction;
254 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
255 tr( "MNU_TOP_VIEW" ), 0, this);
256 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
257 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
258 myActionsMap[ TopId ] = aAction;
261 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
262 tr( "MNU_BOTTOM_VIEW" ), 0, this);
263 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
264 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
265 myActionsMap[ BottomId ] = aAction;
268 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
269 tr( "MNU_LEFT_VIEW" ), 0, this);
270 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
271 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
272 myActionsMap[ LeftId ] = aAction;
275 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
276 tr( "MNU_RIGHT_VIEW" ), 0, this);
277 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
278 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
279 myActionsMap[ RightId ] = aAction;
281 // \li Rotate anticlockwise
282 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
283 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this);
284 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
285 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
286 myActionsMap[ AntiClockWiseId ] = aAction;
288 // \li Rotate clockwise
289 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
290 tr( "MNU_CLOCKWISE_VIEW" ), 0, this);
291 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
292 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
293 myActionsMap[ ClockWiseId ] = aAction;
296 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
297 tr( "MNU_RESET_VIEW" ), 0, this);
298 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
299 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
300 myActionsMap[ ResetId ] = aAction;
302 //! \li Trihedron shown
303 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
304 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
305 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
306 connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
307 myActionsMap[ TrihedronShowId ] = aAction;
310 /*!Create tool bar.*/
311 void VTKViewer_ViewWindow::createToolBar()
313 myToolBar->addAction( myActionsMap[DumpId] );
314 myToolBar->addAction( myActionsMap[TrihedronShowId] );
316 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
317 aScaleAction->insertAction( myActionsMap[FitAllId] );
318 aScaleAction->insertAction( myActionsMap[FitRectId] );
319 aScaleAction->insertAction( myActionsMap[ZoomId] );
320 myToolBar->addAction( aScaleAction );
322 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
323 aPanningAction->insertAction( myActionsMap[PanId] );
324 aPanningAction->insertAction( myActionsMap[GlobalPanId] );
325 myToolBar->addAction( aPanningAction );
327 myToolBar->addAction( myActionsMap[RotationId] );
329 QtxMultiAction* aViewsAction = new QtxMultiAction(myToolBar);
330 aViewsAction->insertAction( myActionsMap[FrontId] );
331 aViewsAction->insertAction( myActionsMap[BackId] );
332 aViewsAction->insertAction( myActionsMap[TopId] );
333 aViewsAction->insertAction( myActionsMap[BottomId] );
334 aViewsAction->insertAction( myActionsMap[LeftId] );
335 aViewsAction->insertAction( myActionsMap[RightId] );
336 myToolBar->addAction( aViewsAction );
338 myToolBar->addAction( myActionsMap[AntiClockWiseId] );
339 myToolBar->addAction( myActionsMap[ClockWiseId] );
341 myToolBar->addAction( myActionsMap[ResetId] );
344 /*!On front view event.*/
345 void VTKViewer_ViewWindow::onFrontView()
347 vtkCamera* camera = myRenderer->GetActiveCamera();
348 camera->SetPosition(1,0,0);
349 camera->SetViewUp(0,0,1);
350 camera->SetFocalPoint(0,0,0);
354 /*!On back view slot.*/
355 void VTKViewer_ViewWindow::onBackView()
357 vtkCamera* camera = myRenderer->GetActiveCamera();
358 camera->SetPosition(-1,0,0);
359 camera->SetViewUp(0,0,1);
360 camera->SetFocalPoint(0,0,0);
364 /*!On back view slot.*/
365 void VTKViewer_ViewWindow::onTopView()
367 vtkCamera* camera = myRenderer->GetActiveCamera();
368 camera->SetPosition(0,0,1);
369 camera->SetViewUp(0,1,0);
370 camera->SetFocalPoint(0,0,0);
374 /*!On bottom view slot.*/
375 void VTKViewer_ViewWindow::onBottomView()
377 vtkCamera* camera = myRenderer->GetActiveCamera();
378 camera->SetPosition(0,0,-1);
379 camera->SetViewUp(0,1,0);
380 camera->SetFocalPoint(0,0,0);
384 /*!On left view slot.*/
385 void VTKViewer_ViewWindow::onLeftView()
387 vtkCamera* camera = myRenderer->GetActiveCamera();
388 camera->SetPosition(0,-1,0);
389 camera->SetViewUp(0,0,1);
390 camera->SetFocalPoint(0,0,0);
394 /*!On right view slot.*/
395 void VTKViewer_ViewWindow::onRightView()
397 vtkCamera* camera = myRenderer->GetActiveCamera();
398 camera->SetPosition(0,1,0);
399 camera->SetViewUp(0,0,1);
400 camera->SetFocalPoint(0,0,0);
405 \brief Rotate view 90 degrees clockwise
407 void VTKViewer_ViewWindow::onClockWiseView()
409 vtkCamera* aCamera = myRenderer->GetActiveCamera();
411 aCamera->OrthogonalizeViewUp();
416 \brief Rotate view 90 degrees conterclockwise
418 void VTKViewer_ViewWindow::onAntiClockWiseView()
420 vtkCamera* aCamera = myRenderer->GetActiveCamera();
422 aCamera->OrthogonalizeViewUp();
426 /*!On reset view slot.*/
427 void VTKViewer_ViewWindow::onResetView()
429 int aTriedronIsVisible = isTrihedronDisplayed();
430 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
431 ::ResetCamera(myRenderer,true);
432 vtkCamera* aCamera = myRenderer->GetActiveCamera();
433 aCamera->SetPosition(1,-1,1);
434 aCamera->SetViewUp(0,0,1);
435 ::ResetCamera(myRenderer,true);
436 if(aTriedronIsVisible) myTrihedron->VisibilityOn();
437 else myTrihedron->VisibilityOff();
438 static double aCoeff = 3.0;
439 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
443 /*!On fit all slot.*/
444 void VTKViewer_ViewWindow::onFitAll()
446 myRWInteractor->GetInteractorStyle()->ViewFitAll();
450 /*!Set background color of the viewport [obsolete]*/
451 void VTKViewer_ViewWindow::setBackgroundColor( const QColor& c )
453 Qtx::BackgroundData bg = background();
458 /*!Returns background color of the viewport [obsolete]*/
459 QColor VTKViewer_ViewWindow::backgroundColor() const
461 return background().color();
464 /*!Set background of the viewport*/
465 void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
469 if ( bgData.isValid() ) {
470 switch ( bgData.mode() ) {
471 case Qtx::ColorBackground:
473 QColor c = bgData.color();
475 // show solid-colored background
476 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
477 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
478 getRenderer()->SetBackground( c.red()/255.0,
480 c.blue()/255.0 ); // set background color
485 case Qtx::SimpleGradientBackground:
488 int type = bgData.gradient( c1, c2 );
494 // show two-color gradient background
495 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
496 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
498 VTKViewer_OpenGLRenderer* aRenderer =
499 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
502 aRenderer->SetGradientType( type );
503 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
504 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
510 case Qtx::CustomGradientBackground:
512 // NOT IMPLEMENTED YET
513 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
514 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
521 if ( bgData.isTextureShown() ) {
523 int textureMode = bgData.texture( fileName );
524 QFileInfo fi( fileName );
525 if ( !fileName.isEmpty() && fi.exists() ) {
526 // read texture from file
527 QString extension = fi.suffix().toLower();
528 vtkImageReader2* aReader = 0;
529 if ( extension == "jpg" || extension == "jpeg" )
530 aReader = vtkJPEGReader::New();
531 else if ( extension == "bmp" )
532 aReader = vtkBMPReader::New();
533 else if ( extension == "tif" || extension == "tiff" )
534 aReader = vtkTIFFReader::New();
535 else if ( extension == "png" )
536 aReader = vtkPNGReader::New();
537 else if ( extension == "mhd" || extension == "mha" )
538 aReader = vtkMetaImageReader::New();
541 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
544 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
545 vtkImageMapToColors* aMap = 0;
546 vtkAlgorithmOutput* anOutput;
548 // special processing for BMP reader
549 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
551 // Special processing for BMP file
552 aBMPReader->SetAllow8BitBMP(1);
554 aMap = vtkImageMapToColors::New();
555 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
556 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
557 aMap->SetOutputFormatToRGB();
559 anOutput = aMap->GetOutputPort();
564 anOutput = aReader->GetOutputPort( 0 );
565 aTexture->SetInputConnection( anOutput );
567 // VSR: Currently, VTK only supports Stretch mode, so below code will give
568 // the same results for all modes
569 switch ( textureMode ) {
570 case Qtx::TileTexture:
571 aTexture->RepeatOn();
572 aTexture->EdgeClampOff();
573 aTexture->InterpolateOff();
575 case Qtx::StretchTexture:
576 aTexture->RepeatOff();
577 aTexture->EdgeClampOff();
578 aTexture->InterpolateOn();
580 case Qtx::CenterTexture:
582 aTexture->RepeatOff();
583 aTexture->EdgeClampOn();
584 aTexture->InterpolateOff();
587 // show textured background
588 getRenderer()->SetTexturedBackground( true ); // switch to texture mode
589 getRenderer()->SetBackgroundTexture( aTexture ); // set texture image
591 // clean-up resources
603 myBackground = bgData;
606 /*!Returns background of the viewport*/
607 Qtx::BackgroundData VTKViewer_ViewWindow::background() const
612 /*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/
613 void VTKViewer_ViewWindow::Repaint(bool theUpdateTrihedron)
615 if (theUpdateTrihedron) onAdjustTrihedron();
616 myRenderWindow->update();
619 /*!Get scale of transformation filter.*/
620 void VTKViewer_ViewWindow::GetScale( double theScale[3] ) {
621 myTransform->GetScale( theScale );
624 /*!Set scale of transformation filter and repaint window.*/
625 void VTKViewer_ViewWindow::SetScale( double theScale[3] ) {
626 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
627 myRWInteractor->Render();
631 /*!Calculation trihedron size.*/
632 void VTKViewer_ViewWindow::onAdjustTrihedron(){
633 if( !isTrihedronDisplayed() )
635 int aVisibleNum = myTrihedron->GetVisibleActorCount(myRenderer);
637 // calculating diagonal of visible props of the renderer
639 myTrihedron->VisibilityOff();
640 ::ComputeVisiblePropBounds(myRenderer,bnd);
641 myTrihedron->VisibilityOn();
643 static bool CalcByDiag = false;
645 aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
646 (bnd[3]-bnd[2])*(bnd[3]-bnd[2])+
647 (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
649 aLength = bnd[1]-bnd[0];
650 aLength = qMax((bnd[3]-bnd[2]),aLength);
651 aLength = qMax((bnd[5]-bnd[4]),aLength);
654 static double aSizeInPercents = 105;
655 QString aSetting;// = SUIT_CONFIG->getSetting("Viewer:TrihedronSize");
656 if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
658 static double EPS_SIZE = 5.0E-3;
659 double aSize = myTrihedron->GetSize();
660 double aNewSize = aLength*aSizeInPercents/100.0;
661 // if the new trihedron size have sufficient difference, then apply the value
662 if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){
663 myTrihedron->SetSize(aNewSize);
666 ::ResetCameraClippingRange(myRenderer);
669 /*!Emit key pressed.*/
670 void VTKViewer_ViewWindow::onKeyPressed(QKeyEvent* event)
672 emit keyPressed( this, event );
675 /*!Emit key released.*/
676 void VTKViewer_ViewWindow::onKeyReleased(QKeyEvent* event)
678 emit keyReleased( this, event );
681 /*!Emit key pressed.*/
682 void VTKViewer_ViewWindow::onMousePressed(QMouseEvent* event)
684 emit mousePressed(this, event);
687 /*!Emit mouse released.*/
688 void VTKViewer_ViewWindow::onMouseReleased(QMouseEvent* event)
690 emit mouseReleased( this, event );
693 /*!Emit mouse moving.*/
694 void VTKViewer_ViewWindow::onMouseMoving(QMouseEvent* event)
696 emit mouseMoving( this, event );
699 /*!Emit mouse double clicked.*/
700 void VTKViewer_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
702 emit mouseDoubleClicked( this, event );
705 /*!Insert actor to renderer and transformation filter.
706 *Move Internal actors, if \a theMoveInternalActors is true.
708 void VTKViewer_ViewWindow::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ){
709 theActor->AddToRender(myRenderer);
710 theActor->SetTransform(myTransform);
711 if(theMoveInternalActors)
712 myRWInteractor->MoveInternalActors();
715 /*!Add actor.Repaint window if \a theUpdate is true.
716 *@see InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors )
718 void VTKViewer_ViewWindow::AddActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
719 InsertActor(theActor);
724 /*!Remove \a theActor from renderer and pepaint, if \a theUpdate is true.*/
725 void VTKViewer_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
726 theActor->RemoveFromRender(myRenderer);
731 /*!@see RemoveActor() and InsertActor().*/
732 void VTKViewer_ViewWindow::MoveActor( VTKViewer_Actor* theActor)
734 RemoveActor(theActor);
735 InsertActor(theActor,true);
738 /*!On trihedron show slot.*/
739 void VTKViewer_ViewWindow::onTrihedronShow()
741 if (isTrihedronDisplayed())
742 myTrihedron->VisibilityOff();
744 myTrihedron->VisibilityOn();
745 myRenderWindow->update();
749 QImage VTKViewer_ViewWindow::dumpView()
751 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
755 /*! The method returns the visual parameters of this view as a formated string
757 QString VTKViewer_ViewWindow::getVisualParameters()
759 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
761 vtkCamera* camera = myRenderer->GetActiveCamera();
762 camera->GetPosition( pos );
763 camera->GetFocalPoint( focalPnt );
764 camera->GetViewUp( viewUp );
765 parScale = camera->GetParallelScale();
769 retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e",
770 pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1],
771 viewUp[2], parScale, scale[0], scale[1], scale[2] );
775 /*! The method restors visual parameters of this view from a formated string
777 void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters )
779 QStringList paramsLst = parameters.split( '*' );
780 if ( paramsLst.size() == 13 ) {
781 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
782 pos[0] = paramsLst[0].toDouble();
783 pos[1] = paramsLst[1].toDouble();
784 pos[2] = paramsLst[2].toDouble();
785 focalPnt[0] = paramsLst[3].toDouble();
786 focalPnt[1] = paramsLst[4].toDouble();
787 focalPnt[2] = paramsLst[5].toDouble();
788 viewUp[0] = paramsLst[6].toDouble();
789 viewUp[1] = paramsLst[7].toDouble();
790 viewUp[2] = paramsLst[8].toDouble();
791 parScale = paramsLst[9].toDouble();
792 scale[0] = paramsLst[10].toDouble();
793 scale[1] = paramsLst[11].toDouble();
794 scale[2] = paramsLst[12].toDouble();
796 vtkCamera* camera = myRenderer->GetActiveCamera();
797 camera->SetPosition( pos );
798 camera->SetFocalPoint( focalPnt );
799 camera->SetViewUp( viewUp );
800 camera->SetParallelScale( parScale );
801 myTransform->SetMatrixScale( scale[0], scale[1], scale[2] );
802 myRWInteractor->Render();