HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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  virtual ~GT_DAParametric();
57 
58  virtual const char *className() const { 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  virtual GT_Storage getStorage() const
83  { return GT_STORE_REAL64; }
84  virtual GT_Size getTupleSize() const
85  { return 2; }
86  virtual int64 getMemoryUsage() const
87  { return sizeof(*this); }
88  virtual GT_Type getTypeInfo() const
89  { return GT_DataArray::getTypeInfo(); }
90  virtual GT_Size entries() const
91  { return myNu*myNv; }
92  virtual uint8 getU8(GT_Offset offset, int idx) const
93  { return getF64(offset, idx) > 0.5; }
94  virtual int32 getI32(GT_Offset offset, int idx) const
95  { return getF64(offset, idx) > 0.5; }
96  virtual int64 getI64(GT_Offset offset, int idx) const
97  { return getF64(offset, idx) > 0.5; }
98  virtual fpreal16 getF16(GT_Offset offset, int idx) const
99  { return idx ? getV(offset) : getU(offset); }
100  virtual fpreal32 getF32(GT_Offset offset, int idx) const
101  { return idx ? getV(offset) : getU(offset); }
102  virtual fpreal64 getF64(GT_Offset offset, int idx) const
103  { return idx ? getV(offset) : getU(offset); }
104  virtual GT_String getS(GT_Offset, int) const { return NULL; }
105  virtual GT_Size getStringIndexCount() const { return -1; }
106  virtual GT_Offset getStringIndex(GT_Offset, int) const { return -1; }
108  UT_IntArray &) const {}
109  virtual GT_DataArrayHandle harden() const
110  { return GT_DataArrayHandle(SYSconst_cast(this)); }
111  /// @}
112 
113 private:
114  /// Map the requested offset to the coordinate in my data
115  inline fpreal64 getU(GT_Offset offset) const
116  {
117  return myU0 + fpreal64(offset % myNu) * myUinc;
118  }
119  inline fpreal64 getV(GT_Offset offset) const
120  {
121  return myV0 + fpreal64(offset / myNu) * myVinc;
122  }
123 
124  fpreal64 myU0, myV0;
125  fpreal64 myUinc, myVinc;
126  GT_Size myNu, myNv;
127 };
128 
129 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1365
GT_Storage
Definition: GT_Types.h:17
GT_DAParametric(GT_Size nu, GT_Size nv, fpreal64 u0=0, fpreal64 u1=1, fpreal64 v0=0, fpreal64 v1=1)
Useful constructor.
virtual GT_String getS(GT_Offset, int) const
GT_DAParametric(const GT_DAParametric &src)
Copy constructor.
virtual int64 getMemoryUsage() const
virtual fpreal64 getF64(GT_Offset offset, int idx=0) const
Definition: GT_DataArray.h:94
const char * GT_String
Definition: GT_Types.h:108
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:126
#define GT_API
Definition: GT_API.h:11
virtual fpreal32 getF32(GT_Offset offset, int idx) const
GT_Type
Definition: GT_Types.h:31
void init(GT_Size nu, GT_Size nv, fpreal64 u0=0, fpreal64 u1=1, fpreal64 v0=0, fpreal64 v1=1)
Initialize with given data.
virtual GT_Storage getStorage() const
virtual GT_DataArrayHandle harden() const
GT_DAParametric()
Default constructor.
virtual fpreal16 getF16(GT_Offset offset, int idx) const
long long int64
Definition: SYS_Types.h:106
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
virtual uint8 getU8(GT_Offset offset, int idx) const
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:30
virtual const char * className() const
double fpreal64
Definition: SYS_Types.h:191
virtual GT_Size getTupleSize() const
GLintptr offset
Definition: glcorearb.h:664
virtual GT_Type getTypeInfo() const
Return "type" information for the data. This defaults to GT_TYPE_NONE.
virtual int32 getI32(GT_Offset offset, int idx) const
int int32
Definition: SYS_Types.h:34
GLfloat v0
Definition: glcorearb.h:815
virtual GT_Size entries() const
virtual void getIndexedStrings(UT_StringArray &, UT_IntArray &) const
unsigned char uint8
Definition: SYS_Types.h:31
virtual GT_Size getStringIndexCount() const
virtual int64 getI64(GT_Offset offset, int idx) const
GLfloat GLfloat v1
Definition: glcorearb.h:816
virtual fpreal64 getF64(GT_Offset offset, int idx) const
virtual GT_Offset getStringIndex(GT_Offset, int) const
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
float fpreal32
Definition: SYS_Types.h:190
Provide uniform parametric coordinates for a curve/surface.
virtual GT_Type getTypeInfo() const
GLenum src
Definition: glcorearb.h:1792