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

Removed unnecessary computation of base OpenGl_Structure for main presentation;

Bounding box of LOD Graphic3d_Structure is computed as combined box for all LOD graphic groups;
Method HasLevelsOfDetail() was added to presentable objects to mark objects presented via LODs at the time of Compute() call;
Redefineable method ComputeLods() was added to presentable object for customization.
This commit is contained in:
vpa
2016-03-31 14:13:13 +03:00
parent a96ac42dfd
commit 05286d6875
11 changed files with 127 additions and 77 deletions

View File

@@ -80,6 +80,11 @@ public:
//! Get z layer ID
Graphic3d_ZLayerId ZLayer() const { return myZLayer; }
const Handle(Graphic3d_LODManager)& GetLodManager() const
{
return myLODManager;
}
public:
//! Update structure visibility state

View File

@@ -83,3 +83,19 @@ void Graphic3d_LODManager::SetRange (const Standard_Integer theLodIdx,
{
return myLODs.Value (myCurrentLODIdx)->GetDrawGroups();
}
//=======================================================================
// function : GetCombinedBndBox
// purpose :
//=======================================================================
void Graphic3d_LODManager::GetCombinedBndBox (Graphic3d_BndBox4f& theBndBox) const
{
for (Standard_Integer aLodIdx = 0; aLodIdx < myLODs.Size(); ++aLodIdx)
{
const Graphic3d_SequenceOfGroup& aGroups = myLODs.Value (aLodIdx)->GetDrawGroups();
for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (aGroups); aGroupIter.More(); aGroupIter.Next())
{
theBndBox.Combine (aGroupIter.Value()->BoundingBox());
}
}
}

View File

@@ -53,6 +53,8 @@ public:
Standard_EXPORT virtual Handle(Graphic3d_LOD) AddNewLOD() = 0;
Standard_EXPORT void GetCombinedBndBox (Graphic3d_BndBox4f& theBndBox) const;
DEFINE_STANDARD_RTTIEXT (Graphic3d_LODManager, Standard_Transient)
protected:

View File

@@ -24,6 +24,7 @@
#include <Graphic3d_DataStructureManager.hxx>
#include <Graphic3d_GraphicDriver.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_LODManager.hxx>
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
#include <Graphic3d_MapOfStructure.hxx>
#include <Graphic3d_MaterialAspect.hxx>
@@ -1768,9 +1769,17 @@ Handle(Graphic3d_StructureManager) Graphic3d_Structure::StructureManager() const
Graphic3d_BndBox4f Graphic3d_Structure::minMaxCoord() const
{
Graphic3d_BndBox4f aBnd;
for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
const Handle(Graphic3d_LODManager)& aLodMgr = myCStructure->GetLodManager();
if (aLodMgr.IsNull())
{
aBnd.Combine (aGroupIter.Value()->BoundingBox());
for (Graphic3d_SequenceOfGroup::Iterator aGroupIter (myCStructure->Groups()); aGroupIter.More(); aGroupIter.Next())
{
aBnd.Combine (aGroupIter.Value()->BoundingBox());
}
}
else
{
aLodMgr->GetCombinedBndBox (aBnd);
}
return aBnd;
}

View File

