From: pkv Date: Thu, 8 Sep 2005 12:39:54 +0000 (+0000) Subject: Provides reqired camera behaviour for Gauss points X-Git-Tag: BR-D5-38-2003_D2005-12-09~9 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4cfb7f08f20e24e667e57ae923e5aedc6334ce55;p=modules%2Fvisu.git Provides reqired camera behaviour for Gauss points --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 51e3e06c..c456b71d 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -128,14 +128,101 @@ protected: vtkSmartPointer myActors[6]; }; // +/////////////////////////////////////////////////////////////////////////// +// +// class: VISU_GPTextActor +// +class vtkViewport; +class VISU_GPTextActor : public vtkTextActor +{ +protected: + VISU_GPTextActor(); + virtual ~VISU_GPTextActor(); + +public: + vtkTypeMacro(VISU_GPTextActor, vtkTextActor); + static VISU_GPTextActor* New(); + // + void SetWorldPoint(const float theCoord[4]); + + float* WorldPoint(); + + virtual int RenderOpaqueGeometry(vtkViewport *theViewport); + +protected: + float myWorldPoint[4]; +}; +// +/////////////////////////////////////////////////////////////////////////// +// +// class: VISU_CursorPyramid +// +#include + +vtkStandardNewMacro(VISU_GPTextActor);// <- static VISU_GPTextActor* New() + +//================================================================== +// function : Constructor +// purpose : +//================================================================== +VISU_GPTextActor::VISU_GPTextActor() +{ + float aCoord[]={0.,0.,0.,1}; + // + SetWorldPoint(aCoord); +} +//================================================================== +// function : ~ +// purpose : +//================================================================== +VISU_GPTextActor::~VISU_GPTextActor() +{ +} +//================================================================== +// function : SetWorldPoint +// purpose : +//================================================================== +void VISU_GPTextActor::SetWorldPoint(const float theCoord[4]) +{ + int i; + // + for (i=0; i<4; ++i){ + myWorldPoint[i]=theCoord[i]; + } +} +//================================================================== +// function : WorldPoint +// purpose : +//================================================================== +float* VISU_GPTextActor::WorldPoint() +{ + return myWorldPoint; +} +//================================================================== +// function : RenderOpaqueGeometry +// purpose : +//================================================================== +int VISU_GPTextActor::RenderOpaqueGeometry(vtkViewport *theViewport) +{ + float aSelectionPoint[3]; + // + theViewport->SetWorldPoint(myWorldPoint); + theViewport->WorldToDisplay(); + theViewport->GetDisplayPoint(aSelectionPoint); + SetPosition(aSelectionPoint); + // + Superclass::RenderOpaqueGeometry(theViewport); +} +// +//VISU_GaussPtsAct vtkStandardNewMacro(VISU_GaussPtsAct); VISU_GaussPtsAct ::VISU_GaussPtsAct(): myGaussPointsPL(NULL), myTextMapper(vtkTextMapper::New()), - myTextActor(vtkTextActor::New()), + myTextActor(VISU_GPTextActor::New()), myLastObjPointID(-1), mySphereSource(vtkSphereSource::New()), mySphereMapper(vtkPolyDataMapper::New()), @@ -164,6 +251,7 @@ VISU_GaussPtsAct mySphereActor->SetPickable(false); // myCursorPyramid->Delete(); + } VISU_GaussPtsAct @@ -249,12 +337,7 @@ VISU_GaussPtsAct // To calculate display (2D) position of the annotation float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; - aRenderer->SetWorldPoint(aWorldCoord); - aRenderer->WorldToDisplay(); - float aSelectionPoint[3]; - aRenderer->GetDisplayPoint(aSelectionPoint); - myTextActor->SetPosition(aSelectionPoint); - + myTextActor->SetWorldPoint(aWorldCoord); // To prepare the annotation text std::ostringstream aStr; aStr<<"Global ID: "<GetVisibility(); @@ -350,8 +433,10 @@ VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector, float z2 = 0.0; bool isShift = theSelectionEvent.myIsShift; bool isRectangle = theSelectionEvent.myIsRectangle; - bool bRet=false; + bool bRet, bHasIO; // + bHasIO=hasIO(); + bRet=false; if( !isRectangle ) { myPointPicker->Pick( x1, y1, z1, aRenderer ); @@ -360,9 +445,9 @@ VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector, mySphereActor->SetVisibility(aSphereVisibility); return bRet; } - + // vtkIdType aVtkId = myPointPicker->GetPointId(); - if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO()) { + if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && bHasIO) { vtkIdType anObjId = GetNodeObjId( aVtkId ); // //double aCoeff=0.667; @@ -388,17 +473,15 @@ VISU_GaussPtsAct::Highlight( SVTK_Selector *theSelector, // // To calculate display (2D) position of the annotation float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; - aRenderer->SetWorldPoint(aWorldCoord); - aRenderer->WorldToDisplay(); - float aSelectionPoint[3]; - aRenderer->GetDisplayPoint(aSelectionPoint); - myTextActor->SetPosition(aSelectionPoint); + myTextActor->SetWorldPoint(aWorldCoord); // float aColor[3]={1.,1.,1.}; mySphereActor->GetProperty()->SetColor(aColor); - } - } + // + }// if( anObjId >= 0 ) { + }//if( aVtkId >= 0 && theSelector->IsValid( this, aVtkId, true ) && hasIO()) }// if( !isRectangle ) + // else { if( vtkDataSet* aDataSet = GetInput() ) { int i, aNbPnts; diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index 99f0c773..34c1f8c2 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -42,6 +42,7 @@ class vtkActor; class vtkInteractorStyle; class VISU_CursorPyramid; +class VISU_GPTextActor; class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct { @@ -78,12 +79,13 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct bool theIsHighlight ); protected: + VISU_GaussPtsAct(); virtual ~VISU_GaussPtsAct(); vtkSmartPointer myGaussPointsPL; vtkSmartPointer myTextMapper; - vtkSmartPointer myTextActor; + vtkSmartPointer myTextActor; vtkIdType myLastObjPointID; vtkSmartPointer mySphereSource; diff --git a/src/VVTK/VVTK_InteractorStyle.cxx b/src/VVTK/VVTK_InteractorStyle.cxx index da7b4bcf..617f8e54 100644 --- a/src/VVTK/VVTK_InteractorStyle.cxx +++ b/src/VVTK/VVTK_InteractorStyle.cxx @@ -32,7 +32,10 @@ #include #include #include +#include +#include +#include //---------------------------------------------------------------------------- vtkStandardNewMacro(VVTK_InteractorStyle); //---------------------------------------------------------------------------- @@ -169,3 +172,32 @@ VVTK_InteractorStyle startOperation(VTK_INTERACTOR_STYLE_CAMERA_NONE); } } + +//---------------------------------------------------------------------------- +void VVTK_InteractorStyle::onFinishOperation() +{ + int aNbObjWas, aNbObjNow; + // + aNbObjWas=GetSelector()->IObjectCount(); + // + SVTK_InteractorStyle::onFinishOperation(); + // + aNbObjNow=GetSelector()->IObjectCount(); + + if (aNbObjWas+aNbObjNow==1){ + double aScale, aCoeff; + vtkRenderer *aRenderer=GetCurrentRenderer(); + vtkCamera *aCamera = aRenderer->GetActiveCamera(); + // + aCoeff=0.667; + aScale = aCamera->GetParallelScale(); + // + if (!aNbObjWas && aNbObjNow) { + aCamera->SetParallelScale(aScale*aCoeff); + } + else { + aCoeff=1./aCoeff; + aCamera->SetParallelScale(aScale*aCoeff); + } + } +} diff --git a/src/VVTK/VVTK_InteractorStyle.h b/src/VVTK/VVTK_InteractorStyle.h index 2a958377..9690b9c7 100644 --- a/src/VVTK/VVTK_InteractorStyle.h +++ b/src/VVTK/VVTK_InteractorStyle.h @@ -57,6 +57,7 @@ class VVTK_EXPORT VVTK_InteractorStyle : public SVTK_InteractorStyle virtual void OnLeftButtonUp(int ctrl, int shift, int x, int y); virtual void OnMiddleButtonUp(int ctrl, int shift, int x, int y); virtual void OnKeyDown(); + virtual void onFinishOperation(); private: bool myIsMidButtonDown;