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