b311480e |
1 | // Created by: Stephanie HUMEAU |
2 | // Copyright (c) 1998-1999 Matra Datavision |
973c2be1 |
3 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
b311480e |
15 | |
7fd59977 |
16 | // Creted: Tue Jun 23 15:39:24 1998 |
7fd59977 |
17 | |
7fd59977 |
18 | #include <Adaptor3d_Curve.hxx> |
42cf5bc1 |
19 | #include <Adaptor3d_HCurve.hxx> |
20 | #include <Approx_CurvlinFunc.hxx> |
7fd59977 |
21 | #include <GeomAdaptor.hxx> |
22 | #include <GeomAdaptor_HCurve.hxx> |
7fd59977 |
23 | #include <GeomFill_Frenet.hxx> |
42cf5bc1 |
24 | #include <GeomFill_GuideTrihedronAC.hxx> |
25 | #include <GeomFill_TrihedronLaw.hxx> |
7fd59977 |
26 | #include <GeomLib.hxx> |
42cf5bc1 |
27 | #include <gp_Dir.hxx> |
28 | #include <gp_Pnt.hxx> |
29 | #include <gp_Vec.hxx> |
30 | #include <Precision.hxx> |
31 | #include <Standard_ConstructionError.hxx> |
32 | #include <Standard_OutOfRange.hxx> |
33 | #include <Standard_Type.hxx> |
34 | #include <TColStd_SequenceOfReal.hxx> |
7fd59977 |
35 | |
36 | //======================================================================= |
37 | //function : GuideTrihedron |
38 | //purpose : Constructor |
39 | //======================================================================= |
b311480e |
40 | GeomFill_GuideTrihedronAC::GeomFill_GuideTrihedronAC(const Handle(Adaptor3d_HCurve) & guide) |
7fd59977 |
41 | { |
42 | myCurve.Nullify(); |
43 | myGuide = guide; |
44 | myTrimG = guide; |
45 | myGuideAC = new (Approx_CurvlinFunc) (myGuide,1.e-7); |
46 | Lguide = myGuideAC->GetLength(); |
47 | UTol = STol = Precision::PConfusion(); |
48 | Orig1 = 0; // origines pour le cas path multi-edges |
49 | Orig2 = 1; |
50 | } |
51 | |
52 | //======================================================================= |
53 | //function : Guide |
54 | //purpose : calculation of trihedron |
55 | //======================================================================= |
56 | |
57 | Handle(Adaptor3d_HCurve) GeomFill_GuideTrihedronAC::Guide()const |
58 | { |
59 | return myGuide; |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : D0 |
64 | //purpose : calculation of trihedron |
65 | //======================================================================= |
66 | Standard_Boolean GeomFill_GuideTrihedronAC::D0(const Standard_Real Param, |
67 | gp_Vec& Tangent, |
68 | gp_Vec& Normal, |
69 | gp_Vec& BiNormal) |
70 | { |
71 | Standard_Real s = myCurveAC->GetSParameter(Param); // abscisse curviligne <=> Param |
72 | Standard_Real OrigG = Orig1 + s*(Orig2-Orig1); // abscisse curv sur le guide (cas multi-edges) |
73 | Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1); // param <=> s sur theGuide |
74 | |
75 | gp_Pnt P, PG; |
76 | gp_Vec To, B; |
77 | myTrimmed->D1(Param, P, To);//point et derivee au parametre Param sur myCurve |
78 | myTrimG->D0(tG, PG);// point au parametre tG sur myGuide |
f9032cf2 |
79 | myCurPointOnGuide = PG; |
7fd59977 |
80 | |
81 | gp_Vec n (P, PG); // vecteur definissant la normale |
82 | |
83 | Normal = n.Normalized(); |
84 | B = To.Crossed(Normal); |
85 | BiNormal = B/B.Magnitude(); |
86 | Tangent = Normal.Crossed(BiNormal); |
87 | Tangent.Normalize(); |
88 | |
89 | return Standard_True; |
90 | } |
91 | |
92 | //======================================================================= |
93 | //function : D1 |
94 | //purpose : calculation of trihedron and first derivative |
95 | //======================================================================= |
96 | Standard_Boolean GeomFill_GuideTrihedronAC::D1(const Standard_Real Param, |
97 | gp_Vec& Tangent, |
98 | gp_Vec& DTangent, |
99 | gp_Vec& Normal, |
100 | gp_Vec& DNormal, |
101 | gp_Vec& BiNormal, |
102 | gp_Vec& DBiNormal) |
103 | { |
104 | //triedre |
105 | Standard_Real s, OrigG, tG, dtg; |
106 | // abscisse curviligne <=> Param |
107 | s = myCurveAC->GetSParameter(Param); |
108 | // parametre <=> s sur theGuide |
109 | OrigG = Orig1 + s*(Orig2-Orig1); |
110 | // parametre <=> s sur theGuide |
111 | tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1); |
112 | |
113 | gp_Pnt P, PG; |
114 | gp_Vec To, DTo, TG, B, BPrim; |
115 | |
116 | myTrimmed->D2(Param, P, To, DTo); |
117 | myTrimG->D1(tG, PG, TG); |
f9032cf2 |
118 | myCurPointOnGuide = PG; |
7fd59977 |
119 | |
120 | gp_Vec n (P, PG), dn; |
121 | Standard_Real Norm = n.Magnitude(); |
122 | if (Norm < 1.e-12) { |
123 | Norm = 1; |
0797d9d3 |
124 | #ifdef OCCT_DEBUG |
7fd59977 |
125 | cout << "GuideTrihedronAC : Normal indefinie" << endl; |
126 | #endif |
127 | } |
128 | |
129 | n /= Norm; |
130 | //derivee de n par rapport a Param |
131 | dtg = (Orig2-Orig1)*(To.Magnitude()/TG.Magnitude())*(Lguide/L); |
132 | dn.SetLinearForm(dtg, TG, -1, To); |
133 | dn /= Norm; |
134 | |
135 | // triedre |
136 | Normal = n; |
137 | B = To.Crossed(Normal); |
138 | Standard_Real NormB = B.Magnitude(); |
139 | B/= NormB; |
140 | |
141 | BiNormal = B; |
142 | |
143 | Tangent = Normal.Crossed(BiNormal); |
144 | Tangent.Normalize(); |
145 | |
146 | // derivee premiere |
147 | DNormal.SetLinearForm(-(n.Dot(dn)), n, dn); |
148 | |
149 | BPrim.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal)); |
150 | |
151 | DBiNormal.SetLinearForm(-(B.Dot(BPrim)), B, BPrim); |
152 | DBiNormal /= NormB; |
153 | |
154 | DTangent.SetLinearForm(Normal.Crossed(DBiNormal), DNormal.Crossed(BiNormal)); |
155 | |
156 | return Standard_True; |
157 | } |
158 | |
159 | |
160 | //======================================================================= |
161 | //function : D2 |
162 | //purpose : calculation of trihedron and derivatives |
163 | //======================================================================= |
164 | Standard_Boolean GeomFill_GuideTrihedronAC::D2(const Standard_Real Param, |
165 | gp_Vec& Tangent, |
166 | gp_Vec& DTangent, |
167 | gp_Vec& D2Tangent, |
168 | gp_Vec& Normal, |
169 | gp_Vec& DNormal, |
170 | gp_Vec& D2Normal, |
171 | gp_Vec& BiNormal, |
172 | gp_Vec& DBiNormal, |
173 | gp_Vec& D2BiNormal) |
174 | { |
175 | // abscisse curviligne <=> Param |
176 | Standard_Real s = myCurveAC->GetSParameter(Param); |
177 | // parametre <=> s sur theGuide |
178 | Standard_Real OrigG = Orig1 + s*(Orig2-Orig1); |
179 | Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(), |
180 | OrigG, 1); |
181 | |
182 | gp_Pnt P,PG; |
183 | gp_Vec TG,DTG; |
184 | // gp_Vec To,DTo,D2To,B; |
185 | gp_Vec To,DTo,D2To; |
186 | |
187 | myTrimmed->D3(Param, P, To, DTo, D2To); |
188 | myTrimG->D2(tG, PG, TG, DTG); |
f9032cf2 |
189 | myCurPointOnGuide = PG; |
7fd59977 |
190 | |
191 | Standard_Real NTo = To.Magnitude(); |
192 | Standard_Real N2To = To.SquareMagnitude(); |
193 | Standard_Real NTG = TG.Magnitude(); |
194 | Standard_Real N2Tp = TG.SquareMagnitude(); |
195 | Standard_Real d2tp_dt2, dtg_dt; |
196 | dtg_dt = (Orig2-Orig1)*(NTo/NTG)*(Lguide/L); |
197 | |
198 | gp_Vec n(P, PG); // vecteur definissant la normale |
199 | Standard_Real Norm = n.Magnitude(), ndn; |
7fd59977 |
200 | //derivee de n par rapport a Param |
201 | gp_Vec dn, d2n; |
202 | dn.SetLinearForm(dtg_dt, TG, -1, To); |
203 | |
204 | //derivee seconde de tG par rapport a Param |
205 | d2tp_dt2 = (Orig2-Orig1)*(Lguide/L) * |
206 | ( DTo.Dot(To) / (NTo*NTG) - N2To*TG*DTG*(Lguide/L) / (N2Tp*N2Tp)); |
207 | //derivee seconde de n par rapport a Param |
208 | d2n.SetLinearForm(dtg_dt*dtg_dt,DTG, d2tp_dt2, TG, -1, DTo); |
209 | |
210 | if (Norm > 1.e-9) { |
211 | n /= Norm; |
212 | dn /= Norm; |
213 | d2n /= Norm; |
214 | } |
215 | //triedre |
216 | Normal = n; |
217 | |
218 | gp_Vec TN, DTN, D2TN; |
219 | TN = To.Crossed(Normal); |
220 | |
221 | |
222 | Standard_Real Norma = TN.Magnitude(); |
223 | if (Norma > 1.e-9) TN /= Norma; |
224 | |
225 | BiNormal = TN; |
226 | |
227 | Tangent = Normal.Crossed(BiNormal); |
228 | // Tangent.Normalize(); |
229 | |
230 | // derivee premiere du triedre |
231 | // gp_Vec DTN = DTo.Crossed(Normal); |
232 | // gp_Vec TDN = To.Crossed(DNormal); |
233 | // gp_Vec DT = DTN + TDN; |
234 | |
235 | ndn = n.Dot(dn); |
236 | DNormal.SetLinearForm(-ndn, n, dn); |
237 | |
238 | DTN.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal)); |
239 | DTN /= Norma; |
240 | Standard_Real TNDTN = TN.Dot(DTN); |
241 | |
242 | DBiNormal.SetLinearForm(-TNDTN, TN, DTN); |
243 | |
244 | DTangent.SetLinearForm(Normal.Crossed(DBiNormal), |
245 | DNormal.Crossed(BiNormal)); |
246 | |
247 | |
248 | //derivee seconde du triedre |
0797d9d3 |
249 | #ifdef OCCT_DEBUG |
76363522 |
250 | gp_Vec DTDN = DTo.Crossed(DNormal); (void)DTDN; |
7fd59977 |
251 | #endif |
252 | Standard_Real TN2 = TN.SquareMagnitude(); |
253 | |
254 | D2Normal.SetLinearForm(-2*ndn, dn, |
255 | 3*ndn*ndn - (dn.SquareMagnitude() + n.Dot(d2n)),n, |
256 | d2n); |
257 | |
258 | |
259 | D2TN.SetLinearForm(1, D2To.Crossed(Normal), |
260 | 2, DTo.Crossed(DNormal), |
261 | To.Crossed(D2Normal)); |
262 | D2TN /= Norma; |
263 | |
264 | D2BiNormal.SetLinearForm(-2*TNDTN, DTN, |
265 | 3*TNDTN*TNDTN - (TN2 + TN.Dot(D2TN)), TN, |
266 | D2TN); |
267 | |
268 | D2Tangent.SetLinearForm(1, D2Normal.Crossed(BiNormal), |
269 | 2, DNormal.Crossed(DBiNormal), |
270 | Normal.Crossed(D2BiNormal) ); |
271 | |
272 | // return Standard_True; |
273 | return Standard_False; |
274 | |
275 | } |
276 | |
277 | |
278 | //======================================================================= |
279 | //function : Copy |
280 | //purpose : |
281 | //======================================================================= |
282 | Handle(GeomFill_TrihedronLaw) GeomFill_GuideTrihedronAC::Copy() const |
283 | { |
284 | Handle(GeomFill_GuideTrihedronAC) copy = |
285 | new (GeomFill_GuideTrihedronAC) (myGuide); |
286 | copy->SetCurve(myCurve); |
287 | copy->Origine(Orig1,Orig2); |
288 | return copy; |
289 | } |
290 | |
291 | //======================================================================= |
292 | //function : SetCurve |
293 | //purpose : |
294 | //======================================================================= |
295 | void GeomFill_GuideTrihedronAC::SetCurve(const Handle(Adaptor3d_HCurve)& C) |
296 | { |
297 | myCurve = C; |
298 | myTrimmed = C; |
299 | if (!myCurve.IsNull()) { |
300 | myCurveAC = new (Approx_CurvlinFunc) (C,1.e-7); |
301 | L = myCurveAC->GetLength(); |
302 | // CorrectOrient(myGuide); |
303 | } |
304 | } |
305 | |
306 | |
307 | //======================================================================= |
308 | //function : NbIntervals |
309 | //purpose : |
310 | //======================================================================= |
311 | Standard_Integer GeomFill_GuideTrihedronAC::NbIntervals(const GeomAbs_Shape S) const |
312 | { |
313 | Standard_Integer Nb; |
314 | Nb = myCurveAC->NbIntervals(S); |
315 | TColStd_Array1OfReal DiscC(1, Nb+1); |
316 | myCurveAC->Intervals(DiscC, S); |
317 | Nb = myGuideAC->NbIntervals(S); |
318 | TColStd_Array1OfReal DiscG(1, Nb+1); |
319 | myGuideAC->Intervals(DiscG, S); |
320 | |
321 | TColStd_SequenceOfReal Seq; |
322 | GeomLib::FuseIntervals(DiscC, DiscG, Seq); |
323 | |
324 | return Seq.Length()-1; |
325 | |
326 | } |
327 | |
328 | //====================================================================== |
329 | //function :Intervals |
330 | //purpose : |
331 | //======================================================================= |
332 | void GeomFill_GuideTrihedronAC::Intervals(TColStd_Array1OfReal& TT, |
333 | const GeomAbs_Shape S) const |
334 | { |
335 | Standard_Integer Nb, ii; |
336 | Nb = myCurveAC->NbIntervals(S); |
337 | TColStd_Array1OfReal DiscC(1, Nb+1); |
338 | myCurveAC->Intervals(DiscC, S); |
339 | Nb = myGuideAC->NbIntervals(S); |
340 | TColStd_Array1OfReal DiscG(1, Nb+1); |
341 | myGuideAC->Intervals(DiscG, S); |
342 | |
343 | TColStd_SequenceOfReal Seq; |
344 | GeomLib::FuseIntervals(DiscC, DiscG, Seq); |
345 | Nb = Seq.Length(); |
346 | |
347 | for (ii=1; ii<=Nb; ii++) { |
348 | TT(ii) = myCurveAC->GetUParameter(myCurve->GetCurve(), Seq(ii), 1); |
349 | } |
350 | |
351 | } |
352 | |
353 | //====================================================================== |
354 | //function :SetInterval |
355 | //purpose : |
356 | //======================================================================= |
357 | void GeomFill_GuideTrihedronAC::SetInterval(const Standard_Real First, |
358 | const Standard_Real Last) |
359 | { |
360 | myTrimmed = myCurve->Trim(First, Last, UTol); |
361 | Standard_Real Sf, Sl, U; |
362 | |
363 | Sf = myCurveAC->GetSParameter(First); |
364 | Sl = myCurveAC->GetSParameter(Last); |
365 | // if (Sl>1) Sl=1; |
366 | // myCurveAC->Trim(Sf, Sl, UTol); |
367 | |
368 | U = Orig1 + Sf*(Orig2-Orig1); |
369 | Sf = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1); |
370 | U = Orig1 + Sl*(Orig2-Orig1); |
371 | Sl = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1); |
372 | myTrimG = myGuide->Trim(Sf, Sl, UTol); |
373 | } |
374 | |
375 | |
376 | |
377 | //======================================================================= |
378 | //function : GetAverageLaw |
379 | //purpose : |
380 | //======================================================================= |
381 | void GeomFill_GuideTrihedronAC::GetAverageLaw(gp_Vec& ATangent, |
382 | gp_Vec& ANormal, |
383 | gp_Vec& ABiNormal) |
384 | { |
385 | Standard_Integer ii; |
386 | Standard_Real t, Delta = (myCurve->LastParameter() - |
387 | myCurve->FirstParameter())/20.001; |
388 | |
389 | ATangent.SetCoord(0.,0.,0.); |
390 | ANormal.SetCoord(0.,0.,0.); |
391 | ABiNormal.SetCoord(0.,0.,0.); |
392 | gp_Vec T, N, B; |
393 | |
b6abaec0 |
394 | for (ii=1; ii<=20; ii++) { |
7fd59977 |
395 | t = myCurve->FirstParameter() +(ii-1)*Delta; |
396 | D0(t, T, N, B); |
397 | ATangent +=T; |
398 | ANormal +=N; |
399 | ABiNormal+=B; |
400 | } |
401 | ATangent /= 20; |
402 | ANormal /= 20; |
403 | ABiNormal /= 20; |
404 | } |
405 | |
406 | //======================================================================= |
407 | //function : IsConstant |
408 | //purpose : |
409 | //======================================================================= |
410 | Standard_Boolean GeomFill_GuideTrihedronAC::IsConstant() const |
411 | { |
412 | return Standard_False; |
413 | } |
414 | |
415 | //======================================================================= |
416 | //function : IsOnlyBy3dCurve |
417 | //purpose : |
418 | //======================================================================= |
419 | Standard_Boolean GeomFill_GuideTrihedronAC::IsOnlyBy3dCurve() const |
420 | { |
421 | return Standard_False; |
422 | } |
423 | |
424 | //======================================================================= |
425 | //function : Origine |
426 | //purpose : |
427 | //======================================================================= |
428 | void GeomFill_GuideTrihedronAC::Origine(const Standard_Real OrACR1, |
429 | const Standard_Real OrACR2) |
430 | { |
431 | Orig1 = OrACR1; |
432 | Orig2 = OrACR2; |
433 | } |