From: apo Date: Mon, 14 Nov 2005 12:43:08 +0000 (+0000) Subject: To implement caching of highlight / prehighlight functionality X-Git-Tag: BR-D5-38-2003_D2005-24-11~6 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e72d110e4d5a0b873124d85d229f1c9d4dcbd514;p=modules%2Fgui.git To implement caching of highlight / prehighlight functionality --- diff --git a/src/SVTK/SALOME_Actor.cxx b/src/SVTK/SALOME_Actor.cxx index 646344064..c7b744bc5 100644 --- a/src/SVTK/SALOME_Actor.cxx +++ b/src/SVTK/SALOME_Actor.cxx @@ -89,7 +89,7 @@ namespace vtkPicker* thePicker, int theObjId) { - int anEdgeId = -1; + int anEdgeId = 0; if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) { float aPickPosition[3]; thePicker->GetPickPosition(aPickPosition); @@ -100,7 +100,7 @@ namespace aLine->EvaluatePosition(aPickPosition,closestPoint,subId,pcoords,aDist,weights); if (aDist < aMinDist) { aMinDist = aDist; - anEdgeId = i; + anEdgeId = -1 - i; } } } @@ -802,7 +802,8 @@ SALOME_Actor vtkRenderer *aRenderer = theInteractorStyle->GetCurrentRenderer(); // myPreHighlightActor->SetVisibility( false ); - + bool anIsPreselected = myIsPreselected; + Selection_Mode aSelectionMode = theSelectionEvent->mySelectionMode; bool anIsChanged = (mySelectionMode != aSelectionMode); @@ -819,7 +820,6 @@ SALOME_Actor if( anActor->hasIO() && myIO->isSame( anActor->getIO() ) ) anActor->SetPreSelected( false ); - anIsChanged = true; }else{ switch(aSelectionMode){ case NodeSelection: @@ -829,16 +829,19 @@ SALOME_Actor int aVtkId = myPointPicker->GetPointId(); if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) ) { int anObjId = GetNodeObjId( aVtkId ); - if ( anObjId >= 0 ) { - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( anObjId ); - - myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); - myPreHighlightActor->SetVisibility( true ); - myPreHighlightActor->MapPoints( this, aMapIndex ); - - myIsPreselected = theIsHighlight; - anIsChanged = true; + myIsPreselected = (anObjId >= 0); + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1)); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToPoints(); + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapPoints( this, aMapIndex ); + } } } break; @@ -854,16 +857,19 @@ SALOME_Actor if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) && hasIO() ) { int anObjId = GetElemObjId (aVtkId ); if ( anObjId >= 0 ) { - if ( CheckDimensionId(aSelectionMode,this,anObjId) ) { - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( anObjId ); - - myPreHighlightActor->GetProperty()->SetRepresentationToSurface(); - myPreHighlightActor->SetVisibility( true ); - myPreHighlightActor->MapCells( this, aMapIndex ); - - myIsPreselected = theIsHighlight; - anIsChanged = true; + myIsPreselected = CheckDimensionId(aSelectionMode,this,anObjId); + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent == 0 || anExtent > 0 && anObjId != aMapIndex(1)); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + + myPreHighlightActor->GetProperty()->SetRepresentationToSurface(); + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapCells( this, aMapIndex ); + } } } } @@ -878,16 +884,22 @@ SALOME_Actor int anObjId = GetElemObjId( aVtkId ); if ( anObjId >= 0 ) { int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId); - TColStd_IndexedMapOfInteger aMapIndex; - aMapIndex.Add( anObjId ); - aMapIndex.Add( anEdgeId ); + myIsPreselected = anEdgeId < 0; + if(myIsPreselected){ + const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex(); + int anExtent = aMapIndex.Extent(); + anIsChanged |= (anExtent != 2); + anIsChanged |= (anExtent == 0 && (anObjId != aMapIndex(1) || anEdgeId != aMapIndex(2))); + if(anIsChanged){ + TColStd_IndexedMapOfInteger aMapIndex; + aMapIndex.Add( anObjId ); + aMapIndex.Add( anEdgeId ); - myPreHighlightActor->GetProperty()->SetRepresentationToWireframe(); - myPreHighlightActor->SetVisibility( true ); - myPreHighlightActor->MapEdge( this, aMapIndex ); - - myIsPreselected = theIsHighlight; - anIsChanged = true; + myPreHighlightActor->GetProperty()->SetRepresentationToWireframe(); + myPreHighlightActor->SetVisibility( true ); + myPreHighlightActor->MapEdge( this, aMapIndex ); + } + } } } break; @@ -906,7 +918,6 @@ SALOME_Actor anActor->SetPreSelected( true ); } } - anIsChanged = true; } default: break; @@ -914,6 +925,7 @@ SALOME_Actor } mySelectionMode = aSelectionMode; + anIsChanged |= (anIsPreselected != myIsPreselected); return anIsChanged; } diff --git a/src/SVTK/SVTK_Actor.cxx b/src/SVTK/SVTK_Actor.cxx index 16faf1791..b633626b2 100644 --- a/src/SVTK/SVTK_Actor.cxx +++ b/src/SVTK/SVTK_Actor.cxx @@ -42,7 +42,10 @@ static int MYDEBUG = 0; #endif -static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet){ +static +void +CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSet) +{ vtkPoints *aPoints = vtkPoints::New(); vtkIdType iEnd = theSourceDataSet->GetNumberOfPoints(); aPoints->SetNumberOfPoints(iEnd); @@ -57,7 +60,8 @@ static void CopyPoints(vtkUnstructuredGrid* theGrid, vtkDataSet *theSourceDataSe vtkStandardNewMacro(SVTK_Actor); -SVTK_Actor::SVTK_Actor() +SVTK_Actor +::SVTK_Actor() { if(MYDEBUG) INFOS("SVTK_Actor - "<SetShrinkFactor(theValue); Modified(); } -void SVTK_Actor::SetShrink() +void +SVTK_Actor +::SetShrink() { if ( !myIsShrinkable ) return; if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) @@ -97,7 +106,9 @@ void SVTK_Actor::SetShrink() } } -void SVTK_Actor::UnShrink() +void +SVTK_Actor +::UnShrink() { if ( !myIsShrunk ) return; if ( vtkDataSet* aDataSet = myPassFilter[0]->GetOutput() ) @@ -111,7 +122,8 @@ void SVTK_Actor::UnShrink() //---------------------------------------------------------------------------- -SVTK_Actor::~SVTK_Actor() +SVTK_Actor +::~SVTK_Actor() { if(MYDEBUG) INFOS("~SVTK_Actor()"); @@ -126,8 +138,19 @@ SVTK_Actor::~SVTK_Actor() //---------------------------------------------------------------------------- -void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +const TColStd_IndexedMapOfInteger& +SVTK_Actor +::GetMapIndex() const +{ + return myMapIndex; +} + + +//---------------------------------------------------------------------------- +void +SVTK_Actor +::MapCells(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { myUnstructuredGrid->Reset(); @@ -139,10 +162,6 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, int aPartId = theMapIndex( ind ); vtkCell* aCell = theMapActor->GetElemCell(aPartId); myUnstructuredGrid->InsertNextCell(aCell->GetCellType(),aCell->GetPointIds()); - //for (int i = 0, iEnd = aCell->GetNumberOfEdges(); i < iEnd; i++){ - // vtkCell* anEdgeCell = aCell->GetEdge(i); - // myUnstructuredGrid->InsertNextCell(VTK_LINE,anEdgeCell->GetPointIds()); - //} } UnShrink(); @@ -150,12 +169,16 @@ void SVTK_Actor::MapCells(SALOME_Actor* theMapActor, SetShrinkFactor(theMapActor->GetShrinkFactor()); SetShrink(); } + + myMapIndex = theMapIndex; } //---------------------------------------------------------------------------- -void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapPoints(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { myUnstructuredGrid->Reset(); if(int aNbOfParts = theMapIndex.Extent()){ @@ -172,12 +195,16 @@ void SVTK_Actor::MapPoints(SALOME_Actor* theMapActor, } UnShrink(); + + myMapIndex = theMapIndex; } //---------------------------------------------------------------------------- -void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, - const TColStd_IndexedMapOfInteger& theMapIndex) +void +SVTK_Actor +::MapEdge(SALOME_Actor* theMapActor, + const TColStd_IndexedMapOfInteger& theMapIndex) { myUnstructuredGrid->Reset(); @@ -227,6 +254,8 @@ void SVTK_Actor::MapEdge(SALOME_Actor* theMapActor, SetShrinkFactor(theMapActor->GetShrinkFactor()); SetShrink(); } + + myMapIndex = theMapIndex; } //---------------------------------------------------------------------------- diff --git a/src/SVTK/SVTK_Actor.h b/src/SVTK/SVTK_Actor.h index 74a883a1a..d43ca24d6 100644 --- a/src/SVTK/SVTK_Actor.h +++ b/src/SVTK/SVTK_Actor.h @@ -56,10 +56,14 @@ public: void MapEdge(SALOME_Actor* theMapActor, const TColStd_IndexedMapOfInteger& theMapIndex); + const TColStd_IndexedMapOfInteger& + GetMapIndex() const; + protected: + TColStd_IndexedMapOfInteger myMapIndex; + vtkUnstructuredGrid* myUnstructuredGrid; vtkDataSetMapper* myMapper; - vtkRenderer* myRenderer; vtkShrinkFilter* myShrinkFilter; diff --git a/src/SVTK/SVTK_InteractorStyle.cxx b/src/SVTK/SVTK_InteractorStyle.cxx index b2e4b60e0..2f8100b57 100644 --- a/src/SVTK/SVTK_InteractorStyle.cxx +++ b/src/SVTK/SVTK_InteractorStyle.cxx @@ -72,10 +72,6 @@ static int MYDEBUG = 0; static int MYDEBUG = 0; #endif -static - bool GetFirstSALOMEActor(vtkPicker *pPicker, - SALOME_Actor*& pSA); - namespace { inline @@ -87,7 +83,29 @@ namespace theInteractor->GetEventPosition(theX,theY); theY = theInteractor->GetSize()[1] - theY - 1; } -} + + //================================================================== + // function : GetFirstSALOMEActor + // purpose : + //================================================================== + struct THaveIO + { + bool + operator()(SALOME_Actor* theActor) + { + return theActor->hasIO(); + } + }; + + inline + SALOME_Actor* + GetFirstSALOMEActor(vtkPicker *thePicker) + { + return VTK::Find(thePicker->GetActors(),THaveIO()); + } +} + + //---------------------------------------------------------------------------- vtkStandardNewMacro(SVTK_InteractorStyle); //---------------------------------------------------------------------------- @@ -95,7 +113,9 @@ vtkStandardNewMacro(SVTK_InteractorStyle); SVTK_InteractorStyle ::SVTK_InteractorStyle(): mySelectionEvent(new SVTK_SelectionEvent()), - myPicker(vtkPicker::New()) + myPicker(vtkPicker::New()), + myLastHighlitedActor(NULL), + myLastPreHighlitedActor(NULL) { myPicker->Delete(); @@ -895,20 +915,17 @@ SVTK_InteractorStyle 0.0, GetCurrentRenderer()); // - SALOME_Actor* aSActor=NULL; - // - GetFirstSALOMEActor(myPicker.GetPointer(), aSActor); - if (aSActor){ - //if(SALOME_Actor* aSActor = SALOME_Actor::SafeDownCast(myPicker->GetActor())){ - if(aSActor->hasIO()){ - aSelectionEvent->myIsRectangle = false; - aSActor->Highlight( this, aSelectionEvent, true ); - } - } - else{ + SALOME_Actor* anActor = GetFirstSALOMEActor(myPicker.GetPointer()); + aSelectionEvent->myIsRectangle = false; + if(anActor){ + anActor->Highlight( this, aSelectionEvent, true ); + }else{ + if(myLastHighlitedActor && myLastHighlitedActor != anActor) + myLastHighlitedActor->Highlight( this, aSelectionEvent, false ); GetSelector()->ClearIObjects(); } - } + myLastHighlitedActor = anActor; + } else { //processing rectangle selection Interactor->StartPickCallback(); @@ -1021,24 +1038,22 @@ SVTK_InteractorStyle this->FindPokedRenderer(aSelectionEvent->myX,aSelectionEvent->myY); bool anIsChanged = false; - SALOME_Actor *aLastActor=NULL; - // - GetFirstSALOMEActor(myPicker.GetPointer(), aLastActor); - if (aLastActor){ - anIsChanged |= aLastActor->PreHighlight( this, aSelectionEvent, false ); - } + myPicker->Pick(aSelectionEvent->myX, aSelectionEvent->myY, 0.0, GetCurrentRenderer()); - SALOME_Actor *anActor=NULL; - // - GetFirstSALOMEActor(myPicker.GetPointer(), anActor); + SALOME_Actor *anActor = GetFirstSALOMEActor(myPicker.GetPointer()); if (anActor){ anIsChanged |= anActor->PreHighlight( this, aSelectionEvent, true ); } - + + if(myLastPreHighlitedActor && myLastPreHighlitedActor != anActor) + anIsChanged |= myLastPreHighlitedActor->PreHighlight( this, aSelectionEvent, false ); + + myLastPreHighlitedActor = anActor; + if(anIsChanged) this->Render(); } @@ -1317,31 +1332,3 @@ SVTK_InteractorStyle void SVTK_InteractorStyle::OnChar() { } -//================================================================== -// function : GetFirstSALOMEActor -// purpose : -//================================================================== -bool GetFirstSALOMEActor(vtkPicker *pPicker, - SALOME_Actor*& pSA) -{ - bool bRet=false; - pSA=NULL; - vtkActor *pA; - // - vtkActorCollection *pActors=pPicker->GetActors(); - // - pActors->InitTraversal(); - while(1) { - pA=pActors->GetNextActor(); - if (!pA) { - break; - } - // - pSA=SALOME_Actor::SafeDownCast(pA); - if (pSA){ - bRet=!bRet; - break; - } - } - return bRet; -} diff --git a/src/SVTK/SVTK_InteractorStyle.h b/src/SVTK/SVTK_InteractorStyle.h index 5667a42cb..a97480dde 100644 --- a/src/SVTK/SVTK_InteractorStyle.h +++ b/src/SVTK/SVTK_InteractorStyle.h @@ -46,6 +46,8 @@ class vtkCell; class vtkPicker; +class SALOME_Actor; + class SVTK_Selector; class SVTK_GenericRenderWindowInteractor; @@ -225,6 +227,9 @@ class SVTK_EXPORT SVTK_InteractorStyle: public vtkInteractorStyle bool myShiftState; int ForcedState; + SALOME_Actor* myLastHighlitedActor; + SALOME_Actor* myLastPreHighlitedActor; + //! "Increment" for pan/rotate/zoom operations int mySpeedIncrement;