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  float getMinColorMapValue() { return minColorMapBound; }
65  float getMaxColorMapValue() { return maxColorMapBound; }
66  float getMinOpacMapValue() { return minOpacMapBound; }
67  float getMaxOpacMapValue() { return maxOpacMapBound; }
68 
69  void setMinColorMapValue(float val) { minColorMapBound = val; }
70  void setMaxColorMapValue(float val) { maxColorMapBound = val; }
71  void setMinOpacMapValue(float val) { minOpacMapBound = val; }
72  void setMaxOpacMapValue(float val) { maxOpacMapBound = val; }
73 
74  //
75  // Variables
76  //
77 
78  int getColorVarNum() { return colorVarNum; }
79  int getOpacVarNum() { return opacVarNum; }
80 
81  virtual void setVarNum(int var) { colorVarNum = var; opacVarNum = var;}
82  virtual void setColorVarNum(int var){ colorVarNum = var; }
83  virtual void setOpacVarNum(int var) { opacVarNum = var; }
84 
85  //
86  // Opacity Maps
87  //
88  virtual OpacityMapBase* createOpacityMap(
89  OpacityMapBase::Type type=OpacityMapBase::CONTROL_POINT
90  );
91  virtual OpacityMapBase* getOpacityMap(int index) const;
92  void deleteOpacityMap(OpacityMapBase *omap);
93  int getNumOpacityMaps() const { return (int)_opacityMaps.size(); }
94 
95  //
96  // Opacity scale factor (scales all opacity maps)
97  //
98  void setOpacityScaleFactor(float val) { opacityScaleFactor = val; }
99  float getOpacityScaleFactor() { return opacityScaleFactor; }
100 
101  //
102  // Opacity composition
103  //
105  {
106  ADDITION = 0,
107  MULTIPLICATION = 1
108  };
109 
110  void setOpacityComposition(CompositionType t) { _compType = t; }
111  CompositionType getOpacityComposition() { return _compType; }
112 
113  //
114  // Colormap
115  //
116  virtual ColorMapBase* getColormap() const;
117 
118  //
119  // Color conversion
120  //
121  static void hsvToRgb(float* hsv, float* rgb);
122  static void rgbToHsv(float* rgb, float* hsv);
123 
124  //
125  // Map a point to the specified range, and quantize it.
126  //
127  static int mapPosition(float x, float minValue, float maxValue, int hSize);
128 
129  int getNumEntries() { return numEntries; }
130  void setNumEntries(int val) { numEntries = val; }
131 
132  //
133  // Map and quantize a real value to the corresponding table index
134  // i.e., quantize to current Mapper function domain
135  //
136  int mapFloatToColorIndex(float point)
137  {
138 
139  int indx = mapPosition(point,
140  getMinColorMapValue(),
141  getMaxColorMapValue(), numEntries-1);
142  if (indx < 0) indx = 0;
143  if (indx > numEntries-1) indx = numEntries-1;
144  return indx;
145  }
146 
147  float mapColorIndexToFloat(int indx)
148  {
149  return (float)(getMinColorMapValue() +
150  ((float)indx)*(float)(getMaxColorMapValue()-
151  getMinColorMapValue())/
152  (float)(numEntries-1));
153  }
154 
155  int mapFloatToOpacIndex(float point)
156  {
157  int indx = mapPosition(point,
158  getMinOpacMapValue(),
159  getMaxOpacMapValue(), numEntries-1);
160  if (indx < 0) indx = 0;
161  if (indx > numEntries-1) indx = numEntries-1;
162  return indx;
163  }
164 
165  float mapOpacIndexToFloat(int indx)
166  {
167  return (float)(getMinOpacMapValue() +
168  ((float)indx)*(float)(getMaxOpacMapValue()-
169  getMinOpacMapValue())/
170  (float)(numEntries-1));
171  }
172 
173  //
174  // Methods to save and restore Mapper functions.
175  // The gui opens the FILEs that are then read/written
176  // Failure results in false/null pointer
177  //
178  // These methods are the same as the transfer function methods,
179  // except for specifying separate color and opacity bounds,
180  // and not having a name attribute
181  //
182 
183  virtual ParamNode* buildNode();
184 
185  virtual bool elementStartHandler(ExpatParseMgr*, int depth,
186  std::string&, const char **);
187 
188  virtual bool elementEndHandler(ExpatParseMgr*, int, std::string&);
189 
190  std::string getName() { return mapperName; }
191 
192  // Mapper function tag is public, visible to flowparams
193  static const string _mapperFunctionTag;
194  TFInterpolator::type colorInterpType() {
195  if (_colormap) return _colormap->interpType();
196  return TFInterpolator::linear;
197  }
198  void setColorInterpType(TFInterpolator::type t){
199  if (_colormap) _colormap->interpType(t);
200  }
201 
202 protected:
203 
204 
205  //
206  // Set to starting values
207  //
208  virtual void init();
209 
210 
211 protected:
212 
213  vector<OpacityMapBase*> _opacityMaps;
215 
216  ColorMapBase *_colormap;
217  //
218  // XML tags
219  //
220  static const string _leftColorBoundAttr;
221  static const string _rightColorBoundAttr;
222  static const string _leftOpacityBoundAttr;
223  static const string _rightOpacityBoundAttr;
224  static const string _opacityCompositionAttr;
225  //Several attributes became tags after version 1.5:
226  static const string _leftColorBoundTag;
227  static const string _rightColorBoundTag;
228  static const string _leftOpacityBoundTag;
229  static const string _rightOpacityBoundTag;
230  static const string _opacityCompositionTag;
231  static const string _hsvAttr;
232  static const string _positionAttr;
233  static const string _opacityAttr;
234  static const string _opacityControlPointTag;
235  static const string _colorControlPointTag;
236  // Additional attributes not yet supported:
237 
238  static const string _rgbAttr;
239 
240  //
241  // Mapping bounds
242  //
243  float minColorMapBound, maxColorMapBound;
244  float minOpacMapBound, maxOpacMapBound;
245 
246  //
247  // Parent params
248  //
249 #ifdef DEAD
250  RenderParams* myParams;
251 #endif
252 
253  //
254  // Size of lookup table. Always 1<<8 currently!
255  //
257 
258  //
259  // Mapper function name, if it's named.
260  //
261  string mapperName;
262 
263  //
264  // Corresponding var nums
265  //
268 
269  //
270  // Opacity scale factor
271  //
273 };
274 };
275 #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:564
virtual void setColorVarNum(int var)
void setMinColorMapValue(float val)
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
void setMaxOpacMapValue(float val)
void setMinOpacMapValue(float val)
static const string _opacityCompositionTag
void setColorInterpType(TFInterpolator::type t)
static const string _rightOpacityBoundAttr
static const string _opacityCompositionAttr
void setMaxColorMapValue(float val)
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)