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