HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_CountArray.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_CountArray.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_CountArray__
12 #define __GT_CountArray__
13 
14 #include "GT_API.h"
15 #include "GT_DataArray.h"
16 #include "GT_Handles.h"
17 
18 class UT_JSONWriter;
19 
20 /// A count/offset array
21 ///
22 /// In a polygon mesh, there is a list of faces. Each face has a number of
23 /// vertices and a list of vertices. Thus, for each polygon, there's an offset
24 /// into the vertex array and a count of the number of vertices to extract.
25 /// This array manages those offsets/counts efficiently
26 /// For example, if there are counts [3, 4, 2], the corresponding offset array
27 /// would be [0, 3, 7]. Thus: @code
28 /// counts.getOffset(0) == 0;
29 /// counts.getOffset(1) == 3;
30 /// counts.getOffset(2) == 7;
31 /// counts.getCount(0) == 3;
32 /// counts.getCount(1) == 4;
33 /// counts.getCount(2) == 2;
34 /// @endcode
36 {
37 public:
39  : myOffsets()
40  , myMaxCount(0)
41  , myMinCount(SYS_INT32_MAX)
42  {
43  }
45  : myOffsets(src.myOffsets)
46  , myMinCount(src.myMinCount)
47  , myMaxCount(src.myMaxCount)
48  {
49  }
51  GT_Size mincount=0, GT_Size maxcount=0)
52  : myOffsets()
53  {
54  init(counts, mincount, maxcount);
55  }
56 
57  /// Return memory used
58  exint getMemoryUsage() const;
59  /// harden the data array
60  void harden();
61 
62  /// Clear the count array
63  void clear()
64  {
65  myOffsets = GT_DataArrayHandle();
66  myMaxCount = 0;
67  }
68 
69  /// Return the storage type
71  {
72  return myOffsets ? myOffsets->getStorage() : GT_STORE_INT32;
73  }
74 
75  /// Initialize given an array of counts
76  void init(const GT_DataArrayHandle &counts,
77  GT_Size mincount=0, GT_Size maxcount=0);
78  /// Initialize when you know that there are @c entries that are all the
79  /// same @c repeated_value.
80  void init(exint entries, exint repeated_value);
81 
82  GT_Size entries() const { return myOffsets ? myOffsets->entries() : 0; }
84  { return idx ? myOffsets->getI64(idx-1) : 0; }
85  GT_Size getCount(exint idx) const
86  {
87  GT_Size size = myOffsets->getI64(idx);
88  if (idx)
89  size -= myOffsets->getI64(idx-1);
90  return size;
91  }
92 
93  /// Test equality
94  bool isEqual(const GT_CountArray &other) const
95  {
96  if (myMinCount != other.myMinCount
97  || myMaxCount != other.myMaxCount)
98  {
99  return false;
100  }
101  if (!myOffsets || !other.myOffsets)
102  return !myOffsets && !other.myOffsets;
103  return myOffsets->isEqual(*other.myOffsets);
104  }
105  bool operator==(const GT_CountArray &other) const
106  { return isEqual(other); }
107  bool operator!=(const GT_CountArray &other) const
108  { return !isEqual(other); }
109 
110  /// Return the minimum value that @c getCount() can return
111  GT_Size getMinCount() const { return myMinCount; }
112  /// Return the maximum value that @c getCount() can return
113  GT_Size getMaxCount() const { return myMaxCount; }
114 
115  /// Return the sum of all the counts
116  GT_Size sumCounts() const { return getOffset(entries()); }
117 
118  GT_DataArrayHandle extractCounts() const;
119  GT_DataArrayHandle extractOffsets() const;
120 
121  /// Creates a list of {0,0,0, 1,1,1,1,1, 2,2} from {3,5,2}
122  GT_DataArrayHandle buildRepeatList() const;
123 
124  /// Saves as an array of the counts (not the offsets). i.e.
125  /// [ getCount(0), getCount(1), ... getCount(n) ]
126  bool save(UT_JSONWriter &w) const;
127 private:
128  GT_DataArrayHandle myOffsets;
129  GT_Size myMinCount;
130  GT_Size myMaxCount;
131 };
132 
133 #endif
GT_Storage
Definition: GT_Types.h:17
bool isEqual(const GT_CountArray &other) const
Test equality.
Definition: GT_CountArray.h:94
GT_Offset getOffset(exint idx) const
Definition: GT_CountArray.h:83
GT_CountArray(const GT_DataArrayHandle &counts, GT_Size mincount=0, GT_Size maxcount=0)
Definition: GT_CountArray.h:50
#define SYS_INT32_MAX
Definition: SYS_Types.h:162
#define GT_API
Definition: GT_API.h:11
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
GLsizeiptr size
Definition: glcorearb.h:663
bool operator==(const GT_CountArray &other) const
GT_Storage getStorage() const
Return the storage type.
Definition: GT_CountArray.h:70
UT_IntrusivePtr< GT_DataArray > GT_DataArrayHandle
Definition: GT_DataArray.h:30
int64 exint
Definition: SYS_Types.h:116
GT_Size getMinCount() const
Return the minimum value that getCount() can return.
GT_Size getMaxCount() const
Return the maximum value that getCount() can return.
png_infop png_sPLT_tpp entries
Definition: png.h:2481
void clear()
Clear the count array.
Definition: GT_CountArray.h:63
GT_Size entries() const
Definition: GT_CountArray.h:82
bool operator!=(const GT_CountArray &other) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
int64 GT_Offset
Definition: GT_Types.h:113
int64 GT_Size
Definition: GT_Types.h:112
GT_Size getCount(exint idx) const
Definition: GT_CountArray.h:85
GT_Size sumCounts() const
Return the sum of all the counts.
GT_CountArray(const GT_CountArray &src)
Definition: GT_CountArray.h:44
GLenum src
Definition: glcorearb.h:1792