1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0026792: Visualization, Graphic3d - Z-fit support for transform persistence is missing after removing Visual3d_View

Add missing code for z-fit support for zoom, rotate persistent object.
Fixed wrong statement that should enable frustum culling optimization for zoom, rotate persistent object.
Fixed BVH_LinearBuilder.lxx to correctly control number of items in leaf node for a case of items with equal bounding boxes.
Added non-regression test case for z-clipping of transform persistent objects.
This commit is contained in:
apl 2015-11-19 11:16:14 +03:00 committed by bugmaster
parent c8b5b3d89e
commit 97f937cc55
7 changed files with 98 additions and 77 deletions

View File

@ -181,10 +181,11 @@ Standard_Integer BVH_LinearBuilder<T, N>::EmitHierachy (BVH_Tree<T, N>*
std::vector<BVH_EncodedLink>::iterator theStart, std::vector<BVH_EncodedLink>::iterator theStart,
std::vector<BVH_EncodedLink>::iterator theFinal) std::vector<BVH_EncodedLink>::iterator theFinal)
{ {
if (theFinal - theStart > BVH_Builder<T, N>::myLeafNodeSize && theBit >= 0) if (theFinal - theStart > BVH_Builder<T, N>::myLeafNodeSize)
{ {
std::vector<BVH_EncodedLink>::iterator aPosition = std::lower_bound ( std::vector<BVH_EncodedLink>::iterator aPosition =
theStart, theFinal, BVH_EncodedLink(), BVH::BitComparator (theBit)); (theBit >= 0) ? std::lower_bound (theStart, theFinal, BVH_EncodedLink(), BVH::BitComparator (theBit))
: theStart + ((theFinal - theStart) / 2);
if (aPosition == theStart || aPosition == theFinal) if (aPosition == theStart || aPosition == theFinal)
{ {

View File

@ -401,53 +401,6 @@ void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructur
} }
} }
//! Auxiliary method for MinMaxValues() method
inline void addStructureBndBox (const Handle(Graphic3d_Structure)& theStruct,
const Standard_Boolean theToIgnoreInfiniteFlag,
Bnd_Box& theBndBox)
{
if (!theStruct->IsVisible())
{
return;
}
else if (theStruct->IsInfinite()
&& !theToIgnoreInfiniteFlag)
{
// XMin, YMin .... ZMax are initialized by means of infinite line data
const Bnd_Box aBox = theStruct->MinMaxValues (Standard_False);
if (!aBox.IsWhole()
&& !aBox.IsVoid())
{
theBndBox.Add (aBox);
}
return;
}
// Only non-empty and non-infinite structures
// are taken into account for calculation of MinMax
if (theStruct->IsEmpty()
|| theStruct->TransformPersistenceMode() != Graphic3d_TMF_None)
{
return;
}
// "FitAll" operation ignores object with transform persistence parameter
const Bnd_Box aBox = theStruct->MinMaxValues (theToIgnoreInfiniteFlag);
// To prevent float overflow at camera parameters calculation and further
// rendering, bounding boxes with at least one vertex coordinate out of
// float range are skipped by view fit algorithms
if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
Abs (aBox.CornerMin().Z()) >= ShortRealLast())
return;
theBndBox.Add (aBox);
}
// ======================================================================= // =======================================================================
// function : MinMaxValues // function : MinMaxValues
// purpose : // purpose :
@ -472,20 +425,70 @@ Bnd_Box Graphic3d_CView::MinMaxValues (const Graphic3d_MapOfStructure& theSet,
{ {
Bnd_Box aResult; Bnd_Box aResult;
const Standard_Integer aViewId = Identification(); const Standard_Integer aViewId = Identification();
Handle(Graphic3d_Camera) aCamera = Camera();
Standard_Integer aWinWidth = 0;
Standard_Integer aWinHeight = 0;
if (IsDefined())
{
Window()->Size (aWinWidth, aWinHeight);
}
for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next()) for (Graphic3d_MapIteratorOfMapOfStructure aStructIter (theSet); aStructIter.More(); aStructIter.Next())
{ {
const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key(); const Handle(Graphic3d_Structure)& aStructure = aStructIter.Key();
if (!aStructIter.Value()->IsVisible()) if (!aStructure->IsVisible() || aStructure->IsEmpty())
{ {
continue; continue;
} }
else if (!aStructIter.Value()->CStructure()->ViewAffinity.IsNull() else if (!aStructure->CStructure()->ViewAffinity.IsNull()
&& !aStructIter.Value()->CStructure()->ViewAffinity->IsVisible (aViewId)) && !aStructure->CStructure()->ViewAffinity->IsVisible (aViewId))
{ {
continue; continue;
} }
addStructureBndBox (aStructure, theToIgnoreInfiniteFlag, aResult); // "FitAll" operation ignores object with transform persistence parameter
if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None)
{
// Panning and 2d persistence apply changes to projection or/and its translation components.
// It makes them incompatible with z-fitting algorithm. Ignored by now.
if (!theToIgnoreInfiniteFlag ||
(aStructure->TransformPersistence().Flags & Graphic3d_TMF_2d) ||
(aStructure->TransformPersistence().Flags & Graphic3d_TMF_PanPers) ||
(aStructure->TransformPersistence().Flags & Graphic3d_TMF_TriedronPers))
{
continue;
}
}
Bnd_Box aBox = aStructure->MinMaxValues (theToIgnoreInfiniteFlag);
if (aBox.IsWhole() || aBox.IsVoid())
{
continue;
}
if (aStructure->TransformPersistence().Flags != Graphic3d_TMF_None)
{
const Graphic3d_Mat4d& aProjectionMat = aCamera->ProjectionMatrix();
const Graphic3d_Mat4d& aWorldViewMat = aCamera->OrientationMatrix();
aStructure->TransformPersistence().Apply (aProjectionMat, aWorldViewMat, aWinWidth, aWinHeight, aBox);
}
// To prevent float overflow at camera parameters calculation and further
// rendering, bounding boxes with at least one vertex coordinate out of
// float range are skipped by view fit algorithms
if (Abs (aBox.CornerMax().X()) >= ShortRealLast() ||
Abs (aBox.CornerMax().Y()) >= ShortRealLast() ||
Abs (aBox.CornerMax().Z()) >= ShortRealLast() ||
Abs (aBox.CornerMin().X()) >= ShortRealLast() ||
Abs (aBox.CornerMin().Y()) >= ShortRealLast() ||
Abs (aBox.CornerMin().Z()) >= ShortRealLast())
{
continue;
}
aResult.Add (aBox);
} }
return aResult; return aResult;
} }

