Warning, /include/Geant4/tools/sg/mnmx is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_mnmx
0005 #define tools_sg_mnmx
0006
0007 #include "node"
0008 #include "bbox_action"
0009
0010 namespace tools {
0011
0012 inline bool mnmx(std::ostream& a_out,sg::node& a_node,vec3f& a_mn,vec3f& a_mx){
0013 sg::bbox_action action(a_out);
0014 a_node.bbox(action);
0015 if(!action.end() || action.box().is_empty()) {
0016 a_out << "tools::mnmx :"
0017 << " bbox problem."
0018 << std::endl;
0019 a_mn.set_value(0,0,0);
0020 a_mx.set_value(0,0,0);
0021 return false;
0022 }
0023 a_mn = action.box().mn();
0024 a_mx = action.box().mx();
0025 return true;
0026 }
0027
0028 }
0029
0030 #include "matrix"
0031
0032 namespace tools {
0033
0034 inline bool center_adjust(std::ostream& a_out,
0035 sg::node& a_node,sg::matrix& a_tsf,
0036 unsigned int a_ww,unsigned int a_wh,
0037 float a_height,
0038 float& a_dx,float& a_dy,float& a_dz,
0039 bool a_verbose = true) {
0040 //NOTE : we assume an ortho camera.
0041 if(!a_ww||!a_wh) {
0042 if(a_verbose) {
0043 a_out << "tools::center_adjust :"
0044 << " null viewer width or height."
0045 << std::endl;
0046 }
0047 a_dx = 0;a_dy = 0;a_dz = 0;
0048 return false;
0049 }
0050 sg::bbox_action _action(a_out);
0051 a_node.bbox(_action);
0052 if(!_action.box().get_size(a_dx,a_dy,a_dz)) {
0053 if(a_verbose) {
0054 a_out << "tools::center_adjust :"
0055 << " empty box."
0056 << std::endl;
0057 }
0058 a_dx = 0;a_dy = 0;a_dz = 0;
0059 return false;
0060 }
0061 if(!a_dx||!a_dy) {
0062 if(a_verbose) {
0063 a_out << "tools::center_adjust :"
0064 << " dx or dy null."
0065 << std::endl;
0066 }
0067 a_dx = 0;a_dy = 0;a_dz = 0;
0068 return false;
0069 }
0070 vec3f c;
0071 if(!_action.box().center(c)) {
0072 if(a_verbose) {
0073 a_out << "tools::center_adjust :"
0074 << " can't get box center."
0075 << std::endl;
0076 }
0077 a_dx = 0;a_dy = 0;a_dz = 0;
0078 return false;
0079 }
0080 float vp_aspect = float(a_ww)/float(a_wh);
0081 float scene_aspect = float(a_dx)/float(a_dy);
0082 //::printf("debug : set_tsf : %d %d : %g %g %g : %g %g\n",
0083 // a_ww,a_wh,a_dx,a_dy,a_dz,vp_aspect,scene_aspect);
0084 float scale;
0085 if(vp_aspect>=scene_aspect) {
0086 scale = a_height/a_dy;
0087 } else {
0088 scale = (vp_aspect*a_height)/a_dx;
0089 }
0090 a_tsf.set_scale(scale,scale,scale);
0091 a_tsf.mul_translate(-c.x(),-c.y(),0);
0092 return true;
0093 }
0094
0095 inline bool center_adjust(std::ostream& a_out,
0096 sg::node& a_node,sg::matrix& a_tsf,
0097 unsigned int a_ww,unsigned int a_wh,
0098 float a_height,bool a_verbose = true) {
0099 float dx,dy,dz;
0100 return center_adjust(a_out,a_node,a_tsf,a_ww,a_wh,a_height,
0101 dx,dy,dz,a_verbose);
0102 }
0103
0104 }
0105
0106 #endif