0024023: Revamp the OCCT Handle -- plugin
[occt.git] / src / BRepCheck / BRepCheck_Vertex.cxx
CommitLineData
b311480e 1// Created on: 1995-12-07
2// Created by: Jacques GOUSSARD
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17#include <BRepCheck_Vertex.ixx>
18
19#include <BRepCheck_ListOfStatus.hxx>
20
21#include <BRep_TVertex.hxx>
22#include <BRep_TEdge.hxx>
23#include <BRep_TFace.hxx>
24
25#include <BRep_PointRepresentation.hxx>
26#include <BRep_ListOfPointRepresentation.hxx>
27#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
28#include <BRep_CurveRepresentation.hxx>
29#include <BRep_ListOfCurveRepresentation.hxx>
30#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
31#include <BRep_GCurve.hxx>
32
33#include <BRep_Tool.hxx>
34
35#include <gp_Pnt2d.hxx>
36#include <Geom_Curve.hxx>
37#include <Geom_Surface.hxx>
38#include <Geom2d_Curve.hxx>
39
40#include <TopExp_Explorer.hxx>
41#include <TopoDS_Iterator.hxx>
42
43#include <BRepCheck.hxx>
44#include <TopoDS.hxx>
45#include <TopoDS_Edge.hxx>
46
47//=======================================================================
48//function : BRepCheck_Vertex
49//purpose :
50//=======================================================================
51
52BRepCheck_Vertex::BRepCheck_Vertex(const TopoDS_Vertex& V)
53{
54 Init(V);
55}
56
57
58
59//=======================================================================
60//function : Minimum
61//purpose :
62//=======================================================================
63
64void BRepCheck_Vertex::Minimum()
65{
66 if (!myMin) {
0d969553 67 // checks the existence of a point 3D
7fd59977 68 BRepCheck_ListOfStatus thelist;
69 myMap.Bind(myShape, thelist);
70 myMap(myShape).Append(BRepCheck_NoError);
71 myMin = Standard_True;
72 }
73}
74
75
76//=======================================================================
77//function : InContext
78//purpose :
79//=======================================================================
80
81void BRepCheck_Vertex::InContext(const TopoDS_Shape& S)
82{
83 if (myMap.IsBound(S)) {
84 return;
85 }
86 BRepCheck_ListOfStatus thelist;
87 myMap.Bind(S, thelist);
88
89// for (TopExp_Explorer exp(S,TopAbs_VERTEX); exp.More(); exp.Next()) {
90 TopExp_Explorer exp(S,TopAbs_VERTEX) ;
91 for ( ; exp.More(); exp.Next()) {
92 if (exp.Current().IsSame(myShape)) {
93 break;
94 }
95 }
96 if (!exp.More()) {
97 BRepCheck::Add(myMap(S),BRepCheck_SubshapeNotInShape);
0d969553 98 return; // leaves
7fd59977 99 }
100
101
102 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
103 const gp_Pnt& prep = TV->Pnt();
104 gp_Pnt Controlp;
105
106 TopAbs_ShapeEnum styp = S.ShapeType();
107 switch (styp) {
108
109 case TopAbs_EDGE:
110 {
0d969553 111 // Try to find the vertex on the edge
7fd59977 112
113 const TopoDS_Edge& E = TopoDS::Edge(S);
114 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
115 TopoDS_Vertex VFind;
116 Standard_Boolean multiple = Standard_False;
117 while (itv.More()) {
118 const TopoDS_Vertex& VF = TopoDS::Vertex(itv.Value());
119 if (itv.Value().IsSame(myShape)) {
120 if (VFind.IsNull()) {
121 VFind = VF;
122 }
123 else {
124 if ((VFind.Orientation() == TopAbs_FORWARD &&
125 VF.Orientation() == TopAbs_REVERSED) ||
126 (VFind.Orientation() == TopAbs_REVERSED &&
127 VF.Orientation() == TopAbs_FORWARD)) {
0d969553 128 // the vertex on the edge is at once F and R
7fd59977 129 multiple = Standard_True;
130 }
131 if (VFind.Orientation() != TopAbs_FORWARD &&
132 VFind.Orientation() != TopAbs_REVERSED) {
133 if (VF.Orientation() == TopAbs_FORWARD ||
134 VF.Orientation() == TopAbs_REVERSED) {
135 VFind = VF;
136 }
137 }
138 }
139 }
140 itv.Next();
141 }
142
0d969553 143 // VFind is not null for sure
7fd59977 144 TopAbs_Orientation orv = VFind.Orientation();
145
146 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
0d969553 147 Tol = Max(Tol,BRep_Tool::Tolerance(E)); // to check
7fd59977 148 Tol *= Tol;
149
150 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
151 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
152 const TopLoc_Location& Eloc = E.Location();
153
154 BRep_ListIteratorOfListOfPointRepresentation itpr;
155 while (itcr.More()) {
0d969553 156 // For each CurveRepresentation, the provided parameter is checked
7fd59977 157 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
158 const TopLoc_Location& loc = cr->Location();
159 TopLoc_Location L = (Eloc * loc).Predivided(myShape.Location());
160
161 if (cr->IsCurve3D()) {
162 const Handle(Geom_Curve)& C = cr->Curve3D();
0d969553 163 if (!C.IsNull()) { // edge non degenerated
7fd59977 164 itpr.Initialize(TV->Points());
165 while (itpr.More()) {
166 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
167 if (pr->IsPointOnCurve(C,L)) {
168 Controlp = C->Value(pr->Parameter());
169 Controlp.Transform(L.Transformation());
170 if (prep.SquareDistance(Controlp)> Tol) {
171 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
172 }
173 }
174 itpr.Next();
175 }
176 if (orv == TopAbs_FORWARD || orv == TopAbs_REVERSED) {
177 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
178 if (orv == TopAbs_FORWARD || multiple) {
179 Controlp = C->Value(GC->First());
180 Controlp.Transform(L.Transformation());
181 if (prep.SquareDistance(Controlp)> Tol) {
182 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
183 }
184 }
185 if (orv == TopAbs_REVERSED || multiple) {
186 Controlp = C->Value(GC->Last());
187 Controlp.Transform(L.Transformation());
188 if (prep.SquareDistance(Controlp)> Tol) {
189 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
190 }
191 }
192 }
193 }
194 }
195 else if (cr->IsCurveOnSurface()) {
196 const Handle(Geom_Surface)& Su = cr->Surface();
197 const Handle(Geom2d_Curve)& PC = cr->PCurve();
198 Handle(Geom2d_Curve) PC2;
199 if (cr->IsCurveOnClosedSurface()) {
200 PC2 = cr->PCurve2();
201 }
202 itpr.Initialize(TV->Points());
203 while (itpr.More()) {
204 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
205 if (pr->IsPointOnCurveOnSurface(PC,Su,L)) {
206 gp_Pnt2d p2d = PC->Value(pr->Parameter());
207 Controlp = Su->Value(p2d.X(),p2d.Y());
208 Controlp.Transform(L.Transformation());
209 if (prep.SquareDistance(Controlp)> Tol) {
210 BRepCheck::Add(myMap(S),
211 BRepCheck_InvalidPointOnCurveOnSurface);
212 }
213 }
214 if (!PC2.IsNull() && pr->IsPointOnCurveOnSurface(PC2,Su,L)) {
215 gp_Pnt2d p2d = PC2->Value(pr->Parameter());
216 Controlp = Su->Value(p2d.X(),p2d.Y());
217 Controlp.Transform(L.Transformation());
218 if (prep.SquareDistance(Controlp)> Tol) {
219 BRepCheck::Add(myMap(S),
220 BRepCheck_InvalidPointOnCurveOnSurface);
221 }
222 }
223 itpr.Next();
224 }
225 }
226 itcr.Next();
227 }
228 if (myMap(S).IsEmpty()) {
229 myMap(S).Append(BRepCheck_NoError);
230 }
231
232 }
233 break;
234
235 case TopAbs_FACE:
236 {
237
238 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
239 const TopLoc_Location& Floc = S.Location();
240 const TopLoc_Location& TFloc = TF->Location();
241 const Handle(Geom_Surface)& Su = TF->Surface();
242 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
243
244 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
0d969553 245 Tol = Max(Tol,BRep_Tool::Tolerance(TopoDS::Face(S))); // to check
7fd59977 246 Tol *= Tol;
247
248 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
249 while (itpr.More()) {
250 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
251 if (pr->IsPointOnSurface(Su,L)) {
252 Controlp = Su->Value(pr->Parameter(),pr->Parameter2());
253 Controlp.Transform(L.Transformation());
254 if (prep.SquareDistance(Controlp)> Tol) {
255 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnSurface);
256 }
257 }
258 itpr.Next();
259 }
260 if (myMap(S).IsEmpty()) {
261 myMap(S).Append(BRepCheck_NoError);
262 }
263 }
264
265 default:
266 break;
267
268 }
269
270}
271
272
273//=======================================================================
274//function : Blind
275//purpose :
276//=======================================================================
277
278void BRepCheck_Vertex::Blind()
279{
280 if (myBlind) {
281 return;
282 }
0d969553
Y
283// modified by NIZHNY-MKK Fri May 7 16:43:38 2004.BEGIN
284// The body of this function is removed because of its useless
285// (see specification "Substitution existing set of evaluation DRAW commands to one").
7fd59977 286
0d969553 287// Check all the representations of the vertex. (i-e checks the TVertex
7fd59977 288// BRepCheck_ListOfStatus& lst = myMap(myShape);
289// lst.Clear(); // there was NoError...
290
291// Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
292// const gp_Pnt& prep = TV->Pnt();
293// Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
294// Tol *= Tol;
295
296// gp_Pnt Controlp;
297// BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
298// BRepCheck_Status stat=BRepCheck_NoError;
299// while (itpr.More()) {
300// const Handle(BRep_PointRepresentation)& pr = itpr.Value();
301// const TopLoc_Location& loc = pr->Location();
302// if (pr->IsPointOnCurve()) {
303// Controlp = pr->Curve()->Value(pr->Parameter());
304// stat = BRepCheck_InvalidPointOnCurve;
305// }
306// else if (pr->IsPointOnCurveOnSurface()) {
307// gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
308// Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
309// stat = BRepCheck_InvalidPointOnCurveOnSurface;
310// }
311// else if (pr->IsPointOnSurface()) {
312// Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
313// stat = BRepCheck_InvalidPointOnSurface;
314// }
315// Controlp.Transform(loc.Transformation());
316// if (prep.SquareDistance(Controlp) > Tol) {
317// BRepCheck::Add(lst,stat);
318// }
319// itpr.Next();
320// }
321
322// if (lst.IsEmpty()) {
323// lst.Append(BRepCheck_NoError);
324// }
325// modified by NIZHNY-MKK Fri May 7 16:43:45 2004.END
326 myBlind = Standard_True;
327}
328
329
330//=======================================================================
331//function : Tolerance
332//purpose :
333//=======================================================================
334
335Standard_Real BRepCheck_Vertex::Tolerance()
336{
337
338 // Check all the representations of the vertex. (i-e checks the TVertex
339 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
340 const gp_Pnt& prep = TV->Pnt();
341 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
342 Tol *= Tol;
343
344 gp_Pnt Controlp;
345 Controlp = prep;
346 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
347 while (itpr.More()) {
348 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
349 const TopLoc_Location& loc = pr->Location();
350 if (pr->IsPointOnCurve()) {
351 if (!pr->Curve().IsNull())
352 Controlp = pr->Curve()->Value(pr->Parameter());
353 }
354 else if (pr->IsPointOnCurveOnSurface()) {
355 gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
356 Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
357 }
358 else if (pr->IsPointOnSurface()) {
359 Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
360 }
361 Controlp.Transform(loc.Transformation());
362 if (prep.SquareDistance(Controlp) > Tol) {
363 Tol = prep.SquareDistance(Controlp);
364 }
365 itpr.Next();
366 }
367 return sqrt(Tol*1.05);
368}
369
370