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 | |
17 | #include <Standard.hxx> |
18 | #include <Standard_DefineAlloc.hxx> |
19 | #include <Standard_Macro.hxx> |
20 | #include <BRepMesh_VertexInspector.hxx> |
848fa7e3 |
21 | #include <BRepMesh.hxx> |
fc9b36d6 |
22 | #include <Standard_OStream.hxx> |
23 | #include <gp_XYZ.hxx> |
24 | #include <gp_XY.hxx> |
25 | |
26 | class BRepMesh_Vertex; |
27 | |
28 | //! Describes data structure intended to keep mesh nodes |
29 | //! defined in UV space and implements functionality |
30 | //! providing their uniqueness regarding thir position. |
31 | class BRepMesh_VertexTool |
32 | { |
33 | public: |
34 | |
35 | DEFINE_STANDARD_ALLOC |
36 | |
37 | //! Constructor. |
848fa7e3 |
38 | //! @param theReservedSize size to be reserved for vector of vertices. |
39 | //! @param theAllocator memory allocator to be used by internal collections. |
40 | Standard_EXPORT BRepMesh_VertexTool( |
41 | const Standard_Integer theReservedSize, |
42 | const Handle(NCollection_IncAllocator)& theAllocator); |
fc9b36d6 |
43 | |
44 | //! Sets new size of cell for cellfilter equal in both directions. |
45 | Standard_EXPORT void SetCellSize(const Standard_Real theSize) |
46 | { |
47 | myCellFilter.Reset(theSize, myAllocator); |
48 | mySelector.Clear(); |
49 | } |
50 | |
51 | //! Sets new size of cell for cellfilter. |
848fa7e3 |
52 | //! @param theSizeX size for X dimension. |
53 | //! @param theSizeY size for Y dimension. |
fc9b36d6 |
54 | Standard_EXPORT void SetCellSize(const Standard_Real theSizeX, |
55 | const Standard_Real theSizeY) |
56 | { |
57 | Standard_Real aCellSize[2] = { theSizeX, theSizeY }; |
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 | |
83 | //! Adds vertex with empty data to the tool. |
84 | Standard_EXPORT Standard_Integer Add(const BRepMesh_Vertex& theVertex); |
85 | |
86 | //! Adds vertex with associated data to the tool. |
848fa7e3 |
87 | //! @param theVertex vertex to be added. |
88 | //! @param theParams data associated with the vertex. |
89 | Standard_EXPORT Standard_Integer Add(const BRepMesh_Vertex& theVertex, |
90 | const BRepMesh::ListOfInteger& theParams); |
fc9b36d6 |
91 | |
92 | //! Deletes vertex with the given index from the tool. |
93 | Standard_EXPORT void Delete(const Standard_Integer theIndex); |
94 | |
95 | //! Returns data assigned to link with the given index. |
848fa7e3 |
96 | //! @param theIndex index of link which data should be returned. |
97 | //! @return attached data. |
98 | inline BRepMesh::ListOfInteger& FindFromIndex(const Standard_Integer theIndex) const |
fc9b36d6 |
99 | { |
848fa7e3 |
100 | return (BRepMesh::ListOfInteger&)myLinksMap.Find(theIndex); |
fc9b36d6 |
101 | } |
102 | |
103 | //! Alias for FindFromIndex. |
848fa7e3 |
104 | BRepMesh::ListOfInteger& operator()(const Standard_Integer theIndex) const |
fc9b36d6 |
105 | { |
106 | return FindFromIndex(theIndex); |
107 | } |
108 | |
109 | //! Returns vertex by the given index. |
110 | inline const BRepMesh_Vertex& FindKey(const Standard_Integer theIndex) |
111 | { |
112 | return mySelector.GetVertex(theIndex); |
113 | } |
114 | |
115 | //! Returns index of the given vertex. |
116 | Standard_EXPORT Standard_Integer FindIndex(const BRepMesh_Vertex& theVertex) |
117 | { |
118 | mySelector.SetPoint(theVertex.Coord()); |
119 | myCellFilter.Inspect (theVertex.Coord(), mySelector); |
120 | return mySelector.GetCoincidentPoint(); |
121 | } |
122 | |
123 | //! Returns a number of vertices. |
124 | inline Standard_Integer Extent() const |
125 | { |
126 | return mySelector.NbVertices(); |
127 | } |
128 | |
129 | //! Returns True when the map contains no keys. <br> |
130 | inline Standard_Boolean IsEmpty() const |
131 | { |
132 | return (Extent() == 0); |
133 | } |
134 | |
135 | //! Substitutes vertex with the given by the given vertex with attributes. |
848fa7e3 |
136 | //! @param theIndex index of vertex to be substituted. |
137 | //! @param theVertex replacement vertex. |
138 | //! @param theData data associated to the vertex. |
139 | Standard_EXPORT void Substitute(const Standard_Integer theIndex, |
140 | const BRepMesh_Vertex& theVertex, |
141 | const BRepMesh::ListOfInteger& theData); |
fc9b36d6 |
142 | |
143 | //! Remove last node from the structure. |
144 | inline void RemoveLast() |
145 | { |
146 | Delete(Extent()); |
147 | } |
148 | |
149 | //! Returns the list with indexes of vertices that have movability attribute |
150 | //! equal to BRepMesh_Deleted and can be replaced with another node. |
848fa7e3 |
151 | inline const BRepMesh::ListOfInteger& GetListOfDelNodes() const |
fc9b36d6 |
152 | { |
153 | return mySelector.GetListOfDelPoints(); |
154 | } |
155 | |
156 | //! Prints statistics. |
157 | Standard_EXPORT void Statistics(Standard_OStream& theStream) const; |
158 | |
159 | private: |
160 | |
161 | //! Expands the given point according to specified tolerance. |
848fa7e3 |
162 | //! @param thePoint point to be expanded. |
163 | //! @param[out] theMinPoint bottom left corner of area defined by expanded point. |
164 | //! @param[out] theMaxPoint top right corner of area defined by expanded point. |
fc9b36d6 |
165 | inline void expandPoint(const gp_XY& thePoint, |
166 | gp_XY& theMinPoint, |
167 | gp_XY& theMaxPoint) |
168 | { |
169 | theMinPoint.SetX(thePoint.X() - myTolerance[0]); |
170 | theMinPoint.SetY(thePoint.Y() - myTolerance[1]); |
171 | theMaxPoint.SetX(thePoint.X() + myTolerance[0]); |
172 | theMaxPoint.SetY(thePoint.Y() + myTolerance[1]); |
173 | } |
174 | |
175 | private: |
176 | |
848fa7e3 |
177 | Handle(NCollection_IncAllocator) myAllocator; |
178 | BRepMesh::VertexCellFilter myCellFilter; |
179 | BRepMesh_VertexInspector mySelector; |
180 | BRepMesh::DMapOfIntegerListOfInteger myLinksMap; |
181 | Standard_Real myTolerance[2]; |
fc9b36d6 |
182 | }; |
183 | |
184 | #endif |