Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_sg_f2plot 4 #ifndef tools_sg_f2plot 5 #define tools_sg_f2plot 5 #define tools_sg_f2plot 6 6 7 // Connexion tools/func to sg/plotter. 7 // Connexion tools/func to sg/plotter. 8 8 9 #include "plottables" 9 #include "plottables" 10 10 11 //#include "../func" 11 //#include "../func" 12 12 13 #include "../words" 13 #include "../words" 14 #include "../S_STRING" 14 #include "../S_STRING" 15 #include "../forit" 15 #include "../forit" 16 16 17 #ifdef TOOLS_MEM 17 #ifdef TOOLS_MEM 18 #include "../mem" 18 #include "../mem" 19 #endif 19 #endif 20 20 21 namespace tools { 21 namespace tools { 22 namespace sg { 22 namespace sg { 23 23 24 template <class T> 24 template <class T> 25 class f1d2plot : public virtual func1D { 25 class f1d2plot : public virtual func1D { 26 public: 26 public: 27 TOOLS_T_SCLASS(T,tools::sg::f1d2plot) 27 TOOLS_T_SCLASS(T,tools::sg::f1d2plot) 28 virtual void* cast(const std::string& a_clas 28 virtual void* cast(const std::string& a_class) const { 29 if(void* p = cmp_cast<f1d2plot>(this,a_cla 29 if(void* p = cmp_cast<f1d2plot>(this,a_class)) {return p;} 30 return func1D::cast(a_class); 30 return func1D::cast(a_class); 31 } 31 } 32 public: //plottable 32 public: //plottable 33 virtual plottable* copy() const {return new 33 virtual plottable* copy() const {return new f1d2plot(*this);} 34 virtual bool is_valid() const {return true;} 34 virtual bool is_valid() const {return true;} 35 virtual const std::string& name() const {ret 35 virtual const std::string& name() const {return m_name;} 36 virtual void set_name(const std::string& a_s 36 virtual void set_name(const std::string& a_s) {m_name = a_s;} 37 virtual const std::string& title() const {re 37 virtual const std::string& title() const {return m_title;} 38 virtual const std::string& legend() const {r 38 virtual const std::string& legend() const {return m_legend;} 39 virtual void set_legend(const std::string& a 39 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 40 40 41 virtual void infos(const std::string& a_opts 41 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 42 a_sinfos.clear(); 42 a_sinfos.clear(); 43 std::string f_lf("\n"); 43 std::string f_lf("\n"); 44 std::vector<std::string> _words; 44 std::vector<std::string> _words; 45 words(a_opts," ",false,_words); 45 words(a_opts," ",false,_words); 46 tools_vforcit(std::string,_words,it) { 46 tools_vforcit(std::string,_words,it) { 47 if(((*it)=="name") && m_name.size()) { 47 if(((*it)=="name") && m_name.size()) { 48 if(a_sinfos.size()) a_sinfos += f_lf; 48 if(a_sinfos.size()) a_sinfos += f_lf; 49 a_sinfos += "Name\n"; 49 a_sinfos += "Name\n"; 50 a_sinfos += m_name; 50 a_sinfos += m_name; 51 } 51 } 52 } 52 } 53 } 53 } 54 public: //func1D 54 public: //func1D 55 virtual bool value(float a_x,float& a_v) con 55 virtual bool value(float a_x,float& a_v) const { 56 if(!m_data.in_domain(a_x)) {a_v = 0;return 56 if(!m_data.in_domain(a_x)) {a_v = 0;return false;} 57 a_v = (float)m_data.value(a_x); 57 a_v = (float)m_data.value(a_x); 58 return true; 58 return true; 59 } 59 } 60 60 61 virtual unsigned int x_steps() const {return 61 virtual unsigned int x_steps() const {return m_data.xdomain_number_of_steps();} 62 virtual float x_min() const {return (float)m 62 virtual float x_min() const {return (float)m_data.xdomain_min();} 63 virtual float x_max() const {return (float)m 63 virtual float x_max() const {return (float)m_data.xdomain_max();} 64 64 65 public: 65 public: 66 f1d2plot(const T& a_data):m_data(a_data){ 66 f1d2plot(const T& a_data):m_data(a_data){ 67 #ifdef TOOLS_MEM 67 #ifdef TOOLS_MEM 68 mem::increment(s_class().c_str()); 68 mem::increment(s_class().c_str()); 69 #endif 69 #endif 70 } 70 } 71 virtual ~f1d2plot(){ 71 virtual ~f1d2plot(){ 72 #ifdef TOOLS_MEM 72 #ifdef TOOLS_MEM 73 mem::decrement(s_class().c_str()); 73 mem::decrement(s_class().c_str()); 74 #endif 74 #endif 75 } 75 } 76 public: 76 public: 77 f1d2plot(const f1d2plot& a_from) 77 f1d2plot(const f1d2plot& a_from) 78 :plottable(a_from),func1D(a_from) 78 :plottable(a_from),func1D(a_from) 79 ,m_data(a_from.m_data) 79 ,m_data(a_from.m_data) 80 ,m_name(a_from.m_name) 80 ,m_name(a_from.m_name) 81 ,m_legend(a_from.m_legend) 81 ,m_legend(a_from.m_legend) 82 ,m_title(a_from.m_title) 82 ,m_title(a_from.m_title) 83 { 83 { 84 #ifdef TOOLS_MEM 84 #ifdef TOOLS_MEM 85 mem::increment(s_class().c_str()); 85 mem::increment(s_class().c_str()); 86 #endif 86 #endif 87 } 87 } 88 f1d2plot& operator=(const f1d2plot& a_from){ 88 f1d2plot& operator=(const f1d2plot& a_from){ 89 m_name = a_from.m_name; 89 m_name = a_from.m_name; 90 m_legend = a_from.m_legend; 90 m_legend = a_from.m_legend; 91 m_title = a_from.m_title; 91 m_title = a_from.m_title; 92 return *this; 92 return *this; 93 } 93 } 94 public: 94 public: 95 void set_title(const std::string& a_s) {m_ti 95 void set_title(const std::string& a_s) {m_title = a_s;} //for gopaw. 96 protected: 96 protected: 97 const T& m_data; 97 const T& m_data; 98 std::string m_name; 98 std::string m_name; 99 std::string m_legend; 99 std::string m_legend; 100 std::string m_title; 100 std::string m_title; 101 }; 101 }; 102 102 103 template <class T> 103 template <class T> 104 class f1d2plot_cp : public f1d2plot<T> { 104 class f1d2plot_cp : public f1d2plot<T> { 105 public: 105 public: 106 TOOLS_T_SCLASS(T,tools::sg::f1d2plot_cp) 106 TOOLS_T_SCLASS(T,tools::sg::f1d2plot_cp) 107 virtual void* cast(const std::string& a_clas 107 virtual void* cast(const std::string& a_class) const { 108 if(void* p = cmp_cast<f1d2plot_cp>(this,a_ 108 if(void* p = cmp_cast<f1d2plot_cp>(this,a_class)) {return p;} 109 return f1d2plot<T>::cast(a_class); 109 return f1d2plot<T>::cast(a_class); 110 } 110 } 111 public: 111 public: 112 f1d2plot_cp(const T& a_data) 112 f1d2plot_cp(const T& a_data) 113 :f1d2plot<T>(m_cp) 113 :f1d2plot<T>(m_cp) 114 ,m_cp(a_data) 114 ,m_cp(a_data) 115 {} 115 {} 116 virtual ~f1d2plot_cp(){} 116 virtual ~f1d2plot_cp(){} 117 public: 117 public: 118 f1d2plot_cp(const f1d2plot_cp& a_from) 118 f1d2plot_cp(const f1d2plot_cp& a_from) 119 :plottable(a_from) 119 :plottable(a_from) 120 ,func1D(a_from) 120 ,func1D(a_from) 121 ,f1d2plot<T>(m_cp) 121 ,f1d2plot<T>(m_cp) 122 ,m_cp(a_from.m_cp) 122 ,m_cp(a_from.m_cp) 123 {} 123 {} 124 f1d2plot_cp& operator=(const f1d2plot_cp& a_ 124 f1d2plot_cp& operator=(const f1d2plot_cp& a_from){ 125 f1d2plot<T>::operator=(a_from); 125 f1d2plot<T>::operator=(a_from); 126 m_cp = a_from.m_cp; 126 m_cp = a_from.m_cp; 127 return *this; 127 return *this; 128 } 128 } 129 protected: 129 protected: 130 T m_cp; 130 T m_cp; 131 }; 131 }; 132 132 133 template <class T> 133 template <class T> 134 class f2d2plot : public virtual func2D { 134 class f2d2plot : public virtual func2D { 135 public: 135 public: 136 TOOLS_T_SCLASS(T,tools::sg::f2d2plot) 136 TOOLS_T_SCLASS(T,tools::sg::f2d2plot) 137 virtual void* cast(const std::string& a_clas 137 virtual void* cast(const std::string& a_class) const { 138 if(void* p = cmp_cast<f2d2plot>(this,a_cla 138 if(void* p = cmp_cast<f2d2plot>(this,a_class)) {return p;} 139 return func2D::cast(a_class); 139 return func2D::cast(a_class); 140 } 140 } 141 public: //plottable 141 public: //plottable 142 virtual plottable* copy() const {return new 142 virtual plottable* copy() const {return new f2d2plot(*this);} 143 virtual bool is_valid() const {return true;} 143 virtual bool is_valid() const {return true;} 144 virtual const std::string& name() const {ret 144 virtual const std::string& name() const {return m_name;} 145 virtual void set_name(const std::string& a_s 145 virtual void set_name(const std::string& a_s) {m_name = a_s;} 146 virtual const std::string& title() const {re 146 virtual const std::string& title() const {return m_title;} 147 virtual const std::string& legend() const {r 147 virtual const std::string& legend() const {return m_legend;} 148 virtual void set_legend(const std::string& a 148 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 149 149 150 virtual void infos(const std::string& a_opts 150 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 151 a_sinfos.clear(); 151 a_sinfos.clear(); 152 std::string f_lf("\n"); 152 std::string f_lf("\n"); 153 std::vector<std::string> _words; 153 std::vector<std::string> _words; 154 words(a_opts," ",false,_words); 154 words(a_opts," ",false,_words); 155 tools_vforcit(std::string,_words,it) { 155 tools_vforcit(std::string,_words,it) { 156 if(((*it)=="name") && m_name.size()) { 156 if(((*it)=="name") && m_name.size()) { 157 if(a_sinfos.size()) a_sinfos += f_lf; 157 if(a_sinfos.size()) a_sinfos += f_lf; 158 a_sinfos += "Name\n"; 158 a_sinfos += "Name\n"; 159 a_sinfos += m_name; 159 a_sinfos += m_name; 160 } 160 } 161 } 161 } 162 } 162 } 163 public: //func2D 163 public: //func2D 164 virtual bool value(float a_x,float a_y,float 164 virtual bool value(float a_x,float a_y,float& a_v) const { 165 if(!m_data.in_domain(a_x,a_y)) {a_v = 0;re 165 if(!m_data.in_domain(a_x,a_y)) {a_v = 0;return false;} 166 a_v = (float)m_data.value(a_x,a_y); 166 a_v = (float)m_data.value(a_x,a_y); 167 return true; 167 return true; 168 } 168 } 169 169 170 virtual unsigned int x_steps() const {return 170 virtual unsigned int x_steps() const {return m_data.xdomain_number_of_steps();} 171 virtual float x_min() const {return m_data.x 171 virtual float x_min() const {return m_data.xdomain_min();} 172 virtual float x_max() const {return m_data.x 172 virtual float x_max() const {return m_data.xdomain_max();} 173 virtual unsigned int y_steps() const {return 173 virtual unsigned int y_steps() const {return m_data.ydomain_number_of_steps();} 174 virtual float y_min() const {return m_data.y 174 virtual float y_min() const {return m_data.ydomain_min();} 175 virtual float y_max() const {return m_data.y 175 virtual float y_max() const {return m_data.ydomain_max();} 176 public: 176 public: 177 f2d2plot(const T& a_data):m_data(a_data){ 177 f2d2plot(const T& a_data):m_data(a_data){ 178 #ifdef TOOLS_MEM 178 #ifdef TOOLS_MEM 179 mem::increment(s_class().c_str()); 179 mem::increment(s_class().c_str()); 180 #endif 180 #endif 181 } 181 } 182 virtual ~f2d2plot(){ 182 virtual ~f2d2plot(){ 183 #ifdef TOOLS_MEM 183 #ifdef TOOLS_MEM 184 mem::decrement(s_class().c_str()); 184 mem::decrement(s_class().c_str()); 185 #endif 185 #endif 186 } 186 } 187 public: 187 public: 188 f2d2plot(const f2d2plot& a_from) 188 f2d2plot(const f2d2plot& a_from) 189 :plottable(a_from),func2D(a_from) 189 :plottable(a_from),func2D(a_from) 190 ,m_data(a_from.m_data) 190 ,m_data(a_from.m_data) 191 ,m_name(a_from.m_name) 191 ,m_name(a_from.m_name) 192 ,m_legend(a_from.m_legend) 192 ,m_legend(a_from.m_legend) 193 ,m_title(a_from.m_title) 193 ,m_title(a_from.m_title) 194 { 194 { 195 #ifdef TOOLS_MEM 195 #ifdef TOOLS_MEM 196 mem::increment(s_class().c_str()); 196 mem::increment(s_class().c_str()); 197 #endif 197 #endif 198 } 198 } 199 f2d2plot& operator=(const f2d2plot& a_from){ 199 f2d2plot& operator=(const f2d2plot& a_from){ 200 m_name = a_from.m_name; 200 m_name = a_from.m_name; 201 m_legend = a_from.m_legend; 201 m_legend = a_from.m_legend; 202 m_title = a_from.m_title; 202 m_title = a_from.m_title; 203 return *this; 203 return *this; 204 } 204 } 205 public: 205 public: 206 void set_title(const std::string& a_s) {m_ti 206 void set_title(const std::string& a_s) {m_title = a_s;} //for gopaw. 207 protected: 207 protected: 208 const T& m_data; 208 const T& m_data; 209 std::string m_name; 209 std::string m_name; 210 std::string m_legend; 210 std::string m_legend; 211 std::string m_title; 211 std::string m_title; 212 }; 212 }; 213 213 214 template <class T> 214 template <class T> 215 class f2d2plot_cp : public f2d2plot<T> { 215 class f2d2plot_cp : public f2d2plot<T> { 216 public: 216 public: 217 TOOLS_T_SCLASS(T,tools::sg::f2d2plot_cp) 217 TOOLS_T_SCLASS(T,tools::sg::f2d2plot_cp) 218 virtual void* cast(const std::string& a_clas 218 virtual void* cast(const std::string& a_class) const { 219 if(void* p = cmp_cast<f2d2plot_cp>(this,a_ 219 if(void* p = cmp_cast<f2d2plot_cp>(this,a_class)) {return p;} 220 return f2d2plot<T>::cast(a_class); 220 return f2d2plot<T>::cast(a_class); 221 } 221 } 222 public: 222 public: 223 f2d2plot_cp(const T& a_data) 223 f2d2plot_cp(const T& a_data) 224 :f2d2plot<T>(m_cp) 224 :f2d2plot<T>(m_cp) 225 ,m_cp(a_data) 225 ,m_cp(a_data) 226 {} 226 {} 227 virtual ~f2d2plot_cp(){} 227 virtual ~f2d2plot_cp(){} 228 public: 228 public: 229 f2d2plot_cp(const f2d2plot_cp& a_from) 229 f2d2plot_cp(const f2d2plot_cp& a_from) 230 :plottable(a_from) 230 :plottable(a_from) 231 ,func2D(a_from) 231 ,func2D(a_from) 232 ,f2d2plot<T>(m_cp) 232 ,f2d2plot<T>(m_cp) 233 ,m_cp(a_from.m_cp) 233 ,m_cp(a_from.m_cp) 234 {} 234 {} 235 f2d2plot_cp& operator=(const f2d2plot_cp& a_ 235 f2d2plot_cp& operator=(const f2d2plot_cp& a_from){ 236 f2d2plot<T>::operator=(a_from); 236 f2d2plot<T>::operator=(a_from); 237 m_cp = a_from.m_cp; 237 m_cp = a_from.m_cp; 238 return *this; 238 return *this; 239 } 239 } 240 protected: 240 protected: 241 T m_cp; 241 T m_cp; 242 }; 242 }; 243 243 244 }} 244 }} 245 245 246 #endif 246 #endif