HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GT_AttributeList.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_AttributeList.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_AttributeList__
12 #define __GT_AttributeList__
13 
14 #include "GT_API.h"
15 #include <UT/UT_IntrusivePtr.h>
16 #include "GT_Types.h"
17 #include "GT_DataArray.h"
18 #include "GT_AttributeMap.h"
19 #include "GT_Handles.h"
20 
21 class GT_DataArray;
22 class GT_AttributeMerge;
23 class UT_JSONWriter;
24 class GU_Detail;
25 
27  : public UT_IntrusiveRefCounter<GT_AttributeList>
28 {
29 public:
30  /// An attribute list stores a list of GT_DataArray values for each
31  /// attribute defined in the map. @c motion_segments specifies the number
32  /// of different motion segments.
33  GT_AttributeList(const GT_AttributeMapHandle &map, int motion_segments=1);
36 
37  /// Create an attribute list using variadic arguments (name value pairs)
38  /// You must pass pointers to the raw GT_DataArray objects. This method
39  /// will create handles which take ownership of the arrays. Pass a NULL
40  /// pointer as the sentinal attribute name for to denote the end of the
41  /// var-args.
42  /// For example: @code
43  /// GT_AttributeList::createAttributeList(
44  /// "P", new GT_Real32Array(...),
45  /// "N", new GT_Real32Array(...),
46  /// "uv", new GT_Real32Array(...),
47  /// NULL);
48  /// @endcode
49  static GT_AttributeListHandle createAttributeList(
50  const char *name,
52  ...
53  );
54 
55  /// Test whether two attribute lists match in their definition. If both
56  /// attribute lists are empty, this will count as a match.
57  static bool matchDefinition(const GT_AttributeListHandle &a,
58  const GT_AttributeListHandle &b);
59 
60 
61  /// Create a new attribute list, adding a new attribute in the process.
62  GT_AttributeListHandle addAttribute(const char *name,
63  const GT_DataArrayHandle &h,
64  bool replace_existing) const;
65 
66  /// Remove an attribute from this list, returning a new attribute list.
67  GT_AttributeListHandle removeAttribute(const char *name) const;
68 
69  /// Remove multiple attributes from this, returning a new attribute list.
70  GT_AttributeListHandle removeAttributes(const UT_StringArray &name) const;
71 
72 
73  /// Harden all the attribute lists
74  void harden();
75 
76  /// Harden a single attribute
77  void harden(int idx);
78 
79  /// Get a handle to the name map for this list.
80  const GT_AttributeMapHandle &getMap() const { return myMap; }
81 
82  /// Return the number of attributes in the list.
83  int entries() const
84  { return myMap->entries(); }
85 
86  /// Return the approximate memory usage. Because data can be shared, this
87  /// may not reflect the usage accurately.
88  int64 getMemoryUsage() const;
89 
90  /// Return the number of motion segements
91  int getSegments() const
92  { return myMotionSegments; }
93 
94  /// Return the list of names
95  const UT_StringArray &getNames() const
96  { return myMap->getNames(); }
97 
98  /// Return the data for the named array
99  const GT_DataArrayHandle &get(const char *name, int segment=0) const
100  { return get(myMap->get(name), segment); }
101 
102  /// Return the data for a given index
103  const GT_DataArrayHandle &get(int index, int motion_segment=0) const;
104 
105  /// Return the name for a given index
106  const char *getName(int index) const
107  { return myMap->getName(index); }
108 
109  /// Return the export name for a given index.
110  const char *getExportName(int index) const
111  { return myMap->getExportName(index); }
112 
113  /// Get original attribute owner for the given attribute.
114  GT_Owner getOriginalOwner(int idx) const
115  { return myMap->getOriginalOwner(idx); }
116 
117  /// Return the index for a given name (returns -1 if miss)
118  int getIndex(const char *name) const
119  { return myMap->get(name); }
120 
121  /// Test of an attribute name exists
122  bool hasName(const char *name) const
123  { return myMap->hasName(name); }
124 
125  /// Assign an array to a given index in the list.
126  void set(int idx, const GT_DataArrayHandle &h,
127  int motion_segment=0);
128 
129  /// Assign an array to a given index in the list for @b all motion segments
130  void setAllSegments(int idx,
131  const GT_DataArrayHandle &h);
132 
133  /// Copies an entire segment of data arrays from a source list to this list.
134  /// This is useful when combining multiple primitives into a single motion
135  /// blurred primitive for example.
136  /// @param dest_segment @n
137  /// Data arrays are copied to this segment in this list
138  /// @param source_list @n
139  /// Data arrays are copied from this source list
140  /// @param source_segment @n
141  /// Data arrays are copied from this segment in the source_list
142  /// @warning The source attribute list @b must have the same maps. The
143  /// code does @b not verify that the maps are the same.
144  bool copySegment(int dest_segment,
145  const GT_AttributeListHandle &source_list,
146  int source_segment=0);
147 
148  /// Create a transformed version of the attributes
150 
151  /// Create a new attribute list containing
152  GT_AttributeListHandle createConstant(GT_Offset offset,
153  GT_Size size) const;
154 
155  /// Create an attribute list of a subset of the contents
156  GT_AttributeListHandle createSubArray(GT_Offset start,
157  GT_Size size) const;
158 
159  /// Create a new attribute list based on the indirect indicies in the
160  /// @c list
161  GT_AttributeListHandle createIndirect(
162  const GT_DataArrayHandle &indirect) const;
163 
164  /// Merge attributes which don't already exist in this attribute list
165  GT_AttributeListHandle mergeNewAttributes(
166  const GT_AttributeListHandle &s) const;
167 
168  /// Create the "s" and "t" attributes for the given u/v vertex count.
169  /// The attributes will only be created if @c nu or @c nv is greater than 0
170  GT_AttributeListHandle createUV(int nu, int nv,
171  fpreal64 s0=0, fpreal64 s1=1,
172  fpreal64 t0=0, fpreal64 t1=1) const;
173 
174  /// Create a merged list of the two lists. This will merge a sub-array of
175  /// the first list and an indirect mapping of the second list.
176  /// This is used to merge a vertex list (l0) with a point list (l1)
177  static GT_AttributeListHandle createMerged(
178  const GT_AttributeMerge &map,
179  const GT_AttributeListHandle &l0,
180  GT_Offset l0_offset, GT_Size l0_size,
181  const GT_AttributeListHandle &l1,
182  const GT_DataArrayHandle &l1_indirect);
183 
184  /// Merge two lists, expanding the constant list to have arrays matching
185  /// the length of the varying array.
186  static GT_AttributeListHandle expandConstantMerge(
187  const GT_AttributeMerge &map,
188  const GT_AttributeListHandle &varying,
189  const GT_AttributeListHandle &constant,
190  GT_Offset const_index=0);
191 
192  /// Merge two lists, creating a constant value list, selecting a single
193  /// element from a varying list.
194  static GT_AttributeListHandle createConstantMerge(
195  const GT_AttributeMerge &map,
196  const GT_AttributeListHandle &varying,
198  const GT_AttributeListHandle &constant);
199 
200  /// Merge an array of N lists to form a single attribute list. All the
201  /// data is concatenated in order.
202  ///
203  /// This method will fail (return an empty list) if any lists don't have
204  /// matching attributes (including motion segments & order of attributes)
205  ///
206  /// The list may have NULL handles.
207  static GT_AttributeListHandle concatenateLists(
208  const UT_Array<GT_AttributeListHandle> &lists);
209 
210  /// Get a 64b hash of all data ids in the list. Return false if any attribs
211  /// have an invalid data id (-1)
212  bool getDataIdHash(int64 &hash, int segment=0) const;
213 
214  /// Refresh the any detail references and data IDs on all data arrays.
215  void updateGeoDetail(const GU_ConstDetailHandle &dtl,
216  GT_Owner scope) const;
217 
218  /// Debug method to dump the list to stdout
219  void dumpList(const char *label="", bool data_too = true);
220 
221  /// Save to a JSON stream
222  bool save(UT_JSONWriter &w) const;
223 
225  {
226  public:
228  : myList(NULL), myCurr(0), mySize(0), mySegment(0) {}
229  iterator(const iterator &src)
230  { *this = src; }
232 
234  {
235  return myList->get(myCurr,
236  mySegment);
237  }
238  const char *getName() const
239  {
240  return myList->getName(myCurr);
241  }
242 
243  void rewind() { myCurr = 0; }
244  void advance() { myCurr++; }
245  bool atEnd() const { return myCurr >= mySize; }
246 
247  iterator &operator++() { advance(); return *this; }
248  // No post increment as it is dangerous.
249  const iterator &operator=(const iterator &src)
250  {
251  myList = src.myList;
252  myCurr = src.myCurr;
253  mySize = src.mySize;
254  return *this;
255  }
256 
257  private:
258  iterator(const GT_AttributeList *list, int segment)
259  : myList(list),
260  mySegment(segment),
261  myCurr(0),
262  mySize(list->entries()) {}
263 
264  const GT_AttributeList *myList;
265  int myCurr, mySize, mySegment;
266  friend class GT_AttributeList;
267  };
268  /// Traverse over all attributes for a given motion segment
269  iterator begin(int segment=0) const { return iterator(this, segment); }
270 
271  // Forward declare nested class (and make it a friend)
272  class gt_CreateIndirectTask;
273  friend class gt_CreateIndirectTask;
274 private:
275  /// Create a new constant data array for the i'th element
276  const GT_DataArrayHandle createConstant(int idx, GT_Offset offset,
277  GT_Size size,
278  int segment) const;
279 
280  /// Create a new sub-array data array for the i'th element
281  const GT_DataArrayHandle createSubArray(int idx, GT_Offset start,
282  GT_Size size,
283  int segment) const;
284 
285  /// Create a new sub-array data array for the i'th element
286  const GT_DataArrayHandle createIndirect(int idx,
288  int segment) const;
289 
290  inline int getSegmentIndex(int index, int segment) const
291  { return index + segment*entries(); }
292 
293  // Keep the 32 bit int first in the structure. Since we inherit from
294  // GA_IntrusiveRefCounter, this alignment makes the object smaller.
295  int myMotionSegments;
296  const GT_AttributeMapHandle myMap;
297  GT_DataArrayHandle *myData;
298 
299  // For threading of creating indirect arrays
300 };
301 
302 #endif
Keep track of merging of attribute maps.
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2544
png_voidp s1
Definition: png.h:2193
const GT_DataArrayHandle & getData() const
GLuint start
Definition: glcorearb.h:474
bool hasName(const char *name) const
Test of an attribute name exists.
#define GT_API
Definition: GT_API.h:11
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
const GT_AttributeMapHandle & getMap() const
Get a handle to the name map for this list.
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
A reference counter base class for use with UT_IntrusivePtr.
GLsizeiptr size
Definition: glcorearb.h:663
const char * getName(int index) const
Return the name for a given index.
iterator(const iterator &src)
const UT_StringArray & getNames() const
Return the list of names.
long long int64
Definition: SYS_Types.h:100
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:38
double fpreal64
Definition: SYS_Types.h:185
GLintptr offset
Definition: glcorearb.h:664
GLboolean * data
Definition: glcorearb.h:130
int entries() const
Return the number of attributes in the list.
GLuint const GLchar * name
Definition: glcorearb.h:785
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_API const UT_StringHolder transform
GT_Owner
Definition: GT_Types.h:72
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
png_infop png_sPLT_tpp entries
Definition: png.h:2481
const char * getName() const
GLuint index
Definition: glcorearb.h:785
const char * getExportName(int index) const
Return the export name for a given index.
GLint GLenum GLint x
Definition: glcorearb.h:408
const void * indirect
Definition: glcorearb.h:1794
int getSegments() const
Return the number of motion segements.
iterator begin(int segment=0) const
Traverse over all attributes for a given motion segment.
GT_Owner getOriginalOwner(int idx) const
Get original attribute owner for the given attribute.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
int64 GT_Offset
Definition: GT_Types.h:110
int64 GT_Size
Definition: GT_Types.h:109
int getIndex(const char *name) const
Return the index for a given name (returns -1 if miss)
const iterator & operator=(const iterator &src)
GLenum src
Definition: glcorearb.h:1792