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

0031490: Foundation Classes, Poly_Connect - speed up temporary allocations

Poly_Connect::Load() now uses NCollection_IncAllocator instead of new/delete
for allocation temporary sequence elements.

StdPrs_ShadedShape, fillFaceBoundaries() now uses NCollection_IncAllocator for temporary points.
This commit is contained in:
kgv 2020-04-08 10:22:26 +03:00 committed by bugmaster
parent f0ada3e8d4
commit 8f08e231fa
2 changed files with 28 additions and 20 deletions

View File

@ -16,6 +16,7 @@
#include <Poly_Connect.hxx>
#include <NCollection_IncAllocator.hxx>
#include <Poly_Triangle.hxx>
#include <Poly_Triangulation.hxx>
@ -23,9 +24,9 @@
struct polyedge
{
polyedge* next; // the next edge in the list
Standard_Integer nd; // the second node of the edge
Standard_Integer nt[2]; // the two adjacent triangles
Standard_Integer nn[2]; // the two adjacent nodes
Standard_Integer nd; // the second node of the edge
DEFINE_STANDARD_ALLOC
};
@ -97,6 +98,8 @@ void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation)
// create an array to store the edges starting from the vertices
NCollection_Array1<polyedge*> anEdges (1, aNbNodes);
anEdges.Init (NULL);
// use incremental allocator for small allocations
Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
// loop on the triangles
NCollection_Vec3<Standard_Integer> aTriNodes;
@ -144,7 +147,7 @@ void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation)
if (ced == NULL)
{
// create the edge if not found
ced = new polyedge();
ced = (polyedge* )anIncAlloc->Allocate (sizeof(polyedge));
ced->next = anEdges[anEdgeNodes[0]];
anEdges[anEdgeNodes[0]] = ced;
ced->nd = anEdgeNodes[1];
@ -196,16 +199,16 @@ void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation)
anAdjIndex += 3;
}
// destroy the edges array
for (Standard_Integer aNodeIter = anEdges.Lower(); aNodeIter <= anEdges.Upper(); ++aNodeIter)
// destroy the edges array - can be skipped when using NCollection_IncAllocator
/*for (Standard_Integer aNodeIter = anEdges.Lower(); aNodeIter <= anEdges.Upper(); ++aNodeIter)
{
for (polyedge* anEdgeIter = anEdges[aNodeIter]; anEdgeIter != NULL;)
{
polyedge* aTmp = anEdgeIter->next;
delete anEdgeIter;
anIncAlloc->Free (anEdgeIter);
anEdgeIter = aTmp;
}
}
}*/
}
//=======================================================================

View File

@ -28,7 +28,9 @@
#include <gp_Dir.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <NCollection_IncAllocator.hxx>
#include <NCollection_List.hxx>
#include <NCollection_Shared.hxx>
#include <Precision.hxx>
#include <Prs3d_Drawer.hxx>
#include <Prs3d_IsoAspect.hxx>
@ -312,14 +314,20 @@ namespace
Standard_Integer aNbPolylines = 0;
TopLoc_Location aTrsf;
TColgp_SequenceOfPnt aSeqPntsExtra;
Handle(NCollection_Shared<TColgp_SequenceOfPnt>) aSeqPntsExtra;
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
{
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
if (aFace.NbChildren() == 0)
{
// handle specifically faces without boundary definition (triangulation-only)
StdPrs_WFShape::AddEdgesOnTriangulation (aSeqPntsExtra, aFace, Standard_False);
if (aSeqPntsExtra.IsNull())
{
Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
aSeqPntsExtra = new NCollection_Shared<TColgp_SequenceOfPnt> (anIncAlloc);
}
StdPrs_WFShape::AddEdgesOnTriangulation (*aSeqPntsExtra, aFace, Standard_False);
}
}
@ -358,26 +366,25 @@ namespace
++aNbPolylines;
}
}
const Standard_Integer aNbExtra = !aSeqPntsExtra.IsNull() ? aSeqPntsExtra->Size() : 0;
if (aNodeNumber == 0)
{
if (aSeqPntsExtra.Size() < 2)
if (aNbExtra < 2)
{
return Handle(Graphic3d_ArrayOfSegments)();
}
Standard_Integer aNbVertices = aSeqPntsExtra.Size();
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbVertices);
for (Standard_Integer aPntIter = 1; aPntIter <= aNbVertices; aPntIter += 2)
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbExtra);
for (TColgp_SequenceOfPnt::Iterator aPntIter (*aSeqPntsExtra); aPntIter.More(); aPntIter.Next())
{
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter));
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter + 1));
aSegments->AddVertex (aPntIter.Value());
}
return aSegments;
}
// create indexed segments array to pack polylines from different edges into single array
const Standard_Integer aSegmentEdgeNb = (aNodeNumber - aNbPolylines) * 2;
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNodeNumber + aSeqPntsExtra.Size(), aSegmentEdgeNb + aSeqPntsExtra.Size());
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNodeNumber + aNbExtra, aSegmentEdgeNb + aNbExtra);
for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next())
{
if (anEdgeIter.Value().Extent() == 0)
@ -433,14 +440,12 @@ namespace
}
}
if (!aSeqPntsExtra.IsNull())
{
Standard_Integer aSegmentEdge = aSegments->VertexNumber();
const Standard_Integer aNbVertices = aSeqPntsExtra.Size();
for (Standard_Integer aPntIter = 1; aPntIter <= aNbVertices; aPntIter += 2)
for (TColgp_SequenceOfPnt::Iterator aPntIter (*aSeqPntsExtra); aPntIter.More(); aPntIter.Next())
{
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter));
aSegments->AddEdge (++aSegmentEdge);
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter + 1));
aSegments->AddVertex (aPntIter.Value());
aSegments->AddEdge (++aSegmentEdge);
}
}