summaryrefslogtreecommitdiff
path: root/src/BRepCheck/BRepCheck_Vertex.cxx
blob: ea78c7f74e53ccc51d45354815e30b25cb12c651 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
// File:	BRepCheck_Vertex.cxx
// Created:	Thu Dec  7 11:12:16 1995
// Author:	Jacques GOUSSARD
//		<jag@bravox>


#include <BRepCheck_Vertex.ixx>

#include <BRepCheck_ListOfStatus.hxx>

#include <BRep_TVertex.hxx>
#include <BRep_TEdge.hxx>
#include <BRep_TFace.hxx>

#include <BRep_PointRepresentation.hxx>
#include <BRep_ListOfPointRepresentation.hxx>
#include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
#include <BRep_CurveRepresentation.hxx>
#include <BRep_ListOfCurveRepresentation.hxx>
#include <BRep_ListIteratorOfListOfCurveRepresentation.hxx>
#include <BRep_GCurve.hxx>

#include <BRep_Tool.hxx>

#include <gp_Pnt2d.hxx>
#include <Geom_Curve.hxx>
#include <Geom_Surface.hxx>
#include <Geom2d_Curve.hxx>

#include <TopExp_Explorer.hxx>
#include <TopoDS_Iterator.hxx>

#include <BRepCheck.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>

//=======================================================================
//function : BRepCheck_Vertex
//purpose  : 
//=======================================================================

BRepCheck_Vertex::BRepCheck_Vertex(const TopoDS_Vertex& V)
{
  Init(V);
}



//=======================================================================
//function : Minimum
//purpose  : 
//=======================================================================

void BRepCheck_Vertex::Minimum()
{
  if (!myMin) {
    // consisterait a verifier l`existence d`un point 3D
    BRepCheck_ListOfStatus thelist;
    myMap.Bind(myShape, thelist);
    myMap(myShape).Append(BRepCheck_NoError);
    myMin = Standard_True;
  }
}


//=======================================================================
//function : InContext
//purpose  : 
//=======================================================================

