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

0027536: Visualization - incorrect behavior of zoom persisted objects

1) Zoom persistence mode now fixes object in pixel coordinates and  is independent on view size

2) Used gp_GTrsf instead of gp_Trsf SelectMgr_ViewerSelector to store  Graphic3d_Mat4d

3) Zoom persisted objects changed behavior (become bigger) therefore test cases were updated according to new state.

4) Corrected scale for rectangular frustum

Updated test for manipulator
This commit is contained in:
aba
2016-06-01 18:37:51 +03:00
committed by bugmaster
parent be5c360207
commit 91d9637224
44 changed files with 250 additions and 101 deletions

View File

@@ -117,6 +117,16 @@ void SelectMgr_BaseFrustum::SetWindowSize (const Standard_Integer theWidth, cons
myBuilder->SetWindowSize (theWidth, theHeight);
}
//=======================================================================
// function : WindowSize
// purpose :
//=======================================================================
void SelectMgr_BaseFrustum::WindowSize (Standard_Integer& theWidth,
Standard_Integer& theHeight)
{
myBuilder->WindowSize (theWidth, theHeight);
}
//=======================================================================
// function : SetBuilder
// purpose :

View File

@@ -16,6 +16,7 @@
#ifndef _SelectMgr_BaseFrustum_HeaderFile
#define _SelectMgr_BaseFrustum_HeaderFile
#include <gp_GTrsf.hxx>
#include <gp_Pnt.hxx>
#include <gp_Pln.hxx>
@@ -70,6 +71,9 @@ public:
Standard_EXPORT void SetWindowSize (const Standard_Integer theWidth,
const Standard_Integer theHeight);
Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
Standard_Integer& theHeight);
//! Passes viewport parameters to builder
Standard_EXPORT void SetViewport (const Standard_Real theX,
const Standard_Real theY,
@@ -102,8 +106,8 @@ public:
//! There are no default parameters, but in case if:
//! - transformation only is needed: @theScaleFactor must be initialized as any negative value;
//! - scale only is needed: @theTrsf must be set to gp_Identity.
virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer /*theScaleFactor*/,
const gp_Trsf& /*theTrsf*/) { return NULL; }
Standard_EXPORT virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer /*theScaleFactor*/,
const gp_GTrsf& /*theTrsf*/) { return NULL; }
//! SAT intersection test between defined volume and given axis-aligned box
Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theBoxMin,

View File

@@ -114,6 +114,17 @@ void SelectMgr_FrustumBuilder::SetViewport (const Standard_Real theX,
myIsViewportSet = Standard_True;
}
//=======================================================================
// function : WindowSize
// purpose :
//=======================================================================
void SelectMgr_FrustumBuilder::WindowSize (Standard_Integer& theWidth,
Standard_Integer& theHeight)
{
theWidth = myWidth;
theHeight = myHeight;
}
//=======================================================================
// function : InvalidateViewport
// purpose :

View File

