g4tools  5.4.0
mnmx
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_mnmx
5 #define tools_sg_mnmx
6 
7 #include "node"
8 #include "bbox_action"
9 
10 namespace tools {
11 
12 inline bool mnmx(std::ostream& a_out,sg::node& a_node,vec3f& a_mn,vec3f& a_mx){
13  sg::bbox_action action(a_out);
14  a_node.bbox(action);
15  if(!action.end() || action.box().is_empty()) {
16  a_out << "tools::mnmx :"
17  << " bbox problem."
18  << std::endl;
19  a_mn.set_value(0,0,0);
20  a_mx.set_value(0,0,0);
21  return false;
22  }
23  a_mn = action.box().mn();
24  a_mx = action.box().mx();
25  return true;
26 }
27 
28 }
29 
30 #include "matrix"
31 
32 namespace tools {
33 
34 inline bool center_adjust(std::ostream& a_out,
35  sg::node& a_node,sg::matrix& a_tsf,
36  unsigned int a_ww,unsigned int a_wh,
37  float a_height,
38  float& a_dx,float& a_dy,float& a_dz,
39  bool a_verbose = true) {
40  //NOTE : we assume an ortho camera.
41  if(!a_ww||!a_wh) {
42  if(a_verbose) {
43  a_out << "tools::center_adjust :"
44  << " null viewer width or height."
45  << std::endl;
46  }
47  a_dx = 0;a_dy = 0;a_dz = 0;
48  return false;
49  }
50  sg::bbox_action _action(a_out);
51  a_node.bbox(_action);
52  if(!_action.box().get_size(a_dx,a_dy,a_dz)) {
53  if(a_verbose) {
54  a_out << "tools::center_adjust :"
55  << " empty box."
56  << std::endl;
57  }
58  a_dx = 0;a_dy = 0;a_dz = 0;
59  return false;
60  }
61  if(!a_dx||!a_dy) {
62  if(a_verbose) {
63  a_out << "tools::center_adjust :"
64  << " dx or dy null."
65  << std::endl;
66  }
67  a_dx = 0;a_dy = 0;a_dz = 0;
68  return false;
69  }
70  vec3f c;
71  if(!_action.box().center(c)) {
72  if(a_verbose) {
73  a_out << "tools::center_adjust :"
74  << " can't get box center."
75  << std::endl;
76  }
77  a_dx = 0;a_dy = 0;a_dz = 0;
78  return false;
79  }
80  float vp_aspect = float(a_ww)/float(a_wh);
81  float scene_aspect = float(a_dx)/float(a_dy);
82  //::printf("debug : set_tsf : %d %d : %g %g %g : %g %g\n",
83  // a_ww,a_wh,a_dx,a_dy,a_dz,vp_aspect,scene_aspect);
84  float scale;
85  if(vp_aspect>=scene_aspect) {
86  scale = a_height/a_dy;
87  } else {
88  scale = (vp_aspect*a_height)/a_dx;
89  }
90  a_tsf.set_scale(scale,scale,scale);
91  a_tsf.mul_translate(-c.x(),-c.y(),0);
92  return true;
93 }
94 
95 inline bool center_adjust(std::ostream& a_out,
96  sg::node& a_node,sg::matrix& a_tsf,
97  unsigned int a_ww,unsigned int a_wh,
98  float a_height,bool a_verbose = true) {
99  float dx,dy,dz;
100  return center_adjust(a_out,a_node,a_tsf,a_ww,a_wh,a_height,
101  dx,dy,dz,a_verbose);
102 }
103 
104 }
105 
106 #endif
tools::box3::mn
const VEC3 & mn() const
Definition: box3:69
node
tools::mnmx
bool mnmx(std::ostream &a_out, sg::node &a_node, vec3f &a_mn, vec3f &a_mx)
Definition: mnmx:12
tools::sg::bbox_action::box
const box3f & box() const
Definition: bbox_action:129
tools::vec3::set_value
void set_value(const T &a0, const T &a1, const T &a2)
Definition: vec3:92
tools::sg::node
Definition: node:28
tools::sg::bbox_action
Definition: bbox_action:15
tools::center_adjust
bool center_adjust(std::ostream &a_out, sg::node &a_node, sg::matrix &a_tsf, unsigned int a_ww, unsigned int a_wh, float a_height, float &a_dx, float &a_dy, float &a_dz, bool a_verbose=true)
Definition: mnmx:34
tools::sg::node::bbox
virtual void bbox(bbox_action &)
Definition: node:55
tools::sg::matrix_action::end
bool end() const
Definition: matrix_action:75
tools::vec3::y
const T & y() const
Definition: vec3:85
matrix
tools::box3::get_size
bool get_size(T_t &a_dx, T_t &a_dy, T_t &a_dz) const
Definition: box3:59
tools::vec3::x
const T & x() const
Definition: vec3:84
tools::sg::matrix::set_scale
void set_scale(float a_x, float a_y, float a_z)
Definition: matrix:93
tools::vec3f
Definition: vec3f:13
tools::box3::is_empty
bool is_empty() const
Definition: box3:67
tools
inlined C code : ///////////////////////////////////
Definition: aida_ntuple:26
tools::sg::matrix
Definition: matrix:19
tools::box3::center
bool center(VEC3 &a_center) const
Definition: box3:37
tools::box3::mx
const VEC3 & mx() const
Definition: box3:70
tools::sg::matrix::mul_translate
void mul_translate(float a_x, float a_y, float a_z)
Definition: matrix:102
bbox_action