1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0027374: Visualization - optimize management of the scene bounding box

OpenGl_View now caches bounding boxes per Z-layer (instead of bounding box of entire scene in Graphic3d_CView).
Redundant invalidation of cached scene bounding box is now avoided in case
when new presentation attributes are assigned to the graphic structure.

Add a new methods ConsiderZoomPersistenceObjects() and considerZoomPersistenceObjects() in the Graphic3d_CView, OpenGl_View and OpenGl_Layer classes.
Call ConsiderZoomPersistenceObjects() in the V3d_View::FitMinMax method.

std::numeric_limits<T>::lowest() fix
This commit is contained in:
duv
2016-05-25 17:00:59 +03:00
committed by bugmaster
parent 5ae6e53dec
commit 50d06d8fcf
13 changed files with 558 additions and 59 deletions

View File

@@ -17,6 +17,29 @@
IMPLEMENT_STANDARD_RTTIEXT(Graphic3d_CView,Graphic3d_DataStructureManager)
namespace
{
static const int THE_DEFAULT_LAYERS[] = { Graphic3d_ZLayerId_Top,
Graphic3d_ZLayerId_Topmost,
Graphic3d_ZLayerId_BotOSD,
Graphic3d_ZLayerId_TopOSD };
static const int THE_NB_DEFAULT_LAYERS = sizeof(THE_DEFAULT_LAYERS) / sizeof(*THE_DEFAULT_LAYERS);
void combineBox (Bnd_Box& aCombined, const Graphic3d_BndBox4f& theBox)
{
if (theBox.IsValid())
{
aCombined.Add (gp_Pnt (theBox.CornerMin().x(),
theBox.CornerMin().y(),
theBox.CornerMin().z()));
aCombined.Add (gp_Pnt (theBox.CornerMax().x(),
theBox.CornerMax().y(),
theBox.CornerMax().z()));
}
}
}
//=======================================================================
//function : Constructor
//purpose :
@@ -349,9 +372,11 @@ void Graphic3d_CView::ReCompute (const Handle(Graphic3d_Structure)& theStruct)
// function : Update
// purpose :
// =======================================================================
void Graphic3d_CView::Update (const Aspect_TypeOfUpdate theUpdateMode)
void Graphic3d_CView::Update (const Aspect_TypeOfUpdate theUpdateMode,
const Graphic3d_ZLayerId theLayerId)
{
myMinMax.Invalidate();
InvalidateZLayerBoundingBox (theLayerId);
if (theUpdateMode == Aspect_TOU_ASAP)
{
Compute();
@@ -409,13 +434,68 @@ void Graphic3d_CView::DisplayedStructures (Graphic3d_MapOfStructure& theStructur
// =======================================================================
Bnd_Box Graphic3d_CView::MinMaxValues (const Standard_Boolean theToIgnoreInfiniteFlag) const
{
if (myMinMax.IsOutdated (theToIgnoreInfiniteFlag))
Bnd_Box aResult;
if (!IsDefined())
{
myMinMax.BoundingBox (theToIgnoreInfiniteFlag) = MinMaxValues (myStructsDisplayed, theToIgnoreInfiniteFlag);
myMinMax.IsOutdated (theToIgnoreInfiniteFlag) = Standard_False;
return aResult;
}
return myMinMax.BoundingBox (theToIgnoreInfiniteFlag);
Handle(Graphic3d_Camera) aCamera = Camera();
Standard_Integer aWinWidth = 0;
Standard_Integer aWinHeight = 0;
Window()->Size (aWinWidth, aWinHeight);
for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
{
Graphic3d_BndBox4f aBox = ZLayerBoundingBox (THE_DEFAULT_LAYERS[aLayer],
aCamera,
aWinWidth,
aWinHeight,
theToIgnoreInfiniteFlag);
combineBox (aResult, aBox);
}
Standard_Integer aMaxZLayer = ZLayerMax();
for (Standard_Integer aLayerId = Graphic3d_ZLayerId_Default; aLayerId <= aMaxZLayer; ++aLayerId)
{
Graphic3d_BndBox4f aBox = ZLayerBoundingBox (aLayerId, aCamera, aWinWidth, aWinHeight, theToIgnoreInfiniteFlag);
combineBox (aResult, aBox);
}
return aResult;
}
// =======================================================================
// function : ConsiderZoomPersistenceObjects
// purpose :
// =======================================================================
Standard_Real Graphic3d_CView::ConsiderZoomPersistenceObjects()
{
if (!IsDefined())
{
return 1.0;
}
Handle(Graphic3d_Camera) aCamera = Camera();
Standard_Integer aWinWidth = 0;
Standard_Integer aWinHeight = 0;
Window()->Size (aWinWidth, aWinHeight);
Standard_Real aMaxCoef = 1.0;
for (Standard_Integer aLayer = 0; aLayer < THE_NB_DEFAULT_LAYERS; ++aLayer)
{
aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (THE_DEFAULT_LAYERS[aLayer], aCamera, aWinWidth, aWinHeight, Standard_False));
}
for (Standard_Integer aLayer = Graphic3d_ZLayerId_Default; aLayer <= ZLayerMax(); ++aLayer)
{
aMaxCoef = Max (aMaxCoef, considerZoomPersistenceObjects (aLayer, aCamera, aWinWidth, aWinHeight, Standard_False));
}
return aMaxCoef;
}
// =======================================================================
@@ -672,7 +752,7 @@ void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
theStructure->CalculateBoundBox();
displayStructure (theStructure->CStructure(), theStructure->DisplayPriority());
Update (theUpdateMode);
Update (theUpdateMode, theStructure->GetZLayer());
return;
}
else if (anAnswer != Graphic3d_TOA_COMPUTE)
@@ -693,7 +773,7 @@ void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
}
displayStructure (anOldStruct->CStructure(), theStructure->DisplayPriority());
Update (theUpdateMode);
Update (theUpdateMode, anOldStruct->GetZLayer());
return;
}
else
@@ -716,7 +796,7 @@ void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
const Handle(Graphic3d_Structure)& aNewStruct = myStructsComputed.Value (aNewIndex);
myStructsComputed.SetValue (anIndex, aNewStruct);
displayStructure (aNewStruct->CStructure(), theStructure->DisplayPriority());
Update (theUpdateMode);
Update (theUpdateMode, aNewStruct->GetZLayer());
return;
}
else
@@ -807,7 +887,7 @@ void Graphic3d_CView::Display (const Handle(Graphic3d_Structure)& theStructure,
myStructsDisplayed.Add (theStructure);
displayStructure (aStruct->CStructure(), theStructure->DisplayPriority());
Update (theUpdateMode);
Update (theUpdateMode, aStruct->GetZLayer());
}
// =======================================================================
@@ -851,7 +931,7 @@ void Graphic3d_CView::Erase (const Handle(Graphic3d_Structure)& theStructure,
}
}
myStructsDisplayed.Remove (theStructure);
Update (theUpdateMode);
Update (theUpdateMode, theStructure->GetZLayer());
}
// =======================================================================