void BRepCheck_Vertex::InContext(const TopoDS_Shape& S)
{
  if (myMap.IsBound(S)) {
    return;
  }
  BRepCheck_ListOfStatus thelist;
  myMap.Bind(S, thelist);

//  for (TopExp_Explorer exp(S,TopAbs_VERTEX); exp.More(); exp.Next()) {
  TopExp_Explorer exp(S,TopAbs_VERTEX) ;
  for ( ; exp.More(); exp.Next()) {
    if (exp.Current().IsSame(myShape)) {
      break;
    }
  }
  if (!exp.More()) {
    BRepCheck::Add(myMap(S),BRepCheck_SubshapeNotInShape);
    return; // on sort
  }


  Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
  const gp_Pnt& prep = TV->Pnt();
  gp_Pnt Controlp;

  TopAbs_ShapeEnum styp = S.ShapeType();
  switch (styp) {

  case TopAbs_EDGE:
    {
      // On essaie de retrouver le vertex sur l`edge
      
      const TopoDS_Edge& E = TopoDS::Edge(S);
      TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
      TopoDS_Vertex VFind;
      Standard_Boolean multiple = Standard_False;
      while (itv.More()) {
	const TopoDS_Vertex& VF = TopoDS::Vertex(itv.Value());
	if (itv.Value().IsSame(myShape)) {
	  if (VFind.IsNull()) {
	    VFind = VF;
	  }
	  else {
	    if ((VFind.Orientation() == TopAbs_FORWARD && 
		 VF.Orientation() == TopAbs_REVERSED) ||
		(VFind.Orientation() == TopAbs_REVERSED &&
		 VF.Orientation() == TopAbs_FORWARD)) {
	      // on a le vertex a la fois F et R sur l`edge
	      multiple = Standard_True; 
	    }
	    if (VFind.Orientation() != TopAbs_FORWARD && 
		VFind.Orientation() != TopAbs_REVERSED) {
	      if (VF.Orientation() == TopAbs_FORWARD ||
		  VF.Orientation() == TopAbs_REVERSED) {
		VFind = VF;
	      }
	    }
	  }
	}
	itv.Next();
      }

      // on est sur que VFind n`est pas nul
      TopAbs_Orientation orv = VFind.Orientation();

      Standard_Real Tol  = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
      Tol = Max(Tol,BRep_Tool::Tolerance(E)); // a voir
      Tol *= Tol;

      Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*)&E.TShape());
      BRep_ListIteratorOfListOfCurveRepresentation itcr(TE->Curves());
      const TopLoc_Location& Eloc = E.Location();

      BRep_ListIteratorOfListOfPointRepresentation itpr;
      while (itcr.More()) {
	// Pour chaque CurveRepresentation, on verifie le parametre fourni
	const Handle(BRep_CurveRepresentation)& cr = itcr.Value();
	const TopLoc_Location& loc = cr->Location();
	TopLoc_Location L = (Eloc * loc).Predivided(myShape.Location());

	if (cr->IsCurve3D()) {
	  const Handle(Geom_Curve)& C = cr->Curve3D();
	  if (!C.IsNull()) { // edge non degenere
	    itpr.Initialize(TV->Points());
	    while (itpr.More()) {
	      const Handle(BRep_PointRepresentation)& pr = itpr.Value();
	      if (pr->IsPointOnCurve(C,L)) {
		Controlp = C->Value(pr->Parameter());
		Controlp.Transform(L.Transformation());
		if (prep.SquareDistance(Controlp)> Tol) {
		  BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
		}
	      }
	      itpr.Next();
	    }
	    if (orv == TopAbs_FORWARD || orv == TopAbs_REVERSED) {
	      const Handle(BRep_GCurve)& GC = *((Handle(BRep_GCurve)*)&cr);
	      if (orv == TopAbs_FORWARD || multiple) {
		Controlp = C->Value(GC->First());
		Controlp.Transform(L.Transformation());
		if (prep.SquareDistance(Controlp)> Tol) {
		  BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
		}
	      }
	      if (orv == TopAbs_REVERSED || multiple) {
		Controlp = C->Value(GC->Last());
		Controlp.Transform(L.Transformation());
		if (prep.SquareDistance(Controlp)> Tol) {
		  BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnCurve);
		}
	      }
	    }
	  }
	}
	else if (cr->IsCurveOnSurface()) {
	  const Handle(Geom_Surface)& Su = cr->Surface();
	  const Handle(Geom2d_Curve)& PC = cr->PCurve();
	  Handle(Geom2d_Curve) PC2;
	  if (cr->IsCurveOnClosedSurface()) {
	    PC2 = cr->PCurve2();
	  }
	  itpr.Initialize(TV->Points());
	  while (itpr.More()) {
	    const Handle(BRep_PointRepresentation)& pr = itpr.Value();
	    if (pr->IsPointOnCurveOnSurface(PC,Su,L)) {
	      gp_Pnt2d p2d = PC->Value(pr->Parameter());
	      Controlp = Su->Value(p2d.X(),p2d.Y());
	      Controlp.Transform(L.Transformation());
	      if (prep.SquareDistance(Controlp)> Tol) {
		BRepCheck::Add(myMap(S),
			       BRepCheck_InvalidPointOnCurveOnSurface);
	      }
	    }
	    if (!PC2.IsNull() && pr->IsPointOnCurveOnSurface(PC2,Su,L)) {
	      gp_Pnt2d p2d = PC2->Value(pr->Parameter());
	      Controlp = Su->Value(p2d.X(),p2d.Y());
	      Controlp.Transform(L.Transformation());
	      if (prep.SquareDistance(Controlp)> Tol) {
		BRepCheck::Add(myMap(S),
			       BRepCheck_InvalidPointOnCurveOnSurface);
	      }
	    }
	    itpr.Next();
	  }
	}
	itcr.Next();
      }
      if (myMap(S).IsEmpty()) {
	myMap(S).Append(BRepCheck_NoError);
      }

    }
    break;

  case TopAbs_FACE:
    {

      Handle(BRep_TFace)& TF = *((Handle(BRep_TFace)*) &S.TShape());
      const TopLoc_Location& Floc = S.Location();
      const TopLoc_Location& TFloc = TF->Location();
      const Handle(Geom_Surface)& Su = TF->Surface();
      TopLoc_Location L = (Floc * TFloc).Predivided(myShape.Location());

      Standard_Real Tol  = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
      Tol = Max(Tol,BRep_Tool::Tolerance(TopoDS::Face(S))); // a voir
      Tol *= Tol;

      BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
      while (itpr.More()) {
	const Handle(BRep_PointRepresentation)& pr = itpr.Value();
	if (pr->IsPointOnSurface(Su,L)) {
	  Controlp = Su->Value(pr->Parameter(),pr->Parameter2());
	  Controlp.Transform(L.Transformation());
	  if (prep.SquareDistance(Controlp)> Tol) {
	    BRepCheck::Add(myMap(S),BRepCheck_InvalidPointOnSurface);
	  }
	}
	itpr.Next();
      }
      if (myMap(S).IsEmpty()) {
	myMap(S).Append(BRepCheck_NoError);
      }
    }

  default:
    break;

  }

}


