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_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>
27 #include <BRep_Tool.hxx>
28 #include <BRep_TVertex.hxx>
29 #include <BRepCheck.hxx>
30 #include <BRepCheck_ListOfStatus.hxx>
31 #include <BRepCheck_Vertex.hxx>
32 #include <Geom2d_Curve.hxx>
33 #include <Geom_Curve.hxx>
34 #include <Geom_Surface.hxx>
35 #include <gp_Pnt2d.hxx>
36 #include <Standard_Type.hxx>
37 #include <TopExp_Explorer.hxx>
39 #include <TopoDS_Edge.hxx>
40 #include <TopoDS_Iterator.hxx>
41 #include <TopoDS_Shape.hxx>
42 #include <TopoDS_Vertex.hxx>
44 IMPLEMENT_STANDARD_RTTIEXT(BRepCheck_Vertex,BRepCheck_Result)
46 //=======================================================================
47 //function : BRepCheck_Vertex
49 //=======================================================================
50 BRepCheck_Vertex::BRepCheck_Vertex(const TopoDS_Vertex& V)
57 //=======================================================================
60 //=======================================================================
62 void BRepCheck_Vertex::Minimum()
65 // checks the existence of a point 3D
66 BRepCheck_ListOfStatus thelist;
67 myMap.Bind(myShape, thelist);
68 myMap(myShape).Append(BRepCheck_NoError);
69 myMin = Standard_True;
74 //=======================================================================
75 //function : InContext
77 //=======================================================================
79 void BRepCheck_Vertex::InContext(const TopoDS_Shape& S)
81 if (myMap.IsBound(S)) {
84 BRepCheck_ListOfStatus thelist;
85 myMap.Bind(S, thelist);
87 // for (TopExp_Explorer exp(S,TopAbs_VERTEX); exp.More(); exp.Next()) {
88 TopExp_Explorer exp(S,TopAbs_VERTEX) ;
89 for ( ; exp.More(); exp.Next()) {
90 if (exp.Current().IsSame(myShape)) {
95 BRepCheck::Add(myMap(S),BRepCheck_SubshapeNotInShape);
100 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
101 const gp_Pnt& prep = TV->Pnt();
104 TopAbs_ShapeEnum styp = S.ShapeType();
109 // Try to find the vertex on the edge
111 const TopoDS_Edge& E = TopoDS::Edge(S);
112 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
114 Standard_Boolean multiple = Standard_False;
116 const TopoDS_Vertex& VF = TopoDS::Vertex(itv.Value());
117 if (itv.Value().IsSame(myShape)) {
118 if (VFind.IsNull()) {
122 if ((VFind.Orientation() == TopAbs_FORWARD &&
123 VF.Orientation() == TopAbs_REVERSED) ||
124 (VFind.Orientation() == TopAbs_REVERSED &&
125 VF.Orientation() == TopAbs_FORWARD)) {
126 // the vertex on the edge is at once F and R
127 multiple = Standard_True;
129 if (VFind.Orientation() != TopAbs_FORWARD &&
130 VFind.Orientation() != TopAbs_REVERSED) {
131 if (VF.Orientation() == TopAbs_FORWARD ||
132 VF.Orientation() == TopAbs_REVERSED) {
141 // VFind is not null for sure
142 TopAbs_Orientation orv = VFind.Orientation();
144 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
145 Tol = Max(Tol,BRep_Tool::Tolerance(E)); // to check
148 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
149 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
150 const TopLoc_Location& Eloc = E.Location();
152 BRep_ListIteratorOfListOfPointRepresentation itpr;
153 while (itcr.More()) {
154 // For each CurveRepresentation, the provided parameter is checked
155 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
156 const TopLoc_Location& loc = cr->Location();
157 TopLoc_Location L = (Eloc * loc).Predivided(myShape.Location());
159 if (cr->IsCurve3D()) {
160 const Handle(Geom_Curve)& C = cr->Curve3D();
161 if (!C.IsNull()) { // edge non degenerated
162 itpr.Initialize(TV->Points());
163 while (itpr.More()) {
164 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
165 if (pr->IsPointOnCurve(C,L)) {
166 Controlp = C->Value(pr->Parameter());
167 Controlp.Transform(L.Transformation());
168 if (prep.SquareDistance(Controlp)> Tol) {
169 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
174 if (orv == TopAbs_FORWARD || orv == TopAbs_REVERSED) {
175 Handle(BRep_GCurve) GC (Handle(BRep_GCurve)::DownCast (cr));
176 if (orv == TopAbs_FORWARD || multiple) {
177 Controlp = C->Value(GC->First());
178 Controlp.Transform(L.Transformation());
179 if (prep.SquareDistance(Controlp)> Tol) {
180 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
183 if (orv == TopAbs_REVERSED || multiple) {
184 Controlp = C->Value(GC->Last());
185 Controlp.Transform(L.Transformation());
186 if (prep.SquareDistance(Controlp)> Tol) {
187 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
193 else if (cr->IsCurveOnSurface()) {
194 const Handle(Geom_Surface)& Su = cr->Surface();
195 const Handle(Geom2d_Curve)& PC = cr->PCurve();
196 Handle(Geom2d_Curve) PC2;
197 if (cr->IsCurveOnClosedSurface()) {
200 itpr.Initialize(TV->Points());
201 while (itpr.More()) {
202 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
203 if (pr->IsPointOnCurveOnSurface(PC,Su,L)) {
204 gp_Pnt2d p2d = PC->Value(pr->Parameter());
205 Controlp = Su->Value(p2d.X(),p2d.Y());
206 Controlp.Transform(L.Transformation());
207 if (prep.SquareDistance(Controlp)> Tol) {
208 BRepCheck::Add(myMap(S),
209 BRepCheck_InvalidPointOnCurveOnSurface);
212 if (!PC2.IsNull() && pr->IsPointOnCurveOnSurface(PC2,Su,L)) {
213 gp_Pnt2d p2d = PC2->Value(pr->Parameter());
214 Controlp = Su->Value(p2d.X(),p2d.Y());
215 Controlp.Transform(L.Transformation());
216 if (prep.SquareDistance(Controlp)> Tol) {
217 BRepCheck::Add(myMap(S),
218 BRepCheck_InvalidPointOnCurveOnSurface);
226 if (myMap(S).IsEmpty()) {
227 myMap(S).Append(BRepCheck_NoError);
236 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
237 const TopLoc_Location& Floc = S.Location();
238 const TopLoc_Location& TFloc = TF->Location();
239 const Handle(Geom_Surface)& Su = TF->Surface();
240 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
242 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
243 Tol = Max(Tol,BRep_Tool::Tolerance(TopoDS::Face(S))); // to check
246 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
247 while (itpr.More()) {
248 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
249 if (pr->IsPointOnSurface(Su,L)) {
250 Controlp = Su->Value(pr->Parameter(),pr->Parameter2());
251 Controlp.Transform(L.Transformation());
252 if (prep.SquareDistance(Controlp)> Tol) {
253 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnSurface);
258 if (myMap(S).IsEmpty()) {
259 myMap(S).Append(BRepCheck_NoError);
271 //=======================================================================
274 //=======================================================================
276 void BRepCheck_Vertex::Blind()
281 // modified by NIZHNY-MKK Fri May 7 16:43:38 2004.BEGIN
282 // The body of this function is removed because of its useless
283 // (see specification "Substitution existing set of evaluation DRAW commands to one").
285 // Check all the representations of the vertex. (i-e checks the TVertex
286 // BRepCheck_ListOfStatus& lst = myMap(myShape);
287 // lst.Clear(); // there was NoError...
289 // Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
290 // const gp_Pnt& prep = TV->Pnt();
291 // Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
295 // BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
296 // BRepCheck_Status stat=BRepCheck_NoError;
297 // while (itpr.More()) {
298 // const Handle(BRep_PointRepresentation)& pr = itpr.Value();
299 // const TopLoc_Location& loc = pr->Location();
300 // if (pr->IsPointOnCurve()) {
301 // Controlp = pr->Curve()->Value(pr->Parameter());
302 // stat = BRepCheck_InvalidPointOnCurve;
304 // else if (pr->IsPointOnCurveOnSurface()) {
305 // gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
306 // Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
307 // stat = BRepCheck_InvalidPointOnCurveOnSurface;
309 // else if (pr->IsPointOnSurface()) {
310 // Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
311 // stat = BRepCheck_InvalidPointOnSurface;
313 // Controlp.Transform(loc.Transformation());
314 // if (prep.SquareDistance(Controlp) > Tol) {
315 // BRepCheck::Add(lst,stat);
320 // if (lst.IsEmpty()) {
321 // lst.Append(BRepCheck_NoError);
323 // modified by NIZHNY-MKK Fri May 7 16:43:45 2004.END
324 myBlind = Standard_True;
328 //=======================================================================
329 //function : Tolerance
331 //=======================================================================
333 Standard_Real BRepCheck_Vertex::Tolerance()
336 // Check all the representations of the vertex. (i-e checks the TVertex
337 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
338 const gp_Pnt& prep = TV->Pnt();
339 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
344 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
345 while (itpr.More()) {
346 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
347 const TopLoc_Location& loc = pr->Location();
348 if (pr->IsPointOnCurve()) {
349 if (!pr->Curve().IsNull())
350 Controlp = pr->Curve()->Value(pr->Parameter());
352 else if (pr->IsPointOnCurveOnSurface()) {
353 gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
354 Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
356 else if (pr->IsPointOnSurface()) {
357 Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
359 Controlp.Transform(loc.Transformation());
360 if (prep.SquareDistance(Controlp) > Tol) {
361 Tol = prep.SquareDistance(Controlp);
365 return sqrt(Tol*1.05);