OpenVDB 9.0.0
AttributeSet.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4/// @file points/AttributeSet.h
5///
6/// @authors Dan Bailey, Mihai Alden
7///
8/// @brief Set of Attribute Arrays which tracks metadata about each array.
9
10#ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
11#define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
12
13#include "AttributeArray.h"
14#include <openvdb/version.h>
15#include <openvdb/MetaMap.h>
16
17#include <limits>
18#include <memory>
19#include <vector>
20
21
22class TestAttributeSet;
23
24
25namespace openvdb {
27namespace OPENVDB_VERSION_NAME {
28namespace points {
29
30
31using GroupType = uint8_t;
32
33
34////////////////////////////////////////
35
36
37/// Ordered collection of uniquely-named attribute arrays
39{
40public:
41 enum { INVALID_POS = std::numeric_limits<size_t>::max() };
42
43 using Ptr = std::shared_ptr<AttributeSet>;
44 using ConstPtr = std::shared_ptr<const AttributeSet>;
45 using UniquePtr = std::unique_ptr<AttributeSet>;
46
47 class Descriptor;
48
49 using DescriptorPtr = std::shared_ptr<Descriptor>;
50 using DescriptorConstPtr = std::shared_ptr<const Descriptor>;
51
52 //////////
53
54 struct Util
55 {
56 /// Attribute and type name pair.
57 struct NameAndType {
58 NameAndType(const std::string& n, const NamePair& t, const Index s = 1)
59 : name(n), type(t), stride(s) {}
63 };
64
65 using NameAndTypeVec = std::vector<NameAndType>;
66 using NameToPosMap = std::map<std::string, size_t>;
67 using GroupIndex = std::pair<size_t, uint8_t>;
68 };
69
70 //////////
71
73
74 /// Construct a new AttributeSet from the given AttributeSet.
75 /// @param attributeSet the old attribute set
76 /// @param arrayLength the desired length of the arrays in the new AttributeSet
77 /// @param lock an optional scoped registry lock to avoid contention
78 /// @note This constructor is typically used to resize an existing AttributeSet as
79 /// it transfers attribute metadata such as hidden and transient flags
80 AttributeSet(const AttributeSet& attributeSet, Index arrayLength,
81 const AttributeArray::ScopedRegistryLock* lock = nullptr);
82
83 /// Construct a new AttributeSet from the given Descriptor.
84 /// @param descriptor stored in the new AttributeSet and used in construction
85 /// @param arrayLength the desired length of the arrays in the new AttributeSet
86 /// @param lock an optional scoped registry lock to avoid contention
87 /// @note Descriptors do not store attribute metadata such as hidden and transient flags
88 /// which live on the AttributeArrays, so for constructing from an existing AttributeSet
89 /// use the AttributeSet(const AttributeSet&, Index) constructor instead
90 AttributeSet(const DescriptorPtr& descriptor, Index arrayLength = 1,
91 const AttributeArray::ScopedRegistryLock* lock = nullptr);
92
93 /// Shallow copy constructor, the descriptor and attribute arrays will be shared.
95
96 /// Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.
98
99 //@{
100 /// @brief Return a reference to this attribute set's descriptor, which might
101 /// be shared with other sets.
102 Descriptor& descriptor() { return *mDescr; }
103 const Descriptor& descriptor() const { return *mDescr; }
104 //@}
105
106 /// @brief Return a pointer to this attribute set's descriptor, which might be
107 /// shared with other sets
108 DescriptorPtr descriptorPtr() const { return mDescr; }
109
110 /// Return the number of attributes in this set.
111 size_t size() const { return mAttrs.size(); }
112
113 /// Return the number of bytes of memory used by this attribute set.
114 size_t memUsage() const;
115
116 /// @brief Return the position of the attribute array whose name is @a name,
117 /// or @c INVALID_POS if no match is found.
118 size_t find(const std::string& name) const;
119
120 /// @brief Replace the attribute array whose name is @a name.
121 /// @return The position of the updated attribute array or @c INVALID_POS
122 /// if the given name does not exist or if the replacement failed because
123 /// the new array type does not comply with the descriptor.
124 size_t replace(const std::string& name, const AttributeArray::Ptr&);
125
126 /// @brief Replace the attribute array stored at position @a pos in this container.
127 /// @return The position of the updated attribute array or @c INVALID_POS
128 /// if replacement failed because the new array type does not comply with
129 /// the descriptor.
130 size_t replace(size_t pos, const AttributeArray::Ptr&);
131
132 //@{
133 /// @brief Return a pointer to the attribute array whose name is @a name or
134 /// a null pointer if no match is found.
135 const AttributeArray* getConst(const std::string& name) const;
136 const AttributeArray* get(const std::string& name) const;
137 AttributeArray* get(const std::string& name);
138 //@}
139
140 //@{
141 /// @brief Return a pointer to the attribute array stored at position @a pos
142 /// in this set.
143 const AttributeArray* getConst(size_t pos) const;
144 const AttributeArray* get(size_t pos) const;
145 AttributeArray* get(size_t pos);
146 //@}
147
148 //@{
149 /// @brief Return the group offset from the name or index of the group
150 /// A group attribute array is a single byte (8-bit), each bit of which
151 /// can denote a group. The group offset is the position of the bit that
152 /// denotes the requested group if all group attribute arrays in the set
153 /// (and only attribute arrays marked as group) were to be laid out linearly
154 /// according to their order in the set.
155 size_t groupOffset(const Name& groupName) const;
156 size_t groupOffset(const Util::GroupIndex& index) const;
157 //@}
158
159 /// Return the group index from the name of the group
160 Util::GroupIndex groupIndex(const Name& groupName) const;
161 /// Return the group index from the offset of the group
162 /// @note see offset description for groupOffset()
163 Util::GroupIndex groupIndex(const size_t offset) const;
164
165 /// Return the indices of the attribute arrays which are group attribute arrays
166 std::vector<size_t> groupAttributeIndices() const;
167
168 /// Return true if the attribute array stored at position @a pos is shared.
169 bool isShared(size_t pos) const;
170 /// @brief If the attribute array stored at position @a pos is shared,
171 /// replace the array with a deep copy of itself that is not
172 /// shared with anyone else.
173 void makeUnique(size_t pos);
174
175 /// Append attribute @a attribute (simple method)
177 const NamePair& type,
178 const Index strideOrTotalSize = 1,
179 const bool constantStride = true,
180 const Metadata* defaultValue = nullptr);
181
182 /// Append attribute @a attribute (descriptor-sharing)
183 /// Requires current descriptor to match @a expected
184 /// On append, current descriptor is replaced with @a replacement
185 /// Provide a @a lock object to avoid contention from appending in parallel
186 AttributeArray::Ptr appendAttribute(const Descriptor& expected, DescriptorPtr& replacement,
187 const size_t pos, const Index strideOrTotalSize = 1,
188 const bool constantStride = true,
189 const Metadata* defaultValue = nullptr,
190 const AttributeArray::ScopedRegistryLock* lock = nullptr);
191
192 /// @brief Remove and return an attribute array by name
193 /// @param name the name of the attribute array to release
194 /// @details Detaches the attribute array from this attribute set and returns it, if
195 /// @a name is invalid, returns an empty shared pointer. This also updates the descriptor
196 /// to remove the reference to the attribute array.
197 /// @note AttributeArrays are stored as shared pointers, so they are not guaranteed
198 /// to be unique. Check the reference count before blindly re-using in a new AttributeSet.
200
201 /// @brief Remove and return an attribute array by index
202 /// @param pos the position index of the attribute to release
203 /// @details Detaches the attribute array from this attribute set and returns it, if
204 /// @a pos is invalid, returns an empty shared pointer. This also updates the descriptor
205 /// to remove the reference to the attribute array.
206 /// @note AttributeArrays are stored as shared pointers, so they are not guaranteed
207 /// to be unique. Check the reference count before blindly re-using in a new AttributeSet.
209
210 /// @brief Remove and return an attribute array by index (unsafe method)
211 /// @param pos the position index of the attribute to release
212 /// @details Detaches the attribute array from this attribute set and returns it, if
213 /// @a pos is invalid, returns an empty shared pointer.
214 /// In cases where the AttributeSet is due to be destroyed, a small performance
215 /// advantage can be gained by leaving the attribute array as a nullptr and not
216 /// updating the descriptor. However, this leaves the AttributeSet in an invalid
217 /// state making it unsafe to call any methods that implicitly derefence the attribute array.
218 /// @note AttributeArrays are stored as shared pointers, so they are not guaranteed
219 /// to be unique. Check the reference count before blindly re-using in a new AttributeSet.
220 /// @warning Only use this method if you're an expert and know the risks of not
221 /// updating the array of attributes or the descriptor.
223
224 /// Drop attributes with @a pos indices (simple method)
225 /// Creates a new descriptor for this attribute set
226 void dropAttributes(const std::vector<size_t>& pos);
227
228 /// Drop attributes with @a pos indices (descriptor-sharing method)
229 /// Requires current descriptor to match @a expected
230 /// On drop, current descriptor is replaced with @a replacement
231 void dropAttributes(const std::vector<size_t>& pos,
232 const Descriptor& expected, DescriptorPtr& replacement);
233
234 /// Re-name attributes in set to match a provided descriptor
235 /// Replaces own descriptor with @a replacement
236 void renameAttributes(const Descriptor& expected, const DescriptorPtr& replacement);
237
238 /// Re order attribute set to match a provided descriptor
239 /// Replaces own descriptor with @a replacement
240 void reorderAttributes(const DescriptorPtr& replacement);
241
242 /// Replace the current descriptor with a @a replacement
243 /// Note the provided Descriptor must be identical to the replacement
244 /// unless @a allowMismatchingDescriptors is true (default is false)
245 void resetDescriptor(const DescriptorPtr& replacement, const bool allowMismatchingDescriptors = false);
246
247 /// Read the entire set from a stream.
248 void read(std::istream&);
249 /// Write the entire set to a stream.
250 /// @param outputTransient if true, write out transient attributes
251 void write(std::ostream&, bool outputTransient = false) const;
252
253 /// This will read the attribute descriptor from a stream.
254 void readDescriptor(std::istream&);
255 /// This will write the attribute descriptor to a stream.
256 /// @param outputTransient if true, write out transient attributes
257 void writeDescriptor(std::ostream&, bool outputTransient = false) const;
258
259 /// This will read the attribute metadata from a stream.
260 void readMetadata(std::istream&);
261 /// This will write the attribute metadata to a stream.
262 /// @param outputTransient if true, write out transient attributes
263 /// @param paged if true, data is written out in pages
264 void writeMetadata(std::ostream&, bool outputTransient = false, bool paged = false) const;
265
266 /// This will read the attribute data from a stream.
267 void readAttributes(std::istream&);
268 /// This will write the attribute data to a stream.
269 /// @param outputTransient if true, write out transient attributes
270 void writeAttributes(std::ostream&, bool outputTransient = false) const;
271
272 /// Compare the descriptors and attribute arrays on the attribute sets
273 /// Exit early if the descriptors do not match
274 bool operator==(const AttributeSet& other) const;
275 bool operator!=(const AttributeSet& other) const { return !this->operator==(other); }
276
277private:
278 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
279
280 DescriptorPtr mDescr;
281 AttrArrayVec mAttrs;
282}; // class AttributeSet
283
284////////////////////////////////////////
285
286
287/// A container for ABI=5 to help ease introduction of upcoming features
288namespace future {
290 {
291 class Element { };
292 std::vector<std::shared_ptr<Element>> mElements;
293 };
294}
295
296
297////////////////////////////////////////
298
299
300/// @brief An immutable object that stores name, type and AttributeSet position
301/// for a constant collection of attribute arrays.
302/// @note The attribute name is actually mutable, but the attribute type
303/// and position can not be changed after creation.
304class OPENVDB_API AttributeSet::Descriptor
305{
306public:
307 using Ptr = std::shared_ptr<Descriptor>;
308
313 using ConstIterator = NameToPosMap::const_iterator;
314
315 /// Utility method to construct a NameAndType sequence.
316 struct Inserter {
318 Inserter& add(const NameAndType& nameAndType) {
319 vec.push_back(nameAndType); return *this;
320 }
321 Inserter& add(const Name& name, const NamePair& type) {
322 vec.emplace_back(name, type); return *this;
323 }
324 Inserter& add(const NameAndTypeVec& other) {
325 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
326 vec.emplace_back(it->name, it->type);
327 }
328 return *this;
329 }
330 };
331
332 //////////
333
335
336 /// Copy constructor
337 Descriptor(const Descriptor&);
338
339 /// Create a new descriptor from a position attribute type and assumes "P" (for convenience).
340 static Ptr create(const NamePair&);
341
342 /// Create a new descriptor as a duplicate with a new attribute appended
343 Ptr duplicateAppend(const Name& name, const NamePair& type) const;
344
345 /// Create a new descriptor as a duplicate with existing attributes dropped
346 Ptr duplicateDrop(const std::vector<size_t>& pos) const;
347
348 /// Return the number of attributes in this descriptor.
349 size_t size() const { return mTypes.size(); }
350
351 /// Return the number of attributes with this attribute type
352 size_t count(const NamePair& type) const;
353
354 /// Return the number of bytes of memory used by this attribute set.
355 size_t memUsage() const;
356
357 /// @brief Return the position of the attribute array whose name is @a name,
358 /// or @c INVALID_POS if no match is found.
359 size_t find(const std::string& name) const;
360
361 /// Rename an attribute array
362 size_t rename(const std::string& fromName, const std::string& toName);
363
364 /// Return the name of the attribute array's type.
365 const Name& valueType(size_t pos) const;
366 /// Return the name of the attribute array's type.
367 const NamePair& type(size_t pos) const;
368
369 /// Retrieve metadata map
371 const MetaMap& getMetadata() const;
372
373 /// Return true if the attribute has a default value
374 bool hasDefaultValue(const Name& name) const;
375 /// Get a default value for an existing attribute
376 template<typename ValueType>
377 ValueType getDefaultValue(const Name& name) const
378 {
379 const size_t pos = find(name);
380 if (pos == INVALID_POS) {
381 OPENVDB_THROW(LookupError, "Cannot find attribute name to set default value.")
382 }
383
384 std::stringstream ss;
385 ss << "default:" << name;
386
387 auto metadata = mMetadata.getMetadata<TypedMetadata<ValueType>>(ss.str());
388
389 if (metadata) return metadata->value();
390
391 return zeroVal<ValueType>();
392 }
393 /// Set a default value for an existing attribute
394 void setDefaultValue(const Name& name, const Metadata& defaultValue);
395 // Remove the default value if it exists
396 void removeDefaultValue(const Name& name);
397 // Prune any default values for which the key is no longer present
399
400 /// Return true if this descriptor is equal to the given one.
401 bool operator==(const Descriptor&) const;
402 /// Return true if this descriptor is not equal to the given one.
403 bool operator!=(const Descriptor& rhs) const { return !this->operator==(rhs); }
404 /// Return true if this descriptor contains the same attributes
405 /// as the given descriptor, ignoring attribute order
406 bool hasSameAttributes(const Descriptor& rhs) const;
407
408 /// Return a reference to the name-to-position map.
409 const NameToPosMap& map() const { return mNameMap; }
410 /// Return a reference to the name-to-position group map.
411 const NameToPosMap& groupMap() const { return mGroupMap; }
412
413 /// Return @c true if group exists
414 bool hasGroup(const Name& group) const;
415 /// @brief Define a group name to offset mapping
416 /// @param group group name
417 /// @param offset group offset
418 /// @param checkValidOffset throws if offset out-of-range or in-use
419 void setGroup(const Name& group, const size_t offset,
420 const bool checkValidOffset = false);
421 /// Drop any mapping keyed by group name
422 void dropGroup(const Name& group);
423 /// Clear all groups
425 /// Rename a group
426 size_t renameGroup(const std::string& fromName, const std::string& toName);
427 /// Return a unique name for a group based on given name
428 const Name uniqueGroupName(const Name& name) const;
429
430 //@{
431 /// @brief Return the group offset from the name or index of the group
432 /// A group attribute array is a single byte (8-bit), each bit of which
433 /// can denote a group. The group offset is the position of the bit that
434 /// denotes the requested group if all group attribute arrays in the set
435 /// (and only attribute arrays marked as group) were to be laid out linearly
436 /// according to their order in the set.
437 size_t groupOffset(const Name& groupName) const;
438 size_t groupOffset(const GroupIndex& index) const;
439 //@}
440
441 /// Return the group index from the name of the group
442 GroupIndex groupIndex(const Name& groupName) const;
443 /// Return the group index from the offset of the group
444 /// @note see offset description for groupOffset()
445 GroupIndex groupIndex(const size_t offset) const;
446
447 /// Return number of bits occupied by a group attribute array
448 static size_t groupBits() { return sizeof(GroupType) * CHAR_BIT; }
449
450 /// Return the total number of available groups
451 /// (group bits * number of group attributes)
452 size_t availableGroups() const;
453
454 /// Return the number of empty group slots which correlates to the number of groups
455 /// that can be stored without increasing the number of group attribute arrays
456 size_t unusedGroups() const;
457
458 /// Return @c true if there are sufficient empty slots to allow compacting
459 bool canCompactGroups() const;
460
461 /// @brief Return a group offset that is not in use
462 /// @param hint if provided, request a specific offset as a hint
463 /// @return index of an offset or size_t max if no available group offsets
465
466 /// @brief Determine if a move is required to efficiently compact the data and store the
467 /// source name, offset and the target offset in the input parameters
468 /// @param sourceName source name
469 /// @param sourceOffset source offset
470 /// @param targetOffset target offset
471 /// @return @c true if move is required to compact the data
472 bool requiresGroupMove(Name& sourceName, size_t& sourceOffset, size_t& targetOffset) const;
473
474 /// @brief Test if there are any group names shared by both descriptors which
475 /// have a different index
476 /// @param rhs the descriptor to compare with
477 /// @return @c true if an index collision exists
478 bool groupIndexCollision(const Descriptor& rhs) const;
479
480 /// Return a unique name for an attribute array based on given name
481 const Name uniqueName(const Name& name) const;
482
483 /// Return true if the name is valid
484 static bool validName(const Name& name);
485
486 /// @brief Extract each name from @a nameStr into @a includeNames, or into @a excludeNames
487 /// if the name is prefixed with a caret.
488 /// @param nameStr the input string of names
489 /// @param includeNames on exit, the list of names that are not prefixed with a caret
490 /// @param excludeNames on exit, the list of names that are prefixed with a caret
491 /// @param includeAll on exit, @c true if a "*" wildcard is present in the @a includeNames
492 static void parseNames( std::vector<std::string>& includeNames,
493 std::vector<std::string>& excludeNames,
494 bool& includeAll,
495 const std::string& nameStr);
496
497 /// @brief Extract each name from @a nameStr into @a includeNames, or into @a excludeNames
498 /// if the name is prefixed with a caret.
499 static void parseNames( std::vector<std::string>& includeNames,
500 std::vector<std::string>& excludeNames,
501 const std::string& nameStr);
502
503 /// Serialize this descriptor to the given stream.
504 void write(std::ostream&) const;
505 /// Unserialize this transform from the given stream.
506 void read(std::istream&);
507
508protected:
509 /// Append to a vector of names and types from this Descriptor in position order
510 void appendTo(NameAndTypeVec& attrs) const;
511
512 /// Create a new descriptor from the given attribute and type name pairs
513 /// and copy the group maps and metamap.
514 static Ptr create(const NameAndTypeVec&, const NameToPosMap&, const MetaMap&);
515
516 size_t insert(const std::string& name, const NamePair& typeName);
517
518private:
519 friend class ::TestAttributeSet;
520
521 NameToPosMap mNameMap;
522 std::vector<NamePair> mTypes;
523 NameToPosMap mGroupMap;
524 MetaMap mMetadata;
525 // as this change is part of an ABI change, there's no good reason to reduce the reserved
526 // space aside from keeping the memory size of an AttributeSet the same for convenience
527 // (note that this assumes a typical three-pointer implementation for std::vector)
528 future::Container mFutureContainer; // occupies 3 reserved slots
529 int64_t mReserved[5]; // for future use
530}; // class Descriptor
531
532} // namespace points
533} // namespace OPENVDB_VERSION_NAME
534} // namespace openvdb
535
536#endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
Attribute Array storage templated on type and compression codec.
#define OPENVDB_API
Definition: Platform.h:254
Definition: Exceptions.h:60
Container that maps names (strings) to values of arbitrary types.
Definition: MetaMap.h:20
Base class for storing metadata information in a grid.
Definition: Metadata.h:24
Templated metadata class to hold specific types.
Definition: Metadata.h:122
T & value()
Return this metadata's value.
Definition: Metadata.h:249
Base class for storing attribute data.
Definition: AttributeArray.h:93
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
size_t replace(const std::string &name, const AttributeArray::Ptr &)
Replace the attribute array whose name is name.
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:313
bool requiresGroupMove(Name &sourceName, size_t &sourceOffset, size_t &targetOffset) const
Determine if a move is required to efficiently compact the data and store the source name,...
const AttributeArray * get(const std::string &name) const
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:108
size_t groupOffset(const Name &groupName) const
Return the group offset from the name or index of the group A group attribute array is a single byte ...
GroupIndex groupIndex(const size_t offset) const
void writeDescriptor(std::ostream &, bool outputTransient=false) const
void dropAttributes(const std::vector< size_t > &pos, const Descriptor &expected, DescriptorPtr &replacement)
bool operator==(const Descriptor &) const
Return true if this descriptor is equal to the given one.
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:311
const MetaMap & getMetadata() const
void clearGroups()
Clear all groups.
size_t memUsage() const
Return the number of bytes of memory used by this attribute set.
size_t renameGroup(const std::string &fromName, const std::string &toName)
Rename a group.
void readDescriptor(std::istream &)
This will read the attribute descriptor from a stream.
static bool validName(const Name &name)
Return true if the name is valid.
size_t groupOffset(const GroupIndex &index) const
void readAttributes(std::istream &)
This will read the attribute data from a stream.
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:111
bool operator==(const AttributeSet &other) const
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:310
size_t rename(const std::string &fromName, const std::string &toName)
Rename an attribute array.
const AttributeArray * getConst(const std::string &name) const
Return a pointer to the attribute array whose name is name or a null pointer if no match is found.
size_t find(const std::string &name) const
Return the position of the attribute array whose name is name, or INVALID_POS if no match is found.
const AttributeArray * getConst(size_t pos) const
Return a pointer to the attribute array stored at position pos in this set.
bool groupIndexCollision(const Descriptor &rhs) const
Test if there are any group names shared by both descriptors which have a different index.
Ptr duplicateDrop(const std::vector< size_t > &pos) const
Create a new descriptor as a duplicate with existing attributes dropped.
size_t unusedGroupOffset(size_t hint=std::numeric_limits< size_t >::max()) const
Return a group offset that is not in use.
AttributeSet(const AttributeSet &attributeSet, Index arrayLength, const AttributeArray::ScopedRegistryLock *lock=nullptr)
const Name & valueType(size_t pos) const
Return the name of the attribute array's type.
AttributeArray::Ptr appendAttribute(const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *defaultValue=nullptr)
Append attribute attribute (simple method)
const Descriptor & descriptor() const
Definition: AttributeSet.h:103
const AttributeArray * get(size_t pos) const
size_t replace(size_t pos, const AttributeArray::Ptr &)
Replace the attribute array stored at position pos in this container.
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:403
AttributeArray::Ptr removeAttribute(const size_t pos)
Remove and return an attribute array by index.
AttributeArray::Ptr removeAttributeUnsafe(const size_t pos)
Remove and return an attribute array by index (unsafe method)
AttributeArray::Ptr removeAttribute(const Name &name)
Remove and return an attribute array by name.
void write(std::ostream &) const
Serialize this descriptor to the given stream.
void renameAttributes(const Descriptor &expected, const DescriptorPtr &replacement)
void resetDescriptor(const DescriptorPtr &replacement, const bool allowMismatchingDescriptors=false)
const NamePair & type(size_t pos) const
Return the name of the attribute array's type.
AttributeSet & operator=(const AttributeSet &)=delete
Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.
void writeAttributes(std::ostream &, bool outputTransient=false) const
AttributeSet(const AttributeSet &)
Shallow copy constructor, the descriptor and attribute arrays will be shared.
Ptr duplicateAppend(const Name &name, const NamePair &type) const
Create a new descriptor as a duplicate with a new attribute appended.
static Ptr create(const NameAndTypeVec &, const NameToPosMap &, const MetaMap &)
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:275
void setDefaultValue(const Name &name, const Metadata &defaultValue)
Set a default value for an existing attribute.
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:50
bool canCompactGroups() const
Return true if there are sufficient empty slots to allow compacting.
void appendTo(NameAndTypeVec &attrs) const
Append to a vector of names and types from this Descriptor in position order.
void read(std::istream &)
Read the entire set from a stream.
void removeDefaultValue(const Name &name)
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:102
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:43
void setGroup(const Name &group, const size_t offset, const bool checkValidOffset=false)
Define a group name to offset mapping.
Descriptor(const Descriptor &)
Copy constructor.
void reorderAttributes(const DescriptorPtr &replacement)
AttributeSet(const DescriptorPtr &descriptor, Index arrayLength=1, const AttributeArray::ScopedRegistryLock *lock=nullptr)
void writeMetadata(std::ostream &, bool outputTransient=false, bool paged=false) const
void makeUnique(size_t pos)
If the attribute array stored at position pos is shared, replace the array with a deep copy of itself...
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:409
size_t groupOffset(const Util::GroupIndex &index) const
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:411
static void parseNames(std::vector< std::string > &includeNames, std::vector< std::string > &excludeNames, const std::string &nameStr)
Extract each name from nameStr into includeNames, or into excludeNames if the name is prefixed with a...
void dropAttributes(const std::vector< size_t > &pos)
Util::GroupIndex groupIndex(const size_t offset) const
AttributeArray::Ptr appendAttribute(const Descriptor &expected, DescriptorPtr &replacement, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *defaultValue=nullptr, const AttributeArray::ScopedRegistryLock *lock=nullptr)
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:44
static void parseNames(std::vector< std::string > &includeNames, std::vector< std::string > &excludeNames, bool &includeAll, const std::string &nameStr)
Extract each name from nameStr into includeNames, or into excludeNames if the name is prefixed with a...
bool hasDefaultValue(const Name &name) const
Return true if the attribute has a default value.
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:377
GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
size_t insert(const std::string &name, const NamePair &typeName)
size_t count(const NamePair &type) const
Return the number of attributes with this attribute type.
std::unique_ptr< AttributeSet > UniquePtr
Definition: AttributeSet.h:45
static size_t groupBits()
Return number of bits occupied by a group attribute array.
Definition: AttributeSet.h:448
MetaMap & getMetadata()
Retrieve metadata map.
AttributeArray * get(const std::string &name)
const Name uniqueName(const Name &name) const
Return a unique name for an attribute array based on given name.
void write(std::ostream &, bool outputTransient=false) const
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:312
static Ptr create(const NamePair &)
Create a new descriptor from a position attribute type and assumes "P" (for convenience).
std::vector< size_t > groupAttributeIndices() const
Return the indices of the attribute arrays which are group attribute arrays.
void dropGroup(const Name &group)
Drop any mapping keyed by group name.
AttributeArray * get(size_t pos)
bool hasSameAttributes(const Descriptor &rhs) const
void readMetadata(std::istream &)
This will read the attribute metadata from a stream.
bool hasGroup(const Name &group) const
Return true if group exists.
const Name uniqueGroupName(const Name &name) const
Return a unique name for a group based on given name.
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:49
bool isShared(size_t pos) const
Return true if the attribute array stored at position pos is shared.
Definition: AttributeSet.h:290
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
uint8_t GroupType
Definition: AttributeSet.h:31
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:107
std::string Name
Definition: Name.h:17
Index32 Index
Definition: Types.h:54
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
Definition: Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:316
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:321
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:324
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:318
NameAndTypeVec vec
Definition: AttributeSet.h:317
Attribute and type name pair.
Definition: AttributeSet.h:57
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:58
NamePair type
Definition: AttributeSet.h:61
Definition: AttributeSet.h:55
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:67
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:66
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:65
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202