mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-09 13:22:24 +03:00
0032086: Visualization - support deferred data loading
1) Extend Poly_Triangulation by mesh purpose, possibility to be cleared and late-load deferred data interfaces. 2) Update BRep_TFace to store list of triangulations istead of single one. And also active one. Update getter and setter of single triangulation and add new methods to interaction with whole triangulations list. 3) Update BRep_Tool to get single triangulation of face according to the input mesh purpose or whole triangulations list. 4) Update BRep_Builder to make face by not only single triangulation but whole triangulations list with specified active one. 5) Add new methods to BRepTools to interact with shape triangulations (Load/Unload/Activate/LoadAll/UnloadAllTriangulation(s)) 6) Add new 'tlateload'command for shape to load/unload/activate triangulations. 7) Update 'trinfo' command by '-lods' options to print detailaed information about LODs of this shape 8) Support empty triangulations by selection. Use bounding box selection in this case. 9) Add new 'outdisplist' option to XDispaly command to print list of displayed objects to output variable but not to theDI 10) Add new '-noecho' option to vdisplay command to skip printing of displayed objects to theDI 11) Create new RWMesh_TriangulationSource as mesh data wrapper for delayed triangulation loading. 12) Create new RWMesh_TriangulationReader as base interface for reading primitive array from the buffer. 13) Cache nodes/triangles number defined in glTF file 14) Use RWMesh_TriangulationSource class as base of RWGltf_GltfLatePrimitiveArray one and RWMesh_TriangulationReader class as base of RWGltf_TriangulationReader one 15) Add possibilty to support of LODs by glTF reader. It is possible to skip data loading and load them later 16) Add new '-skiplateloading' (to skip triangulation loading), '-keeplate' (to keep information about deferred storage to load/unload triangulation later), '-toprintdebuginfo' (to print additional debug information) options to ReadGltf command 17) Add new test of glTF late loading
This commit is contained in:
@@ -36,6 +36,8 @@
|
||||
#include <Geom_Surface.hxx>
|
||||
#include <gp_Lin2d.hxx>
|
||||
#include <gp_Vec2d.hxx>
|
||||
#include <Message.hxx>
|
||||
#include <OSD_FileSystem.hxx>
|
||||
#include <OSD_OpenFile.hxx>
|
||||
#include <Poly_PolygonOnTriangulation.hxx>
|
||||
#include <Poly_Triangulation.hxx>
|
||||
@@ -1020,6 +1022,230 @@ Standard_Boolean BRepTools::Triangulation(const TopoDS_Shape& theShape,
|
||||
return Standard_True;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LoadTriangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean BRepTools::LoadTriangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Integer theTriangulationIdx,
|
||||
const Standard_Boolean theToSetAsActive,
|
||||
const Handle(OSD_FileSystem)& theFileSystem)
|
||||
{
|
||||
Standard_ASSERT_RAISE (theTriangulationIdx >= -1, "Invalid negative triangulation index!");
|
||||
|
||||
Standard_Boolean wasLoaded = false;
|
||||
BRep_Builder aBuilder;
|
||||
TopLoc_Location aDummyLoc;
|
||||
const Handle(OSD_FileSystem)& aFileSystem = !theFileSystem.IsNull() ? theFileSystem : OSD_FileSystem::DefaultFileSystem();
|
||||
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
||||
{
|
||||
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
||||
Handle(Poly_Triangulation) aTriangulation;
|
||||
if (theTriangulationIdx == -1)
|
||||
{
|
||||
// load an active triangulation
|
||||
aTriangulation = BRep_Tool::Triangulation (aFace, aDummyLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
const Poly_ListOfTriangulation& aTriangulations = BRep_Tool::Triangulations (aFace, aDummyLoc);
|
||||
if (theTriangulationIdx >= aTriangulations.Size())
|
||||
{
|
||||
// triangulation index is out of range
|
||||
continue;
|
||||
}
|
||||
Standard_Integer aTriangulationIdx = 0;
|
||||
for (Poly_ListOfTriangulation::Iterator anIter(aTriangulations);
|
||||
anIter.More(); anIter.Next(), aTriangulationIdx++)
|
||||
{
|
||||
if (aTriangulationIdx != theTriangulationIdx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
aTriangulation = anIter.Value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aTriangulation.IsNull() ||
|
||||
!aTriangulation->HasDeferredData())
|
||||
{
|
||||
// NULL triangulation, already loaded triangulation or triangulation without deferred storage
|
||||
// cannot be loaded
|
||||
continue;
|
||||
}
|
||||
if (aTriangulation->LoadDeferredData (aFileSystem))
|
||||
{
|
||||
wasLoaded = true;
|
||||
if (theToSetAsActive
|
||||
&& (theTriangulationIdx != -1)) // triangulation is already active
|
||||
{
|
||||
aBuilder.UpdateFace (aFace, aTriangulation, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
return wasLoaded;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : LoadAllTriangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean BRepTools::LoadAllTriangulations (const TopoDS_Shape& theShape,
|
||||
const Handle(OSD_FileSystem)& theFileSystem)
|
||||
{
|
||||
Standard_Boolean wasLoaded = false;
|
||||
TopLoc_Location aDummyLoc;
|
||||
const Handle(OSD_FileSystem)& aFileSystem = !theFileSystem.IsNull() ? theFileSystem : OSD_FileSystem::DefaultFileSystem();
|
||||
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
||||
{
|
||||
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
||||
for (Poly_ListOfTriangulation::Iterator anIter (BRep_Tool::Triangulations (aFace, aDummyLoc));
|
||||
anIter.More(); anIter.Next())
|
||||
{
|
||||
const Handle(Poly_Triangulation)& aTriangulation = anIter.Value();
|
||||
if (aTriangulation.IsNull() ||
|
||||
!aTriangulation->HasDeferredData())
|
||||
{
|
||||
// NULL triangulation, already loaded triangulation or triangulation without deferred storage
|
||||
// cannot be loaded
|
||||
continue;
|
||||
}
|
||||
wasLoaded = aTriangulation->LoadDeferredData (aFileSystem);
|
||||
}
|
||||
}
|
||||
return wasLoaded;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UnloadTriangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean BRepTools::UnloadTriangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Integer theTriangulationIdx)
|
||||
{
|
||||
Standard_ASSERT_RAISE (theTriangulationIdx >= -1, "Invalid negative triangulation index!");
|
||||
|
||||
Standard_Boolean wasUnloaded = false;
|
||||
TopLoc_Location aDummyLoc;
|
||||
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
||||
{
|
||||
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
||||
Handle(Poly_Triangulation) aTriangulation;
|
||||
if (theTriangulationIdx == -1)
|
||||
{
|
||||
// unload an active triangulation
|
||||
aTriangulation = BRep_Tool::Triangulation (aFace, aDummyLoc);
|
||||
}
|
||||
else
|
||||
{
|
||||
Standard_Integer aTriangulationIdx = 0;
|
||||
const Poly_ListOfTriangulation& aTriangulations = BRep_Tool::Triangulations (aFace, aDummyLoc);
|
||||
if (theTriangulationIdx >= aTriangulations.Size())
|
||||
{
|
||||
// triangulation index is out of range
|
||||
continue;
|
||||
}
|
||||
for (Poly_ListOfTriangulation::Iterator anIter (aTriangulations);
|
||||
anIter.More(); anIter.Next(), aTriangulationIdx++)
|
||||
{
|
||||
if (aTriangulationIdx != theTriangulationIdx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
aTriangulation = anIter.Value();
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (aTriangulation.IsNull() ||
|
||||
!aTriangulation->HasDeferredData())
|
||||
{
|
||||
// NULL triangulation or triangulation without deferred storage cannot be unloaded
|
||||
continue;
|
||||
}
|
||||
wasUnloaded = aTriangulation->UnloadDeferredData();
|
||||
}
|
||||
return wasUnloaded;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : UnloadAllTriangulations
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean BRepTools::UnloadAllTriangulations (const TopoDS_Shape& theShape)
|
||||
{
|
||||
Standard_Boolean wasUnloaded = false;
|
||||
TopLoc_Location aDummyLoc;
|
||||
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
||||
{
|
||||
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
||||
Handle(Poly_Triangulation) aTriangulation;
|
||||
for (Poly_ListOfTriangulation::Iterator anIter (BRep_Tool::Triangulations (aFace, aDummyLoc));
|
||||
anIter.More(); anIter.Next())
|
||||
{
|
||||
aTriangulation = anIter.Value();
|
||||
if (aTriangulation.IsNull() ||
|
||||
!aTriangulation->HasDeferredData())
|
||||
{
|
||||
// NULL triangulation or triangulation without deferred storage cannot be unloaded
|
||||
continue;
|
||||
}
|
||||
wasUnloaded = aTriangulation->UnloadDeferredData();
|
||||
}
|
||||
}
|
||||
return wasUnloaded;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ActivateTriangulation
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
Standard_Boolean BRepTools::ActivateTriangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Integer theTriangulationIdx,
|
||||
const Standard_Boolean theToActivateStrictly)
|
||||
{
|
||||
Standard_ASSERT_RAISE (theTriangulationIdx > -1, "Invalid negative triangulation index!");
|
||||
|
||||
Standard_Boolean wasActivated = false;
|
||||
BRep_Builder aBuilder;
|
||||
TopLoc_Location aDummyLoc;
|
||||
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
||||
{
|
||||
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
||||
Standard_Integer aTriangulationIdx = theTriangulationIdx;
|
||||
const Poly_ListOfTriangulation& aTriangulations = BRep_Tool::Triangulations (aFace, aDummyLoc);
|
||||
const Standard_Integer aTriangulationsNb = aTriangulations.Size();
|
||||
if (theTriangulationIdx >= aTriangulationsNb)
|
||||
{
|
||||
// triangulation index is out of range
|
||||
if (theToActivateStrictly)
|
||||
{
|
||||
// skip activation
|
||||
continue;
|
||||
}
|
||||
// use last available
|
||||
aTriangulationIdx = aTriangulationsNb - 1;
|
||||
}
|
||||
Handle(Poly_Triangulation) anActiveTriangulation;
|
||||
Standard_Integer aTriangulationIter = 0;
|
||||
for (Poly_ListOfTriangulation::Iterator anIter (aTriangulations);
|
||||
anIter.More(); anIter.Next(), aTriangulationIter++)
|
||||
{
|
||||
if (aTriangulationIter != aTriangulationIdx)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
anActiveTriangulation = anIter.Value();
|
||||
break;
|
||||
}
|
||||
if (anActiveTriangulation.IsNull())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
aBuilder.UpdateFace (aFace, anActiveTriangulation, false);
|
||||
wasActivated = true;
|
||||
}
|
||||
return wasActivated;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : IsReallyClosed
|
||||
|
@@ -54,6 +54,7 @@ class BRepTools_ReShape;
|
||||
class Geom_Curve;
|
||||
class Geom2d_Curve;
|
||||
class Geom_Surface;
|
||||
class OSD_FileSystem;
|
||||
|
||||
|
||||
//! The BRepTools package provides utilities for BRep
|
||||
@@ -165,7 +166,9 @@ public:
|
||||
//! Removes all the pcurves of the edges of <S> that
|
||||
//! refer to surfaces not belonging to any face of <S>
|
||||
Standard_EXPORT static void RemoveUnusedPCurves (const TopoDS_Shape& S);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
//! Verifies that each Face from the shape has got a triangulation with a deflection smaller or equal to specified one
|
||||
//! and the Edges a discretization on this triangulation.
|
||||
//! @param theShape [in] shape to verify
|
||||
@@ -178,7 +181,60 @@ public:
|
||||
Standard_EXPORT static Standard_Boolean Triangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Real theLinDefl,
|
||||
const Standard_Boolean theToCheckFreeEdges = Standard_False);
|
||||
|
||||
|
||||
//! Loads triangulation data for each face of the shape
|
||||
//! from some deferred storage using specified shared input file system
|
||||
//! @param theShape [in] shape to load triangulations
|
||||
//! @param theTriangulationIdx [in] index defining what triangulation should be loaded. Starts from 0.
|
||||
//! -1 is used in specific case to load currently already active triangulation.
|
||||
//! If some face doesn't contain triangulation with this index, nothing will be loaded for it.
|
||||
//! Exception will be thrown in case of invalid negative index
|
||||
//! @param theToSetAsActive [in] flag to activate triangulation after its loading
|
||||
//! @param theFileSystem [in] shared file system
|
||||
//! @return TRUE if at least one triangulation is loaded.
|
||||
Standard_EXPORT static Standard_Boolean LoadTriangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Integer theTriangulationIdx = -1,
|
||||
const Standard_Boolean theToSetAsActive = Standard_False,
|
||||
const Handle(OSD_FileSystem)& theFileSystem = Handle(OSD_FileSystem)());
|
||||
|
||||
//! Releases triangulation data for each face of the shape if there is deferred storage to load it later
|
||||
//! @param theShape [in] shape to unload triangulations
|
||||
//! @param theTriangulationIdx [in] index defining what triangulation should be unloaded. Starts from 0.
|
||||
//! -1 is used in specific case to unload currently already active triangulation.
|
||||
//! If some face doesn't contain triangulation with this index, nothing will be unloaded for it.
|
||||
//! Exception will be thrown in case of invalid negative index
|
||||
//! @return TRUE if at least one triangulation is unloaded.
|
||||
Standard_EXPORT static Standard_Boolean UnloadTriangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Integer theTriangulationIdx = -1);
|
||||
|
||||
//! Activates triangulation data for each face of the shape
|
||||
//! from some deferred storage using specified shared input file system
|
||||
//! @param theShape [in] shape to activate triangulations
|
||||
//! @param theTriangulationIdx [in] index defining what triangulation should be activated. Starts from 0.
|
||||
//! Exception will be thrown in case of invalid negative index
|
||||
//! @param theToActivateStrictly [in] flag to activate exactly triangulation with defined theTriangulationIdx index.
|
||||
//! In TRUE case if some face doesn't contain triangulation with this index, active triangulation
|
||||
//! will not be changed for it. Else the last available triangulation will be activated.
|
||||
//! @return TRUE if at least one active triangulation was changed.
|
||||
Standard_EXPORT static Standard_Boolean ActivateTriangulation (const TopoDS_Shape& theShape,
|
||||
const Standard_Integer theTriangulationIdx,
|
||||
const Standard_Boolean theToActivateStrictly = false);
|
||||
|
||||
//! Loads all available triangulations for each face of the shape
|
||||
//! from some deferred storage using specified shared input file system
|
||||
//! @param theShape [in] shape to load triangulations
|
||||
//! @param theFileSystem [in] shared file system
|
||||
//! @return TRUE if at least one triangulation is loaded.
|
||||
Standard_EXPORT static Standard_Boolean LoadAllTriangulations (const TopoDS_Shape& theShape,
|
||||
const Handle(OSD_FileSystem)& theFileSystem = Handle(OSD_FileSystem)());
|
||||
|
||||
//! Releases all available triangulations for each face of the shape if there is deferred storage to load them later
|
||||
//! @param theShape [in] shape to unload triangulations
|
||||
//! @return TRUE if at least one triangulation is unloaded.
|
||||
Standard_EXPORT static Standard_Boolean UnloadAllTriangulations (const TopoDS_Shape& theShape);
|
||||
|
||||
public:
|
||||
|
||||
//! Returns True if the distance between the two
|
||||
//! vertices is lower than their tolerance.
|
||||
Standard_EXPORT static Standard_Boolean Compare (const TopoDS_Vertex& V1, const TopoDS_Vertex& V2);
|
||||
|
Reference in New Issue
Block a user