b311480e |
1 | // Created on: 1993-08-12 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | // PMN : Ajout de la commande smooth |
18 | // PMN : 11/07/97 Passage a GeomliteTest de bsmooth. |
19 | |
20 | #include <Standard_Stream.hxx> |
21 | |
22 | #include <GeomliteTest.hxx> |
23 | #include <DrawTrSurf.hxx> |
24 | #include <Draw.hxx> |
25 | #include <Draw_Appli.hxx> |
26 | #include <Draw_Interpretor.hxx> |
27 | #include <Precision.hxx> |
28 | #include <Draw_Marker3D.hxx> |
29 | #include <Draw_Marker2D.hxx> |
30 | #include <TColgp_HArray1OfPnt.hxx> |
31 | #include <TColgp_SequenceOfPnt.hxx> |
32 | #include <Geom_BSplineCurve.hxx> |
33 | #include <Geom_BezierCurve.hxx> |
34 | #include <TColgp_HArray1OfPnt2d.hxx> |
35 | #include <TColgp_SequenceOfPnt2d.hxx> |
36 | |
37 | #include <Geom2d_BSplineCurve.hxx> |
38 | #include <Geom2d_BezierCurve.hxx> |
39 | #include <DrawTrSurf_BSplineCurve.hxx> |
40 | #include <DrawTrSurf_BezierCurve.hxx> |
41 | #include <DrawTrSurf_BSplineCurve2d.hxx> |
42 | #include <DrawTrSurf_BezierCurve2d.hxx> |
43 | #include <TColgp_HArray1OfPnt.hxx> |
44 | #include <TColgp_Array1OfPnt.hxx> |
45 | #include <TColgp_Array1OfPnt2d.hxx> |
46 | #include <TColgp_HArray1OfVec.hxx> |
47 | #include <TColgp_Array1OfVec.hxx> |
48 | #include <TColStd_Array1OfReal.hxx> |
49 | #include <TColStd_HArray1OfReal.hxx> |
50 | #include <TColStd_HArray1OfBoolean.hxx> |
7fd59977 |
51 | |
52 | #include <AppParCurves_MultiBSpCurve.hxx> |
53 | #include <AppParCurves_MultiCurve.hxx> |
54 | #include <AppDef_MultiLine.hxx> |
f62de372 |
55 | #include <AppDef_Variational.hxx> |
7fd59977 |
56 | #include <AppDef_Compute.hxx> |
57 | #include <AppParCurves_HArray1OfConstraintCouple.hxx> |
58 | #include <AppParCurves_ConstraintCouple.hxx> |
59 | #include <AppDef_HArray1OfMultiPointConstraint.hxx> |
60 | #include <AppDef_Array1OfMultiPointConstraint.hxx> |
61 | #include <math_Vector.hxx> |
62 | |
63 | #ifdef WNT |
64 | #include <stdio.h> |
65 | Standard_IMPORT Draw_Viewer dout; |
66 | #endif |
67 | |
68 | //Draw_Color DrawTrSurf_CurveColor(const Draw_Color); |
69 | |
70 | //======================================================================= |
71 | //function : NbConstraint |
72 | //======================================================================= |
73 | static Standard_Integer NbConstraint(const AppParCurves_Constraint C1, |
74 | const AppParCurves_Constraint C2) |
75 | { |
76 | Standard_Integer N =0; |
77 | switch (C1) { |
78 | case AppParCurves_PassPoint : |
79 | { |
80 | N = 1; |
81 | break; |
82 | } |
83 | case AppParCurves_TangencyPoint : |
84 | { |
85 | N =2; |
86 | break; |
87 | } |
88 | case AppParCurves_CurvaturePoint : |
89 | { |
90 | N = 3; |
91 | break; |
92 | } |
7fd59977 |
93 | default: |
94 | break; |
7fd59977 |
95 | } |
96 | |
97 | switch (C2) { |
98 | case AppParCurves_PassPoint : |
99 | { |
100 | N++; |
101 | break; |
102 | } |
103 | case AppParCurves_TangencyPoint : |
104 | { |
105 | N += 2; |
106 | break; |
107 | } |
108 | case AppParCurves_CurvaturePoint : |
109 | { |
110 | N += 3; |
111 | break; |
112 | } |
7fd59977 |
113 | default: |
114 | break; |
7fd59977 |
115 | } |
116 | return N; |
117 | } |
118 | //======================================================================= |
119 | //function : PointsByPick |
120 | //======================================================================= |
121 | static Standard_Integer PointsByPick |
122 | (Handle(AppDef_HArray1OfMultiPointConstraint)& MPC, Draw_Interpretor& di) |
123 | { |
124 | Standard_Integer id,XX,YY,b, i; |
125 | |
126 | di << "Pick points "<< "\n"; |
127 | dout.Select(id, XX, YY, b); |
128 | Standard_Real zoom = dout.Zoom(id); |
129 | if (b != 1) return 0; |
130 | if (id < 0) return 0; |
131 | gp_Pnt P; |
132 | gp_Pnt2d P2d; |
133 | |
134 | //Standard_Boolean newcurve; |
135 | |
136 | if (dout.Is3D(id)) { |
137 | // Cas du 3D ------- |
138 | Handle(Draw_Marker3D) mark; |
139 | TColgp_SequenceOfPnt ThePoints; |
140 | P.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom, 0.0); |
141 | ThePoints.Append (P); |
142 | mark = new Draw_Marker3D(P, Draw_X, Draw_orange); |
143 | dout << mark; |
144 | dout.Flush(); |
145 | i = 1; |
146 | |
147 | while (b != 3) { |
148 | dout.Select(id,XX,YY,b, Standard_False); |
149 | if (b == 1) { |
150 | i++; |
151 | P.SetCoord( (Standard_Real)XX/zoom, |
152 | (Standard_Real)YY/zoom, 0.0); |
153 | ThePoints.Append(P); |
154 | mark = new Draw_Marker3D(P, Draw_X, Draw_orange); |
155 | dout << mark; |
156 | dout.Flush(); |
157 | } |
158 | } |
159 | |
160 | MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, ThePoints.Length()); |
161 | AppDef_MultiPointConstraint mpc(1,0); |
162 | MPC->ChangeArray1().Init(mpc); |
163 | for (i=1; i<=ThePoints.Length(); i++) { |
164 | AppDef_MultiPointConstraint mpc(1,0); |
165 | mpc.SetPoint(1, ThePoints.Value(i)); |
166 | MPC->SetValue(i, mpc); |
167 | } |
168 | } |
169 | |
170 | else { |
171 | // Cas du 2D ------- |
172 | Handle(Draw_Marker2D) mark; |
173 | TColgp_SequenceOfPnt2d ThePoints; |
174 | P2d.SetCoord((Standard_Real)XX/zoom,(Standard_Real)YY/zoom); |
175 | ThePoints.Append(P2d); |
176 | mark = new Draw_Marker2D(P2d, Draw_X, Draw_orange); |
177 | dout << mark; |
178 | dout.Flush(); |
179 | i = 1; |
180 | |
181 | while (b != 3) { |
182 | dout.Select(id,XX,YY,b, Standard_False); |
183 | |
184 | if (b == 1) { |
185 | i++; |
186 | P2d.SetCoord( (Standard_Real)XX/zoom, (Standard_Real)YY/zoom ); |
187 | ThePoints.Append (P2d); |
188 | mark = new Draw_Marker2D(P2d, Draw_X, Draw_orange); |
189 | dout << mark; |
190 | dout.Flush(); |
191 | } |
192 | } |
193 | |
194 | MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, ThePoints.Length()); |
195 | for (i=1; i<=ThePoints.Length(); i++) { |
196 | AppDef_MultiPointConstraint mpc(0,1); |
197 | mpc.SetPoint2d(1, ThePoints.Value(i)); |
198 | MPC->SetValue(i, mpc); |
199 | } |
200 | } |
201 | return id; |
202 | } |
203 | |
204 | //======================================================================= |
205 | //function : PointsByFile |
206 | //======================================================================= |
207 | static void PointsByFile(Handle(AppDef_HArray1OfMultiPointConstraint)& MPC, |
208 | Handle(AppParCurves_HArray1OfConstraintCouple)& TABofCC, |
209 | ifstream& iFile, |
210 | Draw_Interpretor& di) |
211 | { |
212 | Standard_Integer nbp, i, nbc; |
213 | char c; |
214 | Standard_Real x, y, z; |
215 | |
216 | iFile >> nbp; |
217 | char dimen[3]; |
218 | iFile >> dimen; |
219 | |
220 | if (!strcmp(dimen,"3d")) { |
221 | Handle(Draw_Marker3D) mark; |
222 | MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, nbp); |
223 | |
224 | for (i = 1; i <= nbp; i++) { |
225 | iFile >> x >> y >> z; |
226 | AppDef_MultiPointConstraint mpc(1,0); |
227 | mpc.SetPoint(1, gp_Pnt(x, y, z)); |
228 | MPC->SetValue(i,mpc); |
229 | mark = new Draw_Marker3D(gp_Pnt(x, y, z), Draw_X, Draw_orange); |
230 | dout << mark; |
231 | } |
232 | Standard_Boolean HasConstrainte = Standard_False; |
233 | if (iFile.get(c)) { |
234 | if ( IsControl( (Standard_Character)c) ) { |
235 | if (iFile.get(c)) HasConstrainte = Standard_True; |
236 | } |
237 | else HasConstrainte = Standard_True; |
238 | } |
239 | |
240 | if (HasConstrainte) { |
241 | Standard_Integer num, ordre; |
242 | iFile >> nbc; |
243 | if ((nbc < 1) || (nbc>nbp)) return; // Y a comme un probleme |
244 | AppParCurves_Constraint Constraint = AppParCurves_NoConstraint; |
245 | TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, nbp); |
246 | for(i=1; i<=nbp; i++){ |
247 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
248 | TABofCC->SetValue(i,ACC); |
249 | } |
250 | for(i=1; i<=nbc; i++) { |
251 | iFile >> num >> ordre; |
252 | if ((num<1)||(num>nbp)) { |
253 | di << "Error on point Index in constrainte" << "\n"; |
254 | return; |
255 | } |
256 | Constraint = (AppParCurves_Constraint) (ordre+1); |
257 | TABofCC->ChangeValue(num).SetConstraint(Constraint); |
258 | if (Constraint >= AppParCurves_TangencyPoint) { |
259 | iFile >> x >> y >> z; |
260 | MPC->ChangeValue(num).SetTang(1, gp_Vec(x,y,z)); |
261 | } |
262 | if (Constraint >= AppParCurves_CurvaturePoint) { |
263 | iFile >> x >> y >> z; |
264 | MPC->ChangeValue(num).SetCurv(1, gp_Vec(x,y,z)); |
265 | } |
266 | } |
267 | } |
268 | |
269 | } |
270 | else if (!strcmp(dimen,"2d")) { |
271 | Handle(Draw_Marker2D) mark; |
272 | MPC = new (AppDef_HArray1OfMultiPointConstraint)(1, nbp); |
273 | |
274 | for (i = 1; i <= nbp; i++) { |
275 | iFile >> x >> y; |
276 | AppDef_MultiPointConstraint mpc(0,1); |
277 | mpc.SetPoint2d(1, gp_Pnt2d(x, y)); |
278 | MPC->SetValue(i, mpc); |
279 | mark = new Draw_Marker2D(gp_Pnt2d(x, y), Draw_X, Draw_orange); |
280 | dout << mark; |
281 | } |
282 | |
283 | Standard_Boolean HasConstrainte = Standard_False; |
284 | if (iFile.get(c)) { |
285 | if ( IsControl( (Standard_Character)c) ) { |
286 | if (iFile.get(c)) HasConstrainte = Standard_True; |
287 | } |
288 | else HasConstrainte = Standard_True; |
289 | } |
290 | |
291 | if (HasConstrainte) { |
292 | Standard_Integer num, ordre; |
293 | iFile >> nbc; |
294 | if ((nbc < 1) || (nbc>nbp)) return; // Y a comme un probleme |
295 | AppParCurves_Constraint Constraint = AppParCurves_NoConstraint; |
296 | TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, nbp); |
297 | for(i=1; i<=nbp; i++){ |
298 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
299 | TABofCC->SetValue(i,ACC); |
300 | } |
301 | for(i=1; i<=nbc; i++) { |
302 | iFile >> num >> ordre; |
303 | if ((num<1)||(num>nbp)) { |
304 | di << "Error on point Index in constrainte" << "\n"; |
305 | return; |
306 | } |
307 | Constraint = (AppParCurves_Constraint) (ordre+1); |
308 | TABofCC->ChangeValue(num).SetConstraint(Constraint); |
309 | if (Constraint >= AppParCurves_TangencyPoint) { |
310 | iFile >> x >> y; |
311 | MPC->ChangeValue(num).SetTang2d(1, gp_Vec2d(x,y)); |
312 | } |
313 | if (Constraint >= AppParCurves_CurvaturePoint) { |
314 | iFile >> x >> y; |
315 | MPC->ChangeValue(num).SetCurv2d(1, gp_Vec2d(x,y)); |
316 | } |
317 | } |
318 | } |
319 | } |
320 | } |
321 | |
322 | |
323 | |
324 | //================================================================================== |
325 | static Standard_Integer smoothing (Draw_Interpretor& di,Standard_Integer n, const char** a) |
326 | //================================================================================== |
327 | // Tolerance < 0 lissage "filtre" |
328 | // Tolerance > 0 lissage avec respect de l'erreur max |
329 | // Tolerance = 0 interpolation. |
330 | // |
331 | { |
332 | Standard_Real Tolerance=0; |
1d47d8d0 |
333 | |
7fd59977 |
334 | AppParCurves_Constraint Constraint=AppParCurves_NoConstraint; |
1d47d8d0 |
335 | |
7fd59977 |
336 | Handle(AppParCurves_HArray1OfConstraintCouple)TABofCC; |
337 | TABofCC.Nullify(); |
338 | Handle(AppDef_HArray1OfMultiPointConstraint) Points; |
339 | Standard_Integer id = 0, DegMax = -1; |
340 | |
341 | if (n == 1) { |
342 | di <<"give a name to your curve !" << "\n"; |
343 | return 0; |
344 | } |
345 | if (n == 2) { |
346 | di <<"give a tolerance to your curve !" << "\n"; |
347 | return 0; |
348 | } |
349 | if (n == 3) { |
91322f44 |
350 | Tolerance = Draw::Atof(a[2]); |
7fd59977 |
351 | if (Abs(Tolerance) < Precision::Confusion()*1.e-7) { |
352 | Constraint = AppParCurves_PassPoint; |
353 | } |
354 | else { |
355 | Constraint = AppParCurves_NoConstraint; |
356 | } |
357 | // Designation Graphique ------------------------ |
358 | id = PointsByPick(Points, di); |
359 | } |
360 | else if (n >= 4) { |
361 | Standard_Integer ific = 3; |
91322f44 |
362 | Tolerance = Draw::Atof(a[2]); |
7fd59977 |
363 | if (Abs(Tolerance) < Precision::Confusion()*1.e-7) { |
364 | Constraint = AppParCurves_PassPoint; |
365 | } |
366 | else { |
367 | Constraint = AppParCurves_NoConstraint; |
368 | } |
369 | |
370 | if (! strcmp(a[3],"-D")) { |
91322f44 |
371 | DegMax = Draw::Atoi(a[4]); |
7fd59977 |
372 | ific = 5; |
373 | } |
374 | |
375 | if (n > ific) { |
376 | // lecture du fichier. |
377 | // nbpoints, 2d ou 3d, puis valeurs. |
378 | const char* nomfic = a[ific]; |
379 | ifstream iFile(nomfic, ios::in); |
380 | if (!iFile) { |
381 | di << a[ific] <<"do not exist !" << "\n"; |
382 | return 1; |
383 | } |
384 | PointsByFile(Points, TABofCC, iFile, di); |
385 | } |
386 | else { |
387 | // Designation Graphique |
388 | id = PointsByPick(Points, di); |
389 | } |
390 | } |
391 | |
392 | AppDef_MultiLine AML(Points->Array1()); |
393 | |
394 | // Compute -------------- |
395 | Standard_Integer i; |
396 | if (Points->Value(1).NbPoints()==0){ |
397 | // Cas 2d |
398 | Handle(TColgp_HArray1OfPnt2d) ThePoints; |
399 | // Calcul du lissage |
400 | Standard_Integer NbPoints = Points->Length(); |
401 | if (TABofCC.IsNull()) { |
402 | TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints); |
403 | for(i=1; i<=NbPoints; i++){ |
404 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
405 | TABofCC->SetValue(i,ACC); |
406 | } |
407 | } |
408 | |
f62de372 |
409 | AppDef_Variational Variation(AML, |
7fd59977 |
410 | 1, NbPoints, |
411 | TABofCC); |
412 | |
413 | if (DegMax > 0) { |
414 | if (DegMax < 3) Variation.SetContinuity(GeomAbs_C0); |
415 | else if (DegMax <5) Variation.SetContinuity(GeomAbs_C1); |
416 | Variation.SetMaxDegree(DegMax); |
417 | } |
418 | Variation.SetTolerance( Abs(Tolerance)); |
419 | if (Tolerance>0) { Variation.SetWithMinMax(Standard_True);} |
420 | Variation.Approximate(); |
421 | |
422 | # ifdef DEB |
423 | //Variation.Dump(cout); |
424 | Standard_SStream aSStream; |
425 | Variation.Dump(aSStream); |
426 | di << aSStream; |
427 | # endif |
428 | |
429 | AppParCurves_MultiBSpCurve AnMuC = Variation.Value(); |
430 | |
431 | TColgp_Array1OfPnt2d ThePoles (1, AnMuC.NbPoles() ); |
432 | AnMuC.Curve(1, ThePoles); |
433 | Handle(Geom2d_BSplineCurve) Cvliss = new (Geom2d_BSplineCurve) |
434 | (ThePoles, |
435 | AnMuC.Knots(), |
436 | AnMuC. Multiplicities(), |
437 | AnMuC.Degree() ); |
438 | |
439 | Handle(DrawTrSurf_BSplineCurve2d) |
440 | DC = new DrawTrSurf_BSplineCurve2d(Cvliss); |
441 | DC->ClearPoles(); |
442 | Draw::Set(a[1], DC); |
443 | if (id!=0) dout.RepaintView(id); |
444 | } |
445 | else { |
446 | Standard_Integer NbPoints = Points->Length(); |
447 | if (TABofCC.IsNull()) { |
448 | TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints); |
449 | for(i=1; i<=NbPoints; i++){ |
450 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
451 | TABofCC->SetValue(i,ACC); |
452 | } |
453 | } |
454 | |
f62de372 |
455 | AppDef_Variational Variation(AML, |
7fd59977 |
456 | 1, NbPoints, |
457 | TABofCC); |
458 | |
459 | if (DegMax > 0) { |
460 | if (DegMax < 3) Variation.SetContinuity(GeomAbs_C0); |
461 | else if (DegMax <5) Variation.SetContinuity(GeomAbs_C1); |
462 | Variation.SetMaxDegree(DegMax); |
463 | } |
464 | Variation.SetTolerance( Abs(Tolerance)); |
465 | if (Tolerance>0) { Variation.SetWithMinMax(Standard_True);} |
466 | Variation.Approximate(); |
467 | # ifdef DEB |
468 | //Variation.Dump(cout); |
469 | Standard_SStream aSStream; |
470 | Variation.Dump(aSStream); |
471 | di << aSStream; |
472 | # endif |
473 | |
474 | AppParCurves_MultiBSpCurve AnMuC = Variation.Value(); |
475 | |
476 | TColgp_Array1OfPnt ThePoles (1, AnMuC.NbPoles() ); |
477 | AnMuC.Curve(1, ThePoles); |
478 | Handle(Geom_BSplineCurve) Cvliss = new (Geom_BSplineCurve) |
479 | (ThePoles, |
480 | AnMuC.Knots(), |
481 | AnMuC. Multiplicities(), |
482 | AnMuC.Degree() ); |
483 | |
484 | Handle(DrawTrSurf_BSplineCurve) |
485 | DC = new DrawTrSurf_BSplineCurve(Cvliss); |
486 | DC->ClearPoles(); |
487 | Draw::Set(a[1], DC); |
488 | if (id!=0) dout.RepaintView(id); |
489 | } |
490 | return 0; |
491 | } |
492 | |
493 | //============================================================================= |
494 | static Standard_Integer smoothingbybezier (Draw_Interpretor& di, |
495 | Standard_Integer n, |
496 | const char** a) |
497 | //============================================================================ |
498 | { |
499 | Standard_Real Tolerance=0; |
1d47d8d0 |
500 | AppParCurves_Constraint Constraint = AppParCurves_NoConstraint; |
7fd59977 |
501 | Handle(AppParCurves_HArray1OfConstraintCouple)TABofCC; |
502 | Handle(AppDef_HArray1OfMultiPointConstraint) Points; |
503 | |
504 | Standard_Integer id = 0; |
505 | Standard_Integer methode=0; |
506 | Standard_Integer Degree = 8; |
507 | |
508 | if (n == 1) { |
509 | di <<"give a name to your curve !" << "\n"; |
510 | return 0; |
511 | } |
512 | if (n == 2) { |
513 | di <<"give a tolerance to your curve !" << "\n"; |
514 | return 0; |
515 | } |
516 | if (n == 3) { |
517 | di <<"give a max degree!" << "\n"; |
518 | return 0; |
519 | } |
520 | |
521 | if (n == 4) { |
522 | di <<"give an option!" << "\n"; |
523 | return 0; |
524 | } |
525 | if (n >= 5) { |
91322f44 |
526 | Tolerance = Draw::Atof(a[2]); |
527 | Degree = Draw::Atoi(a[3]); |
7fd59977 |
528 | if (! strcmp(a[4],"-GR")) { |
529 | methode = 1; |
530 | } |
531 | else if (! strcmp(a[4],"-PR")) { |
532 | methode = 2; |
533 | } |
534 | else { methode = 3;} |
535 | |
536 | if (Abs(Tolerance) < Precision::Confusion()*1.e-7) { |
537 | Constraint = AppParCurves_PassPoint; |
538 | } |
539 | else { |
540 | Constraint = AppParCurves_NoConstraint; |
541 | } |
542 | if (n==5) |
543 | // Designation Graphique ------------------------ |
544 | id = PointsByPick(Points, di); |
545 | else { |
546 | // lecture du fichier. |
547 | // nbpoints, 2d ou 3d, puis valeurs. |
548 | const char* nomfic = a[5]; |
549 | ifstream iFile(nomfic, ios::in); |
550 | if (!iFile) { |
551 | di << a[6] <<"do not exist !" << "\n"; |
552 | return 1; |
553 | } |
554 | PointsByFile(Points, TABofCC, iFile, di); |
555 | } |
556 | } |
557 | |
558 | AppDef_MultiLine AML(Points->Array1()); |
559 | |
560 | // Compute -------------- |
561 | Standard_Integer i; |
562 | if (Points->Value(1).NbPoints()==0){ |
563 | // Cas 2d |
564 | Handle(TColgp_HArray1OfPnt2d) ThePoints; |
565 | // Calcul du lissage |
566 | Standard_Integer NbPoints = Points->Length(); |
567 | if (TABofCC.IsNull()) { |
568 | TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints); |
569 | for(i=1; i<=NbPoints; i++){ |
570 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
571 | TABofCC->SetValue(i,ACC); |
572 | } |
573 | |
574 | AppParCurves_ConstraintCouple AC1(1, AppParCurves_PassPoint); |
575 | if (TABofCC->Value(1).Constraint()<AppParCurves_PassPoint) |
576 | TABofCC->SetValue(1, AC1); |
577 | |
578 | AppParCurves_ConstraintCouple AC2(NbPoints, AppParCurves_PassPoint); |
579 | if (TABofCC->Value(NbPoints).Constraint()<AppParCurves_PassPoint) |
580 | TABofCC->SetValue(NbPoints, AC2); |
581 | } |
582 | |
583 | if (methode < 3) { |
584 | Standard_Boolean mySquare = (methode == 2); |
585 | Standard_Integer degmin = 4; |
586 | Standard_Integer NbIteration = 5; |
7fd59977 |
587 | |
588 | if (Degree < 4) degmin = Max(1, Degree -1); |
589 | degmin = Max(degmin, NbConstraint(TABofCC->Value(1).Constraint(), |
590 | TABofCC->Value(NbPoints).Constraint()) ); |
591 | |
592 | AppDef_Compute Appr(degmin, Degree, |
593 | Abs(Tolerance), Abs(Tolerance), |
594 | NbIteration, Standard_False, |
595 | Approx_ChordLength, mySquare); |
596 | |
597 | Appr.SetConstraints(TABofCC->Value(1).Constraint(), |
598 | TABofCC->Value(NbPoints).Constraint()); |
599 | |
600 | Appr.Perform (AML); |
601 | |
602 | if (! Appr.IsAllApproximated()) { |
603 | di << " No result" << "\n"; |
604 | } |
605 | AppParCurves_MultiCurve AnMuC = Appr.Value(); |
606 | ThePoints = new (TColgp_HArray1OfPnt2d) (1, AnMuC.NbPoles() ); |
607 | AnMuC.Curve(1, ThePoints->ChangeArray1()); |
608 | Standard_Real err, err2d; |
609 | Appr.Error(1, err, err2d); |
610 | di <<" Error2D is : " << err2d << "\n"; |
611 | } |
612 | else { |
f62de372 |
613 | AppDef_Variational Varia(AML, |
7fd59977 |
614 | 1, NbPoints, |
615 | TABofCC, |
616 | Degree, 1); |
617 | Varia.SetTolerance(Abs(Tolerance)); |
618 | Varia.Approximate(); |
619 | |
620 | if (! Varia.IsDone()) { |
621 | di << " No result" << "\n"; |
622 | } |
623 | |
624 | AppParCurves_MultiBSpCurve AnMuC = Varia.Value(); |
625 | di <<" Error2D is : " << Varia.MaxError() << "\n"; |
626 | ThePoints = new (TColgp_HArray1OfPnt2d) (1, AnMuC.NbPoles() ); |
627 | AnMuC.Curve(1, ThePoints->ChangeArray1()); |
628 | } |
629 | |
630 | Handle(Geom2d_BezierCurve) Cvliss = |
631 | new (Geom2d_BezierCurve)(ThePoints->Array1()); |
632 | |
633 | Handle(DrawTrSurf_BezierCurve2d) DC = |
634 | new (DrawTrSurf_BezierCurve2d) (Cvliss); |
635 | Draw::Set(a[1], DC); |
636 | if (id!=0) dout.RepaintView(id); |
637 | } |
638 | else { |
639 | // Cas 3d |
640 | Handle(TColgp_HArray1OfPnt) ThePoints; |
641 | Standard_Integer NbPoints = Points->Length(); |
642 | if (TABofCC.IsNull()) { |
643 | TABofCC = new AppParCurves_HArray1OfConstraintCouple(1, NbPoints); |
644 | for(i=1; i<=NbPoints; i++){ |
645 | AppParCurves_ConstraintCouple ACC(i,Constraint); |
646 | TABofCC->SetValue(i,ACC); |
647 | } |
648 | |
649 | |
650 | AppParCurves_ConstraintCouple AC1(1, AppParCurves_PassPoint); |
651 | if (TABofCC->Value(1).Constraint()<AppParCurves_PassPoint) |
652 | TABofCC->SetValue(1, AC1); |
653 | |
654 | AppParCurves_ConstraintCouple AC2(NbPoints, AppParCurves_PassPoint); |
655 | if (TABofCC->Value(NbPoints).Constraint()<AppParCurves_PassPoint) |
656 | TABofCC->SetValue(NbPoints, AC2); |
657 | } |
658 | |
659 | if (methode < 3) { |
660 | Standard_Boolean mySquare = (methode == 2); |
661 | Standard_Integer degmin = 4; |
662 | Standard_Integer NbIteration = 5; |
663 | if (Degree < 4) degmin = Max(1, Degree - 1); |
664 | degmin = Max(degmin, NbConstraint(TABofCC->Value(1).Constraint(), |
665 | TABofCC->Value(NbPoints).Constraint()) ); |
666 | |
667 | AppDef_Compute Appr(degmin, Degree, |
668 | Abs(Tolerance), Abs(Tolerance), |
669 | NbIteration, Standard_False, |
670 | Approx_ChordLength, mySquare); |
671 | |
672 | Appr.SetConstraints(TABofCC->Value(1).Constraint(), |
673 | TABofCC->Value(NbPoints).Constraint()); |
674 | |
675 | Appr.Perform (AML); |
676 | |
677 | if (! Appr.IsAllApproximated()) { |
678 | di << " No result" << "\n"; |
679 | } |
680 | AppParCurves_MultiCurve AnMuC = Appr.Value(); |
681 | ThePoints = new (TColgp_HArray1OfPnt) (1, AnMuC.NbPoles() ); |
682 | AnMuC.Curve(1, ThePoints->ChangeArray1()); |
683 | Standard_Real err, err2d; |
684 | Appr.Error(1, err, err2d); |
685 | di <<" Error3D is : " << err << "\n"; |
686 | } |
687 | else { |
f62de372 |
688 | AppDef_Variational Varia(AML, |
7fd59977 |
689 | 1, NbPoints, |
690 | TABofCC, |
691 | Degree, 1); |
692 | |
693 | Varia.SetTolerance(Abs(Tolerance)); |
694 | Varia.Approximate(); |
695 | if (! Varia.IsDone()) { |
696 | di << " No result" << "\n"; |
697 | } |
698 | |
699 | AppParCurves_MultiBSpCurve AnMuC = Varia.Value(); |
700 | di <<" Error3D is : " << Varia.MaxError() << "\n"; |
701 | ThePoints = new (TColgp_HArray1OfPnt) (1, AnMuC.NbPoles() ); |
702 | AnMuC.Curve(1, ThePoints->ChangeArray1()); |
703 | } |
704 | |
705 | Handle(Geom_BezierCurve) Cvliss = |
706 | new (Geom_BezierCurve)(ThePoints->Array1()); |
707 | |
708 | Handle(DrawTrSurf_BezierCurve) |
709 | DC = new DrawTrSurf_BezierCurve(Cvliss); |
710 | Draw::Set(a[1], DC); |
711 | if (id!=0) dout.RepaintView(id); |
712 | } |
713 | return 0; |
714 | } |
715 | |
716 | //======================================================================= |
717 | //function : ConstraintCommands |
718 | //purpose : |
719 | //======================================================================= |
720 | |
721 | |
722 | void GeomliteTest::ApproxCommands(Draw_Interpretor& theCommands) |
723 | { |
724 | |
725 | static Standard_Boolean loaded = Standard_False; |
726 | if (loaded) return; |
727 | loaded = Standard_True; |
728 | |
729 | DrawTrSurf::BasicCommands(theCommands); |
730 | |
731 | const char* g; |
732 | // constrained constructs |
733 | g = "GEOMETRY Constraints"; |
734 | |
735 | |
736 | theCommands.Add("bsmooth", |
737 | "bsmooth cname tol [-D degree] [fic]", |
738 | __FILE__, |
739 | smoothing, g); |
740 | |
741 | theCommands.Add("bzsmooth", |
742 | "bzsmooth cname tol degree option [fic]", |
743 | __FILE__, |
744 | smoothingbybezier, g); |
745 | } |
746 | |