//=======================================================================
//function : Blind
//purpose  : 
//=======================================================================

void BRepCheck_Vertex::Blind()
{
  if (myBlind) {
    return;
  }
// modified by NIZHNY-MKK  Fri May  7 16:43:38 2004.BEGIN
// The body of this function is removed because of its useless 
// (see specification "Substitution existing set of evaluation DRAW commands to one").

  // Check all the representations  of the vertex. (i-e checks the TVertex
//   BRepCheck_ListOfStatus& lst = myMap(myShape);
//   lst.Clear(); // there was NoError...

//   Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
//   const gp_Pnt& prep = TV->Pnt();
//   Standard_Real Tol  = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
//   Tol *= Tol;

//   gp_Pnt Controlp;
//   BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
//   BRepCheck_Status stat=BRepCheck_NoError;
//   while (itpr.More()) {
//     const Handle(BRep_PointRepresentation)& pr = itpr.Value();
//     const TopLoc_Location& loc = pr->Location();
//     if (pr->IsPointOnCurve()) {
//       Controlp = pr->Curve()->Value(pr->Parameter());
//       stat = BRepCheck_InvalidPointOnCurve;
//     }
//     else if (pr->IsPointOnCurveOnSurface()) {
//       gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
//       Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
//       stat = BRepCheck_InvalidPointOnCurveOnSurface;
//     }
//     else if (pr->IsPointOnSurface()) {
//       Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
//       stat = BRepCheck_InvalidPointOnSurface;
//     }
//     Controlp.Transform(loc.Transformation());
//     if (prep.SquareDistance(Controlp) > Tol) {
//       BRepCheck::Add(lst,stat);
//     }
//     itpr.Next();
//   }

//   if (lst.IsEmpty()) {
//     lst.Append(BRepCheck_NoError);
//   }
// modified by NIZHNY-MKK  Fri May  7 16:43:45 2004.END
  myBlind = Standard_True;
}


//=======================================================================
//function : Tolerance
//purpose  : 
//=======================================================================

Standard_Real BRepCheck_Vertex::Tolerance()
{

  // Check all the representations  of the vertex. (i-e checks the TVertex
  Handle(BRep_TVertex)& TV = *((Handle(BRep_TVertex)*) &myShape.TShape());
  const gp_Pnt& prep = TV->Pnt();
  Standard_Real Tol  = BRep_Tool::Tolerance(TopoDS::Vertex(myShape));
  Tol *= Tol;

  gp_Pnt Controlp;
  Controlp = prep;
  BRep_ListIteratorOfListOfPointRepresentation itpr(TV->Points());
  while (itpr.More()) {
    const Handle(BRep_PointRepresentation)& pr = itpr.Value();
    const TopLoc_Location& loc = pr->Location();
    if (pr->IsPointOnCurve()) {
      if (!pr->Curve().IsNull())
	Controlp = pr->Curve()->Value(pr->Parameter());
    }
    else if (pr->IsPointOnCurveOnSurface()) {
      gp_Pnt2d Puv = pr->PCurve()->Value(pr->Parameter());
      Controlp = pr->Surface()->Value(Puv.X(),Puv.Y());
    }
    else if (pr->IsPointOnSurface()) {
      Controlp = pr->Surface()->Value(pr->Parameter(),pr->Parameter2());
    }
    Controlp.Transform(loc.Transformation());
    if (prep.SquareDistance(Controlp) > Tol) {
      Tol = prep.SquareDistance(Controlp);
    }
    itpr.Next();
  }
  return sqrt(Tol*1.05);
}