1 // Copyright (C) 2007-2013 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.
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->setFloatable( false );
100 connect( myRenderWindow, SIGNAL(KeyPressed( QKeyEvent* )),
101 this, SLOT(onKeyPressed( QKeyEvent* )) );
102 connect( myRenderWindow, SIGNAL(KeyReleased( QKeyEvent* )),
103 this, SLOT(onKeyReleased( QKeyEvent* )) );
104 connect( myRenderWindow, SIGNAL(MouseButtonPressed( QMouseEvent* )),
105 this, SLOT(onMousePressed( QMouseEvent* )) );
106 connect( myRenderWindow, SIGNAL(MouseButtonReleased( QMouseEvent* )),
107 this, SLOT(onMouseReleased( QMouseEvent* )) );
108 connect( myRenderWindow, SIGNAL(MouseDoubleClicked( QMouseEvent* )),
109 this, SLOT(onMouseDoubleClicked( QMouseEvent* )) );
110 connect( myRenderWindow, SIGNAL(MouseMove( QMouseEvent* )),
111 this, SLOT(onMouseMoving( QMouseEvent* )) );
112 connect( myRWInteractor, SIGNAL(RenderWindowModified()),
113 myRenderWindow, SLOT(update()) );
115 connect( myRenderWindow, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
116 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
118 connect( myRWInteractor, SIGNAL(contextMenuRequested( QContextMenuEvent * )),
119 this, SIGNAL(contextMenuRequested( QContextMenuEvent * )) );
122 // set default background
123 setBackground( Qtx::BackgroundData( Qt::black ) );
129 VTKViewer_ViewWindow::~VTKViewer_ViewWindow()
131 myTransform->Delete();
132 // In order to ensure that the interactor unregisters
133 // this RenderWindow, we assign a NULL RenderWindow to
134 // it before deleting it.
135 myRWInteractor->SetRenderWindow( NULL );
136 myRWInteractor->Delete();
139 myRenderer->RemoveAllViewProps();
140 //m_Renderer->Delete() ;
141 myTrihedron->Delete();
144 /*!Checks: is trihedron displayed.*/
145 bool VTKViewer_ViewWindow::isTrihedronDisplayed(){
146 return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
149 /*!Activates 'zooming' transformation*/
150 void VTKViewer_ViewWindow::activateZoom()
152 myRWInteractor->GetInteractorStyle()->startZoom();
155 /*!Activates 'panning' transformation*/
156 void VTKViewer_ViewWindow::activatePanning()
158 myRWInteractor->GetInteractorStyle()->startPan();
161 /*!Activates 'rotation' transformation*/
162 void VTKViewer_ViewWindow::activateRotation()
164 myRWInteractor->GetInteractorStyle()->startRotate();
167 /*!Activate global panning.*/
168 void VTKViewer_ViewWindow::activateGlobalPanning()
170 //if(myTrihedron->GetVisibleActorCount(myRenderer))
171 myRWInteractor->GetInteractorStyle()->startGlobalPan();
174 /*!Activates 'fit area' transformation*/
175 void VTKViewer_ViewWindow::activateWindowFit()
177 myRWInteractor->GetInteractorStyle()->startFitArea();
181 void VTKViewer_ViewWindow::createActions()
183 if (!myActionsMap.isEmpty()) return;
185 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
190 aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_DUMP" ) ),
191 tr( "MNU_DUMP_VIEW" ), 0, this);
192 aAction->setStatusTip(tr("DSC_DUMP_VIEW"));
193 connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView()));
194 myActionsMap[ DumpId ] = aAction;
197 aAction = new QtxAction(tr("MNU_FITALL"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITALL" ) ),
198 tr( "MNU_FITALL" ), 0, this);
199 aAction->setStatusTip(tr("DSC_FITALL"));
200 connect(aAction, SIGNAL(activated()), this, SLOT(onFitAll()));
201 myActionsMap[ FitAllId ] = aAction;
204 aAction = new QtxAction(tr("MNU_FITRECT"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FITAREA" ) ),
205 tr( "MNU_FITRECT" ), 0, this);
206 aAction->setStatusTip(tr("DSC_FITRECT"));
207 connect(aAction, SIGNAL(activated()), this, SLOT(activateWindowFit()));
208 myActionsMap[ FitRectId ] = aAction;
211 aAction = new QtxAction(tr("MNU_ZOOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ZOOM" ) ),
212 tr( "MNU_ZOOM_VIEW" ), 0, this);
213 aAction->setStatusTip(tr("DSC_ZOOM_VIEW"));
214 connect(aAction, SIGNAL(activated()), this, SLOT(activateZoom()));
215 myActionsMap[ ZoomId ] = aAction;
218 aAction = new QtxAction(tr("MNU_PAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_PAN" ) ),
219 tr( "MNU_PAN_VIEW" ), 0, this);
220 aAction->setStatusTip(tr("DSC_PAN_VIEW"));
221 connect(aAction, SIGNAL(activated()), this, SLOT(activatePanning()));
222 myActionsMap[ PanId ] = aAction;
224 //! \li Global Panning
225 aAction = new QtxAction(tr("MNU_GLOBALPAN_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_GLOBALPAN" ) ),
226 tr( "MNU_GLOBALPAN_VIEW" ), 0, this);
227 aAction->setStatusTip(tr("DSC_GLOBALPAN_VIEW"));
228 connect(aAction, SIGNAL(activated()), this, SLOT(activateGlobalPanning()));
229 myActionsMap[ GlobalPanId ] = aAction;
232 aAction = new QtxAction(tr("MNU_ROTATE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ROTATE" ) ),
233 tr( "MNU_ROTATE_VIEW" ), 0, this);
234 aAction->setStatusTip(tr("DSC_ROTATE_VIEW"));
235 connect(aAction, SIGNAL(activated()), this, SLOT(activateRotation()));
236 myActionsMap[ RotationId ] = aAction;
239 aAction = new QtxAction(tr("MNU_FRONT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_FRONT" ) ),
240 tr( "MNU_FRONT_VIEW" ), 0, this);
241 aAction->setStatusTip(tr("DSC_FRONT_VIEW"));
242 connect(aAction, SIGNAL(activated()), this, SLOT(onFrontView()));
243 myActionsMap[ FrontId ] = aAction;
246 aAction = new QtxAction(tr("MNU_BACK_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BACK" ) ),
247 tr( "MNU_BACK_VIEW" ), 0, this);
248 aAction->setStatusTip(tr("DSC_BACK_VIEW"));
249 connect(aAction, SIGNAL(activated()), this, SLOT(onBackView()));
250 myActionsMap[ BackId ] = aAction;
253 aAction = new QtxAction(tr("MNU_TOP_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TOP" ) ),
254 tr( "MNU_TOP_VIEW" ), 0, this);
255 aAction->setStatusTip(tr("DSC_TOP_VIEW"));
256 connect(aAction, SIGNAL(activated()), this, SLOT(onTopView()));
257 myActionsMap[ TopId ] = aAction;
260 aAction = new QtxAction(tr("MNU_BOTTOM_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_BOTTOM" ) ),
261 tr( "MNU_BOTTOM_VIEW" ), 0, this);
262 aAction->setStatusTip(tr("DSC_BOTTOM_VIEW"));
263 connect(aAction, SIGNAL(activated()), this, SLOT(onBottomView()));
264 myActionsMap[ BottomId ] = aAction;
267 aAction = new QtxAction(tr("MNU_LEFT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_LEFT" ) ),
268 tr( "MNU_LEFT_VIEW" ), 0, this);
269 aAction->setStatusTip(tr("DSC_LEFT_VIEW"));
270 connect(aAction, SIGNAL(activated()), this, SLOT(onLeftView()));
271 myActionsMap[ LeftId ] = aAction;
274 aAction = new QtxAction(tr("MNU_RIGHT_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RIGHT" ) ),
275 tr( "MNU_RIGHT_VIEW" ), 0, this);
276 aAction->setStatusTip(tr("DSC_RIGHT_VIEW"));
277 connect(aAction, SIGNAL(activated()), this, SLOT(onRightView()));
278 myActionsMap[ RightId ] = aAction;
280 // \li Rotate anticlockwise
281 aAction = new QtxAction(tr("MNU_ANTICLOCKWISE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_ANTICLOCKWISE" ) ),
282 tr( "MNU_ANTICLOCKWISE_VIEW" ), 0, this);
283 aAction->setStatusTip(tr("DSC_ANTICLOCKWISE_VIEW"));
284 connect(aAction, SIGNAL(triggered()), this, SLOT(onAntiClockWiseView()));
285 myActionsMap[ AntiClockWiseId ] = aAction;
287 // \li Rotate clockwise
288 aAction = new QtxAction(tr("MNU_CLOCKWISE_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_CLOCKWISE" ) ),
289 tr( "MNU_CLOCKWISE_VIEW" ), 0, this);
290 aAction->setStatusTip(tr("DSC_CLOCKWISE_VIEW"));
291 connect(aAction, SIGNAL(triggered()), this, SLOT(onClockWiseView()));
292 myActionsMap[ ClockWiseId ] = aAction;
295 aAction = new QtxAction(tr("MNU_RESET_VIEW"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_RESET" ) ),
296 tr( "MNU_RESET_VIEW" ), 0, this);
297 aAction->setStatusTip(tr("DSC_RESET_VIEW"));
298 connect(aAction, SIGNAL(activated()), this, SLOT(onResetView()));
299 myActionsMap[ ResetId ] = aAction;
301 //! \li Trihedron shown
302 aAction = new QtxAction(tr("MNU_SHOW_TRIHEDRON"), aResMgr->loadPixmap( "VTKViewer", tr( "ICON_VTKVIEWER_VIEW_TRIHEDRON" ) ),
303 tr( "MNU_SHOW_TRIHEDRON" ), 0, this);
304 aAction->setStatusTip(tr("DSC_SHOW_TRIHEDRON"));
305 connect(aAction, SIGNAL(activated()), this, SLOT(onTrihedronShow()));
306 myActionsMap[ TrihedronShowId ] = aAction;
309 /*!Create tool bar.*/
310 void VTKViewer_ViewWindow::createToolBar()
312 myToolBar->addAction( myActionsMap[DumpId] );
313 myToolBar->addAction( myActionsMap[TrihedronShowId] );
315 QtxMultiAction* aScaleAction = new QtxMultiAction( this );
316 aScaleAction->insertAction( myActionsMap[FitAllId] );
317 aScaleAction->insertAction( myActionsMap[FitRectId] );
318 aScaleAction->insertAction( myActionsMap[ZoomId] );
319 myToolBar->addAction( aScaleAction );
321 QtxMultiAction* aPanningAction = new QtxMultiAction( this );
322 aPanningAction->insertAction( myActionsMap[PanId] );
323 aPanningAction->insertAction( myActionsMap[GlobalPanId] );
324 myToolBar->addAction( aPanningAction );
326 myToolBar->addAction( myActionsMap[RotationId] );
328 QtxMultiAction* aViewsAction = new QtxMultiAction(myToolBar);
329 aViewsAction->insertAction( myActionsMap[FrontId] );
330 aViewsAction->insertAction( myActionsMap[BackId] );
331 aViewsAction->insertAction( myActionsMap[TopId] );
332 aViewsAction->insertAction( myActionsMap[BottomId] );
333 aViewsAction->insertAction( myActionsMap[LeftId] );
334 aViewsAction->insertAction( myActionsMap[RightId] );
335 myToolBar->addAction( aViewsAction );
337 myToolBar->addAction( myActionsMap[AntiClockWiseId] );
338 myToolBar->addAction( myActionsMap[ClockWiseId] );
340 myToolBar->addAction( myActionsMap[ResetId] );
343 /*!On front view event.*/
344 void VTKViewer_ViewWindow::onFrontView()
346 vtkCamera* camera = myRenderer->GetActiveCamera();
347 camera->SetPosition(1,0,0);
348 camera->SetViewUp(0,0,1);
349 camera->SetFocalPoint(0,0,0);
353 /*!On back view slot.*/
354 void VTKViewer_ViewWindow::onBackView()
356 vtkCamera* camera = myRenderer->GetActiveCamera();
357 camera->SetPosition(-1,0,0);
358 camera->SetViewUp(0,0,1);
359 camera->SetFocalPoint(0,0,0);
363 /*!On back view slot.*/
364 void VTKViewer_ViewWindow::onTopView()
366 vtkCamera* camera = myRenderer->GetActiveCamera();
367 camera->SetPosition(0,0,1);
368 camera->SetViewUp(0,1,0);
369 camera->SetFocalPoint(0,0,0);
373 /*!On bottom view slot.*/
374 void VTKViewer_ViewWindow::onBottomView()
376 vtkCamera* camera = myRenderer->GetActiveCamera();
377 camera->SetPosition(0,0,-1);
378 camera->SetViewUp(0,1,0);
379 camera->SetFocalPoint(0,0,0);
383 /*!On left view slot.*/
384 void VTKViewer_ViewWindow::onLeftView()
386 vtkCamera* camera = myRenderer->GetActiveCamera();
387 camera->SetPosition(0,-1,0);
388 camera->SetViewUp(0,0,1);
389 camera->SetFocalPoint(0,0,0);
393 /*!On right view slot.*/
394 void VTKViewer_ViewWindow::onRightView()
396 vtkCamera* camera = myRenderer->GetActiveCamera();
397 camera->SetPosition(0,1,0);
398 camera->SetViewUp(0,0,1);
399 camera->SetFocalPoint(0,0,0);
404 \brief Rotate view 90 degrees clockwise
406 void VTKViewer_ViewWindow::onClockWiseView()
408 vtkCamera* aCamera = myRenderer->GetActiveCamera();
410 aCamera->OrthogonalizeViewUp();
415 \brief Rotate view 90 degrees conterclockwise
417 void VTKViewer_ViewWindow::onAntiClockWiseView()
419 vtkCamera* aCamera = myRenderer->GetActiveCamera();
421 aCamera->OrthogonalizeViewUp();
425 /*!On reset view slot.*/
426 void VTKViewer_ViewWindow::onResetView()
428 int aTriedronIsVisible = isTrihedronDisplayed();
429 myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn );
430 ::ResetCamera(myRenderer,true);
431 vtkCamera* aCamera = myRenderer->GetActiveCamera();
432 aCamera->SetPosition(1,-1,1);
433 aCamera->SetViewUp(0,0,1);
434 ::ResetCamera(myRenderer,true);
435 if(aTriedronIsVisible) myTrihedron->VisibilityOn();
436 else myTrihedron->VisibilityOff();
437 static double aCoeff = 3.0;
438 aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
442 /*!On fit all slot.*/
443 void VTKViewer_ViewWindow::onFitAll()
445 myRWInteractor->GetInteractorStyle()->ViewFitAll();
449 /*!Set background color of the viewport [obsolete]*/
450 void VTKViewer_ViewWindow::setBackgroundColor( const QColor& c )
452 Qtx::BackgroundData bg = background();
457 /*!Returns background color of the viewport [obsolete]*/
458 QColor VTKViewer_ViewWindow::backgroundColor() const
460 return background().color();
463 /*!Set background of the viewport*/
464 void VTKViewer_ViewWindow::setBackground( const Qtx::BackgroundData& bgData )
468 if ( bgData.isValid() ) {
469 switch ( bgData.mode() ) {
470 case Qtx::ColorBackground:
472 QColor c = bgData.color();
474 // show solid-colored background
475 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
476 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
477 getRenderer()->SetBackground( c.red()/255.0,
479 c.blue()/255.0 ); // set background color
484 case Qtx::SimpleGradientBackground:
487 int type = bgData.gradient( c1, c2 );
493 // show two-color gradient background
494 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
495 getRenderer()->SetGradientBackground( true ); // switch to gradient mode
497 VTKViewer_OpenGLRenderer* aRenderer =
498 VTKViewer_OpenGLRenderer::SafeDownCast( getRenderer() );
501 aRenderer->SetGradientType( type );
502 aRenderer->SetBackground( c1.redF(), c1.greenF(), c1.blueF() );
503 aRenderer->SetBackground2( c2.redF(), c2.greenF(), c2.blueF() );
509 case Qtx::CustomGradientBackground:
511 // NOT IMPLEMENTED YET
512 getRenderer()->SetTexturedBackground( false ); // cancel texture mode
513 getRenderer()->SetGradientBackground( false ); // cancel gradient mode
520 if ( bgData.isTextureShown() ) {
522 int textureMode = bgData.texture( fileName );
523 QFileInfo fi( fileName );
524 if ( !fileName.isEmpty() && fi.exists() ) {
525 // read texture from file
526 QString extension = fi.suffix().toLower();
527 vtkImageReader2* aReader = 0;
528 if ( extension == "jpg" || extension == "jpeg" )
529 aReader = vtkJPEGReader::New();
530 else if ( extension == "bmp" )
531 aReader = vtkBMPReader::New();
532 else if ( extension == "tif" || extension == "tiff" )
533 aReader = vtkTIFFReader::New();
534 else if ( extension == "png" )
535 aReader = vtkPNGReader::New();
536 else if ( extension == "mhd" || extension == "mha" )
537 aReader = vtkMetaImageReader::New();
540 aReader->SetFileName( fi.absoluteFilePath().toLatin1().constData() );
543 VTKViewer_Texture* aTexture = VTKViewer_Texture::New();
544 vtkImageMapToColors* aMap = 0;
545 vtkAlgorithmOutput* anOutput;
547 // special processing for BMP reader
548 vtkBMPReader* aBMPReader = (vtkBMPReader*)aReader;
550 // Special processing for BMP file
551 aBMPReader->SetAllow8BitBMP(1);
553 aMap = vtkImageMapToColors::New();
554 aMap->SetInputConnection( aBMPReader->GetOutputPort() );
555 aMap->SetLookupTable( (vtkScalarsToColors*)aBMPReader->GetLookupTable() );
556 aMap->SetOutputFormatToRGB();
558 anOutput = aMap->GetOutputPort();
563 anOutput = aReader->GetOutputPort( 0 );
564 aTexture->SetInputConnection( anOutput );
566 // VSR: Currently, VTK only supports Stretch mode, so below code will give
567 // the same results for all modes
568 switch ( textureMode ) {
569 case Qtx::TileTexture:
570 aTexture->RepeatOn();
571 aTexture->EdgeClampOff();
572 aTexture->InterpolateOff();
574 case Qtx::StretchTexture:
575 aTexture->RepeatOff();
576 aTexture->EdgeClampOff();
577 aTexture->InterpolateOn();
579 case Qtx::CenterTexture:
581 aTexture->RepeatOff();
582 aTexture->EdgeClampOn();
583 aTexture->InterpolateOff();
586 // show textured background
587 getRenderer()->SetTexturedBackground( true ); // switch to texture mode
588 getRenderer()->SetBackgroundTexture( aTexture ); // set texture image
590 // clean-up resources
602 myBackground = bgData;
605 /*!Returns background of the viewport*/
606 Qtx::BackgroundData VTKViewer_ViewWindow::background() const
611 /*!Repaint window. If \a theUpdateTrihedron is true - recalculate trihedron.*/
612 void VTKViewer_ViewWindow::Repaint(bool theUpdateTrihedron)
614 if (theUpdateTrihedron) onAdjustTrihedron();
615 myRenderWindow->update();
618 /*!Get scale of transformation filter.*/
619 void VTKViewer_ViewWindow::GetScale( double theScale[3] ) {
620 myTransform->GetScale( theScale );
623 /*!Set scale of transformation filter and repaint window.*/
624 void VTKViewer_ViewWindow::SetScale( double theScale[3] ) {
625 myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] );
626 myRWInteractor->Render();
630 /*!Calculation trihedron size.*/
631 void VTKViewer_ViewWindow::onAdjustTrihedron(){
632 if( !isTrihedronDisplayed() )
634 int aVisibleNum = myTrihedron->GetVisibleActorCount(myRenderer);
636 // calculating diagonal of visible props of the renderer
638 myTrihedron->VisibilityOff();
639 ::ComputeVisiblePropBounds(myRenderer,bnd);
640 myTrihedron->VisibilityOn();
642 static bool CalcByDiag = false;
644 aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
645 (bnd[3]-bnd[2])*(bnd[3]-bnd[2])+
646 (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
648 aLength = bnd[1]-bnd[0];
649 aLength = qMax((bnd[3]-bnd[2]),aLength);
650 aLength = qMax((bnd[5]-bnd[4]),aLength);
653 static double aSizeInPercents = 105;
654 QString aSetting;// = SUIT_CONFIG->getSetting("Viewer:TrihedronSize");
655 if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
657 static double EPS_SIZE = 5.0E-3;
658 double aSize = myTrihedron->GetSize();
659 double aNewSize = aLength*aSizeInPercents/100.0;
660 // if the new trihedron size have sufficient difference, then apply the value
661 if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE){
662 myTrihedron->SetSize(aNewSize);
665 ::ResetCameraClippingRange(myRenderer);
668 /*!Emit key pressed.*/
669 void VTKViewer_ViewWindow::onKeyPressed(QKeyEvent* event)
671 emit keyPressed( this, event );
674 /*!Emit key released.*/
675 void VTKViewer_ViewWindow::onKeyReleased(QKeyEvent* event)
677 emit keyReleased( this, event );
680 /*!Emit key pressed.*/
681 void VTKViewer_ViewWindow::onMousePressed(QMouseEvent* event)
683 emit mousePressed(this, event);
686 /*!Emit mouse released.*/
687 void VTKViewer_ViewWindow::onMouseReleased(QMouseEvent* event)
689 emit mouseReleased( this, event );
692 /*!Emit mouse moving.*/
693 void VTKViewer_ViewWindow::onMouseMoving(QMouseEvent* event)
695 emit mouseMoving( this, event );
698 /*!Emit mouse double clicked.*/
699 void VTKViewer_ViewWindow::onMouseDoubleClicked( QMouseEvent* event )
701 emit mouseDoubleClicked( this, event );
704 /*!Insert actor to renderer and transformation filter.
705 *Move Internal actors, if \a theMoveInternalActors is true.
707 void VTKViewer_ViewWindow::InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors ){
708 theActor->AddToRender(myRenderer);
709 theActor->SetTransform(myTransform);
710 if(theMoveInternalActors)
711 myRWInteractor->MoveInternalActors();
714 /*!Add actor.Repaint window if \a theUpdate is true.
715 *@see InsertActor( VTKViewer_Actor* theActor, bool theMoveInternalActors )
717 void VTKViewer_ViewWindow::AddActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
718 InsertActor(theActor);
723 /*!Remove \a theActor from renderer and pepaint, if \a theUpdate is true.*/
724 void VTKViewer_ViewWindow::RemoveActor( VTKViewer_Actor* theActor, bool theUpdate /*=false*/ ){
725 theActor->RemoveFromRender(myRenderer);
730 /*!@see RemoveActor() and InsertActor().*/
731 void VTKViewer_ViewWindow::MoveActor( VTKViewer_Actor* theActor)
733 RemoveActor(theActor);
734 InsertActor(theActor,true);
737 /*!On trihedron show slot.*/
738 void VTKViewer_ViewWindow::onTrihedronShow()
740 if (isTrihedronDisplayed())
741 myTrihedron->VisibilityOff();
743 myTrihedron->VisibilityOn();
744 myRenderWindow->update();
748 QImage VTKViewer_ViewWindow::dumpView()
750 QPixmap px = QPixmap::grabWindow( myRenderWindow->winId() );
754 /*! The method returns the visual parameters of this view as a formated string
756 QString VTKViewer_ViewWindow::getVisualParameters()
758 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
760 vtkCamera* camera = myRenderer->GetActiveCamera();
761 camera->GetPosition( pos );
762 camera->GetFocalPoint( focalPnt );
763 camera->GetViewUp( viewUp );
764 parScale = camera->GetParallelScale();
768 retStr.sprintf( "%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e*%.12e",
769 pos[0], pos[1], pos[2], focalPnt[0], focalPnt[1], focalPnt[2], viewUp[0], viewUp[1],
770 viewUp[2], parScale, scale[0], scale[1], scale[2] );
774 /*! The method restors visual parameters of this view from a formated string
776 void VTKViewer_ViewWindow::setVisualParameters( const QString& parameters )
778 QStringList paramsLst = parameters.split( '*' );
779 if ( paramsLst.size() == 13 ) {
780 double pos[3], focalPnt[3], viewUp[3], parScale, scale[3];
781 pos[0] = paramsLst[0].toDouble();
782 pos[1] = paramsLst[1].toDouble();
783 pos[2] = paramsLst[2].toDouble();
784 focalPnt[0] = paramsLst[3].toDouble();
785 focalPnt[1] = paramsLst[4].toDouble();
786 focalPnt[2] = paramsLst[5].toDouble();
787 viewUp[0] = paramsLst[6].toDouble();
788 viewUp[1] = paramsLst[7].toDouble();
789 viewUp[2] = paramsLst[8].toDouble();
790 parScale = paramsLst[9].toDouble();
791 scale[0] = paramsLst[10].toDouble();
792 scale[1] = paramsLst[11].toDouble();
793 scale[2] = paramsLst[12].toDouble();
795 vtkCamera* camera = myRenderer->GetActiveCamera();
796 camera->SetPosition( pos );
797 camera->SetFocalPoint( focalPnt );
798 camera->SetViewUp( viewUp );
799 camera->SetParallelScale( parScale );
800 myTransform->SetMatrixScale( scale[0], scale[1], scale[2] );
801 myRWInteractor->Render();