VAPOR3 3.9.4
MapperFunction.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: MapperFunction.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 MapperFunction 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), and/or identify one or more isovalues.
22
23#ifndef MAPPERFUNCTION_H
24#define MAPPERFUNCTION_H
25
26#include <vapor/OpacityMap.h>
27#include <vapor/ColorMap.h>
29#include <vapor/ParamsBase.h>
30
31namespace VAPoR {
32
33class XmlNode;
34class ParamNode;
35
44public:
46
48
50
52
53 virtual ~MapperFunction();
54
57 //
58 int SaveToFile(string path);
59
62 //
63 int LoadFromFile(string path);
64
65 int LoadColormapFromFile(string path);
66
67 // Get static string identifier for this params class
68 //
69 static string GetClassType() { return ("MapperFunctionParams"); }
70
73 float getOpacityValueData(float point) const;
74
80 void hsvValue(float point, float *h, float *sat, float *val) const;
81
85 void rgbValue(float point, float rgb[3]) const
86 {
87 float hsv[3];
88 hsvValue(point, hsv, hsv + 1, hsv + 2);
89 hsvToRgb(hsv, rgb);
90 }
91
95 void rgbaValue(float point, float rgba[4]) const
96 {
97 float hsv[3];
98 hsvValue(point, hsv, hsv + 1, hsv + 2);
99 hsvToRgb(hsv, rgba);
100 rgba[3] = getOpacityValueData(point);
101 }
102
104 void setOpaque();
105
108 bool isOpaque() const;
109
114 void makeLut(float *clut) const;
115
116 void makeLut(std::vector<float> &clut) const;
117 std::vector<float> makeLut() const;
118
121 float getMinMapValue() const { return (getMinMaxMapValue()[0]); };
122
125 float getMaxMapValue() const { return (getMinMaxMapValue()[1]); };
126
130 void setMinMaxMapValue(float val1, float val2);
131
132 void setMinMapValue(float val) { setMinMaxMapValue(val, getMaxMapValue()); }
133
134 void setMaxMapValue(float val) { setMinMaxMapValue(getMinMapValue(), val); }
135
138 vector<double> getMinMaxMapValue() const;
139
141 vector<double> GetCustomMappingSliderRange() const;
143
145 void SetCustomMappingSliderRange(const vector<double> &range);
147
150 virtual OpacityMap *createOpacityMap(OpacityMap::Type type = OpacityMap::CONTROL_POINT);
151
154 //
155 void DeleteOpacityMap(const OpacityMap *omap);
156
160 virtual OpacityMap *GetOpacityMap(int index) const;
161
164 int getNumOpacityMaps() const { return (m_opacityMaps->Size()); };
165
168 void setOpacityScale(double val) { SetValueDouble(_opacityScaleTag, "Set Opacity Scale", val); }
169
172 double getOpacityScale() const { return GetValueDouble(_opacityScaleTag, 1.0); }
173
175 enum CompositionType { ADDITION = 0, MULTIPLICATION = 1 };
176
179 void setOpacityComposition(CompositionType t) { SetValueLong(_opacityCompositionTag, "Set Opacity Composition Type", (long)t); }
180
183 CompositionType getOpacityComposition() const { return (CompositionType)GetValueLong(_opacityCompositionTag, ADDITION); }
184
188 static void hsvToRgb(float *hsv, float *rgb);
189
193 static void rgbToHsv(float *rgb, float *hsv);
194 static vector<float> rgbToHsv(vector<float> rgb);
195
198 int getNumEntries() const { return _numEntries; }
199
204 int mapFloatToIndex(float point) const
205 {
206 int indx = mapPosition(point, getMinMapValue(), getMaxMapValue(), _numEntries - 1);
207 if (indx < 0) indx = 0;
208 if (indx > _numEntries - 1) indx = _numEntries - 1;
209 return indx;
210 }
211
215 float mapIndexToFloat(int indx) const { return (float)(getMinMapValue() + ((float)indx) * (float)(getMaxMapValue() - getMinMapValue()) / (float)(_numEntries - 1)); }
216
220 {
221 ColorMap *cmap = GetColorMap();
222 if (cmap) return cmap->GetInterpType();
223 return TFInterpolator::diverging;
224 }
225
229 {
230 ColorMap *cmap = GetColorMap();
231 if (cmap) cmap->SetInterpType(t);
232 }
233
234 void setUseWhitespace(int state)
235 {
236 ColorMap *cmap = GetColorMap();
237 if (cmap) cmap->SetUseWhitespace(state);
238 }
239
241 {
242 ColorMap *cmap = GetColorMap();
243 return cmap->GetUseWhitespace();
244 }
245
248 virtual ColorMap *GetColorMap() const { return (m_colorMap); }
249
253 //
254 bool GetAutoUpdateHisto() { return ((bool)GetValueLong(_autoUpdateHistoTag, (int)false)); }
255
259 //
260 void SetAutoUpdateHisto(bool val) { SetValueLong(_autoUpdateHistoTag, "enable/disable auto update of histogram", val); }
261
269 bool GetSecondaryVarMapper() { return ((bool)GetValueLong(_autoUpdateHistoTag, (int)false)); }
270
275 //
276 void SetSecondaryVarMapper(bool val) { SetValueLong(_secondaryVarMapperTag, "Apply color through a secondary color", val); }
277
278public:
279 //
280 // XML tags
281 //
282 static const string _dataBoundsTag;
283 static const string _opacityCompositionTag;
284 static const string _opacityScaleTag;
285 static const string _opacityMapsTag;
286 static const string _opacityMapTag;
287 static const string _autoUpdateHistoTag;
288 static const string _secondaryVarMapperTag;
289 static const string CustomMappingSliderRangeTag;
291
292private:
293 //
294 // Size of lookup table. Always 1<<8 currently!
295 //
296 const int _numEntries;
297
298 ParamsContainer *m_opacityMaps;
299 ColorMap * m_colorMap;
300
307 static int mapPosition(float x, float minValue, float maxValue, int hSize);
308
309 // Construct name for new parent of opac map node, unique for this instance;
310 string getNewOpacMapTag(int *tagIndex);
311
312 // Construct a map tag for a specific index
313 string getOpacMapTag(int index) const;
314
315 // Extract the index from the opacity map tag
316 int getOpacMapNum(string tag);
317
318 string _make_omap_name(int index) const;
319};
320
321#ifdef VAPOR3_0_0_ALPHA
322
330class PARAMS_API MFContainer : public MyBase {
331public:
332 MFContainer();
333
341 //
342 MFContainer(RenderParams *p, string tag);
343
344 ~MFContainer();
345
350 //
351 void Insert(string name, MapperFunction *mf);
352
358 MapperFunction *GetMF(string name) const;
359
361 //
362 void Clear();
363
365 //
366 void Erase(string name);
367
369 //
370 vector<string> GetNames() const;
371
372private:
373 RenderParams *_params;
374 string _tag;
375};
376#endif
377
378}; // namespace VAPoR
379#endif // MAPPERFUNCTION_H
void SetUseWhitespace(bool enabled)
TFInterpolator::type GetInterpType() const
Definition: ColorMap.h:55
void SetInterpType(TFInterpolator::type t)
bool GetUseWhitespace() const
Parent class for TransferFunction and IsoControl, supports positioning histogram over color/opacity m...
void SetCustomMappingSliderRange(const vector< double > &range)
Set the size 2 vector of the users custom slider range. Used by TFMappingRangeSelector.
void setUseWhitespace(int state)
int mapFloatToIndex(float point) const
bool isOpaque() const
MapperFunction & operator=(const MapperFunction &rhs)
void setOpacityComposition(CompositionType t)
void rgbaValue(float point, float rgba[4]) const
CompositionType getOpacityComposition() const
MapperFunction(ParamsBase::StateSave *ssave, XmlNode *node)
static vector< float > rgbToHsv(vector< float > rgb)
int SaveToFile(string path)
virtual OpacityMap * GetOpacityMap(int index) const
std::vector< float > makeLut() const
static const string _opacityScaleTag
void makeLut(float *clut) const
void setColorInterpType(TFInterpolator::type t)
static const string _opacityMapTag
void SetUsingCustomMappingSliderRange(bool b)
static const string CustomMappingSliderRangeTag
MapperFunction(ParamsBase::StateSave *ssave)
void setMinMapValue(float val)
static const string _autoUpdateHistoTag
virtual ColorMap * GetColorMap() const
bool IsUsingCustomMappingSliderRange() const
void rgbValue(float point, float rgb[3]) const
static string GetClassType()
CompositionType
Opacity composition types.
vector< double > getMinMaxMapValue() const
void setOpacityScale(double val)
float getOpacityValueData(float point) const
virtual OpacityMap * createOpacityMap(OpacityMap::Type type=OpacityMap::CONTROL_POINT)
static const string _opacityCompositionTag
int LoadColormapFromFile(string path)
void setMaxMapValue(float val)
MapperFunction(const MapperFunction &rhs)
static const string _secondaryVarMapperTag
int LoadFromFile(string path)
void SetSecondaryVarMapper(bool val)
TFInterpolator::type getColorInterpType()
float getMinMapValue() const
static void rgbToHsv(float *rgb, float *hsv)
float mapIndexToFloat(int indx) const
int getUseWhitespace() const
void DeleteOpacityMap(const OpacityMap *omap)
static const string IsUsingCustomMappingSliderRangeTag
void hsvValue(float point, float *h, float *sat, float *val) const
float getMaxMapValue() const
static const string _opacityMapsTag
vector< double > GetCustomMappingSliderRange() const
Returns size 2 vector of the users custom slider range. Used by TFMappingRangeSelector.
static void hsvToRgb(float *hsv, float *rgb)
void makeLut(std::vector< float > &clut) const
int getNumOpacityMaps() const
void setMinMaxMapValue(float val1, float val2)
static const string _dataBoundsTag
void setOpaque()
Make the opacity map completely opaque (opacity 1)
void SetAutoUpdateHisto(bool val)
double getOpacityScale() const
State capture class.
Definition: ParamsBase.h:62
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:50
A Params subclass for managing parameters used by Renderers.
Definition: RenderParams.h:43
An Xml tree.
Definition: XmlNode.h:49
#define PARAMS_API
Definition: common.h:77