HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_Attribute.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_Attribute.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_Attribute__
14 #define __GA_Attribute__
15 
16 #include "GA_API.h"
17 #include "GA_AttributeProxy.h"
18 #include "GA_AttributeType.h"
19 #include "GA_Types.h"
20 
21 #include <UT/UT_Assert.h>
22 #include <UT/UT_StringHolder.h>
23 #include <UT/UT_UniquePtr.h>
24 
25 #include <SYS/SYS_StaticAssert.h>
26 #include <SYS/SYS_Inline.h>
27 #include <SYS/SYS_Types.h>
28 
29 #include <string>
30 #include <string.h>
31 
32 class GA_AIFBlindData;
33 class GA_AIFBlob;
34 class GA_AIFBlobArray;
35 class GA_AIFCompare;
36 class GA_AIFCopyData;
37 class GA_AIFDelta;
38 class GA_AIFEdit;
39 class GA_AIFIndexPair;
40 class GA_AIFInterp;
41 class GA_AIFJSON;
42 class GA_AIFMath;
43 class GA_AIFMerge;
44 class GA_AIFNumericArray;
49 class GA_AIFStat;
50 class GA_AIFStringTuple;
51 class GA_AIFTuple;
52 class GA_Attribute;
53 class GA_CEAttribute;
54 class GA_Defragment;
55 class GA_Detail;
56 class GA_IndexMap;
57 class GA_Range;
58 
59 class UT_JSONParser;
60 class UT_JSONWriter;
61 class UT_MemoryCounter;
62 class UT_OptionEntry;
63 class UT_Options;
64 class UT_String;
65 class UT_WorkBuffer;
66 
68 {
69 public:
72 
74 
75  GA_AttributeOptions &operator=(const GA_AttributeOptions &src);
76 
77  /// Reset to default.
78  void clear();
79 
80  /// Constructs a full UT_Options that includes all symbols that
81  /// are otherwise handled with member variables.
82  void buildFullOptions(UT_Options &fulloptions) const;
83 
84  /// Removes from our myOptions list any options that aren't custom
85  /// and assigns them to local variables. May then delete myOptions
86  /// if it is empty.
87  void extractBuiltinOptions();
88 
89  /// If no custom options are present, create it.
90  UT_Options &createOptions();
91 
92  /// Merges option list on top of our own
93  void mergeOptions(const GA_AttributeOptions &src);
94 
95  /// @{
96  /// Accessors
97  GA_TypeInfo typeInfo() const { return myTypeInfo; }
98  void setTypeInfo(GA_TypeInfo t) { myTypeInfo = t; }
99  bool isNonTransforming() const { return myIsNonTransforming; }
100  void setIsNonTransforming(bool v) { myIsNonTransforming = v; }
101  bool exportToInfoBlock() const { return myExportToInfoBlock; }
102  void setExportToInfoBlock(bool v) { myExportToInfoBlock = v; }
103  bool leaveOnGPU() const { return myLeaveOnGPU; }
104  void setLeaveOnGPU(bool v) { myLeaveOnGPU = v; }
105  /// @}
106 
107  /// Check whether the exportOnMerge() flag has been set, or whether it's at
108  /// its default.
109  bool exportOnMergeSet() const { return myExportOnMergeValid; }
110  /// Check to see whether the export on merge is enabled. If the flag
111  /// hasn't been set, the default value will be used.
112  bool exportOnMerge(bool defval=false) const
113  { return myExportOnMergeValid ? myExportOnMerge : defval; }
114  /// Set the export on merge flag
115  void setExportOnMerge(bool v)
116  {
117  myExportOnMergeValid = true;
118  myExportOnMerge = v;
119  }
120 
121  /// Check whether the exportOnSave() flag has been set, or whether it's at
122  /// its default.
123  bool exportOnSaveSet() const { return myExportOnSaveValid; }
124  /// Check to see whether the export on save is enabled. If the flag
125  /// hasn't been set, the default value will be used.
126  bool exportOnSave(bool defval=false) const
127  { return myExportOnSaveValid ? myExportOnSave : defval; }
128  /// Set the export on save flag
129  void setExportOnSave(bool v)
130  {
131  myExportOnSaveValid = true;
132  myExportOnSave = v;
133  }
134 
135  /// Check to see whether the attribute is a "string set". If the flag
136  /// hasn't been set, the default value will be used.
137  bool isStringSet(bool defval=false) const
138  { return myIsStringSetValid ? myIsStringSet : defval; }
139  /// Set the "string set" flag
140  void setIsStringSet(bool v)
141  {
142  myIsStringSetValid = true;
143  myIsStringSet = v;
144  }
145 
146  /// @{
147  /// Access to options
148  const UT_Options *options() const { return myOptions; }
149  void setOptions(const UT_Options &o);
150  void mergeOptions(const UT_Options &o);
151  void mergeOptions(const UT_Options &o,
152  bool (*match)(const UT_StringHolder &name,
153  const UT_OptionEntry *, void *),
154  void *data);
155  void clearOptions();
156  bool removeOption(const char *name);
157  /// @}
158 
159 private:
160  // Our custom options.
161  UT_Options *myOptions;
162 
163  GA_TypeInfo myTypeInfo;
164 
165  bool myIsNonTransforming : 1;
166  bool myExportOnMergeValid : 1, myExportOnMerge : 1;
167  bool myExportOnSaveValid : 1, myExportOnSave : 1;
168 
169  bool myIsStringSetValid : 1, myIsStringSet : 1;
170 
171  bool myExportToInfoBlock : 1;
172  bool myLeaveOnGPU : 1;
173 
174  bool myDetached : 1;
175 
176  friend class GA_Attribute;
177 };
178 
179 template<typename T>
180 static inline const T *GAgetAIF(const GA_Attribute &attrib)
181 {
183  return NULL;
184 }
185 
186 
187 /// @brief Definition of a geometry attribute
188 ///
189 /// An attribute can be attached to points, vertices, primitives or the detail
190 /// itself. The attribute is responsible for maintaining the data array.
191 ///
192 /// @see @ref Iterators for implications of paged allocation strategies.
193 ///
194 /// The attribute is responsible for providing interfaces (@ref AIF).
195 ///
197 {
198 public:
199  GA_Attribute(
200  const GA_AttributeType &type, const GA_IndexMap &index_map,
201  GA_AttributeScope scope, const UT_StringHolder &name);
202  virtual ~GA_Attribute();
203 
204  const GA_AttributeType &getType() const { return myType; }
205  const GA_IndexMap &getIndexMap() const { return myIndexMap; }
206  const GA_Detail &getDetail() const;
207  GA_Detail &getDetail();
208  GA_AttributeOwner getOwner() const;
209 
210  GA_AttributeScope getScope() const { return myScope; }
211  bool isGroup() const { return myScope == GA_SCOPE_GROUP; }
212 
213  /// @{
214  /// Obtains the proxy representative used as a reference holder to this
215  /// attribute. This proxy gets invalidated when the attribute gets deleted.
216  /// Invalidation clears the proxy's pointer to NULL, but the proxy's memory
217  /// stays valid, unlike the memory of the attribute object.
219  { return GA_AttributeProxyHandle(myProxy); }
221  { return GA_ConstAttributeProxyHandle(myProxy); }
222  /// @}
223 
224  /// @{
225  /// Attribute flags store certain mutable properties of the attribute,
226  /// largely used for internal book keeping and semantic error detection
227 
228  enum AttribFlag {
229  FLAG_TAIL_INITIALIZE = 1,
230  FLAG_STREAM_ACTIVE = 2,
231  FLAG_STREAM_NOPREEXIST = 4 // Note inversion of sense!
232  };
233 
234  bool hasFlag(AttribFlag flag) const
235  { return (myAttribFlags & flag) ? true : false; }
236 
237  void setFlag(AttribFlag flag, bool onoff)
238  {
239  if (onoff)
240  myAttribFlags |= (int)flag;
241  else
242  myAttribFlags &= ~(int)flag;
243  }
244 
245  /// @}
246 
247  /// Uses the "type" option to determine type information
248  /// @see getOptions()
251  {
252  return myOptions.myTypeInfo;
253  }
254 
255  /// Set the option. This sets the "type" option on the attribute
256  /// @see getOptions()
259  {
260  myOptions.myTypeInfo = type;
261  }
262 
263  /// Checks if an attribute should be treated as a texture coordinate attribute.
264  /// Ideally, we could rely on the type info being GA_TYPE_TEXTURE_COORD,
265  /// but old files don't have this, and various importers don't set this.
266  /// If a float[3] (optionnally float[2]) attribute's name starts with "uv"
267  /// and is followed by zero or more digits (and nothing else), it's probably
268  /// safe to assume that it should be treated as a texture attribute.
269  bool shouldInterpretAsTexCoord(bool allow_float2=false) const;
270 
271  /// Returns the approximate type of the attribute
272  GA_StorageClass getStorageClass() const;
273 
274  /// Size of the AIFTuple, if it exists. If it doesn't, 1.
275  int getTupleSize() const;
276 
277  // Methods to get intrinsic data
278  // getName() returns the unprefixed name (as opposed to getFullName())
279  // We have separate const char * versions as this is often passed
280  // to sprintf().
281  const UT_StringHolder &getName() const { return myName; }
282  const UT_StringHolder &getFullName() const { return myName; }
283 
284  /// The data ID is shared by attributes that represent the same underlying
285  /// data and is used by cache mechanisms to avoid rebuilding when data has
286  /// not really changed. An ID of -1 indicates that this attribute is not
287  /// going to get a new ID when its data is changed, and therefore is not
288  /// participating in this scheme.
289  ///
290  /// Two attributes can share the same data ID even when they don't share
291  /// the same internal data pages or even fragmentation patterns. Note
292  /// however that the data ID is not necessarily changed for topology
293  /// changes, so it is necessary to also compare topology data IDs in order
294  /// to be absolutely sure that two attributes sharing the same data ID
295  /// represent the same data (taking into account defragmentation).
297  GA_DataId getDataId() const { return myDataId; }
300  {
301  myDataId = nextDataId();
302  }
304  void bumpDataId()
305  {
306  if (myDataId != GA_INVALID_DATAID)
307  assignNewDataId();
308  }
310  void clearDataId() { myDataId = GA_INVALID_DATAID; }
311 
312  /// This clones the data ID from src. If src has an invalid data ID,
313  /// which can be the case for details not created by SOP_Node or
314  /// SIM_GeometryCopy, we default to bumping the destination data ID.
315  /// This should be used by functions like GA_Attribute::replace()
316  /// when an attribute's data is replaced with that of src.
317  ///
318  /// NOTE: We must always either clone or bump the data ID if we've
319  /// copied from another attribute, even if that src attribute
320  /// has an invalid data ID. See Bug 79446 and 79438.
322  void cloneDataId(const GA_Attribute &src,
323  bool allow_clear = false)
324  {
325  if (allow_clear || src.myDataId != -1)
326  myDataId = src.myDataId;
327  else
328  bumpDataId();
329  }
330  /// NOTE: Just call cloneDataId(src).
333  bool allow_clear = false)
334  {
335  cloneDataId(src, allow_clear);
336  }
337 
338  /// The method to set array size
339  /// *Must* be implemented in subclasses
340  /// Return true if the attribute was resized.
341  virtual bool setArraySize(GA_Offset size) = 0;
342 
343  /// Try to compress data pages
344  /// Will try to compress *all* pages overlapping the specified offset range.
345  /// *Must* be implemented in subclasses
346  virtual void tryCompressAllPages(
347  GA_Offset start_offset = GA_Offset(0),
348  GA_Offset end_offset = GA_INVALID_OFFSET) = 0;
349 
350  /// Harden data pages
351  /// Will harden *all* pages overlapping the specified offset range.
352  /// Once this is done, multiple threads can write to an attribute in
353  /// parallel at a finer granularity than pages.
354  /// *Must* be implemented in subclasses
355  virtual void hardenAllPages(
356  GA_Offset start_offset = GA_Offset(0),
357  GA_Offset end_offset = GA_INVALID_OFFSET) = 0;
358 
359  /// The various concurrency levels supported by attributes for writing
360  /// per-element data.
362  /// No concurrent writes supported.
364  /// Concurrent writes to separate pages supported.
366  /// Concurrent writes to separate elements supported.
367  WRITE_CONCURRENCE_ELEMENT
368  };
369 
370  virtual WriteConcurrence getSupportedWriteConcurrence() const = 0;
371 
372  /// Return the attribute's copy interface or NULL
373  virtual const GA_AIFCopyData *getAIFCopyData() const;
374  /// Return the attribute's delta interface or NULL
375  virtual const GA_AIFDelta *getAIFDelta() const;
376  /// Return the attribute's tuple interface or NULL
377  virtual const GA_AIFTuple *getAIFTuple() const;
378  /// Return the attribute's math interface or NULL
379  virtual const GA_AIFMath *getAIFMath() const;
380  /// Return the attribute's merge interface or NULL
381  virtual const GA_AIFMerge *getAIFMerge() const;
382  /// Return the attribute's interpolation interface or NULL
383  virtual const GA_AIFInterp *getAIFInterp() const;
384  /// Return the attribute's blob interface or NULL
385  virtual const GA_AIFBlob *getAIFBlob() const;
386  /// Return the attribute's blob array interface or NULL
387  virtual const GA_AIFBlobArray *getAIFBlobArray() const;
388  /// Return the attribute's string tuple interface or NULL
389  virtual const GA_AIFStringTuple *getAIFStringTuple() const;
390  /// Return the attribute's shared string tuple interface or NULL
391  virtual const GA_AIFSharedStringTuple *getAIFSharedStringTuple() const;
392  /// Return the attribute's shared string array interface or NULL
393  virtual const GA_AIFSharedStringArray *getAIFSharedStringArray() const;
394  /// Return the attribute's shared options tuple interface or NULL
395  virtual const GA_AIFSharedDictTuple *getAIFSharedDictTuple() const;
396  /// Return the attribute's shared options tuple interface or NULL
397  virtual const GA_AIFSharedDictArray *getAIFSharedDictArray() const;
398  /// Return the attribute's index pair interface or NULL
399  virtual const GA_AIFIndexPair *getAIFIndexPair() const;
400  /// Return the attribute's blind data interface or NULL
401  virtual const GA_AIFBlindData *getAIFBlindData() const;
402  /// Return the attribute's edit interface or NULL
403  virtual const GA_AIFEdit *getAIFEdit() const;
404  /// Return the attribute's comparison interface or NULL
405  virtual const GA_AIFCompare *getAIFCompare() const;
406  /// Return the attribute's arraydata interface or NULL
407  virtual const GA_AIFNumericArray *getAIFNumericArray() const;
408 
409  /// Return the attribute's stat interface. Unlike other interfaces, this
410  /// method has default behaviour.
411  virtual const GA_AIFStat *getAIFStat() const;
412 
413  /// Generic method for getting an AIF by type
414  template <typename T> const T *getAIF() const { return GAgetAIF<T>(*this); }
415 
416  // Options can be used to associated arbitrary data with an attribute.
417  // Common options are defined in GA_Options.h
418  const GA_AttributeOptions &getOptions() const { return myOptions; }
419  GA_AttributeOptions &getOptions() { return myOptions; }
420 
421  /// Although an attribute may be a "point" or "normal", we may not want to
422  /// transform the point. This is the case with "rest" for example.
423  /// At the current time, this sets the flag corresponding with
424  /// "attribute:non_transforming" in the options.
425  /// @see needsTransform()
426  /// @see getTypeInfo()
428  {
429  myOptions.setIsNonTransforming(val);
430  }
431 
432  /// needTransform() checks whether the attribute is a
433  /// floating-point attribute whose type info is a transforming
434  /// type and whose non-transforming flag is false.
435  bool needsTransform(bool include_P = true) const
436  {
437  return getStorageClass() == GA_STORECLASS_FLOAT
438  && !myOptions.isNonTransforming()
439  && GAisTransformingType(getTypeInfo())
440  && (include_P || strcmp(getName(), "P") != 0);
441  }
442 
443  bool isDetached() const
444  {
445  return myOptions.myDetached;
446  }
447 
448  /// @{
449  /// Houdini forces certain restrictions on attribute names. However,
450  /// external software doesn't always have these restrictions. When
451  /// importing attributes, you can store the "real" attribute name, or use
452  /// the "export" name when exporting.
453  ///
454  /// @c getExportName() will return the attribute name if there's no export
455  /// name set.
456  void setExportName(const char *external_name);
457  bool hasExportName() const;
458  std::string getExportName() const;
459  /// @}
460 
461  /// Merge the options passed in with the options in the attribute
463  { myOptions.mergeOptions(src); }
464 
465  // Check to see the value of a specific option
466  bool importOption(const char *name, int &v) const;
467  bool importOption(const char *name, bool &v) const;
468  bool importOption(const char *name, fpreal32 &v) const;
469  bool importOption(const char *name, fpreal64 &v) const;
470  bool importOption(const char *name, UT_String &v) const;
471 
472  /// Methods which can be overridden from GA_Attribute
473 
474  /// Element destruction event. When an element is destroyed, the attribute
475  /// may be notified of this event.
476  virtual bool needDestruction() const;
477  /// Callback invoked if needsDestruction() returns true
478  virtual void destructElement(GA_Offset offset);
479 
480  /// The GA library expects any elements allocated at the end of the array
481  /// to be set to their default values. If this is not the case, then the
482  /// attribute can register itself for special initialization.
483  void setTailInitialization(bool onoff);
484 
485  /// Check whether the attribute is set to tail initialization
486  bool isTailInitialization() const
487  { return hasFlag(FLAG_TAIL_INITIALIZE); }
488 
489  /// When the array size is grown, attributes should initialize the value
490  /// appropriately. When an element is reused, however, the
491  /// reconstructElement is called. This happens if an element is deleted
492  /// then a new element is allocated (using the existing slot)
494  { reconstructElementBlock(offset, GA_Offset(1)); }
495 
496  /// When the array size is grown, attributes should initialize the value
497  /// appropriately. When elements are reused, however,
498  /// reconstructElementBlock is called. This happens if an element is
499  /// deleted and then a new element is allocated (using the existing slot)
500  virtual void reconstructElementBlock(GA_Offset offset, GA_Offset nelements) = 0;
501 
502  /// A method to "compact" any storage. For example, if there's a string
503  /// table associated with the attribute, this gives the attribute the option
504  /// to adjust the table to be more compact.
505  virtual void compactStorage();
506 
507  /// This method is called before a batch deletion operation. It allows the
508  /// attribute to mark objects as dirty so that there can be lazy computation
509  /// of data. For example, re-computing the number of elements in a group.
510  /// This method may be called multiple times, and so should typically just
511  /// set a flag (not perform a lot of computation).
512  virtual void batchDeletion();
513 
514  /// This method returns a new attribute of the same type with identical
515  /// settings. Attribute data is not copied. Derived classes implement
516  /// this method by overriding the virtual doClone(). Those classes not
517  /// supporting cloning are permitted to return NULL.
518  GA_Attribute *clone(const GA_IndexMap &index_map,
519  const UT_StringHolder &name,
520  bool clone_options) const;
521 
522  /// @section JSON-GA_Attribute JSON Schema: GA_Attribute
523  ///
524  /// The schema for an attribute consists of an array of two items. The
525  /// first entry contains of the definition of the attribute. The second
526  /// entry is the "private" data for the attribute. If there is no data for
527  /// the attribute (i.e. the attribute doesn't provide an AIFJSON), then a
528  /// null will be saved as the second element.
529  ///
530  /// The private data is saved/loaded by the GA_AIFJSON class for the
531  /// attribute.
532  ///
533  /// @code
534  /// [
535  /// "name" : "GA_Attribute",
536  /// "description" :
537  /// "An attribute is defined by an array with two items. The
538  /// first item is the definition of the attribute, the second
539  /// is private data associated with the attribute (may be null).",
540  /// "type" : "array",
541  /// "items" : [
542  /// { "$ref" : "GA_Attribute-Definition" }, // Attribute Definition
543  /// { "$ref" : "GA_Attribute-Data" }, // Specific type data
544  /// ],
545  /// ]
546  /// @endcode
547  ///
548  /// @section JSON-GA_Attribute-Definition JSON Schema: GA_Attribute-Definition
549  /// The attribute definition is a map containing the fields required to
550  /// recreate the attribute.
551  /// @code
552  /// {
553  /// "name" : "GA_Attribute-Definition",
554  /// "description" : "An map defining the attribute",
555  /// "type" : "orderedmap",
556  /// "properties": {
557  /// "scope": {
558  /// "type" : "string",
559  /// "optional" : true,
560  /// "default" : "public",
561  /// "description" : "Scope of the attribute",
562  /// },
563  /// "type": {
564  /// "type" : "string",
565  /// "description" : "Attribute type (ATI name)",
566  /// },
567  /// "name": {
568  /// "type" : "string",
569  /// "description" : "Name of the attribute",
570  /// },
571  /// "version": {
572  /// "type" : "integer",
573  /// "optional" : true,
574  /// "description" : "Version level for save",
575  /// },
576  /// "options": {
577  /// "type" : { "$ref" : "UT_Options" }
578  /// "description" : "Arbitrary options on the attribute",
579  /// },
580  /// },
581  /// }
582  /// @endcode
583  /// @see @ref JSON_FileFormat, GA_AttributeSet, GA_AttributeType
584 
585  /// Save the GA_Attribute-Definition section
586  bool jsonSaveDefinition(UT_JSONWriter &w) const;
587 
588  /// Load the GA_Attribute-Definition section
589  static bool jsonLoadDefinition(UT_JSONParser &p,
590  GA_AttributeScope &scope,
591  UT_WorkBuffer &type,
592  UT_WorkBuffer &name,
593  int64 &version,
594  GA_AttributeOptions &options);
595 
596  /// Return the AIF to handle saving/loading of the private data section
597  virtual const GA_AIFJSON *getAIFJSON() const;
598 
599  /// Return the optional "save" version number. This is passed to the JSON
600  /// attribute loader. If the version is <= 0, the version is not saved to
601  /// the file and 0 will be passed to the loader.
602  virtual int getSaveVersion() const;
603 
604  /// Debug validation of allocated array size
605  virtual bool debugValidateArrayCapacity(GA_Offset sz) const;
606 
607  /// Report the memory usage
608  ///
609  /// NOTE: If you're implementing this in a direct subclass of GA_Attribute,
610  /// call getBaseMemoryUsage() to get the amount of memory in the base
611  /// class. If in a more distant descendant class, call
612  /// Base::getMemoryUsage(false) to count the memory in Base and
613  /// above, excluding sizeof(Base).
614  virtual int64 getMemoryUsage(bool inclusive) const = 0;
615 
616  /// Count memory usage using a UT_MemoryCounter in order to count
617  /// shared memory correctly.
618  /// If inclusive is true, the size of this object is counted,
619  /// else only memory owned by this object is counted.
620  /// If this is pointed to by the calling object, inclusive should be true.
621  /// If this is contained in the calling object, inclusive should be false.
622  /// (Its memory was already counted in the size of the calling object.)
623  ///
624  /// NOTE: If you're implementing this in a direct subclass of GA_Attribute,
625  /// call getBaseMemoryUsage() to get the amount of memory in the base
626  /// class. If in a more distant descendant class, call
627  /// Base::countMemory(counter, false) to count the memory in Base and
628  /// above, excluding sizeof(Base).
629  virtual void countMemory(UT_MemoryCounter &counter, bool inclusive) const = 0;
630 
631  /// @{
632  /// @c defragment() defragments the memory used to store data elements
633  virtual void defragment(const GA_Defragment &defrag) = 0;
634  /// @}
635 
636  /// @private
637  /// Used only for optimizing merging of attributes
638  const GA_Attribute *getMergeSource() const { return myMergeSource; }
639 
640  /// This is only here so that select data outside of GA_Attribute
641  /// can also have data IDs, like GA_PrimitiveList and GA_EdgeGroup.
642  static GA_DataId nextDataId();
643 
644  /// @{
645  /// The attribute data may be moved to the GPU, and hence backed
646  /// by a compute buffer (GA_CEAttribute). Flushing will delete
647  /// our buffer & copy it back from the GPU if it has been marked
648  /// as modified.
649 
650  /// Caches a CE Attribute. If a cache already exists, the cached
651  /// data is returned and the write flag updated. If the cache
652  /// does not exist, an attempt is made to build a buffer. If
653  /// read is true, the buffer is initialized with the geometry data.
654  /// This can return NULL if a failure to build an attribute occurs
655  /// (for example, unsupported type or no GPU)
656  GA_CEAttribute *getCEAttribute(GA_StorageClass storage, int &tuplesize, bool isarray, bool read, bool write)
657  { return getCEAttribute(storage, GA_PRECISION_32, tuplesize, isarray, read, write); }
658  GA_CEAttribute *getCEAttribute(GA_StorageClass storage, GA_Precision precision, int &tuplesize, bool isarray, bool read, bool write);
659 
660  void setCEAttribute(GA_CEAttribute *ceattrib, bool leaveOnGPU=false);
661 
662  /// Any CE cache which was marked as written to will be copied
663  /// back to the CPU. It will be left on the GPU, however.
664  void flushCEWriteCaches(bool clearwriteback=true);
665  bool hasPendingCEWriteBack() const;
666 
667  /// Remove all CE Caches, copying back any marked as written to.
668  void flushCECaches();
669 
670  /// Steal the CE attribute from the source attribute, leaving the
671  /// src with a null CE attribute.
672  void stealCEAttribute(const GA_Attribute &src);
673  /// @}
674 
675  /// @{
676  /// During streaming operations it can be important to flag which
677  /// attributes are in the process of being modified. This way
678  /// attempts to random-access read them can be detected and thwarted
679  /// as they won't be valid.
680 
681  /// Is this attribute is currently being streamed? No random
682  /// reads should be done to this attribute. Default is that
683  /// it is not streaming.
684  bool isActivelyStreamed() const
685  { return hasFlag(FLAG_STREAM_ACTIVE); }
686 
687  void setActivelyStreamed(bool isstreaming)
688  { setFlag(FLAG_STREAM_ACTIVE, isstreaming); }
689 
690  /// Was this attribute created as a result of the stream operation?
691  /// This allows detection of attributes that only exist as a result
692  /// of the stream beginning. Default is that it existed.
693  bool existedPriorToStream() const
694  { return !hasFlag(FLAG_STREAM_NOPREEXIST); }
695 
696  void setExistedPriorToStream(bool preexisted)
697  { setFlag(FLAG_STREAM_NOPREEXIST, !preexisted); }
698  /// @}
699 
700 protected:
701  /// For use by getMemoryUsage and countMemory in subclasses to count the
702  /// amount of memory used by this base class (NOTE: *always* exclusive)
703  int64 getBaseMemoryUsage() const;
704 
705  /// Only called by GA_AttributeSet and GA_ElementGroup
706  void setDetached(bool detached)
707  {
708  myOptions.myDetached = detached;
709  }
710 private:
711  /// Method called by the GA_AttributeType::create() factory method to
712  /// initialize the object by calling virtual overrides not accessible
713  /// in our constructor.
714  void initialize();
715 
716  /// Create a new attribute of this type.
717  virtual GA_Attribute *doClone(const GA_IndexMap &index_map,
718  const UT_StringHolder &name) const;
719 
722  const UT_StringHolder &,
723  const UT_Options *,
724  const GA_AttributeOptions *) const;
725 
726  /// @{
727  /// @private
728  /// Only called by GA_AttributeSet and GA_ElementGroup.
729  bool setName(const UT_StringHolder &newname);
730  void setProxy(GA_AttributeProxy *proxy);
731  friend class GA_AttributeSet;
732  friend class GA_ElementGroup;
733  friend class GA_MergeMap;
734  /// @}
735 
736 public:
737 
738  /// Returns true iff that is an attribute whose content can be copied
739  /// from this without any type conversions. This is important to
740  /// avoid reallocation of an attribute if its storage type,
741  /// including tuple size, matches the source attribute exactly.
742  /// Subclasses should call this first and return false if
743  /// this returns false.
744  virtual bool matchesStorage(const GA_Attribute *that) const
745  {
746  if (that == NULL)
747  return false;
748  if (getType().getTypeId() != that->getType().getTypeId())
749  return false;
750  return true;
751  }
752  /// In the case that we're copying from an attribute whose storage
753  /// type matches this exactly, this function copies the metadata
754  /// not associated with the storage, e.g. myOptions,
755  /// *excluding* the name and the data ID.
756  /// The attribute class of that must match the attribute class of that.
757  /// Subclasses must call this.
758  virtual void copyNonStorageMetadata(const GA_Attribute *that)
759  {
760  // NOTE: We shouldn't change myScope or myOptions.myDetached.
761  // For example, if we replace the contents of a private or
762  // detached attribute with those of a public one, it shouldn't
763  // (and can't) become public.
764  // myScope is more an indication of where the *detail* is keeping
765  // track of this attribute, (or not tracking, for detached.)
766  bool detached = myOptions.myDetached;
767  myOptions = that->myOptions;
768  myOptions.myDetached = detached;
769 
770  // NOTE: DO NOT set tail initialization here! This is just an
771  // indication of whether there may be data at non-default values
772  // past myIndexMap.myMaxTouchedOffset.
773  // This should be copied in the implementations of replace(),
774  // instead, since that's associated with referencing the data.
775  //setTailInitialization(that->isTailInitialize());
776  }
777 
778  /// This replaces the entirety of this attribute's content and non-
779  /// storage metadata (except the name) with that of the src attribute.
780  /// matchesStorage(src) should already return true.
781  /// This is primarily for use by GA_AttributeSet::replace().
782  /// NOTE: The internal content sizes may not match exactly if the
783  /// attribute type may overallocate, but the sizes should be such
784  /// that any real data will fit in the destination, so be careful
785  /// and deal with the myTailInitialize flag appropriately if
786  /// any extra elements aren't equal to the default.
787  virtual void replace(const GA_Attribute &src) = 0;
788 
789  /// Copy attribute values for a single element.
790  /// NOTE: The default implementation just tries to use GA_AIFCopyData,
791  /// incurring 2 more virtual calls!
792  /// @{
793  virtual bool copy(GA_Offset desti, GA_Offset srci)
794  { return copy(desti, *this, srci); }
795  virtual bool copy(GA_Offset desti, const GA_Attribute &src, GA_Offset srci);
796  /// @}
797 
798  /// Copy attribute values for a range of elements.
799  /// NOTE: The default implementation just tries to use GA_AIFCopyData,
800  /// incurring 2 more virtual calls!
801  /// WARNING: These do not support overlapping ranges within a single attribute!
802  /// @{
803  virtual bool copy(const GA_Range &destrange, const GA_Range &srcrange)
804  { return copy(destrange, *this, srcrange); }
805  virtual bool copy(const GA_Range &destrange, const GA_Attribute &src, const GA_Range &srcrange);
806  /// @}
807 
808  /// Assign all elements of a range from a single attribute value.
809  /// NOTE: The default implementation just tries to use GA_AIFCopyData,
810  /// incurring 2 more virtual calls, falling back on calling copy() for
811  /// each element in the destination range, which incurs the cost of the
812  /// virtual call for each!
813  /// @{
814  virtual bool fill(const GA_Range &destrange, GA_Offset srci)
815  { return fill(destrange, *this, srci); }
816  virtual bool fill(const GA_Range &destrange, const GA_Attribute &src, GA_Offset srci);
817  /// @}
818 private:
819  const GA_AttributeType &myType;
820  const GA_IndexMap &myIndexMap; // For mapping
821  UT_StringHolder myName; // Unprefixed name
822  GA_AttributeScope myScope; // Public or private
823  GA_AttributeOptions myOptions; // Attribute options
824  GA_AttributeProxy *myProxy; // representative referencer
825  int64 myDataId;
826  const GA_Attribute *myMergeSource; // Needed to optimize merging
827  int myAttribFlags;
828  mutable GA_CEAttribute *myCEAttribute; // OpenCL Backing.
829 };
830 
831 #define GA_GET_AIF_SPECIALIZATION(AIF_NAME) \
832  template <> SYS_STATIC_INLINE const GA_##AIF_NAME * \
833  GAgetAIF(const GA_Attribute &attrib) { return attrib.get##AIF_NAME(); } \
834  /**/
835 GA_GET_AIF_SPECIALIZATION(AIFCopyData)
840 GA_GET_AIF_SPECIALIZATION(AIFInterp)
842 GA_GET_AIF_SPECIALIZATION(AIFBlobArray)
843 GA_GET_AIF_SPECIALIZATION(AIFStringTuple)
844 GA_GET_AIF_SPECIALIZATION(AIFSharedDictTuple)
845 GA_GET_AIF_SPECIALIZATION(AIFSharedDictArray)
846 GA_GET_AIF_SPECIALIZATION(AIFSharedStringTuple)
847 GA_GET_AIF_SPECIALIZATION(AIFSharedStringArray)
848 GA_GET_AIF_SPECIALIZATION(AIFIndexPair)
849 GA_GET_AIF_SPECIALIZATION(AIFBlindData)
851 GA_GET_AIF_SPECIALIZATION(AIFCompare)
852 GA_GET_AIF_SPECIALIZATION(AIFNumericArray)
853 #undef GA_GET_AIF_SPECIALIZATION
854 
855 /// @brief Automatically expand attribute data pages for threading
856 ///
857 /// Normally, threading is allowed only if each thread is guaranteed to write
858 /// to an individual page of data. Not all algorithms are amenable to this
859 /// constraint. Using the GA_AutoThreadExpand class will force the attribute
860 /// to harden all its data pages so that multiple threads can write across page
861 /// boundaries. Multiple threads are still prohibited from writing to the same
862 /// offset. In its destructor, the class will automatically call the compress
863 /// method to regain memory efficiency. For example: @code
864 /// void process(GA_RWAttributeRef &write, GA_ROAttributeRef &read)
865 /// {
866 /// GA_AutoHardenForThreading thread_write(*write.getAttribute());
867 /// // There's no need to harden the read-only attribute, but now that
868 /// // we've hardened the write attribute, our threaded algorithm is able
869 /// // to write data across page boundaries.
870 /// UTparallelFor(range, functor(write, read));
871 /// }
872 /// @endcode
874 {
875 public:
877  GA_Offset start_offset = GA_Offset(0),
878  GA_Offset end_offset = GA_INVALID_OFFSET)
879  : myAttribute(attribute)
880  , myStart(start_offset)
881  , myEnd(end_offset)
882  {
883  myAttribute.hardenAllPages(myStart, myEnd);
884  }
886  {
887  myAttribute.tryCompressAllPages(myStart, myEnd);
888  }
889 private:
890  GA_Attribute &myAttribute;
891  GA_Offset myStart;
892  GA_Offset myEnd;
893 };
894 
895 /// Utility for updating a data id by combining it with another.
896 /// If 'other' is negative then false is returned without any updates.
897 /// To use this for combining multiple data id's, initialize id with
898 /// -1. For example: @code
899 /// GA_DataId getDataId()
900 /// {
901 /// GA_DataId id = -1;
902 /// if (!mixDataId(id, myDataId0))
903 /// return -1;
904 /// if (!mixDataId(id, myDataId1))
905 /// return -1;
906 /// return id;
907 /// }
908 /// @endcode
909 static inline bool
910 GAcombineDataId(GA_DataId &id, GA_DataId other)
911 {
912  if (other < 0)
913  return false;
914  if (other > id)
915  id = other;
916  return true;
917 }
918 
920 
922 
923 #endif
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
type
Definition: core.h:977
GA_CEAttribute * getCEAttribute(GA_StorageClass storage, int &tuplesize, bool isarray, bool read, bool write)
Definition: GA_Attribute.h:656
UT_UniquePtr< const GA_Attribute > GA_ConstAttributeUPtr
Definition: GA_Attribute.h:921
SYS_FORCE_INLINE void bumpDataId()
Definition: GA_Attribute.h:304
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
GLuint counter
Definition: glew.h:2745
Generic Attribute Interface class to access an attribute as a array.
Generic Attribute Interface class to get/set data as index pairs.
virtual bool copy(const GA_Range &destrange, const GA_Range &srcrange)
Definition: GA_Attribute.h:803
void setTypeInfo(GA_TypeInfo t)
Definition: GA_Attribute.h:98
UT_IntrusivePtr< GA_AttributeProxy > GA_AttributeProxyHandle
UT_IntrusivePtr< const GA_AttributeProxy > GA_ConstAttributeProxyHandle
A specialization of GA_AIFDictTuple to access "shared strings".
bool exportOnSave(bool defval=false) const
Definition: GA_Attribute.h:126
GA_StorageClass
Definition: GA_Types.h:71
Attribute Interface class to perform numeric operations on attributes.
Definition: GA_AIFMath.h:88
int64 GA_DataId
Definition: GA_Types.h:686
GA_Precision
Definition: GA_Types.h:86
GA_Attribute * create(const GA_IndexMap &index_map, GA_AttributeScope scope, const UT_StringHolder &name, const UT_Options *creation_options, const GA_AttributeOptions *attribute_options) const
Attribute Interface for accessing generic blob data.
GA_ConstAttributeProxyHandle getProxy() const
Definition: GA_Attribute.h:220
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
void setExportOnMerge(bool v)
Set the export on merge flag.
Definition: GA_Attribute.h:115
void setExportOnSave(bool v)
Set the export on save flag.
Definition: GA_Attribute.h:129
bool hasFlag(AttribFlag flag) const
Definition: GA_Attribute.h:234
void setExportToInfoBlock(bool v)
Definition: GA_Attribute.h:102
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:88
#define GA_API
Definition: GA_API.h:14
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
void setExistedPriorToStream(bool preexisted)
Definition: GA_Attribute.h:696
GLuint const GLchar * name
Definition: glcorearb.h:785
#define GA_INVALID_DATAID
Definition: GA_Types.h:687
virtual bool matchesStorage(const GA_Attribute *that) const
Definition: GA_Attribute.h:744
GLenum src
Definition: glcorearb.h:1792
const UT_StringHolder & getName() const
Definition: GA_Attribute.h:281
SYS_FORCE_INLINE int getTypeId() const
float fpreal32
Definition: SYS_Types.h:200
void read(T &in, bool &v)
Definition: ImfXdr.h:611
GLdouble GLdouble t
Definition: glew.h:1403
No concurrent writes supported.
Definition: GA_Attribute.h:363
#define GA_INVALID_OFFSET
Definition: GA_Types.h:677
A range of elements in an index-map.
Definition: GA_Range.h:42
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
GLsizeiptr size
Definition: glcorearb.h:663
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
double fpreal64
Definition: SYS_Types.h:201
GA_Size GA_Offset
Definition: GA_Types.h:640
SYS_FORCE_INLINE void cloneDataId(const GA_Attribute &src, bool allow_clear=false)
Definition: GA_Attribute.h:322
virtual bool fill(const GA_Range &destrange, GA_Offset srci)
Definition: GA_Attribute.h:814
void setFlag(AttribFlag flag, bool onoff)
Definition: GA_Attribute.h:237
GA_AttributeScope
Definition: GA_Types.h:141
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
Attribute Interface for accessing generic blob data.
Definition: GA_AIFBlob.h:39
Automatically expand attribute data pages for threading.
Definition: GA_Attribute.h:873
const UT_StringHolder & getFullName() const
Definition: GA_Attribute.h:282
Attribute Interface for merging attribute data between details.
Definition: GA_AIFMerge.h:56
std::string OIIO_API replace(string_view str, string_view pattern, string_view replacement, bool global=false)
bool isGroup() const
Definition: GA_Attribute.h:211
This class holds a reference to an attribute. Such an indirection level allows an easy way to invalid...
const GLdouble * v
Definition: glcorearb.h:836
const UT_Options * options() const
Definition: GA_Attribute.h:148
bool needsTransform(bool include_P=true) const
Definition: GA_Attribute.h:435
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
Class to fill GA_Stat information about an attribute. This AIF is used to fill GA_Stat type informati...
Definition: GA_AIFStat.h:30
A specialization of GA_AIFStringArray to access "shared strings".
GA_AutoHardenForThreading(GA_Attribute &attribute, GA_Offset start_offset=GA_Offset(0), GA_Offset end_offset=GA_INVALID_OFFSET)
Definition: GA_Attribute.h:876
void mergeOptions(const GA_AttributeOptions &src)
Merge the options passed in with the options in the attribute.
Definition: GA_Attribute.h:462
long long int64
Definition: SYS_Types.h:116
Attribute Interface class to perform comparisons on attributes.
Definition: GA_AIFCompare.h:27
GLfloat GLfloat p
Definition: glew.h:16656
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
void setLeaveOnGPU(bool v)
Definition: GA_Attribute.h:104
OPENVDB_API void initialize()
Global registration of basic types.
Definition: logging.h:294
SYS_FORCE_INLINE GA_DataId getDataId() const
Definition: GA_Attribute.h:297
GA_AttributeOptions & getOptions()
Definition: GA_Attribute.h:419
GA_AttributeScope getScope() const
Definition: GA_Attribute.h:210
virtual void copyNonStorageMetadata(const GA_Attribute *that)
Definition: GA_Attribute.h:758
GA_TypeInfo
Definition: GA_Types.h:99
UT_UniquePtr< GA_Attribute > GA_AttributeUPtr
Definition: GA_Attribute.h:919
#define GA_GET_AIF_SPECIALIZATION(AIF_NAME)
Definition: GA_Attribute.h:831
const GA_AttributeType & getType() const
Definition: GA_Attribute.h:204
bool exportToInfoBlock() const
Definition: GA_Attribute.h:101
GT_API const UT_StringHolder version
GLenum GLint GLint * precision
Definition: glcorearb.h:1924
GLboolean * data
Definition: glcorearb.h:130
SYS_FORCE_INLINE void clearDataId()
Definition: GA_Attribute.h:310
GLuint GLfloat * val
Definition: glcorearb.h:1607
GA_AttributeOwner
Definition: GA_Types.h:33
A map of string to various well defined value types.
Definition: UT_Options.h:84
bool exportOnMergeSet() const
Definition: GA_Attribute.h:109
void setDetached(bool detached)
Only called by GA_AttributeSet and GA_ElementGroup.
Definition: GA_Attribute.h:706
void setActivelyStreamed(bool isstreaming)
Definition: GA_Attribute.h:687
SYS_FORCE_INLINE GA_TypeInfo getTypeInfo() const
Definition: GA_Attribute.h:250
bool leaveOnGPU() const
Definition: GA_Attribute.h:103
const GA_IndexMap & getIndexMap() const
Definition: GA_Attribute.h:205
virtual bool copy(GA_Offset desti, GA_Offset srci)
Definition: GA_Attribute.h:793
void reconstructElement(GA_Offset offset)
Definition: GA_Attribute.h:493
const T * getAIF() const
Generic method for getting an AIF by type.
Definition: GA_Attribute.h:414
GA_TypeInfo typeInfo() const
Definition: GA_Attribute.h:97
bool isStringSet(bool defval=false) const
Definition: GA_Attribute.h:137
const GA_AttributeOptions & getOptions() const
Definition: GA_Attribute.h:418
A specialization of GA_AIFDictArray to access "shared strings".
A specialization of GA_AIFStringTuple to access "shared strings".
Concurrent writes to separate pages supported.
Definition: GA_Attribute.h:365
OIIO_API bool copy(string_view from, string_view to, std::string &err)
Attribute Interface for blind data per element.
bool isNonTransforming() const
Definition: GA_Attribute.h:99
#define SYS_UNIMPLEMENTED_TEMPLATE(T)
OIIO_API bool attribute(string_view name, TypeDesc type, const void *val)
bool exportOnSaveSet() const
Definition: GA_Attribute.h:123
bool isDetached() const
Definition: GA_Attribute.h:443
getOption("OpenEXR.storage") storage
Definition: HDK_Image.dox:276
Container class for all geometry.
Definition: GA_Detail.h:95
Attribute Interface class to copy attribute data.
void setNonTransforming(bool val)
Definition: GA_Attribute.h:427
bool isTailInitialization() const
Check whether the attribute is set to tail initialization.
Definition: GA_Attribute.h:486
GLintptr offset
Definition: glcorearb.h:664
bool existedPriorToStream() const
Definition: GA_Attribute.h:693
SYS_FORCE_INLINE void assignNewDataId()
Definition: GA_Attribute.h:299
Attribute Interface for file I/O.
Definition: GA_AIFJSON.h:39
void setIsNonTransforming(bool v)
Definition: GA_Attribute.h:100
SYS_FORCE_INLINE void setTypeInfo(GA_TypeInfo type)
Definition: GA_Attribute.h:258
bool exportOnMerge(bool defval=false) const
Definition: GA_Attribute.h:112
void write(T &out, bool v)
Definition: ImfXdr.h:332
AIF to record changes to attribute values.
Definition: GA_AIFEdit.h:397
SYS_FORCE_INLINE void cloneOrBumpDataId(const GA_Attribute &src, bool allow_clear=false)
NOTE: Just call cloneDataId(src).
Definition: GA_Attribute.h:332
Generic Attribute Interface class to access an attribute as a tuple.
Definition: GA_AIFTuple.h:32
bool isActivelyStreamed() const
Definition: GA_Attribute.h:684
Generic Attribute Interface class to work with string indices directly, rather than string values...
void setIsStringSet(bool v)
Set the "string set" flag.
Definition: GA_Attribute.h:140
GA_AttributeProxyHandle getProxy()
Definition: GA_Attribute.h:218
FMT_NOINLINE OutputIt fill(OutputIt it, size_t n, const fill_t< Char > &fill)
Definition: format.h:1483