View File

@@ -108,8 +108,10 @@ public:
//! Computes the new presentation of the structure displayed in this view with the type Graphic3d_TOS_COMPUTED.
Standard_EXPORT void ReCompute (const Handle(Graphic3d_Structure)& theStructure);
//! Updates screen in function of modifications of the structures.
Standard_EXPORT void Update (const Aspect_TypeOfUpdate theUpdateMode);
//! Updates screen in function of modifications of the structures
//! and invalidates bounding box of specified ZLayerId.
Standard_EXPORT void Update (const Aspect_TypeOfUpdate theUpdateMode,
const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN);
//! Returns Standard_True if one of the structures displayed in the view contains Polygons, Triangles or Quadrangles.
Standard_EXPORT Standard_Boolean ContainsFacet() const;
@@ -134,8 +136,7 @@ public:
Standard_EXPORT Standard_Boolean IsComputed (const Standard_Integer theStructId,
Handle(Graphic3d_Structure)& theComputedStruct) const;
//! Returns the coordinates of the boundary box of all
//! structures displayed in the view.
//! Returns the bounding box of all structures displayed in the view.
//! If <theToIgnoreInfiniteFlag> is TRUE, then the boundary box
//! also includes minimum and maximum limits of graphical elements
//! forming parts of infinite structures.
@@ -336,6 +337,20 @@ public:
//! ID for the structure.
virtual void AddZLayer (const Graphic3d_ZLayerId theLayerId) = 0;
//! Returns the maximum Z layer ID.
//! First layer ID is Graphic3d_ZLayerId_Default, last ID is ZLayerMax().
virtual Standard_Integer ZLayerMax() const = 0;
//! Returns the bounding box of all structures displayed in the Z layer.
virtual void InvalidateZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId) const = 0;
//! Returns the bounding box of all structures displayed in the Z layer.
virtual Graphic3d_BndBox4f ZLayerBoundingBox (const Graphic3d_ZLayerId theLayerId,
const Handle(Graphic3d_Camera)& theCamera,
const Standard_Integer theWindowWidth,
const Standard_Integer theWindowHeight,
const Standard_Boolean theToIgnoreInfiniteFlag) const = 0;
//! Remove Z layer from the specified view. All structures
//! displayed at the moment in layer will be displayed in default layer
//! ( the bottom-level z layer ). To unset layer ID from associated
@@ -346,6 +361,9 @@ public:
virtual void SetZLayerSettings (const Graphic3d_ZLayerId theLayerId,
const Graphic3d_ZLayerSettings& theSettings) = 0;
//! Returns zoom-scale factor.
Standard_EXPORT Standard_Real ConsiderZoomPersistenceObjects();
//! Returns pointer to an assigned framebuffer object.
virtual Handle(Standard_Transient) FBO() const = 0;
@@ -522,29 +540,12 @@ private:
virtual void changePriority (const Handle(Graphic3d_CStructure)& theCStructure,
const Standard_Integer theNewPriority) = 0;
protected:
struct CachedMinMax
{
CachedMinMax() { Invalidate(); }
Bnd_Box& BoundingBox (const Standard_Boolean theToIgnoreInfiniteFlag)
{
return !theToIgnoreInfiniteFlag ? myBoundingBox[0] : myBoundingBox[1];
}
Standard_Boolean& IsOutdated (const Standard_Boolean theToIgnoreInfiniteFlag)
{
return !theToIgnoreInfiniteFlag ? myIsOutdated[0] : myIsOutdated[1];
}
void Invalidate()
{
myIsOutdated[0] = Standard_True;
myIsOutdated[1] = Standard_True;
}
Standard_Boolean myIsOutdated [2];
Bnd_Box myBoundingBox[2];
};
//! Returns zoom-scale factor.
virtual Standard_Real considerZoomPersistenceObjects (const Graphic3d_ZLayerId theLayerId,
const Handle(Graphic3d_Camera)& theCamera,
const Standard_Integer theWindowWidth,
const Standard_Integer theWindowHeight,
const Standard_Boolean theToIgnoreInfiniteFlag) const = 0;
protected:
@@ -559,7 +560,6 @@ protected:
Standard_Boolean myIsActive;
Standard_Boolean myIsRemoved;
Graphic3d_TypeOfVisualization myVisualization;
mutable CachedMinMax myMinMax;
private:

