1 // Created on: 1995-12-07
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
23 #include <BRepCheck_Vertex.ixx>
25 #include <BRepCheck_ListOfStatus.hxx>
27 #include <BRep_TVertex.hxx>
28 #include <BRep_TEdge.hxx>
29 #include <BRep_TFace.hxx>
31 #include <BRep_PointRepresentation.hxx>
32 #include <BRep_ListOfPointRepresentation.hxx>
33 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
34 #include <BRep_CurveRepresentation.hxx>
35 #include <BRep_ListOfCurveRepresentation.hxx>
36 #include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
37 #include <BRep_GCurve.hxx>
39 #include <BRep_Tool.hxx>
41 #include <gp_Pnt2d.hxx>
42 #include <Geom_Curve.hxx>
43 #include <Geom_Surface.hxx>
44 #include <Geom2d_Curve.hxx>
46 #include <TopExp_Explorer.hxx>
47 #include <TopoDS_Iterator.hxx>
49 #include <BRepCheck.hxx>
51 #include <TopoDS_Edge.hxx>
53 //=======================================================================
54 //function : BRepCheck_Vertex
56 //=======================================================================
58 BRepCheck_Vertex::BRepCheck_Vertex(const TopoDS_Vertex& V)
65 //=======================================================================
68 //=======================================================================
70 void BRepCheck_Vertex::Minimum()
73 // checks the existence of a point 3D
74 BRepCheck_ListOfStatus thelist;
75 myMap.Bind(myShape, thelist);
76 myMap(myShape).Append(BRepCheck_NoError);
77 myMin = Standard_True;
82 //=======================================================================
83 //function : InContext
85 //=======================================================================
87 void BRepCheck_Vertex::InContext(const TopoDS_Shape& S)
89 if (myMap.IsBound(S)) {
92 BRepCheck_ListOfStatus thelist;
93 myMap.Bind(S, thelist);
95 // for (TopExp_Explorer exp(S,TopAbs_VERTEX); exp.More(); exp.Next()) {
96 TopExp_Explorer exp(S,TopAbs_VERTEX) ;
97 for ( ; exp.More(); exp.Next()) {
98 if (exp.Current().IsSame(myShape)) {
103 BRepCheck::Add(myMap(S),BRepCheck_SubshapeNotInShape);
108 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
109 const gp_Pnt& prep = TV->Pnt();
112 TopAbs_ShapeEnum styp = S.ShapeType();
117 // Try to find the vertex on the edge
119 const TopoDS_Edge& E = TopoDS::Edge(S);
120 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
122 Standard_Boolean multiple = Standard_False;
124 const TopoDS_Vertex& VF = TopoDS::Vertex(itv.Value());
125 if (itv.Value().IsSame(myShape)) {
126 if (VFind.IsNull()) {
130 if ((VFind.Orientation() == TopAbs_FORWARD &&
131 VF.Orientation() == TopAbs_REVERSED) ||
132 (VFind.Orientation() == TopAbs_REVERSED &&
133 VF.Orientation() == TopAbs_FORWARD)) {
134 // the vertex on the edge is at once F and R
135 multiple = Standard_True;
137 if (VFind.Orientation() != TopAbs_FORWARD &&
138 VFind.Orientation() != TopAbs_REVERSED) {
139 if (VF.Orientation() == TopAbs_FORWARD ||
140 VF.Orientation() == TopAbs_REVERSED) {
149 // VFind is not null for sure
150 TopAbs_Orientation orv = VFind.Orientation();
152 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
153 Tol = Max(Tol,BRep_Tool::Tolerance(E)); // to check
156 Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
157 BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
158 const TopLoc_Location& Eloc = E.Location();
160 BRep_ListIteratorOfListOfPointRepresentation itpr;
161 while (itcr.More()) {
162 // For each CurveRepresentation, the provided parameter is checked
163 const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
164 const TopLoc_Location& loc = cr->Location();
165 TopLoc_Location L = (Eloc * loc).Predivided(myShape.Location());
167 if (cr->IsCurve3D()) {
168 const Handle(Geom_Curve)& C = cr->Curve3D();
169 if (!C.IsNull()) { // edge non degenerated
170 itpr.Initialize(TV->Points());
171 while (itpr.More()) {
172 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
173 if (pr->IsPointOnCurve(C,L)) {
174 Controlp = C->Value(pr->Parameter());
175 Controlp.Transform(L.Transformation());
176 if (prep.SquareDistance(Controlp)> Tol) {
177 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
182 if (orv == TopAbs_FORWARD || orv == TopAbs_REVERSED) {
183 const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
184 if (orv == TopAbs_FORWARD || multiple) {
185 Controlp = C->Value(GC->First());
186 Controlp.Transform(L.Transformation());
187 if (prep.SquareDistance(Controlp)> Tol) {
188 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
191 if (orv == TopAbs_REVERSED || multiple) {
192 Controlp = C->Value(GC->Last());
193 Controlp.Transform(L.Transformation());
194 if (prep.SquareDistance(Controlp)> Tol) {
195 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
201 else if (cr->IsCurveOnSurface()) {
202 const Handle(Geom_Surface)& Su = cr->Surface();
203 const Handle(Geom2d_Curve)& PC = cr->PCurve();
204 Handle(Geom2d_Curve) PC2;
205 if (cr->IsCurveOnClosedSurface()) {
208 itpr.Initialize(TV->Points());
209 while (itpr.More()) {
210 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
211 if (pr->IsPointOnCurveOnSurface(PC,Su,L)) {
212 gp_Pnt2d p2d = PC->Value(pr->Parameter());
213 Controlp = Su->Value(p2d.X(),p2d.Y());
214 Controlp.Transform(L.Transformation());
215 if (prep.SquareDistance(Controlp)> Tol) {
216 BRepCheck::Add(myMap(S),
217 BRepCheck_InvalidPointOnCurveOnSurface);
220 if (!PC2.IsNull() && pr->IsPointOnCurveOnSurface(PC2,Su,L)) {
221 gp_Pnt2d p2d = PC2->Value(pr->Parameter());
222 Controlp = Su->Value(p2d.X(),p2d.Y());
223 Controlp.Transform(L.Transformation());
224 if (prep.SquareDistance(Controlp)> Tol) {
225 BRepCheck::Add(myMap(S),
226 BRepCheck_InvalidPointOnCurveOnSurface);
234 if (myMap(S).IsEmpty()) {
235 myMap(S).Append(BRepCheck_NoError);
244 Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
245 const TopLoc_Location& Floc = S.Location();
246 const TopLoc_Location& TFloc = TF->Location();
247 const Handle(Geom_Surface)& Su = TF->Surface();
248 TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());
250 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
251 Tol = Max(Tol,BRep_Tool::Tolerance(TopoDS::Face(S))); // to check
254 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
255 while (itpr.More()) {
256 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
257 if (pr->IsPointOnSurface(Su,L)) {
258 Controlp = Su->Value(pr->Parameter(),pr->Parameter2());
259 Controlp.Transform(L.Transformation());
260 if (prep.SquareDistance(Controlp)> Tol) {
261 BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnSurface);
266 if (myMap(S).IsEmpty()) {
267 myMap(S).Append(BRepCheck_NoError);
279 //=======================================================================
282 //=======================================================================
284 void BRepCheck_Vertex::Blind()
289 // modified by NIZHNY-MKK Fri May 7 16:43:38 2004.BEGIN
290 // The body of this function is removed because of its useless
291 // (see specification "Substitution existing set of evaluation DRAW commands to one").
293 // Check all the representations of the vertex. (i-e checks the TVertex
294 // BRepCheck_ListOfStatus& lst = myMap(myShape);
295 // lst.Clear(); // there was NoError...
297 // Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
298 // const gp_Pnt& prep = TV->Pnt();
299 // Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
303 // BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
304 // BRepCheck_Status stat=BRepCheck_NoError;
305 // while (itpr.More()) {
306 // const Handle(BRep_PointRepresentation)& pr = itpr.Value();
307 // const TopLoc_Location& loc = pr->Location();
308 // if (pr->IsPointOnCurve()) {
309 // Controlp = pr->Curve()->Value(pr->Parameter());
310 // stat = BRepCheck_InvalidPointOnCurve;
312 // else if (pr->IsPointOnCurveOnSurface()) {
313 // gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
314 // Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
315 // stat = BRepCheck_InvalidPointOnCurveOnSurface;
317 // else if (pr->IsPointOnSurface()) {
318 // Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
319 // stat = BRepCheck_InvalidPointOnSurface;
321 // Controlp.Transform(loc.Transformation());
322 // if (prep.SquareDistance(Controlp) > Tol) {
323 // BRepCheck::Add(lst,stat);
328 // if (lst.IsEmpty()) {
329 // lst.Append(BRepCheck_NoError);
331 // modified by NIZHNY-MKK Fri May 7 16:43:45 2004.END
332 myBlind = Standard_True;
336 //=======================================================================
337 //function : Tolerance
339 //=======================================================================
341 Standard_Real BRepCheck_Vertex::Tolerance()
344 // Check all the representations of the vertex. (i-e checks the TVertex
345 Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
346 const gp_Pnt& prep = TV->Pnt();
347 Standard_Real Tol = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
352 BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
353 while (itpr.More()) {
354 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
355 const TopLoc_Location& loc = pr->Location();
356 if (pr->IsPointOnCurve()) {
357 if (!pr->Curve().IsNull())
358 Controlp = pr->Curve()->Value(pr->Parameter());
360 else if (pr->IsPointOnCurveOnSurface()) {
361 gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
362 Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
364 else if (pr->IsPointOnSurface()) {
365 Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
367 Controlp.Transform(loc.Transformation());
368 if (prep.SquareDistance(Controlp) > Tol) {
369 Tol = prep.SquareDistance(Controlp);
373 return sqrt(Tol*1.05);