]> OCCT Git - occt.git/commitdiff
0032135: Visualization - possibility to redefine zoom persistent scale compute in... CR32135
authordrochalo <diogo.lopes@opencascade.com>
Fri, 27 Oct 2023 08:59:40 +0000 (09:59 +0100)
committerdrochalo <diogo.lopes@opencascade.com>
Fri, 27 Oct 2023 08:59:40 +0000 (09:59 +0100)
Added scale factor to Graphic3d_TransformPers.
Added option to rescale objects with zoom persistence on vdisplay command.

src/Graphic3d/Graphic3d_TransformPers.cxx
src/Graphic3d/Graphic3d_TransformPers.hxx
src/ViewerTest/ViewerTest.cxx
tests/v3d/trsf/bug32135 [new file with mode: 0644]

index 5ec8514013330aea6e6bcf1f5e5caca9bccc5775..6cb42610ecbf04284b8127bb867faadf1514d43b 100644 (file)
@@ -45,6 +45,7 @@ void Graphic3d_TransformPers::DumpJson (Standard_OStream& theOStream, Standard_I
   OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
 
   OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMode)
+  OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myZoomPersScale)
 
   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myParams.Params3d)
   OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, &myParams.Params2d)
index e0db73b4e8f59ccbff1d5027731a63bf1937a0d5..13fca597aa90c8365bf2ad79162166cd98f2c43d 100644 (file)
@@ -62,7 +62,8 @@ public:
 
   //! Set transformation persistence.
   Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode)
