HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_Stat.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_Stat.h ( GA Library, C++)
7  *
8  * COMMENTS: Information filled out by stat() operation on GA_Detail.
9  *
10  */
11 
12 #ifndef __GA_Stat__
13 #define __GA_Stat__
14 
15 #include "GA_API.h"
16 
17 #include "GA_Types.h"
18 
19 #include <UT/UT_Array.h>
20 #include <UT/UT_BoundingBox.h>
21 #include <UT/UT_Options.h>
22 #include <UT/UT_StringArray.h>
23 #include <UT/UT_ArrayStringMap.h>
24 
25 class GA_IO;
26 
27 class UT_WorkBuffer;
28 
29 
30 /// Enum to define different levels of verbosity for GA_Detail::stat()
32 {
33  /// Fill minimal information (element counts). When accessing a file with
34  /// this verbosity level, it's possible that the file doesn't need to be
35  /// completely loaded.
36  GA_STAT_BRIEF = 0x00,
37 
38  /// Fill out attribute & group information. When accessing a file with
39  /// this verbosity level, the library may perform simple parsing (without
40  /// intepreting the all the data).
42 
43  /// Compute primitive type and bounding box information.
44  GA_STAT_FULL = 0x02,
45 };
46 
47 /// @brief Class to return information about a GA_Detail
48 ///
49 /// This class is filled out by the GA_Detail::stat() methods.
51 {
52 public:
53  GA_Stat();
54  ~GA_Stat();
55 
56  /// Simple class to store attribute definition (without data)
58  {
59  public:
60  ga_StatAttribute(const char *name="",
61  const char *type_name="",
63  GA_TypeInfo typeinfo = GA_TYPE_VOID,
64  int tuple_size = 1,
65  const char *description="")
66  : myName(name)
67  , myTypeName(type_name)
68  , myScope(scope)
69  , myTypeInfo(typeinfo)
70  , myTupleSize(tuple_size)
71  , myOptions()
72  , myDescription(description)
73  {
74  }
76 
77  const char *getName() const { return myName; }
78  const char *getTypeName() const { return myTypeName; }
79  GA_AttributeScope getScope() const { return myScope; }
80  GA_TypeInfo getTypeInfo() const { return myTypeInfo; }
81  int getTupleSize() const { return myTupleSize; }
82  const UT_Options &getOptions() const { return myOptions; }
83  const char *getDescription() const { return myDescription; }
84 
85  void setName(const UT_StringHolder &n) { myName = n; }
86  void setTypeName(const UT_StringHolder &n) { myTypeName = n; }
87  void setScope(GA_AttributeScope s) { myScope = s; }
88  void setTypeInfo(GA_TypeInfo t) { myTypeInfo = t; }
89  void setTupleSize(int ts) { myTupleSize = ts; }
90  void setOptions(const UT_Options &o) { myOptions = o; }
91  void setDescription(const UT_StringHolder &d) { myDescription = d; }
92 
93  private:
94  UT_StringHolder myName;
95  UT_StringHolder myTypeName; // Type name
96  GA_AttributeScope myScope;
97  GA_TypeInfo myTypeInfo;
98  UT_Options myOptions;
99  UT_StringHolder myDescription;
100  int myTupleSize;
101  };
102 
104  {
105  public:
106  // If the number of entries in the group is unknown, entries can be -1.
107  ga_StatGroup(const char *name="",
108  GA_Size entries=-1,
109  const char *description="")
110  : myName(name)
111  , myEntries(entries)
112  , myDescription(description)
113  {}
115 
116  const char *getName() const { return myName; }
117  GA_Size entries() const { return myEntries; }
118  const char *getDescription() const { return myDescription; }
119 
120  void setName(const UT_StringHolder &n) { myName = n; }
121  void setEntries(GA_Size e) { myEntries = e; }
122  void setDescription(const UT_StringHolder &n) { myDescription = n; }
123  private:
124  UT_StringHolder myName;
125  UT_StringHolder myDescription;
126  GA_Size myEntries;
127  };
128 
130  {
131  public:
133  const char *name="", int rx=0, int ry=0, int rz=0)
134  : myIndex(idx),
135  myName(name),
136  myResX(rx),
137  myResY(ry),
138  myResZ(rz)
139  {}
141 
142  const char *getName() const { return myName; }
143  const UT_StringHolder &getNameHolder() const { return myName; }
144  GA_Index getIndex() const { return myIndex; }
145  GA_Size xres() const { return myResX; }
146  GA_Size yres() const { return myResY; }
147  GA_Size zres() const { return myResZ; }
148 
149  void setName(const UT_StringHolder &n) { myName.harden(n); }
150  void setIndex(GA_Index idx) { myIndex = idx; }
151  void setRes(GA_Size rx, GA_Size ry, GA_Size rz)
152  { myResX = rx; myResY = ry; myResZ = rz; }
153  private:
154  UT_StringHolder myName;
155  GA_Index myIndex;
156  GA_Size myResX, myResY, myResZ;
157  };
158 
159  void clear()
160  {
161  setPointCount(0);
162  setVertexCount(0);
163  setPrimitiveCount(0);
164  clearAllAttributes();
165  clearAllGroups();
166  clearPrimitiveTypes();
167  clearVolumes();
168  }
169 
170  /// @{
171  /// Get/Set the number of elements in the detail
172  /// Availability: level >= GA_STAT_BRIEF
173  GA_Size getPointCount() const { return myPointCount; }
174  GA_Size getVertexCount() const { return myVertexCount; }
175  GA_Size getPrimitiveCount() const { return myPrimitiveCount; }
176 
177  void setPointCount(GA_Size sz) { myPointCount = sz; }
178  void setVertexCount(GA_Size sz) { myVertexCount = sz; }
179  void setPrimitiveCount(GA_Size sz) { myPrimitiveCount = sz; }
180  /// @}
181 
182  /// @{
183  /// Attribute status.
184  /// Availability: level >= GA_STAT_NORMAL
186  {
187  clearAttributes(GA_ATTRIB_VERTEX);
188  clearAttributes(GA_ATTRIB_POINT);
189  clearAttributes(GA_ATTRIB_PRIMITIVE);
190  clearAttributes(GA_ATTRIB_GLOBAL);
191  }
193  {
194  myAttributes[owner].clear();
195  }
197  const ga_StatAttribute &attrib)
198  {
199  myAttributes[owner].append(attrib);
200  }
202  {
203  return myAttributes[owner].entries();
204  }
206  GA_Size i) const
207  {
208  return myAttributes[owner](i);
209  }
210  /// @}
211 
212  /// @{
213  /// Group information.
214  /// Availability: level >= GA_STAT_NORMAL
216  {
217  clearGroups(GA_GROUP_POINT);
218  clearGroups(GA_GROUP_PRIMITIVE);
219  clearGroups(GA_GROUP_EDGE);
220  clearGroups(GA_GROUP_BREAKPOINT);
221  clearGroups(GA_GROUP_VERTEX);
222  }
224  {
225  myGroups[gtype].setCapacity(0);
226  }
227  void appendGroup(GA_GroupType gtype, const ga_StatGroup &group)
228  {
229  myGroups[gtype].append(group);
230  }
232  {
233  return myGroups[gtype].entries();
234  }
236  {
237  return myGroups[gtype](i);
238  }
239  /// @}
240 
241 
242  /// Get the info block options which were set by the stat() operation
243  /// Special options that will be used for quick stats (when the stat level
244  /// is STAT_LEVEL_BRIEF.
245  /// - string primcount_summary
246  /// - string attribute_summary
247  /// - string group_summary
248  /// If possible, the file format should set these from any header
249  /// information.
250  const UT_Options &getInfoOptions() const { return myInfoOptions; }
251 
252  /// Set the info block options stored in the file
253  /// If a float array option is found with the @c bounds_name, it will be
254  /// used to initialize the bounding box of the stat.
255  ///
256  /// The file stat should set these options if possible.
257  void setInfoOptions(const UT_Options &info,
258  const char *bounds_name="bounds");
259 
260  /// @{
261  /// Primitive interface
262  /// Availability: level >= GA_STAT_FULL
264  {
265  myPrimitiveTypes.clear();
266  }
267  void appendPrimitive(const UT_StringHolder &type_name)
268  {
269  myPrimitiveTypes[type_name]++;
270  }
271  void setPrimitiveCount(const UT_StringHolder &type_name,
272  GA_Size count)
273  {
274  myPrimitiveTypes[type_name] = count;
275  }
277  {
278  auto it = myPrimitiveTypes.find(type_name);
279  if (it == myPrimitiveTypes.end())
280  return 0;
281  return it->second;
282  }
283  void getPrimitiveTypes(UT_StringArray &type_names) const
284  {
285  type_names.clear();
286  for (auto it = myPrimitiveTypes.begin();
287  it != myPrimitiveTypes.end(); ++it)
288  {
289  type_names.append(it->first);
290  }
291  type_names.sort();
292  }
293  /// @}
294 
295  /// @{
296  /// Volume interface
297  /// Availability: level >= GA_STAT_FULL
299  {
300  myVolumes.clear();
301  }
302  void appendVolume(GA_Index idx, const char *name, int rx, int ry, int rz)
303  {
304  myVolumes.append(ga_StatVolume(idx, name, rx, ry, rz));
305  }
306  int getNumVolumes() const { return myVolumes.entries(); }
307  const ga_StatVolume &getVolume(int idx) const { return myVolumes(idx); }
308  /// @}
309 
310  /// @{
311  /// Get bounding box
312  /// Availability: level >= GA_STAT_FULL
313  const UT_BoundingBox &getBounds() const { return myBox; }
314  void setBounds(const UT_BoundingBox &b) { myBox = b; }
315  /// @}
316 
317  /// Common output
318  void output(UT_WorkBuffer &buffer, GA_STAT_LEVEL level,
319  bool pretty_print) const;
320 
321  /// Output attribute information only. This appends to the work buffer.
322  void outputAttributes(UT_WorkBuffer &buffer,
323  bool pretty_print) const;
324  /// Output attribute information only. This appends to the work buffer
325  void outputGroups(UT_WorkBuffer &buffer,
326  bool pretty_print) const;
327  /// Output volume information only. This appends to the work buffer
328  void outputVolumes(UT_WorkBuffer &buffer,
329  bool pretty_print) const;
330 
331  /// @{
332  /// Set/get the GA_IO which performed the stat
333  void setIO(const GA_IO *io) { myIO = io; }
334  const GA_IO *getIO() const { return myIO; }
335 
336 
337 private:
338  GA_Size myPointCount;
339  GA_Size myVertexCount;
340  GA_Size myPrimitiveCount;
341 
344  UT_Array<ga_StatVolume> myVolumes;
345 
346  UT_ArrayStringMap<GA_Size> myPrimitiveTypes;
347  UT_Options myInfoOptions;
348  UT_BoundingBox myBox;
349 
350  const GA_IO *myIO;
351 };
352 
353 #endif
const GA_IO * getIO() const
Definition: GA_Stat.h:334
const ga_StatAttribute & getAttribute(GA_AttributeOwner owner, GA_Size i) const
Definition: GA_Stat.h:205
const ga_StatGroup & getGroup(GA_GroupType gtype, GA_Size i) const
Definition: GA_Stat.h:235
Data has no numeric representation.
Definition: GA_Types.h:83
void appendPrimitive(const UT_StringHolder &type_name)
Definition: GA_Stat.h:267
void setRes(GA_Size rx, GA_Size ry, GA_Size rz)
Definition: GA_Stat.h:151
void clearAllGroups()
Definition: GA_Stat.h:215
ga_StatAttribute(const char *name="", const char *type_name="", GA_AttributeScope scope=GA_SCOPE_PUBLIC, GA_TypeInfo typeinfo=GA_TYPE_VOID, int tuple_size=1, const char *description="")
Definition: GA_Stat.h:60
GA_Index getIndex() const
Definition: GA_Stat.h:144
void appendVolume(GA_Index idx, const char *name, int rx, int ry, int rz)
Definition: GA_Stat.h:302
GA_AttributeScope getScope() const
Definition: GA_Stat.h:79
void sort(bool forward, bool numbered)
GA_Size xres() const
Definition: GA_Stat.h:145
GA_TypeInfo getTypeInfo() const
Definition: GA_Stat.h:80
GLint level
Definition: glcorearb.h:107
void clearAttributes(GA_AttributeOwner owner)
Definition: GA_Stat.h:192
GA_Size getVertexCount() const
Definition: GA_Stat.h:174
const char * getName() const
Definition: GA_Stat.h:142
void clearGroups(GA_GroupType gtype)
Definition: GA_Stat.h:223
GA_STAT_LEVEL
Enum to define different levels of verbosity for GA_Detail::stat()
Definition: GA_Stat.h:31
GA_Size zres() const
Definition: GA_Stat.h:147
#define GA_API
Definition: GA_API.h:12
void setName(const UT_StringHolder &n)
Definition: GA_Stat.h:85
const char * getName() const
Definition: GA_Stat.h:116
Standard user attribute level.
Definition: GA_Types.h:127
void clearAllAttributes()
Definition: GA_Stat.h:185
void setPointCount(GA_Size sz)
Definition: GA_Stat.h:177
GA_Size getAttributeCount(GA_AttributeOwner owner) const
Definition: GA_Stat.h:201
GA_Size yres() const
Definition: GA_Stat.h:146
const char * getName() const
Definition: GA_Stat.h:77
GLuint buffer
Definition: glcorearb.h:659
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
void clearVolumes()
Definition: GA_Stat.h:298
void setOptions(const UT_Options &o)
Definition: GA_Stat.h:90
void setDescription(const UT_StringHolder &n)
Definition: GA_Stat.h:122
void setVertexCount(GA_Size sz)
Definition: GA_Stat.h:178
int getTupleSize() const
Definition: GA_Stat.h:81
GA_AttributeScope
Definition: GA_Types.h:121
GLdouble n
Definition: glcorearb.h:2007
GA_Size getGroupCount(GA_GroupType gtype) const
Definition: GA_Stat.h:231
const UT_StringHolder & getNameHolder() const
Definition: GA_Stat.h:143
const ga_StatVolume & getVolume(int idx) const
Definition: GA_Stat.h:307
int getNumVolumes() const
Definition: GA_Stat.h:306
void setDescription(const UT_StringHolder &d)
Definition: GA_Stat.h:91
void setBounds(const UT_BoundingBox &b)
Definition: GA_Stat.h:314
const char * getDescription() const
Definition: GA_Stat.h:83
void setEntries(GA_Size e)
Definition: GA_Stat.h:121
void clearPrimitiveTypes()
Definition: GA_Stat.h:263
ga_StatVolume(GA_Index idx=-1, const char *name="", int rx=0, int ry=0, int rz=0)
Definition: GA_Stat.h:132
const char * getDescription() const
Definition: GA_Stat.h:118
void setPrimitiveCount(const UT_StringHolder &type_name, GA_Size count)
Definition: GA_Stat.h:271
GA_Size getPrimitiveCount() const
Definition: GA_Stat.h:175
GLuint const GLchar * name
Definition: glcorearb.h:785
Simple class to store attribute definition (without data)
Definition: GA_Stat.h:57
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
void setName(const UT_StringHolder &n)
Definition: GA_Stat.h:120
void appendGroup(GA_GroupType gtype, const ga_StatGroup &group)
Definition: GA_Stat.h:227
GLint GLsizei count
Definition: glcorearb.h:404
GA_TypeInfo
Definition: GA_Types.h:80
void setName(const UT_StringHolder &n)
Definition: GA_Stat.h:149
GA_Size getPrimitiveTypeCount(const UT_StringRef &type_name) const
Definition: GA_Stat.h:276
const char * getTypeName() const
Definition: GA_Stat.h:78
void setIO(const GA_IO *io)
Definition: GA_Stat.h:333
GA_AttributeOwner
Definition: GA_Types.h:33
A map of string to various well defined value types.
Definition: UT_Options.h:42
Class to return information about a GA_Detail.
Definition: GA_Stat.h:50
const UT_Options & getInfoOptions() const
Definition: GA_Stat.h:250
png_infop png_sPLT_tpp entries
Definition: png.h:2481
void clear()
Definition: GA_Stat.h:159
void getPrimitiveTypes(UT_StringArray &type_names) const
Definition: GA_Stat.h:283
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:138
void setTypeInfo(GA_TypeInfo t)
Definition: GA_Stat.h:88
exint append(void)
Definition: UT_Array.h:95
const UT_BoundingBox & getBounds() const
Definition: GA_Stat.h:313
void appendAttribute(GA_AttributeOwner owner, const ga_StatAttribute &attrib)
Definition: GA_Stat.h:196
Compute primitive type and bounding box information.
Definition: GA_Stat.h:44
GA_Size entries() const
Definition: GA_Stat.h:117
GA_Size getPointCount() const
Definition: GA_Stat.h:173
ga_StatGroup(const char *name="", GA_Size entries=-1, const char *description="")
Definition: GA_Stat.h:107
void setPrimitiveCount(GA_Size sz)
Definition: GA_Stat.h:179
void clear()
Resets list to an empty list.
Definition: UT_Array.h:513
void setTypeName(const UT_StringHolder &n)
Definition: GA_Stat.h:86
void setScope(GA_AttributeScope s)
Definition: GA_Stat.h:87
void setTupleSize(int ts)
Definition: GA_Stat.h:89
void setIndex(GA_Index idx)
Definition: GA_Stat.h:150
const UT_Options & getOptions() const
Definition: GA_Stat.h:82