mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-10 18:51:21 +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:
parent
f0ada3e8d4
commit
8f08e231fa
@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
#include <Poly_Connect.hxx>
|
#include <Poly_Connect.hxx>
|
||||||
|
|
||||||
|
#include <NCollection_IncAllocator.hxx>
|
||||||
#include <Poly_Triangle.hxx>
|
#include <Poly_Triangle.hxx>
|
||||||
#include <Poly_Triangulation.hxx>
|
#include <Poly_Triangulation.hxx>
|
||||||
|
|
||||||
@ -23,9 +24,9 @@
|
|||||||
struct polyedge
|
struct polyedge
|
||||||
{
|
{
|
||||||
polyedge* next; // the next edge in the list
|
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 nt[2]; // the two adjacent triangles
|
||||||
Standard_Integer nn[2]; // the two adjacent nodes
|
Standard_Integer nn[2]; // the two adjacent nodes
|
||||||
|
Standard_Integer nd; // the second node of the edge
|
||||||
DEFINE_STANDARD_ALLOC
|
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
|
// create an array to store the edges starting from the vertices
|
||||||
NCollection_Array1<polyedge*> anEdges (1, aNbNodes);
|
NCollection_Array1<polyedge*> anEdges (1, aNbNodes);
|
||||||
anEdges.Init (NULL);
|
anEdges.Init (NULL);
|
||||||
|
// use incremental allocator for small allocations
|
||||||
|
Handle(NCollection_IncAllocator) anIncAlloc = new NCollection_IncAllocator();
|
||||||
|
|
||||||
// loop on the triangles
|
// loop on the triangles
|
||||||
NCollection_Vec3<Standard_Integer> aTriNodes;
|
NCollection_Vec3<Standard_Integer> aTriNodes;
|
||||||
@ -144,7 +147,7 @@ void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation)
|
|||||||
if (ced == NULL)
|
if (ced == NULL)
|
||||||
{
|
{
|
||||||
// create the edge if not found
|
// create the edge if not found
|
||||||
ced = new polyedge();
|
ced = (polyedge* )anIncAlloc->Allocate (sizeof(polyedge));
|
||||||
ced->next = anEdges[anEdgeNodes[0]];
|
ced->next = anEdges[anEdgeNodes[0]];
|
||||||
anEdges[anEdgeNodes[0]] = ced;
|
anEdges[anEdgeNodes[0]] = ced;
|
||||||
ced->nd = anEdgeNodes[1];
|
ced->nd = anEdgeNodes[1];
|
||||||
@ -196,16 +199,16 @@ void Poly_Connect::Load (const Handle(Poly_Triangulation)& theTriangulation)
|
|||||||
anAdjIndex += 3;
|
anAdjIndex += 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
// destroy the edges array
|
// destroy the edges array - can be skipped when using NCollection_IncAllocator
|
||||||
for (Standard_Integer aNodeIter = anEdges.Lower(); aNodeIter <= anEdges.Upper(); ++aNodeIter)
|
/*for (Standard_Integer aNodeIter = anEdges.Lower(); aNodeIter <= anEdges.Upper(); ++aNodeIter)
|
||||||
{
|
{
|
||||||
for (polyedge* anEdgeIter = anEdges[aNodeIter]; anEdgeIter != NULL;)
|
for (polyedge* anEdgeIter = anEdges[aNodeIter]; anEdgeIter != NULL;)
|
||||||
{
|
{
|
||||||
polyedge* aTmp = anEdgeIter->next;
|
polyedge* aTmp = anEdgeIter->next;
|
||||||
delete anEdgeIter;
|
anIncAlloc->Free (anEdgeIter);
|
||||||
anEdgeIter = aTmp;
|
anEdgeIter = aTmp;
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
@ -28,7 +28,9 @@
|
|||||||
#include <gp_Dir.hxx>
|
#include <gp_Dir.hxx>
|
||||||
#include <gp_Vec.hxx>
|
#include <gp_Vec.hxx>
|
||||||
#include <gp_Pnt.hxx>
|
#include <gp_Pnt.hxx>
|
||||||
|
#include <NCollection_IncAllocator.hxx>
|
||||||
#include <NCollection_List.hxx>
|
#include <NCollection_List.hxx>
|
||||||
|
#include <NCollection_Shared.hxx>
|
||||||
#include <Precision.hxx>
|
#include <Precision.hxx>
|
||||||
#include <Prs3d_Drawer.hxx>
|
#include <Prs3d_Drawer.hxx>
|
||||||
#include <Prs3d_IsoAspect.hxx>
|
#include <Prs3d_IsoAspect.hxx>
|
||||||
@ -312,14 +314,20 @@ namespace
|
|||||||
Standard_Integer aNbPolylines = 0;
|
Standard_Integer aNbPolylines = 0;
|
||||||
|
|
||||||
TopLoc_Location aTrsf;
|
TopLoc_Location aTrsf;
|
||||||
TColgp_SequenceOfPnt aSeqPntsExtra;
|
|
||||||
|
Handle(NCollection_Shared<TColgp_SequenceOfPnt>) aSeqPntsExtra;
|
||||||
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
for (TopExp_Explorer aFaceIter (theShape, TopAbs_FACE); aFaceIter.More(); aFaceIter.Next())
|
||||||
{
|
{
|
||||||
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
const TopoDS_Face& aFace = TopoDS::Face (aFaceIter.Current());
|
||||||
if (aFace.NbChildren() == 0)
|
if (aFace.NbChildren() == 0)
|
||||||
{
|
{
|
||||||
// handle specifically faces without boundary definition (triangulation-only)
|
// 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;
|
++aNbPolylines;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const Standard_Integer aNbExtra = !aSeqPntsExtra.IsNull() ? aSeqPntsExtra->Size() : 0;
|
||||||
if (aNodeNumber == 0)
|
if (aNodeNumber == 0)
|
||||||
{
|
{
|
||||||
if (aSeqPntsExtra.Size() < 2)
|
if (aNbExtra < 2)
|
||||||
{
|
{
|
||||||
return Handle(Graphic3d_ArrayOfSegments)();
|
return Handle(Graphic3d_ArrayOfSegments)();
|
||||||
}
|
}
|
||||||
|
|
||||||
Standard_Integer aNbVertices = aSeqPntsExtra.Size();
|
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbExtra);
|
||||||
Handle(Graphic3d_ArrayOfSegments) aSegments = new Graphic3d_ArrayOfSegments (aNbVertices);
|
for (TColgp_SequenceOfPnt::Iterator aPntIter (*aSeqPntsExtra); aPntIter.More(); aPntIter.Next())
|
||||||
for (Standard_Integer aPntIter = 1; aPntIter <= aNbVertices; aPntIter += 2)
|
|
||||||
{
|
{
|
||||||
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter));
|
aSegments->AddVertex (aPntIter.Value());
|
||||||
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter + 1));
|
|
||||||
}
|
}
|
||||||
return aSegments;
|
return aSegments;
|
||||||
}
|
}
|
||||||
|
|
||||||
// create indexed segments array to pack polylines from different edges into single array
|
// create indexed segments array to pack polylines from different edges into single array
|
||||||
const Standard_Integer aSegmentEdgeNb = (aNodeNumber - aNbPolylines) * 2;
|
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())
|
for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgesMap); anEdgeIter.More(); anEdgeIter.Next())
|
||||||
{
|
{
|
||||||
if (anEdgeIter.Value().Extent() == 0)
|
if (anEdgeIter.Value().Extent() == 0)
|
||||||
@ -433,14 +440,12 @@ namespace
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!aSeqPntsExtra.IsNull())
|
||||||
{
|
{
|
||||||
Standard_Integer aSegmentEdge = aSegments->VertexNumber();
|
Standard_Integer aSegmentEdge = aSegments->VertexNumber();
|
||||||
const Standard_Integer aNbVertices = aSeqPntsExtra.Size();
|
for (TColgp_SequenceOfPnt::Iterator aPntIter (*aSeqPntsExtra); aPntIter.More(); aPntIter.Next())
|
||||||
for (Standard_Integer aPntIter = 1; aPntIter <= aNbVertices; aPntIter += 2)
|
|
||||||
{
|
{
|
||||||
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter));
|
aSegments->AddVertex (aPntIter.Value());
|
||||||
aSegments->AddEdge (++aSegmentEdge);
|
|
||||||
aSegments->AddVertex (aSeqPntsExtra.Value (aPntIter + 1));
|
|
||||||
aSegments->AddEdge (++aSegmentEdge);
|
aSegments->AddEdge (++aSegmentEdge);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user