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 <UT/UT_RLEArray.h>
17 #include <UT/UT_SmallArray.h>
18 #include <GU/GU_Detail.h>
19 #include <GU/GU_DetailHandle.h>
20 #include "GT_Types.h"
21 #include "GT_Handles.h"
22 
23 /// Wrapper around an array of GA_Offsets. Provides a way to allocate a
24 /// GT_DataArray
26 {
27 public:
28  class pointfromvertex {};
29 
31  : myList()
32  , my32Bit(true)
33  , myMonotonic(true)
34  {}
35  GT_GEOOffsetList(const GU_Detail &gdp, GA_AttributeOwner owner);
36  GT_GEOOffsetList(const GU_Detail &gdp, const GA_Range &range);
38  GT_GEOOffsetList(const GA_Offset *offsets, GA_Size noffsets);
40  : myList(src.myList)
41  , my32Bit(src.my32Bit)
42  , myMonotonic(src.myMonotonic)
43  {
44  }
45  // Given an offset list of vertices, create a new list of their points.
46  // If there are vertices which reference the same point, the point will be
47  // duplicated in the new offset list.
49  const GT_GEOOffsetList &vertex_list,
50  pointfromvertex);
51 
52  /// Extract a sub-array from the given offset list
55 
56  void clear() { myList.clear(); }
57  void reserve(exint numtoadd, bool setentries=false)
58  {
59  // NOTE: GA_OffsetList::setEntries hardens, and GA_OffsetList::reserve
60  // doesn't. GA_OffsetList::reserve also doesn't set entries
61 
62  exint newentries = myList.entries() + numtoadd;
63  if (newentries > myList.capacity() && !myList.isTrivial())
64  {
65  exint newcapacity = SYSmax(newentries, UTbumpAlloc(myList.capacity()));
66 
67  myList.reserve(newcapacity);
68  }
69  if (setentries)
70  {
71  myList.setEntries(newentries, false);
72  my32Bit = my32Bit && (myList.entries() <= (1<<30));
73  myMonotonic = false;
74  }
75  }
77  {
78  if (myList.entries() && offset < myList.last())
79  myMonotonic = false;
80  myList.append(offset);
81  my32Bit = my32Bit && (offset < GA_Offset(1<<30));
82  }
83  void checkMonotonic();
84  void concat(const GT_GEOOffsetList &src);
85  bool isTrivial() const { return myList.isTrivial(); }
86  GT_Size entries() const { return myList.entries(); }
87  GT_Size size() const { return myList.entries(); }
88  GA_Offset get(exint i) const { return GA_Offset(myList(i)); }
89  void set(exint i, GA_Offset value) { myList.set(i, value); }
90  GA_Offset operator()(exint i) const { return get(i); }
91  GA_Offset operator[](exint i) const { return get(i); }
92  bool is32Bit() const { return my32Bit; }
94  { return sizeof(*this) + myList.getMemoryUsage(false); }
95 
96  bool monotonic() const { return myMonotonic; }
97  const GA_OffsetList &offsetList() const { return myList; }
98 
99  /// Create a GT_DataArray for the offsets
100  GT_DataArrayHandle allocateArray() const;
101 
102  /// Assuming that this offset list contains GA_Offset for vertices in the
103  /// given gdp, create a data array for the points referred to by the
104  /// vertices.
105  GT_DataArrayHandle createVertexPointArray(const GA_Detail &gdp) const;
106  GT_DataArrayHandle createVertexPointArray(const GU_ConstDetailHandle &gdh) const;
107 
108  /// Debug
109  void dump(const char *msg="", bool full=true) const;
110 
111 private:
112  GA_OffsetList myList;
113  bool my32Bit;
114  bool myMonotonic;
115 };
116 
117 /// Simple wrapper on an array of sizes, provides a method to allocate a
118 /// GT_DataArray.
120 {
121 public:
123  : myList()
124  , myMin(0)
125  , myMax(0)
126  {}
128  : myList(src.myList)
129  , myMin(src.myMin)
130  , myMax(src.myMax)
131  {
132  }
133  ~GT_GEOSizeList();
134 
135  void clear()
136  {
137  myList.clear();
138  myMin = myMax = 0;
139  }
140  void append(GT_Size item)
141  {
142  if (myList.size() == 0)
143  {
144  myMin = myMax = item;
145  }
146  else
147  {
148  myMin = SYSmin(myMin, item);
149  myMax = SYSmax(myMax, item);
150  }
151  myList.append(item);
152  }
153  bool is32Bit() const { return myMax < (1<<30) && myMin >= -(1<<30); }
154  GT_Size min() const { return myMin; }
155  GT_Size max() const { return myMax; }
156  GT_Size entries() const { return myList.size(); }
157  GT_Size size() const { return myList.size(); }
158  GT_Size get(exint i) const { return GA_Offset(myList[i]); }
159  // NOTE: If using set, you must use setMin and setMax
160  void set(exint i, GA_Size value) { myList[i] = value; }
161  void setMin(GA_Size value) { myMin = value; }
162  void setMax(GA_Size value) { myMax = value; }
163  GT_Size operator()(exint i) const { return get(i); }
164  GT_Size operator[](exint i) const { return get(i); }
165  void reserve(exint numtoadd, bool setentries=false)
166  {
167  if (setentries)
168  myList.setSizeIfNeeded(myList.size()+numtoadd);
169  else
170  myList.setCapacityIfNeeded(myList.size()+numtoadd);
171  }
172 
173  void concat(const GT_GEOSizeList &src);
175 
176  /// Debug
177  void dump(const char *msg="", bool full=true) const;
178 
179 private:
180  UT_SmallArray<GT_Size> myList;
181  GT_Size myMin;
182  GT_Size myMax;
183 };
184 
185 /// Run-length encoded list of sizes. Useful for building lists of counts
186 /// where the same count is repeated multiple times. No random access allowed
188 {
189 public:
191  using iterator = ArrayType::iterator;
192 
194  : myList()
195  , myMin(0)
196  , myMax(0)
197  {}
199  : myList(src.myList)
200  , myMin(src.myMin)
201  , myMax(src.myMax)
202  {
203  }
205 
206  void clear()
207  {
208  myList.clear();
209  myMin = myMax = 0;
210  }
211  void append(GT_Size item)
212  {
213  if (myList.size() == 0)
214  {
215  myMin = myMax = item;
216  }
217  else
218  {
219  myMin = SYSmin(myMin, item);
220  myMax = SYSmax(myMax, item);
221  }
222  myList.append(item);
223  }
224  bool is32Bit() const { return myMax < (1<<30) && myMin >= -(1<<30); }
225  GT_Size min() const { return myMin; }
226  GT_Size max() const { return myMax; }
227  GT_Size size() const { return myList.size(); }
228  // NOTE: If using set, you must use setMin and setMax
229  void setMin(GA_Size value) { myMin = value; }
230  void setMax(GA_Size value) { myMax = value; }
231 
232  void concat(const GT_GEORLESizeList &src);
234 
235  iterator begin() const { return myList.begin(); }
236  iterator end() const { return myList.end(); }
237 
238  /// Debug
239  void dump(const char *msg="", bool full=true) const;
240 
241 private:
242  UT_RLEArray<GT_Size> myList;
243  GT_Size myMin;
244  GT_Size myMax;
245 };
246 
247 #endif
#define SYSmax(a, b)
Definition: SYS_Math.h:1538
ArrayType::iterator iterator
GT_Size min() const
GLenum GLint * range
Definition: glcorearb.h:1925
void setSizeIfNeeded(exint minsize)
Definition: UT_Array.h:679
void concat(const GT_GEOSizeList &src)
GLuint start
Definition: glcorearb.h:475
GLsizei const GLfloat * value
Definition: glcorearb.h:824
#define GT_API
Definition: GT_API.h:13
int64 exint
Definition: SYS_Types.h:125
GA_Offset operator()(exint i) const
Definition: GT_GEOSupport.h:90
SYS_FORCE_INLINE void append(const T &item)
Definition: UT_RLEArray.h:222
bool monotonic() const
Definition: GT_GEOSupport.h:96
void setMin(GA_Size value)
GT_Size entries() const
void reserve(exint numtoadd, bool setentries=false)
Definition: GT_GEOSupport.h:57
GT_Size operator[](exint i) const
exint size() const
Definition: UT_Array.h:646
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:235
A range of elements in an index-map.
Definition: GA_Range.h:42
void dump(const char *msg="", bool full=true) const
Debug.
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
iterator begin() const
void setMax(GA_Size value)
GA_Size GA_Offset
Definition: GA_Types.h:641
iterator end() const
GLintptr offset
Definition: glcorearb.h:665
bool isTrivial() const
Definition: GT_GEOSupport.h:85
SYS_FORCE_INLINE void clear()
Definition: UT_RLEArray.h:149
bool is32Bit() const
GT_DataArrayHandle allocateArray() const
GLuint GLuint end
Definition: glcorearb.h:475
GT_Size size() const
GT_GEORLESizeList(const GT_GEORLESizeList &src)
long long int64
Definition: SYS_Types.h:116
void reserve(exint numtoadd, bool setentries=false)
SYS_FORCE_INLINE exint size() const
Definition: UT_RLEArray.h:146
void setCapacityIfNeeded(exint min_capacity)
Definition: UT_Array.h:603
void append(GT_Size item)
SYS_FORCE_INLINE iterator begin() const
Definition: UT_RLEArray.h:337
const GA_OffsetList & offsetList() const
Definition: GT_GEOSupport.h:97
void append(GA_Offset offset)
Definition: GT_GEOSupport.h:76
exint append()
Definition: UT_Array.h:142
void set(exint i, GA_Offset value)
Definition: GT_GEOSupport.h:89
SYS_FORCE_INLINE iterator end() const
Definition: UT_RLEArray.h:338
GT_Size size() const
void append(GT_Size item)
void setMin(GA_Size value)
GT_Size entries() const
Definition: GT_GEOSupport.h:86
int64 GT_Size
Definition: GT_Types.h:128
GA_Offset operator[](exint i) const
Definition: GT_GEOSupport.h:91
GA_AttributeOwner
Definition: GA_Types.h:34
void concat(const GT_GEORLESizeList &src)
void set(exint i, GA_Size value)
GT_DataArrayHandle allocateArray() const
GT_Size size() const
Definition: GT_GEOSupport.h:87
GT_Size operator()(exint i) const
GT_Size max() const
GT_GEOSizeList(const GT_GEOSizeList &src)
GT_Size max() const
Container class for all geometry.
Definition: GA_Detail.h:96
Definition: core.h:1131
GT_GEOOffsetList(const GT_GEOOffsetList &src)
Definition: GT_GEOSupport.h:39
GT_Size min() const
bool is32Bit() const
void clear()
Resets list to an empty list.
Definition: UT_Array.h:716
bool is32Bit() const
Definition: GT_GEOSupport.h:92
void setMax(GA_Size value)
#define SYSmin(a, b)
Definition: SYS_Math.h:1539
void dump(const char *msg="", bool full=true) const
Debug.
std::string OIIO_UTIL_API concat(string_view s, string_view t)
int64 getMemoryUsage() const
Definition: GT_GEOSupport.h:93
GLenum src
Definition: glcorearb.h:1793