Orbiter 2022
Combinatorial Objects
povray_interface.cpp
Go to the documentation of this file.
1/*
2 * povray_interface.cpp
3 *
4 * Created on: Jan 6, 2019
5 * Author: betten
6 */
7
8
9#include "foundations.h"
10
11
12using namespace std;
13
14
15namespace orbiter {
16namespace layer1_foundations {
17namespace graphics {
18
19
21{
22 //color_white_simple = "pigment{White*0.5 }";
23 color_white_simple.assign("texture{ pigment{ White*0.5 transmit 0.2 } finish {ambient 0.4 diffuse 0.5 roughness 0.001 reflection 0.1 specular .8} }");
24 color_white.assign("texture{ pigment{ White*0.5 transmit 0.5 } finish {ambient 0.4 diffuse 0.5 roughness 0.001 reflection 0.1 specular .8} }");
25 color_white_very_transparent.assign("texture{ pigment{ White*0.5 transmit 0.75 } finish {ambient 0.4 diffuse 0.5 roughness 0.001 reflection 0.1 specular .8} }");
26 color_black.assign("texture{ pigment{ color Black } finish { diffuse 0.9 phong 1}}");
27 color_pink.assign("texture{ pigment{ color Pink } finish { diffuse 0.9 phong 1}}");
28 color_pink_transparent.assign("texture{ pigment{ color Pink transmit 0.5 } finish {diffuse 0.9 phong 0.6} }");
29 color_green.assign("texture{ pigment{ color Green } finish { diffuse 0.9 phong 1}}");
30 color_gold.assign("texture{ pigment{ color Gold } finish { diffuse 0.9 phong 1}}");
31 color_red.assign("texture{ pigment{ color Red } finish { diffuse 0.9 phong 1}}");
32 color_blue.assign("texture{ pigment{ color Blue } finish { diffuse 0.9 phong 1}}");
33 color_yellow.assign("texture{ pigment{ color Yellow } finish { diffuse 0.9 phong 1}}");
34 color_yellow_transparent.assign("texture{ pigment{ color Yellow transmit 0.7 } finish {diffuse 0.9 phong 0.6} }");
35 color_scarlet.assign("texture{ pigment{ color Scarlet } finish { diffuse 0.9 phong 1}}");
36 color_brown.assign("texture{ pigment{ color Brown } finish { diffuse 0.9 phong 1}}");
37 color_orange.assign("texture{ pigment{ color Orange transmit 0.5 } finish { diffuse 0.9 phong 1}}");
38 color_orange_transparent.assign("texture{ pigment{ color Orange transmit 0.7 } finish { diffuse 0.9 phong 1}}");
39 color_orange_no_phong.assign("texture{ pigment{ color Orange transmit 0.6 } finish { diffuse 0.6 brilliance 5 phong 0.3 metallic }}");
40 color_chrome.assign("texture{ Polished_Chrome pigment{quick_color White} }");
41 color_gold_dode.assign("texture{ pigment{color Gold transmit 0.7 } finish {ambient 0.4 diffuse 0.5 roughness 0.001 reflection 0.1 specular .8} }");
42 color_gold_transparent.assign("texture{ pigment{color Gold transmit 0.7 } finish { diffuse 0.6 brilliance 5 phong 0.3 metallic } }");
43 color_red_wine_transparent.assign("texture{ pigment{ color rgb<1, 0,0.25> transmit 0.5 } finish {diffuse 0.9 phong 0.6} }");
44 color_yellow_lemon_transparent.assign("texture{ pigment{ color rgb< 0.35, 0.6, 0.0> transmit 0.5 } finish {diffuse 0.9 phong 0.6} }");
45
46 //double sky[3];
47 //double location[3];
48 //double look_at[3];
49
50}
51
53{
54
55}
56
57
59 double angle,
60 double *sky,
61 double *location,
62 double *look_at,
63 int f_with_background)
64// angle = 22
65// sky <1,1,1>
66// location <-3,1,3>
67// look_at = <0,0,0>
68// or <1,1,1>*-1/sqrt(3)
69{
70 ost << "//Files with predefined colors and textures" << endl;
71 ost << "#version 3.7;" << endl;
72 ost << "#include \"colors.inc\"" << endl;
73 ost << "#include \"glass.inc\"" << endl;
74 ost << "#include \"golds.inc\"" << endl;
75 ost << "#include \"metals.inc\"" << endl;
76 ost << "#include \"stones.inc\"" << endl;
77 ost << "#include \"woods.inc\"" << endl;
78 ost << "#include \"textures.inc\"" << endl;
79 ost << endl;
80
81 int i;
82
83 for (i = 0; i < 3; i++) {
87 }
88
89#if 0
90 ost << "//Place the camera" << endl;
91 ost << "camera {" << endl;
92 ost << " sky <0,0,1> " << endl;
93 ost << " direction <-1,0,0>" << endl;
94 ost << " right <-4/3,0,0> " << endl;
95 ost << " //location <-2.5,0.6,-3>*3" << endl;
96 ost << " //look_at<0,0.2,0>" << endl;
97 ost << " location <0,5,0> //Camera location" << endl;
98 ost << " look_at <0,0,0> //Where camera is pointing" << endl;
99 ost << " angle " << angle << " //Angle of the view" << endl;
100 ost << " // 22 is default, 18 is closer, 28 is further away" << endl;
101 ost << "}" << endl;
102 ost << endl;
103 ost << "//Ambient light to brighten up darker pictures" << endl;
104 ost << "//global_settings { ambient_light White }" << endl;
105 ost << "global_settings { max_trace_level 10 }" << endl;
106 ost << endl;
107 ost << endl;
108 ost << "//Place a light" << endl;
109 ost << "//light_source { <15,30,1> color White*2 } " << endl;
110 ost << "//light_source { <10,10,0> color White*2 } " << endl;
111 ost << "light_source { <0,2,0> color White*2 } " << endl;
112 ost << "light_source { <0,0,2> color White }" << endl;
113 ost << "//light_source { <0,10,0> color White*2}" << endl;
114 ost << endl;
115 ost << endl;
116 ost << endl;
117 ost << "//plane{z,7 pigment {SkyBlue} }" << endl;
118 ost << "plane{y,7 pigment {SkyBlue} }" << endl;
119 ost << endl;
120 ost << "//texture {T_Silver_3A}" << endl;
121 ost << endl;
122 ost << "//Set a background color" << endl;
123 ost << "background { color SkyBlue }" << endl;
124 ost << endl;
125 ost << "union{ " << endl;
126 ost << "/* #declare r=0.09 ; " << endl;
127 ost << endl;
128 ost << "object{ // x-axis" << endl;
129 ost << "cylinder{< 0,0,0 >,<1.5,0,0 > ,r }" << endl;
130 ost << " pigment{Red} " << endl;
131 ost << endl;
132 ost << "} " << endl;
133 ost << "object{ // y-axis" << endl;
134 ost << "cylinder{< 0,0,0 >,<0,1.5,0 > ,r }" << endl;
135 ost << " pigment{Green} " << endl;
136 ost << endl;
137 ost << "} " << endl;
138 ost << "object{ // z-axis" << endl;
139 ost << "cylinder{< 0,0,0 >,<0,0,1.5 > ,r }" << endl;
140 ost << " pigment{Blue} " << endl;
141 ost << endl;
142 ost << "} */" << endl;
143#else
144 ost << "//Place the camera" << endl;
145 ost << "camera {" << endl;
146 ost << " sky <" << sky[0] << "," << sky[1] << "," << sky[2] << ">" << endl;
147 //ost << " sky " << sky << endl;
148 ost << " //direction <1,0,0>" << endl;
149 ost << " //right <1,1,0> " << endl;
150 ost << " location <" << location[0] << "," << location[1] << "," << location[2] << ">" << endl;
151 ost << " look_at <" << look_at[0] << "," << look_at[1] << "," << look_at[2] << ">" << endl;
152 //ost << " look_at " << look_at << endl;
153 ost << " angle " << angle << " //Angle of the view" << endl;
154 ost << " // smaller numbers are closer. Must be less than 180" << endl;
155 ost << "}" << endl;
156 ost << endl;
157 ost << "//Ambient light to brighten up darker pictures" << endl;
158 ost << "//global_settings { ambient_light White }" << endl;
159 ost << "global_settings { max_trace_level 10 }" << endl;
160 ost << "global_settings { assumed_gamma 1.0 }" << endl;
161 ost << endl;
162 ost << "//Place a light" << endl;
163 //ost << "light_source { <4,4,4> color White } " << endl;
164 //ost << "light_source { <-5,0,5> color White }" << endl;
165 ost << "light_source { <" << sky[0] * 6 << "," << sky[1] * 6 << "," << sky[2] * 6 << "> color White } " << endl; // parallel
166 ost << "light_source { <" << location[0] << "," << location[1] << "," << location[2] << "> color White * 2 }" << endl;
167 ost << endl;
168
169 if (f_with_background) {
170 ost << "//Set a background color" << endl;
171 ost << "background { color SkyBlue }" << endl;
172 ost << endl;
173 }
174 else {
175 ost << "//Set a background color" << endl;
176 ost << "background { color White }" << endl;
177 ost << endl;
178 }
179 ost << "// main part:" << endl;
180#endif
181 ost << endl;
182 ost << endl;
183}
184
185
187{
188 ost << " // the next three steps will perform a rotation" << endl;
189 ost << " // around the axis of symmetry 1,1,1:" << endl;
190 ost << endl;
191 ost << " // move 1,1,1 to sqrt(3),0,0:" << endl;
192 ost << " matrix<" << endl;
193 ost << " 1/sqrt(3),2/sqrt(6),0," << endl;
194 ost << " 1/sqrt(3),-1/sqrt(6),1/sqrt(2)," << endl;
195 ost << " 1/sqrt(3),-1/sqrt(6),-1/sqrt(2)," << endl;
196 ost << " 0,0,0>" << endl;
197 ost << endl;
198 ost << endl;
199 ost << " rotate <360*clock,0,0> " << endl;
200 ost << endl;
201 ost << " // move sqrt(3),0,0 back to 1,1,1:" << endl;
202 ost << endl;
203 ost << " matrix<" << endl;
204 ost << " 1/sqrt(3),1/sqrt(3),1/sqrt(3)," << endl;
205 ost << " 2/sqrt(6),-1/sqrt(6),-1/sqrt(6)," << endl;
206 ost << " 0,1/sqrt(2),-1/sqrt(2)," << endl;
207 ost << " 0,0,0>" << endl;
208 ost << endl;
209 ost << endl;
210}
211
213 double *v, ostream &ost)
214{
215 double A[9], Av[9];
216 numerics N;
217
219 A, Av, 0 /* verbose_level */);
220
221 ost << " // the next three steps will perform a rotation" << endl;
222 ost << " // around the axis of symmetry (" << v[0] << ", " << v[1] << "," << v[2] << "):" << endl;
223 ost << endl;
224 ost << " // move axis of symmetry to 1,0,0:" << endl;
225 ost << " matrix<" << endl;
226 ost << " ";
227 N.output_double(A[0], ost);
228 ost << ",";
229 N.output_double(A[1], ost);
230 ost << ",";
231 N.output_double(A[2], ost);
232 ost << ",";
233 ost << " ";
234 N.output_double(A[3], ost);
235 ost << ",";
236 N.output_double(A[4], ost);
237 ost << ",";
238 N.output_double(A[5], ost);
239 ost << ",";
240 ost << " ";
241 N.output_double(A[6], ost);
242 ost << ",";
243 N.output_double(A[7], ost);
244 ost << ",";
245 N.output_double(A[8], ost);
246 ost << ",";
247 ost << endl;
248 ost << " 0,0,0>" << endl;
249 ost << endl;
250 ost << endl;
251 ost << " rotate <360*clock,0,0> " << endl;
252 ost << endl;
253 ost << " // move 1,0,0 back to axis of symmetry:" << endl;
254 ost << endl;
255 ost << " matrix<" << endl;
256 ost << " ";
257 N.output_double(Av[0], ost);
258 ost << ",";
259 N.output_double(Av[1], ost);
260 ost << ",";
261 N.output_double(Av[2], ost);
262 ost << ",";
263 ost << " ";
264 N.output_double(Av[3], ost);
265 ost << ",";
266 N.output_double(Av[4], ost);
267 ost << ",";
268 N.output_double(Av[5], ost);
269 ost << ",";
270 ost << " ";
271 N.output_double(Av[6], ost);
272 ost << ",";
273 N.output_double(Av[7], ost);
274 ost << ",";
275 N.output_double(Av[8], ost);
276 ost << ",";
277 ost << endl;
278 ost << " 0,0,0>" << endl;
279 ost << endl;
280 ost << endl;
281}
282
284 double angle_x_deg, double angle_y_deg, double angle_z_deg, ostream &ost)
285{
286 numerics N;
287
288 ost << " rotate <";
289 N.output_double(angle_x_deg, ost);
290 ost << ",";
291 N.output_double(angle_y_deg, ost);
292 ost << ",";
293 N.output_double(angle_z_deg, ost);
294 ost << ">" << endl;
295}
296
298 double *v, double angle_zero_one, ostream &ost)
299{
300 double A[9], Av[9];
301 numerics N;
302
304 A, Av, 0 /* verbose_level */);
305
306 ost << " // the next three steps will perform a rotation" << endl;
307 ost << " // around the axis of symmetry (" << v[0] << ", " << v[1] << "," << v[2] << "):" << endl;
308 ost << endl;
309 ost << " // move axis of symmetry to (" << v[0] << ", " << v[1] << ", " << v[2] << ") " << endl;
310 ost << " matrix<" << endl;
311 ost << " ";
312 N.output_double(A[0], ost);
313 ost << ",";
314 N.output_double(A[1], ost);
315 ost << ",";
316 N.output_double(A[2], ost);
317 ost << ",";
318 ost << " ";
319 N.output_double(A[3], ost);
320 ost << ",";
321 N.output_double(A[4], ost);
322 ost << ",";
323 N.output_double(A[5], ost);
324 ost << ",";
325 ost << " ";
326 N.output_double(A[6], ost);
327 ost << ",";
328 N.output_double(A[7], ost);
329 ost << ",";
330 N.output_double(A[8], ost);
331 ost << ",";
332 ost << endl;
333 ost << " 0,0,0>" << endl;
334 ost << endl;
335 ost << endl;
336 ost << " rotate <" << angle_zero_one * 360. << ",0,0> " << endl;
337 ost << endl;
338 ost << " // move (" << v[0] << ", " << v[1] << ", " << v[2] << ") back to axis:" << endl;
339 ost << endl;
340 ost << " matrix<" << endl;
341 ost << " ";
342 N.output_double(Av[0], ost);
343 ost << ",";
344 N.output_double(Av[1], ost);
345 ost << ",";
346 N.output_double(Av[2], ost);
347 ost << ",";
348 ost << " ";
349 N.output_double(Av[3], ost);
350 ost << ",";
351 N.output_double(Av[4], ost);
352 ost << ",";
353 N.output_double(Av[5], ost);
354 ost << ",";
355 ost << " ";
356 N.output_double(Av[6], ost);
357 ost << ",";
358 N.output_double(Av[7], ost);
359 ost << ",";
360 N.output_double(Av[8], ost);
361 ost << ",";
362 ost << endl;
363 ost << " 0,0,0>" << endl;
364 ost << endl;
365 ost << endl;
366}
367
368
370{
371 ost << "union{ " << endl;
372 ost << endl;
373 ost << endl;
374 ost << "// uncomment this if you need axes:" << endl;
375 ost << "/* #declare r=0.09 ; " << endl;
376 ost << endl;
377 ost << "object{ // x-axis" << endl;
378 ost << "cylinder{< 0,0,0 >,<1.5,0,0 > ,r }" << endl;
379 ost << " pigment{Red} " << endl;
380 ost << endl;
381 ost << "} " << endl;
382 ost << "object{ // y-axis" << endl;
383 ost << "cylinder{< 0,0,0 >,<0,1.5,0 > ,r }" << endl;
384 ost << " pigment{Green} " << endl;
385 ost << endl;
386 ost << "} " << endl;
387 ost << "object{ // z-axis" << endl;
388 ost << "cylinder{< 0,0,0 >,<0,0,1.5 > ,r }" << endl;
389 ost << " pigment{Blue} " << endl;
390 ost << endl;
391 ost << "} */" << endl;
392}
393
394void povray_interface::union_end(ostream &ost, double scale_factor, double clipping_radius)
395{
396 ost << endl;
397 ost << " scale " << scale_factor << endl;
398 //ost << " scale 1.0" << endl;
399 ost << endl;
400 ost << " clipped_by { sphere{ < 0.,0.,0. > , " << clipping_radius << " } }" << endl;
401 ost << " bounded_by { clipped_by }" << endl;
402 ost << endl;
403 ost << "} // union" << endl;
404}
405
406void povray_interface::union_end_box_clipping(ostream &ost, double scale_factor,
407 double box_x, double box_y, double box_z)
408{
409 ost << endl;
410 ost << " scale " << scale_factor << endl;
411 //ost << " scale 1.0" << endl;
412 ost << endl;
413 ost << " clipped_by { box{ < " << -1 * box_x << ", " << -1 * box_y << ", " << -1 * box_z << " > * " << scale_factor << ", "
414 " < " << box_x << ", " << box_y << ", " << box_z << " > * " << scale_factor << " } }" << endl;
415 ost << " bounded_by { clipped_by }" << endl;
416 ost << endl;
417 ost << "} // union" << endl;
418}
419
420void povray_interface::union_end_no_clipping(ostream &ost, double scale_factor)
421{
422 ost << endl;
423 ost << " scale " << scale_factor << endl;
424 //ost << " scale 1.0" << endl;
425 ost << endl;
426 ost << endl;
427 ost << "} // union" << endl;
428}
429
431{
432
433 ost << endl;
434 ost << "//bottom plane:" << endl;
435 ost << "plane {" << endl;
436 ost << " <1,1,1>*1/sqrt(3), -2" << endl;
437 ost << " texture {" << endl;
438 ost << " pigment {SteelBlue}" << endl;
439 ost << " finish {" << endl;
440 ost << " diffuse 0.6" << endl;
441 ost << " ambient 0.2" << endl;
442 ost << " phong 1" << endl;
443 ost << " phong_size 100" << endl;
444 ost << " reflection 0.25" << endl;
445 ost << " }" << endl;
446 ost << " }" << endl;
447 ost << " } // end plane" << endl;
448#if 0
449 ost << endl;
450 ost << endl;
451 ost << endl;
452 ost << "#declare d = .8; " << endl;
453 ost << endl;
454 ost << "plane {" << endl;
455 ost << " //y, -d" << endl;
456 ost << " z, -d" << endl;
457 ost << " texture {" << endl;
458 ost << " pigment {SkyBlue} // Yellow" << endl;
459 ost << " //pigment {" << endl;
460 ost << " // checker" << endl;
461 ost << " // color rgb<0.5, 0, 0>" << endl;
462 ost << " // color rgb<0, 0.5, 0.5>" << endl;
463 ost << " //}" << endl;
464 ost << " finish {" << endl;
465 ost << " diffuse 0.6" << endl;
466 ost << " ambient 0.2" << endl;
467 ost << " phong 1" << endl;
468 ost << " phong_size 100" << endl;
469 ost << " reflection 0.25" << endl;
470 ost << " }" << endl;
471 ost << " }" << endl;
472 ost << " }" << endl;
473#endif
474 ost << endl;
475 ost << endl;
476
477}
478
479void povray_interface::rotate_111(int h, int nb_frames, ostream &fp)
480{
481 //int nb_frames_per_rotation;
482 //nb_frames_per_rotation = nb_frames;
483 double angle_zero_one = 1. - (h * 1. / (double) nb_frames);
484 // rotate in the opposite direction
485
486 double v[3] = {1.,1.,1.};
487
489 v, angle_zero_one, fp);
490}
491
492void povray_interface::rotate_around_z_axis(int h, int nb_frames, ostream &fp)
493{
494 //int nb_frames_per_rotation;
495 //nb_frames_per_rotation = nb_frames;
496 double angle_zero_one = 1. - (h * 1. / (double) nb_frames);
497 // rotate in the opposite direction
498
499 double v[3] = {0,0,1.};
500
502 v, angle_zero_one, fp);
503}
504
505
506void povray_interface::ini(ostream &ost, const char *fname_pov,
507 int first_frame, int last_frame)
508{
509 ost << "; Persistence Of Vision raytracer version 3.7 example file." << endl;
510 ost << "Antialias=On" << endl;
511 ost << endl;
512 ost << "Antialias_Threshold=0.1" << endl;
513 ost << "Antialias_Depth=2" << endl;
514 ost << "Input_File_Name=" << fname_pov << endl;
515 ost << endl;
516 ost << "Initial_Frame=" << first_frame << endl;
517 ost << "Final_Frame=" << last_frame << endl;
518 ost << "Initial_Clock=0" << endl;
519 ost << "Final_Clock=1" << endl;
520 ost << endl;
521 ost << "Cyclic_Animation=on" << endl;
522 ost << "Pause_when_Done=off" << endl;
523}
524
525}}}
526
527
void union_end(std::ostream &ost, double scale_factor, double clipping_radius)
void rotate_111(int h, int nb_frames, std::ostream &fp)
void beginning(std::ostream &ost, double angle, double *sky, double *location, double *look_at, int f_with_background)
void animation_rotate_xyz(double angle_x_deg, double angle_y_deg, double angle_z_deg, std::ostream &ost)
void rotate_around_z_axis(int h, int nb_frames, std::ostream &fp)
void ini(std::ostream &ost, const char *fname_pov, int first_frame, int last_frame)
void animation_rotate_around_origin_and_given_vector(double *v, std::ostream &ost)
void union_end_no_clipping(std::ostream &ost, double scale_factor)
void union_end_box_clipping(std::ostream &ost, double scale_factor, double box_x, double box_y, double box_z)
void animation_rotate_around_origin_and_given_vector_by_a_given_angle(double *v, double angle_zero_one, std::ostream &ost)
numerical functions, mostly concerned with double
Definition: globals.h:129
void orthogonal_transformation_from_point_to_basis_vector(double *from, double *A, double *Av, int verbose_level)
Definition: numerics.cpp:1099
void output_double(double a, std::ostream &ost)
Definition: numerics.cpp:1177
the orbiter library for the classification of combinatorial objects