MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TransferFunction.hpp
1 #ifndef TRANSFERFUNCTION_HPP
2 #define TRANSFERFUNCTION_HPP
3 
9 #include <Config.hpp>
10 
11 #include <Color.hpp>
12 
13 #include <QMap>
14 #include <QObject>
15 #include <vector>
16 
17 namespace mgx {
23 class mgx_EXPORT TransferFunction {
24 public:
29  RGB = 0,
30  HSV = 1,
31  CYCLIC_HSV = 2
32  };
33 
35  static const double epsilon;
36 
39 
43  typedef std::vector<std::pair<double, Colorf> > value_list;
44 
49 
54  TransferFunction(Interpolation interpolation = RGB);
55 
60 
64  virtual ~TransferFunction() {
65  }
66 
68 
75  static TransferFunction scale(Colorf min, Colorf max, Interpolation interpolation = RGB);
79  static TransferFunction hue_scale();
84  return scale(Colorf(0, 0, 0, 0), Colorf(1, 1, 1, 1));
85  }
90  return scale(Colorf(0, 0, 0, 0), Colorf(1, 0, 0, 1));
91  }
96  return scale(Colorf(0, 0, 0, 0), Colorf(0, 1, 0, 1));
97  }
102  return scale(Colorf(0, 0, 0, 0), Colorf(0, 0, 1, 1));
103  }
108  return scale(Colorf(0, 0, 0, 0), Colorf(1, 1, 0, 1));
109  }
114  return scale(Colorf(0, 0, 0, 0), Colorf(0, 1, 1, 1));
115  }
120  return scale(Colorf(0, 0, 0, 0), Colorf(1, 0, 1, 1));
121  }
126  return scale(Colorf(1, 1, 1, 0), Colorf(1, 1, 1, 1));
127  }
132  return scale(Colorf(1, 0, 0, 0), Colorf(1, 0, 0, 1));
133  }
138  return scale(Colorf(0, 1, 0, 0), Colorf(0, 1, 0, 1));
139  }
144  return scale(Colorf(0, 0, 1, 0), Colorf(0, 0, 1, 1));
145  }
150  return scale(Colorf(1, 1, 0, 0), Colorf(1, 1, 0, 1));
151  }
156  return scale(Colorf(0, 1, 1, 0), Colorf(0, 1, 1, 1));
157  }
162  return scale(Colorf(1, 0, 1, 0), Colorf(1, 0, 1, 1));
163  }
167  static TransferFunction jet();
171  static TransferFunction french_flag();
173 
177  static TransferFunction load(QString spec);
181  QString dump() const;
182 
186  void add_rgba_point(double pos, Colorf col);
187 
191  void add_hsva_point(double pos, Colorf col);
192 
196  void remove_point(double pos);
197 
201  size_t size() const {
202  return values.size();
203  }
204 
208  void move_point(double old_pos, double new_pos);
209 
213  double next_pos(double old_pos) const;
214 
218  double prev_pos(double old_pos) const;
219 
221  double operator[](int i) const;
222 
228  Colorf rgba_point(double position) const;
234  Colorf hsva_point(double position) const;
235 
240  Colorf rgba(double position) const;
245  Colorf hsva(double position) const;
250  double alpha(double position) const;
251 
255  bool empty() const {
256  return values.empty();
257  }
258 
262  TransferFunction& operator=(const TransferFunction& other);
263 
270  bool operator==(const TransferFunction& other) const;
277  bool operator!=(const TransferFunction& other) const;
278 
284  void reverse();
285 
289  void clear();
290 
294  void adjust(double minValue, double maxValue);
295 
300  return _interpolation;
301  }
305  void setInterpolation(Interpolation i);
309  void setPointList(const value_list& lst);
310 
311 protected:
320  Colorf interpolate(double position, double p1, Colorf col1, double p2, Colorf col2) const;
324  void update_keys();
329 
334  Colorf color(double position) const;
335 
341  void add_point(double pos, Colorf col);
342 
354 
359  bool clamp;
360 
365 };
366 } // namespace mgx
367 #endif // TRANSFERFUNCTION_HPP
static TransferFunction constant_yellow()
Scale in transparency.
Definition: TransferFunction.hpp:149
static TransferFunction constant_cyan()
Scale in transparency.
Definition: TransferFunction.hpp:155
virtual ~TransferFunction()
Virtual destructor.
Definition: TransferFunction.hpp:64
static TransferFunction constant_blue()
Scale in transparency.
Definition: TransferFunction.hpp:143
static TransferFunction scale_blue()
Scale in blue.
Definition: TransferFunction.hpp:101
static TransferFunction constant_green()
Scale in transparency.
Definition: TransferFunction.hpp:137
bool empty() const
Returns true if no points are defined.
Definition: TransferFunction.hpp:255
static TransferFunction scale_purple()
Scale in purple.
Definition: TransferFunction.hpp:119
std::vector< std::pair< double, Colorf > > value_list
Type of a list of value/colors.
Definition: TransferFunction.hpp:43
static TransferFunction scale_gray()
Scale in gray.
Definition: TransferFunction.hpp:83
static TransferFunction constant_red()
Scale in transparency.
Definition: TransferFunction.hpp:131
key_map keys
Mapping of the position to the index in the value list.
Definition: TransferFunction.hpp:353
static const double epsilon
epsilon used in floating point comparisons
Definition: TransferFunction.hpp:35
size_t size() const
Returns the number of points.
Definition: TransferFunction.hpp:201
Interpolation interpolation() const
Returns the current interpolation mode.
Definition: TransferFunction.hpp:299
static TransferFunction scale_green()
Scale in green.
Definition: TransferFunction.hpp:95
util::Color< float > Colorf
Type of a color.
Definition: TransferFunction.hpp:38
Interpolation
Type of interpolation.
Definition: TransferFunction.hpp:28
static TransferFunction constant_purple()
Scale in transparency.
Definition: TransferFunction.hpp:161
static TransferFunction constant_gray()
Scale in transparency.
Definition: TransferFunction.hpp:125
static TransferFunction scale_yellow()
Scale in yellow.
Definition: TransferFunction.hpp:107
static TransferFunction scale_cyan()
Scale in cyan.
Definition: TransferFunction.hpp:113
static TransferFunction scale_red()
Scale in red.
Definition: TransferFunction.hpp:89
bool clamp
If true, the colors left and right of the defined points are clamped.
Definition: TransferFunction.hpp:359
Defines the Color class template.
Class defining a transfer function as linear interpolation between set values.
Definition: TransferFunction.hpp:23
Interpolation _interpolation
Current interpolation mode.
Definition: TransferFunction.hpp:328
Colorf exteriorColor
Color left and right of the control points if not clamped.
Definition: TransferFunction.hpp:364
QMap< double, int > key_map
Type of the mapping from the position to the index in the value list.
Definition: TransferFunction.hpp:48
value_list values
List of values.
Definition: TransferFunction.hpp:349