Go to the documentation of this file.
10 #ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
22 class TestAttributeSet;
43 using Ptr = std::shared_ptr<AttributeSet>;
44 using ConstPtr = std::shared_ptr<const AttributeSet>;
100 Descriptor& descriptor() {
return *mDescr; }
111 size_t size()
const {
return mAttrs.size(); }
149 size_t groupOffset(
const Name& groupName)
const;
180 const Metadata* defaultValue =
nullptr);
196 const Metadata* defaultValue =
nullptr,
264 void write(std::ostream&,
bool outputTransient =
false)
const;
277 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
291 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
293 DescriptorPtr mDescr;
305 std::vector<std::shared_ptr<Element>> mElements;
320 using Ptr = std::shared_ptr<Descriptor>;
332 vec.push_back(nameAndType);
return *
this;
335 vec.emplace_back(
name,
type);
return *
this;
338 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
339 vec.emplace_back(it->name, it->type);
362 size_t size()
const {
return mTypes.size(); }
375 size_t rename(
const std::string& fromName,
const std::string& toName);
389 template<
typename ValueType>
392 const size_t pos = find(
name);
393 if (pos == INVALID_POS) {
397 std::stringstream ss;
398 ss <<
"default:" <<
name;
402 if (metadata)
return metadata->
value();
404 return zeroVal<ValueType>();
433 const bool checkValidOffset =
false);
439 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
444 size_t groupOffset(
const Name& groupName)
const;
480 size_t nextUnusedGroupOffset()
const;
508 static void parseNames( std::vector<std::string>& includeNames,
509 std::vector<std::string>& excludeNames,
511 const std::string& nameStr);
515 static void parseNames( std::vector<std::string>& includeNames,
516 std::vector<std::string>& excludeNames,
517 const std::string& nameStr);
535 friend class ::TestAttributeSet;
538 std::vector<NamePair> mTypes;
545 int64_t mReserved[5];
552 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:49
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:331
void reorderAttributes(const DescriptorPtr &replacement)
Definition: AttributeSet.h:55
size_t unusedGroupOffset(size_t hint=std::numeric_limits< size_t >::max()) const
Return a group offset that is not in use.
__attribute__((deprecated)) AttributeArray AttributeArray::Ptr removeAttribute(const Name &name)
Remove and return an attribute array by name.
bool operator==(const Descriptor &) const
Return true if this descriptor is equal to the given one.
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:325
size_t rename(const std::string &fromName, const std::string &toName)
Rename an attribute array.
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:111
AttributeSet(const DescriptorPtr &descriptor, Index arrayLength=1, const AttributeArray::ScopedRegistryLock *lock=nullptr)
size_t availableGroups() const
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:337
bool hasDefaultValue(const Name &name) const
Return true if the attribute has a default value.
bool canCompactGroups() const
Return true if there are sufficient empty slots to allow compacting.
Ptr duplicateDrop(const std::vector< size_t > &pos) const
Create a new descriptor as a duplicate with existing attributes dropped.
bool isShared(size_t pos) const
Return true if the attribute array stored at position pos is shared.
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
Index32 Index
Definition: Types.h:31
Definition: AttributeSet.h:303
AttributeArray * get(const std::string &name)
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:58
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:288
std::string Name
Definition: Name.h:17
Descriptor(const Descriptor &)
Copy constructor.
size_t unusedGroups() const
size_t count(const NamePair &type) const
Return the number of attributes with this attribute type.
void dropAttributes(const std::vector< size_t > &pos)
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:108
Attribute and type name pair.
Definition: AttributeSet.h:57
Library and file format version numbers.
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *defaultValue=nullptr, const bool hidden=false, const bool transient=false)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType)
Definition: PointAttribute.h:242
AttributeArray * get(size_t pos)
Attribute Array storage templated on type and compression codec.
Ptr duplicateAppend(const Name &name, const NamePair &type) const
Create a new descriptor as a duplicate with a new attribute appended.
void read(std::istream &)
Read the entire set from a stream.
void clearGroups()
Clear all groups.
void appendTo(NameAndTypeVec &attrs) const
Append to a vector of names and types from this Descriptor in position order.
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:416
NameAndTypeVec vec
Definition: AttributeSet.h:330
void pruneUnusedDefaultValues()
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:334
std::vector< size_t > groupAttributeIndices() const
Return the indices of the attribute arrays which are group attribute arrays.
const Name const NamePair const Index strideOrTotalSize
Definition: PointAttribute.h:546
void removeDefaultValue(const Name &name)
const AttributeArray * get(size_t pos) const
size_t renameGroup(const std::string &fromName, const std::string &toName)
Rename a group.
size_t insert(const std::string &name, const NamePair &typeName)
const Name const NamePair & type
Definition: PointAttribute.h:545
const NamePair & type(size_t pos) const
Return the name of the attribute array's type.
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.
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:50
void write(std::ostream &, bool outputTransient=false) const
GroupIndex groupIndex(const size_t offset) const
AttributeSet(const AttributeSet &attributeSet, Index arrayLength, const AttributeArray::ScopedRegistryLock *lock=nullptr)
void setDefaultValue(const Name &name, const Metadata &defaultValue)
Set a default value for an existing attribute.
const Name & valueType(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.
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...
Definition: Exceptions.h:60
void dropAttributes(const std::vector< size_t > &pos, const Descriptor &expected, DescriptorPtr &replacement)
const Descriptor & descriptor() const
Definition: AttributeSet.h:103
void dropGroup(const Name &group)
Drop any mapping keyed by group name.
const Name const NamePair const Index const bool constantStride
Definition: PointAttribute.h:547
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:323
size_t replace(const std::string &name, const AttributeArray::Ptr &)
Replace the attribute array whose name is name.
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:424
size_t memUsage() const
Return the number of bytes of memory used by this attribute set.
void write(std::ostream &) const
Serialize this descriptor to the given stream.
bool operator==(const AttributeSet &other) const
std::unique_ptr< AttributeSet > UniquePtr
Definition: AttributeSet.h:45
AttributeSet(const AttributeSet &)
Shallow copy constructor, the descriptor and attribute arrays will be shared.
const AttributeArray * get(const std::string &name) const
Name name
Definition: AttributeSet.h:60
bool hasSameAttributes(const Descriptor &rhs) const
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:65
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:324
const Name uniqueGroupName(const Name &name) const
Return a unique name for a group based on given name.
size_t replace(size_t pos, const AttributeArray::Ptr &)
Replace the attribute array stored at position pos in this container.
__attribute__((deprecated)) AttributeArray 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)
void readMetadata(std::istream &)
This will read the attribute metadata from a stream.
void setGroup(const Name &group, const size_t offset, const bool checkValidOffset=false)
Define a group name to offset mapping.
NamePair type
Definition: AttributeSet.h:61
Base class for storing attribute data.
Definition: AttributeArray.h:93
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
void writeMetadata(std::ostream &, bool outputTransient=false, bool paged=false) const
void renameAttributes(const Descriptor &expected, const DescriptorPtr &replacement)
const Name uniqueName(const Name &name) const
Return a unique name for an attribute array based on given name.
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:44
void readDescriptor(std::istream &)
This will read the attribute descriptor from a stream.
size_t groupOffset(const Util::GroupIndex &index) const
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:329
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:66
GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
bool hasGroup(const Name &group) const
Return true if group exists.
const Name & name
Definition: PointAttribute.h:544
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)
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:422
const MetaMap & getMetadata() const
static size_t groupBits()
Return number of bits occupied by a group attribute array.
Definition: AttributeSet.h:461
void writeDescriptor(std::ostream &, bool outputTransient=false) const
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:67
Definition: AttributeArray.h:119
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
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...
size_t groupOffset(const GroupIndex &index) const
void resetDescriptor(const DescriptorPtr &replacement, const bool allowMismatchingDescriptors=false)
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
Util::GroupIndex groupIndex(const size_t offset) const
bool groupIndexCollision(const Descriptor &rhs) const
Test if there are any group names shared by both descriptors which have a different index.
MetaMap & getMetadata()
Retrieve metadata map.
static Ptr create(const NamePair &)
Create a new descriptor from a position attribute type and assumes "P" (for convenience).
Definition: Exceptions.h:13
uint8_t GroupType
Definition: AttributeSet.h:31
static Ptr create(const NameAndTypeVec &, const NameToPosMap &, const MetaMap &)
AttributeArray::Ptr removeAttribute(const size_t pos)
Remove and return an attribute array by index.
void readAttributes(std::istream &)
This will read the attribute data from a stream.
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,...
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:390
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:326
static bool validName(const Name &name)
Return true if the name is valid.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
void writeAttributes(std::ostream &, bool outputTransient=false) const
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:43
AttributeArray::Ptr removeAttributeUnsafe(const size_t pos)
Remove and return an attribute array by index (unsafe method)
Index stride
Definition: AttributeSet.h:62
void makeUnique(size_t pos)
If the attribute array stored at position pos is shared, replace the array with a deep copy of itself...