From: apo Date: Tue, 23 Aug 2005 07:14:56 +0000 (+0000) Subject: To customize vtkRenderer. X-Git-Tag: BR-D5-38-2003_D2005-12-09~30 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=f72acfaf8a0ca729c77728801ac75db01e7bc6f4;p=modules%2Fgui.git To customize vtkRenderer. Now the introduce SVTK_Renderer is responsible for managing all its internal presentations (like trihedrons and so on) --- diff --git a/src/SVTK/Makefile.in b/src/SVTK/Makefile.in index 4e5379138..a5c9b1f8a 100755 --- a/src/SVTK/Makefile.in +++ b/src/SVTK/Makefile.in @@ -22,6 +22,7 @@ EXPORT_HEADERS= SVTK.h \ SVTK_ViewManager.h \ SVTK_ViewModel.h \ SVTK_ViewWindow.h \ + SVTK_Renderer.h \ SVTK_RenderWindow.h \ SVTK_InteractorStyle.h \ SVTK_RenderWindowInteractor.h \ @@ -43,6 +44,7 @@ LIB_SRC= SVTK_Prs.cxx \ SVTK_View.cxx \ SVTK_ViewManager.cxx \ SVTK_ViewModel.cxx \ + SVTK_Renderer.cxx \ SVTK_ViewWindow.cxx \ SVTK_RenderWindow.cxx \ SVTK_InteractorStyle.cxx \ diff --git a/src/SVTK/SVTK_RenderWindow.cxx b/src/SVTK/SVTK_RenderWindow.cxx index ffcc05210..470893fdf 100644 --- a/src/SVTK/SVTK_RenderWindow.cxx +++ b/src/SVTK/SVTK_RenderWindow.cxx @@ -6,6 +6,8 @@ #include "VTKViewer_Transform.h" #include "VTKViewer_Utilities.h" +#include "SVTK_Renderer.h" + #include "QtxAction.h" #include "SUIT_Session.h" @@ -15,82 +17,34 @@ #include "SUIT_Tools.h" #include "SUIT_ResourceMgr.h" -#include -#include - -#include -#include -#include -#include -#include -#ifndef WNT -#include -#endif +#include #if QT_VERSION > 300 #include #endif -//========================================================== +//---------------------------------------------------------------------------- SVTK_RenderWindow ::SVTK_RenderWindow(QWidget* parent, const char* name) : QMainWindow(parent, name, - Qt::WStyle_NoBorder | Qt::WDestructiveClose | - Qt::WResizeNoErase | Qt::WRepaintNoErase), - myTrihedronSize( 100 ) + Qt::WStyle_NoBorder | + Qt::WDestructiveClose | + Qt::WResizeNoErase | + Qt::WRepaintNoErase), + myRenderWindow(vtkRenderWindow::New()), + myRenderer(SVTK_Renderer::New()) { - myRenderWindow = vtkRenderWindow::New(); + myRenderWindow->Delete(); + myRenderer->Delete(); + #ifndef WNT myRenderWindow->SetDisplayId((void*)x11Display()); #endif myRenderWindow->SetWindowId((void*)winId()); myRenderWindow->DoubleBufferOn(); - //myRenderWindow->DebugOn(); setMouseTracking(true); - myRenderer = vtkRenderer::New(); - myTransform = VTKViewer_Transform::New(); - myTrihedron = SVTK_Trihedron::New(); - myCubeAxes = SVTK_CubeAxesActor2D::New(); - - myTrihedron->AddToRender( myRenderer ); - myRenderer->AddProp(myCubeAxes); - - myRenderWindow->AddRenderer( myRenderer ); - myRenderer->GetActiveCamera()->ParallelProjectionOn(); - myRenderer->LightFollowCameraOn(); - myRenderer->TwoSidedLightingOn(); - - // Set BackgroundColor - QString BgrColorRed = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorRed"); - QString BgrColorGreen = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorGreen"); - QString BgrColorBlue = "0";//SUIT_CONFIG->getSetting("VTKViewer:BackgroundColorBlue"); - - if( !BgrColorRed.isEmpty() && !BgrColorGreen.isEmpty() && !BgrColorBlue.isEmpty() ) - myRenderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. ); - else - myRenderer->SetBackground( 0, 0, 0 ); - - vtkTextProperty* tprop = vtkTextProperty::New(); - tprop->SetColor(1, 1, 1); - tprop->ShadowOn(); - - float bnd[6]; - bnd[0] = bnd[2] = bnd[4] = 0; - bnd[1] = bnd[3] = bnd[5] = myTrihedron->GetSize(); - myCubeAxes->SetLabelFormat("%6.4g"); - myCubeAxes->SetBounds(bnd); - myCubeAxes->SetCamera(myRenderer->GetActiveCamera()); - myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee - myCubeAxes->SetFontFactor(0.8); - myCubeAxes->SetAxisTitleTextProperty(tprop); - myCubeAxes->SetAxisLabelTextProperty(tprop); - myCubeAxes->SetCornerOffset(0); - myCubeAxes->SetScaling(0); - myCubeAxes->SetNumberOfLabels(5); - myCubeAxes->VisibilityOff(); - myCubeAxes->SetTransform(myTransform); - tprop->Delete(); + myRenderWindow->AddRenderer(getRenderer()); myToolBar = new QToolBar(this); myToolBar->setCloseMode(QDockWindow::Undocked); @@ -100,22 +54,48 @@ SVTK_RenderWindow createToolBar(); } -//========================================================== SVTK_RenderWindow ::~SVTK_RenderWindow() +{} + + +//---------------------------------------------------------------------------- +QToolBar* +SVTK_RenderWindow +::getToolBar() { - myRenderWindow->Delete(); + return myToolBar; +} - myTransform->Delete(); +vtkRenderer* +SVTK_RenderWindow +::getRenderer() +{ + return myRenderer.GetPointer(); +} - //m_RW->Delete() ; - myRenderer->RemoveAllProps(); - //m_Renderer->Delete(); - myTrihedron->Delete(); - myCubeAxes->Delete(); +vtkRenderWindow* +SVTK_RenderWindow +::getRenderWindow() +{ + return myRenderWindow.GetPointer(); } -//========================================================== +VTKViewer_Trihedron* +SVTK_RenderWindow +::GetTrihedron() +{ + return myRenderer->GetTrihedron(); +} + +SVTK_CubeAxesActor2D* +SVTK_RenderWindow +::GetCubeAxes() +{ + return myRenderer->GetCubeAxes(); +} + +//---------------------------------------------------------------------------- void SVTK_RenderWindow ::createActions() @@ -262,8 +242,8 @@ void SVTK_RenderWindow ::Repaint( bool theUpdateTrihedron ) { - if( theUpdateTrihedron ) - onAdjustTrihedron(); + if(theUpdateTrihedron) + myRenderer->onAdjustTrihedron(); update(); } @@ -271,10 +251,11 @@ SVTK_RenderWindow //---------------------------------------------------------------------------- void SVTK_RenderWindow -::setBackgroundColor( const QColor& color ) +::setBackgroundColor(const QColor& theColor) { - if( myRenderer ) - myRenderer->SetBackground( color.red()/255., color.green()/255., color.blue()/255. ); + myRenderer->SetBackground(theColor.red()/255.0, + theColor.green()/255.0, + theColor.blue()/255.0); } //---------------------------------------------------------------------------- @@ -282,13 +263,11 @@ QColor SVTK_RenderWindow ::backgroundColor() const { - float backint[3]; - if( myRenderer ) - { - myRenderer->GetBackground( backint ); - return QColor(int(backint[0]*255), int(backint[1]*255), int(backint[2]*255)); - } - return QColor(); + float aBackgroundColor[3]; + myRenderer->GetBackground(aBackgroundColor); + return QColor(int(aBackgroundColor[0]*255), + int(aBackgroundColor[1]*255), + int(aBackgroundColor[2]*255)); } //---------------------------------------------------------------------------- @@ -296,7 +275,7 @@ void SVTK_RenderWindow ::GetScale( double theScale[3] ) { - myTransform->GetMatrixScale( theScale ); + myRenderer->GetScale( theScale ); } //---------------------------------------------------------------------------- @@ -304,7 +283,7 @@ void SVTK_RenderWindow ::SetScale( double theScale[3] ) { - myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); + myRenderer->SetScale( theScale ); Repaint(); } @@ -313,7 +292,7 @@ bool SVTK_RenderWindow ::isTrihedronDisplayed() { - return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; + return myRenderer->isTrihedronDisplayed(); } //---------------------------------------------------------------------------- @@ -321,59 +300,45 @@ bool SVTK_RenderWindow ::isCubeAxesDisplayed() { - return myCubeAxes->GetVisibility() == 1; + return myRenderer->isCubeAxesDisplayed(); } //---------------------------------------------------------------------------- void SVTK_RenderWindow ::activateZoom() -{ - //myInteractorStyle->startZoom(); -} +{} //---------------------------------------------------------------------------- void SVTK_RenderWindow ::activatePanning() -{ - //myInteractorStyle->startPan(); -} +{} //---------------------------------------------------------------------------- void SVTK_RenderWindow ::activateRotation() -{ - //myInteractorStyle->startRotate(); -} +{} //---------------------------------------------------------------------------- void SVTK_RenderWindow ::activateGlobalPanning() -{ - //myInteractorStyle->startGlobalPan(); -} +{} //---------------------------------------------------------------------------- void SVTK_RenderWindow ::activateWindowFit() -{ - //myInteractorStyle->startFitArea(); -} +{} //---------------------------------------------------------------------------- void SVTK_RenderWindow ::onFrontView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(1,0,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myRenderer->onFrontView(); } //---------------------------------------------------------------------------- @@ -381,11 +346,7 @@ void SVTK_RenderWindow ::onBackView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(-1,0,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myRenderer->onBackView(); } //---------------------------------------------------------------------------- @@ -393,11 +354,7 @@ void SVTK_RenderWindow ::onTopView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,0,1); - camera->SetViewUp(0,1,0); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myRenderer->onTopView(); } //---------------------------------------------------------------------------- @@ -405,11 +362,7 @@ void SVTK_RenderWindow ::onBottomView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,0,-1); - camera->SetViewUp(0,1,0); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myRenderer->onBottomView(); } //---------------------------------------------------------------------------- @@ -417,11 +370,7 @@ void SVTK_RenderWindow ::onLeftView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,-1,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myRenderer->onLeftView(); } //---------------------------------------------------------------------------- @@ -429,11 +378,7 @@ void SVTK_RenderWindow ::onRightView() { - vtkCamera* camera = myRenderer->GetActiveCamera(); - camera->SetPosition(0,1,0); - camera->SetViewUp(0,0,1); - camera->SetFocalPoint(0,0,0); - onFitAll(); + myRenderer->onRightView(); } //---------------------------------------------------------------------------- @@ -441,13 +386,7 @@ void SVTK_RenderWindow ::onResetView() { - myRenderer->ResetCamera(); - vtkCamera* aCamera = myRenderer->GetActiveCamera(); - aCamera->SetPosition(1.0,-1.0,0.5); - aCamera->SetViewUp(0.0,0.0,1.0); - - static float aCoeff = 3.0; - aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); + myRenderer->onResetView(); Repaint(); } @@ -456,8 +395,7 @@ void SVTK_RenderWindow ::onFitAll() { - myRenderer->ResetCamera(); - + myRenderer->onFitAll(); Repaint(); } @@ -466,14 +404,7 @@ void SVTK_RenderWindow ::onViewTrihedron() { - if(!myTrihedron) - return; - - if(isTrihedronDisplayed()) - myTrihedron->VisibilityOff(); - else - myTrihedron->VisibilityOn(); - + myRenderer->onViewTrihedron(); Repaint(); } @@ -482,30 +413,21 @@ void SVTK_RenderWindow ::onViewCubeAxes() { - if(!myCubeAxes) - return; - - if(isCubeAxesDisplayed()) - myCubeAxes->VisibilityOff(); - else - myCubeAxes->VisibilityOn(); - + myRenderer->onViewCubeAxes(); Repaint(); } + //---------------------------------------------------------------------------- int SVTK_RenderWindow::GetTrihedronSize() const { - return myTrihedronSize; + return myRenderer->GetTrihedronSize(); } //---------------------------------------------------------------------------- -void SVTK_RenderWindow::SetTrihedronSize( const int sz ) +void SVTK_RenderWindow::SetTrihedronSize( const int theSize ) { - if ( myTrihedronSize == sz ) - return; - - myTrihedronSize = sz; - AdjustTrihedrons( true ); + myRenderer->SetTrihedronSize(theSize); + Repaint(); } /*! If parameter theIsForcedUpdate is true, recalculate parameters for @@ -513,74 +435,10 @@ void SVTK_RenderWindow::SetTrihedronSize( const int sz ) */ void SVTK_RenderWindow -::AdjustTrihedrons(const bool theIsForcedUpdate) +::AdjustTrihedrons(const bool theIsForced) { - if ((!isCubeAxesDisplayed() && !isTrihedronDisplayed()) && !theIsForcedUpdate) - return; - - float bnd[ 6 ]; - float newbnd[6]; - newbnd[ 0 ] = newbnd[ 2 ] = newbnd[ 4 ] = VTK_LARGE_FLOAT; - newbnd[ 1 ] = newbnd[ 3 ] = newbnd[ 5 ] = -VTK_LARGE_FLOAT; - - myCubeAxes->GetBounds(bnd); - - int aVisibleNum = myTrihedron->GetVisibleActorCount( myRenderer ); - //if (aVisibleNum || theIsForcedUpdate) { - if (aVisibleNum) { - // if the new trihedron size have sufficient difference, then apply the value - double aNewSize = 100, anOldSize=myTrihedron->GetSize(); - bool aTDisplayed = isTrihedronDisplayed(); - bool aCDisplayed = isCubeAxesDisplayed(); - if(aTDisplayed) myTrihedron->VisibilityOff(); - if(aCDisplayed) myCubeAxes->VisibilityOff(); - - SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); - static float aSizeInPercents = aResMgr->doubleValue("VTKViewer","trihedron_size", 105); - - ComputeTrihedronSize(myRenderer, aNewSize, anOldSize, aSizeInPercents); - - myTrihedron->SetSize( aNewSize ); - - // iterate through displayed objects and set size if necessary - vtkActorCollection* anActors = getRenderer()->GetActors(); - anActors->InitTraversal(); - while (vtkActor* anActor = anActors->GetNextActor()) - { - if (SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor )) - { - if (aSActor->IsResizable()) - aSActor->SetSize( 0.5 * aNewSize ); - if (aSActor->GetVisibility() && !aSActor->IsInfinitive()) { - float *abounds = aSActor->GetBounds(); - if (abounds[0] > -VTK_LARGE_FLOAT && abounds[1] < VTK_LARGE_FLOAT && - abounds[2] > -VTK_LARGE_FLOAT && abounds[3] < VTK_LARGE_FLOAT && - abounds[4] > -VTK_LARGE_FLOAT && abounds[5] < VTK_LARGE_FLOAT) - for (int i = 0; i < 5; i = i + 2) { - if (abounds[i] < newbnd[i]) newbnd[i] = abounds[i]; - if (abounds[i+1] > newbnd[i+1]) newbnd[i+1] = abounds[i+1]; - } - } - } - } - if (aTDisplayed) myTrihedron->VisibilityOn(); - if (aCDisplayed) myCubeAxes->VisibilityOn(); - - } else { - double aSize = myTrihedron->GetSize(); - newbnd[0] = newbnd[2] = newbnd[4] = 0; - newbnd[1] = newbnd[3] = newbnd[5] = aSize; - } - - if (newbnd[0] < VTK_LARGE_FLOAT && newbnd[2] < VTK_LARGE_FLOAT && newbnd[4] < VTK_LARGE_FLOAT && - newbnd[1] >-VTK_LARGE_FLOAT && newbnd[3] >-VTK_LARGE_FLOAT && newbnd[5] >-VTK_LARGE_FLOAT) { - for(int i=0;i<6;i++) bnd[i] = newbnd[i]; - myCubeAxes->SetBounds(bnd); - } - - myCubeAxes->SetBounds(bnd); - - ::ResetCameraClippingRange(myRenderer); + myRenderer->AdjustTrihedrons(theIsForced); + Repaint(); } //---------------------------------------------------------------------------- @@ -588,7 +446,7 @@ void SVTK_RenderWindow ::onAdjustTrihedron() { - AdjustTrihedrons( false ); + myRenderer->onAdjustTrihedron(); } //---------------------------------------------------------------------------- @@ -596,7 +454,7 @@ void SVTK_RenderWindow ::onAdjustCubeAxes() { - AdjustTrihedrons(false); + myRenderer->onAdjustCubeAxes(); } //---------------------------------------------------------------------------- diff --git a/src/SVTK/SVTK_RenderWindow.h b/src/SVTK/SVTK_RenderWindow.h index b2cd961d9..9419100b9 100644 --- a/src/SVTK/SVTK_RenderWindow.h +++ b/src/SVTK/SVTK_RenderWindow.h @@ -29,6 +29,8 @@ #ifndef SVTK_RenderWindow_h #define SVTK_RenderWindow_h +#include + #include #include @@ -37,6 +39,7 @@ class VTKViewer_Trihedron; class VTKViewer_Transform; class SVTK_CubeAxesActor2D; +class SVTK_Renderer; class QtxAction; @@ -51,13 +54,13 @@ class SVTK_EXPORT SVTK_RenderWindow : public QMainWindow SVTK_RenderWindow( QWidget*, const char* ); virtual ~SVTK_RenderWindow() ; - QToolBar* getToolBar() { return myToolBar; } + QToolBar* getToolBar(); - vtkRenderer* getRenderer() { return myRenderer;} - vtkRenderWindow* getRenderWindow() { return myRenderWindow; } + vtkRenderer* getRenderer(); + vtkRenderWindow* getRenderWindow(); - VTKViewer_Trihedron* GetTrihedron() { return myTrihedron; } - SVTK_CubeAxesActor2D* GetCubeAxes() { return myCubeAxes; } + VTKViewer_Trihedron* GetTrihedron(); + SVTK_CubeAxesActor2D* GetCubeAxes(); int GetTrihedronSize() const; void SetTrihedronSize( const int ); @@ -113,16 +116,11 @@ class SVTK_EXPORT SVTK_RenderWindow : public QMainWindow void createToolBar(); protected: - vtkRenderer* myRenderer; - vtkRenderWindow* myRenderWindow; - - VTKViewer_Transform* myTransform; - VTKViewer_Trihedron* myTrihedron; - int myTrihedronSize; - SVTK_CubeAxesActor2D* myCubeAxes; + vtkSmartPointer myRenderer; + vtkSmartPointer myRenderWindow; - QToolBar* myToolBar; ActionsMap myActionsMap; + QToolBar* myToolBar; }; #endif diff --git a/src/SVTK/SVTK_Renderer.cxx b/src/SVTK/SVTK_Renderer.cxx new file mode 100644 index 000000000..5f18d28ee --- /dev/null +++ b/src/SVTK/SVTK_Renderer.cxx @@ -0,0 +1,459 @@ +#include "SVTK_Renderer.h" + +#include "SVTK_Trihedron.h" +#include "SVTK_CubeAxesActor2D.h" + +#include "VTKViewer_Actor.h" +#include "SALOME_Actor.h" + +#include "VTKViewer_Transform.h" +#include "VTKViewer_Utilities.h" + +#include "SUIT_Session.h" +#include "SUIT_ResourceMgr.h" + +#include +#include +#include +#include + + +//---------------------------------------------------------------------------- +vtkStandardNewMacro(SVTK_Renderer); + +//---------------------------------------------------------------------------- +SVTK_Renderer +::SVTK_Renderer(): + myTransform(VTKViewer_Transform::New()), + myCubeAxes(SVTK_CubeAxesActor2D::New()), + myTrihedron(SVTK_Trihedron::New()), + myTrihedronSize(105), + myPriority(0.0), + myEventCallbackCommand(vtkCallbackCommand::New()) +{ + myTransform->Delete(); + myTrihedron->Delete(); + myCubeAxes->Delete(); + myEventCallbackCommand->Delete(); + + myTrihedron->AddToRender(this); + this->AddProp(GetCubeAxes()); + + vtkTextProperty* aTextProp = vtkTextProperty::New(); + aTextProp->SetColor(1, 1, 1); + aTextProp->ShadowOn(); + + float aBndBox[6]; + aBndBox[0] = aBndBox[2] = aBndBox[4] = 0; + aBndBox[1] = aBndBox[3] = aBndBox[5] = myTrihedron->GetSize(); + myCubeAxes->SetBounds(aBndBox); + myCubeAxes->SetCamera(this->GetActiveCamera()); + + myCubeAxes->SetLabelFormat("%6.4g"); + myCubeAxes->SetFlyModeToOuterEdges(); // ENK remarks: it must bee + myCubeAxes->SetFontFactor(0.8); + myCubeAxes->SetAxisTitleTextProperty(aTextProp); + myCubeAxes->SetAxisLabelTextProperty(aTextProp); + myCubeAxes->SetCornerOffset(0); + myCubeAxes->SetScaling(0); + myCubeAxes->SetNumberOfLabels(5); + myCubeAxes->VisibilityOff(); + myCubeAxes->SetTransform(GetTransform()); + aTextProp->Delete(); + + SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + QColor aColor = aResMgr->colorValue("VTKViewer","background",QColor()); + this->SetBackground(aColor.red()/255.0, + aColor.green()/255.0, + aColor.blue()/255.0); + + this->GetActiveCamera()->ParallelProjectionOn(); + this->LightFollowCameraOn(); + this->TwoSidedLightingOn(); + + myEventCallbackCommand->SetClientData(this); + myEventCallbackCommand->SetCallback(SVTK_Renderer::ProcessEvents); + this->AddObserver(vtkCommand::ResetCameraEvent, + myEventCallbackCommand.GetPointer(), + myPriority); +} + +SVTK_Renderer +::~SVTK_Renderer() +{} + + +void +SVTK_Renderer +::ProcessEvents(vtkObject* vtkNotUsed(theObject), + unsigned long theEvent, + void* theClientData, + void* vtkNotUsed(theCallData)) +{ + SVTK_Renderer* self = reinterpret_cast(theClientData); + + switch(theEvent){ + case vtkCommand::ResetCameraEvent: + self->onFitAll(); + break; + } +} +//---------------------------------------------------------------------------- +SVTK_CubeAxesActor2D* +SVTK_Renderer +::GetCubeAxes() +{ + return myCubeAxes.GetPointer(); +} + +bool +SVTK_Renderer +::isCubeAxesDisplayed() +{ + return myCubeAxes->GetVisibility() == 1; +} + +VTKViewer_Trihedron* +SVTK_Renderer +::GetTrihedron() +{ + return myTrihedron.GetPointer(); +} + +bool +SVTK_Renderer +::isTrihedronDisplayed() +{ + return myTrihedron->GetVisibility() == VTKViewer_Trihedron::eOn; +} + +int +SVTK_Renderer +::GetTrihedronSize() const +{ + return myTrihedronSize; +} + +void +SVTK_Renderer +::SetTrihedronSize(int theSize) +{ + if(myTrihedronSize != theSize){ + myTrihedronSize = theSize; + AdjustTrihedrons(true); + } +} + + +//---------------------------------------------------------------------------- +/*! If parameter theIsForcedUpdate is true, recalculate parameters for + * trihedron and cube axes, even if trihedron and cube axes is invisible. + */ + +inline +bool +CheckBndBox(const float theBounds[6]) +{ + if(theBounds[0] > -VTK_LARGE_FLOAT && theBounds[1] < VTK_LARGE_FLOAT && + theBounds[2] > -VTK_LARGE_FLOAT && theBounds[3] < VTK_LARGE_FLOAT && + theBounds[4] > -VTK_LARGE_FLOAT && theBounds[5] < VTK_LARGE_FLOAT) + return true; + return false; +} + +void +SVTK_Renderer +::AdjustTrihedrons(const bool theIsForced) +{ + bool aTDisplayed = isTrihedronDisplayed(); + bool aCDisplayed = isCubeAxesDisplayed(); + + if(!aCDisplayed && !aTDisplayed && !theIsForced) + return; + + float aBndBox[ 6 ]; + myCubeAxes->GetBounds(aBndBox); + + float aNewBndBox[6]; + aNewBndBox[ 0 ] = aNewBndBox[ 2 ] = aNewBndBox[ 4 ] = VTK_LARGE_FLOAT; + aNewBndBox[ 1 ] = aNewBndBox[ 3 ] = aNewBndBox[ 5 ] = -VTK_LARGE_FLOAT; + + int aVisibleNum = myTrihedron->GetVisibleActorCount(this); + if(aVisibleNum){ + // if the new trihedron size have sufficient difference, then apply the value + double aNewSize = 100; + double anOldSize = myTrihedron->GetSize(); + + if(aTDisplayed) + myTrihedron->VisibilityOff(); + + if(aCDisplayed) + myCubeAxes->VisibilityOff(); + + static SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr(); + float aSizeInPercents = aResMgr->doubleValue("VTKViewer","trihedron_size", 105); + + ComputeTrihedronSize(this,aNewSize,anOldSize,aSizeInPercents); + + myTrihedron->SetSize(aNewSize); + + // iterate through displayed objects and set size if necessary + vtkActorCollection* anActors = this->GetActors(); + anActors->InitTraversal(); + while(vtkActor* anActor = anActors->GetNextActor()){ + if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast( anActor )){ + if(aSActor->IsResizable()) + aSActor->SetSize(0.5 * aNewSize); + if(aSActor->GetVisibility() && !aSActor->IsInfinitive()){ + float *aBounds = aSActor->GetBounds(); + if(CheckBndBox(aBounds)) + for(int i = 0; i < 5; i = i + 2){ + if(aBounds[i] < aNewBndBox[i]) + aNewBndBox[i] = aBounds[i]; + if(aBounds[i+1] > aNewBndBox[i+1]) + aNewBndBox[i+1] = aBounds[i+1]; + } + } + } + } + + if(aTDisplayed) + myTrihedron->VisibilityOn(); + + if(aCDisplayed) + myCubeAxes->VisibilityOn(); + + }else{ + double aSize = myTrihedron->GetSize(); + aNewBndBox[0] = aNewBndBox[2] = aNewBndBox[4] = 0; + aNewBndBox[1] = aNewBndBox[3] = aNewBndBox[5] = aSize; + } + + if(CheckBndBox(aNewBndBox)) + myCubeAxes->SetBounds(aNewBndBox); + + ::ResetCameraClippingRange(this); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onViewTrihedron() +{ + if(isTrihedronDisplayed()) + myTrihedron->VisibilityOff(); + else + myTrihedron->VisibilityOn(); +} + +void +SVTK_Renderer +::onViewCubeAxes() +{ + if(isCubeAxesDisplayed()) + myCubeAxes->VisibilityOff(); + else + myCubeAxes->VisibilityOn(); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onAdjustTrihedron() +{ + AdjustTrihedrons(false); +} + +void +SVTK_Renderer +::onAdjustCubeAxes() +{ + AdjustTrihedrons(false); +} + + +//---------------------------------------------------------------------------- +VTKViewer_Transform* +SVTK_Renderer +::GetTransform() +{ + return myTransform.GetPointer(); +} + +void +SVTK_Renderer +::GetScale( double theScale[3] ) +{ + myTransform->GetMatrixScale( theScale ); +} + +void +SVTK_Renderer +::SetScale( double theScale[3] ) +{ + myTransform->SetMatrixScale( theScale[0], theScale[1], theScale[2] ); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::AddActor(VTKViewer_Actor* theActor) +{ + theActor->SetTransform(GetTransform()); + theActor->AddToRender(this); +} + +void +SVTK_Renderer +::RemoveActor(VTKViewer_Actor* theActor) +{ + theActor->RemoveFromRender(this); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onResetView() +{ + int aTrihedronIsVisible = isTrihedronDisplayed(); + int aCubeAxesIsVisible = isCubeAxesDisplayed(); + + myTrihedron->SetVisibility( VTKViewer_Trihedron::eOnlyLineOn ); + myCubeAxes->SetVisibility(0); + + ::ResetCamera(this,true); + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(1,-1,1); + aCamera->SetViewUp(0,0,1); + ::ResetCamera(this,true); + + if(aTrihedronIsVisible) + myTrihedron->VisibilityOn(); + else + myTrihedron->VisibilityOff(); + + if(aCubeAxesIsVisible) + myCubeAxes->VisibilityOn(); + else + myCubeAxes->VisibilityOff(); + + static float aCoeff = 3.0; + aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale()); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onFitAll() +{ + int aTrihedronWasVisible = false; + int aCubeAxesWasVisible = false; + + aTrihedronWasVisible = isTrihedronDisplayed(); + if(aTrihedronWasVisible) + myTrihedron->VisibilityOff(); + + aCubeAxesWasVisible = isCubeAxesDisplayed(); + if(aCubeAxesWasVisible) + myCubeAxes->VisibilityOff(); + + if(myTrihedron->GetVisibleActorCount(this)){ + myTrihedron->VisibilityOff(); + myCubeAxes->VisibilityOff(); + ::ResetCamera(this); + }else{ + myTrihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn); + myCubeAxes->SetVisibility(2); + ::ResetCamera(this,true); + } + + if(aTrihedronWasVisible) + myTrihedron->VisibilityOn(); + else + myTrihedron->VisibilityOff(); + + if(aCubeAxesWasVisible) + myCubeAxes->VisibilityOn(); + else + myCubeAxes->VisibilityOff(); + + ::ResetCameraClippingRange(this); +} + + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onFrontView() +{ + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(1,0,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onBackView() +{ + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(-1,0,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onTopView() +{ + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(0,0,1); + aCamera->SetViewUp(0,1,0); + aCamera->SetFocalPoint(0,0,0); + this->onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onBottomView() +{ + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(0,0,-1); + aCamera->SetViewUp(0,1,0); + aCamera->SetFocalPoint(0,0,0); + this->onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onLeftView() +{ + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(0,-1,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->onFitAll(); +} + +//---------------------------------------------------------------------------- +void +SVTK_Renderer +::onRightView() +{ + vtkCamera* aCamera = this->GetActiveCamera(); + aCamera->SetPosition(0,1,0); + aCamera->SetViewUp(0,0,1); + aCamera->SetFocalPoint(0,0,0); + this->onFitAll(); +} diff --git a/src/SVTK/SVTK_Renderer.h b/src/SVTK/SVTK_Renderer.h new file mode 100644 index 000000000..25ad29939 --- /dev/null +++ b/src/SVTK/SVTK_Renderer.h @@ -0,0 +1,113 @@ +// SALOME VTKViewer : build VTK viewer into Salome desktop +// +// Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org +// +// +// +// File : VTKViewer_RenderWindow.h +// Author : Nicolas REJNERI +// Module : SALOME +// $Header$ + +#ifndef SVTK_Renderer_h +#define SVTK_Renderer_h + +#include "SVTK.h" + +#include + +#ifndef VTK_IMPLEMENT_MESA_CXX +#include +#define RENDERER_SUPERCLASS vtkOpenGLRenderer +#else +#include +#define RENDERER_SUPERCLASS vtkMesaRenderer +#endif + +class vtkCallbackCommand; + +class VTKViewer_Trihedron; +class VTKViewer_Transform; +class SVTK_CubeAxesActor2D; +class VTKViewer_Actor; + +class SVTK_EXPORT SVTK_Renderer : public RENDERER_SUPERCLASS +{ + protected: + SVTK_Renderer(); + ~SVTK_Renderer(); + + vtkSmartPointer myTransform; + vtkSmartPointer myCubeAxes; + vtkSmartPointer myTrihedron; + int myTrihedronSize; + + // Priority at which events are processed + float myPriority; + + // Used to process events + vtkSmartPointer myEventCallbackCommand; + + // Description: + // Main process event method + static void ProcessEvents(vtkObject* object, + unsigned long event, + void* clientdata, + void* calldata); + + public: + vtkTypeMacro(SVTK_Renderer,RENDERER_SUPERCLASS); + static SVTK_Renderer* New(); + + VTKViewer_Trihedron* GetTrihedron(); + SVTK_CubeAxesActor2D* GetCubeAxes(); + + bool isTrihedronDisplayed(); + bool isCubeAxesDisplayed(); + + int GetTrihedronSize() const; + void SetTrihedronSize(int theSize); + void AdjustTrihedrons(bool theIsForced); + + void onViewTrihedron(); + void onViewCubeAxes(); + + void onAdjustTrihedron(); + void onAdjustCubeAxes(); + + VTKViewer_Transform* GetTransform(); + void SetScale( double theScale[3] ); + void GetScale( double theScale[3] ); + + void AddActor(VTKViewer_Actor* theActor); + void RemoveActor(VTKViewer_Actor* theActor); + + void onFitAll(); + void onResetView(); + + void onFrontView(); + void onBackView(); + void onTopView(); + void onBottomView(); + void onRightView(); + void onLeftView(); +}; + +#endif