summaryrefslogtreecommitdiff
path: root/src/Law/Law_Interpol.cxx
blob: f66d28355d1e6c0c3d94b375d44ee6f29d45b8dd (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
// pmn -> modified 17/01/1996 : utilisation de Curve() et SetCurve()

#include <Law_Interpol.ixx>
#include <Precision.hxx>
#include <TColStd_HArray1OfReal.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Vec2d.hxx>
#include <Law_Interpolate.hxx>

#ifdef DEB
#ifdef DRAW

// Pour le dessin.
#include <Draw_Appli.hxx>
#include <Draw_Display.hxx>
#include <Draw.hxx>
#include <Draw_Segment3D.hxx>
#include <Draw_Segment2D.hxx>
#include <Draw_Marker2D.hxx>
#include <Draw_ColorKind.hxx>
#include <Draw_MarkerShape.hxx>

static void Law_draw1dcurve(const Handle(Law_BSpline)& bs,
                            const gp_Vec2d&            tra,
                            const Standard_Real        scal)
{
  TColStd_Array1OfReal pol(1,bs->NbPoles());
  bs->Poles(pol);
  TColStd_Array1OfReal knots(1,bs->NbKnots());
  bs->Knots(knots);
  TColStd_Array1OfInteger  mults(1,bs->NbKnots());
  bs->Multiplicities(mults);
  Standard_Integer deg = bs->Degree();
  Standard_Integer nbk = knots.Length();
  
  Handle(Draw_Marker2D) mar;
  gp_Pnt2d pp(knots(1),scal*bs->Value(knots(1)));
  pp.Translate(tra);
  gp_Pnt2d qq;
  mar = new Draw_Marker2D(pp,Draw_Square,Draw_cyan);
  dout<<mar;
  Handle(Draw_Segment2D) seg;
  for(Standard_Integer i = 1; i < nbk; i++){
    Standard_Real f = knots(i);
    Standard_Real l = knots(i+1);
    for (Standard_Integer iu = 1; iu <= 30; iu++){
      Standard_Real uu = iu/30.;
      uu = f+uu*(l-f);
      qq.SetCoord(uu,scal*bs->Value(uu));
      qq.Translate(tra);
      seg = new Draw_Segment2D(pp,qq,Draw_jaune);
      dout<<seg;
      pp = qq;
    }
    mar = new Draw_Marker2D(pp,Draw_Square,Draw_cyan);
    dout<<mar;
  }
}

static void Law_draw1dcurve(const TColStd_Array1OfReal&    pol,
                            const TColStd_Array1OfReal&    knots,
                            const TColStd_Array1OfInteger& mults,
                            const Standard_Integer         deg, 
                            const gp_Vec2d&                tra,
                            const Standard_Real            scal)
{
  Handle(Law_BSpline) bs = new Law_BSpline(pol,knots,mults,deg);
  Law_draw1dcurve(bs,tra,scal);
}

static Standard_Boolean Affich = 0;

#endif
#endif

//=======================================================================
//function : Law_Interpol
//purpose  : 
//=======================================================================

Law_Interpol::Law_Interpol()
{
}

//=======================================================================
//function : Set
//purpose  : 
//=======================================================================

void Law_Interpol::Set(const TColgp_Array1OfPnt2d& ParAndRad,
		       const Standard_Boolean Periodic)
{
  Standard_Integer l = ParAndRad.Lower();
  Standard_Integer nbp = ParAndRad.Length();

  Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
  Handle(TColStd_HArray1OfReal) rad;
  if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
  else rad = new TColStd_HArray1OfReal(1,nbp);
  Standard_Real x,y;
  Standard_Integer i;
  for(i = 1; i <= nbp; i++){
    ParAndRad(l + i - 1).Coord(x,y);
    par->SetValue(i,x);
    if(!Periodic || i != nbp) rad->SetValue(i,y);
  }
  Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
  inter.Perform();
  SetCurve(inter.Curve()); 
#ifdef DEB
#ifdef DRAW
  if (Affich) {
    gp_Vec2d veve(0.,0.);
    Law_draw1dcurve(Curve(),veve,1.);
  }
#endif
#endif
}

//=======================================================================
//function : SetInRelative
//purpose  : 
//=======================================================================

void Law_Interpol::SetInRelative(const TColgp_Array1OfPnt2d& ParAndRad,
				 const Standard_Real Ud,
				 const Standard_Real Uf,
				 const Standard_Boolean Periodic)
{
  Standard_Integer l = ParAndRad.Lower(), u = ParAndRad.Upper();
  Standard_Real wd = ParAndRad(l).X(),wf = ParAndRad(u).X();
  Standard_Integer nbp = ParAndRad.Length();
  Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
  Handle(TColStd_HArray1OfReal) rad;
  if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
  else rad = new TColStd_HArray1OfReal(1,nbp);
  Standard_Real x,y;
  Standard_Integer i;
  for(i = 1; i <= nbp; i++){
    ParAndRad(l + i - 1).Coord(x,y);
    par->SetValue(i,(Uf*(x-wd)+Ud*(wf-x))/(wf-wd));
    if(!Periodic || i != nbp) rad->SetValue(i,y);
  }
  Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
  inter.Perform();
  SetCurve(inter.Curve()); 
#ifdef DEB
#ifdef DRAW
  if (Affich) {
    gp_Vec2d veve(0.,0.);
    Law_draw1dcurve(Curve(),veve,1.);
  }
#endif
#endif
}

//=======================================================================
//function : Set
//purpose  : 
//=======================================================================

void Law_Interpol::Set(const TColgp_Array1OfPnt2d& ParAndRad,
		       const Standard_Real Dd,
		       const Standard_Real Df,
		       const Standard_Boolean Periodic)
{
  Standard_Integer l = ParAndRad.Lower();
  Standard_Integer nbp = ParAndRad.Length();

  Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
  Handle(TColStd_HArray1OfReal) rad;
  if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
  else rad = new TColStd_HArray1OfReal(1,nbp);
  Standard_Real x,y;
  Standard_Integer i;
  for(i = 1; i <= nbp; i++){
    ParAndRad(l + i - 1).Coord(x,y);
    par->SetValue(i,x);
    if(!Periodic || i != nbp) rad->SetValue(i,y);
  }
  Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
  inter.Load(Dd,Df);
  inter.Perform();
  SetCurve(inter.Curve()); 
}

//=======================================================================
//function : SetInRelative
//purpose  : 
//=======================================================================

void Law_Interpol::SetInRelative(const TColgp_Array1OfPnt2d& ParAndRad,
				 const Standard_Real Ud,
				 const Standard_Real Uf,
				 const Standard_Real Dd,
				 const Standard_Real Df,
				 const Standard_Boolean Periodic)
{
  Standard_Integer l = ParAndRad.Lower(), u = ParAndRad.Upper();
  Standard_Real wd = ParAndRad(l).X(),wf = ParAndRad(u).X();
  Standard_Integer nbp = ParAndRad.Length();
  Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
  Handle(TColStd_HArray1OfReal) rad;
  if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
  else rad = new TColStd_HArray1OfReal(1,nbp);
  Standard_Real x,y;
  Standard_Integer i;
  for(i = 1; i <= nbp; i++){
    ParAndRad(l + i - 1).Coord(x,y);
    par->SetValue(i,(Uf*(x-wd)+Ud*(wf-x))/(wf-wd));
    if(!Periodic || i != nbp) rad->SetValue(i,y);
  }
  Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
  inter.Load(Dd,Df);
  inter.Perform();
  SetCurve(inter.Curve()); 
}