View File

@ -1,4 +1,4 @@
// Created on: 2015-06-30 // Created on: 2015-06-30
// Created by: Anton POLETAEV // Created by: Anton POLETAEV
// Copyright (c) 2015 OPEN CASCADE SAS // Copyright (c) 2015 OPEN CASCADE SAS
// //
@ -67,7 +67,7 @@ void OpenGl_BVHClipPrimitiveTrsfPersSet::Swap (const Standard_Integer theIdx1,
const Standard_Integer aStructIdx1 = theIdx1 + 1; const Standard_Integer aStructIdx1 = theIdx1 + 1;
const Standard_Integer aStructIdx2 = theIdx2 + 1; const Standard_Integer aStructIdx2 = theIdx2 + 1;
myStructs.Swap (aStructIdx1, aStructIdx2); myStructs .Swap (aStructIdx1, aStructIdx2);
myStructBoxes.Swap (aStructIdx1, aStructIdx2); myStructBoxes.Swap (aStructIdx1, aStructIdx2);
} }
@ -137,7 +137,9 @@ const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >&
const OpenGl_Mat4& theWorldViewMatrix, const OpenGl_Mat4& theWorldViewMatrix,
const Graphic3d_WorldViewProjState& theWVPState) const Graphic3d_WorldViewProjState& theWVPState)
{ {
if (!myIsDirty && (myStructBoxesState.IsValid() && !myStructBoxesState.IsChanged(theWVPState))) if (!myIsDirty
&& (myStructBoxesState.IsValid()
&& !myStructBoxesState.IsChanged (theWVPState)))
{ {
return myBVH; return myBVH;
} }
@ -149,13 +151,8 @@ const NCollection_Handle<BVH_Tree<Standard_ShortReal, 4> >&
const OpenGl_Structure* aStructure = myStructs (aStructIdx); const OpenGl_Structure* aStructure = myStructs (aStructIdx);
HBndBox4f aBoundingBox = new Graphic3d_BndBox4f; HBndBox4f aBoundingBox = new Graphic3d_BndBox4f;
*aBoundingBox = aStructure->BoundingBox();
if (aStructure->TransformPersistence.Flags && !(aStructure->TransformPersistence.Flags & Graphic3d_TMF_2d)) aStructure->TransformPersistence.Apply (theProjectionMatrix, theWorldViewMatrix, 0, 0, *aBoundingBox);
{
*aBoundingBox = aStructure->BoundingBox();
aStructure->TransformPersistence.Apply (theProjectionMatrix, theWorldViewMatrix, 0, 0, *aBoundingBox);
}
myStructBoxes.Add (aBoundingBox); myStructBoxes.Add (aBoundingBox);
} }

View File

