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 <SYS/SYS_Types.h>
26 #include "UT_Assert.h"
27 
28 class UT_API UT_LUT {
29 public:
30  UT_LUT(fpreal val, int size, float (*eval)(float val, float t) = 0);
31  explicit UT_LUT(int size, float (*eval)(float t) = 0);
32  ~UT_LUT();
33 
34  /// Given a LUT defining a function which is already parametrized from 0 to
35  /// 1, we then compute the "inverse" warp LUT which performs an equal-area
36  /// warp from the unit parametrization to the map.
37  void buildConformalWarp(const UT_LUT &src);
38 
39  void buildLUT(float (*eval)(float val, float t));
40  void buildLUT(float (*eval)(float t));
41 
42  void setValue(fpreal v) { myVal = v; }
43  fpreal getValue() const { return myVal; }
44  int getSize() const { return mySize; }
45  fpreal getFSize() const { return myFSize; }
46  fpreal operator()(int i) const
47  {
48  UT_ASSERT_P(i >= 0 && i <= mySize);
49  return myLut[i];
50  }
51 
52 //
53 // The fast routines assume that t is guaranteed to be [0, 1]
54 // The safe method does bounds checking.
55 // Since floating point values are truncated (not rounded), the fast lookup is
56 // safe for values up to 1+0.5F/mySize.
57 //
59  {
60  UT_ASSERT_MSG_P((t==t), "t can't be NaN here!");
61  return myLut[(int)(t*myFSize+0.5F)];
62  }
64  {
65  fpreal rval;
66  if (t < 0) rval = myLut[0];
67  else if (t < 1) rval = myLut[(int)(t*myFSize+0.5F)];
68  else rval = myLut[mySize]; // t >= 1 *OR* NaN
69  return rval;
70  }
71 
72 //
73 // lerp methods do linear interpolation on the LUT
74 //
76  {
77  UT_ASSERT_MSG_P((t==t), "t can't be NaN here!");
78  t *= myFSize;
79  int i1 = (int)t;
80  t -= (fpreal)i1;
81  return (1.0F - t)*myLut[i1] + t*myLut[i1+1];
82  }
84  {
85  fpreal rval;
86  if (t < 0.0F) rval = myLut[0];
87  else if (t < 1.0F)
88  {
89  t *= myFSize;
90  int i1 = (int)t;
91  t -= (fpreal)i1;
92  rval = (1.0F - t)*myLut[i1] + t*myLut[i1+1];
93  }
94  else // t >= 1.0F *OR* t is NaN
95  rval = myLut[mySize];
96  return rval;
97  }
98 
99  int getLUTSize() const { return mySize; }
100  fpreal *getRawLUT() { return myLut; }
101 
102  void bumpRefCount(void) { myRefCount++; }
103  int downRefCount(void) { return --myRefCount; }
104 protected:
105 private:
106  fpreal *myLut; // The lookup table data
107  fpreal myVal; // The value associated with this LUT
108  int mySize; // Size of the LUT
109  fpreal myFSize; // Size as a fpreal (to avoid the cast)
110  int myRefCount; // Reference count for this LUT
111 };
112 #endif
fpreal * getRawLUT()
Definition: UT_LUT.h:100
const GLdouble * v
Definition: glcorearb.h:836
fpreal lerpFast(fpreal t) const
Definition: UT_LUT.h:75
#define UT_API
Definition: UT_API.h:13
fpreal operator()(int i) const
Definition: UT_LUT.h:46
png_uint_32 i
Definition: png.h:2877
GLsizeiptr size
Definition: glcorearb.h:663
fpreal lerpSafe(fpreal t) const
Definition: UT_LUT.h:83
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:125
fpreal getValue() const
Definition: UT_LUT.h:43
fpreal getFSize() const
Definition: UT_LUT.h:45
fpreal safeValue(fpreal t) const
Definition: UT_LUT.h:63
int getLUTSize() const
Definition: UT_LUT.h:99
double fpreal
Definition: SYS_Types.h:270
void setValue(fpreal v)
Definition: UT_LUT.h:42
typedef int
Definition: png.h:1175
void bumpRefCount(void)
Definition: UT_LUT.h:102
int getSize() const
Definition: UT_LUT.h:44
GLuint GLfloat * val
Definition: glcorearb.h:1607
int downRefCount(void)
Definition: UT_LUT.h:103
Definition: UT_LUT.h:28
#define UT_ASSERT_MSG_P(ZZ, MM)
Definition: UT_Assert.h:128
GLenum src
Definition: glcorearb.h:1792
fpreal fastValue(fpreal t) const
Definition: UT_LUT.h:58