summaryrefslogtreecommitdiff
path: root/src/Geom/Geom_SurfaceOfLinearExtrusion.cxx
blob: aac8718fc725cb36f13adb2c3ff711befcf9cc6c (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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
// File:	Geom_SurfaceOfLinearExtrusion.cxx
// Created:	Wed Mar 10 10:28:33 1993
// Author:	JCV
//		<fid@phylox>
// Copyright:	Matra Datavision 1993

//File Geom_SurfaceOfLinearExtrusion.cxx, JCV 4/03/91

#include <GeomAbs_CurveType.hxx>
#include <Geom_SurfaceOfLinearExtrusion.ixx>
#include <Precision.hxx>
#include <gp.hxx>
#include <gp_Ax2d.hxx>
#include <gp_XYZ.hxx>
#include <gp_Lin.hxx>
#include <Geom_Line.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Ellipse.hxx>
#include <Geom_Hyperbola.hxx>
#include <Geom_Parabola.hxx>
#include <Geom_BezierCurve.hxx>
#include <Geom_BSplineCurve.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <Geom_OffsetCurve.hxx>
#include <BSplSLib.hxx>
#include <BSplCLib.hxx>
#include <Standard_RangeError.hxx>

#define  POLES    (poles->Array2())
#define  WEIGHTS  (weights->Array2())
#define  UKNOTS   (uknots->Array1())
#define  VKNOTS   (vknots->Array1())
#define  UFKNOTS  (ufknots->Array1())
#define  VFKNOTS  (vfknots->Array1())
#define  FMULTS   (BSplCLib::NoMults())

typedef Geom_SurfaceOfLinearExtrusion         SurfaceOfLinearExtrusion;
typedef Handle(Geom_SurfaceOfLinearExtrusion) Handle(SurfaceOfLinearExtrusion);
typedef Geom_Curve                            Curve;
typedef Handle(Geom_Curve)                    Handle(Curve);
typedef gp_Dir  Dir;
typedef gp_Pnt  Pnt;
typedef gp_Trsf Trsf;
typedef gp_Vec  Vec;
typedef gp_XYZ  XYZ;

static void LocateSide(const Standard_Real U,
		       const Standard_Integer Side,
		       const Handle(Geom_BSplineCurve)& BSplC,
		       const Standard_Integer NDir,
		       gp_Pnt& P,
		       gp_Vec& D1U,
		       gp_Vec& D2U,
		       gp_Vec& D3U) 
{ 
  Standard_Integer Ideb, Ifin;
  Standard_Real ParTol=Precision::PConfusion()/2;
  BSplC->Geom_BSplineCurve::LocateU(U,ParTol,Ideb,Ifin,Standard_False);   
  if(Side == 1)
    {
      if(Ideb<1) Ideb=1;
      if ((Ideb>=Ifin))  Ifin = Ideb+1;
    }else
  if(Side ==-1)
	{ 
	  if(Ifin > BSplC -> NbKnots()) Ifin=BSplC->NbKnots();
	  if ((Ideb>=Ifin))  Ideb = Ifin-1;
	}

  switch(NDir)
       {
       case 0 :  BSplC->Geom_BSplineCurve::LocalD0(U,Ideb,Ifin,P); break;
       case 1 :  BSplC->Geom_BSplineCurve::LocalD1(U,Ideb,Ifin,P,D1U); break;
       case 2 :  BSplC->Geom_BSplineCurve::LocalD2(U,Ideb,Ifin,P,D1U,D2U); break;
       case 3 :  BSplC->Geom_BSplineCurve::LocalD3(U,Ideb,Ifin,P,D1U,D2U,D3U);break;
	}
   
}

static gp_Vec LocateSideN(const Standard_Real U,
			  const Standard_Integer Side,
			  const Handle(Geom_BSplineCurve)& BSplC,
			  const Standard_Integer Nu,
//			  const	Standard_Integer  Nv ) 
			  const	Standard_Integer ) 
{ 
  Standard_Integer Ideb, Ifin;
  Standard_Real ParTol=Precision::PConfusion()/2;
  BSplC->Geom_BSplineCurve::LocateU(U,ParTol,Ideb,Ifin,Standard_False);   
  if(Side == 1)
    {
      if(Ideb<1) Ideb=1;
      if ((Ideb>=Ifin))  Ifin = Ideb+1;
    }else
      if(Side ==-1)
	{ 
	  if(Ifin > BSplC -> NbKnots()) Ifin=BSplC->NbKnots();
	  if ((Ideb>=Ifin))  Ideb = Ifin-1;
	}
  return BSplC->Geom_BSplineCurve::LocalDN(U,Ideb,Ifin,Nu);
}



//=======================================================================
//function : Copy
//purpose  : 
//=======================================================================

Handle(Geom_Geometry) Geom_SurfaceOfLinearExtrusion::Copy () const 
{
  
  Handle(Geom_SurfaceOfLinearExtrusion) Sr;
  Sr = new SurfaceOfLinearExtrusion (basisCurve, direction);
  return Sr;
}


//=======================================================================
//function : Geom_SurfaceOfLinearExtrusion
//purpose  : 
//=======================================================================

Geom_SurfaceOfLinearExtrusion::Geom_SurfaceOfLinearExtrusion 
  ( const Handle(Curve)& C, 
    const Dir& V) {

   basisCurve = Handle(Curve)::DownCast(C->Copy());  // Copy 10-03-93
   direction  = V;
   smooth     = C->Continuity();
 }


//=======================================================================
//function : UReverse
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::UReverse () { 

  basisCurve->Reverse(); 
}


//=======================================================================
//function : UReversedParameter
//purpose  : 
//=======================================================================

Standard_Real Geom_SurfaceOfLinearExtrusion::UReversedParameter(const Standard_Real U) const {

  return basisCurve->ReversedParameter(U);
}


//=======================================================================
//function : VReverse
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::VReverse () {

  direction.Reverse(); 
}


//=======================================================================
//function : VReversedParameter
//purpose  : 
//=======================================================================

Standard_Real Geom_SurfaceOfLinearExtrusion::VReversedParameter( const Standard_Real V) const {

  return (-V);
}


//=======================================================================
//function : SetDirection
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::SetDirection (const Dir& V) {

   Handle(Geom_Curve) C;
   direction = V;
   C         = basisCurve;
 }


//=======================================================================
//function : SetBasisCurve
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::SetBasisCurve (const Handle(Curve)& C) {

   smooth = C->Continuity();
   basisCurve = Handle(Curve)::DownCast(C->Copy());  // Copy 10-03-93
}


//=======================================================================
//function : Bounds
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::Bounds ( Standard_Real& U1, 
					     Standard_Real& U2,
					     Standard_Real& V1, 
					     Standard_Real& V2 ) const {

  V1 = -Precision::Infinite();  V2 = Precision::Infinite();
  U1 = basisCurve->FirstParameter();  U2 = basisCurve->LastParameter();
}


//=======================================================================
//function : D0
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::D0 (const Standard_Real U, const Standard_Real V, 
					      Pnt& P               )  const {
  
  XYZ Pxyz = direction.XYZ();
  Pxyz.Multiply (V);
  Pxyz.Add (basisCurve->Value (U).XYZ());
  P.SetXYZ(Pxyz);      
}


//=======================================================================
//function : D1
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::D1 ( const Standard_Real U  , 
					 const Standard_Real V  , 
					       Pnt& P  , 
					       Vec& D1U, Vec& D1V) const {

   basisCurve->D1 (U, P, D1U);
   D1V = direction;
   XYZ Pxyz = direction.XYZ();
   Pxyz.Multiply (V);
   Pxyz.Add (P.XYZ());
   P.SetXYZ (Pxyz);
}


//=======================================================================
//function : D2
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::D2 ( const Standard_Real U  , 
					 const Standard_Real V  ,
					       Pnt& P  ,
					       Vec& D1U, Vec& D1V,
					       Vec& D2U, Vec& D2V, Vec& D2UV)
const {

   basisCurve->D2 (U, P, D1U, D2U);
   D1V = direction;
   D2V.SetCoord  (0.0, 0.0, 0.0);
   D2UV.SetCoord (0.0, 0.0, 0.0);
   XYZ Pxyz = direction.XYZ();
   Pxyz.Multiply (V);
   Pxyz.Add (P.XYZ());
   P.SetXYZ (Pxyz);
}


//=======================================================================
//function : D3
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::D3 
  ( const Standard_Real U, const Standard_Real V,
    Pnt& P,
    Vec& D1U, Vec& D1V,
    Vec& D2U, Vec& D2V, Vec& D2UV,
    Vec& D3U, Vec& D3V, Vec& D3UUV, Vec& D3UVV ) const {


   basisCurve->D3 (U, P, D1U, D2U, D3U);
   D1V = direction;
   D2V.SetCoord   (0.0, 0.0, 0.0);
   D3V.SetCoord   (0.0, 0.0, 0.0);
   D3UUV.SetCoord (0.0, 0.0, 0.0);
   D3UVV.SetCoord (0.0, 0.0, 0.0);
   D2UV.SetCoord  (0.0, 0.0, 0.0);
   XYZ Pxyz = direction.XYZ();
   Pxyz.Multiply (V);
   Pxyz.Add (P.XYZ());
   P.SetXYZ (Pxyz);
}
//=======================================================================
//function : DN
//purpose  : 
//=======================================================================

Vec Geom_SurfaceOfLinearExtrusion::DN 
  ( const Standard_Real     U, const Standard_Real , 
    const Standard_Integer Nu, const Standard_Integer Nv) const {

  Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
  if (Nu == 0 && Nv == 1)  return Vec (direction);
  else if (Nv == 0)        return basisCurve->DN (U, Nu);
  else                     return Vec (0.0, 0.0, 0.0);
}


//=======================================================================
//function : LocalD0
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::LocalD0 (const Standard_Real    U,
					     const Standard_Real    V, 
					     const Standard_Integer USide,
					     gp_Pnt&          P     )  const
{ 
  if((USide != 0) && basisCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) 
    { 
      Vec D1U,D2U,D3U;
      Handle( Geom_BSplineCurve) BSplC;
      BSplC= Handle(Geom_BSplineCurve)::DownCast(basisCurve);

      LocateSide(U,USide,BSplC,0,P,D1U,D2U,D3U);
      XYZ Pxyz = direction.XYZ();
      Pxyz.Multiply (V);
      Pxyz.Add (P.XYZ());
      P.SetXYZ (Pxyz);
    }
  else D0(U,V,P);
}        

//=======================================================================
//function : LocalD1
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::LocalD1 (const Standard_Real    U, 
				   const Standard_Real    V,
				   const Standard_Integer USide, 
				         gp_Pnt&          P,
				         gp_Vec&          D1U, 
				         gp_Vec&          D1V)     const
{ 
  if((USide != 0) && basisCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) 
    { 
      Vec D2U,D3U;
      Handle( Geom_BSplineCurve) BSplC;
      BSplC= Handle(Geom_BSplineCurve)::DownCast(basisCurve);

	  LocateSide(U,USide,BSplC,1,P,D1U,D2U,D3U);
	  D1V = direction;
	  XYZ Pxyz = direction.XYZ();
	  Pxyz.Multiply (V);
	  Pxyz.Add (P.XYZ());
	  P.SetXYZ (Pxyz);
    }
  else D1(U,V,P,D1U,D1V);
}

//=======================================================================
//function : LocalD2
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::LocalD2 (const Standard_Real    U,
				   const Standard_Real    V,
				   const Standard_Integer USide,
				         gp_Pnt&          P,
				         gp_Vec&          D1U,
				         gp_Vec&          D1V,
				         gp_Vec&          D2U,
				         gp_Vec&          D2V,
				         gp_Vec&          D2UV) const
{
 if((USide != 0) && basisCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) 
    { 
      Vec D3U;
      Handle( Geom_BSplineCurve) BSplC;
      BSplC= Handle(Geom_BSplineCurve)::DownCast(basisCurve);

	  LocateSide(U,USide,BSplC,2,P,D1U,D2U,D3U);
	  D1V = direction;
	  D2V.SetCoord  (0.0, 0.0, 0.0);
	  D2UV.SetCoord (0.0, 0.0, 0.0);
	  XYZ Pxyz = direction.XYZ();
	  Pxyz.Multiply (V);
	  Pxyz.Add (P.XYZ());
	  P.SetXYZ (Pxyz); 
    }
  else D2(U,V,P,D1U,D1V,D2U,D2V,D2UV);
}

//=======================================================================
//function : LocalD3
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::LocalD3 (const Standard_Real    U, 
				   const Standard_Real    V,
				   const Standard_Integer USide, 
					 gp_Pnt&          P,
				         gp_Vec&          D1U,
				         gp_Vec&          D1V, 
				         gp_Vec&          D2U, 
				         gp_Vec&          D2V, 
				         gp_Vec&          D2UV, 
				         gp_Vec&          D3U,
				         gp_Vec&          D3V,
				         gp_Vec&          D3UUV,
				         gp_Vec&          D3UVV) const
{
  if((USide != 0) && basisCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) 
    { 
      Handle( Geom_BSplineCurve) BSplC;
      BSplC= Handle(Geom_BSplineCurve)::DownCast(basisCurve);

	  LocateSide(U,USide,BSplC,3,P,D1U,D2U,D3U);
	  D1V = direction;
	  D2V.SetCoord   (0.0, 0.0, 0.0);
	  D3V.SetCoord   (0.0, 0.0, 0.0);
	  D3UUV.SetCoord (0.0, 0.0, 0.0);
	  D3UVV.SetCoord (0.0, 0.0, 0.0);
	  D2UV.SetCoord  (0.0, 0.0, 0.0);
	  XYZ Pxyz = direction.XYZ();
	  Pxyz.Multiply (V);
	  Pxyz.Add (P.XYZ());
	  P.SetXYZ (Pxyz);
    }
  else D3(U,V,P,D1U,D1V,D2U,D2V,D2UV,D3U,D3V,D3UUV,D3UVV);

}

//=======================================================================
//function : LocalDN
//purpose  : 
//=======================================================================

gp_Vec Geom_SurfaceOfLinearExtrusion::LocalDN  (const Standard_Real    U, 
				      const Standard_Real    V,
				      const Standard_Integer USide,
				      const Standard_Integer Nu,
				      const Standard_Integer Nv) const
{
  Standard_RangeError_Raise_if (Nu + Nv < 1 || Nu < 0 || Nv <0, " ");
  if (Nu == 0 && Nv == 1)  return Vec (direction);
  else if (Nv == 0) {
    if((USide != 0) && basisCurve->IsKind(STANDARD_TYPE(Geom_BSplineCurve))) { 
      Handle( Geom_BSplineCurve) BSplC;
      BSplC= Handle(Geom_BSplineCurve)::DownCast(basisCurve);
      return LocateSideN(U,USide,BSplC,Nu,Nv);
    }
    else
      return DN(U,V,Nu,Nv);
  }      
  return Vec (0.0, 0.0, 0.0);
}

//=======================================================================
//function : UIso
//purpose  : 
//=======================================================================

Handle(Geom_Curve) Geom_SurfaceOfLinearExtrusion::UIso (const Standard_Real U) const {

  Handle(Geom_Line) L; 
  L = new Geom_Line (basisCurve->Value (U), direction);
  return L;
}


//=======================================================================
//function : VIso
//purpose  : 
//=======================================================================

Handle(Curve) Geom_SurfaceOfLinearExtrusion::VIso (const Standard_Real V) const {
    
  Vec Vdir (direction);
  Vdir.Multiply (V);
  Handle(Curve) C;
  C = Handle(Geom_Curve)::DownCast(basisCurve->Translated(Vdir));
  return C;
}


//=======================================================================
//function : IsCNu
//purpose  : 
//=======================================================================

Standard_Boolean Geom_SurfaceOfLinearExtrusion::IsCNu (const Standard_Integer N) const {

  Standard_RangeError_Raise_if (N < 0, " ");
  return basisCurve->IsCN (N);
}


//=======================================================================
//function : IsCNv
//purpose  : 
//=======================================================================

Standard_Boolean Geom_SurfaceOfLinearExtrusion::IsCNv (const Standard_Integer ) const {

  return Standard_True;
}


//=======================================================================
//function : Transform
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::Transform (const Trsf& T) {

   direction.Transform   (T);
   basisCurve->Transform (T);
}



//=======================================================================
//function : IsUClosed
//purpose  : 
//=======================================================================

Standard_Boolean Geom_SurfaceOfLinearExtrusion::IsUClosed () const { 

  return basisCurve->IsClosed ();
}


//=======================================================================
//function : IsUPeriodic
//purpose  : 
//=======================================================================

Standard_Boolean Geom_SurfaceOfLinearExtrusion::IsUPeriodic () const { 

  return basisCurve->IsPeriodic ();
}

//=======================================================================
//function : IsVClosed
//purpose  : 
//=======================================================================

Standard_Boolean Geom_SurfaceOfLinearExtrusion::IsVClosed () const  {

  return Standard_False; 
}

//=======================================================================
//function : IsVPeriodic
//purpose  : 
//=======================================================================

Standard_Boolean Geom_SurfaceOfLinearExtrusion::IsVPeriodic () const { 

  return Standard_False;
}

//=======================================================================
//function : TransformParameters
//purpose  : 
//=======================================================================

void Geom_SurfaceOfLinearExtrusion::TransformParameters(Standard_Real& U,
							Standard_Real& V,
							const gp_Trsf& T) 
const
{
  U = basisCurve->TransformedParameter(U,T);
  if (!Precision::IsInfinite(V)) V *= Abs(T.ScaleFactor());
}

//=======================================================================
//function : ParametricTransformation
//purpose  : 
//=======================================================================

gp_GTrsf2d Geom_SurfaceOfLinearExtrusion::ParametricTransformation
(const gp_Trsf& T) const
{
  // transformation in the V Direction
  gp_GTrsf2d TV;
  gp_Ax2d Axis(gp::Origin2d(),gp::DX2d());
  TV.SetAffinity(Axis, Abs(T.ScaleFactor()));
  // transformation in the U Direction
  gp_GTrsf2d TU;
  Axis = gp_Ax2d(gp::Origin2d(),gp::DY2d());
  TU.SetAffinity(Axis, basisCurve->ParametricTransformation(T));
 
  return TU * TV;
}