Back to home page

EIC code displayed by LXR

 
 

    


Warning, /include/Geant4/tools/sg/tools 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_tools
0005 #define tools_sg_tools
0006 
0007 #include "separator"
0008 #include "matrix"
0009 #include "text_hershey"
0010 #include "base_freetype"
0011 
0012 #include <cstdio> //sscanf
0013 
0014 namespace tools {
0015 namespace sg {
0016 
0017 inline void add_string(
0018  separator& a_sep
0019 ,const std::string& a_font
0020 ,font_modeling& a_font_modeling
0021 ,const std::string& a_encoding
0022 ,bool //a_smoothing
0023 ,const std::string& a_string
0024 ,float a_x,float a_y,float a_z
0025 ,const vec3f& a_X
0026 ,const vec3f& a_Y
0027 ,float a_size
0028 ,hjust a_hjust
0029 ,vjust a_vjust
0030 ,const base_freetype& a_ttf
0031 ){
0032   if(a_string.empty()) return;
0033 
0034   matrix* tsf = new matrix;
0035 
0036  {tsf->mul_translate(a_x,a_y,a_z);
0037   vec3f X = a_X;
0038   vec3f Y = a_Y;
0039   X.normalize();
0040   Y.normalize();
0041   vec3f Z;X.cross(Y,Z);
0042   Z.cross(X,Y);
0043   mat4f r(X.v0(),Y.v0(),Z.v0(),0, //first row
0044                  X.v1(),Y.v1(),Z.v1(),0,
0045                  X.v2(),Y.v2(),Z.v2(),0,
0046                  0,0,0,1);
0047   tsf->mul_mtx(r);
0048   tsf->mul_scale(a_size,a_size,1);} //applied first on GL
0049 
0050   a_sep.add(tsf);
0051 
0052   if(a_font==font_hershey()) {
0053 
0054     text_hershey* text = new text_hershey;
0055     text->encoding.value(a_encoding);
0056     text->strings.add(a_string);
0057     text->hjust.value(a_hjust);
0058     text->vjust.value(a_vjust);
0059     a_sep.add(text);
0060 
0061   } else {
0062 
0063     base_freetype* text = base_freetype::create(a_ttf);
0064 
0065     text->font = a_font;
0066 
0067     text->strings.add(a_string);
0068     text->hjust.value(a_hjust);
0069     text->vjust.value(a_vjust);
0070     text->modeling = a_font_modeling;
0071     a_sep.add(text);
0072 
0073   }
0074 
0075 }
0076 
0077 inline matrix* add_string_opt(
0078  separator& a_sep
0079 ,const std::string& a_font
0080 ,font_modeling a_font_modeling
0081 ,const std::string& a_encoding
0082 ,bool //a_smoothing
0083 ,const std::string& a_string
0084 ,float a_x,float a_y,float a_z
0085 ,mat4f& a_scale_rot
0086 ,hjust a_hjust
0087 ,vjust a_vjust
0088 ,const base_freetype& a_ttf
0089 ){
0090   //used in axis::update_sg()
0091   if(a_string.empty()) return 0;
0092 
0093   matrix* tsf = new matrix;
0094   tsf->mul_translate(a_x,a_y,a_z);
0095   tsf->mul_mtx(a_scale_rot);
0096   a_sep.add(tsf);
0097 
0098   if(a_font==font_hershey()) {
0099 
0100     text_hershey* text = new text_hershey;
0101     text->encoding.value(a_encoding);
0102     text->strings.add(a_string);
0103     text->hjust.value(a_hjust);
0104     text->vjust.value(a_vjust);
0105     a_sep.add(text);
0106 
0107   } else {
0108 
0109     std::string _s = a_string;
0110     if(a_encoding==encoding_PAW()) {
0111       int mag;
0112       if(::sscanf(a_string.c_str(),"10^%d?",&mag)==1) {
0113         _s[2] = 'e';
0114         _s = _s.substr(0,_s.size()-1);
0115       }
0116     }
0117 
0118     base_freetype* text = base_freetype::create(a_ttf);
0119 
0120     text->font = a_font;
0121 
0122     text->strings.add(_s);
0123     text->hjust.value(a_hjust);
0124     text->vjust.value(a_vjust);
0125     text->modeling = a_font_modeling;
0126     a_sep.add(text);
0127 
0128   }
0129 
0130   return tsf;
0131 }
0132 
0133 }}
0134 
0135 #endif