1 // Created on: 1995-12-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <BRep_CurveRepresentation.hxx>
19 #include <BRep_GCurve.hxx>
20 #include <BRep_TEdge.hxx>
21 #include <BRep_TFace.hxx>
22 #include <BRep_Tool.hxx>
23 #include <BRep_TVertex.hxx>
24 #include <BRepCheck.hxx>
25 #include <BRepCheck_ListOfStatus.hxx>
26 #include <BRepCheck_Vertex.hxx>
27 #include <Geom2d_Curve.hxx>
28 #include <Geom_Curve.hxx>
29 #include <Geom_Surface.hxx>
30 #include <gp_Pnt2d.hxx>
31 #include <Standard_Type.hxx>
32 #include <TopExp_Explorer.hxx>
34 #include <TopoDS_Edge.hxx>
35 #include <TopoDS_Iterator.hxx>
36 #include <TopoDS_Shape.hxx>
37 #include <TopoDS_Vertex.hxx>
39 IMPLEMENT_STANDARD_RTTIEXT(BRepCheck_Vertex,BRepCheck_Result)
41 //=======================================================================
42 //function : BRepCheck_Vertex
44 //=======================================================================
45 BRepCheck_Vertex::BRepCheck_Vertex(const TopoDS_Vertex& V)
52 //=======================================================================
55 //=======================================================================
56 void BRepCheck_Vertex::Minimum()
60 // checks the existence of a point 3D
61 Handle(BRepCheck_HListOfStatus) aNewList = new BRepCheck_HListOfStatus();
62 BRepCheck_ListOfStatus& lst = **myMap.Bound (myShape, aNewList);
63 lst.Append (BRepCheck_NoError);
64 myMin = Standard_True;
69 //=======================================================================
70 //function : InContext
72 //=======================================================================
74 void BRepCheck_Vertex::InContext(const TopoDS_Shape& S)
76 Handle(BRepCheck_HListOfStatus) aHList;
78 Standard_Mutex::Sentry aLock(myMutex.get());
79 if (myMap.IsBound (S))
84 Handle(BRepCheck_HListOfStatus) aNewList = new BRepCheck_HListOfStatus();
85 aHList = *myMap.Bound (S, aNewList);
87 BRepCheck_ListOfStatus& lst = *aHList;
89 TopExp_Explorer exp(S, TopAbs_VERTEX);
90 for (; exp.More(); exp.Next())
92 if (exp.Current().IsSame(myShape)) {
98 BRepCheck::Add (lst, BRepCheck_SubshapeNotInShape);
103 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
104 const gp_Pnt& prep = TV->Pnt();
107 TopAbs_ShapeEnum styp = S.ShapeType();
112 // Try to find the vertex on the edge
113 const TopoDS_Edge& E = TopoDS::Edge(S);
114 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
116 Standard_Boolean multiple = Standard_False;
119 const TopoDS_Vertex& VF = TopoDS::Vertex(itv.Value());
120 if (itv.Value().IsSame(myShape))
128 if ((VFind.Orientation() == TopAbs_FORWARD &&
129 VF.Orientation() == TopAbs_REVERSED) ||
130 (VFind.Orientation() == TopAbs_REVERSED &&
131 VF.Orientation() == TopAbs_FORWARD))
133 // the vertex on the edge is at once F and R
134 multiple = Standard_True;
136 if (VFind.Orientation() != TopAbs_FORWARD &&
137 VFind.Orientation() != TopAbs_REVERSED)
139 if (VF.Orientation() == TopAbs_FORWARD ||
140 VF.Orientation() == TopAbs_REVERSED)
150 // VFind is not null for sure
151 TopAbs_Orientation orv = VFind.Orientation();
153 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
154 Tol = Max(Tol, BRep_Tool::Tolerance(E)); // to check
157 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
158 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
159 const TopLoc_Location& Eloc = E.Location();
161 BRep_ListIteratorOfListOfPointRepresentation itpr;
164 // For each CurveRepresentation, the provided parameter is checked
165 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
166 const TopLoc_Location& loc = cr->Location();
167 TopLoc_Location L = (Eloc * loc).Predivided(myShape.Location());
171 const Handle(Geom_Curve)& C = cr->Curve3D();
172 if (!C.IsNull()) // edge non degenerated
174 itpr.Initialize(TV->Points());
177 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
178 if (pr->IsPointOnCurve (C, L))
180 Controlp = C->Value (pr->Parameter());
181 Controlp.Transform (L.Transformation());
182 if (prep.SquareDistance (Controlp) > Tol)
184 BRepCheck::Add (lst, BRepCheck_InvalidPointOnCurve);
189 if (orv == TopAbs_FORWARD || orv == TopAbs_REVERSED)
191 Handle(BRep_GCurve) GC = Handle(BRep_GCurve)::DownCast(cr);
192 if (orv == TopAbs_FORWARD || multiple)
194 Controlp = C->Value(GC->First());
195 Controlp.Transform(L.Transformation());
196 if (prep.SquareDistance(Controlp) > Tol)
198 BRepCheck::Add (lst, BRepCheck_InvalidPointOnCurve);
201 if (orv == TopAbs_REVERSED || multiple)
203 Controlp = C->Value(GC->Last());
204 Controlp.Transform(L.Transformation());
205 if (prep.SquareDistance (Controlp) > Tol)
207 BRepCheck::Add (lst, BRepCheck_InvalidPointOnCurve);
213 else if (cr->IsCurveOnSurface())
215 const Handle(Geom_Surface)& Su = cr->Surface();
216 const Handle(Geom2d_Curve)& PC = cr->PCurve();
217 Handle(Geom2d_Curve) PC2;
218 if (cr->IsCurveOnClosedSurface())
222 itpr.Initialize(TV->Points());
225 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
226 if (pr->IsPointOnCurveOnSurface(PC, Su, L))
228 gp_Pnt2d p2d = PC->Value(pr->Parameter());
229 Controlp = Su->Value(p2d.X(), p2d.Y());
230 Controlp.Transform(L.Transformation());
231 if (prep.SquareDistance(Controlp) > Tol)
233 BRepCheck::Add (lst, BRepCheck_InvalidPointOnCurveOnSurface);
236 if (!PC2.IsNull() && pr->IsPointOnCurveOnSurface (PC2, Su, L))
238 gp_Pnt2d p2d = PC2->Value(pr->Parameter());
239 Controlp = Su->Value(p2d.X(), p2d.Y());
240 Controlp.Transform(L.Transformation());
241 if (prep.SquareDistance(Controlp) > Tol)
243 BRepCheck::Add (lst, BRepCheck_InvalidPointOnCurveOnSurface);
253 lst.Append (BRepCheck_NoError);
259 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
260 const TopLoc_Location& Floc = S.Location();
261 const TopLoc_Location& TFloc = TF->Location();
262 const Handle(Geom_Surface)& Su = TF->Surface();
263 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
265 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
266 Tol = Max (Tol, BRep_Tool::Tolerance(TopoDS::Face(S))); // to check
269 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
272 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
273 if (pr->IsPointOnSurface (Su, L))
275 Controlp = Su->Value (pr->Parameter(), pr->Parameter2());
276 Controlp.Transform(L.Transformation());
277 if (prep.SquareDistance(Controlp) > Tol)
279 BRepCheck::Add (lst, BRepCheck_InvalidPointOnSurface);
286 lst.Append (BRepCheck_NoError);
297 //=======================================================================
300 //=======================================================================
302 void BRepCheck_Vertex::Blind()
307 // modified by NIZHNY-MKK Fri May 7 16:43:38 2004.BEGIN
308 // The body of this function is removed because of its useless
309 // (see specification "Substitution existing set of evaluation DRAW commands to one").
311 // Check all the representations of the vertex. (i-e checks the TVertex
312 // BRepCheck_ListOfStatus& lst = myMap(myShape);
313 // lst.Clear(); // there was NoError...
315 // Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
316 // const gp_Pnt& prep = TV->Pnt();
317 // Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
321 // BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
322 // BRepCheck_Status stat=BRepCheck_NoError;
323 // while (itpr.More()) {
324 // const Handle(BRep_PointRepresentation)& pr = itpr.Value();
325 // const TopLoc_Location& loc = pr->Location();
326 // if (pr->IsPointOnCurve()) {
327 // Controlp = pr->Curve()->Value(pr->Parameter());
328 // stat = BRepCheck_InvalidPointOnCurve;
330 // else if (pr->IsPointOnCurveOnSurface()) {
331 // gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
332 // Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
333 // stat = BRepCheck_InvalidPointOnCurveOnSurface;
335 // else if (pr->IsPointOnSurface()) {
336 // Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
337 // stat = BRepCheck_InvalidPointOnSurface;
339 // Controlp.Transform(loc.Transformation());
340 // if (prep.SquareDistance(Controlp) > Tol) {
341 // BRepCheck::Add(lst,stat);
346 // if (lst.IsEmpty()) {
347 // lst.Append(BRepCheck_NoError);
349 // modified by NIZHNY-MKK Fri May 7 16:43:45 2004.END
350 myBlind = Standard_True;
354 //=======================================================================
355 //function : Tolerance
357 //=======================================================================
359 Standard_Real BRepCheck_Vertex::Tolerance()
362 // Check all the representations of the vertex. (i-e checks the TVertex
363 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
364 const gp_Pnt& prep = TV->Pnt();
365 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
370 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
371 while (itpr.More()) {
372 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
373 const TopLoc_Location& loc = pr->Location();
374 if (pr->IsPointOnCurve()) {
375 if (!pr->Curve().IsNull())
376 Controlp = pr->Curve()->Value(pr->Parameter());
378 else if (pr->IsPointOnCurveOnSurface()) {
379 gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
380 Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
382 else if (pr->IsPointOnSurface()) {
383 Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
385 Controlp.Transform(loc.Transformation());
386 if (prep.SquareDistance(Controlp) > Tol) {
387 Tol = prep.SquareDistance(Controlp);
391 return sqrt(Tol*1.05);