-  : myMode (theMode)
+  : myMode (theMode),
+    myZoomPersScale(1.0)
   {
     if (IsZoomOrRotate (theMode))
     {
@@ -87,11 +88,24 @@ public:
   //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers.
   Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode,
                            const gp_Pnt& thePnt)
-  : myMode (Graphic3d_TMF_None)
+  : myMode (Graphic3d_TMF_None),
+    myZoomPersScale(1.0)
   {
     SetPersistence (theMode, thePnt);
   }
 
+  //! Set Zoom/Rotate transformation persistence with an anchor 3D point and a scaling factor for zoom persistence.
+  //! Anchor point defines the origin of Local Coordinate system within World Coordinate system.
+  //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers.
+  Graphic3d_TransformPers(const Graphic3d_TransModeFlags theMode,
+                          const gp_Pnt& thePnt,
+                          const Standard_Real theZoomPersScale)
+    : myMode(Graphic3d_TMF_None),
+      myZoomPersScale(1.0)
+  {
+    SetPersistence(theMode, thePnt, theZoomPersScale);
+  }
+
   //! Set 2d/trihedron transformation persistence with a corner and 2D offset.
   //! 2D offset defines the origin of Local Coordinate system as projection of 2D point on screen plane into World Coordinate system.
   //! Throws an exception if persistence mode is not Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d.
@@ -99,7 +113,8 @@ public:
   Graphic3d_TransformPers (const Graphic3d_TransModeFlags theMode,
                            const Aspect_TypeOfTriedronPosition theCorner,
                            const Graphic3d_Vec2i& theOffset = Graphic3d_Vec2i (0, 0))
-  : myMode (Graphic3d_TMF_None)
+  : myMode (Graphic3d_TMF_None),
+    myZoomPersScale(1.0)
   {
     SetPersistence (theMode, theCorner, theOffset);
   }
@@ -116,6 +131,9 @@ public:
   //! Transformation persistence mode flags.
   Graphic3d_TransModeFlags Flags() const { return myMode; }
 
+  //! Zoom persistence scale value.
+  Standard_Real ZoomPersScale() const { return myZoomPersScale; }
+
   //! Set Zoom/Rotate transformation persistence with an anchor 3D point.
   //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers.
   void SetPersistence (const Graphic3d_TransModeFlags theMode,
@@ -132,6 +150,24 @@ public:
     myParams.Params3d.PntZ = thePnt.Z();
   }
 
+  //! Set Zoom/Rotate transformation persistence with an anchor 3D point.
+  //! Throws an exception if persistence mode is not Graphic3d_TMF_ZoomPers, Graphic3d_TMF_ZoomRotatePers or Graphic3d_TMF_RotatePers.
+  void SetPersistence(const Graphic3d_TransModeFlags theMode,
+                      const gp_Pnt& thePnt,
+                      const Standard_Real theZoomPersScale)
+  {
+    if (!IsZoomOrRotate(theMode))
+    {
+      throw Standard_ProgramError("Graphic3d_TransformPers::SetPersistence(), wrong persistence mode.");
+    }
+
+    myMode = theMode;
+    myParams.Params3d.PntX = thePnt.X();
+    myParams.Params3d.PntY = thePnt.Y();
+    myParams.Params3d.PntZ = thePnt.Z();
+    myZoomPersScale = theZoomPersScale;
+  }
+
   //! Set 2d/trihedron transformation persistence with a corner and 2D offset.
   //! Throws an exception if persistence mode is not Graphic3d_TMF_TriedronPers or Graphic3d_TMF_2d.
   void SetPersistence (const Graphic3d_TransModeFlags theMode,
@@ -175,6 +211,17 @@ public:
     myParams.Params3d.PntZ = thePnt.Z();
   }
 
+  //! Set the scaling factor for zoom transformation persistence.
+  void SetZoomPersScale(const Standard_Real theZoomPersScale)
+  {
+    if (!IsZoomOrRotate())
+    {
+      throw Standard_ProgramError("Graphic3d_TransformPers::SetZoomPersScale(), wrong persistence mode.");
+    }
+
+    myZoomPersScale = theZoomPersScale;
+  }
+
   //! Return the corner for 2d/trihedron transformation persistence.
   Aspect_TypeOfTriedronPosition Corner2d() const
   {
@@ -238,7 +285,8 @@ public:
     gp_Vec aVecToObj (theCamera->Eye(), gp_Pnt (myParams.Params3d.PntX, myParams.Params3d.PntY, myParams.Params3d.PntZ));
     const Standard_Real aFocus = aVecToObj.Dot (aVecToEye);
     const gp_XYZ aViewDim = theCamera->ViewDimensions (aFocus);
-    return Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
+    //return Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
+    return myZoomPersScale > 0 ? Abs(aViewDim.Y()) / Standard_Real(aVPSizeY) * myZoomPersScale : Abs(aViewDim.Y()) / Standard_Real(aVPSizeY);
   }
 
   //! Apply transformation to bounding box of presentation.
@@ -332,6 +380,7 @@ private:
 private:
 
   Graphic3d_TransModeFlags myMode;  //!< Transformation persistence mode flags
+  Standard_Real myZoomPersScale;    //!< Scale factor for zoom persistence mode
   union
   {
     PersParams3d Params3d;
index 9fb0cfea5ac3144952f678c25a58352a4dc98f88..d7fe7d82d20c16c5ddffe86cad6b1459d0ea16ce 100644 (file)
@@ -5100,6 +5100,26 @@ static int VDisplay2 (Draw_Interpretor& theDI,
         aTrsfPers = new Graphic3d_TransformPers (aTrsfPers->Mode(), Aspect_TypeOfTriedronPosition (aCorner), Graphic3d_Vec2i (aZ.IntegerValue()));
       }
     }
+    else if (aNameCase == "-trsfperszoom")
+    {
+      if (anArgIter + 1 >= theArgNb
+        || aTrsfPers.IsNull())
+      {
+        Message::SendFail() << "Error: wrong syntax at " << aName << ".";
+        return 1;
+      }
+
+      TCollection_AsciiString aZoomScaleFactor(theArgVec[++anArgIter]);
+      if (!aZoomScaleFactor.IsRealValue(Standard_True))
+      {
+        Message::SendFail() << "Error: wrong syntax at " << aName << ".";
+        return 1;
+      }
+      if (aTrsfPers->IsZoomOrRotate())
+      {
+        aTrsfPers->SetZoomPersScale(aZoomScaleFactor.RealValue());
+      }
+    }
     else if (aNameCase == "-layer"
           || aNameCase == "-zlayer")
     {
diff --git a/tests/v3d/trsf/bug32135 b/tests/v3d/trsf/bug32135
new file mode 100644 (file)
index 0000000..e973d13
--- /dev/null
@@ -0,0 +1,23 @@
+puts "========"
+puts "0032135: Visualization - possibility to redefine zoom persistent scale compute in Graphic3d_TransformPers"
+puts "========"
+
+pload ALL
+vclear
+vinit
+box b 10 10 10
+#display box with zoompersistence and a predefined scale
+#test if zoom changes the box position
+vdisplay b -dispmode 1 -trsfPers zoom
+vzoom 5
+if { [vreadpixel 210 200 -rgb -name] != "DARKGOLDENROD" } { puts "Error" }
+if { [vreadpixel 210 210 -rgb -name] != "BLACK" } { puts "Error" }
+
+vdump ${imagedir}/${casename}_1.png
+
+#display box with zoom persistence but with a bigger scale
+vzoom 0.2
+vdisplay b -dispmode 1 -trsfPers zoom -trsfperszoom 5.0
+if { [vreadpixel 230 215 -rgb -name] != "DARKGOLDENROD" } { puts "Error" }
+
+vdump ${imagedir}/${casename}_2.png
\ No newline at end of file