@@ -62,6 +62,9 @@ public:
Standard_EXPORT void InvalidateViewport();
Standard_EXPORT void WindowSize (Standard_Integer& theWidth,
Standard_Integer& theHeight);
//! Calculates signed distance between plane with equation
//! theEq and point thePnt
Standard_EXPORT Standard_Real SignedPlanePntDist (const SelectMgr_Vec3& theEq,

View File

@@ -323,7 +323,7 @@ void SelectMgr_RectangularFrustum::Build (const gp_Pnt2d& theMinPnt,
// - scale only is needed: @theTrsf must be set to gp_Identity.
// =======================================================================
NCollection_Handle<SelectMgr_BaseFrustum> SelectMgr_RectangularFrustum::ScaleAndTransform (const Standard_Integer theScaleFactor,
const gp_Trsf& theTrsf)
const gp_GTrsf& theTrsf)
{
Standard_ASSERT_RAISE (theScaleFactor > 0,
"Error! Pixel tolerance for selection should be greater than zero");
@@ -357,26 +357,24 @@ NCollection_Handle<SelectMgr_BaseFrustum> SelectMgr_RectangularFrustum::ScaleAnd
if (isToTrsf)
{
aRes->myNearPickedPnt = aRef->myNearPickedPnt.Transformed (theTrsf);
aRes->myFarPickedPnt = aRef->myFarPickedPnt.Transformed (theTrsf);
const Standard_Real aRefScale = aRef->myFarPickedPnt.SquareDistance (aRef->myNearPickedPnt);
gp_Pnt aPoint = aRef->myNearPickedPnt;
theTrsf.Transforms (aPoint.ChangeCoord());
aRes->myNearPickedPnt = aPoint;
aPoint.SetXYZ (aRef->myFarPickedPnt.XYZ());
theTrsf.Transforms (aPoint.ChangeCoord());
aRes->myFarPickedPnt = aPoint;
aRes->myViewRayDir = aRes->myFarPickedPnt.XYZ() - aRes->myNearPickedPnt.XYZ();
// LeftTopNear
aRes->myVertices[0] = aRef->myVertices[0].Transformed (theTrsf);
// LeftTopFar
aRes->myVertices[1] = aRef->myVertices[1].Transformed (theTrsf);
// LeftBottomNear
aRes->myVertices[2] = aRef->myVertices[2].Transformed (theTrsf);
// LeftBottomFar
aRes->myVertices[3] = aRef->myVertices[3].Transformed (theTrsf);
// RightTopNear
aRes->myVertices[4] = aRef->myVertices[4].Transformed (theTrsf);
// RightTopFar
aRes->myVertices[5] = aRef->myVertices[5].Transformed (theTrsf);
// RightBottomNear
aRes->myVertices[6] = aRef->myVertices[6].Transformed (theTrsf);
// RightBottomFar
aRes->myVertices[7] = aRef->myVertices[7].Transformed (theTrsf);
for (Standard_Integer anIt = 0; anIt < 8; anIt++)
{
aPoint = aRef->myVertices[anIt];
theTrsf.Transforms (aPoint.ChangeCoord());
aRes->myVertices[anIt] = aPoint;
}
// Horizontal
aRes->myEdgeDirs[0] = aRes->myVertices[4].XYZ() - aRes->myVertices[0].XYZ();
@@ -391,7 +389,8 @@ NCollection_Handle<SelectMgr_BaseFrustum> SelectMgr_RectangularFrustum::ScaleAnd
// RightUpper
aRes->myEdgeDirs[5] = aRes->myVertices[4].XYZ() - aRes->myVertices[5].XYZ();
aRes->myScale = 1.0 / theTrsf.ScaleFactor();
// Compute scale to transform depth from local coordinate system to world coordinate system
aRes->myScale = Sqrt (aRefScale / aRes->myFarPickedPnt.SquareDistance (aRes->myNearPickedPnt));
}
// compute frustum normals

View File

@@ -51,7 +51,7 @@ public:
//! - transformation only is needed: @theScaleFactor must be initialized as any negative value;
//! - scale only is needed: @theTrsf must be set to gp_Identity.
Standard_EXPORT virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer theScaleFactor,
const gp_Trsf& theTrsf) Standard_OVERRIDE;
const gp_GTrsf& theTrsf) Standard_OVERRIDE;
// SAT Tests for different objects

View File

