From: apo Date: Thu, 15 Dec 2005 16:25:08 +0000 (+0000) Subject: Fix for Bug GVIEW10814 X-Git-Tag: TG-D5-38-2003_D2005-20-12~24 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2b5ac05b2273ce2e1523d7eff89fc5a9426832b3;p=modules%2Fvisu.git Fix for Bug GVIEW10814 size of the cursor is not modified when changing the magnification --- diff --git a/src/OBJECT/VISU_GaussPtsAct.cxx b/src/OBJECT/VISU_GaussPtsAct.cxx index d88d64cc..7260745c 100644 --- a/src/OBJECT/VISU_GaussPtsAct.cxx +++ b/src/OBJECT/VISU_GaussPtsAct.cxx @@ -203,6 +203,8 @@ VISU_GaussPtsAct Superclass::ShallowCopyPL(thePipeLine); UpdateInsideCursorSettings(); + + Highlight(isHighlighted()); } @@ -382,6 +384,73 @@ VISU_GaussPtsAct SetMapper(myMapper.GetPointer()); } + +//---------------------------------------------------------------------------- +namespace +{ + inline + float + GetRadius(vtkIdType theVTKID, + vtkDataArray *theScalarArray, + VISU_GaussPointsPL* theGaussPointsPL) + { + float aRadius = 0.5; + if(theGaussPointsPL->GetPSMapper()->GetPointSpriteMode() == 1) // Geometry mode + aRadius *= theGaussPointsPL->GetSize() * theGaussPointsPL->GetAverageCellSize(); + else if(theGaussPointsPL->GetBicolor()){ + float aVal = theScalarArray->GetTuple1(theVTKID); + if(aVal >= 0) + aRadius *= theGaussPointsPL->GetMaxSize(); + else + aRadius *= theGaussPointsPL->GetMinSize(); + aRadius *= theGaussPointsPL->GetAverageCellSize(); + }else + aRadius *= theGaussPointsPL->GetPointSize(theVTKID,theScalarArray); + + return aRadius; + } +} + +float +VISU_GaussPtsAct +::GetRadius(vtkIdType theVTKID, + vtkDataArray *theScalarArray) +{ + return ::GetRadius(theVTKID,theScalarArray,myDeviceActor->GetPipeLine()); +} + +//---------------------------------------------------------------------------- +float +VISU_GaussPtsAct +::GetMagnification(vtkIdType theObjID) +{ + return GetGaussPointsPL()->GetMagnification(); +} + + +//---------------------------------------------------------------------------- +namespace +{ + inline + float + GetClamp(VISU_GaussPointsPL* theGaussPointsPL) + { + float aClamp = theGaussPointsPL->GetClamp(); + if(theGaussPointsPL->GetPrimitiveType() == VISU_OpenGLPointSpriteMapper::GeomSphere) + return -aClamp; + return aClamp; + } +} + +float +VISU_GaussPtsAct +::GetClamp(vtkIdType theObjID) +{ + return ::GetClamp(GetGaussPointsPL()); +} + + +//---------------------------------------------------------------------------- void VISU_GaussPtsAct ::SetFactory(VISU::TActorFactory* theActorFactory) @@ -594,7 +663,6 @@ VISU_GaussPtsAct vtkDataSet* aDataSet = GetInput(); vtkCellData* aCellData = aDataSet->GetCellData(); if(vtkDataArray *aScalarArray = aCellData->GetScalars()){ - float aRadius = myGaussPointsPL->GetPointSize(aVtkId,aScalarArray) / 2.; float aPyramidHeight = myPickingSettings->GetPyramidHeight(); aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize(); //float aColor[3] = myPreHighlightActor->GetProperty()->GetColor(); @@ -604,7 +672,9 @@ VISU_GaussPtsAct aColor[1] = 1. - aColor[1]; aColor[2] = 1. - aColor[2]; myCursorPyramid->Init(aPyramidHeight, - aRadius, + GetRadius(aVtkId,aScalarArray), + GetMagnification(aVtkId), + GetClamp(anObjId), aNodeCoord, aColor); } @@ -654,6 +724,7 @@ VISU_GaussPtsAct SVTK_SelectionEvent* theSelectionEvent, bool theIsHighlight) { + myIsHighlighted = false; Handle(SALOME_InteractiveObject) anIO = getIO(); int anInitialHasIndex = mySelector->HasIndex(anIO); @@ -705,6 +776,7 @@ VISU_GaussPtsAct if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId, true ) && hasIO()) { vtkIdType anObjId = GetNodeObjId( aVtkId ); if(anObjId >= 0){ + myIsHighlighted = true; // Update the Selector if(mySelector->IsSelected(myIO)) mySelector->AddOrRemoveIndex(myIO,anObjId,theSelectionEvent->myIsShift); @@ -761,6 +833,9 @@ void VISU_GaussPtsAct ::Highlight(bool theIsHighlight) { + if(!mySelector.GetPointer()) + return; + myOutlineActor->SetVisibility(false); myTextActor->SetVisibility(0); myCursorPyramidSelected->SetVisibility(0); @@ -790,17 +865,14 @@ VISU_GaussPtsAct // vtkIdType aVtkId = GetNodeVTKID(anObjId); if(aVtkId >= 0){ - float *aNodeCoord, aVal, aRadius; - // - aNodeCoord = GetNodeCoord(anObjId); + float *aNodeCoord = GetNodeCoord(anObjId); float aWorldCoord[4] = {aNodeCoord[0], aNodeCoord[1], aNodeCoord[2], 1.}; // vtkDataSet* aDataSet = GetInput(); vtkCellData* aDataSetAttributes = aDataSet->GetCellData(); // if(vtkDataArray* aScalarArray = aDataSetAttributes->GetScalars()){ - aVal = aScalarArray->GetTuple1(aVtkId); - aRadius = myGaussPointsPL->GetPointSize(aVtkId, aScalarArray) / 2.; + float aVal = aScalarArray->GetTuple1(aVtkId); // GetScalarBarCtrl()->SetIsMarked(true); GetScalarBarCtrl()->SetMarkValue(aVal); @@ -809,7 +881,9 @@ VISU_GaussPtsAct float aPyramidHeight = myPickingSettings->GetPyramidHeight(); aPyramidHeight = aPyramidHeight*myGaussPointsPL->GetMaxPointSize(); myCursorPyramidSelected->Init(aPyramidHeight, - aRadius, + GetRadius(aVtkId,aScalarArray), + GetMagnification(aVtkId), + GetClamp(anObjId), aNodeCoord, myHighlightActor->GetProperty()->GetColor()); myCursorPyramidSelected->SetVisibility(anIsVisible && theIsHighlight); @@ -980,6 +1054,8 @@ VISU_GaussPtsAct aPipeline->Update(); + Highlight(isHighlighted()); + Update(); } @@ -1121,6 +1197,54 @@ VISU_GaussPtsAct1 } +//---------------------------------------------------------------------------- +float +VISU_GaussPtsAct1 +::GetRadius(vtkIdType theVTKID, + vtkDataArray *theScalarArray) +{ + VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine(); + if(myWidgetCtrl && myWidgetCtrl->GetEnabled()){ + if(myInsideDeviceActor->GetPipeLine()->GetElemObjID(theVTKID) < 0) + aPipeLine = myOutsideDeviceActor->GetPipeLine(); + else + aPipeLine = myInsideDeviceActor->GetPipeLine(); + } + return ::GetRadius(theVTKID,theScalarArray,aPipeLine); +} + + +//---------------------------------------------------------------------------- +float +VISU_GaussPtsAct1 +::GetMagnification(vtkIdType theObjID) +{ + VISU_GaussPointsPL* aPipeLine = myDeviceActor->GetPipeLine(); + if(myWidgetCtrl && myWidgetCtrl->GetEnabled()){ + if(myInsideDeviceActor->GetPipeLine()->GetElemVTKID(theObjID) < 0) + aPipeLine = myOutsideDeviceActor->GetPipeLine(); + else + aPipeLine = myInsideDeviceActor->GetPipeLine(); + } + return aPipeLine->GetMagnification(); +} + + +//---------------------------------------------------------------------------- +float +VISU_GaussPtsAct1 +::GetClamp(vtkIdType theObjID) +{ + if(myWidgetCtrl && myWidgetCtrl->GetEnabled()){ + if(myInsideDeviceActor->GetPipeLine()->GetElemVTKID(theObjID) < 0) + return ::GetClamp(myOutsideDeviceActor->GetPipeLine()); + else + return ::GetClamp(myInsideDeviceActor->GetPipeLine()); + } + return Superclass::GetClamp(theObjID); +} + + //---------------------------------------------------------------- void VISU_GaussPtsAct1 @@ -1225,6 +1349,8 @@ VISU_GaussPtsAct1 aPipeline->Update(); + Highlight(isHighlighted()); + Update(); } diff --git a/src/OBJECT/VISU_GaussPtsAct.h b/src/OBJECT/VISU_GaussPtsAct.h index d80787c8..eba81b9b 100644 --- a/src/OBJECT/VISU_GaussPtsAct.h +++ b/src/OBJECT/VISU_GaussPtsAct.h @@ -241,6 +241,22 @@ class VTKOCC_EXPORT VISU_GaussPtsAct : public VISU_Actor VISU_PipeLine* GetCurrentPL(); + //! To get current value of the radius of the Point Sprite + virtual + float + GetRadius(vtkIdType theVTKID, + vtkDataArray *theScalarArray); + + //! To get current value of the magnification + virtual + float + GetMagnification(vtkIdType theObjID); + + //! To get current value of the clamp + virtual + float + GetClamp(vtkIdType theObjID); + //---------------------------------------------------------------------------- vtkSmartPointer myEventCallbackCommand; @@ -363,6 +379,22 @@ class VTKOCC_EXPORT VISU_GaussPtsAct1 : public VISU_GaussPtsAct void SetMapperInput(vtkDataSet* theDataSet); + //! To get current value of the radius of the Point Sprite + virtual + float + GetRadius(vtkIdType theVTKID, + vtkDataArray *theScalarArray); + + //! To get current value of the magnification + virtual + float + GetMagnification(vtkIdType theObjID); + + //! To get current value of the clamp + virtual + float + GetClamp(vtkIdType theObjID); + //---------------------------------------------------------------------------- // Main process VTK event method static diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.cxx b/src/OBJECT/VISU_GaussPtsDeviceActor.cxx index c608b31d..8b780b10 100644 --- a/src/OBJECT/VISU_GaussPtsDeviceActor.cxx +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.cxx @@ -208,6 +208,8 @@ VISU_CursorPyramid ::VISU_CursorPyramid(): myHeight(10.0), myRadius(5.0), + myMagnification(1.0), + myClamp(256.0), myNbCones(6), myAppendFilter(vtkAppendPolyData::New()), myMapper(vtkPolyDataMapper::New()) @@ -232,6 +234,47 @@ void VISU_CursorPyramid ::Render(vtkRenderer *ren, vtkMapper *vtkNotUsed(m)) { + if (ren == NULL) + { + vtkErrorMacro("No mapper for actor."); + return; + } + + this->SetScale(1.0); + float aMRadius = myRadius*myMagnification; + Init(myHeight,aMRadius); + + if(myClamp > 0.0f){ + float aPoint1[3] = {0.0, 0.0, 0.0}; + ren->SetDisplayPoint(aPoint1); + ren->DisplayToWorld(); + ren->GetWorldPoint(aPoint1); + + float aPoint2[3] = {0.0, myClamp, 0.0}; + ren->SetDisplayPoint(aPoint2); + ren->DisplayToWorld(); + ren->GetWorldPoint(aPoint2); + + float aWorldClamp = + (aPoint2[0] - aPoint1[0])*(aPoint2[0] - aPoint1[0]) + + (aPoint2[1] - aPoint1[1])*(aPoint2[1] - aPoint1[1]) + + (aPoint2[2] - aPoint1[2])*(aPoint2[2] - aPoint1[2]); + + aWorldClamp = sqrt(aWorldClamp); + float aMDiameter = 2.0 * aMRadius; + float aCoeff = aWorldClamp / aMDiameter; + float aMagnification = aWorldClamp / 2.0 / myRadius; + /* + cout<<"aMDiameter = "<GetColor()); + Init(theHeight, myRadius, myMagnification, myClamp, GetPosition(), GetProperty()->GetColor()); } //---------------------------------------------------------------------------- @@ -295,16 +338,28 @@ void VISU_CursorPyramid ::Init(float theHeight, float theRadius, + float theMagnification, + float theClamp, float thePos[3], float theColor[3]) { + Init(theHeight,theRadius*theMagnification); SetPosition(thePos[0],thePos[1],thePos[2]); GetProperty()->SetColor(theColor); SetMapper(myMapper.GetPointer()); myHeight = theHeight; myRadius = theRadius; + myMagnification = theMagnification; + myClamp = theClamp; +} + +void +VISU_CursorPyramid +::Init(float theHeight, + float theRadius) +{ for(int i = 0; i < myNbCones; ++i){ vtkConeSource* aSource = mySources[i].GetPointer(); aSource->SetHeight(theHeight); diff --git a/src/OBJECT/VISU_GaussPtsDeviceActor.h b/src/OBJECT/VISU_GaussPtsDeviceActor.h index b2df8621..ba60a388 100644 --- a/src/OBJECT/VISU_GaussPtsDeviceActor.h +++ b/src/OBJECT/VISU_GaussPtsDeviceActor.h @@ -128,6 +128,8 @@ public: void Init(float theHeight, float theRadius, + float theMagnification, + float theClamp, float thePos[3], float theColor[3]); @@ -136,6 +138,10 @@ public: protected: VISU_CursorPyramid(); + void + Init(float theHeight, + float theRadius); + int myNbCones; vtkSmartPointer mySources[6]; vtkSmartPointer myAppendFilter; @@ -143,6 +149,8 @@ protected: // float myHeight; float myRadius; + float myMagnification; + float myClamp; private: VISU_CursorPyramid(const VISU_CursorPyramid&); // Not implemented diff --git a/src/PIPELINE/VISU_GaussPointsPL.cxx b/src/PIPELINE/VISU_GaussPointsPL.cxx index 1316b2f6..8d1d0dff 100644 --- a/src/PIPELINE/VISU_GaussPointsPL.cxx +++ b/src/PIPELINE/VISU_GaussPointsPL.cxx @@ -138,6 +138,7 @@ VISU_GaussPointsPL myPSMapper->SetInput(aDatsSet); SetPrimitiveType(aPipeLine->GetPrimitiveType()); + SetBicolor(aPipeLine->GetBicolor()); SetClamp(aPipeLine->GetClamp()); SetSize(aPipeLine->GetSize()); SetMinSize(aPipeLine->GetMinSize()); @@ -368,6 +369,9 @@ void VISU_GaussPointsPL ::SetBicolor(bool theBicolor) { + if(GetBicolor() == theBicolor) + return; + myMapperTable->SetBicolor( theBicolor ); myBarTable->SetBicolor( theBicolor );