From 0f13fdf1427e1c3727536f4869e1def40b9a46a0 Mon Sep 17 00:00:00 2001 From: pkv Date: Tue, 6 Sep 2005 06:09:29 +0000 Subject: [PATCH] provides pass vtkInteractorStyle objrct to the methods Highlight(),Prehighlight() in order to be able to use the methods of the class vtkInteractorStyle --- src/OBJECT/VISU_Actor.cxx | 136 +++++++++++++++++++++++++++++++- src/OBJECT/VISU_Actor.h | 16 +++- src/OBJECT/VISU_GaussPtsAct.cxx | 19 +++-- src/OBJECT/VISU_GaussPtsAct.h | 3 +- 4 files changed, 162 insertions(+), 12 deletions(-) diff --git a/src/OBJECT/VISU_Actor.cxx b/src/OBJECT/VISU_Actor.cxx index 2814e57c..1b959f19 100644 --- a/src/OBJECT/VISU_Actor.cxx +++ b/src/OBJECT/VISU_Actor.cxx @@ -33,10 +33,19 @@ #include "VTKViewer_PassThroughFilter.h" #include +#include // VTK Includes #include - +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -72,7 +81,9 @@ VISU_Actor::VISU_Actor(): myMapper(vtkDataSetMapper::New()), myIsShrunk(false), myIsShrinkable(false), - myShrinkFilter(VTKViewer_ShrinkFilter::New()) + myShrinkFilter(VTKViewer_ShrinkFilter::New()), + myAnnotationMapper(vtkTextMapper::New()), + myAnnotationActor(vtkTextActor::New()) { SetDebug(MYVTKDEBUG); @@ -80,6 +91,11 @@ VISU_Actor::VISU_Actor(): myShrinkFilter->SetStoreMapping(true); SetShrinkFactor(); + + myAnnotationMapper->Delete(); + myAnnotationActor->Delete(); + myAnnotationActor->SetMapper(myAnnotationMapper.GetPointer()); + myAnnotationActor.GetPointer()->SetVisibility(0); } VISU_Actor::~VISU_Actor(){ @@ -299,3 +315,119 @@ VISU_Actor return myPipeLine->GetElemCell(theObjID); } + +//================================================================== +// function: PreHighlight +// purpose : +//================================================================== +bool VISU_Actor::PreHighlight( SVTK_Selector* theSelector, + vtkInteractorStyle *theIS, + SVTK_SelectionEvent theSelectionEvent, + bool theIsHighlight ) +{ + bool bRet, anIsChanged; + float x, y, z; + vtkIdType aVtkId; + + bRet=Superclass::PreHighlight(theSelector, + theIS, + theSelectionEvent, + theIsHighlight); + // + myAnnotationActor->SetVisibility(0); + // + anIsChanged = false; + x = theSelectionEvent.myX; + y = theSelectionEvent.myY; + z = 0.0; + vtkRenderer *aRenderer=theIS->GetCurrentRenderer(); + // + if(theIsHighlight) { + switch(mySelectionMode){ + case CellSelection:{ + myCellPicker->Pick(x, y, z, aRenderer); + //if(myCellPicker->GetActor() != this){ + // return false; + //} + aVtkId = myCellPicker->GetCellId(); + if (aVtkId >= 0 && + theSelector->IsValid( this, aVtkId, true ) && + hasIO() ) { + vtkIdType anObjId = GetElemObjId( aVtkId ); + vtkCell* pCell=GetElemCell(anObjId); + if (pCell){ + int aNbPnts, i, j; + float *aCoord, *aCoordX; + // + aNbPnts=pCell->GetNumberOfPoints(); + if (aNbPnts){ + aCoord=new float[3]; + for (j=0; j<3; ++j) { + aCoord[j]=0.; + } + // + vtkPoints * pPnts=pCell->GetPoints(); + for (i=0; iGetPoint(i); + for (j=0; j<3; ++j) { + aCoord[j]+=aCoordX[j]; + } + } + for (j=0; j<3; ++j) { + aCoord[j]/=aNbPnts; + } + //printf(" aVtkId=%d, x=%f, y=%f, {%f, %f, %f}\n", + // aVtkId, x, y, aCoord[0], aCoord[1], aCoord[2]); + // + // Display coordinates + float aWorldCoord[4] = {aCoord[0], aCoord[1], aCoord[2], 1.0}; + aRenderer->SetWorldPoint(aWorldCoord); + aRenderer->WorldToDisplay(); + float aSelectionPoint[3]; + aRenderer->GetDisplayPoint(aSelectionPoint); + myAnnotationActor->SetPosition(aSelectionPoint); + // + // To prepare the annotation text + std::ostringstream aStr; + aStr<<"Global ID: "<< anObjId; + std::string aString = aStr.str(); + myAnnotationMapper->SetInput(aString.c_str()); + + myAnnotationActor->SetVisibility(1); + + delete aCoord; + return true; + } + } + } + } + break; + case NodeSelection: + case EdgeOfCellSelection: + default: + break; + } + } + return bRet; + +} +//================================================================== +// function: AddToRender +// purpose : +//================================================================== +void VISU_Actor::AddToRender(vtkRenderer* theRenderer) +{ + + Superclass::AddToRender(theRenderer); + theRenderer->AddActor(myAnnotationActor.GetPointer()); +} +//================================================================== +// function: RemoveFromRender +// purpose : +//================================================================== +void VISU_Actor::RemoveFromRender(vtkRenderer* theRenderer) +{ + theRenderer->RemoveActor(myAnnotationActor.GetPointer()); + Superclass::RemoveFromRender(theRenderer); + +} diff --git a/src/OBJECT/VISU_Actor.h b/src/OBJECT/VISU_Actor.h index 478a6c07..13c736f2 100644 --- a/src/OBJECT/VISU_Actor.h +++ b/src/OBJECT/VISU_Actor.h @@ -32,11 +32,14 @@ #include "SALOME_Actor.h" #include +#include class vtkProp; class vtkProperty; class vtkDataSetMapper; - +class vtkTextMapper; +class vtkTextActor; +class vtkInteractorStyle; class VTKViewer_ShrinkFilter; class VISU_PipeLine; @@ -89,6 +92,15 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor virtual void SetLineWidth(float theLineWidth); virtual float GetLineWidth(); + virtual void AddToRender( vtkRenderer* ); + + virtual void RemoveFromRender( vtkRenderer* ); + + virtual bool PreHighlight( SVTK_Selector*, + vtkInteractorStyle*, + SVTK_SelectionEvent, + bool ); + virtual void SetVTKMapping(bool theIsVTKMapping); @@ -140,6 +152,8 @@ class VTKOCC_EXPORT VISU_Actor : public SALOME_Actor VTKViewer_ShrinkFilter* myShrinkFilter; bool myIsShrinkable; bool myIsShrunk; + vtkSmartPointer myAnnotationMapper; + vtkSmartPointer myAnnotationActor; }; #endif //VISU_ACTOR_H diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index 9788ee9b..9c1cf3c8 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -45,6 +45,7 @@ #include #include +#include #include @@ -114,16 +115,18 @@ VISU_GaussPtsAct bool VISU_GaussPtsAct ::PreHighlight( SVTK_Selector* theSelector, - vtkRenderer* theRenderer, + vtkInteractorStyle *theIS, SVTK_SelectionEvent theSelectionEvent, bool theIsHighlight ) { + vtkRenderer *aRenderer=theIS->GetCurrentRenderer(); + // myTextActor->SetVisibility(false); mySphereActor->SetVisibility(false); - if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) - return Superclass::PreHighlight(theSelector,theRenderer,theSelectionEvent,theIsHighlight); - + if(theSelectionEvent.mySelectionMode == ActorSelection || !theIsHighlight) { + return Superclass::PreHighlight(theSelector,theIS,theSelectionEvent,theIsHighlight); + } myPreHighlightActor->SetVisibility( false ); bool anIsSelectionModeChanged = (theSelectionEvent.mySelectionMode != mySelectionMode); @@ -142,7 +145,7 @@ VISU_GaussPtsAct case NodeSelection: case CellSelection: { - myPointPicker->Pick( x, y, z, theRenderer ); + myPointPicker->Pick( x, y, z, aRenderer ); if(myPointPicker->GetActor() != this) return false; @@ -157,10 +160,10 @@ VISU_GaussPtsAct // To calculate display (2D) position of the annotation float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.0}; - theRenderer->SetWorldPoint(aWorldCoord); - theRenderer->WorldToDisplay(); + aRenderer->SetWorldPoint(aWorldCoord); + aRenderer->WorldToDisplay(); float aSelectionPoint[3]; - theRenderer->GetDisplayPoint(aSelectionPoint); + aRenderer->GetDisplayPoint(aSelectionPoint); myTextActor->SetPosition(aSelectionPoint); // To prepare the annotation text diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index ae766a54..a2c3e299 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -39,6 +39,7 @@ class vtkTextActor; class vtkSphereSource; class vtkPolyDataMapper; class vtkActor; +class vtkInteractorStyle; class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct { @@ -64,7 +65,7 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_ScalarMapAct virtual bool PreHighlight( SVTK_Selector* theSelector, - vtkRenderer* theRenderer, + vtkInteractorStyle*, SVTK_SelectionEvent theSelectionEvent, bool theIsHighlight ); -- 2.39.2