HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_PrimitiveTracker.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: GA_PrimitiveTracker.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GA_PrimitiveTracker__
12 #define __GA_PrimitiveTracker__
13 
14 #include "GA_API.h"
15 #include "GA_PrimitiveTypeId.h"
16 #include "GA_PrimitiveTypes.h"
17 #include "GA_PrimitiveFamilyMask.h"
18 #include "GA_Types.h"
19 #include <UT/UT_Array.h>
20 #include <UT/UT_Assert.h>
21 
23 
24 /// Class which keeps counts of each type of primitive
26 {
27 public:
30  : myCounts(nullptr)
31  , myEntries(0)
32  {}
35  {
36  clear();
37  }
38 
40  void add(int id)
41  {
42  if (id >= myEntries)
43  grow(id+1);
44  myCounts[id]++;
45  }
46  void add(const GA_PrimitiveTracker &that)
47  {
48  if (that.myEntries > myEntries)
49  grow(that.myEntries);
50  for (int id = 0; id < that.myEntries; ++id)
51  myCounts[id] += that.myCounts[id];
52  }
54  void addMultiple(int id, GA_Size n)
55  {
56  if (id >= myEntries)
57  grow(id+1);
58  myCounts[id] += n;
59  }
60  /// this += (changed - orig)
61  /// This is so that items can be added or removed in separate trackers in
62  /// parallel, and then the changes can be merged back into the original.
63  void applyDiff(const GA_PrimitiveTracker &orig, const GA_PrimitiveTracker &changed)
64  {
65  int maxentries = SYSmax(orig.myEntries, changed.myEntries);
66  if (maxentries > myEntries)
67  grow(maxentries);
68  for (int id = 0; id < maxentries; ++id)
69  myCounts[id] += ((id < changed.myEntries) ? changed.myCounts[id] : 0)
70  - ((id < orig.myEntries) ? orig.myCounts[id] : 0);
71  }
73  void del(int id)
74  {
75  UT_ASSERT_P(id < myEntries);
76  myCounts[id]--;
77  UT_ASSERT_P(myCounts[id] >= 0);
78  }
79  void clear()
80  {
81  if (myEntries)
82  grow(0);
83  }
84  bool contains(const GA_PrimitiveTypeId &type) const
85  {
86  int id = type.get();
87  return id >= myEntries ? false : myCounts[id] > 0;
88  }
89  bool containsOnly(const UT_Array<GA_PrimitiveTypeId> &allowed) const
90  {
91  for (int id = 0; id < myEntries; id++)
92  {
93  if (!myCounts[id])
94  continue;
95 
96  // See if we are in the allowed list.
97  bool matched = false;
98  for (auto && allow : allowed)
99  {
100  if (allow.get() == id)
101  {
102  matched = true;
103  break;
104  }
105  }
106  if (!matched)
107  return false;
108  }
109  return true;
110  }
112  {
113  int id = type.get();
114  return id >= myEntries ? 0 : myCounts[id];
115  }
116 
118  {
119  GA_Size total = 0;
120  if (family & GA_FAMILY_FACE)
121  {
122  total += count(GA_PRIMPOLY);
123  total += count(GA_PRIMBEZCURVE);
124  total += count(GA_PRIMNURBCURVE);
125  }
126  else if (family & GA_FAMILY_CURVE)
127  {
128  total += count(GA_PRIMBEZCURVE);
129  total += count(GA_PRIMNURBCURVE);
130  }
131 
132  if (family & GA_FAMILY_HULL)
133  {
134  total += count(GA_PRIMMESH);
135  total += count(GA_PRIMBEZSURF);
136  total += count(GA_PRIMNURBSURF);
137  }
138  else if (family & GA_FAMILY_TPSURF)
139  {
140  total += count(GA_PRIMBEZSURF);
141  total += count(GA_PRIMNURBSURF);
142  }
143 
144  if (family & GA_FAMILY_QUADRIC)
145  {
146  total += count(GA_PRIMCIRCLE);
147  total += count(GA_PRIMSPHERE);
148  total += count(GA_PRIMTUBE);
149  }
150 
151  if (family & GA_FAMILY_META) // does not include quadric!
152  {
153  total += count(GA_PRIMMETABALL);
154  total += count(GA_PRIMMETASQUAD);
155  total += count(GA_PRIMMETALINE);
156  total += count(GA_PRIMMETABEZ);
157  total += count(GA_PRIMMETATRI);
158  }
159 
160  if (family & GA_FAMILY_VOLUMEELEMENT)
161  {
162  total += count(GA_PRIMTETRAHEDRON);
163  total += count(GA_PRIMHEXAHEDRON);
164  }
165 
166  return total;
167  }
168 
170  {
171  if (myEntries != that.myEntries)
172  {
173  grow(that.myEntries);
174  }
175  for (int i = 0, n = myEntries; i < n; ++i)
176  {
177  myCounts[i] = that.myCounts[i];
178  }
179  return *this;
180  }
181 
182  /// Check to see if there are any primitives which have hasLocalTransform()
183  bool hasLocalTransform(const GA_PrimitiveFactory &f) const;
184 
185  /// Check to see if there are any primitives that may need to flush
186  /// CE buffesr.
187  bool hasCECaches(const GA_PrimitiveFactory &f) const;
188 
189  /// Extract the counts for each primitive type into an array. The array
190  /// should be large enough to hold gdp.getPrimitiveFactory().getTypeCount().
191  /// The method returns the sum of all the primitive in the list
192  GA_Size fillCounts(GA_Size *counts, GA_Size array_size) const;
193 
194  int64 getMemoryUsage(bool inclusive) const
195  {
196  int64 mem = inclusive ? sizeof(*this) : 0;
197  if (myEntries)
198  mem += myEntries * sizeof(myCounts[0]);
199  return mem;
200  }
201 
202 private:
203  void grow(int size);
204 
205  GA_Size *myCounts;
206  int myEntries;
207 };
208 
209 #endif
SYS_FORCE_INLINE ~GA_PrimitiveTracker()
#define SYSmax(a, b)
Definition: SYS_Math.h:1570
void add(const GA_PrimitiveTracker &that)
SYS_FORCE_INLINE GA_PrimitiveTracker()
#define GA_API
Definition: GA_API.h:14
GA_Size count(const GA_PrimitiveTypeId &type) const
SYS_FORCE_INLINE void add(int id)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
GA_PrimitiveFamilyMask
GA_Size countFamily(GA_PrimitiveFamilyMask family) const
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
Class which keeps counts of each type of primitive.
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
SYS_FORCE_INLINE void addMultiple(int id, GA_Size n)
long long int64
Definition: SYS_Types.h:116
SYS_FORCE_INLINE void del(int id)
GLuint id
Definition: glcorearb.h:655
SYS_FORCE_INLINE int get() const
bool contains(const GA_PrimitiveTypeId &type) const
GLsizeiptr size
Definition: glcorearb.h:664
GA_PrimitiveTracker & operator=(const GA_PrimitiveTracker &that)
void applyDiff(const GA_PrimitiveTracker &orig, const GA_PrimitiveTracker &changed)
bool containsOnly(const UT_Array< GA_PrimitiveTypeId > &allowed) const
int64 getMemoryUsage(bool inclusive) const
type
Definition: core.h:1059