10#ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
11#define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
14#include <openvdb/version.h>
23class TestAttributeSet;
44 using Ptr = std::shared_ptr<AttributeSet>;
45 using ConstPtr = std::shared_ptr<const AttributeSet>;
112 size_t size()
const {
return mAttrs.size(); }
124 size_t find(
const std::string& name)
const;
184 const Index strideOrTotalSize = 1,
185 const bool constantStride =
true,
186 const Metadata* defaultValue =
nullptr);
193 const size_t pos,
const Index strideOrTotalSize = 1,
194 const bool constantStride =
true,
195 const Metadata* defaultValue =
nullptr,
257 void write(std::ostream&,
bool outputTransient =
false)
const;
270 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
284 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
286 DescriptorPtr mDescr;
298 std::vector<std::shared_ptr<Element>> mElements;
313 using Ptr = std::shared_ptr<Descriptor>;
325 vec.push_back(nameAndType);
return *
this;
328 vec.emplace_back(name,
type);
return *
this;
331 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
332 vec.emplace_back(it->name, it->type);
355 size_t size()
const {
return mTypes.size(); }
365 size_t find(
const std::string& name)
const;
368 size_t rename(
const std::string& fromName,
const std::string& toName);
382 template<
typename ValueType>
385 const size_t pos =
find(name);
390 std::stringstream ss;
391 ss <<
"default:" << name;
395 if (metadata)
return metadata->value();
426 const bool checkValidOffset =
false);
432 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
498 static void parseNames( std::vector<std::string>& includeNames,
499 std::vector<std::string>& excludeNames,
501 const std::string& nameStr);
505 static void parseNames( std::vector<std::string>& includeNames,
506 std::vector<std::string>& excludeNames,
507 const std::string& nameStr);
525 friend class ::TestAttributeSet;
528 std::vector<NamePair> mTypes;
535 int64_t mReserved[5];
Attribute Array storage templated on type and compression codec.
Definition Exceptions.h:60
Definition AttributeArray.h:120
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
size_t unusedGroups() const
bool operator==(const Descriptor &) const
Return true if this descriptor is equal to the given one.
Util::GroupIndex GroupIndex
Definition AttributeSet.h:317
const MetaMap & getMetadata() const
void clearGroups()
Clear all groups.
size_t memUsage() const
Return the number of bytes of memory used by this attribute set.
size_t renameGroup(const std::string &fromName, const std::string &toName)
Rename a group.
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.
void removeDefaultValue(const Name &name)
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.
void pruneUnusedDefaultValues()
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.
size_t availableGroups() const
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)
size_t memUsageIfLoaded() const
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
Name name
Definition AttributeSet.h:61
Index stride
Definition AttributeSet.h:63
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