@@ -119,6 +119,8 @@ Standard_Boolean SelectMgr_SelectableObjectTrsfPersSet::Remove (const Handle(Sel
const NCollection_Handle<BVH_Tree<Standard_Real, 3> >&
SelectMgr_SelectableObjectTrsfPersSet::BVH (const Graphic3d_Mat4d& theProjectionMatrix,
const Graphic3d_Mat4d& theWorldViewMatrix,
const Standard_Integer theViewportWidth,
const Standard_Integer theViewportHeight,
const Graphic3d_WorldViewProjState& theWVPState)
{
if (!myIsDirty && (myObjectBoxesState.IsValid() && !myObjectBoxesState.IsChanged(theWVPState)))
@@ -139,7 +141,7 @@ const NCollection_Handle<BVH_Tree<Standard_Real, 3> >&
anObject->BoundingBox (aBoundingBox);
if (!aBoundingBox.IsVoid())
{
anObject->TransformPersistence().Apply (theProjectionMatrix, theWorldViewMatrix, 0, 0, aBoundingBox);
anObject->TransformPersistence().Apply (theProjectionMatrix, theWorldViewMatrix, theViewportWidth, theViewportHeight, aBoundingBox);
}
}

View File

@@ -87,6 +87,8 @@ public:
//! Returns BVH tree for the given world view projection (builds it if necessary).
Standard_EXPORT const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& BVH (const Graphic3d_Mat4d& theProjectionMatrix,
const Graphic3d_Mat4d& theWorldViewMatrix,
const Standard_Integer theViewportWidth,
const Standard_Integer theViewportHeight,
const Graphic3d_WorldViewProjState& theWVPState);
private:

View File

@@ -44,7 +44,7 @@ SelectMgr_SelectingVolumeManager::SelectMgr_SelectingVolumeManager (Standard_Boo
// - scale only is needed: @theTrsf must be set to gp_Identity.
//=======================================================================
SelectMgr_SelectingVolumeManager SelectMgr_SelectingVolumeManager::ScaleAndTransform (const Standard_Integer theScaleFactor,
const gp_Trsf& theTrsf)
const gp_GTrsf& theTrsf)
{
SelectMgr_SelectingVolumeManager aMgr (Standard_False);
@@ -137,6 +137,15 @@ const Graphic3d_WorldViewProjState& SelectMgr_SelectingVolumeManager::WorldViewP
return mySelectingVolumes[Frustum]->WorldViewProjState();
}
//=======================================================================
// function : WindowSize
// purpose :
//=======================================================================
void SelectMgr_SelectingVolumeManager::WindowSize (Standard_Integer& theWidth, Standard_Integer& theHeight)
{
mySelectingVolumes[Frustum]->WindowSize (theWidth, theHeight);
}
//=======================================================================
// function : SetCamera
// purpose : Updates viewport in all selecting volumes

View File

@@ -47,7 +47,7 @@ public:
//! - transformation only is needed: @theScaleFactor must be initialized as any negative value;
//! - scale only is needed: @theTrsf must be set to gp_Identity.
Standard_EXPORT virtual SelectMgr_SelectingVolumeManager ScaleAndTransform (const Standard_Integer theScaleFactor,
const gp_Trsf& theTrsf);
const gp_GTrsf& theTrsf);
Standard_EXPORT virtual Standard_Integer GetActiveSelectionType() const Standard_OVERRIDE;
@@ -68,6 +68,8 @@ public:
//! @return current world view transformation common for all selecting volumes
Standard_EXPORT const Graphic3d_Mat4d& WorldViewMatrix() const;
Standard_EXPORT void WindowSize (Standard_Integer& theWidth, Standard_Integer& theHeight);
//! @return current camera world view projection transformation state common for all selecting volumes
Standard_EXPORT const Graphic3d_WorldViewProjState& WorldViewProjState() const;

View File

@@ -129,22 +129,16 @@ void SelectMgr_TriangularFrustum::Build (const gp_Pnt2d& theP1,
// - scale only is needed: @theTrsf must be set to gp_Identity.
//=======================================================================
NCollection_Handle<SelectMgr_BaseFrustum> SelectMgr_TriangularFrustum::ScaleAndTransform (const Standard_Integer /*theScale*/,
const gp_Trsf& theTrsf)
const gp_GTrsf& theTrsf)
{
SelectMgr_TriangularFrustum* aRes = new SelectMgr_TriangularFrustum();
// V0_Near
aRes->myVertices[0] = myVertices[0].Transformed (theTrsf);
// V1_Near
aRes->myVertices[1] = myVertices[1].Transformed (theTrsf);
// V2_Near
aRes->myVertices[2] = myVertices[2].Transformed (theTrsf);
// V0_Far
aRes->myVertices[3] = myVertices[3].Transformed (theTrsf);
// V1_Far
aRes->myVertices[4] = myVertices[4].Transformed (theTrsf);
// V2_Far
aRes->myVertices[5] = myVertices[5].Transformed (theTrsf);
for (Standard_Integer anIt = 0; anIt < 6; anIt++)
{
gp_Pnt aPoint = myVertices[anIt];
theTrsf.Transforms (aPoint.ChangeCoord());
aRes->myVertices[anIt] = aPoint;
}
aRes->myIsOrthographic = myIsOrthographic;

View File

@@ -41,7 +41,7 @@ public:
//! Returns a copy of the frustum transformed according to the matrix given
Standard_EXPORT virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer theScale,
const gp_Trsf& theTrsf) Standard_OVERRIDE;
const gp_GTrsf& theTrsf) Standard_OVERRIDE;
// SAT Tests for different objects

