libpgplotxx.a (C++ interface to PGPLOT)
xpgplotxx.h
Go to the documentation of this file.
1 
44 // include guard
45 #ifndef TF_XPGPLOTCPP_H_VERSION
46 
47 #define TF_XPGPLOTCPP_H_VERSION \
48  "TF_XPGPLOTCPP_H V1.7 (17-03-2015)"
49 
50 #include<pgplotxx/pgplotxx.h>
51 
52 namespace pgplot {
53 
59 
68  class Tlinestyle {
69  public:
71  enum Eflags {
72  Fnone=0, Fls=1, Flw=2, Fci=4, Frgb=8, Fhls=16
73  };
76  Mls(1), Mci(1), Mlw(1), Mflags(Fnone) { }
78  Tlinestyle(const int& lw):
79  Mls(1), Mci(1), Mlw(lw), Mflags(Flw) { }
81  Tlinestyle(const int& lw, const int& ls):
82  Mls(ls), Mci(1), Mlw(lw), Mflags(Flw|Fls) { }
84  Tlinestyle(const int& lw, const int& ls, const int& ci):
85  Mls(ls), Mci(ci), Mlw(lw), Mflags(Flw|Fls|Fci) { }
87 
88  Tlinestyle& setlw(const int& lw)
90  { Mflags=(Mflags | Flw); Mlw=lw; return(*this); }
92  Tlinestyle& setls(const int& ls)
93  { Mflags=(Mflags | Fls); Mls=ls; return(*this); }
95  Tlinestyle& setci(const int& ci)
96  { Mflags=(Mflags | Fci); Mci=ci; return(*this); }
98  Tlinestyle& sethls(const Tcol& hls);
100  Tlinestyle& setrgb(const Tcol& rgb);
102  Tlinestyle& clw() { Mflags &= (!Flw); return(*this); }
104  Tlinestyle& cls() { Mflags &= (!Fls); return(*this); }
106  Tlinestyle& cci() { Mflags &= (!Fci); return(*this); }
108  Tlinestyle& ccr() { Mflags &= (!(Frgb|Fhls)); return(*this); }
110 
112  bool operator!=(const Tlinestyle& ls) const;
113 
115  template<class T>
116  T& operator()(T& dev) const
117  { apply(dev); return(dev); }
118  private:
120  void apply(basic_device& dev) const;
121 
123  int Mls;
125  int Mci;
127  int Mlw;
129  int Mflags;
132  }; // class Tlinestyle
133 
135  inline bool operator==(const Tlinestyle& a, const Tlinestyle& b)
136  { return(!(a!=b)); }
137 
138  /*----------------------------------------------------------------------*/
139 
141  class Ttiledpanels;
142 
149  class Tpanel {
151  friend class Ttiledpanels;
152  public:
159  Tpanel(const Trect& win,
160  const Trect& tvp=Trect(0.,1.,0.,1.),
161  const Trect& vp=Trect(0.1,0.9,0.1,0.9)):
162  Mvp(tvp), Mtvp(tvp), Mwin(win)
163  { setvp(vp); }
172  Tpanel(const Tpanel& ref,
173  const Trect& win,
174  const Trect& tvp=Trect(0.,1.,0.,1.),
175  const Trect& vp=Trect(0.1,0.9,0.1,0.9)):
176  Mvp(ref.Mtvp), Mtvp(ref.Mtvp), Mwin(win)
177  { Mtvp.shrinkf(tvp); Mvp=Mtvp; setvp(vp); }
179  Tpanel& setvp(const Trect& vp)
180  { Mvp=Mtvp; Mvp.shrinkf(vp); return(*this); }
182  Tpanel& settvp(const Trect& tvp)
183  { Mtvp=tvp; return(*this); }
185  Tpanel& setwin(const Trect& win)
186  { Mwin=win; return(*this); }
188  Trect getvp() const { return(Mvp); }
190  Trect gettvp() const { return(Mtvp); }
192  Trect getwin() const { return(Mwin); }
194  template <class T>
195  T& operator()(T& dev) const
196  {
197  dev.svp(Mvp);
198  dev.swin(Mwin);
199  return(dev);
200  }
202  template <class T>
203  T& erase(T& dev) const
204  {
205  dev.svp(Mtvp);
206  int fs=dev.qfs();
207  int ci=dev.qci();
208  dev.sfs(1);
209  dev.sci(0);
210  dev.rect(Mwin);
211  dev.sfs(fs);
212  dev.sci(ci);
213  return(this->operator()(dev));
214  }
215  protected:
218  Mvp(Trect(0.,1.,0.,1.)), Mtvp(Trect(0.,1.,0.,1.)),
219  Mwin(Trect(0.,1.,0.,1.))
220  { }
221  // private:
228  }; // class Tpanel
229 
230  /*----------------------------------------------------------------------*/
231 
238  class Ttiledpanels {
239  public:
248  Ttiledpanels(const Tpanel& panel, const Trect& svp, const Trect& win,
249  const int& nx, const int& ny):
250  Mvp(panel.Mtvp), Mnx(nx), Mny(ny), Mpanels(0)
251  { this->setup(svp, win, nx, ny); }
260  Ttiledpanels(const Trect& vp, const Trect& svp, const Trect& win,
261  const int& nx, const int& ny):
262  Mvp(vp), Mnx(nx), Mny(ny), Mpanels(0)
263  { this->setup(svp, win, nx, ny); }
270  Ttiledpanels(const Ttiledpanels& panels);
272  ~Ttiledpanels();
274  int nxsub() const { return(Mnx); }
276  int nysub() const { return(Mny); }
278  Tpanel& operator()(const int& ix, const int& iy);
285  Ttiledpanels& operator=(const Ttiledpanels& panels);
286  private:
288  void setup(const Trect& svp, const Trect& win,
289  const int& nx, const int& ny);
293  int Mnx, Mny;
296  }; // class Ttiledpanels
297 
298  /*----------------------------------------------------------------------*/
299 
301  namespace boxflags {
307  enum Eelem { Fnone=0,
311  Faxis=2,
313  Fgrid=4,
327  Fxtime=128,
329  Fytime=256
330  }; // enum Eelem
331 
337  enum Emodes {
339 
340  Fselect=1, Fxselect=1, Fhselect=1, Flselect=1,
353 
355 
356  Fticksinvert=16,
365 
367 
368  Flabelopp=16,
379 
381 
382  Ftimenoday=16,
395 
398  }; // enum Emodes
399  } // namespace boxflags
400 
451  class Tboxstyle {
452  public:
458  Tboxstyle(const bool& tbox=false);
460 
461 
468  Tboxstyle& setmode(const int& elem, const int& modes,
469  const bool& set=true);
471  Tboxstyle& setstyle(const int& elem, const Tlinestyle& style);
473  Tboxstyle& setxtickint(const int& minor=0, const float& major=0.)
474  { Mxtick=major; Mxticksub=minor; return(*this); }
476  Tboxstyle& setytickint(const int& minor=0, const float& major=0.)
477  { Mytick=major; Myticksub=minor; return(*this); }
479 
481  template<class T>
482  T& operator()(T& dev) const
483  { apply(dev); return(dev); }
484  private:
486  void apply(basic_device& dev) const;
488  void issuecommand(basic_device& dev,
489  const Tlinestyle& linestyle,
490  const char* xopt,
491  const char* yopt) const;
492 
494 
495  int Mgridflags;
500 
502 
503  int Mframeflags;
508 
510 
511  int Maxisflags;
516 
518 
522  float Mxtick, Mytick;
528 
530 
536 
538 
539  bool Mtbox;
544  }; // class Tboxstyle
545 
546  /*----------------------------------------------------------------------*/
547 
557  class Ttext {
558  public:
560  Ttext(): Mxref(0.), Myref(0.), Mangle(0.), Mjust(0.),
561  Mxnl(0.), Mynl(0.), Minline(false) { }
571  Ttext(const float& x, const float& y, const float& angle=0.,
572  const float& just=0.):
573  Mxref(x), Myref(y), Mangle(angle), Mjust(just), Mxnl(0.),
574  Mynl(0.), Minline(false), Merase(false) { }
582  Ttext& print(basic_device& dev, const char* txt,
583  const bool& nl=false, const float& sep=0.025);
588  Tbbox bbox() const { return(Mbbox); }
590  void erase() { Merase=true; }
592  void noerase() { Merase=false; }
594  Ttext& space(basic_device& dev);
595  private:
597  void advance(const float* xbox,
598  const float* ybox,
599  const bool& nl,
600  const float& sep);
601  float Mxref, Myref;
602  float Mangle, Mjust;
603  float Mxnl, Mynl;
604  bool Minline;
606  bool Merase;
607  }; // class Ttext
608 
610 
611  //*======================================================================*/
612  /* \name constants
613  *
614  */
623 
624  /*======================================================================*/
625  /* \name extension functions
626  *
627  * Functions extending the PGPLOT functionality
628  */
630 
641  template<class S>
642  Trange find_series_range(const S& series)
643  {
644  typename S::BrowserT iter=series;
645  float value(*iter);
646  Trange result(value,value);
647  while (iter.hot())
648  {
649  value=(*iter);
650  result.min=(result.min > value ? value : result.min);
651  result.max=(result.max < value ? value : result.max);
652  ++iter;
653  }
654  return(result);
655  }
656 
678  template<class T, class SX, class SY>
679  T& series_line(T& dev, const SX& x, const SY& y)
680  {
681  typename SX::BrowserT ix=x;
682  typename SY::BrowserT iy=y;
683  float fx=float(*ix);
684  float fy=float(*iy);
685  dev.move(fx, fy);
686  while ((ix.hot()) && (iy.hot()))
687  { fx=float(*ix); fy=float(*iy); dev.draw(fx, fy); ++ix; ++iy; }
688  return(dev);
689  }
690 
694  enum Eerrdir {
707  };
708 
733  template<class T, class SX, class SY, class SE>
734  T& series_errb(T& dev, const SX& x, const SY& y, const SE& e,
735  const Eerrdir& dir=Fdirver, const float& t=1.)
736  {
737  typename SX::BrowserT ix=x;
738  typename SY::BrowserT iy=y;
739  typename SE::BrowserT ie=e;
740  float fx=float(*ix);
741  float fy=float(*iy);
742  float fe=float(*ie);
743  int idir=int(dir);
744  while ((ix.hot()) && (iy.hot()) && (ie.hot()))
745  { fx=float(*ix); fy=float(*iy); fe=float(*ie);
746  dev.err1(idir, fx, fy, fe, t); ++ix; ++iy; ++ie; }
747  return(dev);
748  }
749 
752 } // namespace pgplot
753 
754 #endif // TF_XPGPLOTCPP_H_VERSION (includeguard)
755 
756 /* ----- END OF xpgplotxx.h ----- */
Trect getvp() const
return viewport
Definition: xpgplotxx.h:188
yselect, vselect, rselect (y, vertical, right)
Definition: xpgplotxx.h:343
bool Mtbox
is a TBOX
Definition: xpgplotxx.h:540
int Mytimeflags
is a TBOX
Definition: xpgplotxx.h:542
Tlinestyle Maxisstyle
axis linestyle
Definition: xpgplotxx.h:514
Tlinestyle Mframestyle
frame linestyle
Definition: xpgplotxx.h:506
int Mlw
line width
Definition: xpgplotxx.h:127
Trect Mwin
world coordinates
Definition: xpgplotxx.h:227
Tlinestyle & sethls(const Tcol &hls)
set color representation with hls values
Definition: xpgplotxx.cc:85
Trange c_range19(0.1, 0.9)
range form 0.1 to 0.9
Definition: xpgplotxx.h:618
panel area
Definition: xpgplotxx.h:149
box style
Definition: xpgplotxx.h:451
int Mxtickflags
tick options
Definition: xpgplotxx.h:520
+x (x to x+e)
Definition: xpgplotxx.h:696
-y (y to y-e)
Definition: xpgplotxx.h:702
int nysub() const
return number of x-subpanels
Definition: xpgplotxx.h:276
Ttiledpanels(const Tpanel &panel, const Trect &svp, const Trect &win, const int &nx, const int &ny)
Definition: xpgplotxx.h:248
opposite (labels)
Definition: xpgplotxx.h:369
T & erase(T &dev) const
erase panel area
Definition: xpgplotxx.h:203
int nxsub() const
return number of x-subpanels
Definition: xpgplotxx.h:274
contains all pgplot stuff
Definition: affpgplot.cc:46
hold bounding box for text etc.
Definition: structs.h:204
Tpanel(const Trect &win, const Trect &tvp=Trect(0., 1., 0., 1.), const Trect &vp=Trect(0.1, 0.9, 0.1, 0.9))
Definition: xpgplotxx.h:159
+y (y to y+e)
Definition: xpgplotxx.h:698
int Mgridflags
has grid
Definition: xpgplotxx.h:496
text plotting tool.
Definition: xpgplotxx.h:557
Eflags
flags indicating the setting used
Definition: xpgplotxx.h:71
setting selection flags
Definition: xpgplotxx.h:343
-x (x to x-e)
Definition: xpgplotxx.h:700
Tbbox Mbbox
place to store bounding box of print function
Definition: xpgplotxx.h:605
int Mxlabelflags
label options
Definition: xpgplotxx.h:532
Tboxstyle & setytickint(const int &minor=0, const float &major=0.)
set y-ticks interval
Definition: xpgplotxx.h:476
Trect Mtvp
total viewport including labels
Definition: xpgplotxx.h:225
int Mls
line style
Definition: xpgplotxx.h:123
+/-x (x-e to x+e)
Definition: xpgplotxx.h:704
void setup(const Trect &svp, const Trect &win, const int &nx, const int &ny)
function used by constructors
Definition: xpgplotxx.cc:128
T & series_errb(T &dev, const SX &x, const SY &y, const SE &e, const Eerrdir &dir=Fdirver, const float &t=1.)
draw error bars from series
Definition: xpgplotxx.h:734
Tpanel & setwin(const Trect &win)
set world coordinates
Definition: xpgplotxx.h:185
hold any parameter range
Definition: structs.h:42
multipanel area
Definition: xpgplotxx.h:238
T & operator()(T &dev) const
use in device context
Definition: xpgplotxx.h:195
major (tick marks)
Definition: xpgplotxx.h:361
T & series_line(T &dev, const SX &x, const SY &y)
draw an open polygon from a dense series
Definition: xpgplotxx.h:679
int Mnx
number of subpanels
Definition: xpgplotxx.h:293
C++ interface for PGPLOT.
Tpanel()
default constructor
Definition: xpgplotxx.h:217
logarithmic scale (labels)
Definition: xpgplotxx.h:377
Tlinestyle & cls()
discard line style setting
Definition: xpgplotxx.h:104
Tlinestyle Mgridstyle
grid linestyle
Definition: xpgplotxx.h:498
Tpanel(const Tpanel &ref, const Trect &win, const Trect &tvp=Trect(0., 1., 0., 1.), const Trect &vp=Trect(0.1, 0.9, 0.1, 0.9))
Definition: xpgplotxx.h:172
Tlinestyle(const int &lw, const int &ls, const int &ci)
linewidth and linestyle and color index constructor
Definition: xpgplotxx.h:84
Tlinestyle Mticksstyle
ticks linestyle
Definition: xpgplotxx.h:526
void advance(const float *xbox, const float *ybox, const bool &nl, const float &sep)
advance to new reference position
Definition: xpgplotxx.cc:466
Tlinestyle & setlw(const int &lw)
set linewidth
Definition: xpgplotxx.h:89
Tlinestyle & ccr()
discard colour representation setting
Definition: xpgplotxx.h:108
bool operator==(const Tlinestyle &a, const Tlinestyle &b)
compare for euqality
Definition: xpgplotxx.h:135
setting selection flags
Definition: xpgplotxx.h:341
int Mci
color index
Definition: xpgplotxx.h:125
int Mflags
flags
Definition: xpgplotxx.h:129
Frltbselect (right, left, top, and bottom)
Definition: xpgplotxx.h:349
Ttiledpanels(const Trect &vp, const Trect &svp, const Trect &win, const int &nx, const int &ny)
Definition: xpgplotxx.h:260
Tlinestyle & setci(const int &ci)
set color index
Definition: xpgplotxx.h:95
~Ttiledpanels()
destructor
Definition: xpgplotxx.cc:185
Tboxstyle & setmode(const int &elem, const int &modes, const bool &set=true)
general mode setting
Definition: xpgplotxx.cc:223
Trange find_series_range(const S &series)
find range in series
Definition: xpgplotxx.h:642
bool Minline
true if text was written previously with no nl
Definition: xpgplotxx.h:604
Trect gettvp() const
return total viewport
Definition: xpgplotxx.h:190
Tbbox bbox() const
return bounding box of previously printed text.
Definition: xpgplotxx.h:588
extend (tick marks)
Definition: xpgplotxx.h:359
force exponential (labels)
Definition: xpgplotxx.h:375
Tpanel * Mpanels
array of subpanels
Definition: xpgplotxx.h:295
Tpanel & setvp(const Trect &vp)
set viewport relative to total viewport
Definition: xpgplotxx.h:179
Trange c_range01(0., 1.)
range form 0 to 1
Definition: xpgplotxx.h:616
int Mylabelflags
label options
Definition: xpgplotxx.h:532
Tboxstyle(const bool &tbox=false)
Definition: xpgplotxx.cc:205
Tpanel & operator()(const int &ix, const int &iy)
return subpanel
Definition: xpgplotxx.cc:190
float Mangle
Definition: xpgplotxx.h:602
omit first label (time scale)
Definition: xpgplotxx.h:391
degrees, minutes, and seconds (time scale)
Definition: xpgplotxx.h:389
T & operator()(T &dev) const
apply boxstyle to device context
Definition: xpgplotxx.h:482
Tlinestyle()
default constructor
Definition: xpgplotxx.h:75
pgplot base class
Definition: basicdevice.h:57
Tlinestyle(const int &lw)
linewidth constructor
Definition: xpgplotxx.h:78
bselect (bottom)
Definition: xpgplotxx.h:347
setting selection flags
Definition: xpgplotxx.h:343
Ttext(const float &x, const float &y, const float &angle=0., const float &just=0.)
setup initial text position and orientation.
Definition: xpgplotxx.h:571
Trect getwin() const
return world coordinate range
Definition: xpgplotxx.h:192
int Myticksub
tick options
Definition: xpgplotxx.h:524
int Mxticksub
tick subintervals
Definition: xpgplotxx.h:524
void issuecommand(basic_device &dev, const Tlinestyle &linestyle, const char *xopt, const char *yopt) const
issue appropriate box command
Definition: xpgplotxx.cc:286
do not include day field (time scale)
Definition: xpgplotxx.h:383
int Mytickflags
tick options
Definition: xpgplotxx.h:520
float Mynl
text reference position for carriage return
Definition: xpgplotxx.h:603
int Mxtimeflags
time scale options
Definition: xpgplotxx.h:542
line style attributes
Definition: xpgplotxx.h:68
float Mytick
tick options
Definition: xpgplotxx.h:522
Tlinestyle(const int &lw, const int &ls)
linewidth and linestyle constructor
Definition: xpgplotxx.h:81
force decimal (labels)
Definition: xpgplotxx.h:373
float min
range [min....max]
Definition: structs.h:44
Tlinestyle & clw()
discard line width setting
Definition: xpgplotxx.h:102
Trect c_rect1919(c_range19, c_range19)
rect form 0.1,0.1 to 0.9,0.9
Definition: xpgplotxx.h:622
setting selection flags
Definition: xpgplotxx.h:341
Tcol Mcol
rgb or hls colour setting
Definition: xpgplotxx.h:131
void apply(basic_device &dev) const
apply to basic device class
Definition: xpgplotxx.cc:70
hour modulus 24h (time scale)
Definition: xpgplotxx.h:385
setting selection flags
Definition: xpgplotxx.h:351
Fxyselect, Fhvselect (x and y, left and right)
Definition: xpgplotxx.h:351
void noerase()
do not erase text box prior to plotting text
Definition: xpgplotxx.h:592
hold any rectangle
Definition: structs.h:130
a struct to hold colour triples i.e. rgb or hls values
Definition: structs.h:220
Ttiledpanels & operator=(const Ttiledpanels &panels)
Definition: xpgplotxx.cc:168
Ttext()
default constructor.
Definition: xpgplotxx.h:560
Ttext & space(basic_device &dev)
advance one character
Definition: xpgplotxx.cc:520
int Mframeflags
has frame
Definition: xpgplotxx.h:504
float Mxtick
major tick interval
Definition: xpgplotxx.h:522
vertical (labels)
Definition: xpgplotxx.h:371
Tlinestyle & setls(const int &ls)
set linestyle
Definition: xpgplotxx.h:92
float Mjust
parameters to pgptxt
Definition: xpgplotxx.h:602
Tlinestyle & cci()
discard colour index setting
Definition: xpgplotxx.h:106
Tlinestyle & setrgb(const Tcol &rgb)
set color representation with rgb values
Definition: xpgplotxx.cc:97
float max
Definition: structs.h:44
minor (tick marks)
Definition: xpgplotxx.h:363
Ttext & print(basic_device &dev, const char *txt, const bool &nl=false, const float &sep=0.025)
print text.
Definition: xpgplotxx.cc:440
void apply(basic_device &dev) const
apply to basic device class
Definition: xpgplotxx.cc:306
Trect c_rect0101(c_range01, c_range01)
rect form 0,0 to 1,1
Definition: xpgplotxx.h:620
Trect & shrinkf(const Trect &rect)
fractional shrink/expand
Definition: structs.h:169
setting selection flags
Definition: xpgplotxx.h:341
void erase()
erase text box prior to plotting text
Definition: xpgplotxx.h:590
Eerrdir
error bar directions
Definition: xpgplotxx.h:694
omit leading zeros (time scale)
Definition: xpgplotxx.h:393
Tboxstyle & setxtickint(const int &minor=0, const float &major=0.)
set x-ticks interval
Definition: xpgplotxx.h:473
use superscript symbols (time scale)
Definition: xpgplotxx.h:387
Trect Mvp
the total view surface area
Definition: xpgplotxx.h:291
setting selection flags
Definition: xpgplotxx.h:341
Tlinestyle Mlabelstyle
labels linestyle
Definition: xpgplotxx.h:534
float Myref
text reference position
Definition: xpgplotxx.h:601
Trect Mvp
view port for graph
Definition: xpgplotxx.h:223
bool operator!=(const Tlinestyle &ls) const
compare
Definition: xpgplotxx.cc:109
+/-y (y-e to y+e)
Definition: xpgplotxx.h:706
bool Merase
erase box prior to plotting text
Definition: xpgplotxx.h:606
Tboxstyle & setstyle(const int &elem, const Tlinestyle &style)
set linestyle
Definition: xpgplotxx.cc:268
T & operator()(T &dev) const
apply linestyle to device context
Definition: xpgplotxx.h:116
int Maxisflags
has axis
Definition: xpgplotxx.h:512
Tpanel & settvp(const Trect &tvp)
set total viewport relative to device surface
Definition: xpgplotxx.h:182