0032951: Coding - get rid of unused headers [GeomConvert to IGESBasic]
[occt.git] / src / GeomFill / GeomFill_SweepFunction.cxx
1 // Created on: 1997-11-21
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef OCCT_DEBUG
18 #define No_Standard_RangeError
19 #define No_Standard_OutOfRange
20 #define No_Standard_DimensionError
21 #endif
22
23
24 #include <GeomFill_LocationLaw.hxx>
25 #include <GeomFill_SectionLaw.hxx>
26 #include <GeomFill_SweepFunction.hxx>
27 #include <GeomLib.hxx>
28 #include <gp_Pnt.hxx>
29 #include <Precision.hxx>
30 #include <Standard_Type.hxx>
31 #include <TColStd_SequenceOfReal.hxx>
32
33 IMPLEMENT_STANDARD_RTTIEXT(GeomFill_SweepFunction,Approx_SweepFunction)
34
35 //=======================================================================
36 //function : GeomFill_SweepFunction
37 //purpose  : 
38 //=======================================================================
39 GeomFill_SweepFunction::
40 GeomFill_SweepFunction(const Handle(GeomFill_SectionLaw)& Section,
41                        const Handle(GeomFill_LocationLaw)& Location,
42                        const Standard_Real  FirstParameter,
43                        const Standard_Real  FirstParameterOnS,
44                        const Standard_Real  RatioParameterOnS)
45 {
46   myLoc = Location;
47   mySec = Section;
48   myf = FirstParameter;
49   myfOnS = FirstParameterOnS;
50   myRatio =  RatioParameterOnS;
51 }
52
53 //=======================================================================
54 //function : D0
55 //purpose  : 
56 //=======================================================================
57 Standard_Boolean GeomFill_SweepFunction::D0(const Standard_Real Param,
58                                             const Standard_Real,
59                                             const Standard_Real,
60                                             TColgp_Array1OfPnt& Poles,
61                                             TColgp_Array1OfPnt2d& Poles2d,
62                                             TColStd_Array1OfReal& Weigths) 
63 {
64   Standard_Integer ii, L;
65   Standard_Boolean Ok;
66   Standard_Real T =  myfOnS + (Param - myf) * myRatio;
67   L = Poles.Length();
68
69   Ok = myLoc->D0(Param, M, V, Poles2d);
70   if (!Ok) return Ok;
71   Ok = mySec->D0(T, Poles, Weigths);
72   if (!Ok) return Ok;
73
74   for (ii=1; ii<=L; ii++) {
75     gp_XYZ& aux = Poles(ii).ChangeCoord();
76     aux *= M;
77     aux += V.XYZ();
78   }
79   return Standard_True;
80 }
81
82 //=======================================================================
83 //function : D1
84 //purpose  : 
85 //=======================================================================
86  Standard_Boolean GeomFill_SweepFunction::D1(const Standard_Real Param,
87                                              const Standard_Real,
88                                              const Standard_Real,
89                                              TColgp_Array1OfPnt& Poles,
90                                              TColgp_Array1OfVec& DPoles,
91                                              TColgp_Array1OfPnt2d& Poles2d,
92                                              TColgp_Array1OfVec2d& DPoles2d,
93                                              TColStd_Array1OfReal& Weigths,
94                                              TColStd_Array1OfReal& DWeigths) 
95 {
96   Standard_Integer ii, L;
97   Standard_Boolean Ok;
98   Standard_Real T =  myfOnS + (Param - myf) * myRatio;
99   gp_XYZ PPrim;
100   L = Poles.Length();
101
102   Ok = myLoc->D1(Param, M,  V, DM, DV, Poles2d, DPoles2d);
103   if (!Ok) return Ok;
104   Ok = mySec->D1(T, Poles, DPoles, Weigths, DWeigths);
105   if (!Ok) return Ok;
106
107   for (ii=1; ii<=L; ii++) {
108     PPrim = DPoles(ii).XYZ();
109     gp_XYZ& P = Poles(ii).ChangeCoord();
110     PPrim *= myRatio;
111     DWeigths(ii) *= myRatio;
112     PPrim *= M;
113     PPrim += DM*P;
114     PPrim += DV.XYZ();
115     DPoles(ii).SetXYZ(PPrim);
116    
117     P *= M;
118     P += V.XYZ();
119   }  
120   return Standard_True;
121 }
122
123 //=======================================================================
124 //function : D2
125 //purpose  : 
126 //=======================================================================
127  Standard_Boolean GeomFill_SweepFunction::D2(const Standard_Real Param,
128                                              const Standard_Real,
129                                              const Standard_Real ,
130                                              TColgp_Array1OfPnt& Poles,
131                                              TColgp_Array1OfVec& DPoles,
132                                              TColgp_Array1OfVec& D2Poles,
133                                              TColgp_Array1OfPnt2d& Poles2d,
134                                              TColgp_Array1OfVec2d& DPoles2d,
135                                              TColgp_Array1OfVec2d& D2Poles2d,
136                                              TColStd_Array1OfReal& Weigths,
137                                              TColStd_Array1OfReal& DWeigths,
138                                              TColStd_Array1OfReal& D2Weigths) 
139 {
140   Standard_Integer ii, L;
141   Standard_Boolean Ok;
142   Standard_Real T =  myfOnS + (Param - myf) * myRatio;
143   Standard_Real squareratio = myRatio*myRatio;
144   L = Poles.Length();
145
146   Ok = myLoc->D2(Param, M,  V, DM, DV, D2M, D2V, 
147                  Poles2d, DPoles2d, D2Poles2d);
148   if (!Ok) return Ok;
149   Ok = mySec->D2(T, Poles, DPoles, D2Poles, 
150                  Weigths, DWeigths, D2Weigths);
151   if (!Ok) return Ok;
152
153   for (ii=1; ii<=L; ii++) {
154     gp_XYZ PSecn = D2Poles(ii).XYZ();
155     gp_XYZ PPrim = DPoles(ii).XYZ();
156     PPrim *= myRatio;
157     DWeigths(ii) *= myRatio;
158     PSecn *= squareratio;
159     D2Weigths(ii) *= squareratio;
160     gp_XYZ& P = Poles(ii).ChangeCoord();
161
162     PSecn *= M;
163     PSecn += 2*(DM*PPrim);
164     PSecn += D2M*P;
165     PSecn += D2V.XYZ();
166     D2Poles(ii).SetXYZ(PSecn);
167
168     PPrim *= M;
169     PPrim += DM*P;
170     PPrim += DV.XYZ();
171     DPoles(ii).SetXYZ(PPrim);
172
173     P *= M;
174     P += V.XYZ();
175   } 
176    return Standard_True;
177 }
178
179 //=======================================================================
180 //function : Nb2dCurves
181 //purpose  : 
182 //=======================================================================
183  Standard_Integer GeomFill_SweepFunction::Nb2dCurves() const
184 {
185   return myLoc->Nb2dCurves();
186 }
187
188 //=======================================================================
189 //function : SectionShape
190 //purpose  : 
191 //=======================================================================
192  void GeomFill_SweepFunction::SectionShape(Standard_Integer& NbPoles,
193                                            Standard_Integer& NbKnots,
194                                            Standard_Integer& Degree) const
195 {
196   mySec->SectionShape(NbPoles, NbKnots, Degree); 
197 }
198
199 //=======================================================================
200 //function : Knots
201 //purpose  : 
202 //=======================================================================
203  void GeomFill_SweepFunction::Knots(TColStd_Array1OfReal& TKnots) const
204 {
205   mySec->Knots(TKnots);
206 }
207
208 //=======================================================================
209 //function : Mults
210 //purpose  : 
211 //=======================================================================
212  void GeomFill_SweepFunction::Mults(TColStd_Array1OfInteger& TMults) const
213 {
214  mySec->Mults(TMults);
215 }
216
217 //=======================================================================
218 //function : IsRational
219 //purpose  : 
220 //=======================================================================
221  Standard_Boolean GeomFill_SweepFunction::IsRational() const
222 {
223  return mySec->IsRational();
224 }
225
226 //=======================================================================
227 //function : NbIntervals
228 //purpose  : 
229 //=======================================================================
230  Standard_Integer GeomFill_SweepFunction::NbIntervals(const GeomAbs_Shape S) const
231 {
232   Standard_Integer Nb_Sec, Nb_Loc;
233   Nb_Sec  =  mySec->NbIntervals(S);
234   Nb_Loc  =  myLoc->NbIntervals(S);
235
236   if  (Nb_Sec==1) {
237     return Nb_Loc;
238   }
239   else if (Nb_Loc==1) {
240     return Nb_Sec;
241   }
242
243   TColStd_Array1OfReal IntS(1, Nb_Sec+1);
244   TColStd_Array1OfReal IntL(1, Nb_Loc+1);
245   TColStd_SequenceOfReal    Inter;
246   Standard_Real T;
247   Standard_Integer ii;
248   mySec->Intervals(IntS, S);
249   for (ii=1; ii<=Nb_Sec+1; ii++) {
250     T = (IntS(ii) - myfOnS) / myRatio +  myf;
251     IntS(ii) = T;
252   }
253   myLoc->Intervals(IntL, S);
254
255   GeomLib::FuseIntervals( IntS, IntL, Inter, Precision::PConfusion()*0.99);
256   return Inter.Length()-1; 
257 }
258
259 //=======================================================================
260 //function : Intervals
261 //purpose  : 
262 //=======================================================================
263  void GeomFill_SweepFunction::Intervals(TColStd_Array1OfReal& T,const GeomAbs_Shape S) const
264 {
265   Standard_Integer Nb_Sec, Nb_Loc, ii;
266   Nb_Sec  =  mySec->NbIntervals(S);
267   Nb_Loc  =  myLoc->NbIntervals(S);
268
269   if  (Nb_Sec==1) {
270     myLoc->Intervals(T, S);
271     return;
272   }
273   else if (Nb_Loc==1) {
274     Standard_Real t;
275     mySec->Intervals(T, S);
276     for (ii=1; ii<=Nb_Sec+1; ii++) {
277       t = (T(ii) - myfOnS) / myRatio +  myf;
278       T(ii) = t;
279     }
280     return;
281   }
282
283   TColStd_Array1OfReal IntS(1, Nb_Sec+1);
284   TColStd_Array1OfReal IntL(1, Nb_Loc+1);
285   TColStd_SequenceOfReal    Inter;
286   Standard_Real t;
287
288   mySec->Intervals(IntS, S);
289   for (ii=1; ii<=Nb_Sec+1; ii++) {
290     t = (IntS(ii) - myfOnS) / myRatio +  myf;
291     IntS(ii) = t;
292   }
293   myLoc->Intervals(IntL, S);
294
295   GeomLib::FuseIntervals(IntS, IntL, Inter, Precision::PConfusion()*0.99);
296   for (ii=1; ii<=Inter.Length(); ii++)
297     T(ii) = Inter(ii);
298 }
299
300 //=======================================================================
301 //function : SetInterval
302 //purpose  : 
303 //=======================================================================
304  void GeomFill_SweepFunction::SetInterval(const Standard_Real First,
305                                           const Standard_Real Last) 
306 {
307   Standard_Real uf, ul;
308   myLoc->SetInterval(First, Last);
309   uf = myf + (First - myf) * myRatio;
310   ul = myf + (Last  - myf) * myRatio;
311   mySec->SetInterval(uf, ul);
312 }
313
314 //=======================================================================
315 //function :
316 //purpose  : 
317 //=======================================================================
318  void GeomFill_SweepFunction::GetTolerance(const Standard_Real BoundTol,
319                                            const Standard_Real SurfTol,
320                                            const Standard_Real AngleTol,
321                                            TColStd_Array1OfReal& Tol3d) const
322 {
323   mySec->GetTolerance( BoundTol, SurfTol, AngleTol, Tol3d);
324 }
325
326
327 //=======================================================================
328 //function : Resolution
329 //purpose  : 
330 //=======================================================================
331 void GeomFill_SweepFunction::Resolution(const Standard_Integer Index,
332                                         const Standard_Real Tol,
333                                         Standard_Real& TolU,
334                                         Standard_Real& TolV)const
335 {
336  myLoc->Resolution(Index, Tol, TolU, TolV);
337 }
338
339 //=======================================================================
340 //function :
341 //purpose  : 
342 //=======================================================================
343  void GeomFill_SweepFunction::SetTolerance(const Standard_Real Tol3d,
344                                            const Standard_Real Tol2d) 
345 {
346   mySec->SetTolerance(Tol3d, Tol2d);
347   myLoc->SetTolerance(Tol3d, Tol2d);
348 }
349
350 //=======================================================================
351 //function :
352 //purpose  : 
353 //=======================================================================
354  gp_Pnt GeomFill_SweepFunction::BarycentreOfSurf() const
355 {
356   gp_Pnt Bary;
357   gp_Vec Translate;
358   gp_Mat aM;
359
360   Bary =  mySec->BarycentreOfSurf();
361   myLoc->GetAverageLaw(aM, Translate);
362   Bary.ChangeCoord() *= aM;
363   Bary.ChangeCoord() += Translate.XYZ();
364
365   return Bary;
366 }
367
368 //=======================================================================
369 //function :
370 //purpose  : 
371 //=======================================================================
372  Standard_Real GeomFill_SweepFunction::MaximalSection() const
373 {
374   Standard_Real L =  mySec->MaximalSection();
375   L *= myLoc->GetMaximalNorm();
376   return L;
377 }
378
379 //=======================================================================
380 //function :
381 //purpose  : 
382 //=======================================================================
383  void GeomFill_SweepFunction::GetMinimalWeight(TColStd_Array1OfReal& Weigths) const
384 {
385   mySec->GetMinimalWeight(Weigths);
386 }
387
388
389
390
391
392
393
394
395
396
397
398
399