1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 // pmn -> modified 17/01/1996 : utilisation de Curve() et SetCurve()
17 #include <Law_Interpol.ixx>
18 #include <Precision.hxx>
19 #include <TColStd_HArray1OfReal.hxx>
20 #include <gp_Pnt2d.hxx>
21 #include <gp_Vec2d.hxx>
22 #include <Law_Interpolate.hxx>
28 #include <Draw_Appli.hxx>
29 #include <Draw_Display.hxx>
31 #include <Draw_Segment3D.hxx>
32 #include <Draw_Segment2D.hxx>
33 #include <Draw_Marker2D.hxx>
34 #include <Draw_ColorKind.hxx>
35 #include <Draw_MarkerShape.hxx>
37 static void Law_draw1dcurve(const Handle(Law_BSpline)& bs,
39 const Standard_Real scal)
41 TColStd_Array1OfReal pol(1,bs->NbPoles());
43 TColStd_Array1OfReal knots(1,bs->NbKnots());
45 TColStd_Array1OfInteger mults(1,bs->NbKnots());
46 bs->Multiplicities(mults);
47 Standard_Integer deg = bs->Degree();
48 Standard_Integer nbk = knots.Length();
50 Handle(Draw_Marker2D) mar;
51 gp_Pnt2d pp(knots(1),scal*bs->Value(knots(1)));
54 mar = new Draw_Marker2D(pp,Draw_Square,Draw_cyan);
56 Handle(Draw_Segment2D) seg;
57 for(Standard_Integer i = 1; i < nbk; i++){
58 Standard_Real f = knots(i);
59 Standard_Real l = knots(i+1);
60 for (Standard_Integer iu = 1; iu <= 30; iu++){
61 Standard_Real uu = iu/30.;
63 qq.SetCoord(uu,scal*bs->Value(uu));
65 seg = new Draw_Segment2D(pp,qq,Draw_jaune);
69 mar = new Draw_Marker2D(pp,Draw_Square,Draw_cyan);
74 static void Law_draw1dcurve(const TColStd_Array1OfReal& pol,
75 const TColStd_Array1OfReal& knots,
76 const TColStd_Array1OfInteger& mults,
77 const Standard_Integer deg,
79 const Standard_Real scal)
81 Handle(Law_BSpline) bs = new Law_BSpline(pol,knots,mults,deg);
82 Law_draw1dcurve(bs,tra,scal);
85 static Standard_Boolean Affich = 0;
90 //=======================================================================
91 //function : Law_Interpol
93 //=======================================================================
95 Law_Interpol::Law_Interpol()
99 //=======================================================================
102 //=======================================================================
104 void Law_Interpol::Set(const TColgp_Array1OfPnt2d& ParAndRad,
105 const Standard_Boolean Periodic)
107 Standard_Integer l = ParAndRad.Lower();
108 Standard_Integer nbp = ParAndRad.Length();
110 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
111 Handle(TColStd_HArray1OfReal) rad;
112 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
113 else rad = new TColStd_HArray1OfReal(1,nbp);
116 for(i = 1; i <= nbp; i++){
117 ParAndRad(l + i - 1).Coord(x,y);
119 if(!Periodic || i != nbp) rad->SetValue(i,y);
121 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
123 SetCurve(inter.Curve());
127 gp_Vec2d veve(0.,0.);
128 Law_draw1dcurve(Curve(),veve,1.);
134 //=======================================================================
135 //function : SetInRelative
137 //=======================================================================
139 void Law_Interpol::SetInRelative(const TColgp_Array1OfPnt2d& ParAndRad,
140 const Standard_Real Ud,
141 const Standard_Real Uf,
142 const Standard_Boolean Periodic)
144 Standard_Integer l = ParAndRad.Lower(), u = ParAndRad.Upper();
145 Standard_Real wd = ParAndRad(l).X(),wf = ParAndRad(u).X();
146 Standard_Integer nbp = ParAndRad.Length();
147 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
148 Handle(TColStd_HArray1OfReal) rad;
149 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
150 else rad = new TColStd_HArray1OfReal(1,nbp);
153 for(i = 1; i <= nbp; i++){
154 ParAndRad(l + i - 1).Coord(x,y);
155 par->SetValue(i,(Uf*(x-wd)+Ud*(wf-x))/(wf-wd));
156 if(!Periodic || i != nbp) rad->SetValue(i,y);
158 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
160 SetCurve(inter.Curve());
164 gp_Vec2d veve(0.,0.);
165 Law_draw1dcurve(Curve(),veve,1.);
171 //=======================================================================
174 //=======================================================================
176 void Law_Interpol::Set(const TColgp_Array1OfPnt2d& ParAndRad,
177 const Standard_Real Dd,
178 const Standard_Real Df,
179 const Standard_Boolean Periodic)
181 Standard_Integer l = ParAndRad.Lower();
182 Standard_Integer nbp = ParAndRad.Length();
184 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
185 Handle(TColStd_HArray1OfReal) rad;
186 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
187 else rad = new TColStd_HArray1OfReal(1,nbp);
190 for(i = 1; i <= nbp; i++){
191 ParAndRad(l + i - 1).Coord(x,y);
193 if(!Periodic || i != nbp) rad->SetValue(i,y);
195 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
198 SetCurve(inter.Curve());
201 //=======================================================================
202 //function : SetInRelative
204 //=======================================================================
206 void Law_Interpol::SetInRelative(const TColgp_Array1OfPnt2d& ParAndRad,
207 const Standard_Real Ud,
208 const Standard_Real Uf,
209 const Standard_Real Dd,
210 const Standard_Real Df,
211 const Standard_Boolean Periodic)
213 Standard_Integer l = ParAndRad.Lower(), u = ParAndRad.Upper();
214 Standard_Real wd = ParAndRad(l).X(),wf = ParAndRad(u).X();
215 Standard_Integer nbp = ParAndRad.Length();
216 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
217 Handle(TColStd_HArray1OfReal) rad;
218 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
219 else rad = new TColStd_HArray1OfReal(1,nbp);
222 for(i = 1; i <= nbp; i++){
223 ParAndRad(l + i - 1).Coord(x,y);
224 par->SetValue(i,(Uf*(x-wd)+Ud*(wf-x))/(wf-wd));
225 if(!Periodic || i != nbp) rad->SetValue(i,y);
227 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
230 SetCurve(inter.Curve());