VAPoR  0.1
transferfunction.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: transferfunction.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: November 2004
16 //
17 // Description: Defines the TransferFunction class
18 // This is the mathematical definition of the transfer function
19 // It is defined in terms of floating point coordinates, converted
20 // into a mapping of quantized values (LUT) with specified domain at
21 // rendering time. Interfaces to the TFEditor and DvrParams classes.
22 // The TransferFunction deals with an mapping on the interval [0,1]
23 // that is remapped to a specified interval by the user.
24 //
25 #ifndef TRANSFERFUNCTION_H
26 #define TRANSFERFUNCTION_H
27 #define MAXCONTROLPOINTS 50
28 #include <vapor/tfinterpolator.h>
29 //#include "params.h"
30 #include "mapperfunction.h"
31 #include <vapor/ExpatParseMgr.h>
32 #include <qcolor.h>
33 
34 namespace VAPoR {
35 class TFEditor;
36 class RenderParams;
37 class XmlNode;
38 class ParamNode;
39 
41 {
42 
43 public:
44 
46  TransferFunction(RenderParams* p, int nBits=8);
47  TransferFunction(const MapperFunctionBase &mapper);
48  TransferFunction(const ParamsBase* parent);
49  virtual ~TransferFunction();
51 
52  //
53  // Note: All public methods use actual real coords.
54  // (Protected methods use normalized points in [0,1]
55  //
56 
57  //
58  // Transfer function has identical min,max map bounds, but
59  // Parent class has them potentially unequal.
60  //
61  void setMinMapValue(float minVal)
62  { setMinOpacMapValue(minVal); setMinColorMapValue(minVal);}
63 
64  void setMaxMapValue(float val)
65  { setMaxOpacMapValue(val); setMaxColorMapValue(val); }
66 
67  float getMinMapValue() {return getMinColorMapValue();}
68  float getMaxMapValue() {return getMaxColorMapValue();}
69 
70  int mapFloatToIndex(float f) { return mapFloatToColorIndex(f); }
71  float mapIndexToFloat(int indx) { return mapColorIndexToFloat(indx); }
72 
73  void setVarNum(int var) { colorVarNum = var; opacVarNum = var; }
74 
75  //
76  // Methods to save and restore transfer functions.
77  // The gui opens the FILEs that are then read/written
78  // Failure results in false/null pointer
79  //
80  bool saveToFile(ofstream& f);
81  static TransferFunction* loadFromFile(ifstream& is, RenderParams *p);
82 
83  virtual ParamNode* buildNode(const string& tfname);
84  virtual ParamNode* buildNode();
85 
86  //All the parsing can be done with the start handlers
87  bool elementStartHandler(ExpatParseMgr*, int depth , std::string& s,
88  const char **attr);
89  bool elementEndHandler(ExpatParseMgr*, int , std::string&);
90 
91  //Transfer function tag is visible to session
92  static const string _transferFunctionTag;
93  virtual void hookup(RenderParams* p, int cvar, int ovar){
94  _params = p;
95  colorVarNum = cvar;
96  opacVarNum = ovar;
97  if(_colormap)((VColormap*)_colormap)->setMapper(this);
98  if(_opacityMaps.size()>0) ((OpacityMap*)_opacityMaps[0])->setMapper(this);
99  }
100  virtual TransferFunction* deepCopy(ParamNode* newRoot = 0){
101  TransferFunction* tf = new TransferFunction(*this);
102  tf->SetRootParamNode(newRoot);
103  if(newRoot) newRoot->SetParamsBase(tf);
104  return tf;
105  }
106 
107 protected:
108 
109  //
110  //Set to starting values
111  //
112  virtual void init();
113 
114 protected:
115 
116  //
117  // XML tags
118  //
119  static const string _tfNameAttr;
120  static const string _leftBoundAttr;
121  static const string _rightBoundAttr;
122  static const string _leftBoundTag;
123  static const string _rightBoundTag;
124  static const string _tfNameTag;
125 };
126 };
127 #endif //TRANSFERFUNCTION_H
static const string _rightBoundAttr
#define PARAMS_API
Definition: common.h:63
void setMinMapValue(float minVal)
A Params subclass for managing parameters used by Renderers.
Definition: params.h:564
static const string _leftBoundAttr
static const string _leftBoundTag
static const string _transferFunctionTag
virtual void SetRootParamNode(ParamNode *pn)
Definition: ParamsBase.h:222
Nodes with state in Xml tree representation.
Definition: ParamsBase.h:57
static ParamsBase * CreateDefaultInstance()
virtual void hookup(RenderParams *p, int cvar, int ovar)
static const string _tfNameTag
float mapIndexToFloat(int indx)
static const string _tfNameAttr
void setMaxMapValue(float val)
static const string _rightBoundTag
An Xml tree.
Definition: ParamNode.h:30
virtual TransferFunction * deepCopy(ParamNode *newRoot=0)