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