@@ -53,50 +53,6 @@ void MeshVS_LODBuilder::Build (const Handle(Prs3d_Presentation)& theBasePrs,
if (myParentMesh == NULL)
return;
//if (!theIsElement)
//{
// Standard_Boolean hasSelectFlag = ((aDispMode & MeshVS_DMF_SelectionPrs) != 0);
// Standard_Boolean hasHilightFlag = ((aDispMode & MeshVS_DMF_HilightPrs) != 0);
// Standard_Real aCoordsBuf[3];
// TColStd_Array1OfReal aCoords (*aCoordsBuf, 1, 3);
// Standard_Integer aNodesNb;
// MeshVS_EntityType aType;
// TColStd_PackedMapOfInteger anIDs;
// anIDs.Assign (myNodeIdxs);
// if (!hasSelectFlag && !hasHilightFlag)
// {
// // subtract the hidden nodes and ids to exclude (to minimize allocated memory)
// Handle(TColStd_HPackedMapOfInteger) aHiddenNodes = aMesh->GetHiddenNodes();
// if (!aHiddenNodes.IsNull())
// anIDs.Subtract (aHiddenNodes->Map());
// }
// Standard_Integer aSize = anIDs.Extent();
// if (aSize > 0)
// {
// Handle(Graphic3d_ArrayOfPoints) aNodePoints = new Graphic3d_ArrayOfPoints (aSize);
// Standard_Integer aPntsNb = 0;
// for (TColStd_MapIteratorOfPackedMapOfInteger aNodeIdxsIter (myNodeIdxs); aNodeIdxsIter.More(); aNodeIdxsIter.Next())
// {
// const Standard_Integer aKey = aNodeIdxsIter.Key();
// if (GetGeom (aKey, Standard_False, aCoords, aNodesNb, aType))
// {
// aPntsNb++;
// aNodePoints->AddVertex (aCoords(1), aCoords(2), aCoords(3));
// }
// }
// if (aPntsNb > 0)
// {
// Handle(Graphic3d_LOD) aNewLod = Prs3d_Root::NewLOD (aMainPrs);
// Handle(Graphic3d_Group) aLODGroup = aNewLod->NewGroup();
// aLODGroup->AddPrimitiveArray (aNodePoints);
// }
// return;
// }
//}
if (theIsElement)
{
Standard_Integer aMaxNodesNb;
@@ -424,6 +380,8 @@ void MeshVS_LODBuilder::Build (const Handle(Prs3d_Presentation)& theBasePrs,
}
}
#include <Prs3d_Root.hxx>
//================================================================
// Function : drawArrays
// Purpose :
@@ -459,6 +417,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs
if (isPolygons && theFillAsp->FrontMaterial().Transparency() < 0.01)
{
Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs);
//Prs3d_Root::NewGroup ( theBasePrs );
//Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup ( theBasePrs );
theFillAsp->SetEdgeOff();
@@ -489,6 +449,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs
if (isPolylines && !theIsPolygonsEdgesOff)
{
Handle (Graphic3d_Group) aLGroup = aNewLod->NewGroup (theBasePrs);
//Prs3d_Root::NewGroup ( theBasePrs );
//Handle (Graphic3d_Group) aLGroup = Prs3d_Root::CurrentGroup ( theBasePrs );
theFillAsp->SetEdgeOff();
if (theIsSelected)
@@ -505,6 +467,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs
if (isLinkPolylines)
{
Handle (Graphic3d_Group) aBeamGroup = aNewLod->NewGroup (theBasePrs);
//Prs3d_Root::NewGroup ( theBasePrs );
//Handle (Graphic3d_Group) aBeamGroup = Prs3d_Root::CurrentGroup ( theBasePrs );
theFillAsp->SetEdgeOff();
if (!theIsSelected)
@@ -517,6 +481,8 @@ void MeshVS_LODBuilder::drawArrays (const Handle(Prs3d_Presentation)& theBasePrs
if (isPolygons && theFillAsp->FrontMaterial().Transparency() >= 0.01)
{
Handle (Graphic3d_Group) aGroup = aNewLod->NewGroup (theBasePrs);
//Prs3d_Root::NewGroup ( theBasePrs );
//Handle (Graphic3d_Group) aGroup = Prs3d_Root::CurrentGroup ( theBasePrs );
theFillAsp->SetEdgeOff();

View File

@@ -138,6 +138,35 @@ MeshVS_Mesh::MeshVS_Mesh (const Standard_Boolean theIsAllowOverlapped )
myHilightDrawer->SetDouble ( MeshVS_DA_MarkerScale, 2.0 );
}
//================================================================
// Function : HasLevelsOfDetail
// Purpose :
//================================================================
Standard_Boolean MeshVS_Mesh::HasLevelsOfDetail() const
{
return !myLODDataSources.IsEmpty();
}
//================================================================
// Function : ComputeLods
// Purpose :
//================================================================
void MeshVS_Mesh::ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode)
{
for (Standard_Integer aLodBldrIdx = 1; aLodBldrIdx <= myBuilders.Length(); ++aLodBldrIdx)
{
const Handle(MeshVS_LODBuilder) aLodBldr = Handle(MeshVS_LODBuilder)::DownCast (myBuilders.Value (aLodBldrIdx));
if (aLodBldr.IsNull())
continue;
const TColStd_PackedMapOfInteger aTrgIdxs = aLodBldr->GetDataSource()->GetAllElements();
if (!aTrgIdxs.IsEmpty())
aLodBldr->Build (thePrs, aTrgIdxs, TColStd_PackedMapOfInteger(), Standard_True, theMode);
}
}
//================================================================
// Function : Compute
// Purpose :
@@ -172,6 +201,7 @@ void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMg
thePresentation->Clear();
Standard_Integer len = myBuilders.Length();
if ( theMode > 0 )
{
for ( Standard_Integer i=1; i<=len; i++ )
{
Handle (MeshVS_PrsBuilder) aCurrent = myBuilders.Value ( i );
@@ -188,22 +218,6 @@ void MeshVS_Mesh::Compute ( const Handle(PrsMgr_PresentationManager3d)& thePrsMg
aCurrent->Build ( thePresentation, aElems, aElemsToExclude, Standard_True, theMode );
}
}
if (myLODDataSources.Size() > 0)
{
for (Standard_Integer aLodBldrIdx = 1; aLodBldrIdx <= myBuilders.Length(); ++aLodBldrIdx)
{
const Handle(MeshVS_LODBuilder) aLodBldr = Handle(MeshVS_LODBuilder)::DownCast (myBuilders.Value (aLodBldrIdx));
if (aLodBldr.IsNull() || !aLodBldr->TestFlags (theMode))
continue;
const TColStd_PackedMapOfInteger aVertIdxs = aLodBldr->GetDataSource()->GetAllNodes();
const TColStd_PackedMapOfInteger aTrgIdxs = aLodBldr->GetDataSource()->GetAllElements();
if (HasNodes)
aLodBldr->Build (thePresentation, aVertIdxs, aNodesToExclude, Standard_False, theMode);
if (HasElements)
aLodBldr->Build (thePresentation, aTrgIdxs, aElemsToExclude, Standard_True, theMode);
}
}
if ( ShowComputeTime )

View File

@@ -181,6 +181,8 @@ public:
//! Returns True if the given owner represents a whole mesh.
Standard_EXPORT virtual Standard_Boolean IsWholeMeshOwner (const Handle(SelectMgr_EntityOwner)& theOwner) const;
Standard_EXPORT virtual Standard_Boolean HasLevelsOfDetail() const Standard_OVERRIDE;
friend class MeshVS_PrsBuilder;
@@ -188,6 +190,10 @@ friend class MeshVS_PrsBuilder;
protected:
Standard_EXPORT virtual void ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode = 0) Standard_OVERRIDE;
//! Stores all vertices that belong to one of the faces to the given map
//! @param theAllElements [in] the map of all mesh elements
//! @param theNbMaxFaceNodes [in] the maximum amount of nodes per face, retrieved from drawer

View File

@@ -795,7 +795,7 @@ void OpenGl_Structure::SetDetailLevelRange (const Standard_Integer theIdOfLOD,
Standard_ASSERT_RAISE (theFrom < theTo,
"The upper boundary of the interval must be greater than lower one!");
if (theIdOfLOD < 0 || theIdOfLOD > myLODManager->NbOfDetailLevels())
if (myLODManager.IsNull() || theIdOfLOD < 0 || theIdOfLOD > myLODManager->NbOfDetailLevels())
return;
myLODManager->SetRange (theIdOfLOD, theFrom, theTo);

View File

@@ -71,7 +71,10 @@ void PrsMgr_PresentableObject::Fill (const Handle(PrsMgr_PresentationManager)& t
const Standard_Integer theMode)
{
Handle(Prs3d_Presentation) aStruct3d = thePrs->Presentation();
Compute (thePrsMgr, aStruct3d, theMode);
if (!HasLevelsOfDetail())
Compute (thePrsMgr, aStruct3d, theMode);
else
ComputeLods (thePrsMgr, aStruct3d, theMode);
UpdateTransformation (aStruct3d);
aStruct3d->SetClipPlanes (myClipPlanes);
aStruct3d->SetTransformPersistence (GetTransformPersistenceMode(), GetTransformPersistencePoint());
@@ -523,3 +526,26 @@ Standard_Boolean PrsMgr_PresentableObject::IsMutable() const
{
return myIsMutable;
}
// =======================================================================
// function : ComputeLods
// purpose :
// =======================================================================
void PrsMgr_PresentableObject::ComputeLods (const Handle(PrsMgr_PresentationManager3d)& /*thePrsMgr*/,
const Handle(Prs3d_Presentation)& /*thePrs*/,
const Standard_Integer /*theMode*/)
{
if (HasLevelsOfDetail())
{
Standard_NotImplemented::Raise ("cannot compute levels of detail");
}
}
// =======================================================================
// function : HasLevelsOfDetail
// purpose :
// =======================================================================
Standard_Boolean PrsMgr_PresentableObject::HasLevelsOfDetail() const
{
return Standard_False;
}

View File

@@ -199,6 +199,8 @@ public:
//! Returns parent of current object in scene hierarchy.
Standard_EXPORT PrsMgr_PresentableObjectPointer Parent() const;
Standard_EXPORT virtual Standard_Boolean HasLevelsOfDetail() const;
friend class PrsMgr_Presentation;
friend class PrsMgr_PresentationManager;
@@ -219,7 +221,11 @@ protected:
Standard_EXPORT PrsMgr_PresentableObject(const PrsMgr_TypeOfPresentation3d aTypeOfPresentation3d = PrsMgr_TOP_AllView);
Standard_EXPORT virtual ~PrsMgr_PresentableObject();
Standard_EXPORT virtual void ComputeLods (const Handle(PrsMgr_PresentationManager3d)& thePrsMgr,
const Handle(Prs3d_Presentation)& thePrs,
const Standard_Integer theMode = 0);
//! Calculates the 3D view aPresentation and its
//! updates. The latter are managed by aPresentationManager.
//! aPresentableObject has the display mode aMode;

View File

@@ -10,15 +10,15 @@ meshlod m $aTmpFolder/lod_data.txt
# iges shapes. the following sequence of commands creates both
# stl and brep files for the iges shape
##########################################################################
igesbrep $aPathToData/iges/bearing.iges res *
vdisplay res
# write created brep to file
save res $aTmpFolder/bearing.brep
trinfo res
# copy maximal deflection value, then re-mesh the shape with proper
# deflection
tclean res
incmesh res $maxDeflection
# save corresponding stl with the same triangulation as will be used
# for generaion of LODs
writestl res $aTmpFolder/bearing.stl
# igesbrep $aPathToData/iges/bearing.iges res *
# vdisplay res
# # write created brep to file
# save res $aTmpFolder/bearing.brep
# trinfo res
# # copy maximal deflection value, then re-mesh the shape with proper
# # deflection
# tclean res
# incmesh res $maxDeflection
# # save corresponding stl with the same triangulation as will be used
# # for generaion of LODs
# writestl res $aTmpFolder/bearing.stl