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