MorphoGraphX  2.0-1-227
TransferFunction.hpp
Go to the documentation of this file.
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
28 {
34  class mgx_EXPORT TransferFunction
35  {
36  public:
41  RGB = 0,
42  HSV = 1,
43  CYCLIC_HSV = 2
44  };
45 
47  static const double epsilon;
48 
51 
55  typedef std::vector<std::pair<double, Colorf> > value_list;
56 
60  typedef QMap<double, int> key_map;
61 
66  TransferFunction(Interpolation interpolation = RGB);
67 
72 
76  virtual ~TransferFunction() {
77  }
78 
80 
87  static TransferFunction scale(Colorf min, Colorf max, Interpolation interpolation = RGB);
91  static TransferFunction hue_scale();
96  return scale(Colorf(0, 0, 0, 0), Colorf(1, 1, 1, 1));
97  }
102  return scale(Colorf(0, 0, 0, 0), Colorf(1, 0, 0, 1));
103  }
108  return scale(Colorf(0, 0, 0, 0), Colorf(0, 1, 0, 1));
109  }
114  return scale(Colorf(0, 0, 0, 0), Colorf(0, 0, 1, 1));
115  }
120  return scale(Colorf(0, 0, 0, 0), Colorf(1, 1, 0, 1));
121  }
126  return scale(Colorf(0, 0, 0, 0), Colorf(0, 1, 1, 1));
127  }
132  return scale(Colorf(0, 0, 0, 0), Colorf(1, 0, 1, 1));
133  }
138  return scale(Colorf(1, 1, 1, 0), Colorf(1, 1, 1, 1));
139  }
144  return scale(Colorf(1, 0, 0, 0), Colorf(1, 0, 0, 1));
145  }
150  return scale(Colorf(0, 1, 0, 0), Colorf(0, 1, 0, 1));
151  }
156  return scale(Colorf(0, 0, 1, 0), Colorf(0, 0, 1, 1));
157  }
162  return scale(Colorf(1, 1, 0, 0), Colorf(1, 1, 0, 1));
163  }
168  return scale(Colorf(0, 1, 1, 0), Colorf(0, 1, 1, 1));
169  }
174  return scale(Colorf(1, 0, 1, 0), Colorf(1, 0, 1, 1));
175  }
179  static TransferFunction jet();
183  static TransferFunction french_flag();
184 
188  static TransferFunction blackbody();
192  static TransferFunction uniform_jet();
196  static TransferFunction helix_warm();
200  static TransferFunction helix_cool();
204  static TransferFunction helix_full();
206 
207  static TransferFunction batlow_10();
208  static TransferFunction parula();
209 
213  static TransferFunction load(QString spec);
217  QString dump() const;
218 
222  void add_rgba_point(double pos, Colorf col);
223 
227  void add_hsva_point(double pos, Colorf col);
228 
232  void remove_point(double pos);
233 
237  size_t size() const {
238  return values.size();
239  }
240 
244  void move_point(double old_pos, double new_pos);
245 
249  double next_pos(double old_pos) const;
250 
254  double prev_pos(double old_pos) const;
255 
257  double operator[](int i) const;
258 
264  Colorf rgba_point(double position) const;
270  Colorf hsva_point(double position) const;
271 
276  Colorf rgba(double position) const;
281  Colorf hsva(double position) const;
286  double alpha(double position) const;
287 
291  bool empty() const {
292  return values.empty();
293  }
294 
298  TransferFunction& operator=(const TransferFunction& other);
299 
306  bool operator==(const TransferFunction& other) const;
313  bool operator!=(const TransferFunction& other) const;
314 
320  void reverse();
321 
325  void clear();
326 
330  void adjust(double minValue, double maxValue);
331 
336  return _interpolation;
337  }
341  void setInterpolation(Interpolation i);
345  void setPointList(const value_list& lst);
346 
347  protected:
356  Colorf interpolate(double position, double p1, Colorf col1, double p2, Colorf col2) const;
360  void update_keys();
365 
370  Colorf color(double position) const;
371 
377  void add_point(double pos, Colorf col);
378 
390 
395  bool clamp;
396 
401  };
402 }
403 #endif
mgx::TransferFunction::scale_gray
static TransferFunction scale_gray()
Scale in gray.
Definition: TransferFunction.hpp:95
mgx::TransferFunction::constant_green
static TransferFunction constant_green()
Scale in transparency.
Definition: TransferFunction.hpp:149
mgx::Colorf
Color< float > Colorf
Definition: Color.hpp:317
mgx::TransferFunction::clamp
bool clamp
If true, the colors left and right of the defined points are clamped.
Definition: TransferFunction.hpp:395
mgx::TransferFunction::Colorf
Color< float > Colorf
Type of a color.
Definition: TransferFunction.hpp:50
mgx::TransferFunction::values
value_list values
List of values.
Definition: TransferFunction.hpp:385
mgx::TransferFunction
Definition: TransferFunction.hpp:34
mgx::TransferFunction::scale_green
static TransferFunction scale_green()
Scale in green.
Definition: TransferFunction.hpp:107
mgx::TransferFunction::scale_red
static TransferFunction scale_red()
Scale in red.
Definition: TransferFunction.hpp:101
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::TransferFunction::scale_yellow
static TransferFunction scale_yellow()
Scale in yellow.
Definition: TransferFunction.hpp:119
mgx::TransferFunction::scale_purple
static TransferFunction scale_purple()
Scale in purple.
Definition: TransferFunction.hpp:131
mgx::TransferFunction::Interpolation
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:40
mgx::TransferFunction::constant_cyan
static TransferFunction constant_cyan()
Scale in transparency.
Definition: TransferFunction.hpp:167
mgx::TransferFunction::constant_purple
static TransferFunction constant_purple()
Scale in transparency.
Definition: TransferFunction.hpp:173
mgx::TransferFunction::constant_yellow
static TransferFunction constant_yellow()
Scale in transparency.
Definition: TransferFunction.hpp:161
mgx::interpolate
T CU_HOST_DEVICE interpolate(const T &a, const T &b, const T &s)
Interpolate between values.
Definition: Geometry.hpp:177
mgx::TransferFunction::size
size_t size() const
Returns the number of points.
Definition: TransferFunction.hpp:237
mgx::max
T CU_HOST_DEVICE max(const T a, const T b)
Definition: Util.hpp:34
mgx::TransferFunction::key_map
QMap< double, int > key_map
Type of the mapping from the position to the index in the value list.
Definition: TransferFunction.hpp:60
mgx::TransferFunction::keys
key_map keys
Mapping of the position to the index in the value list.
Definition: TransferFunction.hpp:389
mgx::TransferFunction::~TransferFunction
virtual ~TransferFunction()
Virtual destructor.
Definition: TransferFunction.hpp:76
mgx::TransferFunction::empty
bool empty() const
Returns true if no points are defined.
Definition: TransferFunction.hpp:291
mgx::TransferFunction::constant_blue
static TransferFunction constant_blue()
Scale in transparency.
Definition: TransferFunction.hpp:155
mgx::TransferFunction::constant_red
static TransferFunction constant_red()
Scale in transparency.
Definition: TransferFunction.hpp:143
mgx::TransferFunction::interpolation
Interpolation interpolation() const
Returns the current interpolation mode.
Definition: TransferFunction.hpp:335
Color.hpp
mgx::min
CU_HOST_DEVICE T min(const T a, const T b)
Definition: Util.hpp:26
mgx::TransferFunction::scale_blue
static TransferFunction scale_blue()
Scale in blue.
Definition: TransferFunction.hpp:113
mgx::Color< float >
mgx::TransferFunction::exteriorColor
Colorf exteriorColor
Color left and right of the control points if not clamped.
Definition: TransferFunction.hpp:400
mgx::TransferFunction::constant_gray
static TransferFunction constant_gray()
Scale in transparency.
Definition: TransferFunction.hpp:137
mgx::TransferFunction::_interpolation
Interpolation _interpolation
Current interpolation mode.
Definition: TransferFunction.hpp:364
mgx::TransferFunction::epsilon
static const double epsilon
epsilon used in floating point comparisons
Definition: TransferFunction.hpp:47
mgx::TransferFunction::scale_cyan
static TransferFunction scale_cyan()
Scale in cyan.
Definition: TransferFunction.hpp:125
mgx::TransferFunction::value_list
std::vector< std::pair< double, Colorf > > value_list
Type of a list of value/colors.
Definition: TransferFunction.hpp:55