Test for 0022778: Bug in BRepMesh
[occt.git] / src / Law / Law_Interpol.cxx
CommitLineData
b311480e 1// Copyright (c) 1995-1999 Matra Datavision
2// Copyright (c) 1999-2012 OPEN CASCADE SAS
3//
4// The content of this file is subject to the Open CASCADE Technology Public
5// License Version 6.5 (the "License"). You may not use the content of this file
6// except in compliance with the License. Please obtain a copy of the License
7// at http://www.opencascade.org and read it completely before using this file.
8//
9// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
10// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11//
12// The Original Code and all software distributed under the License is
13// distributed on an "AS IS" basis, without warranty of any kind, and the
14// Initial Developer hereby disclaims all such warranties, including without
15// limitation, any warranties of merchantability, fitness for a particular
16// purpose or non-infringement. Please see the License for the specific terms
17// and conditions governing the rights and limitations under the License.
18
7fd59977 19// pmn -> modified 17/01/1996 : utilisation de Curve() et SetCurve()
20
21#include <Law_Interpol.ixx>
22#include <Precision.hxx>
23#include <TColStd_HArray1OfReal.hxx>
24#include <gp_Pnt2d.hxx>
25#include <gp_Vec2d.hxx>
26#include <Law_Interpolate.hxx>
27
28#ifdef DEB
29#ifdef DRAW
30
31// Pour le dessin.
32#include <Draw_Appli.hxx>
33#include <Draw_Display.hxx>
34#include <Draw.hxx>
35#include <Draw_Segment3D.hxx>
36#include <Draw_Segment2D.hxx>
37#include <Draw_Marker2D.hxx>
38#include <Draw_ColorKind.hxx>
39#include <Draw_MarkerShape.hxx>
40
41static void Law_draw1dcurve(const Handle(Law_BSpline)& bs,
42 const gp_Vec2d& tra,
43 const Standard_Real scal)
44{
45 TColStd_Array1OfReal pol(1,bs->NbPoles());
46 bs->Poles(pol);
47 TColStd_Array1OfReal knots(1,bs->NbKnots());
48 bs->Knots(knots);
49 TColStd_Array1OfInteger mults(1,bs->NbKnots());
50 bs->Multiplicities(mults);
51 Standard_Integer deg = bs->Degree();
52 Standard_Integer nbk = knots.Length();
53
54 Handle(Draw_Marker2D) mar;
55 gp_Pnt2d pp(knots(1),scal*bs->Value(knots(1)));
56 pp.Translate(tra);
57 gp_Pnt2d qq;
58 mar = new Draw_Marker2D(pp,Draw_Square,Draw_cyan);
59 dout<<mar;
60 Handle(Draw_Segment2D) seg;
61 for(Standard_Integer i = 1; i < nbk; i++){
62 Standard_Real f = knots(i);
63 Standard_Real l = knots(i+1);
64 for (Standard_Integer iu = 1; iu <= 30; iu++){
65 Standard_Real uu = iu/30.;
66 uu = f+uu*(l-f);
67 qq.SetCoord(uu,scal*bs->Value(uu));
68 qq.Translate(tra);
69 seg = new Draw_Segment2D(pp,qq,Draw_jaune);
70 dout<<seg;
71 pp = qq;
72 }
73 mar = new Draw_Marker2D(pp,Draw_Square,Draw_cyan);
74 dout<<mar;
75 }
76}
77
78static void Law_draw1dcurve(const TColStd_Array1OfReal& pol,
79 const TColStd_Array1OfReal& knots,
80 const TColStd_Array1OfInteger& mults,
81 const Standard_Integer deg,
82 const gp_Vec2d& tra,
83 const Standard_Real scal)
84{
85 Handle(Law_BSpline) bs = new Law_BSpline(pol,knots,mults,deg);
86 Law_draw1dcurve(bs,tra,scal);
87}
88
89static Standard_Boolean Affich = 0;
90
91#endif
92#endif
93
94//=======================================================================
95//function : Law_Interpol
96//purpose :
97//=======================================================================
98
99Law_Interpol::Law_Interpol()
100{
101}
102
103//=======================================================================
104//function : Set
105//purpose :
106//=======================================================================
107
108void Law_Interpol::Set(const TColgp_Array1OfPnt2d& ParAndRad,
109 const Standard_Boolean Periodic)
110{
111 Standard_Integer l = ParAndRad.Lower();
7fd59977 112 Standard_Integer nbp = ParAndRad.Length();
113
114 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
115 Handle(TColStd_HArray1OfReal) rad;
116 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
117 else rad = new TColStd_HArray1OfReal(1,nbp);
118 Standard_Real x,y;
119 Standard_Integer i;
120 for(i = 1; i <= nbp; i++){
121 ParAndRad(l + i - 1).Coord(x,y);
122 par->SetValue(i,x);
123 if(!Periodic || i != nbp) rad->SetValue(i,y);
124 }
125 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
126 inter.Perform();
127 SetCurve(inter.Curve());
128#ifdef DEB
129#ifdef DRAW
130 if (Affich) {
131 gp_Vec2d veve(0.,0.);
132 Law_draw1dcurve(Curve(),veve,1.);
133 }
134#endif
135#endif
136}
137
138//=======================================================================
139//function : SetInRelative
140//purpose :
141//=======================================================================
142
143void Law_Interpol::SetInRelative(const TColgp_Array1OfPnt2d& ParAndRad,
144 const Standard_Real Ud,
145 const Standard_Real Uf,
146 const Standard_Boolean Periodic)
147{
148 Standard_Integer l = ParAndRad.Lower(), u = ParAndRad.Upper();
149 Standard_Real wd = ParAndRad(l).X(),wf = ParAndRad(u).X();
150 Standard_Integer nbp = ParAndRad.Length();
151 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
152 Handle(TColStd_HArray1OfReal) rad;
153 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
154 else rad = new TColStd_HArray1OfReal(1,nbp);
155 Standard_Real x,y;
156 Standard_Integer i;
157 for(i = 1; i <= nbp; i++){
158 ParAndRad(l + i - 1).Coord(x,y);
159 par->SetValue(i,(Uf*(x-wd)+Ud*(wf-x))/(wf-wd));
160 if(!Periodic || i != nbp) rad->SetValue(i,y);
161 }
162 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
163 inter.Perform();
164 SetCurve(inter.Curve());
165#ifdef DEB
166#ifdef DRAW
167 if (Affich) {
168 gp_Vec2d veve(0.,0.);
169 Law_draw1dcurve(Curve(),veve,1.);
170 }
171#endif
172#endif
173}
174
175//=======================================================================
176//function : Set
177//purpose :
178//=======================================================================
179
180void Law_Interpol::Set(const TColgp_Array1OfPnt2d& ParAndRad,
181 const Standard_Real Dd,
182 const Standard_Real Df,
183 const Standard_Boolean Periodic)
184{
185 Standard_Integer l = ParAndRad.Lower();
7fd59977 186 Standard_Integer nbp = ParAndRad.Length();
187
188 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
189 Handle(TColStd_HArray1OfReal) rad;
190 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
191 else rad = new TColStd_HArray1OfReal(1,nbp);
192 Standard_Real x,y;
193 Standard_Integer i;
194 for(i = 1; i <= nbp; i++){
195 ParAndRad(l + i - 1).Coord(x,y);
196 par->SetValue(i,x);
197 if(!Periodic || i != nbp) rad->SetValue(i,y);
198 }
199 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
200 inter.Load(Dd,Df);
201 inter.Perform();
202 SetCurve(inter.Curve());
203}
204
205//=======================================================================
206//function : SetInRelative
207//purpose :
208//=======================================================================
209
210void Law_Interpol::SetInRelative(const TColgp_Array1OfPnt2d& ParAndRad,
211 const Standard_Real Ud,
212 const Standard_Real Uf,
213 const Standard_Real Dd,
214 const Standard_Real Df,
215 const Standard_Boolean Periodic)
216{
217 Standard_Integer l = ParAndRad.Lower(), u = ParAndRad.Upper();
218 Standard_Real wd = ParAndRad(l).X(),wf = ParAndRad(u).X();
219 Standard_Integer nbp = ParAndRad.Length();
220 Handle(TColStd_HArray1OfReal) par = new TColStd_HArray1OfReal(1,nbp);
221 Handle(TColStd_HArray1OfReal) rad;
222 if(Periodic) rad = new TColStd_HArray1OfReal(1,nbp - 1);
223 else rad = new TColStd_HArray1OfReal(1,nbp);
224 Standard_Real x,y;
225 Standard_Integer i;
226 for(i = 1; i <= nbp; i++){
227 ParAndRad(l + i - 1).Coord(x,y);
228 par->SetValue(i,(Uf*(x-wd)+Ud*(wf-x))/(wf-wd));
229 if(!Periodic || i != nbp) rad->SetValue(i,y);
230 }
231 Law_Interpolate inter(rad,par,Periodic,Precision::Confusion());
232 inter.Load(Dd,Df);
233 inter.Perform();
234 SetCurve(inter.Curve());
235}