MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColorBar.hpp
1 #ifndef COLORBAR_H
2 #define COLORBAR_H
3 
4 #include <Config.hpp>
5 #include <GL.hpp>
6 
7 #include <MGXViewer/qglviewer.h>
8 #include <Parms.hpp>
9 
10 #include <iostream>
11 #include <QDataStream>
12 #include <QString>
13 #include <QTextStream>
14 #include <string>
15 #include <valarray>
16 
17 namespace mgx {
18  class mgx_EXPORT Colorbar {
19  public:
20  typedef std::valarray<double> array;
21  enum Position { TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT };
22 
23  enum Orientation { HORIZONTAL, VERTICAL };
24 
25  Colorbar(Position pos = RIGHT);
26 
27  void draw(QGLViewer* viewer, GLuint colormapTexId, QPaintDevice* device = 0) const;
28 
29  Position position;
30  Orientation orientation;
31  QFont font;
32 
33  double scale_length;
34  double width;
35  double distance_to_border;
36  double text_to_bar;
37  double tick_size;
38  double exp_size;
39  double epsilon;
40  double line_width;
41 
42  double vmin, vmax;
43 
44  double globalScaling;
45 
46  QString label;
47 
48  void readParms(util::Parms& parms, QString section);
49  void writeParms(QTextStream& pout, QString section);
50 
51  void scaleDrawing(double scale);
52  void restoreScale();
53 
54  protected:
55  void startScreenCoordinatesSystem(QPaintDevice* device) const;
56  void stopScreenCoordinatesSystem() const;
57 
58  mutable double prev_width, prev_height;
59  void getValues(double start, double end, double delta, array& result) const;
60  array selectValuesDirect(double length, bool is_vertical, const QFontMetricsF& metric, double min_dist) const;
61  std::pair<double, double> significantDigits(double start, double end) const;
62  bool canRenderTicks(const array& ticks, double length, double min_dist, bool is_vertical,
63  const QFontMetricsF& font_metric) const;
64  QStringList _tick2str(const array& ticks, QString* extra = 0) const;
65  array selectValues(double length, bool is_vertical, const QFontMetricsF* metric = 0) const;
66  };
67 
68  std::ostream& operator<<(std::ostream& s, const Colorbar::Position& pos);
69  std::istream& operator>>(std::istream& s, Colorbar::Position& pos);
70 
71  QTextStream& operator<<(QTextStream& s, const Colorbar::Position& pos);
72  QTextStream& operator>>(QTextStream& s, Colorbar::Position& pos);
73 
74  QDataStream& operator<<(QDataStream& s, const Colorbar::Position& pos);
75  QDataStream& operator>>(QDataStream& s, Colorbar::Position& pos);
76 } // namespace mgx
77 #endif // COLORBAR_H
Defines the util::Parms class.
Definition: ColorBar.hpp:18
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:105