Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2011-06-02 |
2 | // Created by: Oleg AGASHIN | |
973c2be1 | 3 | // Copyright (c) 2011-2014 OPEN CASCADE SAS |
b311480e | 4 | // |
973c2be1 | 5 | // This file is part of Open CASCADE Technology software library. |
b311480e | 6 | // |
d5f74e42 | 7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
973c2be1 | 9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 12 | // |
973c2be1 | 13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. | |
51c3cc5f O |
15 | |
16 | #include <BRepMesh_VertexTool.ixx> | |
17 | #include <gp_XY.hxx> | |
18 | #include <Precision.hxx> | |
19 | #include <BRepMesh_Vertex.hxx> | |
20 | #include <BRepMesh_VertexInspector.hxx> | |
21 | #include <BRepMesh_BaseAllocator.hxx> | |
22 | ||
23 | //======================================================================= | |
24 | //function : BRepMesh_VertexTool | |
25 | //purpose : | |
26 | //======================================================================= | |
27 | BRepMesh_VertexTool::BRepMesh_VertexTool(const BRepMesh_BaseAllocator& theAlloc) | |
28 | : myAllocator(theAlloc), | |
29 | myCellFilter(0., myAllocator), | |
30 | mySelector(64,myAllocator), | |
31 | myTol(0,1) | |
32 | { | |
33 | SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() ); | |
34 | SetTolerance( Precision::Confusion(), Precision::Confusion() ); | |
35 | } | |
36 | ||
37 | //======================================================================= | |
38 | //function : BRepMesh_VertexTool | |
39 | //purpose : | |
40 | //======================================================================= | |
41 | BRepMesh_VertexTool::BRepMesh_VertexTool(const Standard_Integer nbComp, | |
42 | const BRepMesh_BaseAllocator& theAlloc) | |
43 | : myAllocator(theAlloc), | |
44 | myCellFilter(0., myAllocator), | |
45 | mySelector(Max(nbComp,64),myAllocator), | |
46 | myTol(0,1) | |
47 | { | |
48 | SetCellSize ( Precision::Confusion()+0.05*Precision::Confusion() ); | |
49 | SetTolerance( Precision::Confusion(), Precision::Confusion() ); | |
50 | } | |
51 | ||
52 | //======================================================================= | |
53 | //function : SetCellSize | |
54 | //purpose : | |
55 | //======================================================================= | |
56 | void BRepMesh_VertexTool::SetCellSize(const Standard_Real theSize) | |
57 | { | |
58 | myCellFilter.Reset(theSize, myAllocator); | |
59 | mySelector.Clear(); | |
60 | } | |
61 | ||
62 | //======================================================================= | |
63 | //function : SetCellSize | |
64 | //purpose : | |
65 | //======================================================================= | |
66 | void BRepMesh_VertexTool::SetCellSize(const Standard_Real theXSize, | |
67 | const Standard_Real theYSize) | |
68 | { | |
69 | Standard_Real aCellSize[2]; | |
70 | aCellSize[0] = theXSize; | |
71 | aCellSize[1] = theYSize; | |
72 | ||
73 | myCellFilter.Reset(aCellSize, myAllocator); | |
74 | mySelector.Clear(); | |
75 | } | |
76 | ||
77 | //======================================================================= | |
78 | //function : SetTolerance | |
79 | //purpose : | |
80 | //======================================================================= | |
81 | void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTol) | |
82 | { | |
83 | mySelector.SetTolerance( theTol ); | |
84 | myTol(0) = theTol; | |
85 | myTol(1) = theTol; | |
86 | } | |
87 | ||
88 | //======================================================================= | |
89 | //function : SetTolerance | |
90 | //purpose : | |
91 | //======================================================================= | |
92 | void BRepMesh_VertexTool::SetTolerance(const Standard_Real theTolX, const Standard_Real theTolY) | |
93 | { | |
94 | mySelector.SetTolerance( theTolX, theTolY ); | |
95 | myTol(0) = theTolX; | |
96 | myTol(1) = theTolY; | |
97 | } | |
98 | ||
99 | //======================================================================= | |
100 | //function : Add | |
101 | //purpose : | |
102 | //======================================================================= | |
103 | Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex) | |
104 | { | |
105 | Standard_Integer anIndex = FindIndex(theVertex); | |
106 | if ( anIndex == 0 ) | |
107 | { | |
108 | BRepMesh_ListOfInteger thelist(myAllocator); | |
109 | anIndex = Add(theVertex, thelist); | |
110 | } | |
111 | return anIndex; | |
112 | } | |
113 | ||
114 | //======================================================================= | |
115 | //function : Add | |
116 | //purpose : | |
117 | //======================================================================= | |
118 | Standard_Integer BRepMesh_VertexTool::Add(const BRepMesh_Vertex& theVertex, | |
119 | const BRepMesh_ListOfInteger& theParams) | |
120 | { | |
121 | Standard_Integer anIndex = mySelector.Add(theVertex); | |
122 | myLinksMap.Bind(anIndex, theParams); | |
123 | gp_XY aMinPnt, aMaxPnt; | |
124 | ExpandPoint(theVertex.Coord(), aMinPnt, aMaxPnt); | |
125 | myCellFilter.Add(anIndex, aMinPnt, aMaxPnt); | |
126 | return anIndex; | |
127 | } | |
128 | ||
129 | //======================================================================= | |
130 | //function : Delete | |
131 | //purpose : | |
132 | //======================================================================= | |
133 | void BRepMesh_VertexTool::Delete(const Standard_Integer theIndex) | |
134 | { | |
135 | BRepMesh_Vertex& aV = mySelector.GetVertex(theIndex); | |
136 | gp_XY aMinPnt, aMaxPnt; | |
137 | ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt); | |
138 | myCellFilter.Remove (theIndex, aMinPnt, aMaxPnt); | |
139 | mySelector.Delete(theIndex); | |
140 | } | |
141 | ||
142 | //======================================================================= | |
143 | //function : RemoveLast | |
144 | //purpose : | |
145 | //======================================================================= | |
146 | void BRepMesh_VertexTool::RemoveLast() | |
147 | { | |
148 | Standard_Integer aIndex = mySelector.GetNbVertices(); | |
149 | Delete( aIndex ); | |
150 | } | |
151 | ||
152 | //======================================================================= | |
153 | //function : GetListOfDelNodes | |
154 | //purpose : | |
155 | //======================================================================= | |
156 | const BRepMesh_ListOfInteger& BRepMesh_VertexTool::GetListOfDelNodes() const | |
157 | { | |
158 | return mySelector.GetListOfDelNodes(); | |
159 | } | |
160 | ||
161 | //======================================================================= | |
162 | //function : FindIndex | |
163 | //purpose : | |
164 | //======================================================================= | |
165 | Standard_Integer BRepMesh_VertexTool::FindIndex(const BRepMesh_Vertex& theVertex) | |
166 | { | |
35e08fe8 | 167 | mySelector.SetCurrent(theVertex.Coord(),Standard_False); |
51c3cc5f O |
168 | myCellFilter.Inspect (theVertex.Coord(), mySelector); |
169 | return mySelector.GetCoincidentInd(); | |
170 | } | |
171 | ||
172 | //======================================================================= | |
173 | //function : FindKey | |
174 | //purpose : | |
175 | //======================================================================= | |
176 | const BRepMesh_Vertex& BRepMesh_VertexTool::FindKey(const Standard_Integer theIndex) | |
177 | { | |
178 | return mySelector.GetVertex(theIndex); | |
179 | } | |
180 | ||
181 | //======================================================================= | |
182 | //function : Substitute | |
183 | //purpose : | |
184 | //======================================================================= | |
185 | void BRepMesh_VertexTool::Substitute(const Standard_Integer Index, | |
186 | const BRepMesh_Vertex& theVertex, | |
187 | const BRepMesh_ListOfInteger& theData) | |
188 | { | |
189 | BRepMesh_Vertex& aV = mySelector.GetVertex(Index); | |
190 | gp_XY aMinPnt, aMaxPnt; | |
191 | ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt); | |
192 | myCellFilter.Remove (Index, aMinPnt, aMaxPnt); | |
193 | aV = theVertex; | |
194 | ExpandPoint(aV.Coord(), aMinPnt, aMaxPnt); | |
195 | myCellFilter.Add(Index, aMinPnt, aMaxPnt); | |
196 | FindFromIndex(Index) = theData; | |
197 | } | |
198 | ||
199 | //======================================================================= | |
200 | //function : Extent | |
201 | //purpose : | |
202 | //======================================================================= | |
203 | Standard_Integer BRepMesh_VertexTool::Extent() const | |
204 | { | |
205 | return mySelector.GetNbVertices(); | |
206 | } | |
207 | ||
208 | //======================================================================= | |
209 | //function : IsEmpty | |
210 | //purpose : | |
211 | //======================================================================= | |
212 | Standard_Boolean BRepMesh_VertexTool::IsEmpty() const | |
213 | { | |
214 | return mySelector.GetNbVertices() == 0; | |
215 | } | |
216 | ||
217 | //======================================================================= | |
218 | //function : FindFromIndex | |
219 | //purpose : | |
220 | //======================================================================= | |
221 | BRepMesh_ListOfInteger& BRepMesh_VertexTool::FindFromIndex(const Standard_Integer theIndex) const | |
222 | { | |
223 | return (BRepMesh_ListOfInteger&) myLinksMap.Find(theIndex); | |
224 | } | |
225 | ||
226 | //======================================================================= | |
227 | //function : | |
228 | //purpose : | |
229 | //======================================================================= | |
230 | void BRepMesh_VertexTool::ExpandPoint(const gp_XY& thePnt, gp_XY& theMinPnt, gp_XY& theMaxPnt) | |
231 | { | |
232 | theMinPnt.SetX(thePnt.X() - myTol(0)); | |
233 | theMinPnt.SetY(thePnt.Y() - myTol(1)); | |
234 | theMaxPnt.SetX(thePnt.X() + myTol(0)); | |
235 | theMaxPnt.SetY(thePnt.Y() + myTol(1)); | |
236 | } | |
237 | ||
238 | //======================================================================= | |
239 | //function : Statistics | |
240 | //purpose : | |
241 | //======================================================================= | |
242 | void BRepMesh_VertexTool::Statistics(Standard_OStream& S) const | |
243 | { | |
244 | S <<"\nStructure Statistics\n---------------\n\n"; | |
245 | S <<"This structure has "<<mySelector.GetNbVertices()<<" Nodes\n\n"; | |
246 | } |