0027490: BRepMesh: Reduce number of memory allocations
[occt.git] / src / BRepMesh / BRepMesh_VertexTool.hxx
CommitLineData
fc9b36d6 1// Copyright (c) 2013 OPEN CASCADE SAS
2//
3// This file is part of Open CASCADE Technology software library.
4//
5// This library is free software; you can redistribute it and/or modify it under
6// the terms of the GNU Lesser General Public License version 2.1 as published
7// by the Free Software Foundation, with special exception defined in the file
8// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9// distribution for complete text of the license and disclaimer of any warranty.
10//
11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
13
14#ifndef _BRepMesh_VertexTool_HeaderFile
15#define _BRepMesh_VertexTool_HeaderFile
16
50bc8f96 17#include <NCollection_Array1.hxx>
fc9b36d6 18#include <Standard.hxx>
19#include <Standard_DefineAlloc.hxx>
20#include <Standard_Macro.hxx>
21#include <BRepMesh_VertexInspector.hxx>
848fa7e3 22#include <BRepMesh.hxx>
fc9b36d6 23#include <Standard_OStream.hxx>
24#include <gp_XYZ.hxx>
25#include <gp_XY.hxx>
26
27class BRepMesh_Vertex;
28
29//! Describes data structure intended to keep mesh nodes
30//! defined in UV space and implements functionality
31//! providing their uniqueness regarding thir position.
32class BRepMesh_VertexTool
33{
34public:
35
36 DEFINE_STANDARD_ALLOC
37
38 //! Constructor.
848fa7e3 39 //! @param theAllocator memory allocator to be used by internal collections.
40 Standard_EXPORT BRepMesh_VertexTool(
848fa7e3 41 const Handle(NCollection_IncAllocator)& theAllocator);
fc9b36d6 42
43 //! Sets new size of cell for cellfilter equal in both directions.
44 Standard_EXPORT void SetCellSize(const Standard_Real theSize)
45 {
46 myCellFilter.Reset(theSize, myAllocator);
47 mySelector.Clear();
48 }
49
50 //! Sets new size of cell for cellfilter.
848fa7e3 51 //! @param theSizeX size for X dimension.
52 //! @param theSizeY size for Y dimension.
fc9b36d6 53 Standard_EXPORT void SetCellSize(const Standard_Real theSizeX,
54 const Standard_Real theSizeY)
55 {
50bc8f96 56 Standard_Real aCellSizeC[2] = { theSizeX, theSizeY };
57 NCollection_Array1<Standard_Real> aCellSize(aCellSizeC[0], 1, 2);
fc9b36d6 58 myCellFilter.Reset(aCellSize, myAllocator);
59 mySelector.Clear();
60 }
61
62 //! Sets the tolerance to be used for identification of
63 //! coincident vertices equal for both dimensions.
64 Standard_EXPORT void SetTolerance(const Standard_Real theTolerance)
65 {
66 mySelector.SetTolerance( theTolerance );
67 myTolerance[0] = theTolerance;
68 myTolerance[1] = theTolerance;
69 }
70
71 //! Sets the tolerance to be used for identification of
72 //! coincident vertices.
848fa7e3 73 //! @param theToleranceX tolerance for X dimension.
74 //! @param theToleranceY tolerance for Y dimension.
fc9b36d6 75 Standard_EXPORT void SetTolerance(const Standard_Real theToleranceX,
76 const Standard_Real theToleranceY)
77 {
78 mySelector.SetTolerance( theToleranceX, theToleranceY );
79 myTolerance[0] = theToleranceX;
80 myTolerance[1] = theToleranceY;
81 }
82
71316196 83 //! Gets the tolerance to be used for identification of
84 //! coincident vertices.
85 //! @param theToleranceX tolerance for X dimension.
86 //! @param theToleranceY tolerance for Y dimension.
87 Standard_EXPORT void GetTolerance(Standard_Real& theToleranceX,
88 Standard_Real& theToleranceY)
89 {
90 theToleranceX = myTolerance[0];
91 theToleranceY = myTolerance[1];
92 }
93
fc9b36d6 94 //! Adds vertex with empty data to the tool.
2caff0b3 95 //! @param theVertex node to be added to the mesh.
96 //! @param isForceAdd adds the given node to structure without
97 //! checking on coincidence with other nodes.
98 //! @return index of the node in the structure.
99 Standard_EXPORT Standard_Integer Add(
100 const BRepMesh_Vertex& theVertex,
101 const Standard_Boolean isForceAdd);
fc9b36d6 102
103 //! Deletes vertex with the given index from the tool.
104 Standard_EXPORT void Delete(const Standard_Integer theIndex);
105
2caff0b3 106 //! Returns set of mesh vertices.
107 inline const BRepMesh::HVectorOfVertex& Vertices() const
fc9b36d6 108 {
2caff0b3 109 return mySelector.Vertices();
fc9b36d6 110 }
111
2caff0b3 112 //! Returns set of mesh vertices.
113 inline BRepMesh::HVectorOfVertex& ChangeVertices()
fc9b36d6 114 {
2caff0b3 115 return mySelector.ChangeVertices();
fc9b36d6 116 }
117
118 //! Returns vertex by the given index.
119 inline const BRepMesh_Vertex& FindKey(const Standard_Integer theIndex)
120 {
121 return mySelector.GetVertex(theIndex);
122 }
123
124 //! Returns index of the given vertex.
125 Standard_EXPORT Standard_Integer FindIndex(const BRepMesh_Vertex& theVertex)
126 {
127 mySelector.SetPoint(theVertex.Coord());
128 myCellFilter.Inspect (theVertex.Coord(), mySelector);
129 return mySelector.GetCoincidentPoint();
130 }
131
132 //! Returns a number of vertices.
133 inline Standard_Integer Extent() const
134 {
135 return mySelector.NbVertices();
136 }
137
138 //! Returns True when the map contains no keys. <br>
139 inline Standard_Boolean IsEmpty() const
140 {
141 return (Extent() == 0);
142 }
143
144 //! Substitutes vertex with the given by the given vertex with attributes.
848fa7e3 145 //! @param theIndex index of vertex to be substituted.
146 //! @param theVertex replacement vertex.
2caff0b3 147 Standard_EXPORT void Substitute(const Standard_Integer theIndex,
148 const BRepMesh_Vertex& theVertex);
fc9b36d6 149
150 //! Remove last node from the structure.
151 inline void RemoveLast()
152 {
153 Delete(Extent());
154 }
155
156 //! Returns the list with indexes of vertices that have movability attribute
157 //! equal to BRepMesh_Deleted and can be replaced with another node.
848fa7e3 158 inline const BRepMesh::ListOfInteger& GetListOfDelNodes() const
fc9b36d6 159 {
160 return mySelector.GetListOfDelPoints();
161 }
162
163 //! Prints statistics.
164 Standard_EXPORT void Statistics(Standard_OStream& theStream) const;
165
166private:
167
168 //! Expands the given point according to specified tolerance.
848fa7e3 169 //! @param thePoint point to be expanded.
170 //! @param[out] theMinPoint bottom left corner of area defined by expanded point.
171 //! @param[out] theMaxPoint top right corner of area defined by expanded point.
fc9b36d6 172 inline void expandPoint(const gp_XY& thePoint,
173 gp_XY& theMinPoint,
174 gp_XY& theMaxPoint)
175 {
176 theMinPoint.SetX(thePoint.X() - myTolerance[0]);
177 theMinPoint.SetY(thePoint.Y() - myTolerance[1]);
178 theMaxPoint.SetX(thePoint.X() + myTolerance[0]);
179 theMaxPoint.SetY(thePoint.Y() + myTolerance[1]);
180 }
181
182private:
183
848fa7e3 184 Handle(NCollection_IncAllocator) myAllocator;
185 BRepMesh::VertexCellFilter myCellFilter;
186 BRepMesh_VertexInspector mySelector;
848fa7e3 187 Standard_Real myTolerance[2];
fc9b36d6 188};
189
190#endif