MorphoGraphX
ColorBar.hpp
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef COLORBAR_H
12 #define COLORBAR_H
13 
14 #include <Config.hpp>
15 #include <GL.hpp>
16 
17 #include <MGXViewer/qglviewer.h>
18 #include <Parms.hpp>
19 
20 #include <iostream>
21 #include <QDataStream>
22 #include <QString>
23 #include <QTextStream>
24 #include <string>
25 #include <valarray>
26 
27 namespace mgx {
28  class mgx_EXPORT Colorbar {
29  public:
30  typedef std::valarray<double> array;
31  enum Position { TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_RIGHT, BOTTOM_LEFT };
32 
33  enum Orientation { HORIZONTAL, VERTICAL };
34 
35  Colorbar(Position pos = RIGHT);
36 
37  void draw(QGLViewer* viewer, GLuint colormapTexId, QPaintDevice* device = 0) const;
38 
39  Position position;
40  Orientation orientation;
41  QFont font;
42 
43  double scale_length;
44  double width;
45  double distance_to_border;
46  double text_to_bar;
47  double tick_size;
48  double exp_size;
49  double epsilon;
50  double line_width;
51 
52  double vmin, vmax;
53 
54  double globalScaling;
55 
56  QString label;
57 
58  void readParms(util::Parms& parms, QString section);
59  void writeParms(QTextStream& pout, QString section);
60 
61  void scaleDrawing(double scale);
62  void restoreScale();
63 
64  protected:
65  void startScreenCoordinatesSystem(QPaintDevice* device) const;
66  void stopScreenCoordinatesSystem() const;
67 
68  mutable double prev_width, prev_height;
69  void getValues(double start, double end, double delta, array& result) const;
70  array selectValuesDirect(double length, bool is_vertical, const QFontMetricsF& metric, double min_dist) const;
71  std::pair<double, double> significantDigits(double start, double end) const;
72  bool canRenderTicks(const array& ticks, double length, double min_dist, bool is_vertical,
73  const QFontMetricsF& font_metric) const;
74  QStringList _tick2str(const array& ticks, QString* extra = 0) const;
75  array selectValues(double length, bool is_vertical, const QFontMetricsF* metric = 0) const;
76  };
77 
78  std::ostream& operator<<(std::ostream& s, const Colorbar::Position& pos);
79  std::istream& operator>>(std::istream& s, Colorbar::Position& pos);
80 
81  QTextStream& operator<<(QTextStream& s, const Colorbar::Position& pos);
82  QTextStream& operator>>(QTextStream& s, Colorbar::Position& pos);
83 
84  QDataStream& operator<<(QDataStream& s, const Colorbar::Position& pos);
85  QDataStream& operator>>(QDataStream& s, Colorbar::Position& pos);
86 } // namespace mgx
87 #endif // COLORBAR_H
Defines the util::Parms class.
Definition: ColorBar.hpp:28
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
A utility class to parse L-Studio like parameter files.
Definition: Parms.hpp:115