OpenVDB: openvdb/points/AttributeSet.h Source File

OpenVDB 12.1.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 {
27 OPENVDB_USE_VERSION_NAMESPACE
28namespace OPENVDB_VERSION_NAME {
29namespace points {
30
31
32 using GroupType = uint8_t;
33
34
35////////////////////////////////////////
36
37
38/// Ordered collection of uniquely-named attribute arrays
39 class OPENVDB_API AttributeSet
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) {}
61 Name name;
62 NamePair type;
63 Index stride;
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
73 AttributeSet();
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.
95 AttributeSet(const AttributeSet&);
96
97 /// Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.
98 AttributeSet& operator=(const AttributeSet&) = delete;
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)
182 AttributeArray::Ptr appendAttribute(const Name& name,
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
192 AttributeArray::Ptr appendAttribute(const Descriptor& expected, DescriptorPtr& replacement,
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.
205 AttributeArray::Ptr removeAttribute(const Name& name);
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.
214 AttributeArray::Ptr removeAttribute(const size_t pos);
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.
228 AttributeArray::Ptr removeAttributeUnsafe(const size_t pos);
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
294 namespace future {
295 class Container
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.
310 class OPENVDB_API AttributeSet::Descriptor
311{
312public:
313 using Ptr = std::shared_ptr<Descriptor>;
314
315 using NameAndType = Util::NameAndType;
316 using NameAndTypeVec = Util::NameAndTypeVec;
317 using GroupIndex = Util::GroupIndex;
318 using NameToPosMap = Util::NameToPosMap;
319 using ConstIterator = NameToPosMap::const_iterator;
320
321 /// Utility method to construct a NameAndType sequence.
322 struct Inserter {
323 NameAndTypeVec vec;
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
340 Descriptor();
341
342 /// Copy constructor
343 Descriptor(const Descriptor&);
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
376 MetaMap& getMetadata();
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
404 void pruneUnusedDefaultValues();
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
430 void clearGroups();
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
AttributeArray.h
Attribute Array storage templated on type and compression codec.
MetaMap.h
OPENVDB_API
#define OPENVDB_API
Definition Platform.h:291
openvdb::v12_1::LookupError
Definition Exceptions.h:60
openvdb::v12_1::MetaMap
Container that maps names (strings) to values of arbitrary types.
Definition MetaMap.h:20
openvdb::v12_1::Metadata
Base class for storing metadata information in a grid.
Definition Metadata.h:25
openvdb::v12_1::TypedMetadata
Templated metadata class to hold specific types.
Definition Metadata.h:123
openvdb::v12_1::points::AttributeArray::ScopedRegistryLock
Definition AttributeArray.h:120
openvdb::v12_1::points::AttributeArray
Base class for storing attribute data.
Definition AttributeArray.h:94
openvdb::v12_1::points::AttributeArray::Ptr
std::shared_ptr< AttributeArray > Ptr
Definition AttributeArray.h:126
openvdb::v12_1::points::AttributeSet::Descriptor
An immutable object that stores name, type and AttributeSet position for a constant collection of att...
Definition AttributeSet.h:311
openvdb::v12_1::points::AttributeSet::Descriptor::ConstIterator
NameToPosMap::const_iterator ConstIterator
Definition AttributeSet.h:319
openvdb::v12_1::points::AttributeSet::Descriptor::requiresGroupMove
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,...
openvdb::v12_1::points::AttributeSet::Descriptor::groupOffset
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 ...
openvdb::v12_1::points::AttributeSet::Descriptor::groupIndex
GroupIndex groupIndex(const size_t offset) const
openvdb::v12_1::points::AttributeSet::Descriptor::unusedGroups
size_t unusedGroups() const
openvdb::v12_1::points::AttributeSet::Descriptor::operator==
bool operator==(const Descriptor &) const
Return true if this descriptor is equal to the given one.
openvdb::v12_1::points::AttributeSet::Descriptor::GroupIndex
Util::GroupIndex GroupIndex
Definition AttributeSet.h:317
openvdb::v12_1::points::AttributeSet::Descriptor::getMetadata
const MetaMap & getMetadata() const
openvdb::v12_1::points::AttributeSet::Descriptor::clearGroups
void clearGroups()
Clear all groups.
openvdb::v12_1::points::AttributeSet::Descriptor::memUsage
size_t memUsage() const
Return the number of bytes of memory used by this attribute set.
openvdb::v12_1::points::AttributeSet::Descriptor::renameGroup
size_t renameGroup(const std::string &fromName, const std::string &toName)
Rename a group.
openvdb::v12_1::points::AttributeSet::Descriptor::validName
static bool validName(const Name &name)
Return true if the name is valid.
openvdb::v12_1::points::AttributeSet::Descriptor::groupOffset
size_t groupOffset(const GroupIndex &index) const
openvdb::v12_1::points::AttributeSet::Descriptor::size
size_t size() const
Return the number of attributes in this descriptor.
Definition AttributeSet.h:355
openvdb::v12_1::points::AttributeSet::Descriptor::NameAndTypeVec
Util::NameAndTypeVec NameAndTypeVec
Definition AttributeSet.h:316
openvdb::v12_1::points::AttributeSet::Descriptor::rename
size_t rename(const std::string &fromName, const std::string &toName)
Rename an attribute array.
openvdb::v12_1::points::AttributeSet::Descriptor::find
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.
openvdb::v12_1::points::AttributeSet::Descriptor::groupIndexCollision
bool groupIndexCollision(const Descriptor &rhs) const
Test if there are any group names shared by both descriptors which have a different index.
openvdb::v12_1::points::AttributeSet::Descriptor::duplicateDrop
Ptr duplicateDrop(const std::vector< size_t > &pos) const
Create a new descriptor as a duplicate with existing attributes dropped.
openvdb::v12_1::points::AttributeSet::Descriptor::unusedGroupOffset
size_t unusedGroupOffset(size_t hint=std::numeric_limits< size_t >::max()) const
Return a group offset that is not in use.
openvdb::v12_1::points::AttributeSet::Descriptor::valueType
const Name & valueType(size_t pos) const
Return the name of the attribute array's type.
openvdb::v12_1::points::AttributeSet::Descriptor::operator!=
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition AttributeSet.h:409
openvdb::v12_1::points::AttributeSet::Descriptor::write
void write(std::ostream &) const
Serialize this descriptor to the given stream.
openvdb::v12_1::points::AttributeSet::Descriptor::type
const NamePair & type(size_t pos) const
Return the name of the attribute array's type.
openvdb::v12_1::points::AttributeSet::Descriptor::duplicateAppend
Ptr duplicateAppend(const Name &name, const NamePair &type) const
Create a new descriptor as a duplicate with a new attribute appended.
openvdb::v12_1::points::AttributeSet::Descriptor::create
static Ptr create(const NameAndTypeVec &, const NameToPosMap &, const MetaMap &)
openvdb::v12_1::points::AttributeSet::Descriptor::setDefaultValue
void setDefaultValue(const Name &name, const Metadata &defaultValue)
Set a default value for an existing attribute.
openvdb::v12_1::points::AttributeSet::Descriptor::canCompactGroups
bool canCompactGroups() const
Return true if there are sufficient empty slots to allow compacting.
openvdb::v12_1::points::AttributeSet::Descriptor::appendTo
void appendTo(NameAndTypeVec &attrs) const
Append to a vector of names and types from this Descriptor in position order.
openvdb::v12_1::points::AttributeSet::Descriptor::read
void read(std::istream &)
Unserialize this transform from the given stream.
openvdb::v12_1::points::AttributeSet::Descriptor::removeDefaultValue
void removeDefaultValue(const Name &name)
openvdb::v12_1::points::AttributeSet::Descriptor::Ptr
std::shared_ptr< Descriptor > Ptr
Definition AttributeSet.h:313
openvdb::v12_1::points::AttributeSet::Descriptor::setGroup
void setGroup(const Name &group, const size_t offset, const bool checkValidOffset=false)
Define a group name to offset mapping.
openvdb::v12_1::points::AttributeSet::Descriptor::Descriptor
Descriptor(const Descriptor &)
Copy constructor.
openvdb::v12_1::points::AttributeSet::Descriptor::pruneUnusedDefaultValues
void pruneUnusedDefaultValues()
openvdb::v12_1::points::AttributeSet::Descriptor::map
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition AttributeSet.h:415
openvdb::v12_1::points::AttributeSet::Descriptor::groupMap
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition AttributeSet.h:417
openvdb::v12_1::points::AttributeSet::Descriptor::parseNames
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...
openvdb::v12_1::points::AttributeSet::Descriptor::Descriptor
Descriptor()
openvdb::v12_1::points::AttributeSet::Descriptor::parseNames
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...
openvdb::v12_1::points::AttributeSet::Descriptor::hasDefaultValue
bool hasDefaultValue(const Name &name) const
Return true if the attribute has a default value.
openvdb::v12_1::points::AttributeSet::Descriptor::getDefaultValue
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition AttributeSet.h:383
openvdb::v12_1::points::AttributeSet::Descriptor::groupIndex
GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
openvdb::v12_1::points::AttributeSet::Descriptor::insert
size_t insert(const std::string &name, const NamePair &typeName)
openvdb::v12_1::points::AttributeSet::Descriptor::count
size_t count(const NamePair &type) const
Return the number of attributes with this attribute type.
openvdb::v12_1::points::AttributeSet::Descriptor::groupBits
static size_t groupBits()
Return number of bits occupied by a group attribute array.
Definition AttributeSet.h:454
openvdb::v12_1::points::AttributeSet::Descriptor::getMetadata
MetaMap & getMetadata()
Retrieve metadata map.
openvdb::v12_1::points::AttributeSet::Descriptor::uniqueName
const Name uniqueName(const Name &name) const
Return a unique name for an attribute array based on given name.
openvdb::v12_1::points::AttributeSet::Descriptor::availableGroups
size_t availableGroups() const
openvdb::v12_1::points::AttributeSet::Descriptor::NameToPosMap
Util::NameToPosMap NameToPosMap
Definition AttributeSet.h:318
openvdb::v12_1::points::AttributeSet::Descriptor::create
static Ptr create(const NamePair &)
Create a new descriptor from a position attribute type and assumes "P" (for convenience).
openvdb::v12_1::points::AttributeSet::Descriptor::dropGroup
void dropGroup(const Name &group)
Drop any mapping keyed by group name.
openvdb::v12_1::points::AttributeSet::Descriptor::hasSameAttributes
bool hasSameAttributes(const Descriptor &rhs) const
openvdb::v12_1::points::AttributeSet::Descriptor::NameAndType
Util::NameAndType NameAndType
Definition AttributeSet.h:315
openvdb::v12_1::points::AttributeSet::Descriptor::hasGroup
bool hasGroup(const Name &group) const
Return true if group exists.
openvdb::v12_1::points::AttributeSet::Descriptor::uniqueGroupName
const Name uniqueGroupName(const Name &name) const
Return a unique name for a group based on given name.
openvdb::v12_1::points::AttributeSet::replace
size_t replace(const std::string &name, const AttributeArray::Ptr &)
Replace the attribute array whose name is name.
openvdb::v12_1::points::AttributeSet::get
const AttributeArray * get(const std::string &name) const
openvdb::v12_1::points::AttributeSet::descriptorPtr
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition AttributeSet.h:109
openvdb::v12_1::points::AttributeSet::groupOffset
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 ...
openvdb::v12_1::points::AttributeSet::writeDescriptor
void writeDescriptor(std::ostream &, bool outputTransient=false) const
openvdb::v12_1::points::AttributeSet::dropAttributes
void dropAttributes(const std::vector< size_t > &pos, const Descriptor &expected, DescriptorPtr &replacement)
openvdb::v12_1::points::AttributeSet::memUsageIfLoaded
size_t memUsageIfLoaded() const
openvdb::v12_1::points::AttributeSet::groupIndex
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
openvdb::v12_1::points::AttributeSet::memUsage
size_t memUsage() const
Return the number of bytes of memory used by this attribute set.
openvdb::v12_1::points::AttributeSet::readDescriptor
void readDescriptor(std::istream &)
This will read the attribute descriptor from a stream.
openvdb::v12_1::points::AttributeSet::readAttributes
void readAttributes(std::istream &)
This will read the attribute data from a stream.
openvdb::v12_1::points::AttributeSet::size
size_t size() const
Return the number of attributes in this set.
Definition AttributeSet.h:112
openvdb::v12_1::points::AttributeSet::operator==
bool operator==(const AttributeSet &other) const
openvdb::v12_1::points::AttributeSet::getConst
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.
openvdb::v12_1::points::AttributeSet::find
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.
openvdb::v12_1::points::AttributeSet::getConst
const AttributeArray * getConst(size_t pos) const
Return a pointer to the attribute array stored at position pos in this set.
openvdb::v12_1::points::AttributeSet::AttributeSet
AttributeSet(const AttributeSet &attributeSet, Index arrayLength, const AttributeArray::ScopedRegistryLock *lock=nullptr)
openvdb::v12_1::points::AttributeSet::appendAttribute
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)
openvdb::v12_1::points::AttributeSet::descriptor
const Descriptor & descriptor() const
Definition AttributeSet.h:104
openvdb::v12_1::points::AttributeSet::get
const AttributeArray * get(size_t pos) const
openvdb::v12_1::points::AttributeSet::replace
size_t replace(size_t pos, const AttributeArray::Ptr &)
Replace the attribute array stored at position pos in this container.
openvdb::v12_1::points::AttributeSet::removeAttribute
AttributeArray::Ptr removeAttribute(const size_t pos)
Remove and return an attribute array by index.
openvdb::v12_1::points::AttributeSet::removeAttributeUnsafe
AttributeArray::Ptr removeAttributeUnsafe(const size_t pos)
Remove and return an attribute array by index (unsafe method)
openvdb::v12_1::points::AttributeSet::removeAttribute
AttributeArray::Ptr removeAttribute(const Name &name)
Remove and return an attribute array by name.
openvdb::v12_1::points::AttributeSet::renameAttributes
void renameAttributes(const Descriptor &expected, const DescriptorPtr &replacement)
openvdb::v12_1::points::AttributeSet::resetDescriptor
void resetDescriptor(const DescriptorPtr &replacement, const bool allowMismatchingDescriptors=false)
openvdb::v12_1::points::AttributeSet::operator=
AttributeSet & operator=(const AttributeSet &)=delete
Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.
openvdb::v12_1::points::AttributeSet::writeAttributes
void writeAttributes(std::ostream &, bool outputTransient=false) const
openvdb::v12_1::points::AttributeSet::AttributeSet
AttributeSet(const AttributeSet &)
Shallow copy constructor, the descriptor and attribute arrays will be shared.
openvdb::v12_1::points::AttributeSet::operator!=
bool operator!=(const AttributeSet &other) const
Definition AttributeSet.h:281
openvdb::v12_1::points::AttributeSet::DescriptorConstPtr
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition AttributeSet.h:51
openvdb::v12_1::points::AttributeSet::read
void read(std::istream &)
Read the entire set from a stream.
openvdb::v12_1::points::AttributeSet::descriptor
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition AttributeSet.h:103
openvdb::v12_1::points::AttributeSet::Ptr
std::shared_ptr< AttributeSet > Ptr
Definition AttributeSet.h:44
openvdb::v12_1::points::AttributeSet::reorderAttributes
void reorderAttributes(const DescriptorPtr &replacement)
openvdb::v12_1::points::AttributeSet::AttributeSet
AttributeSet(const DescriptorPtr &descriptor, Index arrayLength=1, const AttributeArray::ScopedRegistryLock *lock=nullptr)
openvdb::v12_1::points::AttributeSet::writeMetadata
void writeMetadata(std::ostream &, bool outputTransient=false, bool paged=false) const
openvdb::v12_1::points::AttributeSet::makeUnique
void makeUnique(size_t pos)
If the attribute array stored at position pos is shared, replace the array with a deep copy of itself...
openvdb::v12_1::points::AttributeSet::AttributePositionLabel
AttributePositionLabel
Definition AttributeSet.h:42
openvdb::v12_1::points::AttributeSet::INVALID_POS
@ INVALID_POS
Definition AttributeSet.h:42
openvdb::v12_1::points::AttributeSet::AttributeSet
AttributeSet()
openvdb::v12_1::points::AttributeSet::groupOffset
size_t groupOffset(const Util::GroupIndex &index) const
openvdb::v12_1::points::AttributeSet::dropAttributes
void dropAttributes(const std::vector< size_t > &pos)
openvdb::v12_1::points::AttributeSet::groupIndex
Util::GroupIndex groupIndex(const size_t offset) const
openvdb::v12_1::points::AttributeSet::appendAttribute
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)
openvdb::v12_1::points::AttributeSet::ConstPtr
std::shared_ptr< const AttributeSet > ConstPtr
Definition AttributeSet.h:45
openvdb::v12_1::points::AttributeSet::UniquePtr
std::unique_ptr< AttributeSet > UniquePtr
Definition AttributeSet.h:46
openvdb::v12_1::points::AttributeSet::get
AttributeArray * get(const std::string &name)
openvdb::v12_1::points::AttributeSet::write
void write(std::ostream &, bool outputTransient=false) const
openvdb::v12_1::points::AttributeSet::groupAttributeIndices
std::vector< size_t > groupAttributeIndices() const
Return the indices of the attribute arrays which are group attribute arrays.
openvdb::v12_1::points::AttributeSet::get
AttributeArray * get(size_t pos)
openvdb::v12_1::points::AttributeSet::readMetadata
void readMetadata(std::istream &)
This will read the attribute metadata from a stream.
openvdb::v12_1::points::AttributeSet::DescriptorPtr
std::shared_ptr< Descriptor > DescriptorPtr
Definition AttributeSet.h:50
openvdb::v12_1::points::AttributeSet::isShared
bool isShared(size_t pos) const
Return true if the attribute array stored at position pos is shared.
openvdb::v12_1::points::future::Container
Definition AttributeSet.h:296
openvdb::v12_1::points::future
A container for ABI=5 to help ease introduction of upcoming features.
Definition AttributeSet.h:294
openvdb::v12_1::points::index
Definition IndexIterator.h:35
openvdb::v12_1::points::GroupType
uint8_t GroupType
Definition AttributeSet.h:32
openvdb::v12_1::Name
std::string Name
Definition Name.h:19
openvdb::v12_1::Index
Index32 Index
Definition Types.h:54
openvdb::v12_1::NamePair
std::pair< Name, Name > NamePair
Definition AttributeArray.h:40
openvdb::v12_1::zeroVal
constexpr T zeroVal()
Return the value of type T that corresponds to zero.
Definition Math.h:70
openvdb
Definition Exceptions.h:13
OPENVDB_THROW
#define OPENVDB_THROW(exception, message)
Definition Exceptions.h:74
openvdb::v12_1::points::AttributeSet::Descriptor::Inserter
Utility method to construct a NameAndType sequence.
Definition AttributeSet.h:322
openvdb::v12_1::points::AttributeSet::Descriptor::Inserter::add
Inserter & add(const Name &name, const NamePair &type)
Definition AttributeSet.h:327
openvdb::v12_1::points::AttributeSet::Descriptor::Inserter::add
Inserter & add(const NameAndTypeVec &other)
Definition AttributeSet.h:330
openvdb::v12_1::points::AttributeSet::Descriptor::Inserter::add
Inserter & add(const NameAndType &nameAndType)
Definition AttributeSet.h:324
openvdb::v12_1::points::AttributeSet::Descriptor::Inserter::vec
NameAndTypeVec vec
Definition AttributeSet.h:323
openvdb::v12_1::points::AttributeSet::Util::NameAndType
Attribute and type name pair.
Definition AttributeSet.h:58
openvdb::v12_1::points::AttributeSet::Util::NameAndType::NameAndType
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition AttributeSet.h:59
openvdb::v12_1::points::AttributeSet::Util::NameAndType::name
Name name
Definition AttributeSet.h:61
openvdb::v12_1::points::AttributeSet::Util::NameAndType::stride
Index stride
Definition AttributeSet.h:63
openvdb::v12_1::points::AttributeSet::Util::NameAndType::type
NamePair type
Definition AttributeSet.h:62
openvdb::v12_1::points::AttributeSet::Util
Definition AttributeSet.h:56
openvdb::v12_1::points::AttributeSet::Util::GroupIndex
std::pair< size_t, uint8_t > GroupIndex
Definition AttributeSet.h:68
openvdb::v12_1::points::AttributeSet::Util::NameToPosMap
std::map< std::string, size_t > NameToPosMap
Definition AttributeSet.h:67
openvdb::v12_1::points::AttributeSet::Util::NameAndTypeVec
std::vector< NameAndType > NameAndTypeVec
Definition AttributeSet.h:66
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218