HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_GEOSupport.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_GEOSupport.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_GEOSupport__
12 #define __GT_GEOSupport__
13 
14 #include "GT_API.h"
15 #include <UT/UT_Array.h>
16 #include <GU/GU_Detail.h>
17 #include <GU/GU_DetailHandle.h>
18 #include <GA/GA_TempBuffer.h>
19 #include "GT_Types.h"
20 #include "GT_Handles.h"
21 
22 /// Wrapper around an array of GA_Offsets. Provides a way to allocate a
23 /// GT_DataArray
25 {
26 public:
27  class pointfromvertex {};
28 
30  : myList()
31  , my32Bit(true)
32  , myMonotonic(true)
33  {}
34  GT_GEOOffsetList(const GU_Detail &gdp, GA_AttributeOwner owner);
35  GT_GEOOffsetList(const GU_Detail &gdp, const GA_Range &range);
37  GT_GEOOffsetList(const GA_Offset *offsets, GA_Size noffsets);
39  : myList(src.myList)
40  , my32Bit(src.my32Bit)
41  , myMonotonic(src.myMonotonic)
42  {
43  }
44  // Given an offset list of vertices, create a new list of their points.
45  // If there are vertices which reference the same point, the point will be
46  // duplicated in the new offset list.
48  const GT_GEOOffsetList &vertex_list,
49  pointfromvertex);
50 
51  /// Extract a sub-array from the given offset list
54 
55  void clear() { myList.clear(); }
56  void reserve(exint numtoadd, bool setentries=false)
57  {
58  // NOTE: GA_OffsetList::setEntries hardens, and GA_OffsetList::reserve
59  // doesn't. GA_OffsetList::reserve also doesn't set entries
60 
61  exint newentries = myList.entries() + numtoadd;
62  if (newentries > myList.capacity() && !myList.isTrivial())
63  {
64  exint newcapacity = SYSmax(newentries, UTbumpAlloc(myList.capacity()));
65 
66  myList.reserve(newcapacity);
67  }
68  if (setentries)
69  {
70  myList.setEntries(newentries, false);
71  my32Bit = my32Bit && (myList.entries() <= (1<<30));
72  myMonotonic = false;
73  }
74  }
76  {
77  if (myList.entries() && offset < myList.last())
78  myMonotonic = false;
79  myList.append(offset);
80  my32Bit = my32Bit && (offset < GA_Offset(1<<30));
81  }
82  void checkMonotonic();
83  void concat(const GT_GEOOffsetList &src);
84  bool isTrivial() const { return myList.isTrivial(); }
85  GT_Size entries() const { return myList.entries(); }
86  GA_Offset get(exint i) const { return GA_Offset(myList(i)); }
87  void set(exint i, GA_Offset value) { myList.set(i, value); }
88  GA_Offset operator()(exint i) const { return get(i); }
89  bool is32Bit() const { return my32Bit; }
91  { return sizeof(*this) + myList.getMemoryUsage(false); }
92 
93  bool monotonic() const { return myMonotonic; }
94  const GA_OffsetList &offsetList() const { return myList; }
95 
96  /// Create a GT_DataArray for the offsets
97  GT_DataArrayHandle allocateArray() const;
98 
99  /// Assuming that this offset list contains GA_Offset for vertices in the
100  /// given gdp, create a data array for the points referred to by the
101  /// vertices.
102  GT_DataArrayHandle createVertexPointArray(const GA_Detail &gdp) const;
103  GT_DataArrayHandle createVertexPointArray(const GU_ConstDetailHandle &gdh) const;
104 
105  /// Debug
106  void dump(const char *msg="", bool full=true) const;
107 
108 private:
109  GA_OffsetList myList;
110  bool my32Bit;
111  bool myMonotonic;
112 };
113 
114 /// Simple wrapper on an array of sizes, provides a method to allocate a
115 /// GT_DataArray.
117 {
118 public:
120  : myList()
121  , myMin(0)
122  , myMax(0)
123  {}
125  : myList(src.myList)
126  , myMin(src.myMin)
127  , myMax(src.myMax)
128  {
129  }
130  ~GT_GEOSizeList();
131 
132  void clear()
133  {
134  myList.clear();
135  myMin = myMax = 0;
136  }
137  void append(GT_Size item)
138  {
139  if (myList.entries() == 0)
140  {
141  myMin = myMax = item;
142  }
143  else
144  {
145  myMin = SYSmin(myMin, item);
146  myMax = SYSmax(myMax, item);
147  }
148  myList.append(item);
149  }
150  bool is32Bit() const { return myMax < (1<<30) && myMin >= -(1<<30); }
151  GT_Size min() const { return myMin; }
152  GT_Size max() const { return myMax; }
153  GT_Size entries() const { return myList.entries(); }
154  GT_Size get(exint i) const { return GA_Offset(myList(i)); }
155  // NOTE: If using set, you must use setMin and setMax
156  void set(exint i, GA_Size value) { myList.setValue(i, value); }
157  void setMin(GA_Size value) { myMin = value; }
158  void setMax(GA_Size value) { myMax = value; }
159  GT_Size operator()(exint i) const { return get(i); }
160  void reserve(exint numtoadd, bool setentries=false)
161  {
162  myList.reserve(myList.entries() + numtoadd, setentries);
163  }
164 
165  void concat(const GT_GEOSizeList &src);
167 
168  /// Debug
169  void dump(const char *msg="", bool full=true) const;
170 
171 private:
172  GA_TempBuffer<GT_Size> myList;
173  GT_Size myMin;
174  GT_Size myMax;
175 };
176 
177 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1367
GT_Size min() const
GLenum GLint * range
Definition: glcorearb.h:1924
void setValue(GA_Size i, const T &value)
Set an item in the buffer to the given value.
Definition: GA_TempBuffer.h:84
void concat(const GT_GEOSizeList &src)
GLuint start
Definition: glcorearb.h:474
#define GT_API
Definition: GT_API.h:11
GA_Offset operator()(exint i) const
Definition: GT_GEOSupport.h:88
bool monotonic() const
Definition: GT_GEOSupport.h:93
GA_Size entries() const
How many elements in the buffer.
Definition: GA_TempBuffer.h:60
void setMin(GA_Size value)
GT_Size entries() const
void reserve(exint numtoadd, bool setentries=false)
Definition: GT_GEOSupport.h:56
png_uint_32 i
Definition: png.h:2877
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
A range of elements in an index-map.
Definition: GA_Range.h:42
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
void setMax(GA_Size value)
GA_Size GA_Offset
Definition: GA_Types.h:617
long long int64
Definition: SYS_Types.h:107
void clear()
Clear all entries.
Definition: GA_TempBuffer.h:48
bool isTrivial() const
Definition: GT_GEOSupport.h:84
bool is32Bit() const
GT_DataArrayHandle allocateArray() const
int64 exint
Definition: SYS_Types.h:116
GLuint GLuint end
Definition: glcorearb.h:474
GLintptr offset
Definition: glcorearb.h:664
void reserve(exint numtoadd, bool setentries=false)
void append(GT_Size item)
const GA_OffsetList & offsetList() const
Definition: GT_GEOSupport.h:94
void append(GA_Offset offset)
Definition: GT_GEOSupport.h:75
void set(exint i, GA_Offset value)
Definition: GT_GEOSupport.h:87
GT_Size entries() const
Definition: GT_GEOSupport.h:85
GLsizei const GLfloat * value
Definition: glcorearb.h:823
GA_AttributeOwner
Definition: GA_Types.h:33
void set(exint i, GA_Size value)
GT_Size operator()(exint i) const
GT_GEOSizeList(const GT_GEOSizeList &src)
GT_Size max() const
void reserve(GA_Size size, bool setsize=false)
Reserve storage.
Definition: GA_TempBuffer.h:66
Container class for all geometry.
Definition: GA_Detail.h:95
GT_GEOOffsetList(const GT_GEOOffsetList &src)
Definition: GT_GEOSupport.h:38
int64 GT_Size
Definition: GT_Types.h:112
bool is32Bit() const
Definition: GT_GEOSupport.h:89
#define SYSmin(a, b)
Definition: SYS_Math.h:1368
void dump(const char *msg="", bool full=true) const
Debug.
void append(const T &value)
Append an element to the array.
Definition: GA_TempBuffer.h:76
int64 getMemoryUsage() const
Definition: GT_GEOSupport.h:90
GLenum src
Definition: glcorearb.h:1792