Orbiter 2022
Combinatorial Objects
scene2.cpp
Go to the documentation of this file.
1/*
2 * scene2.cpp
3 *
4 * Created on: Jan 21, 2021
5 * Author: betten
6 */
7
8
9
10
11
12#include "foundations.h"
13
14using namespace std;
15
16
17
18#define EPSILON 0.01
19
20namespace orbiter {
21namespace layer1_foundations {
22namespace graphics {
23
24
25void scene::create_regulus(int idx, int nb_lines, int verbose_level)
26{
27 int f_v = (verbose_level >= 1);
28 double coeff[10];
29 numerics Num;
30 int k, i, j;
31
32 if (f_v) {
33 cout << "scene::create_regulus" << endl;
34 }
35
36
37 double axx;
38 double ayy;
39 double azz;
40 double axy;
41 double axz;
42 double ayz;
43 double ax;
44 double ay;
45 double az;
46 double a1;
47
48 double A[9];
49 double lambda[3];
50 double Basis[9];
51 double Basis_t[9];
52 double B[9];
53 double C[9];
54 double D[9];
55 double E[9];
56 double F[9];
57 double R[9];
58
59 double vec_a[3];
60 double vec_c[3];
61 double vec_d[3];
62 double vec_e[1];
63 double vec_f[1];
64 double c1;
65
66 double x6[6];
67 double w6[6];
68 double y6[6];
69 double z6[6];
70
71 int *line_idx;
72 int axis_of_symmetry_idx;
73
74 axx = quadric_coords(idx, 0);
75 axy = quadric_coords(idx, 1);
76 axz = quadric_coords(idx, 2);
77 ax = quadric_coords(idx, 3);
78 ayy = quadric_coords(idx, 4);
79 ayz = quadric_coords(idx, 5);
80 ay = quadric_coords(idx, 6);
81 azz = quadric_coords(idx, 7);
82 az = quadric_coords(idx, 8);
83 a1 = quadric_coords(idx, 9);
84
85 coeff[0] = axx;
86 coeff[1] = axy;
87 coeff[2] = axz;
88 coeff[3] = ax;
89 coeff[4] = ayy;
90 coeff[5] = ayz;
91 coeff[6] = ay;
92 coeff[7] = azz;
93 coeff[8] = az;
94 coeff[9] = a1;
95
96 if (f_v) {
97 cout << "scene::create_regulus coeff=" << endl;
98 Num.print_system(coeff, 10, 1);
99 }
100
101
102 //quadric1_idx = S->quadric(coeff); // Q(2 * h + 0)
103
104 // A is the 3 x 3 symmetric coefficient matrix
105 // of the quadratic terms:
106 A[0] = axx;
107 A[4] = ayy;
108 A[8] = azz;
109 A[1] = A[3] = axy * 0.5;
110 A[2] = A[6] = axz * 0.5;
111 A[5] = A[7] = ayz * 0.5;
112
113 // vec_a is the linear terms:
114 vec_a[0] = ax;
115 vec_a[1] = ay;
116 vec_a[2] = az;
117 if (f_v) {
118 cout << "scene::create_regulus A=" << endl;
119 Num.print_system(A, 3, 3);
120 cout << "scene::create_regulus a=" << endl;
121 Num.print_system(vec_a, 1, 3);
122 }
123
124
125 if (f_v) {
126 cout << "scene::create_regulus" << endl;
127 }
128 Num.eigenvalues(A, 3, lambda, verbose_level - 2);
129 Num.eigenvectors(A, Basis,
130 3, lambda, verbose_level - 2);
131
132 if (f_v) {
133 cout << "scene::create_regulus Basis=" << endl;
134 Num.print_system(Basis, 3, 3);
135 }
136 Num.transpose_matrix_nxn(Basis, Basis_t, 3);
137
138 Num.mult_matrix_matrix(Basis_t, A, B, 3, 3, 3);
139 Num.mult_matrix_matrix(B, Basis, C, 3, 3, 3);
140 // C = Basis_t * A * Basis = diagonal matrix
141
142 if (f_v) {
143 cout << "scene::create_regulus diagonalized matrix is" << endl;
144 }
145 Num.print_system(C, 3, 3);
146
147 for (i = 0; i < 3; i++) {
148 for (j = 0; j < 3; j++) {
149 D[i * 3 + j] = 0;
150
151 if (i == j) {
152 if (ABS(C[i * 3 + i]) > 0.0001) {
153 D[i * 3 + i] = 1. / C[i * 3 + i]; // 1 / lambda_i
154 }
155 else {
156 cout << "Warning zero eigenvalue" << endl;
157 D[i * 3 + i] = 0;
158 }
159 }
160 }
161 }
162 if (f_v) {
163 cout << "scene::create_regulus D=" << endl;
164 Num.print_system(D, 3, 3);
165 }
166
167 Num.mult_matrix_matrix(Basis, D, E, 3, 3, 3);
168 Num.mult_matrix_matrix(E, Basis_t, F, 3, 3, 3);
169 // F = Basis * D * Basis_t
170 Num.mult_matrix_matrix(F, vec_a, vec_c, 3, 3, 1);
171 for (i = 0; i < 3; i++) {
172 vec_c[i] *= 0.5;
173 }
174 // c = 1/2 * Basis * D * Basis_t * a
175
176 if (f_v) {
177 cout << "scene::create_regulus c=" << endl;
178 Num.print_system(vec_c, 3, 1);
179 }
180
181
182 Num.mult_matrix_matrix(vec_c, A, vec_d, 1, 3, 3);
183 Num.mult_matrix_matrix(vec_d, vec_c, vec_e, 1, 3, 1);
184 // e = c^\top * A * c
185
186 Num.mult_matrix_matrix(vec_a, vec_c, vec_f, 1, 3, 1);
187 // f = a^\top * c
188
189 c1 = vec_e[0] - vec_f[0] + a1;
190 // e - f + a1
191
192 if (f_v) {
193 cout << "scene::create_regulus e=" << vec_e[0] << endl;
194 cout << "scene::create_regulus f=" << vec_f[0] << endl;
195 cout << "scene::create_regulus a1=" << a1 << endl;
196 cout << "scene::create_regulus c1=" << c1 << endl;
197 }
198
199 coeff[0] = C[0 * 3 + 0]; // x^2
200 coeff[1] = 0;
201 coeff[2] = 0;
202 coeff[3] = 0;
203 coeff[4] = C[1 * 3 + 1]; // y^2
204 coeff[5] = 0;
205 coeff[6] = 0;
206 coeff[7] = C[2 * 3 + 2]; // z^2
207 coeff[8] = 0;
208 coeff[9] = c1;
209
210 if (f_v) {
211 cout << "scene::create_regulus coeff=" << endl;
212 Num.print_system(coeff, 10, 1);
213 }
214
215
216 //quadric2_idx = S->quadric(coeff); // Q(2 * h + 1)
217
218 // the axis of symmetry:
219 x6[0] = 0;
220 x6[1] = 0;
221 x6[2] = -1;
222 x6[3] = 0;
223 x6[4] = 0;
224 x6[5] = 1;
225
226
227
228 // mapping x \mapsto Basis * x - c
229 Num.mult_matrix_matrix(Basis, x6, y6, 3, 3, 1);
230 Num.mult_matrix_matrix(Basis, x6 + 3, y6 + 3, 3, 3, 1);
231
232 Num.vec_linear_combination(1, y6,
233 -1, vec_c, z6, 3);
234 Num.vec_linear_combination(1, y6 + 3,
235 -1, vec_c, z6 + 3, 3);
236
237 // create the axis of symmetry inside the scene
238 axis_of_symmetry_idx = line_through_two_pts(z6, sqrt(3) * 100.);
239 // Line h * (TARGET_NB_LINES + 1) + 0
240
241
242 // create a line on the cone:
243 x6[0] = 0;
244 x6[1] = 0;
245 x6[2] = 0;
246 if (lambda[2] < 0) {
247 x6[3] = sqrt(-lambda[2]);
248 x6[4] = 0;
249 x6[5] = sqrt(lambda[0]);
250 }
251 else {
252 x6[3] = sqrt(lambda[2]);
253 x6[4] = 0;
254 x6[5] = sqrt(-lambda[0]);
255 }
256 x6[0] = - x6[3];
257 x6[1] = - x6[4];
258 x6[2] = - x6[5];
259
260 // mapping x \mapsto Basis * x - c
261 Num.mult_matrix_matrix(Basis, x6, y6, 3, 3, 1);
262 Num.mult_matrix_matrix(Basis, x6 + 3, y6 + 3, 3, 3, 1);
263
264 Num.vec_linear_combination(1, y6,
265 -1, vec_c, z6, 3);
266 Num.vec_linear_combination(1, y6 + 3,
267 -1, vec_c, z6 + 3, 3);
268
269
270 line_idx = NEW_int(nb_lines);
271
272
273 line_idx[0] = line_through_two_pts(z6, sqrt(3) * 100.);
274 // Line h * (TARGET_NB_LINES + 1) + 1
275
276 // create the remaining lines on the cone using symmetry:
277
278 double phi;
279
280 phi = 2. * M_PI / (double) nb_lines;
281 for (k = 1; k < nb_lines; k++) {
282 Num.make_Rz(R, (double) k * phi);
283 Num.mult_matrix_matrix(R, x6, w6, 3, 3, 1);
284 Num.mult_matrix_matrix(R, x6 + 3, w6 + 3, 3, 3, 1);
285
286
287 // mapping x \mapsto Basis * x - c
288 Num.mult_matrix_matrix(Basis, w6, y6, 3, 3, 1);
289 Num.mult_matrix_matrix(Basis, w6 + 3, y6 + 3, 3, 3, 1);
290
291 Num.vec_linear_combination(1, y6,
292 -1, vec_c, z6, 3);
293 Num.vec_linear_combination(1, y6 + 3,
294 -1, vec_c, z6 + 3, 3);
295
296 line_idx[k] = line_through_two_pts(z6, sqrt(3) * 100.);
297 // Line h * (TARGET_NB_LINES + 1) + 1 + k
298
299 }
300
301 cout << "adding group for axis of symmetry:" << endl;
302 add_a_group_of_things(&axis_of_symmetry_idx, 1, verbose_level);
303
304 cout << "adding group for lines of the regulus:" << endl;
305 add_a_group_of_things(line_idx, nb_lines, verbose_level);
306
307 FREE_int(line_idx);
308
309
310 if (f_v) {
311 cout << "scene::create_regulus done" << endl;
312 }
313}
314
315void scene::clipping_by_cylinder(int line_idx, double r, ostream &ost)
316{
317 int h;
318 numerics N;
319
320 ost << " clipped_by { cylinder{<";
321 for (h = 0; h < 3; h++) {
322 N.output_double(Line_coords[line_idx * 6 + h], ost);
323 if (h < 2) {
324 ost << ", ";
325 }
326 }
327 ost << ">,<";
328 for (h = 0; h < 3; h++) {
329 N.output_double(Line_coords[line_idx * 6 + 3 + h], ost);
330 if (h < 2) {
331 ost << ", ";
332 }
333 }
334 ost << ">, " << r << " } } // line " << line_idx << endl;
335 ost << " bounded_by { clipped_by }" << endl;
336
337}
338
339int scene::scan1(int argc, std::string *argv, int &i, int verbose_level)
340{
341 //int f_v = (verbose_level >= 1);
343
344 if (ST.stringcmp(argv[i], "-cubic_lex") == 0) {
345 cout << "-cubic_lex" << endl;
346 string coeff_text;
347 double *coeff;
348 int coeff_sz;
349 numerics Numerics;
350
351 coeff_text.assign(argv[++i]);
352 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
353 if (coeff_sz != 20) {
354 cout << "For -cubic_lex, number of coefficients must be 20; is " << coeff_sz << endl;
355 exit(1);
356 }
357 cubic(coeff);
358 delete [] coeff;
359 }
360 else if (ST.stringcmp(argv[i], "-cubic_orbiter") == 0) {
361 cout << "-cubic_orbiter" << endl;
362 string coeff_text;
363 double *coeff;
364 int coeff_sz;
365 numerics Numerics;
366
367 coeff_text.assign(argv[++i]);
368 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
369 if (coeff_sz != 20) {
370 cout << "For -cubic_orbiter, the number of coefficients must be 20; is " << coeff_sz << endl;
371 exit(1);
372 }
374 delete [] coeff;
375 }
376 else if (ST.stringcmp(argv[i], "-cubic_Goursat") == 0) {
377 cout << "-cubic_Goursat" << endl;
378 string coeff_text;
379 double *coeff;
380 int coeff_sz;
381 numerics Numerics;
382
383 coeff_text.assign(argv[++i]);
384 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
385 if (coeff_sz != 3) {
386 cout << "For -cubic_Goursat, number of coefficients must be 3; is " << coeff_sz << endl;
387 exit(1);
388 }
389 cubic_Goursat_ABC(coeff[0], coeff[1], coeff[2]);
390 delete [] coeff;
391 }
392 else if (ST.stringcmp(argv[i], "-quadric_lex_10") == 0) {
393 cout << "-quadric_lex_10" << endl;
394 string coeff_text;
395 double *coeff;
396 int coeff_sz;
397 numerics Numerics;
398
399 coeff_text.assign(argv[++i]);
400 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
401 if (coeff_sz != 10) {
402 cout << "For -quadric_lex_10, number of coefficients must be 10; is " << coeff_sz << endl;
403 exit(1);
404 }
405 quadric(coeff);
406 delete [] coeff;
407 }
408 else if (ST.stringcmp(argv[i], "-quartic_lex_35") == 0) {
409 cout << "-quartic_lex_35" << endl;
410 string coeff_text;
411 double *coeff;
412 int coeff_sz;
413 numerics Numerics;
414
415 coeff_text.assign(argv[++i]);
416 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
417 if (coeff_sz != 35) {
418 cout << "For -quartic_lex_35, number of coefficients must be 35; is " << coeff_sz << endl;
419 exit(1);
420 }
421 quartic(coeff);
422 delete [] coeff;
423 }
424 else if (ST.stringcmp(argv[i], "-quintic_lex_56") == 0) {
425 cout << "-quintic_lex_56" << endl;
426 string coeff_text;
427 double *coeff;
428 int coeff_sz;
429 numerics Numerics;
430
431 coeff_text.assign(argv[++i]);
432 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
433 if (coeff_sz != 56) {
434 cout << "For -quintic_lex_56, number of coefficients must be 56; is " << coeff_sz << endl;
435 exit(1);
436 }
437 quintic(coeff);
438 delete [] coeff;
439 }
440 else if (ST.stringcmp(argv[i], "-octic_lex_165") == 0) {
441 cout << "-octic_lex_165" << endl;
442 string coeff_text;
443 double *coeff;
444 int coeff_sz;
445 numerics Numerics;
446
447 coeff_text.assign(argv[++i]);
448 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
449 if (coeff_sz != 165) {
450 cout << "For -octic_lex_165, number of coefficients must be 165; is " << coeff_sz << endl;
451 exit(1);
452 }
453 octic(coeff);
454 delete [] coeff;
455 }
456 else if (ST.stringcmp(argv[i], "-point") == 0) {
457 cout << "-point" << endl;
458 string coeff_text;
459 double *coeff;
460 int coeff_sz;
461 numerics Numerics;
462 int idx;
463
464 coeff_text.assign(argv[++i]);
465 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
466 if (coeff_sz != 3) {
467 cout << "For -point, the number of coefficients must be 3; is " << coeff_sz << endl;
468 exit(1);
469 }
470 idx = point(coeff[0], coeff[1], coeff[2]);
471 cout << "created point " << idx << endl;
472 delete [] coeff;
473 }
474 else if (ST.stringcmp(argv[i], "-point_list_from_csv_file") == 0) {
475 cout << "-point_list_from_csv_file" << endl;
476 string fname;
477 double *M;
478 int m, n, h;
480
481 fname.assign(argv[++i]);
482 Fio.double_matrix_read_csv(fname, M,
483 m, n, verbose_level);
484 cout << "The file " << fname << " contains " << m
485 << " point coordinates, each with " << n << " coordinates" << endl;
486 if (n == 2) {
487 for (h = 0; h < m; h++) {
488 point(M[h * 2 + 0], M[h * 2 + 1], 0);
489 }
490 }
491 else if (n == 3) {
492 for (h = 0; h < m; h++) {
493 point(M[h * 3 + 0], M[h * 3 + 1], M[h * 3 + 2]);
494 }
495 }
496 else if (n == 4) {
497 for (h = 0; h < m; h++) {
498 point(M[h * 4 + 0], M[h * 4 + 1], M[h * 4 + 2]);
499 }
500 }
501 else {
502 cout << "The file " << fname << " should have either 2 or three columns" << endl;
503 exit(1);
504 }
505 delete [] M;
506 }
507 else if (ST.stringcmp(argv[i], "-line_through_two_points_recentered_from_csv_file") == 0) {
508 cout << "-line_through_two_points_recentered_from_csv_file" << endl;
509 string fname;
510 double *M;
511 int m, n, h;
513
514 fname.assign(argv[++i]);
515 Fio.double_matrix_read_csv(fname, M,
516 m, n, verbose_level);
517 cout << "The file " << fname << " contains " << m
518 << " point coordinates, each with " << n << " coordinates" << endl;
519 if (n != 6) {
520 cout << "The file " << fname << " should have 6 columns" << endl;
521 exit(1);
522 }
523 for (h = 0; h < m; h++) {
524 line_after_recentering(M[h * 6 + 0], M[h * 6 + 1], M[h * 6 + 2],
525 M[h * 6 + 3], M[h * 6 + 4], M[h * 6 + 5],
526 10);
527 }
528 delete [] M;
529 }
530 else if (ST.stringcmp(argv[i], "-line_through_two_points_from_csv_file") == 0) {
531 cout << "-line_through_two_points_from_csv_file" << endl;
532 string fname;
533 double *M;
534 int m, n, h;
536
537 fname.assign(argv[++i]);
538 Fio.double_matrix_read_csv(fname, M,
539 m, n, verbose_level);
540 cout << "The file " << fname << " contains " << m
541 << " point coordinates, each with " << n << " coordinates" << endl;
542 if (n != 6) {
543 cout << "The file " << fname << " should have 6 columns" << endl;
544 exit(1);
545 }
546 for (h = 0; h < m; h++) {
547 line(M[h * 6 + 0], M[h * 6 + 1], M[h * 6 + 2],
548 M[h * 6 + 3], M[h * 6 + 4], M[h * 6 + 5]);
549 }
550 delete [] M;
551 }
552 else if (ST.stringcmp(argv[i], "-point_as_intersection_of_two_lines") == 0) {
553 cout << "-point_as_intersection_of_two_lines" << endl;
554 string Idx_text;
555 int *Idx;
556 int Idx_sz;
557 //numerics Numerics;
558
559 Idx_text.assign(argv[++i]);
560 Int_vec_scan(Idx_text, Idx, Idx_sz);
561 if (Idx_sz != 2) {
562 cout << "For -point_as_intersection_of_two_lines, "
563 "the number of indices must be 2; is " << Idx_sz << endl;
564 exit(1);
565 }
567 FREE_int(Idx);
568 }
569 else if (ST.stringcmp(argv[i], "-edge") == 0) {
570 cout << "-edge" << endl;
571 string Idx_text;
572 int *Idx;
573 int Idx_sz;
574 //numerics Numerics;
575
576 Idx_text.assign(argv[++i]);
577 Int_vec_scan(Idx_text, Idx, Idx_sz);
578 if (Idx_sz != 2) {
579 cout << "For -edge, the number of indices must be 2; is " << Idx_sz << endl;
580 exit(1);
581 }
582 edge(Idx[0], Idx[1]);
583 FREE_int(Idx);
584 }
585 else if (ST.stringcmp(argv[i], "-label") == 0) {
586 cout << "-label" << endl;
587 int pt_idx;
588 string text;
589 //numerics Numerics;
590
591 pt_idx = ST.strtoi(argv[++i]);
592 text.assign(argv[++i]);
593 label(pt_idx, text);
594 }
595 else if (ST.stringcmp(argv[i], "-triangular_face_given_by_three_lines") == 0) {
596 cout << "-triangular_face_given_by_three_lines" << endl;
597 string Idx_text;
598 int *Idx;
599 int Idx_sz;
600 //numerics Numerics;
601
602 Idx_text.assign(argv[++i]);
603 Int_vec_scan(Idx_text, Idx, Idx_sz);
604 if (Idx_sz != 3) {
605 cout << "For -triangular_face_given_by_three_lines, "
606 "the number of indices must be 3; is " << Idx_sz << endl;
607 exit(1);
608 }
609 triangle(Idx[0], Idx[1], Idx[2], 0 /* verbose_level */);
610 FREE_int(Idx);
611 }
612 else if (ST.stringcmp(argv[i], "-face") == 0) {
613 cout << "-face" << endl;
614 string Idx_text;
615 int *Idx;
616 int Idx_sz;
617 //numerics Numerics;
618
619 Idx_text.assign(argv[++i]);
620 Int_vec_scan(Idx_text, Idx, Idx_sz);
621 face(Idx, Idx_sz);
622 FREE_int(Idx);
623 }
624 else if (ST.stringcmp(argv[i], "-quadric_through_three_skew_lines") == 0) {
625 cout << "-quadric_through_three_skew_lines" << endl;
626 string Idx_text;
627 int *Idx;
628 int Idx_sz;
629 //numerics Numerics;
630
631 Idx_text.assign(argv[++i]);
632 Int_vec_scan(Idx_text, Idx, Idx_sz);
633 if (Idx_sz != 3) {
634 cout << "For -quadric_through_three_skew_lines, "
635 "the number of indices must be 3; is " << Idx_sz << endl;
636 exit(1);
637 }
638 quadric_through_three_lines(Idx[0], Idx[1], Idx[2], 0 /* verbose_level */);
639 FREE_int(Idx);
640 }
641 else if (ST.stringcmp(argv[i], "-plane_defined_by_three_points") == 0) {
642 cout << "-plane_defined_by_three_points" << endl;
643 string Idx_text;
644 int *Idx;
645 int Idx_sz;
646 //numerics Numerics;
647
648 Idx_text.assign(argv[++i]);
649 Int_vec_scan(Idx_text, Idx, Idx_sz);
650 if (Idx_sz != 3) {
651 cout << "For -plane_defined_by_three_points, "
652 "the number of indices must be 3; is " << Idx_sz << endl;
653 exit(1);
654 }
655 plane_through_three_points(Idx[0], Idx[1], Idx[2]);
656 FREE_int(Idx);
657 }
658 else if (ST.stringcmp(argv[i], "-line_through_two_points_recentered") == 0) {
659 cout << "-line_through_two_points_recentered" << endl;
660 string coeff_text;
661 double *coeff;
662 int coeff_sz;
663 numerics Numerics;
664
665 coeff_text.assign(argv[++i]);
666 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
667 if (coeff_sz != 6) {
668 cout << "For -line_through_two_points_recentered, "
669 "the number of coefficients must be 6; is " << coeff_sz << endl;
670 exit(1);
671 }
672 //S->line(coeff[0], coeff[1], coeff[2], coeff[3], coeff[4], coeff[5]);
673 line_after_recentering(coeff[0], coeff[1], coeff[2], coeff[3], coeff[4], coeff[5], 10);
674 delete [] coeff;
675 }
676 else if (ST.stringcmp(argv[i], "-line_through_two_points") == 0) {
677 cout << "-line_through_two_points" << endl;
678 string coeff_text;
679 double *coeff;
680 int coeff_sz;
681 numerics Numerics;
682
683 coeff_text.assign(argv[++i]);
684 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
685 if (coeff_sz != 6) {
686 cout << "For -line_through_two_points, "
687 "the number of coefficients must be 6; is " << coeff_sz << endl;
688 exit(1);
689 }
690 line(coeff[0], coeff[1], coeff[2], coeff[3], coeff[4], coeff[5]);
691 //S->line_after_recentering(coeff[0], coeff[1], coeff[2], coeff[3], coeff[4], coeff[5], 10);
692 delete [] coeff;
693 }
694 else if (ST.stringcmp(argv[i], "-line_through_two_existing_points") == 0) {
695 cout << "-line_through_two_existing_points" << endl;
696 string Idx_text;
697 int *Idx;
698 int Idx_sz;
699 //numerics Numerics;
700
701 Idx_text.assign(argv[++i]);
702 Int_vec_scan(Idx_text, Idx, Idx_sz);
703 if (Idx_sz != 2) {
704 cout << "For -line_through_two_existing_points, "
705 "the number of indices must be 2; is " << Idx_sz << endl;
706 exit(1);
707 }
708 line_through_two_points(Idx[0], Idx[1], 0 /* verbose_level */);
709 FREE_int(Idx);
710 }
711 else if (ST.stringcmp(argv[i], "-line_through_point_with_direction") == 0) {
712 cout << "-line_through_point_with_direction" << endl;
713 string coeff_text;
714 double *coeff;
715 int coeff_sz;
716 numerics Numerics;
717
718 coeff_text.assign(argv[++i]);
719 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
720 if (coeff_sz != 6) {
721 cout << "For -line_through_point_with_direction, "
722 "the number of coefficients must be 6; is " << coeff_sz << endl;
723 exit(1);
724 }
725 line_after_recentering(coeff[0], coeff[1], coeff[2], coeff[0] + coeff[3], coeff[1] + coeff[4], coeff[2] + coeff[5], 10);
726 delete [] coeff;
727 }
728 else if (ST.stringcmp(argv[i], "-plane_by_dual_coordinates") == 0) {
729 cout << "-plane_by_dual_coordinates" << endl;
730 string coeff_text;
731 double *coeff;
732 int coeff_sz;
733 numerics Numerics;
734
735 coeff_text.assign(argv[++i]);
736 Numerics.vec_scan(coeff_text, coeff, coeff_sz);
737 if (coeff_sz != 4) {
738 cout << "For -plane_by_dual_coordinates, "
739 "the number of coefficients must be 4; is " << coeff_sz << endl;
740 exit(1);
741 }
743 delete [] coeff;
744 }
745 else if (ST.stringcmp(argv[i], "-dodecahedron") == 0) {
746 cout << "-dodecahedron" << endl;
747
748 int first_pt_idx;
749
750 first_pt_idx = nb_points;
751
753 Dodecahedron_edges(first_pt_idx);
754 //cout << "Found " << S->nb_edges << " edges of the Dodecahedron" << endl;
755 Dodecahedron_planes(first_pt_idx);
756
757 // 20 points
758 // 30 edges
759 // 12 faces
760
761 }
762 else if (ST.stringcmp(argv[i], "-Hilbert_Cohn_Vossen_surface") == 0) {
763 cout << "-Hilbert_Cohn_Vossen_surface" << endl;
764
766
767 // 1 cubic surface
768 // 45 planes
769 // 27 lines
770
771 }
772 else if (ST.stringcmp(argv[i], "-Clebsch_surface") == 0) {
773 cout << "-Clebsch_surface" << endl;
774
775 create_Clebsch_surface(verbose_level);
776
777 // 1 cubic surface
778 // 27 lines
779 // 7 Eckardt points
780
781 }
782 else if (ST.stringcmp(argv[i], "-obj_file") == 0) {
783 cout << "-obj_file" << endl;
784 string fname;
785
786 fname.assign(argv[++i]);
787 cout << "before reading file " << fname << endl;
788 read_obj_file(fname, verbose_level - 1);
789 cout << "after reading file " << fname << endl;
790 }
791 else {
792 return FALSE;
793 }
794 return TRUE;
795}
796
797int scene::scan2(int argc, std::string *argv, int &i, int verbose_level)
798{
799 int f_v = (verbose_level >= 1);
801
802 if (ST.stringcmp(argv[i], "-group_of_things") == 0) {
803 cout << "-group_of_things" << endl;
804 string Idx_text;
805 int *Idx;
806 int Idx_sz;
807
808 Idx_text.assign(argv[++i]);
809 cout << "group: " << Idx_text << endl;
810 Int_vec_scan(Idx_text, Idx, Idx_sz);
811 cout << "group: ";
812 Int_vec_print(cout, Idx, Idx_sz);
813 cout << endl;
814 add_a_group_of_things(Idx, Idx_sz, verbose_level);
815 FREE_int(Idx);
816 cout << "end of -group_of_things" << endl;
817 }
818 else if (ST.stringcmp(argv[i], "-group_of_things_with_offset") == 0) {
819 cout << "-group_of_things" << endl;
820 string Idx_text;
821 int *Idx;
822 int Idx_sz;
823 int offset, h;
824
825 offset = ST.strtoi(argv[++i]);
826 Idx_text.assign(argv[++i]);
827 Int_vec_scan(Idx_text, Idx, Idx_sz);
828 for (h = 0; h < Idx_sz; h++) {
829 Idx[h] += offset;
830 }
831 add_a_group_of_things(Idx, Idx_sz, verbose_level);
832 FREE_int(Idx);
833 }
834 else if (ST.stringcmp(argv[i], "-group_of_things_as_interval") == 0) {
835 cout << "-group_of_things_as_interval" << endl;
836 int start;
837 int len;
838 int h;
839 int *Idx;
840
841 start = ST.strtoi(argv[++i]);
842 len = ST.strtoi(argv[++i]);
843 Idx = NEW_int(len);
844 for (h = 0; h < len; h++) {
845 Idx[h] = start + h;
846 }
847 add_a_group_of_things(Idx, len, verbose_level);
848 FREE_int(Idx);
849 }
850 else if (ST.stringcmp(argv[i], "-group_of_things_as_interval_with_exceptions") == 0) {
851 cout << "-group_of_things_as_interval_with_exceptions" << endl;
852 int start;
853 int len;
854 string exceptions_text;
855 int h;
856 int *Idx;
857 int *exceptions;
858 int exceptions_sz;
860
861 start = ST.strtoi(argv[++i]);
862 len = ST.strtoi(argv[++i]);
863 exceptions_text.assign(argv[++i]);
864
865 Int_vec_scan(exceptions_text, exceptions, exceptions_sz);
866
867 Idx = NEW_int(len);
868 for (h = 0; h < len; h++) {
869 Idx[h] = start + h;
870 }
871
872 for (h = 0; h < exceptions_sz; h++) {
873 if (!Sorting.int_vec_search_and_remove_if_found(Idx, len, exceptions[h])) {
874 cout << "-group_of_things_as_interval_with_exceptions "
875 "exception not found, value = " << exceptions[h] << endl;
876 exit(1);
877 }
878 }
879
880 FREE_int(exceptions);
881
882 cout << "creating a group of things of size " << len << endl;
883
884 add_a_group_of_things(Idx, len, verbose_level);
885 FREE_int(Idx);
886 }
887 else if (ST.stringcmp(argv[i], "-group_of_all_points") == 0) {
888 cout << "-group_of_all_points" << endl;
889 int *Idx;
890 int Idx_sz;
891 int h;
892
893 Idx_sz = nb_points;
894 Idx = NEW_int(Idx_sz);
895 for (h = 0; h < Idx_sz; h++) {
896 Idx[h] = h;
897 }
898 add_a_group_of_things(Idx, Idx_sz, verbose_level);
899 FREE_int(Idx);
900 }
901 else if (ST.stringcmp(argv[i], "-group_of_all_faces") == 0) {
902 cout << "-group_of_all_faces" << endl;
903 int *Idx;
904 int Idx_sz;
905 int h;
906
907 Idx_sz = nb_faces;
908 Idx = NEW_int(Idx_sz);
909 for (h = 0; h < Idx_sz; h++) {
910 Idx[h] = h;
911 }
912 add_a_group_of_things(Idx, Idx_sz, verbose_level);
913 cout << "created group " << group_of_things.size() - 1
914 << " consisting of " << Idx_sz << " faces" << endl;
915 FREE_int(Idx);
916 }
917 else if (ST.stringcmp(argv[i], "-group_subset_at_random") == 0) {
918 cout << "-group_subset_at_random" << endl;
919 int group_idx;
920 double percentage;
921 int *Selection;
922 int sz_old;
923 int sz;
924 int j, r;
927
928 group_idx = ST.strtoi(argv[++i]);
929 percentage = ST.strtoi(argv[++i]);
930
931
932 sz_old = group_of_things[group_idx].size();
933 if (f_v) {
934 cout << "sz_old" << sz_old << endl;
935 }
936 sz = sz_old * percentage;
937 Selection = NEW_int(sz);
938 for (j = 0; j < sz; j++) {
939 r = Os.random_integer(sz_old);
940 Selection[j] = group_of_things[group_idx][r];
941 }
942 Sorting.int_vec_sort_and_remove_duplicates(Selection, sz);
943
944 add_a_group_of_things(Selection, sz, verbose_level);
945
946 FREE_int(Selection);
947 }
948 else if (ST.stringcmp(argv[i], "-create_regulus") == 0) {
949 cout << "-create_regulus" << endl;
950 int idx, nb_lines;
951
952 idx = ST.strtoi(argv[++i]);
953 nb_lines = ST.strtoi(argv[++i]);
954 create_regulus(idx, nb_lines, verbose_level);
955 }
956 else if (ST.stringcmp(argv[i], "-spheres") == 0) {
957 cout << "-spheres" << endl;
958 int group_idx;
959 double rad;
960 string properties;
961
962 group_idx = ST.strtoi(argv[++i]);
963 rad = ST.strtof(argv[++i]);
964 properties.assign(argv[++i]);
965
967
968 D.init_spheres(group_idx, rad, properties, verbose_level);
969 Drawables.push_back(D);
970 }
971 else if (ST.stringcmp(argv[i], "-cylinders") == 0) {
972 cout << "-cylinders" << endl;
973 int group_idx;
974 double rad;
975 string properties;
976
977 group_idx = ST.strtoi(argv[++i]);
978 rad = ST.strtof(argv[++i]);
979 properties.assign(argv[++i]);
980
982
983 D.init_cylinders(group_idx, rad, properties, verbose_level);
984 Drawables.push_back(D);
985 }
986 else if (ST.stringcmp(argv[i], "-prisms") == 0) {
987 cout << "-prisms" << endl;
988 int group_idx;
989 double thickness;
990 string properties;
991
992 group_idx = ST.strtoi(argv[++i]);
993 thickness = ST.strtof(argv[++i]);
994 properties.assign(argv[++i]);
995
997
998 D.init_prisms(group_idx, thickness, properties, verbose_level);
999 Drawables.push_back(D);
1000 }
1001 else if (ST.stringcmp(argv[i], "-planes") == 0) {
1002 cout << "-planes" << endl;
1003 int group_idx;
1004 //double thickness;
1005 string properties;
1006
1007 group_idx = ST.strtoi(argv[++i]);
1008 //thickness = atof(argv[++i]);
1009 properties.assign(argv[++i]);
1010
1012
1013 D.init_planes(group_idx, properties, verbose_level);
1014 Drawables.push_back(D);
1015 }
1016 else if (ST.stringcmp(argv[i], "-lines") == 0) {
1017 cout << "-lines" << endl;
1018 int group_idx;
1019 double rad;
1020 string properties;
1021
1022 group_idx = ST.strtoi(argv[++i]);
1023 rad = ST.strtof(argv[++i]);
1024 properties.assign(argv[++i]);
1025
1027
1028 D.init_lines(group_idx, rad, properties, verbose_level);
1029 Drawables.push_back(D);
1030 }
1031 else if (ST.stringcmp(argv[i], "-cubics") == 0) {
1032 cout << "-cubics" << endl;
1033 int group_idx;
1034 //double thickness;
1035 string properties;
1036
1037 group_idx = ST.strtoi(argv[++i]);
1038 //thickness = atof(argv[++i]);
1039 properties.assign(argv[++i]);
1040
1042
1043 D.init_cubics(group_idx, properties, verbose_level);
1044 Drawables.push_back(D);
1045 }
1046 else if (ST.stringcmp(argv[i], "-quadrics") == 0) {
1047 cout << "-quadrics" << endl;
1048 int group_idx;
1049 //double thickness;
1050 string properties;
1051
1052 group_idx = ST.strtoi(argv[++i]);
1053 //thickness = atof(argv[++i]);
1054 properties.assign(argv[++i]);
1055
1057
1058 D.init_quadrics(group_idx, properties, verbose_level);
1059 Drawables.push_back(D);
1060 }
1061 else if (ST.stringcmp(argv[i], "-quartics") == 0) {
1062 cout << "-quartics" << endl;
1063 int group_idx;
1064 //double thickness;
1065 string properties;
1066
1067 group_idx = ST.strtoi(argv[++i]);
1068 //thickness = atof(argv[++i]);
1069 properties.assign(argv[++i]);
1070
1072
1073 D.init_quartics(group_idx, properties, verbose_level);
1074 Drawables.push_back(D);
1075 }
1076 else if (ST.stringcmp(argv[i], "-quintics") == 0) {
1077 cout << "-quintics" << endl;
1078 int group_idx;
1079 //double thickness;
1080 string properties;
1081
1082 group_idx = ST.strtoi(argv[++i]);
1083 //thickness = atof(argv[++i]);
1084 properties.assign(argv[++i]);
1085
1087
1088 D.init_quintics(group_idx, properties, verbose_level);
1089 Drawables.push_back(D);
1090 }
1091 else if (ST.stringcmp(argv[i], "-octics") == 0) {
1092 cout << "-octics" << endl;
1093 int group_idx;
1094 //double thickness;
1095 string properties;
1096
1097 group_idx = ST.strtoi(argv[++i]);
1098 //thickness = atof(argv[++i]);
1099 properties.assign(argv[++i]);
1100
1102
1103 D.init_octics(group_idx, properties, verbose_level);
1104 Drawables.push_back(D);
1105 }
1106 else if (ST.stringcmp(argv[i], "-texts") == 0) {
1107 cout << "-texts" << endl;
1108 int group_idx;
1109 double thickness_half;
1110 double scale;
1111 string properties;
1112
1113 group_idx = ST.strtoi(argv[++i]);
1114 thickness_half = ST.strtof(argv[++i]);
1115 scale = ST.strtof(argv[++i]);
1116 properties.assign(argv[++i]);
1117
1119
1120 D.init_labels(group_idx, thickness_half, scale, properties, verbose_level);
1121 Drawables.push_back(D);
1122 }
1123 else if (ST.stringcmp(argv[i], "-deformation_of_cubic_lex") == 0) {
1124 cout << "-deformation_of_cubic_lex" << endl;
1125 string coeff1_text;
1126 string coeff2_text;
1127 int nb_frames;
1128 double angle_start, angle_max, angle_min;
1129 double *coeff1;
1130 double *coeff2;
1131 int coeff_sz;
1132 numerics Numerics;
1133
1134 nb_frames = ST.strtoi(argv[++i]);
1135 angle_start = ST.strtof(argv[++i]);
1136 angle_max = ST.strtof(argv[++i]);
1137 angle_min = ST.strtof(argv[++i]);
1138 coeff1_text.assign(argv[++i]);
1139 Numerics.vec_scan(coeff1_text, coeff1, coeff_sz);
1140 if (coeff_sz != 20) {
1141 cout << "For -deformation_of_cubic_lex, number of coefficients "
1142 "must be 20; is " << coeff_sz << endl;
1143 exit(1);
1144 }
1145 coeff2_text.assign(argv[++i]);
1146 Numerics.vec_scan(coeff2_text, coeff2, coeff_sz);
1147 if (coeff_sz != 20) {
1148 cout << "For -deformation_of_cubic_lex, number of coefficients "
1149 "must be 20; is " << coeff_sz << endl;
1150 exit(1);
1151 }
1153 nb_frames, angle_start, angle_max, angle_min,
1154 coeff1, coeff2,
1155 verbose_level);
1156 delete [] coeff1;
1157 delete [] coeff2;
1158 }
1159 else if (ST.stringcmp(argv[i], "-group_is_animated") == 0) {
1160 cout << "-group_is_animated" << endl;
1161 int group_idx;
1162
1163 group_idx = ST.strtoi(argv[++i]);
1164
1165 //S->Drawables.push_back(D);
1166
1167 animated_groups.push_back(group_idx);
1168
1169 cout << "-group_is_animated " << group_idx << endl;
1170 }
1171 else {
1172 return FALSE;
1173 }
1174 return TRUE;
1175}
1176
1177int scene::read_scene_objects(int argc, std::string *argv,
1178 int i0, int verbose_level)
1179{
1180 int f_v = (verbose_level >= 1);
1181 int i;
1183
1184 if (f_v) {
1185 cout << "scene::read_scene_objects" << endl;
1186 }
1187 for (i = i0; i < argc; i++) {
1188
1189 if (scan1(argc, argv, i, verbose_level)) {
1190
1191 }
1192 else if (scan2(argc, argv, i, verbose_level)) {
1193
1194 }
1195 else if (ST.stringcmp(argv[i], "-scene_objects_end") == 0) {
1196 cout << "-scene_object_end " << endl;
1197 break;
1198 }
1199 else {
1200 cout << "-scene: unrecognized option " << argv[i] << " ignored" << endl;
1201 continue;
1202 }
1203 }
1204 if (f_v) {
1205 cout << "scene::read_scene_objects done" << endl;
1206 }
1207 return i + 1;
1208}
1209
1210
1211
1212}}}
1213
1214
a collection of functions related to sorted vectors
int int_vec_search_and_remove_if_found(int *v, int &len, int a)
Definition: sorting.cpp:1077
functions related to strings and character arrays
a set of objects that should be drawn with certain povray properties
Definition: graphics.h:349
void init_cylinders(int group_idx, double rad, std::string &properties, int verbose_level)
void init_quintics(int group_idx, std::string &properties, int verbose_level)
void init_planes(int group_idx, std::string &properties, int verbose_level)
void init_cubics(int group_idx, std::string &properties, int verbose_level)
void init_octics(int group_idx, std::string &properties, int verbose_level)
void init_quartics(int group_idx, std::string &properties, int verbose_level)
void init_labels(int group_idx, double thickness_half, double scale, std::string &properties, int verbose_level)
void init_lines(int group_idx, double rad, std::string &properties, int verbose_level)
void init_quadrics(int group_idx, std::string &properties, int verbose_level)
void init_spheres(int group_idx, double rad, std::string &properties, int verbose_level)
void init_prisms(int group_idx, double thickness, std::string &properties, int verbose_level)
int line_through_two_pts(double *x6, double rad)
Definition: scene.cpp:821
void clipping_by_cylinder(int line_idx, double r, std::ostream &ost)
Definition: scene2.cpp:315
void add_a_group_of_things(int *Idx, int sz, int verbose_level)
Definition: scene.cpp:4915
int point(double x1, double x2, double x3)
Definition: scene.cpp:967
int read_scene_objects(int argc, std::string *argv, int i0, int verbose_level)
Definition: scene2.cpp:1177
int cubic_Goursat_ABC(double A, double B, double C)
Definition: scene.cpp:1376
int line(double x1, double x2, double x3, double y1, double y2, double y3)
Definition: scene.cpp:871
int scan1(int argc, std::string *argv, int &i, int verbose_level)
Definition: scene2.cpp:339
int point_as_intersection_of_two_lines(int line1, int line2)
Definition: scene.cpp:1017
std::vector< std::vector< int > > group_of_things
Definition: graphics.h:1217
int scan2(int argc, std::string *argv, int &i, int verbose_level)
Definition: scene2.cpp:797
int plane_through_three_points(int pt1, int pt2, int pt3)
Definition: scene.cpp:1107
double label(int idx, std::string &txt)
Definition: scene.cpp:194
int triangle(int line1, int line2, int line3, int verbose_level)
Definition: scene.cpp:999
int line_after_recentering(double x1, double x2, double x3, double y1, double y2, double y3, double rad)
Definition: scene.cpp:888
double quadric_coords(int idx, int j)
Definition: scene.cpp:269
void deformation_of_cubic_lex(int nb_frames, double angle_start, double angle_max, double angle_min, double *coeff1, double *coeff2, int verbose_level)
Definition: scene.cpp:1325
void Dodecahedron_edges(int first_pt_idx)
Definition: scene.cpp:2931
void read_obj_file(std::string &fname, int verbose_level)
Definition: scene.cpp:4757
std::vector< drawable_set_of_objects > Drawables
Definition: graphics.h:1221
void create_Hilbert_Cohn_Vossen_surface(int verbose_level)
Definition: scene.cpp:3458
int line_through_two_points(int pt1, int pt2, double rad)
Definition: scene.cpp:920
int quadric_through_three_lines(int line_idx1, int line_idx2, int line_idx3, int verbose_level)
Definition: scene.cpp:1132
void create_regulus(int idx, int nb_lines, int verbose_level)
Definition: scene2.cpp:25
void Dodecahedron_planes(int first_pt_idx)
Definition: scene.cpp:2958
void create_Clebsch_surface(int verbose_level)
Definition: scene.cpp:3404
numerical functions, mostly concerned with double
Definition: globals.h:129
void make_Rz(double *R, double phi)
Definition: numerics.cpp:885
void eigenvectors(double *A, double *Basis, int n, double *lambda, int verbose_level)
Definition: numerics.cpp:2087
void print_system(double *A, int m, int n)
Definition: numerics.cpp:270
void vec_linear_combination(double c1, double *v1, double c2, double *v2, double *v3, int len)
Definition: numerics.cpp:59
void eigenvalues(double *A, int n, double *lambda, int verbose_level)
Definition: numerics.cpp:2004
void transpose_matrix_nxn(double *A, double *At, int n)
Definition: numerics.cpp:1213
void vec_scan(const char *s, double *&v, int &len)
Definition: numerics.cpp:2218
void output_double(double a, std::ostream &ost)
Definition: numerics.cpp:1177
void mult_matrix_matrix(double *A, double *B, double *C, int m, int n, int o)
Definition: numerics.cpp:855
void double_matrix_read_csv(std::string &fname, double *&M, int &m, int &n, int verbose_level)
Definition: file_io.cpp:1595
#define Int_vec_scan(A, B, C)
Definition: foundations.h:716
#define FREE_int(p)
Definition: foundations.h:640
#define NEW_int(n)
Definition: foundations.h:625
#define ABS(x)
Definition: foundations.h:220
#define TRUE
Definition: foundations.h:231
#define FALSE
Definition: foundations.h:234
#define M_PI
Definition: foundations.h:237
#define Int_vec_print(A, B, C)
Definition: foundations.h:685
the orbiter library for the classification of combinatorial objects