HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_LUT.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT library (C++)
7  *
8  * COMMENTS: This is a generalized look up table for effecient
9  * computation of single valued arrays.
10  * These use inline methods since the whole purpose
11  * of a LUT is speed.
12  *
13  * Revision 1.1.1.1 1995/09/17 18:10:22 mark
14  * initial source release
15  *
16  * Revision 1.1 94/06/16 18:33:33 prisms
17  * Initial revision
18  *
19  */
20 
21 #ifndef __UT_LUT_H__
22 #define __UT_LUT_H__
23 
24 #include "UT_API.h"
25 #include "UT_Assert.h"
26 #include "UT_NonCopyable.h"
27 #include <SYS/SYS_Types.h>
28 
30 {
31 public:
32  UT_LUT(fpreal val, int size, float (*eval)(float val, float t) = 0);
33  explicit UT_LUT(int size, float (*eval)(float t) = 0);
34  ~UT_LUT();
35 
37 
38  /// Given a LUT defining a function which is already parametrized from 0 to
39  /// 1, we then compute the "inverse" warp LUT which performs an equal-area
40  /// warp from the unit parametrization to the map.
41  void buildConformalWarp(const UT_LUT &src);
42 
43  void buildLUT(float (*eval)(float val, float t));
44  void buildLUT(float (*eval)(float t));
45 
46  void setValue(fpreal v) { myVal = v; }
47  fpreal getValue() const { return myVal; }
48  int getSize() const { return mySize; }
49  fpreal getFSize() const { return myFSize; }
50  fpreal operator()(int i) const
51  {
52  UT_ASSERT_P(i >= 0 && i <= mySize);
53  return myLut[i];
54  }
55 
56 //
57 // The fast routines assume that t is guaranteed to be [0, 1]
58 // The safe method does bounds checking.
59 // Since floating point values are truncated (not rounded), the fast lookup is
60 // safe for values up to 1+0.5F/mySize.
61 //
63  {
64  UT_ASSERT_MSG_P((t==t), "t can't be NaN here!");
65  return myLut[(int)(t*myFSize+0.5F)];
66  }
68  {
69  fpreal rval;
70  if (t < 0) rval = myLut[0];
71  else if (t < 1) rval = myLut[(int)(t*myFSize+0.5F)];
72  else rval = myLut[mySize]; // t >= 1 *OR* NaN
73  return rval;
74  }
75 
76 //
77 // lerp methods do linear interpolation on the LUT
78 //
80  {
81  UT_ASSERT_MSG_P((t==t), "t can't be NaN here!");
82  t *= myFSize;
83  int i1 = (int)t;
84  t -= (fpreal)i1;
85  return (1.0F - t)*myLut[i1] + t*myLut[i1+1];
86  }
88  {
89  fpreal rval;
90  if (t < 0.0F) rval = myLut[0];
91  else if (t < 1.0F)
92  {
93  t *= myFSize;
94  int i1 = (int)t;
95  t -= (fpreal)i1;
96  rval = (1.0F - t)*myLut[i1] + t*myLut[i1+1];
97  }
98  else // t >= 1.0F *OR* t is NaN
99  rval = myLut[mySize];
100  return rval;
101  }
102 
103  int getLUTSize() const { return mySize; }
104  fpreal *getRawLUT() { return myLut; }
105 
106  void bumpRefCount() { myRefCount++; }
107  int downRefCount() { return --myRefCount; }
108 protected:
109 private:
110  fpreal *myLut; // The lookup table data
111  fpreal myVal; // The value associated with this LUT
112  int mySize; // Size of the LUT
113  fpreal myFSize; // Size as a fpreal (to avoid the cast)
114  int myRefCount; // Reference count for this LUT
115 };
116 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
fpreal * getRawLUT()
Definition: UT_LUT.h:104
const GLdouble * v
Definition: glcorearb.h:837
fpreal lerpFast(fpreal t) const
Definition: UT_LUT.h:79
#define UT_API
Definition: UT_API.h:14
#define UT_ASSERT_MSG_P(ZZ,...)
Definition: UT_Assert.h:158
fpreal operator()(int i) const
Definition: UT_LUT.h:50
fpreal lerpSafe(fpreal t) const
Definition: UT_LUT.h:87
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
int downRefCount()
Definition: UT_LUT.h:107
fpreal getValue() const
Definition: UT_LUT.h:47
GLint i1
Definition: glad.h:2724
HUSD_API bool eval(VtValue &val, T &ret_val)
fpreal getFSize() const
Definition: UT_LUT.h:49
void bumpRefCount()
Definition: UT_LUT.h:106
GLdouble t
Definition: glad.h:2397
fpreal safeValue(fpreal t) const
Definition: UT_LUT.h:67
GLsizeiptr size
Definition: glcorearb.h:664
int getLUTSize() const
Definition: UT_LUT.h:103
void setValue(fpreal v)
Definition: UT_LUT.h:46
fpreal64 fpreal
Definition: SYS_Types.h:277
int getSize() const
Definition: UT_LUT.h:48
GLuint GLfloat * val
Definition: glcorearb.h:1608
Definition: UT_LUT.h:29
GLenum src
Definition: glcorearb.h:1793
fpreal fastValue(fpreal t) const
Definition: UT_LUT.h:62