1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

Compare commits

...

1 Commits

Author SHA1 Message Date
drochalo
bfed908c8f 0032135: Visualization - possibility to redefine zoom persistent scale compute in Graphic3d_TransformPers
Added scale factor to Graphic3d_TransformPers.
Added option to rescale objects with zoom persistence on vdisplay command.
2023-10-27 09:59:40 +01:00
4 changed files with 97 additions and 4 deletions

View 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)

View 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;

View 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")
{

23
tests/v3d/trsf/bug32135 Normal file
View File

@@ -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