g4tools  5.4.0
set_plotter_camera
Go to the documentation of this file.
1 // Copyright (C) 2010, Guy Barrand. All rights reserved.
2 // See the file tools.license for terms.
3 
4 #ifndef tools_sg_set_plotter_camera
5 #define tools_sg_set_plotter_camera
6 
7 #include "plotter"
8 #include "ortho"
9 
10 namespace tools {
11 namespace sg {
12 
13 inline void set_plotter_camera(float a_XSIZ,float a_YSIZ,float a_ZSIZ,
14  plotter& a_plotter,ortho& a_camera,unsigned int a_ww,unsigned int a_wh) {
15  if(!a_ww || !a_wh) return;
16 
17  a_plotter.width.value(a_XSIZ);
18  a_plotter.height.value(a_YSIZ);
19  a_plotter.depth.value(a_ZSIZ);
20 
21  enum plotter_viewport_mapping {
22  pvp_adjust_viewport,
23  pvp_leave_alone
24  };
25 
26  plotter_viewport_mapping pvp = pvp_adjust_viewport;
27  //plotter_viewport_mapping pvp = pvp_leave_alone;
28 
29  typedef plotter::shape_type st_t;
30  st_t plotter_shape = plotter::xy;
31 
32  float aspect = float(a_ww)/float(a_wh);
33 
34  {float XSIZ = a_plotter.width.value();
35  float YSIZ = a_plotter.height.value();
36  if((plotter_shape==plotter::xy) &&
37  (pvp==pvp_adjust_viewport)) {
38  // Adjust the plotter XSIZ and YSIZ so that YSIZ matches viewport height
39  // and plotter XSIZ matches viewport width.
40  // It it the CERN-ROOT and osc-plot logic.
41  if(aspect>=1) { //w>h
42  // camera must match in height YSIZ. Adjust XSIZ.
43  a_plotter.width.value(YSIZ * aspect);
44  } else {
45  // camera must match in width XSIZ. Adjust YSIZ.
46  a_plotter.height.value(XSIZ / aspect);
47  }
48  }}
49 
50  {float camera_znear = 0;
51  float camera_zfar = 0;
52  float camera_z_pos = 0;
53  // if camera ortho :
54  float camera_height = 0;
55 
56  float XSIZ = a_plotter.width.value();
57  float YSIZ = a_plotter.height.value();
58  float z = 4 * a_plotter.depth.value();
59  camera_z_pos = z;
60  camera_znear = 0.01F*z;
61  camera_zfar = 100*z;
62  //cam ortho :
63  if(plotter_shape==plotter::xyz) {
64  camera_height = YSIZ;
65  } else {
66  if(pvp==pvp_leave_alone) {
67  // Adjust camera so that plotter XSIZ/YSIZ be not distorded.
68  // If viewport aspect ratio > plotter aspect ratio
69  // the plotter YSIZ matches the viewport height. If not
70  // it is the plotter XSIZ that will match the viewport width.
71  // It is the PAW logic for one region.
72  float plotterAspect = XSIZ/YSIZ;
73  if(aspect<plotterAspect) {
74  camera_height = XSIZ / aspect;
75  } else {
76  camera_height = YSIZ;
77  }
78  } else if(pvp==pvp_adjust_viewport) {
79  camera_height = YSIZ;
80  }
81  }
82 
83  a_camera.height.value(camera_height);
84  a_camera.znear.value(camera_znear);
85  a_camera.zfar.value(camera_zfar);
86 
87  a_camera.position.value(vec3f(0,0,camera_z_pos));
88  a_camera.orientation.value(rotf(vec3f(0,0,1),0));}
89 }
90 
91 inline void set_plotter_camera(plotter& a_plotter,ortho& a_camera,unsigned int a_ww,unsigned int a_wh) {
92  //PAW logic :
93  float xfac = 1.0F/20.0F; //0.05
94  float yfac = 1.0F/20.0F; //0.05
95  float XSIZ = 20 * xfac; //1 //page width
96  float YSIZ = 20 * yfac; //1 //page height
97  float zfac = 1.0F/20.0F; //0.05
98  float ZSIZ = 20 * zfac; //1 //page depth
99  set_plotter_camera(XSIZ,YSIZ,ZSIZ,a_plotter,a_camera,a_ww,a_wh);
100 }
101 
102 }}
103 
104 #endif
plotter
tools::sg::base_camera::orientation
sf_rotf orientation
Definition: base_camera:33
tools::rotf
Definition: rotf:16
tools::sg::base_camera::position
sf_vec3f position
Definition: base_camera:29
tools::sg::plotter::xy
@ xy
Definition: plotter:150
tools::sg::ortho::height
sf< float > height
Definition: ortho:24
tools::sg::set_plotter_camera
void set_plotter_camera(float a_XSIZ, float a_YSIZ, float a_ZSIZ, plotter &a_plotter, ortho &a_camera, unsigned int a_ww, unsigned int a_wh)
Definition: set_plotter_camera:13
tools::sg::base_camera::zfar
sf< float > zfar
Definition: base_camera:28
tools::sg::plotter
Definition: plotter:45
tools::sg::ortho
Definition: ortho:12
tools::sg::plotter::shape_type
shape_type
Definition: plotter:149
ortho
tools::sg::plotter::width
sf< float > width
Definition: plotter:58
tools::vec3f
Definition: vec3f:13
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::plotter::height
sf< float > height
Definition: plotter:59
tools::sg::plotter::xyz
@ xyz
Definition: plotter:151
tools::sg::bsf::value
T & value()
Definition: bsf:98
tools::sg::plotter::depth
sf< float > depth
Definition: plotter:65
tools::sg::base_camera::znear
sf< float > znear
Definition: base_camera:27