Commit | Line | Data |
---|---|---|
c80dc6c3 O |
1 | // File: BRepMesh_FastDiscretFace.cxx |
2 | // Created: | |
3 | // Author: Ekaterina SMIRNOVA | |
7fd59977 | 4 | // Copyright: Open CASCADE SAS 2008 |
5 | ||
6 | #include <BRepMesh_FastDiscretFace.ixx> | |
7 | ||
8 | #include <Adaptor3d_IsoCurve.hxx> | |
9 | #include <BRepAdaptor_Curve.hxx> | |
10 | #include <BRepMesh_GeomTool.hxx> | |
11 | #include <BRepMesh_ListOfXY.hxx> | |
12 | #include <BRepMesh_Array1OfVertexOfDelaun.hxx> | |
13 | #include <BRepMesh_ListIteratorOfListOfVertex.hxx> | |
14 | #include <BRepMesh_ListIteratorOfListOfXY.hxx> | |
15 | #include <BRepMesh_PairOfPolygon.hxx> | |
16 | #include <BRepMesh_DataMapIteratorOfDataMapOfShapePairOfPolygon.hxx> | |
17 | #include <BRep_ListIteratorOfListOfPointRepresentation.hxx> | |
18 | #include <BRepMesh_ClassifierPtr.hxx> | |
19 | #include <BRep_Builder.hxx> | |
20 | #include <BRep_PointRepresentation.hxx> | |
21 | #include <BRep_TVertex.hxx> | |
22 | #include <BRep_Tool.hxx> | |
23 | #include <Geom_Surface.hxx> | |
24 | #include <ElSLib.hxx> | |
7fd59977 | 25 | #include <Standard_ErrorHandler.hxx> |
26 | #include <Standard_Failure.hxx> | |
b0cf1019 | 27 | #include <SortTools_ShellSortOfReal.hxx> |
7fd59977 | 28 | #include <Poly_PolygonOnTriangulation.hxx> |
29 | #include <Poly_Triangulation.hxx> | |
b0cf1019 | 30 | #include <TCollection_CompareOfReal.hxx> |
7fd59977 | 31 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 | 32 | #include <TColStd_SequenceOfReal.hxx> |
33 | #include <TColStd_Array1OfInteger.hxx> | |
7fd59977 | 34 | #include <TColStd_HArray1OfReal.hxx> |
7fd59977 | 35 | #include <TopExp_Explorer.hxx> |
7fd59977 | 36 | #include <TopoDS.hxx> |
37 | #include <TopExp.hxx> | |
38 | #include <TColgp_Array1OfPnt2d.hxx> | |
39 | #include <NCollection_Map.hxx> | |
40 | #include <Geom_BSplineSurface.hxx> | |
41 | #include <GeomLib.hxx> | |
42 | #include <Bnd_Box2d.hxx> | |
43 | ||
51c3cc5f O |
44 | #define UVDEFLECTION 1.e-05 |
45 | ||
7fd59977 | 46 | static Standard_Real FUN_CalcAverageDUV(TColStd_Array1OfReal& P, const Standard_Integer PLen) |
47 | { | |
48 | Standard_Integer i, j, n = 0; | |
49 | Standard_Real p, result = 0.; | |
50 | ||
51 | for(i = 1; i <= PLen; i++) | |
52 | { | |
53 | // Sort | |
54 | for(j = i + 1; j <= PLen; j++) | |
55 | { | |
56 | if(P(i) > P(j)) | |
57 | { | |
58 | p = P(i); | |
59 | P(i) = P(j); | |
60 | P(j) = p; | |
61 | } | |
62 | } | |
63 | // Accumulate | |
64 | if (i != 1) | |
65 | { | |
66 | p = Abs(P(i) - P(i-1)); | |
67 | if(p > 1.e-7) | |
68 | { | |
69 | result += p; | |
70 | n++; | |
71 | } | |
72 | } | |
73 | } | |
74 | return (n? (result / (Standard_Real) n) : -1.); | |
75 | } | |
76 | ||
77 | //======================================================================= | |
78 | //function : BRepMesh_FastDiscretFace | |
79 | //purpose : | |
80 | //======================================================================= | |
c80dc6c3 O |
81 | BRepMesh_FastDiscretFace::BRepMesh_FastDiscretFace |
82 | (const Standard_Real theAngle, | |
83 | const Standard_Boolean theWithShare) : | |
84 | myAngle(theAngle), myWithShare(theWithShare), myNbLocat(0), | |
7fd59977 | 85 | myInternalVerticesMode(Standard_True) |
86 | { | |
87 | myAllocator = new NCollection_IncAllocator(64000); | |
88 | } | |
89 | ||
90 | //======================================================================= | |
91 | //function : Add(face) | |
92 | //purpose : | |
93 | //======================================================================= | |
94 | ||
c80dc6c3 O |
95 | void BRepMesh_FastDiscretFace::Add(const TopoDS_Face& theFace, |
96 | const Handle(BRepMesh_FaceAttribute)& theAttrib, | |
97 | const TopTools_DataMapOfShapeReal& theMapDefle) | |
7fd59977 | 98 | { |
99 | #ifndef DEB_MESH | |
100 | try | |
101 | { | |
102 | OCC_CATCH_SIGNALS | |
103 | #endif | |
c80dc6c3 O |
104 | TopoDS_Face face = theFace; |
105 | TopLoc_Location loc; | |
106 | ||
107 | const Handle(Poly_Triangulation)& aFaceTrigu = BRep_Tool::Triangulation(face, loc); | |
108 | if ( aFaceTrigu.IsNull() ) | |
109 | return; | |
110 | ||
111 | myAttrib = theAttrib; | |
7fd59977 | 112 | face.Orientation(TopAbs_FORWARD); |
c80dc6c3 | 113 | myStructure.Nullify(); |
7fd59977 | 114 | Handle(NCollection_IncAllocator) anAlloc = Handle(NCollection_IncAllocator)::DownCast(myAllocator); |
115 | anAlloc->Reset(Standard_False); | |
c80dc6c3 | 116 | myStructure=new BRepMesh_DataStructureOfDelaun(anAlloc); |
51c3cc5f O |
117 | |
118 | Standard_Real umax = myAttrib->GetUMax(); | |
119 | Standard_Real umin = myAttrib->GetUMin(); | |
120 | Standard_Real vmax = myAttrib->GetVMax(); | |
121 | Standard_Real vmin = myAttrib->GetVMin(); | |
122 | ||
123 | Standard_Real aTolU = (umax - umin) * UVDEFLECTION; | |
124 | Standard_Real aTolV = (vmax - vmin) * UVDEFLECTION; | |
125 | Standard_Real uCellSize = 14 * aTolU; | |
126 | Standard_Real vCellSize = 14 * aTolV; | |
127 | ||
128 | myStructure->Data().SetCellSize ( uCellSize, vCellSize ); | |
129 | myStructure->Data().SetTolerance( aTolU, aTolV ); | |
130 | ||
131 | ||
7fd59977 | 132 | BRepAdaptor_Surface BS(face, Standard_False); |
133 | Handle(BRepAdaptor_HSurface) gFace = new BRepAdaptor_HSurface(BS); | |
134 | ||
135 | GeomAbs_SurfaceType thetype; | |
136 | thetype = BS.GetType(); | |
137 | ||
7fd59977 | 138 | TopAbs_Orientation orFace = face.Orientation(); |
7fd59977 | 139 | |
c80dc6c3 O |
140 | if (!myWithShare) |
141 | myVertices.Clear(); | |
7fd59977 | 142 | |
c80dc6c3 O |
143 | myListver.Clear(); |
144 | myVemap.Clear(); | |
145 | myLocation2d.Clear(); | |
146 | myInternaledges.Clear(); | |
7fd59977 | 147 | |
148 | Standard_Integer i = 1; | |
7fd59977 | 149 | Standard_Integer ipn = 0; |
c80dc6c3 | 150 | |
7fd59977 | 151 | TopoDS_Iterator exW(face); |
152 | for (; exW.More(); exW.Next()) { | |
153 | const TopoDS_Shape& aWire = exW.Value(); | |
154 | if (aWire.ShapeType() != TopAbs_WIRE) | |
c80dc6c3 | 155 | continue; |
7fd59977 | 156 | TopoDS_Iterator ex(aWire); |
157 | for(; ex.More(); ex.Next()) { | |
c80dc6c3 O |
158 | const TopoDS_Edge& edge = TopoDS::Edge(ex.Value()); |
159 | if(edge.IsNull()) | |
160 | continue; | |
161 | ||
162 | RestoreStructureFromTriangulation(edge, face, gFace, aFaceTrigu, theMapDefle(edge), loc); | |
7fd59977 | 163 | } |
164 | } | |
165 | ||
166 | //////////////////////////////////////////////////////////// | |
167 | //add internal vertices after self-intersection check | |
168 | Standard_Integer nbVertices = 0; | |
169 | if(myInternalVerticesMode) { | |
170 | for(TopExp_Explorer ex(face,TopAbs_VERTEX ,TopAbs_EDGE); ex.More(); ex.Next()) { | |
c80dc6c3 O |
171 | const TopoDS_Vertex& aVert = TopoDS::Vertex(ex.Current()); |
172 | Add(aVert,face,gFace); | |
7fd59977 | 173 | } |
c80dc6c3 | 174 | nbVertices = myVemap.Extent(); |
7fd59977 | 175 | } |
176 | ||
177 | // essai de determination de la longueur vraie: | |
178 | // akm (bug OCC16) : We must calculate these measures in non-singular | |
179 | // parts of face. Let`s try to compute average value of three | |
180 | // (umin, (umin+umax)/2, umax), and respectively for v. | |
181 | // vvvvv | |
182 | //Standard_Real longu = 0.0, longv = 0.0; //, last , first; | |
183 | //gp_Pnt P11, P12, P21, P22, P31, P32; | |
184 | ||
51c3cc5f O |
185 | Standard_Real deltaX = myAttrib->GetDeltaX(); |
186 | Standard_Real deltaY = myAttrib->GetDeltaY(); | |
7fd59977 | 187 | |
188 | TColStd_Array1OfInteger tabvert_corr(1, nbVertices); | |
189 | gp_Pnt2d p2d; | |
190 | ||
191 | // Check the necessity to fill the map of parameters | |
192 | const Standard_Boolean useUVParam = (thetype == GeomAbs_Torus || | |
c80dc6c3 O |
193 | thetype == GeomAbs_BezierSurface || |
194 | thetype == GeomAbs_BSplineSurface); | |
7fd59977 | 195 | myUParam.Clear(); |
196 | myVParam.Clear(); | |
197 | ||
51c3cc5f | 198 | BRepMesh_VertexTool aMoveNodes(myVemap.Extent(), myAllocator); |
7fd59977 | 199 | |
51c3cc5f O |
200 | aMoveNodes.SetCellSize ( uCellSize / deltaX, vCellSize / deltaY); |
201 | aMoveNodes.SetTolerance( aTolU / deltaX, aTolV / deltaY); | |
202 | ||
c80dc6c3 | 203 | for (i = 1; i <= myStructure->NbNodes(); i++) |
7fd59977 | 204 | { |
c80dc6c3 | 205 | const BRepMesh_Vertex& v = myStructure->GetNode(i); |
7fd59977 | 206 | p2d = v.Coord(); |
207 | if (useUVParam) { | |
c80dc6c3 O |
208 | myUParam.Add(p2d.X()); |
209 | myVParam.Add(p2d.Y()); | |
7fd59977 | 210 | } |
211 | gp_XY res; | |
51c3cc5f O |
212 | res.SetCoord((p2d.X() - umin ) / deltaX, |
213 | (p2d.Y() - vmin ) / deltaY); | |
7fd59977 | 214 | BRepMesh_Vertex v_new(res,v.Location3d(),v.Movability()); |
c80dc6c3 | 215 | const BRepMesh_ListOfInteger& alist = myStructure->GetNodeList(i); |
51c3cc5f | 216 | aMoveNodes.Add(v_new, alist); |
7fd59977 | 217 | tabvert_corr(i) = i; |
c80dc6c3 O |
218 | } |
219 | myStructure->ReplaceNodes(aMoveNodes); | |
2b59653e | 220 | |
7fd59977 | 221 | Standard_Boolean rajout; |
222 | ||
c80dc6c3 | 223 | BRepMesh_ClassifierPtr& classifier = theAttrib->GetClassifier(); |
7fd59977 | 224 | |
225 | switch (thetype) | |
226 | { | |
7fd59977 | 227 | case GeomAbs_Sphere: |
228 | case GeomAbs_Torus: | |
229 | rajout = Standard_True; | |
230 | break; | |
231 | default: | |
232 | rajout = Standard_False; | |
233 | } | |
234 | ||
c80dc6c3 | 235 | BRepMesh_Delaun trigu(myStructure, tabvert_corr, orFace==TopAbs_FORWARD); |
7fd59977 | 236 | |
237 | //removed all free edges from triangulation | |
c80dc6c3 | 238 | Standard_Integer nbLinks = myStructure->NbNodes(); |
7fd59977 | 239 | for(i = 1; i <= nbLinks; i++) |
240 | { | |
c80dc6c3 | 241 | if(myStructure->ElemConnectedTo(i).Extent() < 1) |
7fd59977 | 242 | { |
243 | BRepMesh_Edge& anEdge = (BRepMesh_Edge&)trigu.GetEdge(i); | |
c80dc6c3 | 244 | if(anEdge.Movability()==BRepMesh_Deleted) |
7fd59977 | 245 | continue; |
c80dc6c3 O |
246 | anEdge.SetMovability(BRepMesh_Free); |
247 | myStructure->RemoveLink(i); | |
7fd59977 | 248 | } |
249 | } | |
250 | ||
251 | Standard_Boolean isaline; | |
51c3cc5f | 252 | isaline = ((umax-umin) < UVDEFLECTION) || ((vmax-vmin) < UVDEFLECTION); |
7fd59977 | 253 | |
254 | Standard_Real aDef = -1; | |
c80dc6c3 | 255 | if (!isaline && myStructure->ElemOfDomain().Extent() > 0) { |
7fd59977 | 256 | TColStd_ListOfInteger badTri, nulTri; |
257 | ||
258 | if(!rajout) | |
259 | { | |
c80dc6c3 O |
260 | aDef = Control(gFace, theAttrib->GetDefFace(), myListver, badTri, nulTri, trigu, Standard_True); |
261 | if( aDef > theAttrib->GetDefFace() || aDef < 0.) | |
262 | rajout = Standard_True; | |
7fd59977 | 263 | } |
264 | ||
265 | if(!rajout) { | |
c80dc6c3 O |
266 | if(useUVParam) { |
267 | if(BS.IsUClosed()) { | |
268 | if(myVParam.Extent() > 2) { | |
269 | rajout = Standard_True; | |
270 | } | |
271 | } | |
272 | if(BS.IsVClosed()) { | |
273 | if(myUParam.Extent() > 2) { | |
274 | rajout = Standard_True; | |
275 | } | |
276 | } | |
277 | } | |
7fd59977 | 278 | } |
279 | ||
280 | if(rajout){ | |
c80dc6c3 O |
281 | InternalVertices(gFace, myListver, theAttrib->GetDefFace(), classifier); |
282 | ||
283 | if (myListver.Extent() > 0) { | |
284 | BRepMesh_Array1OfVertexOfDelaun verttab(1, myListver.Extent()); | |
285 | BRepMesh_ListIteratorOfListOfVertex itVer(myListver); | |
286 | ipn = 1; | |
287 | for (; itVer.More(); itVer.Next()) | |
288 | verttab(ipn++) = itVer.Value(); | |
289 | trigu.AddVertices(verttab); | |
290 | } | |
291 | //control internal points | |
292 | BRepMesh_ListOfVertex vvlist; | |
293 | aDef = Control(gFace, theAttrib->GetDefFace(), vvlist, badTri, nulTri, trigu, Standard_False); | |
294 | myListver.Append(vvlist); | |
7fd59977 | 295 | } |
296 | } | |
297 | ||
c80dc6c3 | 298 | //modify myStructure back |
51c3cc5f O |
299 | aMoveNodes.SetCellSize ( uCellSize, vCellSize ); |
300 | aMoveNodes.SetTolerance( aTolU , aTolV ); | |
c80dc6c3 | 301 | for (i = 1; i <= myStructure->NbNodes(); i++) |
7fd59977 | 302 | { |
c80dc6c3 | 303 | const BRepMesh_Vertex& v = myStructure->GetNode(i); |
7fd59977 | 304 | p2d = v.Coord(); |
305 | gp_XY res; | |
51c3cc5f | 306 | res.SetCoord(p2d.X() * deltaX + umin, p2d.Y() * deltaY + vmin); |
7fd59977 | 307 | BRepMesh_Vertex v_new(res,v.Location3d(),v.Movability()); |
c80dc6c3 | 308 | const BRepMesh_ListOfInteger& alist = myStructure->GetNodeList(i); |
51c3cc5f | 309 | aMoveNodes.Add(v_new, alist); |
7fd59977 | 310 | } |
c80dc6c3 | 311 | myStructure->ReplaceNodes(aMoveNodes); |
7fd59977 | 312 | |
c80dc6c3 | 313 | AddInShape(face, (aDef < 0.0)? theAttrib->GetDefFace() : aDef); |
7fd59977 | 314 | #ifndef DEB_MESH |
315 | } | |
316 | catch(Standard_Failure) | |
317 | { | |
318 | BRep_Builder B; | |
319 | Handle(Poly_Triangulation) TNull; | |
c80dc6c3 | 320 | B.UpdateFace(theFace,TNull); |
7fd59977 | 321 | } |
322 | #endif // DEB_MESH | |
c80dc6c3 O |
323 | myStructure.Nullify(); |
324 | myAttrib.Nullify(); | |
7fd59977 | 325 | } |
326 | ||
327 | //======================================================================= | |
c80dc6c3 O |
328 | //function : RestoreStructureFromTriangulation(edge) |
329 | //purpose : Restore structure of Delaun from triangulation on face | |
7fd59977 | 330 | //======================================================================= |
c80dc6c3 O |
331 | Standard_Boolean BRepMesh_FastDiscretFace::RestoreStructureFromTriangulation |
332 | (const TopoDS_Edge& theEdge, | |
333 | const TopoDS_Face& theFace, | |
334 | const Handle(BRepAdaptor_HSurface)& theSurf, | |
335 | const Handle(Poly_Triangulation)& theTrigu, | |
336 | const Standard_Real theDefEdge, | |
337 | const TopLoc_Location& theLoc) | |
7fd59977 | 338 | { |
c80dc6c3 O |
339 | // oan: changes for right restoring of triangulation data from face & edges |
340 | Handle(Poly_PolygonOnTriangulation) Poly; | |
341 | Poly = BRep_Tool::PolygonOnTriangulation(theEdge, theTrigu, theLoc); | |
7fd59977 | 342 | |
c80dc6c3 | 343 | if (Poly.IsNull() || !Poly->HasParameters()) |
7fd59977 | 344 | { |
c80dc6c3 O |
345 | return Standard_False; |
346 | } | |
347 | ||
348 | // 2d vertex indices | |
349 | TopAbs_Orientation orEdge = theEdge.Orientation(); | |
350 | // Get end points on 2d curve | |
351 | gp_Pnt2d uvFirst, uvLast; | |
352 | BRep_Tool::UVPoints(theEdge, theFace, uvFirst, uvLast); | |
7fd59977 | 353 | |
c80dc6c3 O |
354 | // Get vertices |
355 | TopoDS_Vertex pBegin, pEnd; | |
356 | TopExp::Vertices(theEdge,pBegin,pEnd); | |
b0cf1019 | 357 | |
c80dc6c3 O |
358 | const Standard_Boolean sameUV = |
359 | uvFirst.IsEqual(uvLast, Precision::PConfusion()); | |
b0cf1019 | 360 | |
c80dc6c3 O |
361 | const TColgp_Array1OfPnt2d& UVNodes = theTrigu->UVNodes(); |
362 | const TColgp_Array1OfPnt& Nodes = theTrigu->Nodes(); | |
363 | const TColStd_Array1OfInteger& Indices = Poly->Nodes(); | |
b0cf1019 | 364 | |
c80dc6c3 O |
365 | const Standard_Integer nbnodes = Indices.Length(); |
366 | TColStd_Array1OfInteger NewNodes(1, nbnodes); | |
367 | ||
368 | gp_Pnt P3d; | |
369 | gp_XY anUV; | |
b0cf1019 | 370 | |
c80dc6c3 O |
371 | // Process first vertex |
372 | Standard_Integer ipf; | |
373 | if (myVertices.IsBound(pBegin)) | |
374 | { | |
375 | ipf = myVertices.Find(pBegin); | |
376 | } | |
377 | else | |
378 | { | |
379 | if (sameUV && myVertices.IsBound(pEnd)) | |
380 | { | |
381 | ipf = myVertices.Find(pEnd); | |
382 | } | |
383 | else | |
384 | { | |
385 | P3d = Nodes(Indices(1)); | |
386 | if (!theLoc.IsIdentity()) | |
387 | P3d.Transform(theLoc.Transformation()); | |
388 | myNbLocat++; | |
389 | myLocation3d.Bind(myNbLocat, P3d); | |
390 | ipf = myNbLocat; | |
391 | } | |
392 | myVertices.Bind(pBegin,ipf); | |
393 | } | |
394 | ||
395 | //Controle vertice tolerances | |
396 | gp_Pnt pFirst = theSurf->Value(uvFirst.X(), uvFirst.Y()); | |
397 | gp_Pnt pLast = theSurf->Value(uvLast.X(), uvLast.Y()); | |
398 | ||
399 | Standard_Real mindist = 10. * Max(pFirst.Distance(BRep_Tool::Pnt(pBegin)), | |
400 | pLast.Distance(BRep_Tool::Pnt(pEnd))); | |
b0cf1019 | 401 | |
c80dc6c3 O |
402 | if (mindist < BRep_Tool::Tolerance(pBegin) || |
403 | mindist < BRep_Tool::Tolerance(pEnd) ) mindist = theDefEdge; | |
404 | ||
405 | anUV = FindUV(pBegin, uvFirst, ipf, theSurf, mindist, myLocation2d); | |
406 | Standard_Integer iv1, isv1; | |
407 | BRepMesh_Vertex vf(anUV, ipf, BRepMesh_Frontier); | |
408 | iv1 = myStructure->AddNode(vf); | |
409 | isv1 = myVemap.FindIndex(iv1); | |
410 | if (isv1 == 0) | |
411 | isv1 = myVemap.Add(iv1); | |
412 | NewNodes(1) = isv1; | |
413 | ||
414 | // Process last vertex | |
415 | Standard_Integer ipl, ivl; | |
416 | if (pEnd.IsSame(pBegin)) | |
417 | { | |
418 | ipl = ipf; | |
419 | } | |
420 | else | |
421 | { | |
422 | if (myVertices.IsBound(pEnd)) | |
423 | { | |
424 | ipl = myVertices.Find(pEnd); | |
425 | } | |
426 | else | |
427 | { | |
428 | if (sameUV) | |
429 | { | |
430 | ipl = ipf; | |
431 | ivl = iv1; | |
7fd59977 | 432 | } |
433 | else | |
434 | { | |
c80dc6c3 O |
435 | P3d = Nodes(Indices(nbnodes)); |
436 | if (!theLoc.IsIdentity()) | |
437 | P3d.Transform(theLoc.Transformation()); | |
438 | myNbLocat++; | |
439 | myLocation3d.Bind(myNbLocat, P3d); | |
440 | ipl = myNbLocat; | |
7fd59977 | 441 | } |
c80dc6c3 | 442 | myVertices.Bind(pEnd,ipl); |
7fd59977 | 443 | } |
444 | } | |
7fd59977 | 445 | |
c80dc6c3 O |
446 | anUV = FindUV(pEnd, uvLast, ipl, theSurf, mindist, myLocation2d); |
447 | BRepMesh_Vertex vl(anUV, ipl, BRepMesh_Frontier); | |
448 | ||
449 | Standard_Integer isvl; | |
450 | ivl = myStructure->AddNode(vl); | |
451 | isvl = myVemap.FindIndex(ivl); | |
452 | if (isvl == 0) | |
453 | isvl = myVemap.Add(ivl); | |
454 | NewNodes(nbnodes) = isvl; | |
455 | ||
456 | BRepMesh_Vertex v; | |
7fd59977 | 457 | |
c80dc6c3 O |
458 | Standard_Integer i; |
459 | for (i = 2; i < nbnodes; i++) | |
460 | { | |
461 | // Record 3d point | |
462 | P3d = Nodes(Indices(i)); | |
463 | if (!theLoc.IsIdentity()) | |
464 | P3d.Transform(theLoc.Transformation()); | |
465 | myNbLocat++; | |
466 | myLocation3d.Bind(myNbLocat, P3d); | |
467 | ||
468 | // Record 2d point | |
469 | anUV = UVNodes(Indices(i)).Coord(); | |
470 | ||
471 | Standard_Integer iv2, isv; | |
472 | v.Initialize(anUV, myNbLocat, BRepMesh_Frontier); | |
473 | iv2 = myStructure->AddNode(v); | |
474 | isv = myVemap.FindIndex(iv2); | |
475 | if (isv == 0) | |
476 | isv = myVemap.Add(iv2); | |
477 | NewNodes(i) = isv; | |
478 | ||
479 | //add links | |
480 | if (orEdge == TopAbs_FORWARD) | |
481 | myStructure->AddLink(BRepMesh_Edge(iv1,iv2,BRepMesh_Frontier)); | |
482 | else if (orEdge == TopAbs_REVERSED) | |
483 | myStructure->AddLink(BRepMesh_Edge(iv2,iv1,BRepMesh_Frontier)); | |
484 | else if (orEdge == TopAbs_INTERNAL) | |
485 | myStructure->AddLink(BRepMesh_Edge(iv1,iv2,BRepMesh_Fixed)); | |
486 | iv1 = iv2; | |
487 | } | |
488 | ||
489 | // last point | |
490 | if (iv1 != ivl) { | |
491 | if (orEdge == TopAbs_FORWARD) | |
492 | myStructure->AddLink(BRepMesh_Edge(iv1,ivl,BRepMesh_Frontier)); | |
493 | else if (orEdge == TopAbs_REVERSED) | |
494 | myStructure->AddLink(BRepMesh_Edge(ivl,iv1,BRepMesh_Frontier)); | |
495 | else if (orEdge == TopAbs_INTERNAL) | |
496 | myStructure->AddLink(BRepMesh_Edge(iv1,ivl,BRepMesh_Fixed)); | |
497 | } | |
498 | ||
499 | Handle(Poly_PolygonOnTriangulation) P1 = | |
500 | new Poly_PolygonOnTriangulation(NewNodes, Poly->Parameters()->Array1()); | |
501 | P1->Deflection(theDefEdge); | |
502 | if (myInternaledges.IsBound(theEdge)) | |
503 | { | |
504 | BRepMesh_PairOfPolygon& pair = myInternaledges.ChangeFind(theEdge); | |
505 | if (theEdge.Orientation() == TopAbs_REVERSED) | |
506 | pair.Append(P1); | |
507 | else | |
508 | pair.Prepend(P1); | |
509 | } | |
510 | else | |
511 | { | |
512 | BRepMesh_PairOfPolygon pair1; | |
513 | pair1.Append(P1); | |
514 | myInternaledges.Bind(theEdge, pair1); | |
515 | } | |
b0cf1019 | 516 | |
c80dc6c3 O |
517 | return Standard_True; |
518 | } | |
b0cf1019 P |
519 | |
520 | //======================================================================= | |
521 | //function : InternalVertices | |
522 | //purpose : | |
523 | //======================================================================= | |
524 | ||
b0cf1019 P |
525 | static void filterParameters(const TColStd_IndexedMapOfReal& theParams, |
526 | const Standard_Real theMinDist, | |
527 | const Standard_Real theFilterDist, | |
528 | TColStd_SequenceOfReal& theResult) | |
529 | { | |
530 | // Sort sequence of parameters | |
531 | TColStd_SequenceOfReal aParamTmp; | |
532 | Standard_Integer aParamLength = 1; | |
533 | const Standard_Integer anInitLen = theParams.Extent(); | |
703a6abd | 534 | |
b0cf1019 P |
535 | TColStd_Array1OfReal aParamArray(1, anInitLen); |
536 | Standard_Integer j; | |
537 | for (j = 1; j <= anInitLen; j++) | |
538 | aParamArray(j) = theParams(j); | |
539 | ||
540 | TCollection_CompareOfReal aCompare; | |
541 | SortTools_ShellSortOfReal::Sort(aParamArray, aCompare); | |
542 | ||
0d969553 | 543 | // mandadory pre-filtering using the first (minimal) filter value |
b0cf1019 P |
544 | Standard_Real aP1, aP2; |
545 | aP1 = aParamArray(1); | |
546 | aParamTmp.Append(aP1); | |
547 | for (j = 2; j <= anInitLen; j++) | |
548 | { | |
549 | aP2 = aParamArray(j); | |
550 | if ((aP2-aP1) > theMinDist) | |
551 | { | |
552 | aParamTmp.Append(aP2); | |
553 | aP1 = aP2; | |
554 | aParamLength++; | |
555 | } | |
703a6abd | 556 | } |
b0cf1019 P |
557 | |
558 | //add last point if required | |
559 | if(aParamArray(anInitLen)-theParams(aParamLength) > theMinDist) | |
703a6abd | 560 | { |
b0cf1019 P |
561 | aParamTmp.Append(aParamArray(anInitLen)); |
562 | aParamLength++; | |
703a6abd | 563 | } |
b0cf1019 P |
564 | |
565 | //perform filtering on series | |
566 | Standard_Real aLastAdded, aLastCandidate; | |
567 | Standard_Boolean isCandidateDefined = Standard_False; | |
568 | aLastAdded = aParamTmp.First(); | |
569 | aLastCandidate = aLastAdded; | |
570 | theResult.Append(aParamTmp.First()); | |
571 | ||
572 | for(j=2;j<aParamTmp.Length();j++) | |
703a6abd | 573 | { |
b0cf1019 P |
574 | Standard_Real aVal = aParamTmp.Value(j); |
575 | if(aVal-aLastAdded > theFilterDist) | |
576 | { | |
577 | //adds the parameter | |
578 | if(isCandidateDefined) { | |
579 | aLastAdded = aLastCandidate; | |
580 | isCandidateDefined = Standard_False; | |
581 | j--; | |
582 | } | |
583 | else | |
584 | { | |
585 | aLastAdded = aVal; | |
586 | } | |
587 | theResult.Append(aLastAdded); | |
588 | continue; | |
589 | } | |
590 | ||
591 | aLastCandidate = aVal; | |
592 | isCandidateDefined = Standard_True; | |
703a6abd | 593 | } |
b0cf1019 | 594 | theResult.Append(aParamTmp.Last()); |
4071d9e6 O |
595 | |
596 | if( theResult.Length() == 2 ) | |
597 | { | |
598 | Standard_Real dist = theResult.Last() - theResult.First(); | |
599 | Standard_Integer nbint = (Standard_Integer)((dist / theFilterDist) + 0.5); | |
600 | ||
601 | if( nbint > 1 ) | |
602 | { | |
603 | //Five points more is maximum | |
604 | if( nbint > 5 ) | |
605 | { | |
606 | nbint = 5; | |
607 | } | |
608 | ||
609 | Standard_Integer i; | |
610 | Standard_Real dU = dist / nbint; | |
611 | for( i = 1; i < nbint; i++ ) | |
612 | { | |
613 | theResult.InsertAfter(i, theResult.First()+i*dU); | |
614 | } | |
615 | } | |
616 | } | |
703a6abd | 617 | } |
7fd59977 | 618 | |
c80dc6c3 O |
619 | void BRepMesh_FastDiscretFace::InternalVertices(const Handle(BRepAdaptor_HSurface)& theCaro, |
620 | BRepMesh_ListOfVertex& theInternalV, | |
621 | const Standard_Real theDefFace, | |
622 | const BRepMesh_ClassifierPtr& theClassifier) | |
7fd59977 | 623 | { |
624 | BRepMesh_Vertex newV; | |
625 | gp_Pnt2d p2d; | |
626 | gp_Pnt p3d; | |
627 | ||
0d969553 | 628 | // work following the type of surface |
c80dc6c3 O |
629 | const BRepAdaptor_Surface& BS = *(BRepAdaptor_Surface*)&(theCaro->Surface()); |
630 | GeomAbs_SurfaceType thetype = theCaro->GetType(); | |
7fd59977 | 631 | |
c80dc6c3 O |
632 | Standard_Real umax = myAttrib->GetUMax(); |
633 | Standard_Real umin = myAttrib->GetUMin(); | |
634 | Standard_Real vmax = myAttrib->GetVMax(); | |
635 | Standard_Real vmin = myAttrib->GetVMin(); | |
636 | Standard_Real deltaX = myAttrib->GetDeltaX(); | |
637 | Standard_Real deltaY = myAttrib->GetDeltaY(); | |
7fd59977 | 638 | |
2b59653e E |
639 | if (thetype == GeomAbs_Sphere) |
640 | { | |
641 | gp_Sphere S = BS.Sphere(); | |
7fd59977 | 642 | const Standard_Real R = S.Radius(); |
643 | ||
644 | // Calculate parameters for iteration in V direction | |
c80dc6c3 | 645 | Standard_Real Dv = 1.0 - (theDefFace/R); |
7fd59977 | 646 | if (Dv < 0.0) Dv = 0.0; |
647 | Standard_Real oldDv = 2.0 * ACos (Dv); | |
648 | Dv = .7 * oldDv; //.7 ~= sqrt(2.) - Dv is hypotenuse of triangle when oldDv is legs | |
649 | const Standard_Real sv = vmax - vmin; | |
650 | Dv = sv/((Standard_Integer)(sv/Dv) + 1); | |
651 | const Standard_Real pasvmax = vmax-Dv*0.5; | |
652 | ||
653 | //Du can be defined from relation: 2*r*Sin(Du/2) = 2*R*Sin(Dv/2), r = R*Cos(v) | |
654 | //here approximate relation r*Du = R*Dv is used | |
655 | ||
656 | Standard_Real Du, pasu, pasv; //, ru; | |
657 | const Standard_Real su = umax-umin; | |
658 | Standard_Boolean Shift = Standard_False; | |
659 | for (pasv = vmin + Dv; pasv < pasvmax; pasv += Dv) | |
660 | { | |
661 | // Calculate parameters for iteration in U direction | |
662 | // 1.-.365*pasv*pasv is simple approximation of Cos(pasv) | |
663 | // with condition that it gives ~.1 when pasv = pi/2 | |
664 | Du = Dv/(1.-.365*pasv*pasv); | |
665 | Du = su/((Standard_Integer)(su/Du) + 1); | |
666 | Shift = !Shift; | |
667 | const Standard_Real d = (Shift)? Du*.5 : 0.; | |
668 | const Standard_Real pasumax = umax-Du*0.5 + d; | |
669 | for (pasu = umin + Du - d; pasu < pasumax; pasu += Du) | |
670 | { | |
c80dc6c3 | 671 | if (theClassifier->Perform(gp_Pnt2d(pasu, pasv)) == TopAbs_IN) |
7fd59977 | 672 | { |
673 | // Record 3d point | |
674 | #ifdef DEB_MESH_CHRONO | |
c80dc6c3 | 675 | D0Internal++; |
7fd59977 | 676 | #endif |
c80dc6c3 O |
677 | ElSLib::D0(pasu, pasv, S, p3d); |
678 | myNbLocat++; | |
679 | myLocation3d.Bind(myNbLocat, p3d); | |
7fd59977 | 680 | // Record 2d point |
c80dc6c3 O |
681 | p2d.SetCoord((pasu-umin)/deltaX, (pasv-vmin)/deltaY); |
682 | newV.Initialize(p2d.XY(), myNbLocat, BRepMesh_Free); | |
683 | theInternalV.Append(newV); | |
684 | } | |
7fd59977 | 685 | } |
686 | } | |
687 | } | |
688 | else if (thetype == GeomAbs_Cylinder) | |
689 | { | |
690 | gp_Cylinder S = BS.Cylinder(); | |
691 | const Standard_Real R = S.Radius(); | |
692 | ||
693 | // Calculate parameters for iteration in U direction | |
c80dc6c3 | 694 | Standard_Real Du = 1.0 - (theDefFace/R); |
7fd59977 | 695 | if (Du < 0.0) Du = 0.0; |
696 | Du = 2.0 * ACos (Du); | |
c80dc6c3 | 697 | if (Du > myAngle) Du = myAngle; |
7fd59977 | 698 | const Standard_Real su = umax - umin; |
699 | const Standard_Integer nbU = (Standard_Integer)(su/Du); | |
700 | Du = su/(nbU+1); | |
701 | ||
702 | // Calculate parameters for iteration in V direction | |
703 | const Standard_Real sv = vmax - vmin; | |
704 | Standard_Integer nbV = (Standard_Integer)( nbU*sv/(su*R) ); | |
705 | nbV = Min(nbV, 100*nbU); | |
706 | Standard_Real Dv = sv/(nbV+1); | |
707 | ||
708 | Standard_Real pasu, pasv, pasvmax = vmax-Dv*0.5, pasumax = umax-Du*0.5; | |
709 | for (pasv = vmin + Dv; pasv < pasvmax; pasv += Dv) { | |
710 | for (pasu = umin + Du; pasu < pasumax; pasu += Du) { | |
c80dc6c3 | 711 | if (theClassifier->Perform(gp_Pnt2d(pasu, pasv)) == TopAbs_IN) |
7fd59977 | 712 | { |
713 | // Record 3d point | |
c80dc6c3 O |
714 | ElSLib::D0(pasu, pasv, S, p3d); |
715 | myNbLocat++; | |
716 | myLocation3d.Bind(myNbLocat, p3d); | |
7fd59977 | 717 | // Record 2d point |
c80dc6c3 O |
718 | p2d.SetCoord((pasu-umin)/deltaX, (pasv-vmin)/deltaY); |
719 | newV.Initialize(p2d.XY(), myNbLocat, BRepMesh_Free); | |
720 | theInternalV.Append(newV); | |
721 | } | |
7fd59977 | 722 | } |
723 | } | |
724 | } | |
725 | else if (thetype == GeomAbs_Cone) | |
726 | { | |
727 | Standard_Real R, RefR, SAng; | |
728 | gp_Cone C = BS.Cone(); | |
729 | RefR = C.RefRadius(); | |
730 | SAng = C.SemiAngle(); | |
731 | R = Max(Abs(RefR+vmin*Sin(SAng)), Abs(RefR+vmax*Sin(SAng))); | |
732 | Standard_Real Du, Dv, pasu, pasv; | |
c80dc6c3 | 733 | Du = Max(1.0e0 - (theDefFace/R),0.0e0); |
7fd59977 | 734 | Du = (2.0 * ACos (Du)); |
735 | Standard_Integer nbU = (Standard_Integer) ( (umax-umin)/Du ); | |
736 | Standard_Integer nbV = (Standard_Integer) ( nbU*(vmax-vmin)/((umax-umin)*R) ); | |
737 | Du = (umax-umin)/(nbU+1); | |
738 | Dv = (vmax-vmin)/(nbV+1); | |
739 | ||
740 | Standard_Real pasvmax = vmax-Dv*0.5, pasumax = umax-Du*0.5; | |
741 | for (pasv = vmin + Dv; pasv < pasvmax; pasv += Dv) { | |
742 | for (pasu = umin + Du; pasu < pasumax; pasu += Du) { | |
c80dc6c3 | 743 | if (theClassifier->Perform(gp_Pnt2d(pasu, pasv)) == TopAbs_IN) |
7fd59977 | 744 | { |
745 | // Record 3d point | |
c80dc6c3 O |
746 | ElSLib::D0(pasu, pasv, C, p3d); |
747 | myNbLocat++; | |
748 | myLocation3d.Bind(myNbLocat, p3d); | |
7fd59977 | 749 | // Record 2d point |
750 | p2d.SetCoord((pasu-umin)/deltaX, (pasv-vmin)/deltaY); | |
c80dc6c3 O |
751 | newV.Initialize(p2d.XY(), myNbLocat, BRepMesh_Free); |
752 | theInternalV.Append(newV); | |
753 | } | |
7fd59977 | 754 | } |
755 | } | |
756 | } | |
757 | else if (thetype == GeomAbs_Torus) | |
758 | { | |
759 | gp_Torus T = BS.Torus(); | |
760 | ||
761 | Standard_Boolean insert; | |
762 | Standard_Integer i, j, ParamULength, ParamVLength; | |
763 | Standard_Real pp, pasu, pasv; | |
764 | Standard_Real r = T.MinorRadius(), R = T.MajorRadius(); | |
765 | ||
766 | TColStd_SequenceOfReal ParamU, ParamV; | |
767 | ||
768 | Standard_Real Du, Dv;//, pasu, pasv; | |
c80dc6c3 | 769 | Dv = Max(1.0e0 - (theDefFace/r),0.0e0) ; |
7fd59977 | 770 | Standard_Real oldDv = 2.0 * ACos (Dv); |
c80dc6c3 | 771 | oldDv = Min(oldDv, myAngle); |
7fd59977 | 772 | Dv = 0.9*oldDv; //TWOTHIRD * oldDv; |
773 | Dv = oldDv; | |
774 | ||
775 | Standard_Integer nbV = Max((Standard_Integer)((vmax-vmin)/Dv), 2); | |
776 | Dv = (vmax-vmin)/(nbV+1); | |
777 | Standard_Real ru = R + r; | |
778 | if (ru > 1.e-16) | |
779 | { | |
c80dc6c3 O |
780 | Du = 2.0 * ACos(Max(1.0 - (theDefFace/ru),0.0)); |
781 | if (myAngle < Du) Du = myAngle; | |
7fd59977 | 782 | Standard_Real aa = sqrt(Du*Du + oldDv*oldDv); |
783 | if(aa < gp::Resolution()) | |
784 | return; | |
785 | Du *= Min(oldDv, Du) / aa; | |
786 | } | |
787 | else Du = Dv; | |
788 | ||
789 | Standard_Integer nbU = Max((Standard_Integer)((umax-umin)/Du), 2); | |
790 | nbU = Max(nbU , (int)(nbV*(umax-umin)*R/((vmax-vmin)*r)/5.)); | |
791 | Du = (umax-umin)/(nbU+1); | |
792 | ||
793 | if (R < r) | |
794 | { | |
0d969553 Y |
795 | // As the points of edges are returned. |
796 | // in this case, the points are not representative. | |
7fd59977 | 797 | |
0d969553 Y |
798 | //-- Choose DeltaX and DeltaY so that to avoid skipping points on the grid |
799 | for (i = 0; i <= nbU; i++) ParamU.Append(umin + i* Du); | |
7fd59977 | 800 | }//R<r |
801 | else //U if R > r | |
802 | { | |
803 | //--ofv: U | |
804 | // Number of mapped U parameters | |
805 | const Standard_Integer LenU = myUParam.Extent(); | |
806 | // Fill array of U parameters | |
807 | TColStd_Array1OfReal Up(1,LenU); | |
808 | for (j = 1; j <= LenU; j++) Up(j) = myUParam(j); | |
809 | ||
0d969553 | 810 | // Calculate DU, leave array of parameters |
7fd59977 | 811 | Standard_Real aDU = FUN_CalcAverageDUV(Up,LenU); |
812 | aDU = Max(aDU, Abs(umax - umin) / (Standard_Real) nbU / 2.); | |
813 | Standard_Real dUstd = Abs(umax - umin) / (Standard_Real) LenU; | |
814 | if (aDU > dUstd) dUstd = aDU; | |
815 | // Add U parameters | |
816 | for (j = 1; j <= LenU; j++) | |
817 | { | |
818 | pp = Up(j); | |
819 | insert = Standard_True; | |
820 | ParamULength = ParamU.Length(); | |
821 | for (i = 1; i <= ParamULength && insert; i++) | |
822 | { | |
823 | insert = (Abs(ParamU.Value(i)-pp) > (0.5*dUstd)); | |
824 | } | |
825 | if (insert) ParamU.Append(pp); | |
826 | } | |
827 | } | |
828 | ||
829 | //--ofv: V | |
830 | // Number of mapped V parameters | |
831 | const Standard_Integer LenV = myVParam.Extent(); | |
832 | // Fill array of V parameters | |
833 | TColStd_Array1OfReal Vp(1,LenV); | |
834 | for (j = 1; j <= LenV; j++) Vp(j) = myVParam(j); | |
835 | // Calculate DV, sort array of parameters | |
836 | Standard_Real aDV = FUN_CalcAverageDUV(Vp,LenV); | |
837 | aDV = Max(aDV, Abs(vmax - vmin) / (Standard_Real) nbV / 2.); | |
838 | ||
839 | Standard_Real dVstd = Abs(vmax - vmin) / (Standard_Real) LenV; | |
840 | if (aDV > dVstd) dVstd = aDV; | |
841 | // Add V parameters | |
842 | for (j = 1; j <= LenV; j++) | |
843 | { | |
844 | pp = Vp(j); | |
845 | ||
846 | insert = Standard_True; | |
847 | ParamVLength = ParamV.Length(); | |
848 | for (i = 1; i <= ParamVLength && insert; i++) | |
849 | { | |
850 | insert = (Abs(ParamV.Value(i)-pp) > (dVstd*2./3.)); | |
851 | } | |
852 | if (insert) ParamV.Append(pp); | |
853 | } | |
854 | ||
855 | Standard_Integer Lu = ParamU.Length(), Lv = ParamV.Length(); | |
856 | Standard_Real uminnew = umin+deltaY*0.1; | |
857 | Standard_Real vminnew = vmin+deltaX*0.1; | |
858 | Standard_Real umaxnew = umax-deltaY*0.1; | |
859 | Standard_Real vmaxnew = vmax-deltaX*0.1; | |
860 | ||
861 | for (i = 1; i <= Lu; i++) | |
862 | { | |
863 | pasu = ParamU.Value(i); | |
864 | if (pasu >= uminnew && pasu < umaxnew) | |
865 | { | |
c80dc6c3 | 866 | for (j = 1; j <= Lv; j++) |
7fd59977 | 867 | { |
c80dc6c3 O |
868 | pasv = ParamV.Value(j); |
869 | if (pasv >= vminnew && pasv < vmaxnew) | |
7fd59977 | 870 | { |
c80dc6c3 | 871 | if (theClassifier->Perform(gp_Pnt2d(pasu, pasv)) == TopAbs_IN) |
7fd59977 | 872 | { |
873 | // Record 3d point | |
c80dc6c3 O |
874 | ElSLib::D0(pasu, pasv, T, p3d); |
875 | myNbLocat++; | |
876 | myLocation3d.Bind(myNbLocat, p3d); | |
7fd59977 | 877 | // Record 2d point |
c80dc6c3 O |
878 | p2d.SetCoord((pasu-umin)/deltaX, (pasv-vmin)/deltaY); |
879 | newV.Initialize(p2d.XY(), myNbLocat, BRepMesh_Free); | |
880 | theInternalV.Append(newV); | |
881 | } | |
882 | } | |
883 | } | |
7fd59977 | 884 | } |
885 | } | |
886 | } | |
887 | else if (thetype == GeomAbs_BezierSurface || thetype == GeomAbs_BSplineSurface) | |
888 | { | |
b0cf1019 | 889 | //define resolutions |
c80dc6c3 O |
890 | Standard_Real uRes = BS.UResolution(theDefFace); |
891 | Standard_Real vRes = BS.VResolution(theDefFace); | |
b0cf1019 P |
892 | |
893 | // Sort and filter sequence of parameters | |
894 | Standard_Real aMinDu = Precision::PConfusion(); | |
895 | if(deltaX < 1.) | |
896 | aMinDu/=deltaX; | |
897 | ||
898 | Standard_Real aDuMaxLim = 0.1*(umax-umin); | |
899 | Standard_Real ddu = Min(aDuMaxLim,Max(0.005*(umax-umin),2.*uRes)); | |
900 | TColStd_SequenceOfReal ParamU; | |
901 | filterParameters(myUParam,aMinDu,ddu,ParamU); | |
902 | Standard_Integer ParamULength = ParamU.Length(); | |
903 | ||
904 | Standard_Real aMinDv = Precision::PConfusion(); | |
905 | if(deltaY < 1) | |
906 | aMinDv/=deltaY; | |
907 | ||
908 | Standard_Real aDvMaxLim = 0.1*(vmax-vmin); | |
909 | Standard_Real ddv = Min(aDvMaxLim,Max(0.005*(vmax-vmin),2.*vRes)); | |
910 | TColStd_SequenceOfReal ParamV; | |
911 | filterParameters(myVParam,aMinDv,ddv,ParamV); | |
912 | Standard_Integer ParamVLength = ParamV.Length(); | |
7fd59977 | 913 | |
b0cf1019 | 914 | // check intermediate isolines |
7fd59977 | 915 | Handle(Geom_Surface) B; |
916 | if (thetype == GeomAbs_BezierSurface) { | |
7fd59977 | 917 | B = BS.Bezier(); |
918 | } | |
919 | else { | |
b0cf1019 | 920 | B = BS.BSpline(); |
7fd59977 | 921 | } |
7fd59977 | 922 | |
923 | gp_Pnt P1, P2, PControl; | |
b0cf1019 | 924 | Standard_Real u, v, dist; |
7fd59977 | 925 | |
926 | // precision for compare square distances | |
927 | double dPreci = Precision::Confusion()*Precision::Confusion(); | |
928 | ||
929 | // Insert V parameters by deflection criterion | |
b0cf1019 P |
930 | Standard_Integer i,j; |
931 | Standard_Real V1, V2, U1, U2; | |
7fd59977 | 932 | for (i = 1; i <= ParamULength; i++) { |
933 | Handle(Geom_Curve) IsoU = B->UIso(ParamU.Value(i)); | |
934 | V1 = ParamV.Value(1); | |
935 | P1 = IsoU->Value(V1); | |
936 | for (j = 2; j <= ParamVLength;) { | |
937 | V2 = ParamV.Value(j); | |
938 | P2 = IsoU->Value(V2); | |
939 | v = 0.5*(V1+V2); | |
c80dc6c3 | 940 | PControl = IsoU->Value(v); |
7fd59977 | 941 | // 23.03.2010 skl for OCC21645 - change precision for comparison |
942 | if( P1.SquareDistance(P2) > dPreci ) { | |
943 | gp_Lin L (P1, gp_Dir(gp_Vec(P1, P2))); | |
944 | dist = L.Distance(PControl); | |
945 | } | |
c80dc6c3 | 946 | else { |
7fd59977 | 947 | dist = P1.Distance(PControl); |
948 | } | |
c80dc6c3 | 949 | if (dist > theDefFace) { |
7fd59977 | 950 | // insertion |
951 | ParamV.InsertBefore(j, v); | |
952 | ParamVLength++; | |
953 | } | |
954 | else { | |
b0cf1019 P |
955 | //put regular grig for normals |
956 | gp_Dir N1(0,0,1),N2(0,0,1); | |
957 | Standard_Boolean aSt1 = GeomLib::NormEstim(B, gp_Pnt2d(ParamU.Value(i),V1), Precision::Confusion(), N1); | |
958 | Standard_Boolean aSt2 = GeomLib::NormEstim(B, gp_Pnt2d(ParamU.Value(i),v), Precision::Confusion(), N2); | |
c80dc6c3 | 959 | |
b0cf1019 | 960 | Standard_Real anAngle1 = N2.Angle(N1); |
c80dc6c3 | 961 | if(aSt1 < 1 && aSt2 < 1 && anAngle1 > myAngle ) { |
b0cf1019 P |
962 | // insertion |
963 | ParamV.InsertBefore(j, v); | |
964 | ParamVLength++; | |
965 | } | |
966 | else { | |
967 | V1 = V2; | |
968 | P1 = P2; | |
969 | j++; | |
970 | } | |
c80dc6c3 | 971 | } |
7fd59977 | 972 | } |
973 | } | |
974 | ||
975 | for (i = 2; i < ParamVLength; i++) { | |
976 | v = ParamV.Value(i); | |
977 | Handle(Geom_Curve) IsoV = B->VIso(v); | |
978 | U1 = ParamU.Value(1); | |
979 | P1 = IsoV->Value(U1); | |
980 | for (j = 2; j <= ParamULength;) { | |
981 | U2 = ParamU.Value(j); | |
c80dc6c3 O |
982 | P2 = IsoV->Value(U2); |
983 | u = 0.5*(U1+U2); | |
984 | PControl = IsoV->Value(u); | |
7fd59977 | 985 | // 23.03.2010 skl for OCC21645 - change precision for comparison |
986 | if( P1.SquareDistance(P2) > dPreci ) { | |
987 | gp_Lin L (P1, gp_Dir(gp_Vec(P1, P2))); | |
988 | dist = L.Distance(PControl); | |
989 | } | |
990 | else { | |
991 | dist = P1.Distance(PControl); | |
992 | } | |
c80dc6c3 | 993 | if (dist > theDefFace) { |
7fd59977 | 994 | // insertion |
995 | ParamU.InsertBefore(j, u); | |
996 | ParamULength++; | |
997 | } | |
998 | else { | |
999 | //check normal | |
b0cf1019 P |
1000 | //put regular grig for normals |
1001 | gp_Dir N1(0,0,1),N2(0,0,1); | |
1002 | Standard_Boolean aSt1 = GeomLib::NormEstim(B, gp_Pnt2d(U1,v), Precision::Confusion(), N1); | |
1003 | Standard_Boolean aSt2 = GeomLib::NormEstim(B, gp_Pnt2d(u,v), Precision::Confusion(), N2); | |
1004 | ||
1005 | Standard_Real anAngle1 = N2.Angle(N1); | |
c80dc6c3 | 1006 | if(aSt1 < 1 && aSt2 < 1 && anAngle1 > myAngle) { |
b0cf1019 P |
1007 | // insertion |
1008 | ParamU.InsertBefore(j, u); | |
1009 | ParamULength++; | |
1010 | } | |
1011 | else { | |
1012 | U1 = U2; | |
1013 | P1 = P2; | |
1014 | if (j < ParamULength) { | |
1015 | // Classify intersection point | |
c80dc6c3 | 1016 | if (theClassifier->Perform(gp_Pnt2d(U1, v)) == TopAbs_IN) |
b0cf1019 P |
1017 | { |
1018 | // Record 3d point | |
c80dc6c3 O |
1019 | myNbLocat++; |
1020 | myLocation3d.Bind(myNbLocat, P1); | |
b0cf1019 P |
1021 | // Record 2d point |
1022 | p2d.SetCoord((U1-umin)/deltaX, (v-vmin)/deltaY); | |
c80dc6c3 O |
1023 | newV.Initialize(p2d.XY(), myNbLocat, BRepMesh_Free); |
1024 | theInternalV.Append(newV); | |
b0cf1019 | 1025 | } |
7fd59977 | 1026 | } |
b0cf1019 | 1027 | j++; |
7fd59977 | 1028 | } |
c80dc6c3 | 1029 | } |
7fd59977 | 1030 | } |
1031 | } | |
1032 | } | |
1033 | else { | |
c80dc6c3 | 1034 | const Standard_Real anAngle = 0.35; |
7fd59977 | 1035 | |
1036 | Standard_Integer i, j, nbpointsU = 10, nbpointsV = 10; | |
b0cf1019 | 1037 | Adaptor3d_IsoCurve tabu[11], tabv[11]; |
7fd59977 | 1038 | |
1039 | TColStd_SequenceOfReal ParamU, ParamV; | |
1040 | Standard_Real u, v, du, dv; | |
1041 | Standard_Integer iu, iv; | |
1042 | Standard_Real f, l; | |
1043 | ||
1044 | du = (umax-umin) / (nbpointsU+1); dv = (vmax-vmin) / (nbpointsV+1); | |
1045 | ||
b0cf1019 | 1046 | for (iu = 0; iu <= nbpointsU; iu++) { |
7fd59977 | 1047 | u = umin + iu*du; |
c80dc6c3 | 1048 | tabu[iu].Load(theCaro); |
b0cf1019 | 1049 | tabu[iu].Load(GeomAbs_IsoU, u); |
7fd59977 | 1050 | } |
1051 | ||
b0cf1019 | 1052 | for (iv = 0; iv <= nbpointsV; iv++) { |
7fd59977 | 1053 | v = vmin + iv*dv; |
c80dc6c3 | 1054 | tabv[iv].Load(theCaro); |
b0cf1019 | 1055 | tabv[iv].Load(GeomAbs_IsoV, v); |
7fd59977 | 1056 | } |
1057 | ||
1058 | Standard_Integer imax = 1, MaxV = 0; | |
1059 | ||
b0cf1019 | 1060 | GCPnts_TangentialDeflection* tabGU = new GCPnts_TangentialDeflection[nbpointsU+1]; |
7fd59977 | 1061 | |
b0cf1019 | 1062 | for (i = 0; i <= nbpointsU; i++) { |
7fd59977 | 1063 | f = Max(vmin, tabu[i].FirstParameter()); |
1064 | l = Min(vmax, tabu[i].LastParameter()); | |
c80dc6c3 | 1065 | GCPnts_TangentialDeflection theDeflection(tabu[i], f, l, anAngle, 0.7*theDefFace, 2); |
7fd59977 | 1066 | tabGU[i] = theDeflection; |
1067 | if (tabGU[i].NbPoints() > MaxV) { | |
c80dc6c3 O |
1068 | MaxV = tabGU[i].NbPoints(); |
1069 | imax = i; | |
7fd59977 | 1070 | } |
1071 | } | |
1072 | ||
0d969553 | 1073 | // return table of parameters V: |
7fd59977 | 1074 | Standard_Integer NV = tabGU[imax].NbPoints(); |
1075 | for (i = 1; i <= NV; i++) { | |
1076 | ParamV.Append(tabGU[imax].Parameter(i)); | |
1077 | } | |
1078 | delete [] tabGU; | |
1079 | ||
1080 | imax = 1; | |
1081 | Standard_Integer MaxU = 0; | |
1082 | ||
b0cf1019 | 1083 | GCPnts_TangentialDeflection* tabGV = new GCPnts_TangentialDeflection[nbpointsV+1]; |
7fd59977 | 1084 | |
b0cf1019 | 1085 | for (i = 0; i <= nbpointsV; i++) { |
7fd59977 | 1086 | f = Max(umin, tabv[i].FirstParameter()); |
1087 | l = Min(umax, tabv[i].LastParameter()); | |
c80dc6c3 | 1088 | GCPnts_TangentialDeflection thedeflection2(tabv[i], f, l, anAngle, 0.7*theDefFace, 2); |
7fd59977 | 1089 | tabGV[i] = thedeflection2; |
1090 | if (tabGV[i].NbPoints() > MaxU) { | |
c80dc6c3 O |
1091 | MaxU = tabGV[i].NbPoints(); |
1092 | imax = i; | |
7fd59977 | 1093 | } |
1094 | } | |
1095 | ||
0d969553 | 1096 | // return table of parameters U: |
7fd59977 | 1097 | Standard_Integer NU = tabGV[imax].NbPoints(); |
1098 | for (i = 1; i <= NU; i++) { | |
1099 | ParamU.Append(tabGV[imax].Parameter(i)); | |
1100 | } | |
1101 | delete [] tabGV; | |
1102 | ||
1103 | if (ParamU.Length() == 2) { | |
1104 | ParamU.InsertAfter(1, (umax+umin)*0.5); | |
1105 | } | |
1106 | if (ParamV.Length() == 2) { | |
1107 | ParamV.InsertAfter(1, (vmax+vmin)*0.5); | |
1108 | } | |
1109 | ||
1110 | TColStd_SequenceOfReal InsertV, InsertU; | |
1111 | gp_Pnt P1; | |
1112 | ||
1113 | Adaptor3d_IsoCurve IsoV; | |
c80dc6c3 | 1114 | IsoV.Load(theCaro); |
7fd59977 | 1115 | |
1116 | Standard_Integer Lu = ParamU.Length(), Lv = ParamV.Length(); | |
1117 | ||
1118 | for (i = 2; i < Lv; i++) { | |
1119 | v = ParamV.Value(i); | |
1120 | IsoV.Load(GeomAbs_IsoV, v); | |
1121 | for (j = 2; j < Lu; j++) { | |
c80dc6c3 O |
1122 | u = ParamU.Value(j); |
1123 | if (theClassifier->Perform(gp_Pnt2d(u, v)) == TopAbs_IN) | |
7fd59977 | 1124 | { |
1125 | // Record 3d point | |
c80dc6c3 O |
1126 | P1 = IsoV.Value(u); |
1127 | myNbLocat++; | |
1128 | myLocation3d.Bind(myNbLocat, P1); | |
7fd59977 | 1129 | // Record 2d point |
c80dc6c3 O |
1130 | p2d.SetCoord((u-umin)/deltaX, (v-vmin)/deltaY); |
1131 | newV.Initialize(p2d.XY(), myNbLocat, BRepMesh_Free); | |
1132 | theInternalV.Append(newV); | |
1133 | } | |
7fd59977 | 1134 | } |
1135 | } | |
1136 | } | |
1137 | #ifdef DEB_MESH_CHRONO | |
1138 | chInternal.Stop(); | |
1139 | #endif | |
1140 | } | |
1141 | ||
1142 | /** | |
1143 | * Internal class Couple, moved from MeshData package | |
1144 | */ | |
1145 | ||
1146 | class BRepMesh_Couple | |
1147 | { | |
1148 | public: | |
1149 | BRepMesh_Couple() { myI1 = myI2 = 0; } | |
1150 | BRepMesh_Couple(const Standard_Integer I1, | |
c80dc6c3 | 1151 | const Standard_Integer I2) |
7fd59977 | 1152 | { myI1 = I1; myI2 = I2; } |
1153 | ||
1154 | Standard_Integer myI1; | |
1155 | Standard_Integer myI2; | |
1156 | }; | |
1157 | ||
1158 | inline Standard_Boolean IsEqual(const BRepMesh_Couple& one, | |
1159 | const BRepMesh_Couple& other) | |
1160 | { | |
1161 | if (one.myI1 == other.myI1 && | |
1162 | one.myI2 == other.myI2) return Standard_True; | |
1163 | else return Standard_False; | |
1164 | } | |
1165 | ||
1166 | inline Standard_Integer HashCode(const BRepMesh_Couple& one, | |
1167 | const Standard_Integer Upper) | |
1168 | { | |
1169 | return ::HashCode((one.myI1+one.myI2), Upper); | |
1170 | } | |
1171 | ||
1172 | typedef NCollection_Map<BRepMesh_Couple> BRepMesh_MapOfCouple; | |
1173 | ||
1174 | //======================================================================= | |
1175 | //function : Control | |
1176 | //purpose : | |
1177 | //======================================================================= | |
c80dc6c3 O |
1178 | Standard_Real BRepMesh_FastDiscretFace::Control(const Handle(BRepAdaptor_HSurface)& theCaro, |
1179 | const Standard_Real theDefFace, | |
1180 | BRepMesh_ListOfVertex& theInternalV, | |
1181 | TColStd_ListOfInteger& theBadTriangles, | |
1182 | TColStd_ListOfInteger& theNulTriangles, | |
1183 | BRepMesh_Delaun& theTrigu, | |
1184 | const Standard_Boolean theIsFirst) | |
7fd59977 | 1185 | { |
1186 | //IMPORTANT: Constants used in calculations | |
1187 | const Standard_Real MinimalArea2d = 1.e-9; | |
1188 | const Standard_Real MinimalSqLength3d = 1.e-12; | |
c80dc6c3 | 1189 | const Standard_Real aDef2 = theDefFace*theDefFace; |
7fd59977 | 1190 | |
1191 | // Define the number of iterations | |
1192 | Standard_Integer myNbIterations = 11; | |
c80dc6c3 | 1193 | const Standard_Integer nbPasses = (theIsFirst? 1 : myNbIterations); |
7fd59977 | 1194 | |
1195 | // Initialize stop condition | |
1196 | Standard_Boolean allDegenerated = Standard_False; | |
1197 | Standard_Integer nbInserted = 1; | |
1198 | ||
1199 | // Create map of links to skip already processed | |
b0cf1019 P |
1200 | Standard_Integer nbtriangles; |
1201 | ||
c80dc6c3 | 1202 | nbtriangles = myStructure->ElemOfDomain().Extent(); |
7fd59977 | 1203 | if (nbtriangles <= 0) return -1.0; |
1204 | BRepMesh_MapOfCouple theCouples(3*nbtriangles); | |
1205 | ||
1206 | gp_XY mi2d; | |
1207 | gp_XYZ vecEd1, vecEd2, vecEd3; | |
1208 | gp_Pnt pDef; | |
1209 | Standard_Real dv = 0, defl = 0, maxdef = -1; | |
1210 | Standard_Integer pass = 1, nf = 0, nl = 0; | |
7fd59977 | 1211 | BRepMesh_Vertex InsVertex; |
1212 | Standard_Boolean caninsert; | |
1213 | ||
c80dc6c3 O |
1214 | Standard_Real sqdefface = theDefFace * theDefFace; |
1215 | Standard_Real ddu = theCaro->UResolution(theDefFace); | |
1216 | Standard_Real ddv = theCaro->VResolution(theDefFace); | |
7fd59977 | 1217 | |
c80dc6c3 | 1218 | GeomAbs_SurfaceType thetype = theCaro->GetType(); |
7fd59977 | 1219 | Handle(Geom_Surface) BSpl; |
1220 | Standard_Boolean isSpline = Standard_False; | |
1221 | if (thetype == GeomAbs_BezierSurface || thetype == GeomAbs_BSplineSurface) | |
1222 | { | |
1223 | isSpline = Standard_True; | |
1224 | if (thetype == GeomAbs_BezierSurface) | |
c80dc6c3 | 1225 | BSpl = theCaro->Bezier(); |
7fd59977 | 1226 | else |
c80dc6c3 | 1227 | BSpl = theCaro->BSpline(); |
7fd59977 | 1228 | } |
c80dc6c3 | 1229 | |
7fd59977 | 1230 | NCollection_DataMap<Standard_Integer,gp_Dir> aNorMap; |
1231 | NCollection_DataMap<Standard_Integer,Standard_Integer> aStatMap; | |
1232 | ||
1233 | // Perform refinement passes | |
1234 | for (; pass <= nbPasses && nbInserted && !allDegenerated; pass++) | |
1235 | { | |
c80dc6c3 O |
1236 | theInternalV.Clear(); |
1237 | theBadTriangles.Clear(); | |
7fd59977 | 1238 | |
1239 | // Reset stop condition | |
1240 | allDegenerated = Standard_True; | |
1241 | nbInserted = 0; | |
1242 | maxdef = -1.0; | |
1243 | ||
1244 | // Do not insert nodes in last pass in non-SharedMode | |
c80dc6c3 | 1245 | caninsert = (myWithShare || pass < nbPasses); |
7fd59977 | 1246 | |
1247 | // Read mesh size | |
c80dc6c3 | 1248 | nbtriangles = myStructure->ElemOfDomain().Extent(); |
7fd59977 | 1249 | if (nbtriangles <= 0) break; |
1250 | ||
1251 | // Iterate on current triangles | |
c80dc6c3 O |
1252 | BRepMesh_MapOfInteger::Iterator triDom; |
1253 | const BRepMesh_MapOfInteger& TriMap = myStructure->ElemOfDomain(); | |
7fd59977 | 1254 | triDom.Initialize(TriMap); |
1255 | Standard_Integer aNbPnt = 0; | |
c80dc6c3 O |
1256 | Standard_Real umin = myAttrib->GetUMin(); |
1257 | Standard_Real vmin = myAttrib->GetVMin(); | |
1258 | Standard_Real deltaX = myAttrib->GetDeltaX(); | |
1259 | Standard_Real deltaY = myAttrib->GetDeltaY(); | |
7fd59977 | 1260 | for (; triDom.More(); triDom.Next()) |
1261 | { | |
1262 | Standard_Integer TriId = triDom.Key(); | |
1263 | const BRepMesh_Triangle& curTri=Triangle(TriId); | |
c80dc6c3 O |
1264 | if (curTri.Movability()==BRepMesh_Deleted) continue; |
1265 | ||
7fd59977 | 1266 | Standard_Boolean o1, o2, o3; |
1267 | Standard_Integer v1 = 0, v2 = 0, v3 = 0, e1 = 0, e2 = 0, e3 = 0; | |
1268 | curTri.Edges(e1, e2, e3, o1, o2, o3); | |
1269 | ||
1270 | const BRepMesh_Edge& edg1=Edge(e1); | |
1271 | const BRepMesh_Edge& edg2=Edge(e2); | |
1272 | const BRepMesh_Edge& edg3=Edge(e3); | |
1273 | ||
c80dc6c3 O |
1274 | Standard_Boolean m1 = (edg1.Movability() == BRepMesh_Frontier); |
1275 | Standard_Boolean m2 = (edg2.Movability() == BRepMesh_Frontier); | |
1276 | Standard_Boolean m3 = (edg3.Movability() == BRepMesh_Frontier); | |
7fd59977 | 1277 | if (o1) { |
c80dc6c3 O |
1278 | v1=edg1.FirstNode(); |
1279 | v2=edg1.LastNode(); | |
7fd59977 | 1280 | } |
1281 | else { | |
c80dc6c3 O |
1282 | v1=edg1.LastNode(); |
1283 | v2=edg1.FirstNode(); | |
7fd59977 | 1284 | } |
1285 | if (o2) | |
c80dc6c3 | 1286 | v3=edg2.LastNode(); |
7fd59977 | 1287 | else |
c80dc6c3 | 1288 | v3=edg2.FirstNode(); |
7fd59977 | 1289 | |
1290 | const BRepMesh_Vertex& vert1=Vertex(v1); | |
1291 | const BRepMesh_Vertex& vert2=Vertex(v2); | |
1292 | const BRepMesh_Vertex& vert3=Vertex(v3); | |
1293 | ||
c80dc6c3 O |
1294 | const gp_XYZ& p1=myLocation3d(vert1.Location3d()).Coord(); |
1295 | const gp_XYZ& p2=myLocation3d(vert2.Location3d()).Coord(); | |
1296 | const gp_XYZ& p3=myLocation3d(vert3.Location3d()).Coord(); | |
7fd59977 | 1297 | |
1298 | vecEd1 = p2 - p1; | |
1299 | vecEd2 = p3 - p2; | |
1300 | vecEd3 = p1 - p3; | |
1301 | ||
1302 | // Check for degenerated triangle | |
1303 | if (vecEd1.SquareModulus() < MinimalSqLength3d || | |
1304 | vecEd2.SquareModulus() < MinimalSqLength3d || | |
1305 | vecEd3.SquareModulus() < MinimalSqLength3d) | |
1306 | { | |
c80dc6c3 | 1307 | theNulTriangles.Append(TriId); |
7fd59977 | 1308 | continue; |
1309 | } | |
1310 | ||
1311 | allDegenerated = Standard_False; | |
1312 | ||
1313 | gp_XY xy1(vert1.Coord().X()*deltaX+umin,vert1.Coord().Y()*deltaY+vmin); | |
1314 | gp_XY xy2(vert2.Coord().X()*deltaX+umin,vert2.Coord().Y()*deltaY+vmin); | |
1315 | gp_XY xy3(vert3.Coord().X()*deltaX+umin,vert3.Coord().Y()*deltaY+vmin); | |
1316 | ||
1317 | // Check triangle area in 2d | |
1318 | if (Abs((xy2-xy1)^(xy3-xy1)) < MinimalArea2d) | |
1319 | { | |
c80dc6c3 | 1320 | theNulTriangles.Append(TriId); |
7fd59977 | 1321 | continue; |
1322 | } | |
1323 | ||
1324 | // Check triangle normal | |
1325 | gp_XYZ normal(vecEd1^vecEd2); | |
1326 | dv = normal.Modulus(); | |
1327 | if (dv < Precision::Confusion()) | |
1328 | { | |
c80dc6c3 | 1329 | theNulTriangles.Append(TriId); |
7fd59977 | 1330 | continue; |
1331 | } | |
1332 | normal /= dv; | |
1333 | ||
1334 | // Check deflection on triangle | |
1335 | mi2d = (xy1+xy2+xy3)/3.0; | |
c80dc6c3 | 1336 | theCaro->D0(mi2d.X(), mi2d.Y(), pDef); |
b0cf1019 P |
1337 | defl = Abs(normal*(pDef.XYZ()-p1)); |
1338 | defl = defl*defl; | |
1339 | /*mi2d = (xy1+xy2+xy3)/3.0; | |
c80dc6c3 | 1340 | theCaro->D0(mi2d.X(), mi2d.Y(), pDef); |
b0cf1019 | 1341 | defl = pDef.SquareDistance((p1+p2+p3)/3.);*/ |
7fd59977 | 1342 | if (defl > maxdef) maxdef = defl; |
1343 | if (defl > sqdefface) | |
1344 | { | |
c80dc6c3 | 1345 | if (theIsFirst) break; |
7fd59977 | 1346 | if (caninsert) |
1347 | { | |
1348 | // Record new vertex | |
1349 | aNbPnt++; | |
c80dc6c3 O |
1350 | myNbLocat++; |
1351 | myLocation3d.Bind(myNbLocat,pDef); | |
7fd59977 | 1352 | mi2d.SetCoord((mi2d.X()-umin)/deltaX,(mi2d.Y()-vmin)/deltaY); |
c80dc6c3 O |
1353 | InsVertex.Initialize(mi2d,myNbLocat,BRepMesh_Free); |
1354 | theInternalV.Append(InsVertex); | |
7fd59977 | 1355 | } |
c80dc6c3 | 1356 | theBadTriangles.Append(TriId); |
7fd59977 | 1357 | } |
1358 | ||
1359 | if (!m2) // Not a boundary | |
1360 | { | |
1361 | // Check if this link was already processed | |
1362 | if (v2 < v3) { nf = v2; nl = v3; } else { nf = v3; nl = v2; } | |
1363 | if (theCouples.Add(BRepMesh_Couple(nf,nl))) | |
1364 | { | |
1365 | // Check deflection on edge 1 | |
1366 | mi2d = (xy2+xy3)*0.5; | |
c80dc6c3 | 1367 | theCaro->D0(mi2d.X(), mi2d.Y(), pDef); |
b0cf1019 P |
1368 | gp_Lin L (p2, gp_Vec(p2, p3)); |
1369 | defl = L.SquareDistance(pDef); | |
7fd59977 | 1370 | if (defl > maxdef) maxdef = defl; |
1371 | if (defl > sqdefface) | |
1372 | { | |
c80dc6c3 | 1373 | if (theIsFirst) break; |
7fd59977 | 1374 | if (caninsert) |
1375 | { | |
1376 | // Record new vertex | |
1377 | aNbPnt++; | |
c80dc6c3 O |
1378 | myNbLocat++; |
1379 | myLocation3d.Bind(myNbLocat,pDef); | |
7fd59977 | 1380 | mi2d.SetCoord((mi2d.X()-umin)/deltaX,(mi2d.Y()-vmin)/deltaY); |
c80dc6c3 O |
1381 | InsVertex.Initialize(mi2d,myNbLocat,BRepMesh_Free); |
1382 | theInternalV.Append(InsVertex); | |
7fd59977 | 1383 | } |
c80dc6c3 | 1384 | theBadTriangles.Append(TriId); |
7fd59977 | 1385 | } |
1386 | } | |
1387 | } | |
1388 | ||
1389 | if (!m3) // Not a boundary | |
1390 | { | |
1391 | // Check if this link was already processed | |
1392 | if (v1 < v3) { nf = v1; nl = v3; } else { nf = v3; nl = v1; } | |
1393 | if (theCouples.Add(BRepMesh_Couple(nf,nl))) | |
1394 | { | |
1395 | // Check deflection on edge 2 | |
1396 | mi2d = (xy3+xy1)*0.5; | |
c80dc6c3 | 1397 | theCaro->D0(mi2d.X(), mi2d.Y(), pDef); |
b0cf1019 P |
1398 | gp_Lin L (p1, gp_Vec(p1, p3)); |
1399 | defl = L.SquareDistance(pDef); | |
7fd59977 | 1400 | if (defl > maxdef) maxdef = defl; |
1401 | if (defl > sqdefface) | |
1402 | { | |
c80dc6c3 | 1403 | if (theIsFirst) break; |
7fd59977 | 1404 | if (caninsert) |
1405 | { | |
1406 | // Record new vertex | |
1407 | aNbPnt++; | |
c80dc6c3 O |
1408 | myNbLocat++; |
1409 | myLocation3d.Bind(myNbLocat,pDef); | |
7fd59977 | 1410 | mi2d.SetCoord((mi2d.X()-umin)/deltaX,(mi2d.Y()-vmin)/deltaY); |
c80dc6c3 O |
1411 | InsVertex.Initialize(mi2d,myNbLocat,BRepMesh_Free); |
1412 | theInternalV.Append(InsVertex); | |
7fd59977 | 1413 | } |
c80dc6c3 | 1414 | theBadTriangles.Append(TriId); |
7fd59977 | 1415 | } |
1416 | } | |
1417 | } | |
1418 | ||
1419 | if (!m1) // Not a boundary | |
1420 | { | |
1421 | // Check if this link was already processed | |
1422 | if (v1 < v2) { nf = v1; nl = v2; } else { nf = v2; nl = v1; } | |
1423 | if (theCouples.Add(BRepMesh_Couple(nf,nl))) | |
1424 | { | |
1425 | // Check deflection on edge 3 | |
1426 | mi2d = (xy1+xy2)*0.5; | |
c80dc6c3 | 1427 | theCaro->D0(mi2d.X(), mi2d.Y(), pDef); |
b0cf1019 P |
1428 | gp_Lin L (p1, gp_Vec(p1, p2)); |
1429 | defl = L.SquareDistance(pDef); | |
7fd59977 | 1430 | if (defl > maxdef) maxdef = defl; |
1431 | if (defl > sqdefface) | |
1432 | { | |
c80dc6c3 | 1433 | if (theIsFirst) break; |
7fd59977 | 1434 | if (caninsert) |
1435 | { | |
1436 | // Record new vertex | |
1437 | aNbPnt++; | |
c80dc6c3 O |
1438 | myNbLocat++; |
1439 | myLocation3d.Bind(myNbLocat,pDef); | |
7fd59977 | 1440 | mi2d.SetCoord((mi2d.X()-umin)/deltaX,(mi2d.Y()-vmin)/deltaY); |
c80dc6c3 O |
1441 | InsVertex.Initialize(mi2d,myNbLocat,BRepMesh_Free); |
1442 | theInternalV.Append(InsVertex); | |
7fd59977 | 1443 | } |
c80dc6c3 | 1444 | theBadTriangles.Append(TriId); |
7fd59977 | 1445 | } |
1446 | } | |
1447 | } | |
1448 | ||
b0cf1019 | 1449 | //check normal on bsplines |
c80dc6c3 | 1450 | if(theIsFirst && isSpline && !BSpl.IsNull() ) |
7fd59977 | 1451 | { |
c80dc6c3 | 1452 | gp_Dir N1(0,0,1), N2(0,0,1), N3(0,0,1); |
7fd59977 | 1453 | Standard_Integer aSt1, aSt2, aSt3; |
1454 | if(aNorMap.IsBound(v1)) { | |
1455 | aSt1 = aStatMap.Find(v1); | |
1456 | N1 =aNorMap.Find(v1); | |
1457 | } | |
1458 | else { | |
1459 | aSt1 = GeomLib::NormEstim(BSpl, gp_Pnt2d(xy1), Precision::Confusion(), N1); | |
1460 | aStatMap.Bind(v1,aSt1); | |
1461 | aNorMap.Bind(v1,N1); | |
1462 | } | |
1463 | ||
1464 | if(aNorMap.IsBound(v2)) { | |
1465 | aSt2 = aStatMap.Find(v2); | |
1466 | N2 = aNorMap.Find(v2); | |
1467 | } | |
1468 | else { | |
1469 | aSt2 = GeomLib::NormEstim(BSpl, gp_Pnt2d(xy2), Precision::Confusion(), N2); | |
1470 | aStatMap.Bind(v2,aSt2); | |
1471 | aNorMap.Bind(v2,N2); | |
1472 | } | |
1473 | ||
1474 | if(aNorMap.IsBound(v3)) { | |
1475 | aSt3 = aStatMap.Find(v3); | |
1476 | N3 = aNorMap.Find(v3); | |
1477 | } | |
1478 | else { | |
1479 | aSt3 = GeomLib::NormEstim(BSpl, gp_Pnt2d(xy3), Precision::Confusion(), N3); | |
1480 | aStatMap.Bind(v3,aSt3); | |
1481 | aNorMap.Bind(v3,N3.XYZ()); | |
1482 | } | |
c80dc6c3 O |
1483 | |
1484 | Standard_Real anAngle1 = N2.Angle(N1); | |
7fd59977 | 1485 | Standard_Real anAngle2 = N3.Angle(N2); |
1486 | Standard_Real anAngle3 = N1.Angle(N3); | |
c80dc6c3 O |
1487 | if(aSt1 < 1 && aSt2 < 1 && aSt3 < 1 && |
1488 | (anAngle1 > myAngle || anAngle2 > myAngle || anAngle3 > myAngle)) { | |
1489 | ||
7fd59977 | 1490 | maxdef = -1; |
1491 | break; | |
7fd59977 | 1492 | } |
1493 | } | |
1494 | } | |
1495 | ||
c80dc6c3 | 1496 | if (!theIsFirst && theInternalV.Extent() > 0) |
7fd59977 | 1497 | { |
c80dc6c3 O |
1498 | BRepMesh_Array1OfVertexOfDelaun verttab(1, theInternalV.Extent()); |
1499 | BRepMesh_ListIteratorOfListOfVertex itVer(theInternalV); | |
7fd59977 | 1500 | Standard_Integer ipn = 1; |
1501 | for (; itVer.More(); itVer.Next()) | |
1502 | verttab(ipn++) = itVer.Value(); | |
1503 | ||
c80dc6c3 | 1504 | theTrigu.AddVertices(verttab); |
7fd59977 | 1505 | nbInserted++; |
1506 | } | |
1507 | } | |
b0cf1019 P |
1508 | |
1509 | if (maxdef < 0) | |
7fd59977 | 1510 | return maxdef; |
1511 | return Sqrt(maxdef); | |
1512 | } | |
1513 | ||
1514 | //======================================================================= | |
1515 | //function : AddInShape | |
1516 | //purpose : | |
1517 | //======================================================================= | |
c80dc6c3 O |
1518 | void BRepMesh_FastDiscretFace::AddInShape(const TopoDS_Face& theFace, |
1519 | const Standard_Real theDefFace) | |
7fd59977 | 1520 | { |
1521 | // gp_Pnt Pt; | |
1522 | BRep_Builder B; | |
c80dc6c3 O |
1523 | TopLoc_Location loc = theFace.Location(); |
1524 | Handle(Poly_Triangulation) TOld = BRep_Tool::Triangulation(theFace, loc); | |
7fd59977 | 1525 | Handle(Poly_Triangulation) TNull; |
1526 | Handle(Poly_PolygonOnTriangulation) NullPoly; | |
c80dc6c3 | 1527 | B.UpdateFace(theFace,TNull); |
7fd59977 | 1528 | |
1529 | try{ | |
c80dc6c3 | 1530 | BRepMesh_MapOfInteger::Iterator it; |
7fd59977 | 1531 | |
1532 | Standard_Integer e1, e2, e3, nTri; | |
1533 | Standard_Integer v1, v2, v3, iv1, iv2, iv3; | |
1534 | Standard_Integer i, index; | |
1535 | Standard_Boolean o1, o2, o3; | |
c80dc6c3 | 1536 | TopAbs_Orientation orFace = theFace.Orientation(); |
7fd59977 | 1537 | |
c80dc6c3 | 1538 | const BRepMesh_MapOfInteger& TriMap = myStructure->ElemOfDomain(); |
7fd59977 | 1539 | it.Initialize(TriMap); |
1540 | ||
1541 | nTri = TriMap.Extent(); | |
1542 | ||
1543 | if (nTri != 0) { | |
1544 | ||
1545 | Poly_Array1OfTriangle Tri(1, nTri); | |
1546 | ||
1547 | i = 1; | |
1548 | ||
1549 | for (; it.More(); it.Next()) { | |
c80dc6c3 | 1550 | myStructure->GetElement(it.Key()).Edges(e1, e2, e3, o1, o2, o3); |
7fd59977 | 1551 | |
c80dc6c3 O |
1552 | const BRepMesh_Edge& ve1=myStructure->GetLink(e1); |
1553 | const BRepMesh_Edge& ve2=myStructure->GetLink(e2); | |
1554 | const BRepMesh_Edge& ve3=myStructure->GetLink(e3); | |
7fd59977 | 1555 | |
1556 | if (o1) { | |
c80dc6c3 | 1557 | v1=ve1.FirstNode(); |
7fd59977 | 1558 | } |
1559 | else { | |
c80dc6c3 | 1560 | v1=ve1.LastNode(); |
7fd59977 | 1561 | } |
1562 | if (o2) | |
1563 | { | |
1564 | v2=ve2.FirstNode(); | |
c80dc6c3 | 1565 | v3=ve2.LastNode(); |
7fd59977 | 1566 | } |
1567 | else | |
1568 | { | |
c80dc6c3 O |
1569 | v3=ve2.FirstNode(); |
1570 | v2=ve2.LastNode(); | |
7fd59977 | 1571 | } |
1572 | ||
c80dc6c3 O |
1573 | iv1 = myVemap.FindIndex(v1); |
1574 | if (iv1 == 0) iv1 = myVemap.Add(v1); | |
1575 | iv2 = myVemap.FindIndex(v2); | |
1576 | if (iv2 == 0) iv2 = myVemap.Add(v2); | |
1577 | iv3 = myVemap.FindIndex(v3); | |
1578 | if (iv3 == 0) iv3 = myVemap.Add(v3); | |
7fd59977 | 1579 | |
1580 | if (orFace == TopAbs_REVERSED) Tri(i++).Set(iv1, iv3, iv2); | |
1581 | else Tri(i++).Set(iv1, iv2, iv3); | |
1582 | } | |
1583 | ||
c80dc6c3 | 1584 | Standard_Integer nbVertices = myVemap.Extent(); |
7fd59977 | 1585 | Handle(Poly_Triangulation) T = new Poly_Triangulation(nbVertices, nTri, Standard_True); |
1586 | Poly_Array1OfTriangle& Trian = T->ChangeTriangles(); | |
1587 | Trian = Tri; | |
1588 | TColgp_Array1OfPnt& Nodes = T->ChangeNodes(); | |
1589 | TColgp_Array1OfPnt2d& Nodes2d = T->ChangeUVNodes(); | |
1590 | ||
1591 | for (i = 1; i <= nbVertices; i++) { | |
c80dc6c3 | 1592 | index = myVemap.FindKey(i); |
7fd59977 | 1593 | Nodes(i) = Pnt(index); |
1594 | Nodes2d(i).SetXY(Vertex(index).Coord()); | |
1595 | } | |
1596 | ||
c80dc6c3 | 1597 | T->Deflection(theDefFace); |
7fd59977 | 1598 | |
0d969553 | 1599 | // storage of triangulation in BRep. |
7fd59977 | 1600 | BRep_Builder B1; |
c80dc6c3 | 1601 | //TopLoc_Location loc = theFace.Location(); |
7fd59977 | 1602 | if (!loc.IsIdentity()) { |
1603 | gp_Trsf tr = loc.Transformation(); | |
1604 | tr.Invert(); | |
1605 | for (i = Nodes.Lower(); i <= Nodes.Upper(); i++) | |
c80dc6c3 | 1606 | Nodes(i).Transform(tr); |
7fd59977 | 1607 | } |
c80dc6c3 | 1608 | B1.UpdateFace(theFace, T); |
7fd59977 | 1609 | |
0d969553 | 1610 | // implement polygons on triangulation in the face: |
c80dc6c3 | 1611 | BRepMesh_DataMapIteratorOfDataMapOfShapePairOfPolygon It(myInternaledges); |
7fd59977 | 1612 | |
1613 | for (; It.More(); It.Next()) { | |
1614 | const BRepMesh_PairOfPolygon& pair = It.Value(); | |
1615 | const Handle(Poly_PolygonOnTriangulation)& NOD1 = pair.First(); | |
1616 | const Handle(Poly_PolygonOnTriangulation)& NOD2 = pair.Last(); | |
1617 | if ( NOD1 == NOD2 ) { | |
c80dc6c3 O |
1618 | B.UpdateEdge(TopoDS::Edge(It.Key()), NullPoly, TOld,loc); |
1619 | B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, T, loc); | |
7fd59977 | 1620 | } |
1621 | else { | |
c80dc6c3 O |
1622 | B.UpdateEdge(TopoDS::Edge(It.Key()), NullPoly, TOld,loc); |
1623 | B.UpdateEdge(TopoDS::Edge(It.Key()), NOD1, NOD2, T, loc); | |
7fd59977 | 1624 | } |
1625 | } | |
1626 | } | |
1627 | } | |
51c3cc5f | 1628 | |
7fd59977 | 1629 | catch(Standard_Failure) |
1630 | { | |
c80dc6c3 | 1631 | // MESH_FAILURE(theFace); |
7fd59977 | 1632 | } |
1633 | } | |
1634 | ||
1635 | ||
1636 | //======================================================================= | |
1637 | //function : Triangle | |
1638 | //purpose : | |
1639 | //======================================================================= | |
1640 | ||
c80dc6c3 | 1641 | const BRepMesh_Triangle& BRepMesh_FastDiscretFace::Triangle(const Standard_Integer Index) const |
7fd59977 | 1642 | { |
c80dc6c3 | 1643 | return myStructure->GetElement(Index); |
7fd59977 | 1644 | } |
1645 | ||
1646 | //======================================================================= | |
1647 | //function : NbEdges | |
1648 | //purpose : | |
1649 | //======================================================================= | |
1650 | ||
1651 | /*Standard_Integer BRepMesh_FastDiscretFace::NbEdges() const | |
1652 | { | |
c80dc6c3 | 1653 | return myStructure->NbLinks(); |
7fd59977 | 1654 | }*/ |
1655 | ||
1656 | //======================================================================= | |
1657 | //function : Edge | |
1658 | //purpose : | |
1659 | //======================================================================= | |
1660 | ||
1661 | const BRepMesh_Edge& BRepMesh_FastDiscretFace::Edge(const Standard_Integer Index) const | |
1662 | { | |
c80dc6c3 | 1663 | return myStructure->GetLink(Index); |
7fd59977 | 1664 | } |
1665 | ||
1666 | ||
1667 | //======================================================================= | |
1668 | //function : Vertex | |
1669 | //purpose : | |
1670 | //======================================================================= | |
1671 | ||
c80dc6c3 | 1672 | const BRepMesh_Vertex& BRepMesh_FastDiscretFace::Vertex(const Standard_Integer Index) const |
7fd59977 | 1673 | { |
c80dc6c3 | 1674 | return myStructure->GetNode(Index); |
7fd59977 | 1675 | } |
1676 | ||
1677 | //======================================================================= | |
1678 | //function : Pnt | |
1679 | //purpose : | |
1680 | //======================================================================= | |
1681 | ||
1682 | const gp_Pnt& BRepMesh_FastDiscretFace::Pnt(const Standard_Integer Index) const | |
1683 | { | |
c80dc6c3 | 1684 | return myLocation3d(myStructure->GetNode(Index).Location3d()); |
7fd59977 | 1685 | } |
1686 | ||
1687 | //======================================================================= | |
1688 | //function : FindUV | |
1689 | //purpose : | |
1690 | //======================================================================= | |
1691 | ||
c80dc6c3 O |
1692 | gp_XY BRepMesh_FastDiscretFace::FindUV(const TopoDS_Vertex& theV, |
1693 | const gp_Pnt2d& theXY, | |
1694 | const Standard_Integer theIp, | |
1695 | const Handle(BRepAdaptor_HSurface)& theSFace, | |
1696 | const Standard_Real theMinDist, | |
1697 | BRepMesh_DataMapOfIntegerListOfXY& theLocation2dMap) | |
7fd59977 | 1698 | { |
c80dc6c3 O |
1699 | gp_XY anUV; |
1700 | if (theLocation2dMap.IsBound(theIp)) | |
7fd59977 | 1701 | { |
c80dc6c3 O |
1702 | BRepMesh_ListOfXY& L = theLocation2dMap.ChangeFind(theIp); |
1703 | anUV = L.First(); | |
7fd59977 | 1704 | if (L.Extent() != 1) |
1705 | { | |
1706 | BRepMesh_ListIteratorOfListOfXY it(L); | |
1707 | it.Next(); | |
c80dc6c3 | 1708 | Standard_Real dd, dmin = theXY.Distance(gp_Pnt2d(anUV)); |
7fd59977 | 1709 | for (; it.More(); it.Next()) |
1710 | { | |
c80dc6c3 O |
1711 | dd = theXY.Distance(gp_Pnt2d(it.Value())); |
1712 | if (dd < dmin) | |
7fd59977 | 1713 | { |
c80dc6c3 O |
1714 | anUV = it.Value(); |
1715 | dmin = dd; | |
1716 | } | |
7fd59977 | 1717 | } |
1718 | } | |
1719 | ||
c80dc6c3 | 1720 | const Standard_Real tol = Min(2. * BRep_Tool::Tolerance(theV), theMinDist); |
7fd59977 | 1721 | |
c80dc6c3 O |
1722 | const Standard_Real Utol2d = .5 * (theSFace->LastUParameter() - theSFace->FirstUParameter()); |
1723 | const Standard_Real Vtol2d = .5 * (theSFace->LastVParameter() - theSFace->FirstVParameter()); | |
7fd59977 | 1724 | |
c80dc6c3 O |
1725 | const gp_Pnt p1 = theSFace->Value(anUV.X(), anUV.Y()); |
1726 | const gp_Pnt p2 = theSFace->Value(theXY.X(), theXY.Y()); | |
7fd59977 | 1727 | |
c80dc6c3 O |
1728 | if (Abs(anUV.X() - theXY.X()) > Utol2d || |
1729 | Abs(anUV.Y() - theXY.Y()) > Vtol2d || | |
1730 | !p1.IsEqual(p2, tol)) | |
7fd59977 | 1731 | { |
c80dc6c3 O |
1732 | anUV = theXY.Coord(); |
1733 | L.Append(anUV); | |
7fd59977 | 1734 | } |
1735 | } | |
1736 | else | |
1737 | { | |
c80dc6c3 | 1738 | anUV = theXY.Coord(); |
7fd59977 | 1739 | BRepMesh_ListOfXY L; |
c80dc6c3 O |
1740 | L.Append(anUV); |
1741 | theLocation2dMap.Bind(theIp, L); | |
7fd59977 | 1742 | } |
c80dc6c3 | 1743 | return anUV; |
7fd59977 | 1744 | } |
1745 | ||
1746 | ||
1747 | static Standard_Boolean GetVertexParameters(const TopoDS_Vertex& theVert, | |
c80dc6c3 O |
1748 | const TopoDS_Face& theFace, |
1749 | gp_Pnt2d& thePoint) | |
7fd59977 | 1750 | { |
1751 | TopLoc_Location L; | |
1752 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(theFace,L); | |
1753 | L = L.Predivided(theVert.Location()); | |
1754 | BRep_ListIteratorOfListOfPointRepresentation itpr = | |
1755 | ((*((Handle(BRep_TVertex)*) &theVert.TShape()))->Points()); | |
0d969553 | 1756 | // Check first if there are PointRepresentation (case non Manifold) |
7fd59977 | 1757 | |
1758 | while (itpr.More()) { | |
1759 | if (itpr.Value()->IsPointOnSurface(S,L)) { | |
1760 | thePoint.SetCoord(itpr.Value()->Parameter(), | |
c80dc6c3 | 1761 | itpr.Value()->Parameter2()); |
7fd59977 | 1762 | return Standard_True; |
1763 | } | |
1764 | itpr.Next(); | |
1765 | } | |
1766 | return Standard_False; | |
1767 | } | |
c80dc6c3 | 1768 | |
7fd59977 | 1769 | //======================================================================= |
1770 | //function : Add | |
0d969553 | 1771 | //purpose : method intended to add internal myVertices in triangulation. |
7fd59977 | 1772 | //======================================================================= |
7fd59977 | 1773 | void BRepMesh_FastDiscretFace::Add(const TopoDS_Vertex& theVert, |
c80dc6c3 O |
1774 | const TopoDS_Face& theFace, |
1775 | const Handle(BRepAdaptor_HSurface)& thegFace) | |
7fd59977 | 1776 | { |
1777 | const TopAbs_Orientation anOrient = theVert.Orientation(); | |
1778 | gp_Pnt2d uvXY; | |
1779 | if( anOrient != TopAbs_INTERNAL || !GetVertexParameters(theVert,theFace,uvXY)) | |
1780 | return; | |
1781 | Standard_Integer indVert =0; | |
c80dc6c3 O |
1782 | if (myVertices.IsBound(theVert)) |
1783 | indVert = myVertices.Find(theVert); | |
7fd59977 | 1784 | else |
1785 | { | |
c80dc6c3 O |
1786 | myNbLocat++; |
1787 | myLocation3d.Bind(myNbLocat, BRep_Tool::Pnt(theVert)); | |
1788 | indVert = myNbLocat; | |
1789 | myVertices.Bind(theVert, indVert); | |
7fd59977 | 1790 | } |
1791 | Standard_Real mindist = BRep_Tool::Tolerance(theVert); | |
1792 | // gp_Pnt2d uvXY = BRep_Tool::Parameters(theVert,theFace); | |
c80dc6c3 O |
1793 | gp_XY anUV = FindUV(theVert, uvXY, indVert, thegFace, mindist, myLocation2d); |
1794 | BRepMesh_Vertex vf(anUV, indVert, BRepMesh_Fixed); | |
1795 | Standard_Integer ivff = myStructure->AddNode(vf); | |
1796 | Standard_Integer isvf = myVemap.FindIndex(ivff); | |
1797 | if (isvf == 0) isvf = myVemap.Add(ivff); | |
7fd59977 | 1798 | } |