MorphoGraphX
TransferFunction.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 TRANSFERFUNCTION_HPP
12 #define TRANSFERFUNCTION_HPP
13 
19 #include <Config.hpp>
20 
21 #include <Color.hpp>
22 
23 #include <QMap>
24 #include <QObject>
25 #include <vector>
26 
27 namespace mgx {
33 class mgx_EXPORT TransferFunction {
34 public:
39  RGB = 0,
40  HSV = 1,
41  CYCLIC_HSV = 2
42  };
43 
45  static const double epsilon;
46 
49 
53  typedef std::vector<std::pair<double, Colorf> > value_list;
54 
59 
64  TransferFunction(Interpolation interpolation = RGB);
65 
70 
74  virtual ~TransferFunction() {
75  }
76 
78 
85  static TransferFunction scale(Colorf min, Colorf max, Interpolation interpolation = RGB);
89  static TransferFunction hue_scale();
94  return scale(Colorf(0, 0, 0, 0), Colorf(1, 1, 1, 1));
95  }
100  return scale(Colorf(0, 0, 0, 0), Colorf(1, 0, 0, 1));
101  }
106  return scale(Colorf(0, 0, 0, 0), Colorf(0, 1, 0, 1));
107  }
112  return scale(Colorf(0, 0, 0, 0), Colorf(0, 0, 1, 1));
113  }
118  return scale(Colorf(0, 0, 0, 0), Colorf(1, 1, 0, 1));
119  }
124  return scale(Colorf(0, 0, 0, 0), Colorf(0, 1, 1, 1));
125  }
130  return scale(Colorf(0, 0, 0, 0), Colorf(1, 0, 1, 1));
131  }
136  return scale(Colorf(1, 1, 1, 0), Colorf(1, 1, 1, 1));
137  }
142  return scale(Colorf(1, 0, 0, 0), Colorf(1, 0, 0, 1));
143  }
148  return scale(Colorf(0, 1, 0, 0), Colorf(0, 1, 0, 1));
149  }
154  return scale(Colorf(0, 0, 1, 0), Colorf(0, 0, 1, 1));
155  }
160  return scale(Colorf(1, 1, 0, 0), Colorf(1, 1, 0, 1));
161  }
166  return scale(Colorf(0, 1, 1, 0), Colorf(0, 1, 1, 1));
167  }
172  return scale(Colorf(1, 0, 1, 0), Colorf(1, 0, 1, 1));
173  }
177  static TransferFunction jet();
181  static TransferFunction french_flag();
183 
187  static TransferFunction load(QString spec);
191  QString dump() const;
192 
196  void add_rgba_point(double pos, Colorf col);
197 
201  void add_hsva_point(double pos, Colorf col);
202 
206  void remove_point(double pos);
207 
211  size_t size() const {
212  return values.size();
213  }
214 
218  void move_point(double old_pos, double new_pos);
219 
223  double next_pos(double old_pos) const;
224 
228  double prev_pos(double old_pos) const;
229 
231  double operator[](int i) const;
232 
238  Colorf rgba_point(double position) const;
244  Colorf hsva_point(double position) const;
245 
250  Colorf rgba(double position) const;
255  Colorf hsva(double position) const;
260  double alpha(double position) const;
261 
265  bool empty() const {
266  return values.empty();
267  }
268 
272  TransferFunction& operator=(const TransferFunction& other);
273 
280  bool operator==(const TransferFunction& other) const;
287  bool operator!=(const TransferFunction& other) const;
288 
294  void reverse();
295 
299  void clear();
300 
304  void adjust(double minValue, double maxValue);
305 
310  return _interpolation;
311  }
315  void setInterpolation(Interpolation i);
319  void setPointList(const value_list& lst);
320 
321 protected:
330  Colorf interpolate(double position, double p1, Colorf col1, double p2, Colorf col2) const;
334  void update_keys();
339 
344  Colorf color(double position) const;
345 
351  void add_point(double pos, Colorf col);
352 
359  value_list values;
363  key_map keys;
364 
369  bool clamp;
370 
375 };
376 } // namespace mgx
377 #endif // TRANSFERFUNCTION_HPP
static TransferFunction constant_yellow()
Scale in transparency.
Definition: TransferFunction.hpp:159
static TransferFunction constant_cyan()
Scale in transparency.
Definition: TransferFunction.hpp:165
virtual ~TransferFunction()
Virtual destructor.
Definition: TransferFunction.hpp:74
static TransferFunction constant_blue()
Scale in transparency.
Definition: TransferFunction.hpp:153
static TransferFunction scale_blue()
Scale in blue.
Definition: TransferFunction.hpp:111
static TransferFunction constant_green()
Scale in transparency.
Definition: TransferFunction.hpp:147
bool empty() const
Returns true if no points are defined.
Definition: TransferFunction.hpp:265
static TransferFunction scale_purple()
Scale in purple.
Definition: TransferFunction.hpp:129
std::vector< std::pair< double, Colorf > > value_list
Type of a list of value/colors.
Definition: TransferFunction.hpp:53
static TransferFunction scale_gray()
Scale in gray.
Definition: TransferFunction.hpp:93
static TransferFunction constant_red()
Scale in transparency.
Definition: TransferFunction.hpp:141
key_map keys
Mapping of the position to the index in the value list.
Definition: TransferFunction.hpp:363
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
static const double epsilon
epsilon used in floating point comparisons
Definition: TransferFunction.hpp:45
size_t size() const
Returns the number of points.
Definition: TransferFunction.hpp:211
Interpolation interpolation() const
Returns the current interpolation mode.
Definition: TransferFunction.hpp:309
static TransferFunction scale_green()
Scale in green.
Definition: TransferFunction.hpp:105
util::Color< float > Colorf
Type of a color.
Definition: TransferFunction.hpp:48
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:38
static TransferFunction constant_purple()
Scale in transparency.
Definition: TransferFunction.hpp:171
static TransferFunction constant_gray()
Scale in transparency.
Definition: TransferFunction.hpp:135
static TransferFunction scale_yellow()
Scale in yellow.
Definition: TransferFunction.hpp:117
static TransferFunction scale_cyan()
Scale in cyan.
Definition: TransferFunction.hpp:123
static TransferFunction scale_red()
Scale in red.
Definition: TransferFunction.hpp:99
bool clamp
If true, the colors left and right of the defined points are clamped.
Definition: TransferFunction.hpp:369
Defines the Color class template.
Class defining a transfer function as linear interpolation between set values.
Definition: TransferFunction.hpp:33
Interpolation _interpolation
Current interpolation mode.
Definition: TransferFunction.hpp:338
Colorf exteriorColor
Color left and right of the control points if not clamped.
Definition: TransferFunction.hpp:374
QMap< double, int > key_map
Type of the mapping from the position to the index in the value list.
Definition: TransferFunction.hpp:58
value_list values
List of values.
Definition: TransferFunction.hpp:359