VAPoR  0.1
MapperFunctionBase.h
Go to the documentation of this file.
1 //************************************************************************
2 // *
3 // Copyright (C) 2004 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: MapperFunctionBase.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: August 2005
16 //
17 // Description: Defines the MapperFunctionBase class
18 // This is the mathematical definition of a function
19 // that can be used to map data to either colors or opacities
20 // Subclasses can either implement color or transparency
21 // mapping (or both)
22 
23 #ifndef MAPPERFUNCTIONBASE_H
24 #define MAPPERFUNCTIONBASE_H
25 #define MAXCONTROLPOINTS 50
26 #include <iostream>
27 #include <vapor/ExpatParseMgr.h>
28 #include <vapor/OpacityMapBase.h>
29 #include <vapor/ColorMapBase.h>
30 #include <vapor/tfinterpolator.h>
31 #include <vapor/ParamsBase.h>
32 
33 namespace VAPoR {
34 class XmlNode;
35 class ParamNode;
37 {
38 
39 public:
40  MapperFunctionBase(const string& name);
41  MapperFunctionBase(int nBits, const string& name);
43 
44  virtual ~MapperFunctionBase();
45 
46  //
47  // Function values
48  //
49  float opacityValue(float point);
50  void hsvValue(float point, float* h, float* sat, float* val);
51 
52  void setOpaque();
53  bool isOpaque();
54 
55  //
56  // Build a lookup table[numEntries][4]
57  // (Caller must pass in an empty array)
58  //
59  void makeLut(float* clut);
60 
61  //
62  // Data Bounds
63  //
64 
65 
66  void setMinMapValue(float val) { minMapBound = val; }
67  void setMaxMapValue(float val) { maxMapBound = val; }
68  float getMinMapValue() { return minMapBound; }
69  float getMaxMapValue() { return maxMapBound; }
70 
71  //
72  // Variables
73  //
74 
75  int getColorVarNum() { return colorVarNum; }
76  int getOpacVarNum() { return opacVarNum; }
77 
78  virtual void setVarNum(int var) { colorVarNum = var; opacVarNum = var;}
79  virtual void setColorVarNum(int var){ colorVarNum = var; }
80  virtual void setOpacVarNum(int var) { opacVarNum = var; }
81 
82  //
83  // Opacity Maps
84  //
85  virtual OpacityMapBase* createOpacityMap(
86  OpacityMapBase::Type type=OpacityMapBase::CONTROL_POINT
87  );
88  virtual OpacityMapBase* getOpacityMap(int index) const;
89  void deleteOpacityMap(OpacityMapBase *omap);
90  int getNumOpacityMaps() const { return (int)_opacityMaps.size(); }
91 
92  //
93  // Opacity scale factor (scales all opacity maps)
94  //
95  void setOpacityScaleFactor(float val) { opacityScaleFactor = val; }
96  float getOpacityScaleFactor() { return opacityScaleFactor; }
97 
98  //
99  // Opacity composition
100  //
102  {
103  ADDITION = 0,
104  MULTIPLICATION = 1
105  };
106 
107  void setOpacityComposition(CompositionType t) { _compType = t; }
108  CompositionType getOpacityComposition() { return _compType; }
109 
110  //
111  // Colormap
112  //
113  virtual ColorMapBase* getColormap() const;
114 
115  //
116  // Color conversion
117  //
118  static void hsvToRgb(float* hsv, float* rgb);
119  static void rgbToHsv(float* rgb, float* hsv);
120 
121  //
122  // Map a point to the specified range, and quantize it.
123  //
124  static int mapPosition(float x, float minValue, float maxValue, int hSize);
125 
126  int getNumEntries() { return numEntries; }
127  void setNumEntries(int val) { numEntries = val; }
128 
129  //
130  // Map and quantize a real value to the corresponding table index
131  // i.e., quantize to current Mapper function domain
132  //
133  int mapFloatToColorIndex(float point)
134  {
135 
136  int indx = mapPosition(point,
137  getMinMapValue(),
138  getMaxMapValue(), numEntries-1);
139  if (indx < 0) indx = 0;
140  if (indx > numEntries-1) indx = numEntries-1;
141  return indx;
142  }
143 
144  float mapColorIndexToFloat(int indx)
145  {
146  return (float)(getMinMapValue() +
147  ((float)indx)*(float)(getMaxMapValue()-
148  getMinMapValue())/
149  (float)(numEntries-1));
150  }
151 
152  int mapFloatToOpacIndex(float point)
153  {
154  int indx = mapPosition(point,
155  getMinMapValue(),
156  getMaxMapValue(), numEntries-1);
157  if (indx < 0) indx = 0;
158  if (indx > numEntries-1) indx = numEntries-1;
159  return indx;
160  }
161 
162  float mapOpacIndexToFloat(int indx)
163  {
164  return (float)(getMinMapValue() +
165  ((float)indx)*(float)(getMaxMapValue()-
166  getMinMapValue())/
167  (float)(numEntries-1));
168  }
169 
170  //
171  // Methods to save and restore Mapper functions.
172  // The gui opens the FILEs that are then read/written
173  // Failure results in false/null pointer
174  //
175  // These methods are the same as the transfer function methods,
176  // except for specifying separate color and opacity bounds,
177  // and not having a name attribute
178  //
179 
180  virtual ParamNode* buildNode();
181 
182  virtual bool elementStartHandler(ExpatParseMgr*, int depth,
183  std::string&, const char **);
184 
185  virtual bool elementEndHandler(ExpatParseMgr*, int, std::string&);
186 
187  std::string getName() { return mapperName; }
188 
189  // Mapper function tag is public, visible to flowparams
190  static const string _mapperFunctionTag;
191  TFInterpolator::type colorInterpType() {
192  if (_colormap) return _colormap->interpType();
193  return TFInterpolator::linear;
194  }
195  void setColorInterpType(TFInterpolator::type t){
196  if (_colormap) _colormap->interpType(t);
197  }
198 
199 protected:
200 
201 
202  //
203  // Set to starting values
204  //
205  virtual void init();
206 
207 
208 protected:
209 
210  vector<OpacityMapBase*> _opacityMaps;
212 
213  ColorMapBase *_colormap;
214  //
215  // XML tags
216  //
217  static const string _leftColorBoundAttr;
218  static const string _rightColorBoundAttr;
219  static const string _leftOpacityBoundAttr;
220  static const string _rightOpacityBoundAttr;
221  static const string _opacityCompositionAttr;
222  //Several attributes became tags after version 1.5:
223  static const string _leftColorBoundTag;
224  static const string _rightColorBoundTag;
225  static const string _leftOpacityBoundTag;
226  static const string _rightOpacityBoundTag;
227  static const string _opacityCompositionTag;
228  static const string _hsvAttr;
229  static const string _positionAttr;
230  static const string _opacityAttr;
231  static const string _opacityControlPointTag;
232  static const string _colorControlPointTag;
233  // Additional attributes not yet supported:
234 
235  static const string _rgbAttr;
236 
237  //
238  // Mapping bounds
239  //
240  float minMapBound, maxMapBound;
241 
242  //
243  // Parent params
244  //
245 #ifdef DEAD
246  RenderParams* myParams;
247 #endif
248 
249  //
250  // Size of lookup table. Always 1<<8 currently!
251  //
253 
254  //
255  // Mapper function name, if it's named.
256  //
257  string mapperName;
258 
259  //
260  // Corresponding var nums
261  //
264 
265  //
266  // Opacity scale factor
267  //
269 };
270 };
271 #endif //MAPPERFUNCTIONBASE_H
float mapOpacIndexToFloat(int indx)
#define PARAMS_API
Definition: common.h:63
CompositionType getOpacityComposition()
A Params subclass for managing parameters used by Renderers.
Definition: params.h:569
virtual void setColorVarNum(int var)
static const string _rightColorBoundAttr
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:57
int mapFloatToColorIndex(float point)
virtual void setOpacVarNum(int var)
float mapColorIndexToFloat(int indx)
vector< OpacityMapBase * > _opacityMaps
static const string _rightColorBoundTag
static const string _colorControlPointTag
static const string _hsvAttr
static const string _leftOpacityBoundAttr
TFInterpolator::type colorInterpType()
int mapFloatToOpacIndex(float point)
static const string _leftOpacityBoundTag
virtual void setVarNum(int var)
void setOpacityScaleFactor(float val)
static const string _positionAttr
static const string _leftColorBoundTag
static const string _rightOpacityBoundTag
static const string _opacityCompositionTag
void setColorInterpType(TFInterpolator::type t)
static const string _rightOpacityBoundAttr
static const string _opacityCompositionAttr
static const string _opacityAttr
static const string _leftColorBoundAttr
static const string _rgbAttr
static const string _opacityControlPointTag
static const string _mapperFunctionTag
An Xml tree.
Definition: ParamNode.h:30
void setOpacityComposition(CompositionType t)