Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 3 4 #ifndef tools_sg_plottables 5 #define tools_sg_plottables 6 7 #include "plottable" 8 #include "enums" 9 10 namespace tools { 11 namespace sg { 12 13 class bins1D : public virtual plottable { 14 public: 15 TOOLS_SCLASS(tools::sg::bins1D) 16 public: 17 virtual void* cast(const std::string& a_class) const { 18 if(void* p = cmp_cast<bins1D>(this,a_class)) {return p;} 19 return plottable::cast(a_class); 20 } 21 public: 22 virtual ~bins1D(){} 23 public: 24 virtual void bins_Sw_range(float&,float&,bool) const = 0; 25 public: 26 // axis : 27 virtual unsigned int bins() const = 0; 28 virtual float axis_min() const = 0; 29 virtual float axis_max() const = 0; 30 // bins on axis : 31 virtual float bin_lower_edge(int) const = 0; 32 virtual float bin_upper_edge(int) const = 0; 33 // bins : 34 virtual bool has_entries_per_bin() const = 0; 35 virtual unsigned int bin_entries(int) const = 0; 36 virtual float bin_Sw(int) const = 0; 37 virtual float bin_error(int) const = 0; 38 public: 39 virtual bool is_profile() const = 0; 40 }; 41 42 class bins2D : public virtual plottable { 43 public: 44 TOOLS_SCLASS(tools::sg::bins2D) 45 public: 46 virtual void* cast(const std::string& a_class) const { 47 if(void* p = cmp_cast<bins2D>(this,a_class)) {return p;} 48 return plottable::cast(a_class); 49 } 50 public: 51 virtual ~bins2D(){} 52 public: 53 virtual void bins_Sw_range(float&,float&,bool) const = 0; 54 public: 55 // x axis : 56 virtual unsigned int x_bins() const = 0; 57 virtual float x_axis_min() const = 0; 58 virtual float x_axis_max() const = 0; 59 // y axis : 60 virtual unsigned int y_bins() const = 0; 61 virtual float y_axis_min() const = 0; 62 virtual float y_axis_max() const = 0; 63 // bins on x axis : 64 virtual float bin_lower_edge_x(int) const = 0; 65 virtual float bin_upper_edge_x(int) const = 0; 66 // bins on y axis : 67 virtual float bin_lower_edge_y(int) const = 0; 68 virtual float bin_upper_edge_y(int) const = 0; 69 // bins : 70 virtual bool has_entries_per_bin() const = 0; 71 virtual unsigned int bin_entries(int,int) const = 0; 72 virtual float bin_Sw(int,int) const = 0; 73 virtual float bin_error(int,int) const = 0; 74 }; 75 76 class func1D : public virtual plottable { 77 public: 78 TOOLS_SCLASS(tools::sg::func1D) 79 public: 80 virtual void* cast(const std::string& a_class) const { 81 if(void* p = cmp_cast<func1D>(this,a_class)) {return p;} 82 return plottable::cast(a_class); 83 } 84 public: 85 virtual ~func1D(){} 86 public: 87 virtual bool value(float,float&) const = 0; 88 virtual unsigned int x_steps() const = 0; 89 virtual float x_min() const = 0; 90 virtual float x_max() const = 0; 91 }; 92 93 class func2D : public virtual plottable { 94 public: 95 TOOLS_SCLASS(tools::sg::func2D) 96 public: 97 virtual void* cast(const std::string& a_class) const { 98 if(void* p = cmp_cast<func2D>(this,a_class)) {return p;} 99 return plottable::cast(a_class); 100 } 101 public: 102 virtual ~func2D(){} 103 public: 104 virtual bool value(float,float,float&) const = 0; 105 virtual unsigned int x_steps() const = 0; 106 virtual float x_min() const = 0; 107 virtual float x_max() const = 0; 108 virtual unsigned int y_steps() const = 0; 109 virtual float y_min() const = 0; 110 virtual float y_max() const = 0; 111 /* 112 //For "inside" functions : 113 virtual unsigned int number_of_points() const = 0; 114 virtual bool ith_point(int,float&,float&,bool&) const = 0; 115 virtual bool set_ith_point(int,float,float) = 0; 116 virtual bool dragger_update_points() const = 0; 117 */ 118 }; 119 120 class points2D : public virtual plottable { 121 public: 122 TOOLS_SCLASS(tools::sg::points2D) 123 public: 124 virtual void* cast(const std::string& a_class) const { 125 if(void* p = cmp_cast<points2D>(this,a_class)) {return p;} 126 return plottable::cast(a_class); 127 } 128 public: 129 virtual ~points2D(){} 130 public: 131 virtual float x_axis_min() const = 0; 132 virtual float x_axis_max() const = 0; 133 virtual float y_axis_min() const = 0; 134 virtual float y_axis_max() const = 0; 135 136 virtual unsigned int points() const = 0; 137 virtual bool ith_point(unsigned int,float&,float&) const = 0; 138 }; 139 140 class points3D : public virtual plottable { 141 public: 142 TOOLS_SCLASS(tools::sg::points3D) 143 public: 144 virtual void* cast(const std::string& a_class) const { 145 if(void* p = cmp_cast<points3D>(this,a_class)) {return p;} 146 return plottable::cast(a_class); 147 } 148 public: 149 virtual ~points3D(){} 150 public: 151 virtual float x_axis_min() const = 0; 152 virtual float x_axis_max() const = 0; 153 virtual float y_axis_min() const = 0; 154 virtual float y_axis_max() const = 0; 155 virtual float z_axis_min() const = 0; 156 virtual float z_axis_max() const = 0; 157 158 virtual unsigned int points() const = 0; 159 virtual bool ith_point(unsigned int,float&,float&,float&) const = 0; 160 }; 161 162 inline const std::string& s_tools_sg_fit2plot() { 163 static const std::string s_v("tools::sg::fit2plot"); 164 return s_v; 165 } 166 167 }} 168 169 //////////////////////////////////////////////////////////////////////////////// 170 /// primitives : /////////////////////////////////////////////////////////////// 171 //////////////////////////////////////////////////////////////////////////////// 172 #include "../colorf" 173 174 namespace tools { 175 namespace sg { 176 177 class plottable_text : public virtual plotprim { 178 typedef plotprim parent; 179 public: 180 TOOLS_SCLASS(plottable_text) 181 public: //tools::sg::plotprim 182 virtual void* cast(const std::string& a_class) const { 183 if(void* p = cmp_cast<plottable_text>(this,a_class)) {return p;} 184 return 0; 185 } 186 virtual plotprim* copy() const {return new plottable_text(*this);} 187 public: 188 enum text_mode { 189 text_as_it, 190 text_enforce_width, 191 text_enforce_height 192 }; 193 public: 194 plottable_text(const std::string& a_TEXT,float a_X,float a_Y, 195 float a_SIZE,text_mode a_text_mode, 196 /* 197 float a_ANGLE = 0, 198 char a_HJUST = 'L',char a_VJUST = 'B', 199 const std::string& a_FONT = "Hershey",const colorf& a_TXCI = colorf(0,0,0,1), 200 float a_SCALE = 1,bool a_SMOOTHING = false,bool a_HINTING = false,float a_line_width = 1, 201 font_modeling a_font_modeling = font_filled 202 */ 203 float a_ANGLE, 204 char a_HJUST,char a_VJUST, 205 const std::string& a_FONT,const colorf& a_TXCI, 206 float a_SCALE,bool a_SMOOTHING,bool a_HINTING,float a_line_width, 207 font_modeling a_font_modeling 208 ) 209 :m_TEXT(a_TEXT),m_X(a_X),m_Y(a_Y) 210 ,m_SIZE(a_SIZE),m_text_mode(a_text_mode) 211 ,m_ANGLE(a_ANGLE) 212 ,m_HJUST(a_HJUST) 213 ,m_VJUST(a_VJUST) 214 ,m_FONT(a_FONT),m_TXCI(a_TXCI) 215 ,m_SCALE(a_SCALE),m_SMOOTHING(a_SMOOTHING),m_HINTING(a_HINTING),m_line_width(a_line_width) 216 ,m_font_modeling(a_font_modeling) 217 {} 218 public: 219 plottable_text(const plottable_text& a_from) 220 :parent(a_from) 221 ,m_TEXT(a_from.m_TEXT) 222 ,m_X(a_from.m_X),m_Y(a_from.m_Y) 223 ,m_SIZE(a_from.m_SIZE),m_text_mode(a_from.m_text_mode) 224 ,m_ANGLE(a_from.m_ANGLE) 225 ,m_HJUST(a_from.m_HJUST) 226 ,m_VJUST(a_from.m_VJUST) 227 ,m_FONT(a_from.m_FONT),m_TXCI(a_from.m_TXCI) 228 ,m_SCALE(a_from.m_SCALE),m_SMOOTHING(a_from.m_SMOOTHING),m_HINTING(a_from.m_HINTING),m_line_width(a_from.m_line_width) 229 ,m_font_modeling(a_from.m_font_modeling) 230 {} 231 plottable_text& operator=(const plottable_text& a_from) { 232 m_TEXT = a_from.m_TEXT; 233 m_X = a_from.m_X; 234 m_Y = a_from.m_Y; 235 m_SIZE = a_from.m_SIZE; 236 m_text_mode = a_from.m_text_mode; 237 m_ANGLE = a_from.m_ANGLE; 238 m_HJUST = a_from.m_HJUST; 239 m_VJUST = a_from.m_VJUST; 240 m_FONT = a_from.m_FONT; 241 m_TXCI = a_from.m_TXCI; 242 m_SCALE = a_from.m_SCALE; 243 m_SMOOTHING = a_from.m_SMOOTHING; 244 m_HINTING = a_from.m_HINTING; 245 m_line_width = a_from.m_line_width; 246 m_font_modeling = a_from.m_font_modeling; 247 return *this; 248 } 249 public: 250 std::string m_TEXT; 251 float m_X; 252 float m_Y; 253 float m_SIZE; 254 text_mode m_text_mode; 255 float m_ANGLE; 256 char m_HJUST; 257 char m_VJUST; 258 std::string m_FONT; 259 colorf m_TXCI; 260 float m_SCALE; 261 bool m_SMOOTHING; 262 bool m_HINTING; 263 float m_line_width; //used if font is hershey. 264 font_modeling m_font_modeling; 265 }; 266 267 class plottable_box : public virtual plotprim { 268 typedef plotprim parent; 269 public: 270 TOOLS_SCLASS(plottable_box) 271 public: //tools::sg::plotprim 272 virtual void* cast(const std::string& a_class) const { 273 if(void* p = cmp_cast<plottable_box>(this,a_class)) {return p;} 274 return 0; 275 } 276 virtual plotprim* copy() const {return new plottable_box(*this);} 277 public: 278 enum fill_area_style { 279 HOLLOW = 0, 280 SOLID = 1, 281 PATTERN = 2, 282 HATCHED = 3 283 }; 284 public: 285 plottable_box(float a_X1,float a_Y1,float a_X2,float a_Y2, 286 fill_area_style a_FAIS,const colorf& a_FACI, 287 int a_FASI, 288 bool a_BORD,const colorf& a_PLCI,float a_LWID) 289 :m_X1(a_X1),m_Y1(a_Y1),m_X2(a_X2),m_Y2(a_Y2) 290 ,m_FAIS(a_FAIS),m_FACI(a_FACI),m_FASI(a_FASI),m_BORD(a_BORD),m_PLCI(a_PLCI),m_LWID(a_LWID) 291 {} 292 public: 293 plottable_box(const plottable_box& a_from) 294 :parent(a_from) 295 ,m_X1(a_from.m_X1),m_Y1(a_from.m_Y1) 296 ,m_X2(a_from.m_X2),m_Y2(a_from.m_Y2) 297 ,m_FAIS(a_from.m_FAIS),m_FACI(a_from.m_FACI),m_FASI(a_from.m_FASI),m_BORD(a_from.m_BORD),m_PLCI(a_from.m_PLCI) 298 ,m_LWID(a_from.m_LWID) 299 {} 300 plottable_box& operator=(const plottable_box& a_from) { 301 m_X1 = a_from.m_X1; 302 m_Y1 = a_from.m_Y1; 303 m_X2 = a_from.m_X2; 304 m_Y2 = a_from.m_Y2; 305 m_FAIS = a_from.m_FAIS; 306 m_FACI = a_from.m_FACI; 307 m_FASI = a_from.m_FASI; 308 m_BORD = a_from.m_BORD; 309 m_PLCI = a_from.m_PLCI; 310 m_LWID = a_from.m_LWID; 311 return *this; 312 } 313 public: 314 float m_X1; 315 float m_Y1; 316 float m_X2; 317 float m_Y2; 318 fill_area_style m_FAIS; 319 colorf m_FACI; 320 int m_FASI; 321 bool m_BORD; 322 colorf m_PLCI; 323 float m_LWID; 324 }; 325 326 class plottable_ellipse : public virtual plotprim { 327 typedef plotprim parent; 328 public: 329 TOOLS_SCLASS(plottable_ellipse) 330 public: //tools::sg::plotprim 331 virtual void* cast(const std::string& a_class) const { 332 if(void* p = cmp_cast<plottable_ellipse>(this,a_class)) {return p;} 333 return 0; 334 } 335 virtual plotprim* copy() const {return new plottable_ellipse(*this);} 336 public: 337 enum fill_area_style { 338 HOLLOW = 0, 339 SOLID = 1, 340 PATTERN = 2, 341 HATCHED = 3 342 }; 343 public: 344 plottable_ellipse(float a_X,float a_Y,float a_R1,float a_R2, 345 fill_area_style a_FAIS,const colorf& a_FACI, 346 int a_FASI, 347 bool a_BORD,const colorf& a_PLCI,float a_LWID) 348 :m_X(a_X),m_Y(a_Y),m_R1(a_R1),m_R2(a_R2) 349 ,m_FAIS(a_FAIS),m_FACI(a_FACI),m_FASI(a_FASI),m_BORD(a_BORD),m_PLCI(a_PLCI),m_LWID(a_LWID) 350 {} 351 public: 352 plottable_ellipse(const plottable_ellipse& a_from) 353 :parent(a_from) 354 ,m_X(a_from.m_X),m_Y(a_from.m_Y) 355 ,m_R1(a_from.m_R1),m_R2(a_from.m_R2) 356 ,m_FAIS(a_from.m_FAIS),m_FACI(a_from.m_FACI),m_FASI(a_from.m_FASI),m_BORD(a_from.m_BORD),m_PLCI(a_from.m_PLCI) 357 ,m_LWID(a_from.m_LWID) 358 {} 359 plottable_ellipse& operator=(const plottable_ellipse& a_from) { 360 m_X = a_from.m_X; 361 m_Y = a_from.m_Y; 362 m_R1 = a_from.m_R1; 363 m_R2 = a_from.m_R2; 364 m_FAIS = a_from.m_FAIS; 365 m_FACI = a_from.m_FACI; 366 m_FASI = a_from.m_FASI; 367 m_BORD = a_from.m_BORD; 368 m_PLCI = a_from.m_PLCI; 369 m_LWID = a_from.m_LWID; 370 return *this; 371 } 372 public: 373 float m_X; 374 float m_Y; 375 float m_R1; 376 float m_R2; 377 fill_area_style m_FAIS; 378 colorf m_FACI; 379 int m_FASI; 380 bool m_BORD; 381 colorf m_PLCI; 382 float m_LWID; 383 }; 384 385 }} 386 387 #include "../img" 388 #include "../typedefs" 389 390 namespace tools { 391 namespace sg { 392 393 class plottable_img : public virtual plotprim { 394 typedef plotprim parent; 395 public: 396 TOOLS_SCLASS(plottable_img) 397 public: //tools::sg::plotprim 398 virtual void* cast(const std::string& a_class) const { 399 if(void* p = cmp_cast<plottable_img>(this,a_class)) {return p;} 400 return 0; 401 } 402 virtual plotprim* copy() const {return new plottable_img(*this);} 403 public: 404 plottable_img(const img<byte>& a_img,float a_X,float a_Y,float a_WIDTH,float a_HEIGHT,float a_THETA,float a_PHI) 405 :m_img(a_img) 406 ,m_X(a_X),m_Y(a_Y) 407 ,m_WIDTH(a_WIDTH),m_HEIGHT(a_HEIGHT),m_THETA(a_THETA),m_PHI(a_PHI) 408 {} 409 public: 410 plottable_img(const plottable_img& a_from) 411 :parent(a_from) 412 ,m_img(a_from.m_img) 413 ,m_X(a_from.m_X),m_Y(a_from.m_Y) 414 ,m_WIDTH(a_from.m_WIDTH),m_HEIGHT(a_from.m_HEIGHT),m_THETA(a_from.m_THETA),m_PHI(a_from.m_PHI) 415 {} 416 plottable_img& operator=(const plottable_img& a_from) { 417 m_img = a_from.m_img; 418 m_X = a_from.m_X; 419 m_Y = a_from.m_Y; 420 m_WIDTH = a_from.m_WIDTH; 421 m_HEIGHT = a_from.m_HEIGHT; 422 m_THETA = a_from.m_THETA; 423 m_PHI = a_from.m_PHI; 424 return *this; 425 } 426 public: 427 img<byte> m_img; 428 float m_X; 429 float m_Y; 430 float m_WIDTH; 431 float m_HEIGHT; 432 float m_THETA; 433 float m_PHI; 434 }; 435 436 }} 437 438 439 #endif