HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_DAParametric.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: GT_DAParametric.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_DAParametric__
12 #define __GT_DAParametric__
13 
14 #include "GT_API.h"
15 #include "GT_DataArray.h"
16 #include <SYS/SYS_Math.h>
17 
18 /// @brief Provide uniform parametric coordinates for a curve/surface
19 ///
20 /// An efficient way of representing parametric coordinates
21 /// For a patch: @code
22 /// uv = GT_DAParamtric(nu, nv);
23 /// @endcode
24 /// For a curve primitive: @code
25 /// uv = GT_DAParamtric(nu, 1);
26 /// @endcode
27 ///
29 {
30 public:
31  /// Default constructor
33  : GT_DataArray()
34  {
35  init(2, 2);
36  }
37  /// Useful constructor
39  fpreal64 u0=0, fpreal64 u1=1,
40  fpreal64 v0=0, fpreal64 v1=1)
41  : GT_DataArray()
42  {
43  init(nu, nv, u0, u1, v0, v1);
44  }
45  /// Copy constructor
47  : myNu(src.myNu),
48  myNv(src.myNv),
49  myU0(src.myU0),
50  myUinc(src.myUinc),
51  myV0(src.myV0),
52  myVinc(src.myVinc),
53  GT_DataArray()
54  {
55  }
56  ~GT_DAParametric() override;
57 
58  const char *className() const override { return "GT_DAParametric"; }
59 
60  /// Initialize with given data
61  void init(GT_Size nu, GT_Size nv,
62  fpreal64 u0=0, fpreal64 u1=1,
63  fpreal64 v0=0, fpreal64 v1=1)
64  {
65  myNu = SYSmax(nu, (GT_Size)1);
66  myNv = SYSmax(nv, (GT_Size)1);
67  myU0 = u0;
68  myV0 = v0;
69  myUinc = myNu > 1 ? (u1-u0)/fpreal64(myNu - 1) : 1;
70  myVinc = myNv > 1 ? (v1-v0)/fpreal64(myNv - 1) : 1;
71  }
72  /// @{
73  /// After being duplicated, you can perform a binary split
74  void splitU0() { myUinc *= 0.5; }
75  void splitU1() { myUinc *= 0.5; myU0 += myUinc*myNu; }
76  void splitV0() { myVinc *= 0.5; }
77  void splitV1() { myVinc *= 0.5; myV0 += myVinc*myNv; }
78  /// @}
79 
80  /// @{
81  /// Methods defined on GT_DataArray
82  GT_Storage getStorage() const override
83  { return GT_STORE_REAL64; }
84  GT_Size getTupleSize() const override
85  { return 2; }
86  int64 getMemoryUsage() const override
87  { return sizeof(*this); }
88  GT_Type getTypeInfo() const override
89  { return GT_DataArray::getTypeInfo(); }
90  GT_Size entries() const override
91  { return myNu*myNv; }
92  uint8 getU8(GT_Offset offset, int idx) const override
93  { return getF64(offset, idx) > 0.5; }
94  int32 getI32(GT_Offset offset, int idx) const override
95  { return getF64(offset, idx) > 0.5; }
96  int64 getI64(GT_Offset offset, int idx) const override
97  { return getF64(offset, idx) > 0.5; }
98  fpreal16 getF16(GT_Offset offset, int idx) const override
99  { return idx ? getV(offset) : getU(offset); }
100  fpreal32 getF32(GT_Offset offset, int idx) const override
101  { return idx ? getV(offset) : getU(offset); }
102  fpreal64 getF64(GT_Offset offset, int idx) const override
103  { return idx ? getV(offset) : getU(offset); }
104  GT_String getS(GT_Offset, int) const override
106  GT_Size getStringIndexCount() const override
107  { return -1; }
108  GT_Offset getStringIndex(GT_Offset, int) const override
109  { return -1; }
111  UT_IntArray &) const override {}
112  GT_Size getDictIndexCount() const override
113  { return -1; }
114  GT_Offset getDictIndex(GT_Offset, int) const override
115  { return -1; }
117  UT_IntArray &) const override {}
118  GT_DataArrayHandle harden() const override
119  { return GT_DataArrayHandle(SYSconst_cast(this)); }
120  /// @}
121 
122 private:
123  /// Map the requested offset to the coordinate in my data
124  inline fpreal64 getU(GT_Offset offset) const
125  {
126  return myU0 + fpreal64(offset % myNu) * myUinc;
127  }
128  inline fpreal64 getV(GT_Offset offset) const
129  {
130  return myV0 + fpreal64(offset / myNu) * myVinc;
131  }
132 
133  fpreal64 myU0, myV0;
134  fpreal64 myUinc, myVinc;
135  GT_Size myNu, myNv;
136 };
137 
138 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1538
GT_Storage
Definition: GT_Types.h:19
int64 getI64(GT_Offset offset, int idx) const override
GT_DAParametric(GT_Size nu, GT_Size nv, fpreal64 u0=0, fpreal64 u1=1, fpreal64 v0=0, fpreal64 v1=1)
Useful constructor.
GT_DAParametric(const GT_DAParametric &src)
Copy constructor.
int int32
Definition: SYS_Types.h:39
const char * className() const override
fpreal32 getF32(GT_Offset offset, int idx) const override
virtual fpreal64 getF64(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:114
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:136
void getIndexedDicts(UT_Array< UT_OptionsHolder > &, UT_IntArray &) const override
GT_Size entries() const override
#define GT_API
Definition: GT_API.h:13
GT_Type
Definition: GT_Types.h:36
void init(GT_Size nu, GT_Size nv, fpreal64 u0=0, fpreal64 u1=1, fpreal64 v0=0, fpreal64 v1=1)
Initialize with given data.
float fpreal32
Definition: SYS_Types.h:200
GLdouble u1
Definition: glad.h:2676
GT_Type getTypeInfo() const override
int64 getMemoryUsage() const override
GT_DAParametric()
Default constructor.
double fpreal64
Definition: SYS_Types.h:201
unsigned char uint8
Definition: SYS_Types.h:36
GT_DataArrayHandle harden() const override
GLintptr offset
Definition: glcorearb.h:665
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
void getIndexedStrings(UT_StringArray &, UT_IntArray &) const override
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:32
GT_Offset getDictIndex(GT_Offset, int) const override
static const UT_StringHolder theEmptyString
GT_Offset getStringIndex(GT_Offset, int) const override
virtual GT_Type getTypeInfo() const
Return "type" information for the data. This defaults to GT_TYPE_NONE.
int64 GT_Offset
Definition: GT_Types.h:129
long long int64
Definition: SYS_Types.h:116
GT_String getS(GT_Offset, int) const override
fpreal64 getF64(GT_Offset offset, int idx) const override
GT_Size getStringIndexCount() const override
fpreal16 getF16(GT_Offset offset, int idx) const override
GLfloat v0
Definition: glcorearb.h:816
int64 GT_Size
Definition: GT_Types.h:128
GT_Storage getStorage() const override
GLfloat GLfloat v1
Definition: glcorearb.h:817
int32 getI32(GT_Offset offset, int idx) const override
uint8 getU8(GT_Offset offset, int idx) const override
Provide uniform parametric coordinates for a curve/surface.
GT_Size getTupleSize() const override
GT_Size getDictIndexCount() const override
GLenum src
Definition: glcorearb.h:1793