]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Fix for Bug GVIEW10814
authorapo <apo@opencascade.com>
Thu, 15 Dec 2005 16:25:08 +0000 (16:25 +0000)
committerapo <apo@opencascade.com>
Thu, 15 Dec 2005 16:25:08 +0000 (16:25 +0000)
  size of the cursor is not modified when changing the magnification

src/OBJECT/VISU_GaussPtsAct.cxx
src/OBJECT/VISU_GaussPtsAct.h
src/OBJECT/VISU_GaussPtsDeviceActor.cxx
src/OBJECT/VISU_GaussPtsDeviceActor.h
src/PIPELINE/VISU_GaussPointsPL.cxx

index d88d64ccb8a4602d589db4af455b0b28b63ea900..7260745c8f1d2f3e2a350758d7ee86399303b4e8 100644 (file)
@@ -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();
 }
 
index d80787c83a24a2ceea6ad15acab6b5e9f53f9fed..eba81b9b534b7abd71ddcca6a5acdacaaedfe867 100644 (file)
@@ -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<vtkCallbackCommand> 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
index c608b31d78fa0619577e33d861002f6347b50c88..8b780b10069cab393c9de1de8fb97b810ce55a2a 100644 (file)
@@ -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 = "<<aMDiameter<<"; aCoeff = "<<aCoeff<<
+      "; myMagnification = "<<myMagnification<<"; aMagnification = "<<aMagnification<<endl;
+    */
+    if(aCoeff < 1.0){
+      this->SetScale(aCoeff);
+      if(aMagnification > myMagnification)
+       Init(myHeight/aCoeff,aMRadius);
+    }
+  }
+
   if (this->Mapper == NULL)
     {
     vtkErrorMacro("No mapper for actor.");
@@ -287,7 +330,7 @@ void
 VISU_CursorPyramid
 ::SetHeight(float theHeight)
 {
-  Init(theHeight, myRadius, GetPosition(), GetProperty()->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);
index b2df8621c8c87411f44b249c465ca157352f6d81..ba60a38859d8ebeb0d1f7f5c5d335ed8d0f86c32 100644 (file)
@@ -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<vtkConeSource> mySources[6];
   vtkSmartPointer<vtkAppendPolyData> myAppendFilter;
@@ -143,6 +149,8 @@ protected:
   //
   float myHeight;
   float myRadius;
+  float myMagnification;
+  float myClamp;
 
  private:
   VISU_CursorPyramid(const VISU_CursorPyramid&); // Not implemented
index 1316b2f679c4a740775044bfd9fda6437bcdb75d..8d1d0dff678a95319de15b0e816b5d19e30b9478 100644 (file)
@@ -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 );