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 <UT/UT_Array.h>
18 #include <UT/UT_BoundingBox.h>
19 #include <UT/UT_Options.h>
20 #include <UT/UT_StringArray.h>
21 #include <UT/UT_ArrayStringMap.h>
22 
23 #include "GA_Types.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  /// Get/Set the preferred precision
184  /// Availability: level >= GA_STAT_BRIEF
185  void setPrecision(GA_Precision prec) { myPrecision = prec; }
186  GA_Precision getPrecision() const { return myPrecision; }
187  /// @}
188 
189  /// @{
190  /// Attribute status.
191  /// Availability: level >= GA_STAT_NORMAL
193  {
194  clearAttributes(GA_ATTRIB_VERTEX);
195  clearAttributes(GA_ATTRIB_POINT);
196  clearAttributes(GA_ATTRIB_PRIMITIVE);
197  clearAttributes(GA_ATTRIB_GLOBAL);
198  }
200  {
201  myAttributes[owner].clear();
202  }
204  const ga_StatAttribute &attrib)
205  {
206  myAttributes[owner].append(attrib);
207  }
209  {
210  return myAttributes[owner].entries();
211  }
213  GA_Size i) const
214  {
215  return myAttributes[owner](i);
216  }
217  /// @}
218 
219  /// @{
220  /// Group information.
221  /// Availability: level >= GA_STAT_NORMAL
223  {
224  clearGroups(GA_GROUP_POINT);
225  clearGroups(GA_GROUP_PRIMITIVE);
226  clearGroups(GA_GROUP_EDGE);
227  clearGroups(GA_GROUP_BREAKPOINT);
228  clearGroups(GA_GROUP_VERTEX);
229  }
231  {
232  myGroups[gtype].setCapacity(0);
233  }
235  {
236  myGroups[gtype].append(group);
237  }
239  {
240  return myGroups[gtype].entries();
241  }
242  const ga_StatGroup &getGroup(GA_GroupType gtype, GA_Size i) const
243  {
244  return myGroups[gtype](i);
245  }
246  /// @}
247 
248 
249  /// Get the info block options which were set by the stat() operation
250  /// Special options that will be used for quick stats (when the stat level
251  /// is STAT_LEVEL_BRIEF.
252  /// - string primcount_summary
253  /// - string attribute_summary
254  /// - string group_summary
255  /// If possible, the file format should set these from any header
256  /// information.
257  const UT_Options &getInfoOptions() const { return myInfoOptions; }
258 
259  /// Set the info block options stored in the file
260  /// If a float array option is found with the @c bounds_name, it will be
261  /// used to initialize the bounding box of the stat.
262  ///
263  /// The file stat should set these options if possible.
264  void setInfoOptions(const UT_Options &info,
265  const char *bounds_name="bounds");
266 
267  /// @{
268  /// Primitive interface
269  /// Availability: level >= GA_STAT_FULL
271  {
272  myPrimitiveTypes.clear();
273  }
274  void appendPrimitive(const UT_StringHolder &type_name)
275  {
276  myPrimitiveTypes[type_name]++;
277  }
278  void setPrimitiveCount(const UT_StringHolder &type_name,
279  GA_Size count)
280  {
281  myPrimitiveTypes[type_name] = count;
282  }
284  {
285  auto it = myPrimitiveTypes.find(type_name);
286  if (it == myPrimitiveTypes.end())
287  return 0;
288  return it->second;
289  }
290  void getPrimitiveTypes(UT_StringArray &type_names) const
291  {
292  type_names.clear();
293  for (auto it = myPrimitiveTypes.begin();
294  it != myPrimitiveTypes.end(); ++it)
295  {
296  type_names.append(it->first);
297  }
298  type_names.sort();
299  }
300  /// @}
301 
302  /// @{
303  /// Volume interface
304  /// Availability: level >= GA_STAT_FULL
306  {
307  myVolumes.clear();
308  }
309  void appendVolume(GA_Index idx, const char *name, int rx, int ry, int rz)
310  {
311  myVolumes.append(ga_StatVolume(idx, name, rx, ry, rz));
312  }
313  int getNumVolumes() const { return myVolumes.entries(); }
314  const ga_StatVolume &getVolume(int idx) const { return myVolumes(idx); }
315  /// @}
316 
317  /// @{
318  /// Get bounding box
319  /// Availability: level >= GA_STAT_FULL
320  const UT_BoundingBox &getBounds() const { return myBox; }
321  void setBounds(const UT_BoundingBox &b) { myBox = b; }
322  /// @}
323 
324  /// Common output
325  void output(UT_WorkBuffer &buffer, GA_STAT_LEVEL level,
326  bool pretty_print) const;
327 
328  /// Output attribute information only. This appends to the work buffer.
329  void outputAttributes(UT_WorkBuffer &buffer,
330  bool pretty_print) const;
331  /// Output attribute information only. This appends to the work buffer
332  void outputGroups(UT_WorkBuffer &buffer,
333  bool pretty_print) const;
334  /// Output volume information only. This appends to the work buffer
335  void outputVolumes(UT_WorkBuffer &buffer,
336  bool pretty_print) const;
337 
338  /// @{
339  /// Set/get the GA_IO which performed the stat
340  void setIO(const GA_IO *io) { myIO = io; }
341  const GA_IO *getIO() const { return myIO; }
342 
343 
344 private:
345  GA_Size myPointCount;
346  GA_Size myVertexCount;
347  GA_Size myPrimitiveCount;
348 
349  GA_Precision myPrecision;
350 
353  UT_Array<ga_StatVolume> myVolumes;
354 
355  UT_ArrayStringMap<GA_Size> myPrimitiveTypes;
356  UT_Options myInfoOptions;
357  UT_BoundingBox myBox;
358 
359  const GA_IO *myIO;
360 };
361 
362 #endif
GLdouble s
Definition: glew.h:1390
const GA_IO * getIO() const
Definition: GA_Stat.h:341
const ga_StatAttribute & getAttribute(GA_AttributeOwner owner, GA_Size i) const
Definition: GA_Stat.h:212
const ga_StatGroup & getGroup(GA_GroupType gtype, GA_Size i) const
Definition: GA_Stat.h:242
Data has no numeric representation.
Definition: GA_Types.h:102
void appendPrimitive(const UT_StringHolder &type_name)
Definition: GA_Stat.h:274
void setRes(GA_Size rx, GA_Size ry, GA_Size rz)
Definition: GA_Stat.h:151
void clearAllGroups()
Definition: GA_Stat.h:222
GLuint const GLchar * name
Definition: glew.h:1814
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 setPrecision(GA_Precision prec)
Definition: GA_Stat.h:185
void appendVolume(GA_Index idx, const char *name, int rx, int ry, int rz)
Definition: GA_Stat.h:309
GA_Precision
Definition: GA_Types.h:86
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
void clearAttributes(GA_AttributeOwner owner)
Definition: GA_Stat.h:199
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:230
GA_Precision getPrecision() const
Definition: GA_Stat.h:186
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:147
void clearAllAttributes()
Definition: GA_Stat.h:192
void setPointCount(GA_Size sz)
Definition: GA_Stat.h:177
GA_Size getAttributeCount(GA_AttributeOwner owner) const
Definition: GA_Stat.h:208
GA_Size yres() const
Definition: GA_Stat.h:146
const char * getName() const
Definition: GA_Stat.h:77
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:233
void clearVolumes()
Definition: GA_Stat.h:305
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:141
GA_Size getGroupCount(GA_GroupType gtype) const
Definition: GA_Stat.h:238
const UT_StringHolder & getNameHolder() const
Definition: GA_Stat.h:143
const ga_StatVolume & getVolume(int idx) const
Definition: GA_Stat.h:314
int getNumVolumes() const
Definition: GA_Stat.h:313
void setDescription(const UT_StringHolder &d)
Definition: GA_Stat.h:91
GLuint buffer
Definition: glew.h:1680
void setBounds(const UT_BoundingBox &b)
Definition: GA_Stat.h:321
const char * getDescription() const
Definition: GA_Stat.h:83
GLsizei n
Definition: glew.h:4040
void setEntries(GA_Size e)
Definition: GA_Stat.h:121
void clearPrimitiveTypes()
Definition: GA_Stat.h:270
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:278
GA_Size getPrimitiveCount() const
Definition: GA_Stat.h:175
Simple class to store attribute definition (without data)
Definition: GA_Stat.h:57
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:633
void setName(const UT_StringHolder &n)
Definition: GA_Stat.h:120
void appendGroup(GA_GroupType gtype, const ga_StatGroup &group)
Definition: GA_Stat.h:234
exint append()
Definition: UT_Array.h:95
GA_TypeInfo
Definition: GA_Types.h:99
void setName(const UT_StringHolder &n)
Definition: GA_Stat.h:149
GA_Size getPrimitiveTypeCount(const UT_StringRef &type_name) const
Definition: GA_Stat.h:283
const char * getTypeName() const
Definition: GA_Stat.h:78
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
void setIO(const GA_IO *io)
Definition: GA_Stat.h:340
GA_AttributeOwner
Definition: GA_Types.h:33
A map of string to various well defined value types.
Definition: UT_Options.h:84
Class to return information about a GA_Detail.
Definition: GA_Stat.h:50
const UT_Options & getInfoOptions() const
Definition: GA_Stat.h:257
void clear()
Definition: GA_Stat.h:159
void getPrimitiveTypes(UT_StringArray &type_names) const
Definition: GA_Stat.h:290
GA_GroupType
An ordinal enum for the different types of groups in GA.
Definition: GA_Types.h:159
GLuint GLuint GLsizei count
Definition: glew.h:1253
void setTypeInfo(GA_TypeInfo t)
Definition: GA_Stat.h:88
const UT_BoundingBox & getBounds() const
Definition: GA_Stat.h:320
void appendAttribute(GA_AttributeOwner owner, const ga_StatAttribute &attrib)
Definition: GA_Stat.h:203
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:528
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
GLint level
Definition: glew.h:1252
GLdouble GLdouble t
Definition: glew.h:1398
GLboolean GLuint group
Definition: glew.h:2745