@ -35,10 +35,8 @@ OpenGl_BVHTreeSelector::OpenGl_BVHTreeSelector()
// ======================================================================= // =======================================================================
void OpenGl_BVHTreeSelector::SetViewVolume (const Handle(Graphic3d_Camera)& theCamera) void OpenGl_BVHTreeSelector::SetViewVolume (const Handle(Graphic3d_Camera)& theCamera)
{ {
if (myWorldViewProjState == theCamera->WorldViewProjState()) if (!myWorldViewProjState.IsChanged (theCamera->WorldViewProjState()))
{
return; return;
}
myIsProjectionParallel = theCamera->IsOrthographic(); myIsProjectionParallel = theCamera->IsOrthographic();

View File

@ -64,7 +64,7 @@ void OpenGl_Layer::Add (const OpenGl_Structure* theStruct,
} }
else if (!isForChangePriority) else if (!isForChangePriority)
{ {
if (!theStruct->TransformPersistence.Flags) if (theStruct->TransformPersistence.Flags == Graphic3d_TMF_None)
{ {
myBVHPrimitives.Add (theStruct); myBVHPrimitives.Add (theStruct);
} }
@ -177,7 +177,7 @@ void OpenGl_Layer::renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace)
if (aStruct->IsAlwaysRendered()) if (aStruct->IsAlwaysRendered())
continue; continue;
if (!aStruct->TransformPersistence.Flags) if (aStruct->TransformPersistence.Flags == Graphic3d_TMF_None)
{ {
myBVHPrimitives.Add (aStruct); myBVHPrimitives.Add (aStruct);
} }
@ -224,7 +224,8 @@ void OpenGl_Layer::renderTraverse (const Handle(OpenGl_Workspace)& theWorkspace)
void OpenGl_Layer::traverse (OpenGl_BVHTreeSelector& theSelector) const void OpenGl_Layer::traverse (OpenGl_BVHTreeSelector& theSelector) const
{ {
// handle a case when all objects are infinite // handle a case when all objects are infinite
if (myBVHPrimitives.Size() == 0 && myBVHPrimitivesTrsfPers.Size() == 0) if (myBVHPrimitives .Size() == 0
&& myBVHPrimitivesTrsfPers.Size() == 0)
return; return;
theSelector.CacheClipPtsProjections(); theSelector.CacheClipPtsProjections();
@ -237,20 +238,18 @@ void OpenGl_Layer::traverse (OpenGl_BVHTreeSelector& theSelector) const
if (isTrsfPers) if (isTrsfPers)
{ {
if (myBVHPrimitivesTrsfPers.Size() == 0) if (myBVHPrimitivesTrsfPers.Size() == 0)
{
continue; continue;
}
const OpenGl_Mat4& aProjection = theSelector.ProjectionMatrix(); const OpenGl_Mat4& aProjection = theSelector.ProjectionMatrix();
const OpenGl_Mat4& aWorldView = theSelector.WorldViewMatrix(); const OpenGl_Mat4& aWorldView = theSelector.WorldViewMatrix();
const Graphic3d_WorldViewProjState& aWVPState = theSelector.WorldViewProjState(); const Graphic3d_WorldViewProjState& aWVPState = theSelector.WorldViewProjState();
aBVHTree = myBVHPrimitivesTrsfPers.BVH (aProjection, aWorldView, aWVPState); aBVHTree = myBVHPrimitivesTrsfPers.BVH (aProjection, aWorldView, aWVPState);
} }
else else
{ {
if (myBVHPrimitives.Size() == 0) if (myBVHPrimitives.Size() == 0)
{
continue; continue;
}
aBVHTree = myBVHPrimitives.BVH(); aBVHTree = myBVHPrimitives.BVH();
} }

View File

@ -163,7 +163,9 @@ public:
|| IsForHighlight || IsForHighlight
|| IsMutable || IsMutable
|| Is2dText || Is2dText
|| TransformPersistence.Flags != 0; || (TransformPersistence.Flags & Graphic3d_TMF_2d) != 0
|| (TransformPersistence.Flags & Graphic3d_TMF_PanPers) != 0
|| (TransformPersistence.Flags & Graphic3d_TMF_TriedronPers) != 0;
} }
//! This method releases GL resources without actual elements destruction. //! This method releases GL resources without actual elements destruction.

21
tests/bugs/vis/bug26792 Normal file
View File

@ -0,0 +1,21 @@
puts "================================================================"
puts "CR26792"
puts "Visualization, Graphic3d - Z-fit support for transform persistence is missing after removing Visual3d_View"
puts "================================================================"
puts ""
vinit
vclear
vaxo
box b 100 100 100
vdisplay b -trsfPers zoom
vzoom 0.01
vzfit
checkcolor 204 184 1.0 1.0 0.0
checkcolor 232 205 1.0 1.0 0.0
checkcolor 262 182 1.0 1.0 0.0
checkcolor 233 184 1.0 1.0 0.0
set only_screen 1