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  int mapFloatToIndex(float f) { return mapFloatToColorIndex(f); }
59  float mapIndexToFloat(int indx) { return mapColorIndexToFloat(indx); }
60 
61  void setVarNum(int var) { colorVarNum = var; opacVarNum = var; }
62 
63  //
64  // Methods to save and restore transfer functions.
65  // The gui opens the FILEs that are then read/written
66  // Failure results in false/null pointer
67  //
68  bool saveToFile(ofstream& f);
69  static TransferFunction* loadFromFile(ifstream& is, RenderParams *p);
70 
71  virtual ParamNode* buildNode(const string& tfname);
72  virtual ParamNode* buildNode();
73 
74  //All the parsing can be done with the start handlers
75  bool elementStartHandler(ExpatParseMgr*, int depth , std::string& s,
76  const char **attr);
77  bool elementEndHandler(ExpatParseMgr*, int , std::string&);
78 
79  //Transfer function tag is visible to session
80  static const string _transferFunctionTag;
81  virtual void hookup(RenderParams* p, int cvar, int ovar){
82  _params = p;
83  colorVarNum = cvar;
84  opacVarNum = ovar;
85  if(_colormap)((VColormap*)_colormap)->setMapper(this);
86  if(_opacityMaps.size()>0) ((OpacityMap*)_opacityMaps[0])->setMapper(this);
87  }
88  virtual TransferFunction* deepCopy(ParamNode* newRoot = 0){
89  TransferFunction* tf = new TransferFunction(*this);
90  tf->SetRootParamNode(newRoot);
91  if(newRoot) newRoot->SetParamsBase(tf);
92  return tf;
93  }
94 
95 protected:
96 
97  //
98  //Set to starting values
99  //
100  virtual void init();
101 
102 protected:
103 
104  //
105  // XML tags
106  //
107  static const string _tfNameAttr;
108  static const string _leftBoundAttr;
109  static const string _rightBoundAttr;
110  static const string _leftBoundTag;
111  static const string _rightBoundTag;
112  static const string _tfNameTag;
113 };
114 };
115 #endif //TRANSFERFUNCTION_H
static const string _rightBoundAttr
#define PARAMS_API
Definition: common.h:63
A Params subclass for managing parameters used by Renderers.
Definition: params.h:569
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
static const string _rightBoundTag
An Xml tree.
Definition: ParamNode.h:30
virtual TransferFunction * deepCopy(ParamNode *newRoot=0)