View File

@@ -123,7 +123,7 @@ void Graphic3d_Structure::Clear (const Standard_Boolean theWithDestruction)
myCStructure->ContainsFacet = 0;
myStructureManager->Clear (this, theWithDestruction);
Update();
Update (true);
}
//=======================================================================
@@ -363,7 +363,7 @@ void Graphic3d_Structure::SetVisible (const Standard_Boolean theValue)
myCStructure->visible = isVisible;
myCStructure->OnVisibilityChanged();
Update();
Update (true);
}
//=============================================================================
@@ -1385,7 +1385,7 @@ void Graphic3d_Structure::Connect (const Handle(Graphic3d_Structure)& theStructu
GraphicConnect (theStructure);
myStructureManager->Connect (this, theStructure);
Update();
Update (true);
}
else // Graphic3d_TOC_ANCESTOR
{
@@ -1422,7 +1422,7 @@ void Graphic3d_Structure::Disconnect (const Handle(Graphic3d_Structure)& theStru
myStructureManager->Disconnect (this, theStructure);
CalculateBoundBox();
Update();
Update (true);
}
else if (RemoveAncestor (aStructure))
{
@@ -1562,7 +1562,7 @@ void Graphic3d_Structure::SetTransform (const TColStd_Array2OfReal& theMat
myCStructure->UpdateTransformation();
myStructureManager->SetTransform (this, aNewTrsf);
Update();
Update (true);
}
//=============================================================================
@@ -1986,14 +1986,15 @@ void Graphic3d_Structure::PrintNetwork (const Handle(Graphic3d_Structure)& theSt
//function : Update
//purpose :
//=============================================================================
void Graphic3d_Structure::Update() const
void Graphic3d_Structure::Update (const bool theUpdateLayer) const
{
if (IsDeleted())
{
return;
}
myStructureManager->Update (myStructureManager->UpdateMode());
myStructureManager->Update (myStructureManager->UpdateMode(),
theUpdateLayer ? myCStructure->ZLayer() : Graphic3d_ZLayerId_UNKNOWN);
}
//=============================================================================

View File

@@ -532,9 +532,9 @@ private:
//! Returns the manager to which <me> is associated.
Standard_EXPORT Handle(Graphic3d_StructureManager) StructureManager() const;
//! Calls the Update method of the StructureManager which
//! contains the Structure <me>.
Standard_EXPORT void Update() const;
//! Calls the Update method of the StructureManager which contains the Structure <me>.
//! If theUpdateLayer is true then invalidates bounding box of ZLayer.
Standard_EXPORT void Update (const bool theUpdateLayer = false) const;
//! Updates the c structure associated to <me>.
Standard_EXPORT void UpdateStructure (const Handle(Graphic3d_AspectLine3d)& CTXL, const Handle(Graphic3d_AspectText3d)& CTXT, const Handle(Graphic3d_AspectMarker3d)& CTXM, const Handle(Graphic3d_AspectFillArea3d)& CTXF);

View File

@@ -83,11 +83,12 @@ Aspect_TypeOfUpdate Graphic3d_StructureManager::UpdateMode() const
// function : Update
// purpose :
// ========================================================================
void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode) const
void Graphic3d_StructureManager::Update (const Aspect_TypeOfUpdate theMode,
const Graphic3d_ZLayerId theLayerId) const
{
for (Graphic3d_IndexedMapOfView::Iterator aViewIt (myDefinedViews); aViewIt.More(); aViewIt.Next())
{
aViewIt.Value()->Update (theMode);
aViewIt.Value()->Update (theMode, theLayerId);
}
}

View File

@@ -109,8 +109,10 @@ public:
//! TOU_WAIT on demand (Update)
Standard_EXPORT Aspect_TypeOfUpdate UpdateMode() const;
//! Updates screen in function of modifications of the structures.
Standard_EXPORT virtual void Update (const Aspect_TypeOfUpdate theMode = Aspect_TOU_ASAP) const;
//! Updates screen in function of modifications of the structures
//! and invalidates bounding box of specified ZLayerId.
Standard_EXPORT virtual void Update (const Aspect_TypeOfUpdate theMode = Aspect_TOU_ASAP,
const Graphic3d_ZLayerId theLayerId = Graphic3d_ZLayerId_UNKNOWN) const;
//! Deletes and erases the 3D structure manager.
Standard_EXPORT virtual void Remove();