View File

@@ -109,7 +109,7 @@ void SelectMgr_TriangularFrustumSet::Build (const TColgp_Array1OfPnt2d& thePoint
// - scale only is needed: @theTrsf must be set to gp_Identity.
// =======================================================================
NCollection_Handle<SelectMgr_BaseFrustum> SelectMgr_TriangularFrustumSet::ScaleAndTransform (const Standard_Integer theScale,
const gp_Trsf& theTrsf)
const gp_GTrsf& theTrsf)
{
SelectMgr_TriangularFrustumSet* aRes = new SelectMgr_TriangularFrustumSet();

View File

@@ -48,7 +48,7 @@ public:
//! Returns a copy of the frustum with all sub-volumes transformed according to the matrix given
Standard_EXPORT virtual NCollection_Handle<SelectMgr_BaseFrustum> ScaleAndTransform (const Standard_Integer theScale,
const gp_Trsf& theTrsf) Standard_OVERRIDE;
const gp_GTrsf& theTrsf) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Overlaps (const SelectMgr_Vec3& theMinPnt,
const SelectMgr_Vec3& theMaxPnt,

View File

@@ -19,6 +19,7 @@
// AGV OCT/23/03 : Optimize the method SortResult() (OCC4201)
#include <BVH_Tree.hxx>
#include <gp_GTrsf.hxx>
#include <gp_Pnt.hxx>
#include <OSD_Environment.hxx>
#include <Precision.hxx>
@@ -267,12 +268,12 @@ void SelectMgr_ViewerSelector::checkOverlap (const Handle(SelectBasics_Sensitive
// necessary calculations
//=======================================================================
void SelectMgr_ViewerSelector::computeFrustum (const Handle(SelectBasics_SensitiveEntity)& theEnt,
const gp_Trsf& theInvTrsf,
const gp_GTrsf& theInvTrsf,
SelectMgr_FrustumCache& theCachedMgrs,
SelectMgr_SelectingVolumeManager& theResMgr)
{
Standard_Integer aScale = isToScaleFrustum (theEnt) ? sensitivity (theEnt) : 1;
const gp_Trsf aTrsfMtr = theEnt->HasInitLocation() ? theEnt->InvInitLocation() * theInvTrsf : theInvTrsf;
const gp_GTrsf aTrsfMtr = theEnt->HasInitLocation() ? theEnt->InvInitLocation() * theInvTrsf : theInvTrsf;
const Standard_Boolean toScale = aScale != 1;
const Standard_Boolean toTransform = aTrsfMtr.Form() != gp_Identity;
if (toScale && toTransform)
@@ -309,7 +310,7 @@ void SelectMgr_ViewerSelector::traverseObject (const Handle(SelectMgr_Selectable
const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& aSensitivesTree = anEntitySet->BVH();
gp_Trsf aInversedTrsf;
gp_GTrsf aInversedTrsf;
if (theObject->HasTransformation() || theObject->TransformPersistence().Flags)
{
@@ -321,14 +322,24 @@ void SelectMgr_ViewerSelector::traverseObject (const Handle(SelectMgr_Selectable
{
const Graphic3d_Mat4d& aProjection = mySelectingVolumeMgr.ProjectionMatrix();
const Graphic3d_Mat4d& aWorldView = mySelectingVolumeMgr.WorldViewMatrix();
Standard_Integer aViewportWidth;
Standard_Integer aViewportHeight;
mySelectingVolumeMgr.WindowSize (aViewportWidth, aViewportHeight);
gp_Trsf aTPers;
Graphic3d_Mat4d aMat = theObject->TransformPersistence().Compute (aProjection, aWorldView, 0, 0);
aTPers.SetValues (aMat.GetValue (0, 0), aMat.GetValue (0, 1), aMat.GetValue (0, 2), aMat.GetValue (0, 3),
aMat.GetValue (1, 0), aMat.GetValue (1, 1), aMat.GetValue (1, 2), aMat.GetValue (1, 3),
aMat.GetValue (2, 0), aMat.GetValue (2, 1), aMat.GetValue (2, 2), aMat.GetValue (2, 3));
gp_GTrsf aTPers;
Graphic3d_Mat4d aMat = theObject->TransformPersistence().Compute (aProjection, aWorldView, aViewportWidth, aViewportHeight);
aTPers.SetValue (1, 1, aMat.GetValue (0, 0));
aTPers.SetValue (1, 2, aMat.GetValue (0, 1));
aTPers.SetValue (1, 3, aMat.GetValue (0, 2));
aTPers.SetValue (2, 1, aMat.GetValue (1, 0));
aTPers.SetValue (2, 2, aMat.GetValue (1, 1));
aTPers.SetValue (2, 3, aMat.GetValue (1, 2));
aTPers.SetValue (3, 1, aMat.GetValue (2, 0));
aTPers.SetValue (3, 2, aMat.GetValue (2, 1));
aTPers.SetValue (3, 3, aMat.GetValue (2, 2));
aTPers.SetTranslationPart (gp_XYZ (aMat.GetValue (0, 3), aMat.GetValue (1, 3), aMat.GetValue (2, 3)));
aInversedTrsf = (aTPers * theObject->Transformation()).Inverted();
aInversedTrsf = (aTPers * gp_GTrsf (theObject->Transformation())).Inverted();
}
}
@@ -429,7 +440,10 @@ void SelectMgr_ViewerSelector::TraverseSensitives()
const Graphic3d_Mat4d& aProjection = mySelectingVolumeMgr.ProjectionMatrix();
const Graphic3d_Mat4d& aWorldView = mySelectingVolumeMgr.WorldViewMatrix();
const Graphic3d_WorldViewProjState& aWVPState = mySelectingVolumeMgr.WorldViewProjState();
aBVHTree = mySelectableObjectsTrsfPers.BVH (aProjection, aWorldView, aWVPState);
Standard_Integer aViewportWidth;
Standard_Integer aViewportHeight;
mySelectingVolumeMgr.WindowSize (aViewportWidth, aViewportHeight);
aBVHTree = mySelectableObjectsTrsfPers.BVH (aProjection, aWorldView, aViewportWidth, aViewportHeight, aWVPState);
}
else
{
@@ -842,9 +856,12 @@ void SelectMgr_ViewerSelector::RebuildObjectsTree (const Standard_Boolean theIsF
const Graphic3d_Mat4d& aProjection = mySelectingVolumeMgr.ProjectionMatrix();
const Graphic3d_Mat4d& aWorldView = mySelectingVolumeMgr.WorldViewMatrix();
const Graphic3d_WorldViewProjState& aWVPState = mySelectingVolumeMgr.WorldViewProjState();
Standard_Integer aViewportWidth;
Standard_Integer aViewportHeight;
mySelectingVolumeMgr.WindowSize (aViewportWidth, aViewportHeight);
mySelectableObjects.BVH();
mySelectableObjectsTrsfPers.BVH (aProjection, aWorldView, aWVPState);
mySelectableObjectsTrsfPers.BVH (aProjection, aWorldView, aViewportWidth, aViewportHeight, aWVPState);
}
}

View File

@@ -310,10 +310,11 @@ private:
//! needs to be scaled and transformed for the entity and performs
//! necessary calculations
void computeFrustum (const Handle(SelectBasics_SensitiveEntity)& theEnt,
const gp_Trsf& theInvTrsf,
const gp_GTrsf& theInvTrsf,
SelectMgr_FrustumCache& theCachedMgrs,
SelectMgr_SelectingVolumeManager& theResMgr);
protected:
Standard_Boolean preferclosest;