summaryrefslogtreecommitdiff
path: root/inc/Contap_ContourGen_3.gxx
blob: e117fcb3ba74fbae8d3f695c8762f41e86c0947e (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
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
//-- Contap_ContourGen_3.gxx

#define Tolpetit 1.e-10  // pour dist au carre
#include <ElSLib.hxx>


#include <TColStd_SequenceOfInteger.hxx>

static Standard_Boolean FindLine(Contap_TheLine& Line,
				 const TheSurface& Surf,
				 const gp_Pnt2d& Pt2d,
				 gp_Pnt& Ptref,
				 Standard_Real& Paramin,
				 gp_Vec& Tgmin,
				 gp_Vec& Norm)
{
//  Standard_Integer i;
  gp_Pnt pt,ptmin;
  gp_Vec tg;
  Standard_Real para,dist;
  Standard_Real dismin = RealLast();

  Contap_TheSurfProps::Normale(Surf,Pt2d.X(),Pt2d.Y(),Ptref,Norm);

  if (Line.TypeContour() == Contap_Lin) {
    gp_Lin lin(Line.Line());
    para = ElCLib::Parameter(lin,Ptref);
    ElCLib::D1(para,lin,pt,tg);
    dist = pt.Distance(Ptref) + Abs(Norm.Dot(lin.Direction()));
  }
  else { // Contap__Circle
    gp_Circ cir(Line.Circle());
    para = ElCLib::Parameter(cir,Ptref);
    ElCLib::D1(para,cir,pt,tg);
    dist = pt.Distance(Ptref)+Abs(Norm.Dot(tg/cir.Radius()));
  }
  if (dist < dismin) {
    dismin = dist;
    Paramin = para;
    ptmin = pt;
    Tgmin = tg;
  }
  if (ptmin.SquareDistance(Ptref) <= Tolpetit) {
    return Standard_True;
  }
  else {
    return Standard_False;
  }
}


static void PutPointsOnLine (const Contap_TheSearch& solrst,
			     const TheSurface& Surf,
			     Contap_TheSequenceOfLine& slin)

{
  Standard_Integer i,l;//,index; 
  Standard_Integer NbPoints = solrst.NbPoints();

  Standard_Real theparam;

  IntSurf_Transition TLine,TArc;
  Standard_Boolean goon;
  
  gp_Pnt2d pt2d;
  gp_Vec2d d2d;

  gp_Pnt ptonsurf;
  gp_Vec vectg,normale,tgtrst;
  Standard_Real paramlin = 0;

  
  Standard_Integer nbLin = slin.Length();
  for(l=1;l<=nbLin;l++) { 
    Contap_TheLine& Line=slin.ChangeValue(l);
    for (i=1; i<= NbPoints; i++) {
      
      const Contap_ThePathPointOfTheSearch& PStart = solrst.Point(i);
      const TheArc& thearc = PStart.Arc();
      theparam = PStart.Parameter();
      
      TheArcTool::D1(thearc,theparam,pt2d,d2d);
      goon = FindLine(Line,Surf,pt2d,ptonsurf,paramlin,vectg,normale);
      
      Contap_ThePoint PPoint;

      if (goon) {
	gp_Vec d1u,d1v;
	gp_Pnt bidpt;
	TheSurfaceTool::D1(Surf,pt2d.X(),pt2d.Y(),bidpt,d1u,d1v);
	PPoint.SetValue(ptonsurf,pt2d.X(),pt2d.Y());
	if (normale.Magnitude() < RealEpsilon()) {
	  TLine.SetValue();
	  TArc.SetValue();
	}
	else {
	  // Petit test qui devrait permettre de bien traiter les pointes
	  // des cones, et les sommets d`une sphere. Il faudrait peut-etre
	  // rajouter une methode dans SurfProps
	  
	  if (Abs(d2d.Y()) <= Precision::Confusion()) {
	    tgtrst = d1v.Crossed(normale);
	    if(d2d.X() < 0.0) 
	      tgtrst.Reverse();
	  }
	  else {
	    tgtrst.SetLinearForm(d2d.X(),d1u,d2d.Y(),d1v);
	  }
	  IntSurf::MakeTransition(vectg,tgtrst,normale,TLine,TArc);
	}
	
	PPoint.SetArc(thearc,theparam, TLine, TArc);
	PPoint.SetParameter(paramlin);
	if (!PStart.IsNew()) {
	  PPoint.SetVertex(PStart.Vertex());
	}
	Line.Add(PPoint);
      }
    }
  }
}


//----------------------------------------------------------------------------------
//-- Orientation des contours Apparents quand ceux-ci sont des lignes ou des cercles
//-- On prend un point de la ligne ou du cercle ---> P 
//-- On projete ce point sur la surface P ---> u,v
//-- et on evalue la transition au point u,v
//----------------------------------------------------------------------------------

IntSurf_TypeTrans ComputeTransitionOngpLine
  (Contap_TheSurfFunction& SFunc,
   const gp_Lin& L)
{ 
  const TheSurface& Surf=SFunc.Surface();
  GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(Surf);
  gp_Pnt P;
  gp_Vec T;
  ElCLib::D1(0.0,L,P,T);
  Standard_Real u = 0.0,v= 0.0;
  switch (typS) {
  case GeomAbs_Cylinder: {
    ElSLib::Parameters(TheSurfaceTool::Cylinder(Surf),P,u,v);
      break;
    }
  case GeomAbs_Cone: {
    ElSLib::Parameters(TheSurfaceTool::Cone(Surf),P,u,v);
      break;
    }
  case GeomAbs_Sphere: { 
    ElSLib::Parameters(TheSurfaceTool::Sphere(Surf),P,u,v);
      break;
    }
#ifndef DEB
  default:
    break;
#endif
  }
  return(ComputeTransitionOnLine(SFunc,u,v,T));
}


IntSurf_TypeTrans ComputeTransitionOngpCircle
  (Contap_TheSurfFunction& SFunc,
   const gp_Circ& C)
{ 
  const TheSurface& Surf=SFunc.Surface();
  GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(Surf);
  gp_Pnt P;
  gp_Vec T;
  ElCLib::D1(0.0,C,P,T);
  Standard_Real u= 0.0,v= 0.0;
  switch (typS) {
  case GeomAbs_Cylinder: {
    ElSLib::Parameters(TheSurfaceTool::Cylinder(Surf),P,u,v);
      break;
    }
  case GeomAbs_Cone: {
    ElSLib::Parameters(TheSurfaceTool::Cone(Surf),P,u,v);
      break;
    }
  case GeomAbs_Sphere: { 
    ElSLib::Parameters(TheSurfaceTool::Sphere(Surf),P,u,v);
      break;
    }
#ifndef DEB
  default:
    break;
#endif
  }
  return(ComputeTransitionOnLine(SFunc,u,v,T));
  
}


void Contap_ContourGen::PerformAna(const Handle(TheTopolTool)& Domain)
{

  done = Standard_False;
  slin.Clear();

  Standard_Real TolArc = 1.e-5;

  Standard_Integer nbCont, nbPointRst, i;
  //gp_Circ cirsol;
  //gp_Lin linsol;
  Contap_ContAna contana;
  Contap_TheLine theline;
  const TheSurface& Surf = mySFunc.Surface();
  Contap_TFunction TypeFunc(mySFunc.FunctionType());
  Standard_Boolean PerformSolRst = Standard_True;

  GeomAbs_SurfaceType typS = TheSurfaceTool::GetType(Surf);

  switch (typS) {
  case GeomAbs_Plane: 
    {
      gp_Pln pl(TheSurfaceTool::Plane(Surf));
      switch (TypeFunc) {
      case Contap_ContourStd:
	{
	  gp_Dir Dirpln(pl.Axis().Direction());
	  if (Abs(mySFunc.Direction().Dot(Dirpln)) > Precision::Angular()) {
	    // Aucun point du plan n`est solution, en particulier aucun point
	    // sur restriction.
	    PerformSolRst = Standard_False;
	  }
	}
	break;
      case Contap_ContourPrs:
	{
	  gp_Pnt Eye(mySFunc.Eye());
	  if (pl.Distance(Eye) > Precision::Confusion()) {
	    // Aucun point du plan n`est solution, en particulier aucun point
	    // sur restriction.
	    PerformSolRst = Standard_False;
	  }	    
	}
	break;
      case Contap_DraftStd:
	{
	  gp_Dir Dirpln(pl.Axis().Direction());
	  Standard_Real Sina = Sin(mySFunc.Angle());
	  if (Abs(mySFunc.Direction().Dot(Dirpln)+ Sina) > //voir SurfFunction
	      Precision::Angular()) {
	  
	    PerformSolRst = Standard_False;
	  }
	}
	break;
      case Contap_DraftPrs:
      default:
	{
	}
      }
    }
    break;

  case GeomAbs_Sphere:
    {
      switch (TypeFunc) {
      case Contap_ContourStd:
	{
	  contana.Perform(TheSurfaceTool::Sphere(Surf),mySFunc.Direction());
	}
	break;
      case Contap_ContourPrs:
	{
	  contana.Perform(TheSurfaceTool::Sphere(Surf),mySFunc.Eye());
	}
	break;
      case Contap_DraftStd:
	{
	  contana.Perform(TheSurfaceTool::Sphere(Surf),
			  mySFunc.Direction(),mySFunc.Angle());
	}
	break;
      case Contap_DraftPrs:
      default:
	{
	}
      }
    }
    break;

  case GeomAbs_Cylinder:
    {
      switch (TypeFunc) {
      case Contap_ContourStd:
	{
	  contana.Perform(TheSurfaceTool::Cylinder(Surf),mySFunc.Direction());
	}
	break;
      case Contap_ContourPrs:
	{
	  contana.Perform(TheSurfaceTool::Cylinder(Surf),mySFunc.Eye());
	}
	break;
      case Contap_DraftStd:
	{
	  contana.Perform(TheSurfaceTool::Cylinder(Surf),
			  mySFunc.Direction(),mySFunc.Angle());
	}
	break;
      case Contap_DraftPrs:
      default:
	{
	}
      }
    }
    break;

  case GeomAbs_Cone:
    {
      switch (TypeFunc) {
      case Contap_ContourStd:
	{
	  contana.Perform(TheSurfaceTool::Cone(Surf),mySFunc.Direction());
	}
	break;
      case Contap_ContourPrs:
	{
	  contana.Perform(TheSurfaceTool::Cone(Surf),mySFunc.Eye());
	}
	break;
      case Contap_DraftStd:
	{
	  contana.Perform(TheSurfaceTool::Cone(Surf),
			  mySFunc.Direction(),mySFunc.Angle());
	}
	break;
      case Contap_DraftPrs:
      default:
	{
	}
      }
#ifndef DEB
    default:
      break;
#endif
    }
    break;
  }
  
  if (typS != GeomAbs_Plane) {

    if (!contana.IsDone()) {
      return;
    }

    nbCont = contana.NbContours();

    if (contana.NbContours() == 0) {
      done = Standard_True;
      return;
    }

    GeomAbs_CurveType typL = contana.TypeContour();
    if (typL == GeomAbs_Circle) {
      theline.SetValue(contana.Circle());
      IntSurf_TypeTrans TransCircle;
      TransCircle = ComputeTransitionOngpCircle(mySFunc,contana.Circle());
      theline.SetTransitionOnS(TransCircle);
      slin.Append(theline);
    }
    else if (typL == GeomAbs_Line) {
      for (i=1; i<=nbCont; i++) {
        theline.SetValue(contana.Line(i));
	IntSurf_TypeTrans TransLine;
	TransLine = ComputeTransitionOngpLine(mySFunc,contana.Line(i));
	theline.SetTransitionOnS(TransLine);
	slin.Append(theline);
	theline.Clear();
      }
      
/*
      if (typS == GeomAbs_Cone) {
        Standard_Real u,v;
	gp_Cone thecone(TheSurfaceTool::Cone(Surf));
	ElSLib::Parameters(thecone,thecone.Apex(),u,v);
	Contap_ThePoint vtxapex(thecone.Apex(),u,v);
	vtxapex.SetInternal();
	vtxapex.SetMultiple();
	for (i=1; i<=nbCont i++) {
          slin.ChangeValue(i).Add(vtxapex);
	}
      }
*/
    }
  }

  if(PerformSolRst) { 
    
    solrst.Perform(myAFunc,Domain,TolArc,TolArc);
    if (!solrst.IsDone()) {
      return;
    }
    nbPointRst = solrst.NbPoints();
    
    if (nbPointRst != 0) {
      PutPointsOnLine(solrst,Surf,slin);
    }
    
    if (solrst.NbSegments() !=0) {
      ProcessSegments(solrst,slin,TolArc,mySFunc,Domain);
    }
    
    
    //-- lbr 
    //Standard_Boolean oneremov;
    Standard_Integer nblinto = slin.Length();
    TColStd_SequenceOfInteger SeqToDestroy;
    
    //-- cout<<" Construct Contour_3   nblin = "<<nblinto<<endl;
    for(i=1; i<= nblinto ; i++) { 
      //-- cout<<" nbvtx : "<<slin.Value(i).NbVertex()<<endl;
      //--if(slin.Value(i).NbVertex() > 1) { 
      if(slin.Value(i).TypeContour() != Contap_Restriction) { 
	LineConstructor(slin,Domain,slin.ChangeValue(i),Surf);
	SeqToDestroy.Append(i);
      }
      //-- }
    }
    for(i=SeqToDestroy.Length(); i>=1; i--) { 
      slin.Remove(SeqToDestroy.Value(i));
    } 
  }

  done = Standard_True;
}