VTKViewer_RenderWindow.cxx \
VTKViewer_RenderWindowInteractor.cxx \
VTKViewer_InteractorStyleSALOME.cxx \
- VTKViewer_VectorText.cxx
+ VTKViewer_Trihedron.cxx \
+ VTKViewer_VectorText.cxx \
+ VTKViewer_Utilities.cxx
LIB_MOC = \
VTKViewer.h \
// Module : SALOME
// $Header$
-using namespace std;
#include "VTKViewer_InteractorStyleSALOME.h"
#include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Trihedron.h"
-#include <qapplication.h>
#include "QAD_Config.h"
#include "QAD_Application.h"
#include "QAD_Desktop.h"
#include <vtkImageData.h>
#include <vtkFollower.h>
-
+#include <qapplication.h>
//VRV: porting on Qt 3.0.5
#if QT_VERSION >= 0x030005
#include <qpainter.h>
#endif
//VRV: porting on Qt 3.0.5
-//----------------------------------------------------------------------------
-VTKViewer_InteractorStyleSALOME *VTKViewer_InteractorStyleSALOME::New()
-{
- // First try to create the object from the vtkObjectFactory
- vtkObject* ret = vtkObjectFactory::CreateInstance("VTKViewer_InteractorStyleSALOME");
- if(ret)
- {
- return (VTKViewer_InteractorStyleSALOME*)ret;
- }
- // If the factory was unable to create the object, then create it here.
- return new VTKViewer_InteractorStyleSALOME;
-}
+using namespace std;
+extern int SetVisibility(vtkActorCollection* theCollection, int theParam);
+extern int GetVisibility(vtkActorCollection* theCollection);
//----------------------------------------------------------------------------
+vtkStandardNewMacro(VTKViewer_InteractorStyleSALOME);
+//----------------------------------------------------------------------------
+
VTKViewer_InteractorStyleSALOME::VTKViewer_InteractorStyleSALOME()
{
- m_Triedron = 0;
+ m_Trihedron = 0;
this->MotionFactor = 10.0;
this->State = VTK_INTERACTOR_STYLE_CAMERA_NONE;
this->RadianToDegree = 180.0 / vtkMath::Pi();
}
//----------------------------------------------------------------------------
-void VTKViewer_InteractorStyleSALOME::setTriedron( vtkActorCollection* triedron )
-{
- m_Triedron = triedron;
+void VTKViewer_InteractorStyleSALOME::setTriedron(VTKViewer_Trihedron* theTrihedron){
+ m_Trihedron = theTrihedron;
}
//----------------------------------------------------------------------------
cam->Azimuth(rxf);
cam->Elevation(ryf);
cam->OrthogonalizeViewUp();
- this->CurrentRenderer->ResetCameraClippingRange();
- vtkRenderWindowInteractor *rwi = this->Interactor;
- /* VSV Light follows camera: if (this->CurrentLight)
- {
- // get the first light
- this->CurrentLight->SetPosition(cam->GetPosition());
- this->CurrentLight->SetFocalPoint(cam->GetFocalPoint());
- } */
- rwi->Render();
+ ::ResetCameraClippingRange(this->CurrentRenderer);
+ this->Interactor->Render();
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
void VTKViewer_InteractorStyleSALOME::ControlLblSize(double aOldScale, double aNewScale) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- bool IsConeActor = true;
- while(!(ac==NULL)) {
- float aMaxXRange;
- float aMaxYRange;
- float aMaxZRange;
- if(ac->IsA("vtkFollower")) {
- float aScale[3];
- ac->GetScale(aScale);
-
- float aPosition[3];
- ac->GetPosition(aPosition);
-
- float aPercent = (aOldScale-aNewScale)/aOldScale;
- ac->SetScale(aScale[0]*(1-aPercent),aScale[1]*(1-aPercent),aScale[2]*(1-aPercent));
-
- //Set new position
- float aLength = ac->GetLength();
- if (aPosition[0]!=0) {
- //x
- aPosition[0] = aMaxXRange;
- } else if (aPosition[1]!=0) {
- //y
- aPosition[1] = aMaxYRange;
- } else if (aPosition[2]!=0) {
- //z
- aPosition[2] = aMaxZRange;
- }
- ac->SetPosition(aPosition);
-
- IsConeActor = true;
- }
- else {
- if (IsConeActor) {
- //coneActor is the first in the list (see m_Triedron->AddItem(...) in VTKViewer_ViewFrame::AddVector(...))
- IsConeActor = false;
-
- float aPosition[3];
- ac->GetPosition(aPosition);
-
- if (aPosition[0]!=0) {
- //x
- float* aXRange = ac->GetXRange();
- if (aXRange[0] < aXRange[1]) aMaxXRange = aXRange[1];
- else aMaxXRange = aXRange[0];
- } else if (aPosition[1]!=0) {
- //y
- float* aYRange = ac->GetYRange();
- if (aYRange[0] < aYRange[1]) aMaxYRange = aYRange[1];
- else aMaxYRange = aYRange[0];
- } else if (aPosition[2]!=0) {
- //z
- float* aZRange = ac->GetZRange();
- if (aZRange[0] < aZRange[1]) aMaxZRange = aZRange[1];
- else aMaxZRange = aZRange[0];
- }
- }
- }
- ac = m_Triedron->GetNextActor();
- }
+ return;
}
//----------------------------------------------------------------------------
void VTKViewer_InteractorStyleSALOME::DollyXY(int dx, int dy)
{
- vtkCamera *cam;
+ if (this->CurrentRenderer == NULL) return;
+
double dxf = this->MotionFactor * (double)(dx) / (double)(this->CurrentRenderer->GetCenter()[1]);
double dyf = this->MotionFactor * (double)(dy) / (double)(this->CurrentRenderer->GetCenter()[1]);
double zoomFactor = pow((double)1.1, dxf + dyf);
- if (this->CurrentRenderer == NULL)
- {
- return;
- }
-
- cam = this->CurrentRenderer->GetActiveCamera();
- if (cam->GetParallelProjection())
- {
- double aOldScale = cam->GetParallelScale();
- cam->SetParallelScale(cam->GetParallelScale()/zoomFactor);
- double aNewScale = cam->GetParallelScale();
-
- // for controlling label size
- ControlLblSize(aOldScale,aNewScale);
- }
- else
- {
- cam->Dolly(zoomFactor);
- this->CurrentRenderer->ResetCameraClippingRange();
- }
+ vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
+ if (aCam->GetParallelProjection())
+ aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
+ else{
+ aCam->Dolly(zoomFactor);
+ ::ResetCameraClippingRange(this->CurrentRenderer);
+ }
/* VSV Light follows camera: if (this->CurrentLight)
{
qApp->installEventFilter(this);
}
+
+void VTKViewer_InteractorStyleSALOME::ViewFitAll() {
+ int aTriedronWasVisible = false;
+ if(m_Trihedron){
+ aTriedronWasVisible =
+ m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+ if(aTriedronWasVisible) m_Trihedron->VisibilityOff();
+ }
+
+ if(m_Trihedron->GetVisibleActorCount(CurrentRenderer)){
+ m_Trihedron->VisibilityOff();
+ ::ResetCamera(CurrentRenderer);
+ }else{
+ m_Trihedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+ ::ResetCamera(CurrentRenderer,true);
+ }
+ if(aTriedronWasVisible) m_Trihedron->VisibilityOn();
+ else m_Trihedron->VisibilityOff();
+}
+
+
// starts Global Panning operation (e.g. through menu command)
void VTKViewer_InteractorStyleSALOME::startGlobalPan()
{
vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
myScale = cam->GetParallelScale();
+ ViewFitAll();
// make fit all
- Standard_Boolean TriedronWasVisible = false;
- if ( m_Triedron ) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- if(ac->GetVisibility()) {
- TriedronWasVisible = true;
- ac->VisibilityOff();
- }
- ac = m_Triedron->GetNextActor();
- }
- }
- this->CurrentRenderer->ResetCamera();
- this->CurrentRenderer->ResetCameraClippingRange();
- if( m_Triedron && TriedronWasVisible ) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOn();
- ac = m_Triedron->GetNextActor();
- }
- }
+// int TriedronWasVisible = false;
+// if(m_Trihedron){
+// TriedronWasVisible =
+// m_Trihedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+// if(TriedronWasVisible) m_Trihedron->VisibilityOff();
+// }
+
+// ::ResetCamera(this->CurrentRenderer);
+
+// if(m_Trihedron)
+// if(TriedronWasVisible)
+// m_Trihedron->VisibilityOn();
+
//VTKViewer_RenderWindow* aRW = dynamic_cast<VTKViewer_RenderWindow*>(this->Interactor->GetRenderWindow());
if (myGUIWindow) myGUIWindow->update();
const int right,
const int bottom)
{
- if (this->CurrentRenderer == NULL) {
- return;
- }
- vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
+ if (this->CurrentRenderer == NULL) return;
// move camera
int x = (left + right)/2;
int oldY = aSize[1]/2;
TranslateView(oldX, oldY, x, y);
-
// zoom camera
double dxf = (double)(aSize[0]) / (double)(abs(right - left));
double dyf = (double)(aSize[1]) / (double)(abs(bottom - top));
double zoomFactor = (dxf + dyf)/2 ;
- if (cam->GetParallelProjection()) {
- cam->SetParallelScale(cam->GetParallelScale()/zoomFactor);
- } else {
- cam->Dolly(zoomFactor);
- this->CurrentRenderer->ResetCameraClippingRange();
+ vtkCamera *aCam = this->CurrentRenderer->GetActiveCamera();
+ if(aCam->GetParallelProjection())
+ aCam->SetParallelScale(aCam->GetParallelScale()/zoomFactor);
+ else{
+ aCam->Dolly(zoomFactor);
+ ::ResetCameraClippingRange(this->CurrentRenderer);
}
//vtkRenderWindowInteractor *rwi = this->Interactor;
void VTKViewer_InteractorStyleSALOME::onStartOperation()
{
if (!myGUIWindow) return;
+ // VSV: LOD actor activisation
+ // this->Interactor->GetRenderWindow()->SetDesiredUpdateRate(this->Interactor->GetDesiredUpdateRate());
switch (State) {
case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
case VTK_INTERACTOR_STYLE_CAMERA_FIT:
{
if (!myGUIWindow) return;
+
QAD_Study* aActiveStudy = QAD_Application::getDesktop()->getActiveStudy();
SALOME_Selection* aSel = SALOME_Selection::Selection( aActiveStudy->getSelection() );
vtkRenderWindowInteractor *rwi = this->Interactor;
+ // VSV: LOD actor activisation
+ // rwi->GetRenderWindow()->SetDesiredUpdateRate(rwi->GetStillUpdateRate());
+
int aSelectionMode = aSel->SelectionMode();
bool aSelActiveCompOnly = aSel->IsSelectActiveCompOnly();
- SALOMEDS::SComponent_var aActiveComponent = SALOMEDS::SComponent::_narrow(
- aActiveStudy->getStudyDocument()->FindObject(QAD_Application::getDesktop()->getActiveComponent()));
switch (State) {
case VTK_INTERACTOR_STYLE_CAMERA_SELECT:
vtkActorCollection* listactors = NULL;
this->FindPokedRenderer(x, y);
rwi->StartPickCallback();
+
+// vtkPicker* aPicker = vtkPicker::SafeDownCast(rwi->GetPicker());
+// if (aPicker)
+// aPicker->SetTolerance(0.01);
+
rwi->GetPicker()->Pick(x, y, 0.0, this->CurrentRenderer);
if ( rwi->GetPicker()->IsA("vtkCellPicker") ) {
}
} else {
//processing rectangle selection
+ SALOMEDS::SComponent_var aActiveComponent = SALOMEDS::SComponent::
+ _narrow(aActiveStudy->getStudyDocument()->
+ FindObject(QAD_Application::getDesktop()->getActiveComponent()));
+ if(aSelActiveCompOnly && aActiveComponent->_is_nil()) return;
rwi->StartPickCallback();
if (!myShiftState) {
if(SActor->hasIO()) {
Handle(SALOME_InteractiveObject) IO = SActor->getIO();
if(IO.IsNull()) continue;
- if(aSelActiveCompOnly)
+ if(aSelActiveCompOnly) {
if(strcmp(aActiveComponent->ComponentDataType(),IO->getComponentDataType()) != 0)
continue;
+ }
if(vtkDataSet* aDataSet = SActor->GetMapper()->GetInput()){
for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++){
if(vtkCell* aCell = aDataSet->GetCell(i)){
}
break;
}
+ if (myGUIWindow) myGUIWindow->update();
+
}
// called during viewer operation when user moves mouse (!put necessary processing here!)
// restore zoom scale
vtkCamera *cam = this->CurrentRenderer->GetActiveCamera();
cam->SetParallelScale(myScale);
- this->CurrentRenderer->ResetCameraClippingRange();
+ ::ResetCameraClippingRange(this->CurrentRenderer);
/* VSV Light follows camera: if (this->CurrentLight) {
this->CurrentLight->SetPosition(cam->GetPosition());
#include <qcursor.h>
#include "SALOME_Actor.h"
+class VTKViewer_Trihedron;
#define VTK_INTERACTOR_STYLE_CAMERA_NONE 0
#define VTK_INTERACTOR_STYLE_CAMERA_ROTATE 1
// programmers.
static VTKViewer_InteractorStyleSALOME *New();
- void setTriedron( vtkActorCollection* triedron );
+ void setTriedron(VTKViewer_Trihedron* theTrihedron);
vtkTypeMacro(VTKViewer_InteractorStyleSALOME, vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
void OnRightButtonDown(int ctrl, int shift, int x, int y);
void OnRightButtonUp (int ctrl, int shift, int x, int y);
+ void ViewFitAll();
+
protected:
VTKViewer_InteractorStyleSALOME();
~VTKViewer_InteractorStyleSALOME();
bool myCursorState;
bool myShiftState;
int ForcedState;
- vtkActorCollection* m_Triedron;
+ VTKViewer_Trihedron* m_Trihedron;
QWidget* myGUIWindow;
#include <vtkRenderWindowInteractor.h>
#include <vtkRendererCollection.h>
#include <vtkXOpenGLRenderWindow.h>
+#include <vtkCamera.h>
//#include <GL/gl.h>
//#include <GL/glu.h>
myRW->SetDisplayId((void*)x11Display());
myRW->SetWindowId((void*)winId());
myRW->DoubleBufferOn();
+ setMouseTracking(true);
}
VTKViewer_RenderWindow::~VTKViewer_RenderWindow() {
}
void VTKViewer_RenderWindow::resizeEvent(QResizeEvent* theEvent) {
- vtkRenderWindowInteractor* aRWI = myRW->GetInteractor();
- if (aRWI != NULL)
- aRWI->SetSize(width(), height());
- myRW->SetSize(width(), height());
+ int aWidth = myRW->GetSize()[0], aHeight = myRW->GetSize()[1];
+ if(vtkRenderWindowInteractor* aRWI = myRW->GetInteractor())
+ aRWI->UpdateSize(width(), height());
+ if(aWidth != width() || aHeight != height()){
+ vtkRendererCollection * aRenderers = myRW->GetRenderers();
+ aRenderers->InitTraversal();
+ double aCoeff = 1.0;
+ if(vtkRenderer *aRenderer = aRenderers->GetNextItem()){
+ vtkCamera *aCamera = aRenderer->GetActiveCamera();
+ double aScale = aCamera->GetParallelScale();
+ if((aWidth - width())*(aHeight - height()) > 0)
+ aCoeff = sqrt(double(aWidth)/double(width())*double(height())/double(aHeight));
+ else
+ aCoeff = double(aWidth)/double(width());
+ aCamera->SetParallelScale(aScale*aCoeff);
+ }
+ }
}
// Module : SALOME
// $Header$
-using namespace std;
#include "VTKViewer_RenderWindowInteractor.h"
#include "VTKViewer_RenderWindow.h"
#include "VTKViewer_InteractorStyleSALOME.h"
#include <vtkRendererCollection.h>
#include <vtkPolyDataWriter.h>
-
// QT Includes
#include <qkeycode.h>
+using namespace std;
+
VTKViewer_RenderWindowInteractor* VTKViewer_RenderWindowInteractor::New() {
vtkObject *ret = vtkObjectFactory::CreateInstance("VTKViewer_RenderWindowInteractor") ;
if( ret ) {
return ;
}
+
+void VTKViewer_RenderWindowInteractor::SetInteractorStyle(vtkInteractorObserver *theInteractor){
+ myInteractorStyle = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(theInteractor);
+ vtkRenderWindowInteractor::SetInteractorStyle(theInteractor);
+}
+
+
void VTKViewer_RenderWindowInteractor::SetSelectionMode(int mode)
{
Cell_Actor->VisibilityOff();
bool hilight,
bool update)
{
- VTKViewer_InteractorStyleSALOME* aStyle = VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
- if (!aStyle) return false;
-
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
- theActors->InitTraversal();
- vtkActor *ac = theActors->GetNextActor();
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
- if ( IObject->isSame( anActor->getIO() ) ) {
- if ( anActor->GetMapper() == NULL ) {
- return false;
- }
- //highlight or unhilight actors
- if ( anActor->hasHighlight() ) {
- anActor->highlight(hilight);
- } else {
- if ( anActor->GetVisibility() == 1 ) {
- if (hilight) {
- vtkActor2D *actor2D;
- vtkProp3D *prop3D;
- if ( (prop3D=vtkProp3D::SafeDownCast(anActor)) != NULL ) {
- aStyle->HighlightProp3D(prop3D);
- } else if ( (actor2D=vtkActor2D::SafeDownCast(anActor)) != NULL ) {
- aStyle->HighlightActor2D(actor2D);
- }
- //this->InteractorStyle->HighlightProp(anActor);
- } else {
- aStyle->HighlightProp3D(NULL);
- aStyle->HighlightActor2D(NULL);
- //this->InteractorStyle->HighlightProp(NULL);
- }
+ VTKViewer_InteractorStyleSALOME* aStyle =
+ VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
+ if(!aStyle) return false;
+ vtkRendererCollection* aRenColl = this->RenderWindow->GetRenderers();
+ aRenColl->InitTraversal();
+ while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
+ vtkActorCollection* theActors = aRen->GetActors();
+ theActors->InitTraversal();
+ while(vtkActor *anAct = theActors->GetNextActor()) {
+ if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
+ if(anActor->hasIO()){
+ if(IObject->isSame(anActor->getIO())){
+ if(anActor->GetMapper() == NULL)
+ return false;
+ //highlight or unhilight actors
+ if(anActor->hasHighlight())
+ anActor->highlight(hilight);
+ else{
+ if(anActor->GetVisibility() == 1 && hilight)
+ aStyle->HighlightProp(anActor);
+ else if(!hilight)
+ aStyle->HighlightProp(NULL);
}
}
}
}
}
- ac = theActors->GetNextActor();
}
- }
- if (update) {
+ if(update){
Render();
emit RenderWindowModified();
}
-
return false;
}
}
-bool VTKViewer_RenderWindowInteractor::unHighlightAll()
-{
- vtkRenderer* aren;
- for (this->RenderWindow->GetRenderers()->InitTraversal();
- (aren = this->RenderWindow->GetRenderers()->GetNextItem()); ) {
- vtkActorCollection* theActors = aren->GetActors();
+bool VTKViewer_RenderWindowInteractor::unHighlightAll(){
+ VTKViewer_InteractorStyleSALOME* aStyle =
+ VTKViewer_InteractorStyleSALOME::SafeDownCast(this->InteractorStyle);
+ if(aStyle) aStyle->HighlightProp(NULL);
+ vtkRendererCollection* aRenColl = this->RenderWindow->GetRenderers();
+ aRenColl->InitTraversal();
+ while(vtkRenderer* aRen = this->RenderWindow->GetRenderers()->GetNextItem()){
+ vtkActorCollection* theActors = aRen->GetActors();
theActors->InitTraversal();
-
- if ( theActors->IsItemPresent(Point_Actor) != 0 )
- aren->RemoveActor( Point_Actor );
- if ( theActors->IsItemPresent( Edge_Actor ) != 0 )
- aren->RemoveActor( Edge_Actor );
- if ( theActors->IsItemPresent( Cell_Actor ) != 0 )
- aren->RemoveActor( Cell_Actor );
-
- vtkActor *ac = theActors->GetNextActor();
-
- while(!(ac==NULL)) {
- if ( ac->IsA("SALOME_Actor") ) {
- SALOME_Actor* anActor = SALOME_Actor::SafeDownCast( ac );
- if ( anActor->hasIO() ) {
+ if(theActors->IsItemPresent(Point_Actor))
+ aRen->RemoveActor(Point_Actor);
+ if(theActors->IsItemPresent(Edge_Actor))
+ aRen->RemoveActor(Edge_Actor);
+ if(theActors->IsItemPresent(Cell_Actor))
+ aRen->RemoveActor(Cell_Actor);
+ vtkActor *anActor = theActors->GetNextActor();
+ while(vtkActor *anAct = theActors->GetNextActor()) {
+ if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(anAct)){
+ if(anActor->hasIO()){
//highlight or unhilight actors
- if ( anActor->hasHighlight() )
+ if(anActor->hasHighlight())
anActor->highlight(false);
}
}
- ac = theActors->GetNextActor();
}
}
-
emit RenderWindowModified() ;
return false;
}
#include <TColStd_MapOfInteger.hxx>
#include <TColStd_MapIteratorOfMapOfInteger.hxx>
-class VTKViewer_RenderWindow;
class vtkPolyData;
class vtkPolyDataMapper;
+class VTKViewer_RenderWindow;
+class VTKViewer_InteractorStyleSALOME;
+
// ------------------------------------------------------------
// :TRICKY: Fri Apr 21 22:19:27 2000 Pagey
// The Signal/Slot mechanism used by Qt requires that QObject
static VTKViewer_RenderWindowInteractor *New() ;
- vtkTypeMacro(vtkRenderWindowInteractor,vtkObject);
+ vtkTypeMacro(VTKViewer_RenderWindowInteractor,vtkRenderWindowInteractor);
void PrintSelf(ostream& os, vtkIndent indent);
// want to have mouse interaction.
virtual void Initialize();
+ virtual void SetInteractorStyle(vtkInteractorObserver *);
+ VTKViewer_InteractorStyleSALOME* GetInteractorStyleSALOME(){
+ return myInteractorStyle;
+ }
+
// Description:
// This will start up the X event loop and never return. If you
// call this method it will loop processing X events until the
vtkRenderer* GetRenderer();
QWidget* getGUIWindow() {return myGUIWindow;}
- void setGUIWindow(QWidget* theWin) { myGUIWindow = theWin;}
-
+ void setGUIWindow(QWidget* theWin) {myGUIWindow = theWin;}
+
typedef void (*TCreateMapperFun)(vtkPolyData *theSourcePolyData,
- vtkPolyDataMapper* theMapper,
- const TColStd_MapOfInteger& theMapIndex);
+ vtkPolyDataMapper* theMapper,
+ const TColStd_MapOfInteger& theMapIndex);
protected:
VTKViewer_RenderWindowInteractor();
~VTKViewer_RenderWindowInteractor();
+ VTKViewer_InteractorStyleSALOME* myInteractorStyle;
+
bool highlight(const Handle(SALOME_InteractiveObject)& IObject,
const TColStd_MapOfInteger& MapIndex, TCreateMapperFun theFun,
vtkActor *theActor, bool hilight, bool update );
- //
+
// Timer used during various mouse events to figure
// out mouse movements.
- //
QTimer *mTimer ;
//CAI: Display mode
vtkActor* Edge_Actor; //NB
vtkActor* Cell_Actor;
- //
// User for switching to stereo mode.
- //
int PositionBeforeStereo[2];
- //
+
// Connect/disconnect all slots which allow events on the
// render window to be passed to the interactor.
- //
void ConnectSlots() ;
void DisconnectSlots() ;
void ProcessSlotConnections(bool conn) ;
void KeyPressed(QKeyEvent *event) ;
private slots:
- //
// Not all of these slots are needed in VTK_MAJOR_VERSION=3,
// but moc does not understand "#if VTK_MAJOR_VERSION". Hence,
// we have to include all of these for the time being. Once,
// this bug in MOC is fixed, we can separate these.
- //
void TimerFunc() ;
+
signals:
void RenderWindowModified() ;
#endif
+
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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_Trihedron.cxx
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#include "VTKViewer_Trihedron.h"
+#include "utilities.h"
+#include "SALOME_Actor.h"
+
+// VTK Includes
+#include <vtkMath.h>
+#include <vtkMapper.h>
+#include <vtkDataSet.h>
+#include <vtkRenderer.h>
+#include <vtkFollower.h>
+#include <vtkRenderWindow.h>
+#include <vtkObjectFactory.h>
+
+#include <vtkActor.h>
+#include <vtkProperty.h>
+#include <vtkLineSource.h>
+#include <vtkConeSource.h>
+#include <vtkPolyDataMapper.h>
+
+#include "VTKViewer_VectorText.h"
+
+using namespace std;
+
+//==============================================================================
+
+class VTKViewer_UnScaledActor: public vtkFollower{
+ VTKViewer_UnScaledActor(const VTKViewer_UnScaledActor&);
+
+public:
+ vtkTypeMacro(VTKViewer_UnScaledActor,vtkFollower);
+ static VTKViewer_UnScaledActor *New();
+
+ virtual void SetSize(int theSize);
+ virtual void Render(vtkRenderer *theRenderer);
+
+protected:
+ VTKViewer_UnScaledActor();
+ int mySize;
+};
+
+vtkStandardNewMacro(VTKViewer_UnScaledActor);
+
+VTKViewer_UnScaledActor::VTKViewer_UnScaledActor(){}
+
+void VTKViewer_UnScaledActor::Render(vtkRenderer *theRenderer){
+ if(theRenderer){
+ float P[2][3] = {{-1.0, -1.0, 0.0},{+1.0, +1.0, 0.0}};
+ theRenderer->ViewToWorld(P[0][0],P[0][1],P[0][2]);
+ theRenderer->ViewToWorld(P[1][0],P[1][1],P[1][2]);
+ float aWorldDiag = sqrt((P[1][0]-P[0][0])*(P[1][0]-P[0][0])+
+ (P[1][1]-P[0][1])*(P[1][1]-P[0][1])+
+ (P[1][2]-P[0][2])*(P[1][2]-P[0][2]));
+ int* aSize = theRenderer->GetRenderWindow()->GetSize();
+ float aWinDiag = sqrt(float(aSize[0]*aSize[0]+aSize[1]*aSize[1]));
+ vtkDataSet* aDataSet = GetMapper()->GetInput();
+ float aLength = aDataSet->GetLength();
+ float aScale = mySize*aWorldDiag/aWinDiag/aLength*sqrt(float(aSize[0])/float(aSize[1]));
+ SetScale(aScale);
+ }
+ vtkFollower::Render(theRenderer);
+}
+
+void VTKViewer_UnScaledActor::SetSize(int theSize){
+ mySize = theSize;
+}
+
+//==============================================================================
+
+// The base class for concreate Axis
+// Its only duty is to give correct initialization and destruction
+// of its pipe-lines
+class VTKViewer_Axis : public vtkObject{
+protected:
+ VTKViewer_Axis();
+ VTKViewer_Axis(const VTKViewer_Axis&);
+ virtual ~VTKViewer_Axis();
+ public:
+ vtkTypeMacro(VTKViewer_Axis,vtkObject);
+
+ virtual void AddToRender(vtkRenderer* theRenderer){
+ theRenderer->AddActor(myLabelActor);
+ theRenderer->AddActor(myArrowActor);
+ theRenderer->AddActor(myLineActor);
+ }
+
+ virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis);
+ virtual VTKViewer_Trihedron::TVisibility GetVisibility() {
+ return myVisibility;
+ }
+
+ virtual void SetCamera(vtkCamera* theCamera){
+ myLabelActor->SetCamera(theCamera);
+ }
+
+ virtual void SetProperty(vtkProperty* theProperty){
+ myLabelActor->SetProperty(theProperty);
+ myArrowActor->SetProperty(theProperty);
+ myLineActor->SetProperty(theProperty);
+ }
+
+ virtual void SetSize(float theSize);
+
+ virtual VTKViewer_UnScaledActor* GetLabel(){
+ return myLabelActor;
+ }
+
+ virtual VTKViewer_UnScaledActor* GetArrow(){
+ return myArrowActor;
+ }
+
+protected:
+ VTKViewer_Trihedron::TVisibility myVisibility;
+ float myDir[3], myRot[3];
+
+ vtkActor *myLineActor;
+ VTKViewer_UnScaledActor *myArrowActor;
+ VTKViewer_UnScaledActor *myLabelActor;
+
+ vtkPolyDataMapper *myMapper[3];
+ vtkLineSource *myLineSource;
+ vtkConeSource *myConeSource;
+ VTKViewer_VectorText* myVectorText;
+};
+
+VTKViewer_Axis::VTKViewer_Axis(){
+ // Initialize the Line pipe-line representation
+ myLineSource = vtkLineSource::New();
+ myLineSource->SetPoint1(0.0,0.0,0.0);
+
+ myMapper[0] = vtkPolyDataMapper::New();
+ myMapper[0]->SetInput(myLineSource->GetOutput());
+
+ myLineActor = vtkActor::New();
+ myLineActor->SetMapper(myMapper[0]);
+ myLineActor->PickableOff();
+
+ // Initialize the Arrow pipe-line representation
+ myConeSource = vtkConeSource::New();
+ myConeSource->SetResolution(2);
+ myConeSource->SetAngle(10);
+
+ myMapper[1] = vtkPolyDataMapper::New();
+ myMapper[1]->SetInput(myConeSource->GetOutput());
+
+ myArrowActor = VTKViewer_UnScaledActor::New();
+ myArrowActor->SetMapper(myMapper[1]);
+ static int aArrowActorSize = 24;
+ myArrowActor->SetSize(aArrowActorSize);
+ myArrowActor->PickableOff();
+
+ // Initialize the Label pipe-line representation
+ myVectorText = VTKViewer_VectorText::New();
+
+ myMapper[2] = vtkPolyDataMapper::New();
+ myMapper[2]->SetInput(myVectorText->GetOutput());
+
+ myLabelActor = VTKViewer_UnScaledActor::New();
+ myLabelActor->SetMapper(myMapper[2]);
+ static int aLabelActorSize = 12;
+ myLabelActor->SetSize(aLabelActorSize);
+ myLabelActor->PickableOff();
+
+ // Initialise visibility param.
+ myVisibility = VTKViewer_Trihedron::eOn;
+}
+
+VTKViewer_Axis::~VTKViewer_Axis(){
+ // Destroy of the Label pipe-line representation
+ myLabelActor->Delete();
+
+ myMapper[2]->RemoveAllInputs();
+ myMapper[2]->Delete();
+
+ myVectorText->Delete();
+
+ // Destroy of the Arrow pipe-line representation
+ myArrowActor->Delete();
+
+ myMapper[1]->RemoveAllInputs();
+ myMapper[1]->Delete();
+
+ myConeSource->Delete();
+
+ // Destroy of the Arrow pipe-line representation
+ myLineActor->Delete();
+
+ myMapper[2]->RemoveAllInputs();
+ myMapper[2]->Delete();
+
+ myLineSource->Delete();
+}
+
+void VTKViewer_Axis::SetVisibility(VTKViewer_Trihedron::TVisibility theVis){
+ switch(theVis){
+ case VTKViewer_Trihedron::eOff:
+ case VTKViewer_Trihedron::eOn:
+ myLabelActor->SetVisibility(theVis);
+ myArrowActor->SetVisibility(theVis);
+ myLineActor->SetVisibility(theVis);
+ break;
+ case VTKViewer_Trihedron::eOnlyLineOn:
+ myLabelActor->VisibilityOff();
+ myArrowActor->VisibilityOff();
+ myLineActor->VisibilityOn();
+ break;
+ default:
+ return;
+ }
+ myVisibility = theVis;
+}
+
+void VTKViewer_Axis::SetSize(float theSize){
+ float aPosition[3] = {myDir[0]*theSize, myDir[1]*theSize, myDir[2]*theSize};
+ myLineSource->SetPoint2(aPosition);
+
+ myArrowActor->SetPosition(0.0,0.0,0.0);
+ myArrowActor->AddPosition(aPosition);
+ myArrowActor->SetOrientation(myRot);
+
+ myLabelActor->SetPosition(0.0,0.0,0.0);
+ myLabelActor->AddPosition(aPosition);
+}
+
+//==============================================================================
+class VTKViewer_XAxis : public VTKViewer_Axis{
+protected:
+ VTKViewer_XAxis();
+ VTKViewer_XAxis(const VTKViewer_XAxis&);
+public:
+ vtkTypeMacro(VTKViewer_XAxis,VTKViewer_Axis);
+ static VTKViewer_XAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_XAxis);
+
+VTKViewer_XAxis::VTKViewer_XAxis(){
+ myDir[0] = 1.0; myDir[1] = 0.0; myDir[2] = 0.0;
+ myRot[0] = 0.0; myRot[1] = 0.0; myRot[2] = 0.0;
+ myVectorText->SetText("X");
+ vtkProperty* aProperty = vtkProperty::New();
+ aProperty->SetColor(1.0,0.0,0.0);
+ SetProperty(aProperty);
+ aProperty->Delete();
+}
+
+//==============================================================================
+class VTKViewer_YAxis : public VTKViewer_Axis{
+protected:
+ VTKViewer_YAxis();
+ VTKViewer_YAxis(const VTKViewer_YAxis&);
+public:
+ vtkTypeMacro(VTKViewer_YAxis,VTKViewer_Axis);
+ static VTKViewer_YAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_YAxis);
+
+VTKViewer_YAxis::VTKViewer_YAxis(){
+ myDir[0] = 0.0; myDir[1] = 1.0; myDir[2] = 0.0;
+ myRot[0] = 0.0; myRot[1] = 0.0; myRot[2] = 90.;
+ myVectorText->SetText("Y");
+ vtkProperty* aProperty = vtkProperty::New();
+ aProperty->SetColor(0.0,1.0,0.0);
+ SetProperty(aProperty);
+ aProperty->Delete();
+}
+
+//==============================================================================
+class VTKViewer_ZAxis : public VTKViewer_Axis{
+protected:
+ VTKViewer_ZAxis();
+ VTKViewer_ZAxis(const VTKViewer_ZAxis&);
+public:
+ vtkTypeMacro(VTKViewer_ZAxis,VTKViewer_Axis);
+ static VTKViewer_ZAxis *New();
+};
+
+vtkStandardNewMacro(VTKViewer_ZAxis);
+
+VTKViewer_ZAxis::VTKViewer_ZAxis(){
+ myDir[0] = 0.0; myDir[1] = 0.0; myDir[2] = 1.0;
+ myRot[0] = 0.0; myRot[1] = -90; myRot[2] = 0.0;
+ myVectorText->SetText("Z");
+ vtkProperty* aProperty = vtkProperty::New();
+ aProperty->SetColor(0.0,0.0,1.0);
+ SetProperty(aProperty);
+ aProperty->Delete();
+}
+
+//==============================================================================
+
+vtkStandardNewMacro(VTKViewer_Trihedron);
+
+VTKViewer_Trihedron::VTKViewer_Trihedron(){
+ myPresent = vtkActorCollection::New();
+ myAxis[0] = VTKViewer_XAxis::New();
+ myAxis[1] = VTKViewer_YAxis::New();
+ myAxis[2] = VTKViewer_ZAxis::New();
+ static float aSize = 100;
+ SetSize(aSize);
+}
+
+VTKViewer_Trihedron::~VTKViewer_Trihedron(){
+ myPresent->RemoveAllItems();
+ myPresent->Delete();
+ for(int i = 0; i < 3; i++)
+ myAxis[i]->Delete();
+}
+
+void VTKViewer_Trihedron::SetSize(float theSize){
+ mySize = theSize;
+ for(int i = 0; i < 3; i++)
+ myAxis[i]->SetSize(theSize);
+}
+
+void VTKViewer_Trihedron::SetVisibility(TVisibility theVis){
+ for(int i = 0; i < 3; i++)
+ myAxis[i]->SetVisibility(theVis);
+}
+
+VTKViewer_Trihedron::TVisibility VTKViewer_Trihedron::GetVisibility(){
+ return myAxis[0]->GetVisibility();
+}
+
+void VTKViewer_Trihedron::AddToRender(vtkRenderer* theRenderer){
+ vtkCamera* aCamera = theRenderer->GetActiveCamera();
+ for(int i = 0; i < 3; i++){
+ myAxis[i]->AddToRender(theRenderer);
+ myAxis[i]->SetCamera(aCamera);
+ }
+}
+
+void VTKViewer_Trihedron::RemoveFromRender(vtkRenderer* theRenderer){
+ myPresent->InitTraversal();
+ while(vtkActor* anActor = myPresent->GetNextActor())
+ theRenderer->RemoveActor(anActor);
+}
+
+int VTKViewer_Trihedron::GetVisibleActorCount(vtkRenderer* theRenderer){
+ //TVisibility aVis = GetVisibility();
+ //SetVisibility(eOff);
+ vtkActorCollection* aCollection = theRenderer->GetActors();
+ aCollection->InitTraversal();
+ int aCount = 0;
+ while(vtkActor* prop = aCollection->GetNextActor())
+ if( prop->GetVisibility())
+ if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(prop))
+ if(!anActor->IsInfinitive())
+ aCount++;
+ //int aCount = theRenderer->VisibleActorCount();
+ //SetVisibility(aVis);
+ return aCount;
+}
+
+void VTKViewer_Trihedron::Render(vtkRenderer* theRenderer){
+ for(int i = 0; i < 3; i++)
+ {
+ myAxis[i]->GetLabel()->Render(theRenderer);
+ myAxis[i]->GetArrow()->Render(theRenderer);
+ }
+}
+
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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_Trihedron.h
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#ifndef VTKViewer_Trihedron_H
+#define VTKViewer_Trihedron_H
+
+#include <vtkObject.h>
+
+class vtkActorCollection;
+class VTKViewer_Axis;
+class vtkRenderer;
+
+class VTKViewer_Trihedron : public vtkObject{
+ protected:
+ VTKViewer_Trihedron();
+ VTKViewer_Trihedron(const VTKViewer_Trihedron&);
+ virtual ~VTKViewer_Trihedron();
+ public:
+ vtkTypeMacro(VTKViewer_Trihedron,vtkObject);
+ static VTKViewer_Trihedron *New();
+
+ virtual void SetSize(float theSize);
+ virtual float GetSize() { return mySize;}
+
+ enum TVisibility{eOff, eOn, eOnlyLineOn};
+ virtual void SetVisibility(TVisibility theVis);
+ virtual void VisibilityOff() { SetVisibility(eOff);}
+ virtual void VisibilityOn() { SetVisibility(eOn);}
+ virtual TVisibility GetVisibility();
+
+ virtual void AddToRender(vtkRenderer* theRenderer);
+ virtual void RemoveFromRender(vtkRenderer* theRenderer);
+
+ virtual int GetVisibleActorCount(vtkRenderer* theRenderer);
+
+ virtual void Render(vtkRenderer *theRenderer);
+
+protected:
+ vtkActorCollection* myPresent;
+ VTKViewer_Axis* myAxis[3];
+ float mySize;
+};
+
+#endif
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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_Utilities.cxx
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#include "VTKViewer_Utilities.h"
+#include "utilities.h"
+#include "SALOME_Actor.h"
+
+// VTK Includes
+#include <vtkMath.h>
+#include <vtkCamera.h>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+
+using namespace std;
+
+//see vtkRenderer::ResetCamera(float bounds[6]) method
+void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint){
+ if(!theRenderer) return;
+ float bounds[6];
+ int aCount = ComputeVisiblePropBounds(theRenderer,bounds);
+ if(theUsingZeroFocalPoint || aCount){
+ float aLength = bounds[1]-bounds[0];
+ aLength = max((bounds[3]-bounds[2]),aLength);
+ aLength = max((bounds[5]-bounds[4]),aLength);
+
+ double vn[3];
+ if ( theRenderer->GetActiveCamera() != NULL )
+ theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
+ else{
+ INFOS("Trying to reset non-existant camera");
+ return;
+ }
+
+ float center[3] = {0.0, 0.0, 0.0};
+ if(!theUsingZeroFocalPoint){
+ center[0] = (bounds[0] + bounds[1])/2.0;
+ center[1] = (bounds[2] + bounds[3])/2.0;
+ center[2] = (bounds[4] + bounds[5])/2.0;
+ }
+ theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
+
+ float width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
+ (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
+ (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
+
+ double ang = theRenderer->GetActiveCamera()->GetViewAngle();
+ float distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
+
+ // check view-up vector against view plane normal
+ double *vup = theRenderer->GetActiveCamera()->GetViewUp();
+ if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 ){
+ MESSAGE("Resetting view-up since view plane normal is parallel");
+ theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
+ }
+
+ // update the camera
+ theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
+ center[1]+distance*vn[1],
+ center[2]+distance*vn[2]);
+ // find size of the window
+ int* winsize = theRenderer->GetSize();
+ if(winsize[0] < winsize[1]) width *= float(winsize[1])/float(winsize[0]);
+
+ if(theUsingZeroFocalPoint) width *= sqrt(2.0);
+
+ theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
+ }
+ //workaround on VTK
+ //theRenderer->ResetCameraClippingRange(bounds);
+ ResetCameraClippingRange(theRenderer);
+}
+
+
+// Compute the bounds of the visible props
+int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]){
+ vtkProp *prop;
+ float *bounds;
+ int aCount=0;
+
+ theBounds[0] = theBounds[2] = theBounds[4] = VTK_LARGE_FLOAT;
+ theBounds[1] = theBounds[3] = theBounds[5] = -VTK_LARGE_FLOAT;
+
+ // loop through all props
+ vtkActorCollection* aCollection = theRenderer->GetActors();
+ aCollection->InitTraversal();
+ while (vtkActor* prop = aCollection->GetNextActor()) {
+ // if it's invisible, or has no geometry, we can skip the rest
+ if ( prop->GetVisibility() )
+ {
+ if(SALOME_Actor* anActor = SALOME_Actor::SafeDownCast(prop))
+ if(anActor->IsInfinitive()) continue;
+ bounds = prop->GetBounds();
+ // make sure we haven't got bogus bounds
+ if ( bounds != NULL &&
+ bounds[0] > -VTK_LARGE_FLOAT && bounds[1] < VTK_LARGE_FLOAT &&
+ bounds[2] > -VTK_LARGE_FLOAT && bounds[3] < VTK_LARGE_FLOAT &&
+ bounds[4] > -VTK_LARGE_FLOAT && bounds[5] < VTK_LARGE_FLOAT )
+ {
+ aCount++;
+
+ if (bounds[0] < theBounds[0])
+ {
+ theBounds[0] = bounds[0];
+ }
+ if (bounds[1] > theBounds[1])
+ {
+ theBounds[1] = bounds[1];
+ }
+ if (bounds[2] < theBounds[2])
+ {
+ theBounds[2] = bounds[2];
+ }
+ if (bounds[3] > theBounds[3])
+ {
+ theBounds[3] = bounds[3];
+ }
+ if (bounds[4] < theBounds[4])
+ {
+ theBounds[4] = bounds[4];
+ }
+ if (bounds[5] > theBounds[5])
+ {
+ theBounds[5] = bounds[5];
+ }
+ }//not bogus
+ }
+ }
+ return aCount;
+}
+
+
+//see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
+void ResetCameraClippingRange(vtkRenderer* theRenderer){
+ if(!theRenderer || !theRenderer->VisibleActorCount()) return;
+
+ vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
+ if( anActiveCamera == NULL ){
+ MESSAGE("Trying to reset clipping range of non-existant camera");
+ return;
+ }
+
+ // Find the plane equation for the camera view plane
+ double vn[3];
+ anActiveCamera->GetViewPlaneNormal(vn);
+ double position[3];
+ anActiveCamera->GetPosition(position);
+
+ float bounds[6];
+ theRenderer->ComputeVisiblePropBounds(bounds);
+
+ double center[3];
+ center[0] = (bounds[0] + bounds[1])/2.0;
+ center[1] = (bounds[2] + bounds[3])/2.0;
+ center[2] = (bounds[4] + bounds[5])/2.0;
+
+ double width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
+ (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
+ (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
+
+ double distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
+ (position[1]-center[1])*(position[1]-center[1]) +
+ (position[2]-center[2])*(position[2]-center[2]));
+
+ float range[2] = {distance - width/2.0, distance + width/2.0};
+
+ // Do not let the range behind the camera throw off the calculation.
+ if (range[0] < 0.0) range[0] = 0.0;
+
+ anActiveCamera->SetClippingRange( range );
+}
--- /dev/null
+// SALOME VTKViewer :
+//
+// 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_Utilities.h
+// Author : Alexey PETROV
+// Module : SALOME
+// $Header:
+
+#ifndef VTKViewer_Utilities_H
+#define VTKViewer_Utilities_H
+
+class vtkRenderer;
+
+extern void ResetCamera(vtkRenderer* theRenderer, int theUsingZeroFocalPoint = false);
+extern int ComputeVisiblePropBounds(vtkRenderer* theRenderer, float theBounds[6]);
+extern void ResetCameraClippingRange(vtkRenderer* theRenderer);
+extern float EPS_BNDBOX;
+
+#endif
// $Header$
#include "VTKViewer_ViewFrame.h"
+#include "VTKViewer_Utilities.h"
+#include "VTKViewer_Trihedron.h"
#include "VTKViewer_RenderWindow.h"
+#include "VTKViewer_InteractorStyleSALOME.h"
#include "SALOME_Transform.h"
#include "SALOME_TransformFilter.h"
#include "QAD_Desktop.h"
#include "SALOME_Selection.h"
#include "SALOME_InteractiveObject.hxx"
-#include "VTKViewer_InteractorStyleSALOME.h"
-#include "VTKViewer_VectorText.h"
#include "utilities.h"
// VTK Includes
#include <vtkActor.h>
#include <vtkRenderer.h>
-#include <vtkPolyDataMapper.h>
-
-#include <vtkMath.h>
-#include <vtkLine.h>
-#include <vtkConeSource.h>
-#include <vtkFollower.h>
+#include <vtkTransform.h>
using namespace std;
+
/*!
Constructor
*/
{
m_ViewUp[0] = 0; m_ViewUp[1] = 0; m_ViewUp[2] = -1;
m_ViewNormal[0] = 0; m_ViewNormal[1] = 0; m_ViewNormal[2] = 1;
+ m_Triedron = VTKViewer_Trihedron::New();
m_Transform = SALOME_Transform::New();
+ //m_Renderer = VTKViewer_Renderer::New() ;
+ m_Renderer = vtkRenderer::New() ;
- // m_InitialSetupDone = false ;
+ m_Triedron->AddToRender(m_Renderer);
InitialSetup();
-}
-
-
-vtkFollower* CreateTextActor(char *text, float aSize) {
- VTKViewer_VectorText* aTxt = VTKViewer_VectorText::New();
- aTxt->SetText(text);
- vtkPolyDataMapper* textMapper = vtkPolyDataMapper::New();
- textMapper->SetInput(aTxt->GetOutput());
- vtkFollower* textActor = vtkFollower::New();
- textActor->SetMapper(textMapper);
- float aScale = 17 * aSize/100;
- textActor->SetScale(aScale, aScale, aScale);
- return textActor;
-}
-
-void VTKViewer_ViewFrame::AddVector(float* o,float* p,vtkRenderer* renderer, float aSize) {
- vtkPoints* myPoints = vtkPoints::New();
- vtkLine* myLine = vtkLine::New();
-
- myPoints->InsertNextPoint(o);
- myPoints->InsertNextPoint(p);
-
- (myLine->GetPointIds())->InsertNextId(0);
- (myLine->GetPointIds())->InsertNextId(1);
-
- vtkActor* lineActor = vtkActor::New();
-
- vtkCellArray* cell = vtkCellArray::New();
-
- cell->InsertNextCell(myLine);
-
- vtkPolyData* output = vtkPolyData::New();
-
- output->SetPoints(myPoints);
- output->SetLines(cell);
-
- vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
-
- mapper->SetInput(output);
-
- lineActor->SetMapper(mapper);
-
- // Create CONE
-
- vtkConeSource* acone = vtkConeSource::New();
-
- float dim = aSize;
-
- acone->SetResolution(2);
- // acone->SetAngle(70);
- acone->SetRadius(0.02*dim);
- acone->SetHeight(0.08*dim);
-
- vtkActor* coneActor = vtkActor::New();
-
- vtkPolyDataMapper* coneMapper = vtkPolyDataMapper::New();
- coneMapper->SetInput(acone->GetOutput());
-
- coneActor->SetMapper(coneMapper);
- float rot[3];
- rot[0]=0; rot[1]=0; rot[2]=0;
-
- vtkFollower* aTextActor;
-
- coneActor->AddPosition(p);
- if(p[0]!=0) {
- // x
- aTextActor = CreateTextActor("X", dim);
- } else if(p[1]!=0) {
- // y
- rot[2]=90;
- coneActor->AddOrientation(rot);
- aTextActor = CreateTextActor("Y", dim);
- } else if(p[2]!=0) {
- // z
- rot[1]=-90;
- coneActor->AddOrientation(rot);
- aTextActor = CreateTextActor("Z", dim);
- }
- aTextActor->AddPosition(p);
- aTextActor->SetCamera(renderer->GetActiveCamera());
-
- coneActor->GetProperty()->SetInterpolation(1);
- coneActor->GetProperty()->SetRepresentationToSurface();
- coneActor->GetProperty()->SetAmbient(1);
- coneActor->GetProperty()->SetAmbientColor(1,1,1);
- coneActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
- coneActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
- lineActor->GetProperty()->SetInterpolation(1);
- lineActor->GetProperty()->SetRepresentationToSurface();
- lineActor->GetProperty()->SetAmbient(1);
- lineActor->GetProperty()->SetAmbientColor(1,1,1);
- lineActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
- lineActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
- aTextActor->GetProperty()->SetAmbient(1);
- aTextActor->GetProperty()->SetAmbientColor(1,1,1);
- aTextActor->GetProperty()->SetDiffuseColor(0.7,0.7,0.7);
- aTextActor->GetProperty()->SetSpecularColor(0.7,0.7,0.7);
-
- coneActor->PickableOff();
- lineActor->PickableOff();
- aTextActor->PickableOff();
-
- m_Triedron->AddItem(coneActor);
- m_Triedron->AddItem(lineActor);
- m_Triedron->AddItem(aTextActor);
-
- renderer->AddActor(coneActor);
- renderer->AddActor(lineActor);
- renderer->AddActor(aTextActor);
}
-bool VTKViewer_ViewFrame::isTrihedronDisplayed() {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- if(ac->GetVisibility()) return true;
- ac = m_Triedron->GetNextActor();
- }
- return false;
-}
-
-void VTKViewer_ViewFrame::SetTrihedronSize(int size)
-{
- m_Triedron->InitTraversal();
- vtkActor* anActor = m_Triedron->GetNextActor();
- while(!(anActor==NULL)) {
- m_Renderer->RemoveActor( anActor );
- anActor = m_Triedron->GetNextActor();
- }
-
- m_Triedron->RemoveAllItems();
- AddAxis(m_Renderer);
- m_RW->update();
-}
-
-
-void VTKViewer_ViewFrame::AddAxis(vtkRenderer* renderer) {
- float origine[3];
- float X[3];
- float Y[3];
- float Z[3];
- float dim;
-
- QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
- if( Size.isEmpty() ){
- dim = 100;
- } else {
- dim = Size.toFloat();
- }
-
- origine[0]=0; origine[1]=0; origine[2]=0;
- X[0]=origine[0]+dim; X[1]=origine[0]; X[2]=origine[0];
- Y[0]=origine[0]; Y[1]=origine[0]+dim; Y[2]=origine[0];
- Z[0]=origine[0]; Z[1]=origine[0]; Z[2]=origine[0]+dim;
-
- AddVector(origine,X,renderer, dim);
- AddVector(origine,Y,renderer, dim);
- AddVector(origine,Z,renderer, dim);
-
-}
-
-/*!
- Returns widget containing 3D-Viewer
-*/
-QWidget* VTKViewer_ViewFrame::getViewWidget()
-{
- return m_RW;
-}
-
-
void VTKViewer_ViewFrame::InitialSetup() {
- m_Renderer = vtkRenderer::New() ;
-
m_RW = new VTKViewer_RenderWindow(this, "RenderWindow");
m_RW->getRenderWindow()->AddRenderer(m_Renderer);
m_Renderer->SetBackground( BgrColorRed.toInt()/255., BgrColorGreen.toInt()/255., BgrColorBlue.toInt()/255. );
else
m_Renderer->SetBackground( 0, 0, 0 );
-
- // CREATE AXIS
- m_Triedron = vtkActorCollection::New();
- AddAxis(m_Renderer);
-
+
// Create an interactor.
m_RWInteractor = VTKViewer_RenderWindowInteractor::New();
m_RWInteractor->setGUIWindow(m_RW);
m_RWInteractor->SetInteractorStyle(RWS);
m_RWInteractor->Initialize();
- RWS->setTriedron( m_Triedron );
+ RWS->setTriedron(m_Triedron);
//SRN: additional initialization, to init CurrentRenderer of vtkInteractorStyle
RWS->FindPokedRenderer(0, 0);
}
VTKViewer_ViewFrame::~VTKViewer_ViewFrame() {
- //
+ m_Transform->Delete() ;
// In order to ensure that the interactor unregisters
// this RenderWindow, we assign a NULL RenderWindow to
// it before deleting it.
- //
- m_Transform->Delete() ;
-
m_RWInteractor->SetRenderWindow(NULL) ;
m_RWInteractor->Delete() ;
//m_RW->Delete() ;
-
+ m_Renderer->RemoveAllProps();
// NRI : BugID 1137: m_Renderer->Delete() ;
+ m_Triedron->Delete();
+ MESSAGE("VTKViewer_ViewFrame::~VTKViewer_ViewFrame()");
}
+/*!
+ Returns widget containing 3D-Viewer
+*/
+QWidget* VTKViewer_ViewFrame::getViewWidget(){
+ return m_RW;
+}
+
+bool VTKViewer_ViewFrame::isTrihedronDisplayed(){
+ return m_Triedron->GetVisibility() == VTKViewer_Trihedron::eOn;
+}
+
+void VTKViewer_ViewFrame::onAdjustTrihedron(){
+ if(!isTrihedronDisplayed())
+ return;
+ int aVisibleNum = m_Triedron->GetVisibleActorCount(m_Renderer);
+ if(aVisibleNum){
+ // calculating diagonal of visible props of the renderer
+ float bnd[6];
+ m_Triedron->VisibilityOff();
+ ::ComputeVisiblePropBounds(m_Renderer,bnd);
+ m_Triedron->VisibilityOn();
+ float aLength = 0;
+ static bool CalcByDiag = false;
+ if(CalcByDiag){
+ aLength = sqrt((bnd[1]-bnd[0])*(bnd[1]-bnd[0])+
+ (bnd[3]-bnd[2])*(bnd[3]-bnd[2])+
+ (bnd[5]-bnd[4])*(bnd[5]-bnd[4]));
+ }else{
+ aLength = bnd[1]-bnd[0];
+ aLength = max((bnd[3]-bnd[2]),aLength);
+ aLength = max((bnd[5]-bnd[4]),aLength);
+ }
+
+ static float aSizeInPercents = 105;
+ QString aSetting = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
+ if(!aSetting.isEmpty()) aSizeInPercents = aSetting.toFloat();
+
+ static float EPS_SIZE = 5.0E-3;
+ float aSize = m_Triedron->GetSize();
+ float aNewSize = aLength*aSizeInPercents/100.0;
+ // if the new trihedron size have sufficient difference, then apply the value
+ if(fabs(aNewSize-aSize) > aSize*EPS_SIZE || fabs(aNewSize-aSize) > aNewSize*EPS_SIZE)
+ m_Triedron->SetSize(aNewSize);
+ }
+ m_Triedron->Render(m_Renderer);
+ ::ResetCameraClippingRange(m_Renderer);
+}
/*!
Display/hide Trihedron
*/
-void VTKViewer_ViewFrame::onViewTrihedron()
-{
- if (isTrihedronDisplayed()) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOff();
- ac = m_Triedron->GetNextActor();
- }
+void VTKViewer_ViewFrame::onViewTrihedron(){
+ if(!m_Triedron) return;
+ if(isTrihedronDisplayed())
+ m_Triedron->VisibilityOff();
+ else{
+ m_Triedron->VisibilityOn();
}
- else {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOn();
- ac = m_Triedron->GetNextActor();
- }
- m_TriedronVisible = true;
- }
- m_RW->update();
+ Repaint();
}
/*!
Provides top projection of the active view
*/
-void VTKViewer_ViewFrame::onViewTop() {
+void VTKViewer_ViewFrame::onViewTop(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
camera->SetPosition(0,0,1);
camera->SetViewUp(0,1,0);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides bottom projection of the active view
*/
-void VTKViewer_ViewFrame::onViewBottom()
-{
+void VTKViewer_ViewFrame::onViewBottom(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
camera->SetPosition(0,0,-1);
camera->SetViewUp(0,1,0);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides left projection of the active view
*/
-void VTKViewer_ViewFrame::onViewLeft()
-{
+void VTKViewer_ViewFrame::onViewLeft(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
camera->SetPosition(0,1,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides right projection of the active view
*/
-void VTKViewer_ViewFrame::onViewRight()
-{
+void VTKViewer_ViewFrame::onViewRight(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetFocalPoint(0,0,0);
camera->SetPosition(0,-1,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides back projection of the active view
*/
-void VTKViewer_ViewFrame::onViewBack()
-{
+void VTKViewer_ViewFrame::onViewBack(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(-1,0,0);
- camera->SetFocalPoint(0,0,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
Provides front projection of the active view
*/
-void VTKViewer_ViewFrame::onViewFront()
-{
+void VTKViewer_ViewFrame::onViewFront(){
vtkCamera* camera = m_Renderer->GetActiveCamera();
camera->SetPosition(1,0,0);
- camera->SetFocalPoint(0,0,0);
camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
+ camera->SetFocalPoint(0,0,0);
onViewFitAll();
- m_RW->update();
}
/*!
- Reset the active view
+ Fits all objects in the active view
*/
-void VTKViewer_ViewFrame::onViewReset()
-{
- vtkCamera* camera = m_Renderer->GetActiveCamera();
- camera->SetPosition(1,-1,1);
- camera->SetFocalPoint(0,0,0);
- camera->SetViewUp(0,0,1);
- m_Renderer->ResetCamera();
-
- double aOldScale = camera->GetParallelScale();
- camera->SetParallelScale(500);
- double aNewScale = camera->GetParallelScale();
-
- //for controlling labels scale after reset
- float dim;
- QString Size = QAD_CONFIG->getSetting("Viewer:TrihedronSize");
- if( Size.isEmpty() ){
- dim = 100;
- } else {
- dim = Size.toFloat();
- }
- float aScale = 17 * dim/100;
+void VTKViewer_ViewFrame::onViewFitAll(){
+ m_RWInteractor->GetInteractorStyleSALOME()->ViewFitAll();
+// int aTriedronWasVisible = isTrihedronDisplayed();
+// if(m_Triedron->GetVisibleActorCount(m_Renderer)){
+// m_Triedron->VisibilityOff();
+// ::ResetCamera(m_Renderer);
+// }else{
+// m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+// ::ResetCamera(m_Renderer,true);
+// }
+// if(aTriedronWasVisible) m_Triedron->VisibilityOn();
+// else m_Triedron->VisibilityOff();
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- bool IsConeActor = true;
- while(!(ac==NULL)) {
- if(ac->IsA("vtkFollower")) {
- ac->SetScale(aScale, aScale, aScale);
- IsConeActor = true;
- }
- else {
- if (IsConeActor) {
- //coneActor is the first in the list (see m_Triedron->AddItem(...) in VTKViewer_ViewFrame::AddVector(...))
- IsConeActor = false;
- }
- }
- ac = m_Triedron->GetNextActor();
- }
+ Repaint();
+}
- m_Renderer->ResetCameraClippingRange();
- m_RW->update();
+/*!
+ Reset the active view
+*/
+void VTKViewer_ViewFrame::onViewReset(){
+ int aTriedronIsVisible = isTrihedronDisplayed();
+ m_Triedron->SetVisibility(VTKViewer_Trihedron::eOnlyLineOn);
+ ::ResetCamera(m_Renderer,true);
+ vtkCamera* aCamera = m_Renderer->GetActiveCamera();
+ aCamera->SetPosition(1,-1,1);
+ aCamera->SetViewUp(0,0,1);
+ ::ResetCamera(m_Renderer,true);
+ if(aTriedronIsVisible) m_Triedron->VisibilityOn();
+ else m_Triedron->VisibilityOff();
+ static float aCoeff = 3.0;
+ aCamera->SetParallelScale(aCoeff*aCamera->GetParallelScale());
+ Repaint();
}
/*!
Rotates the active view
*/
-void VTKViewer_ViewFrame::onViewRotate()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startRotate();
+void VTKViewer_ViewFrame::onViewRotate(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startRotate();
}
/*!
Sets a new center of the active view
*/
-void VTKViewer_ViewFrame::onViewGlobalPan()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startGlobalPan();
+void VTKViewer_ViewFrame::onViewGlobalPan(){
+ if(m_Triedron->GetVisibleActorCount(m_Renderer))
+ m_RWInteractor->GetInteractorStyleSALOME()->startGlobalPan();
}
/*!
Zooms the active view
*/
-void VTKViewer_ViewFrame::onViewZoom()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startZoom();
+void VTKViewer_ViewFrame::onViewZoom(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startZoom();
}
/*!
Moves the active view
*/
-void VTKViewer_ViewFrame::onViewPan()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startPan();
+void VTKViewer_ViewFrame::onViewPan(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startPan();
}
/*!
Fits all obejcts within a rectangular area of the active view
*/
-void VTKViewer_ViewFrame::onViewFitArea()
-{
- VTKViewer_InteractorStyleSALOME* RWS = dynamic_cast<VTKViewer_InteractorStyleSALOME*>(getRWInteractor()->GetInteractorStyle());
- if (RWS)
- RWS->startFitArea();
-}
-
-/*!
- Fits all objects in the active view
-*/
-// Reset the camera clipping range to include this entire bounding box
-static void ResetCameraClippingRange(vtkRenderer* theRenderer, float bounds[6] )
-{
- //see vtkRenderer::ResetCameraClippingRange(float bounds[6]) method
- double vn[3], position[3], a, b, c, d;
- double range[2], dist;
- int i, j, k;
- float center[3];
- float distance;
- float width;
-
- vtkCamera* anActiveCamera = theRenderer->GetActiveCamera();
- if ( anActiveCamera == NULL )
- {
- //vtkErrorMacro(<< "Trying to reset clipping range of non-existant camera");
- return;
- }
-
- // Find the plane equation for the camera view plane
- anActiveCamera->GetViewPlaneNormal(vn);
- anActiveCamera->GetPosition(position);
-// a = -vn[0];
-// b = -vn[1];
-// c = -vn[2];
-// d = -(a*position[0] + b*position[1] + c*position[2]);
-
- // Set the max near clipping plane and the min far clipping plane
-// range[0] = a*bounds[0] + b*bounds[2] + c*bounds[4] + d;
-// range[1] = 1e-18;
-
- // Find the closest / farthest bounding box vertex
-// for ( k = 0; k < 2; k++ )
-// {
-// for ( j = 0; j < 2; j++ )
-// {
-// for ( i = 0; i < 2; i++ )
-// {
-// dist = a*bounds[i] + b*bounds[2+j] + c*bounds[4+k] + d;
-// range[0] = (dist<range[0])?(dist):(range[0]);
-// range[1] = (dist>range[1])?(dist):(range[1]);
-// }
-// }
-// }
-
- center[0] = (bounds[0] + bounds[1])/2.0;
- center[1] = (bounds[2] + bounds[3])/2.0;
- center[2] = (bounds[4] + bounds[5])/2.0;
- width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
- (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
- (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
- distance = sqrt((position[0]-center[0])*(position[0]-center[0]) +
- (position[1]-center[1])*(position[1]-center[1]) +
- (position[2]-center[2])*(position[2]-center[2]));
- range[0] = distance - width/2.0;
- range[1] = distance + width/2.0;
-
- // Give ourselves a little breathing room
- range[0] = 0.99*range[0] - (range[1] - range[0])*0.5;
- range[1] = 1.01*range[1] + (range[1] - range[0])*0.5;
-
- // Make sure near is not bigger than far
- range[0] = (range[0] >= range[1])?(0.01*range[1]):(range[0]);
-
- // Make sure near is at least some fraction of far - this prevents near
- // from being behind the camera or too close in front. How close is too
- // close depends on the resolution of the depth buffer
- int ZBufferDepth = 16;
- vtkRenderWindow* aRenderWindow = theRenderer->GetRenderWindow();
- if (aRenderWindow)
- {
- ZBufferDepth = aRenderWindow->GetDepthBufferSize();
- }
- //
- if ( ZBufferDepth <= 16 )
- {
- range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
- }
- else if ( ZBufferDepth <= 24 )
- {
- range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
- }
- else
- {
- range[0] = (range[0] < 0.01*range[1])?(0.01*range[1]):(range[0]);
- }
- anActiveCamera->SetClippingRange( range );
-}
-
-static void ResetCamera(vtkRenderer* theRenderer, vtkActorCollection* theTriedron, VTKViewer_RenderWindowInteractor* theRWInteractor){
- //see vtkRenderer::ResetCamera(float bounds[6]) method
- float bounds[6];
- if(!theRenderer) return;
- theRenderer->ComputeVisiblePropBounds( bounds );
-
- float center[3];
- float distance;
- float width;
- double vn[3], *vup;
- int* winsize;
-
- if ( theRenderer->GetActiveCamera() != NULL )
- {
- theRenderer->GetActiveCamera()->GetViewPlaneNormal(vn);
- }
- else
- {
- MESSAGE("Trying to reset non-existant camera");
- return;
- }
-
- center[0] = (bounds[0] + bounds[1])/2.0;
- center[1] = (bounds[2] + bounds[3])/2.0;
- center[2] = (bounds[4] + bounds[5])/2.0;
- width = sqrt((bounds[1]-bounds[0])*(bounds[1]-bounds[0]) +
- (bounds[3]-bounds[2])*(bounds[3]-bounds[2]) +
- (bounds[5]-bounds[4])*(bounds[5]-bounds[4]));
- double ang = theRenderer->GetActiveCamera()->GetViewAngle();
- distance = 2.0*width/tan(ang*vtkMath::Pi()/360.0);
-
- // find size of the window
- winsize = theRenderer->GetSize();
-
- // check view-up vector against view plane normal
- vup = theRenderer->GetActiveCamera()->GetViewUp();
- if ( fabs(vtkMath::Dot(vup,vn)) > 0.999 )
- {
- MESSAGE("Resetting view-up since view plane normal is parallel");
- theRenderer->GetActiveCamera()->SetViewUp(-vup[2], vup[0], vup[1]);
- }
-
- // update the camera
- theRenderer->GetActiveCamera()->SetFocalPoint(center[0],center[1],center[2]);
- theRenderer->GetActiveCamera()->SetPosition(center[0]+distance*vn[0],
- center[1]+distance*vn[1],
- center[2]+distance*vn[2]);
- // setup default parallel scale
- double aOldScale = theRenderer->GetActiveCamera()->GetParallelScale();
-
- if(winsize[0]<winsize[1] )
- width=width*(float(winsize[1])/float(winsize[0]));
-
- theRenderer->GetActiveCamera()->SetParallelScale(width/2.0);
- double aNewScale = theRenderer->GetActiveCamera()->GetParallelScale();
-
- // for controlling label size
- VTKViewer_InteractorStyleSALOME* Style = 0;
- if (theRWInteractor->GetInteractorStyle()->IsA("VTKViewer_InteractorStyleSALOME")) {
- Style = VTKViewer_InteractorStyleSALOME::SafeDownCast(theRWInteractor->GetInteractorStyle());
- Style->ControlLblSize(aOldScale,aNewScale);
- }
-
- //workaround on VTK
- //theRenderer->ResetCameraClippingRange(bounds);
- ResetCameraClippingRange(theRenderer,bounds);
-}
-
-void VTKViewer_ViewFrame::onViewFitAll()
-{
- Standard_Boolean TriedronWasVisible = false;
- if (isTrihedronDisplayed()) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOff();
- ac = m_Triedron->GetNextActor();
- }
- TriedronWasVisible = true;
- }
- bool hasVisibleActors = m_Renderer->VisibleActorCount() > 0;
- if ( hasVisibleActors ) { // if there are visible actors, not to take into account Trihedron
- ResetCamera(m_Renderer,m_Triedron,m_RWInteractor);
- }
- if(TriedronWasVisible) {
- m_Triedron->InitTraversal();
- vtkActor *ac = m_Triedron->GetNextActor();
- while(!(ac==NULL)) {
- ac->VisibilityOn();
- ac = m_Triedron->GetNextActor();
- }
- if ( !hasVisibleActors ) { // if there are NO visible actors, fit view to see only Trihedron
- ResetCamera(m_Renderer,m_Triedron,m_RWInteractor);
- }
- }
- //m_Renderer->ResetCameraClippingRange();
- m_RW->update();
+void VTKViewer_ViewFrame::onViewFitArea(){
+ m_RWInteractor->GetInteractorStyleSALOME()->startFitArea();
}
/*!
}
-void VTKViewer_ViewFrame::Repaint()
+void VTKViewer_ViewFrame::Repaint(bool theUpdateTrihedron)
{
- // m_RWInteractor->Render();
+ if (theUpdateTrihedron) onAdjustTrihedron();
m_RW->update();
}
void VTKViewer_ViewFrame::SetScale(double theScale[3]){
m_Transform->SetScale(theScale[0], theScale[1], theScale[2]);
- m_Transform->Modified();
- vtkActorCollection* theActors = m_Renderer->GetActors();
- theActors->InitTraversal();
- vtkActor *anActor;
- while(anActor = theActors->GetNextActor())
- anActor->GetMapper()->Update();
+ m_RWInteractor->Render();
Repaint();
}
theActor->SetVisibility(true);
theActor->AddToRender(m_Renderer);
theActor->SetTransform(m_Transform);
- if(update){
- m_Renderer->ResetCameraClippingRange();
- m_RWInteractor->Render();
- }
+ if(update) Repaint();
}
void VTKViewer_ViewFrame::RemoveActor( SALOME_Actor* theActor, bool update /*=false*/ ){
theActor->RemoveFromRender(m_Renderer);
- if(update){
- m_Renderer->ResetCameraClippingRange();
- m_RWInteractor->Render();
- }
+ if(update) Repaint();
}
// VTK Includes
class vtkRenderer;
-class vtkActorCollection;
class vtkTransform;
+class VTKViewer_Trihedron;
class QAD_EXPORT VTKViewer_ViewFrame : public QAD_ViewFrame{
Q_OBJECT;
VTKViewer_RenderWindowInteractor* getRWInteractor() {return m_RWInteractor;}
bool isTrihedronDisplayed();
- void SetTrihedronSize( int dim );
-
+
void setBackgroundColor( const QColor& );
QColor backgroundColor() const;
void Erase(const Handle(SALOME_InteractiveObject)& IObject, bool immediatly = true);
void DisplayAll();
void EraseAll();
- void Repaint();
+ void Repaint(bool theUpdateTrihedron);
+ void Repaint() { Repaint(true); }
//apply existing transformation on adding SALOME_Actor
void SetScale(double theScale[3]);
void AddActor(SALOME_Actor*, bool update = false);
void RemoveActor(SALOME_Actor*, bool update = false);
- private:
- void AddVector(float* o,float* p,vtkRenderer* renderer, float aSize);
- void AddAxis(vtkRenderer* renderer);
-
public slots:
void onViewPan();
void onViewZoom();
void onViewBottom();
void onViewTop();
void onViewTrihedron();
+ void onAdjustTrihedron();
private:
double m_ViewUp[3];
double m_ViewNormal[3];
-
+
void InitialSetup();
vtkRenderer* m_Renderer;
VTKViewer_RenderWindow* m_RW;
VTKViewer_RenderWindowInteractor* m_RWInteractor;
- Standard_Boolean m_TriedronVisible;
- vtkActorCollection* m_Triedron;
-
+ VTKViewer_Trihedron *m_Triedron;
SALOME_Transform *m_Transform;
};
#endif