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;
40 using Ptr = std::shared_ptr<AttributeSet>;
41 using ConstPtr = std::shared_ptr<const AttributeSet>;
55 : name(n), type(t), stride(s) {}
96 Descriptor& descriptor() {
return *mDescr; }
107 size_t size()
const {
return mAttrs.size(); }
114 size_t find(
const std::string& name)
const;
145 size_t groupOffset(
const Name& groupName)
const;
171 const Index strideOrTotalSize = 1,
172 const bool constantStride =
true,
180 const size_t pos,
const Index strideOrTotalSize = 1,
181 const bool constantStride =
true,
211 void write(std::ostream&,
bool outputTransient =
false)
const;
224 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
238 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
240 DescriptorPtr mDescr;
248 #if OPENVDB_ABI_VERSION_NUMBER >= 5
253 std::vector<std::shared_ptr<Element>> mElements;
269 using Ptr = std::shared_ptr<Descriptor>;
281 vec.push_back(nameAndType);
return *
this;
284 vec.emplace_back(name, type);
return *
this;
287 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
288 vec.emplace_back(it->name, it->type);
311 size_t size()
const {
return mTypes.size(); }
321 size_t find(
const std::string& name)
const;
324 size_t rename(
const std::string& fromName,
const std::string& toName);
338 template<
typename ValueType>
341 const size_t pos = find(name);
342 if (pos == INVALID_POS) {
346 std::stringstream ss;
347 ss <<
"default:" << name;
351 if (metadata)
return metadata->
value();
353 return zeroVal<ValueType>();
384 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
389 size_t groupOffset(
const Name& groupName)
const;
417 static void parseNames( std::vector<std::string>& includeNames,
418 std::vector<std::string>& excludeNames,
420 const std::string& nameStr);
424 static void parseNames( std::vector<std::string>& includeNames,
425 std::vector<std::string>& excludeNames,
426 const std::string& nameStr);
444 friend class ::TestAttributeSet;
447 std::vector<NamePair> mTypes;
450 #if OPENVDB_ABI_VERSION_NUMBER >= 5
455 int64_t mReserved[5];
457 int64_t mReserved[8];
465 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:273
void readAttributes(std::istream &)
This will read the attribute data from a stream.
size_t replace(size_t pos, const AttributeArray::Ptr &)
Replace the attribute array stored at position pos in this container.
bool isShared(size_t pos) const
Return true if the attribute array stored at position pos is shared.
AttributeArray * get(const std::string &name)
void setDefaultValue(const Name &name, const Metadata &defaultValue)
Set a default value for an existing attribute.
Base class for storing attribute data.
Definition: AttributeArray.h:93
Descriptor(const Descriptor &)
Copy constructor.
AttributeSet & operator=(const AttributeSet &)=delete
Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:274
Definition: Exceptions.h:60
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:41
size_t groupOffset(const Util::GroupIndex &index) const
void setGroup(const Name &group, const size_t offset)
Define a group name to offset mapping.
bool hasGroup(const Name &group) const
Return true if group exists.
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:371
size_t count(const NamePair &type) const
Return the number of attributes with this attribute type.
AttributeArray::Ptr appendAttribute(const Descriptor &expected, DescriptorPtr &replacement, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true, const AttributeArray::ScopedRegistryLock *lock=nullptr)
static Ptr create(const NamePair &)
Create a new descriptor from a position attribute type and assumes "P" (for convenience).
Index stride
Definition: AttributeSet.h:58
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:365
NameAndTypeVec vec
Definition: AttributeSet.h:279
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:126
bool hasSameAttributes(const Descriptor &rhs) const
Library and file format version numbers.
Attribute Array storage templated on type and compression codec.
static bool validName(const Name &name)
Return true if the name is valid.
const Name uniqueGroupName(const Name &name) const
Return a unique name for a group based on given name.
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:40
void makeUnique(size_t pos)
If the attribute array stored at position pos is shared, replace the array with a deep copy of itself...
void dropAttributes(const std::vector< size_t > &pos)
const NamePair & type(size_t pos) const
Return the name of the attribute array's type.
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:45
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:104
AttributeArray * get(size_t pos)
const Name uniqueName(const Name &name) const
Return a unique name for an attribute array based on given name.
void appendTo(NameAndTypeVec &attrs) const
Append to a vector of names and types from this Descriptor in position order.
bool operator==(const Descriptor &) const
Return true if this descriptor is equal to the given one.
Definition: AttributeSet.h:51
void dropGroup(const Name &group)
Drop any mapping keyed by group name.
AttributeSet(const DescriptorPtr &descriptor, Index arrayLength=1, const AttributeArray::ScopedRegistryLock *lock=nullptr)
GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
void removeDefaultValue(const Name &name)
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:272
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:373
bool hasDefaultValue(const Name &name) const
Return true if the attribute has a default value.
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 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.
Util::GroupIndex groupIndex(const size_t offset) const
void write(std::ostream &, bool outputTransient=false) const
AttributeSet(const AttributeSet &)
Shallow copy constructor, the descriptor and attribute arrays will be shared.
AttributeSet(const AttributeSet &attributeSet, Index arrayLength, const AttributeArray::ScopedRegistryLock *lock=nullptr)
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:235
const Name & valueType(size_t pos) const
Return the name of the attribute array's type.
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:471
void dropAttributes(const std::vector< size_t > &pos, const Descriptor &expected, DescriptorPtr &replacement)
const Descriptor & descriptor() const
Definition: AttributeSet.h:99
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:339
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:275
void readMetadata(std::istream &)
This will read the attribute metadata from a stream.
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:280
void renameAttributes(const Descriptor &expected, const DescriptorPtr &replacement)
Attribute and type name pair.
Definition: AttributeSet.h:53
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:61
NamePair type
Definition: AttributeSet.h:57
Ptr duplicateAppend(const Name &name, const NamePair &type) const
Create a new descriptor as a duplicate with a new attribute appended.
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
void clearGroups()
Clear all groups.
bool operator==(const AttributeSet &other) const
Definition: AttributeArray.h:120
Name name
Definition: AttributeSet.h:56
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:107
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:36
const AttributeArray * get(size_t pos) const
size_t renameGroup(const std::string &fromName, const std::string &toName)
Rename a group.
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:286
const MetaMap & getMetadata() const
void writeDescriptor(std::ostream &, bool outputTransient=false) const
Index32 Index
Definition: Types.h:31
size_t insert(const std::string &name, const NamePair &typeName)
Ptr duplicateDrop(const std::vector< size_t > &pos) const
Create a new descriptor as a duplicate with existing attributes dropped.
std::string Name
Definition: Name.h:17
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:46
void writeMetadata(std::ostream &, bool outputTransient=false, bool paged=false) const
GroupIndex groupIndex(const size_t offset) const
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:62
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:278
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:63
static Ptr create(const NameAndTypeVec &, const NameToPosMap &, const MetaMap &)
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: AttributeSet.h:251
void readDescriptor(std::istream &)
This will read the attribute descriptor from a stream.
void writeAttributes(std::ostream &, bool outputTransient=false) const
Definition: Exceptions.h:13
AttributeArray::Ptr appendAttribute(const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr defaultValue=Metadata::Ptr())
Append attribute attribute (simple method)
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.
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:54
size_t groupOffset(const GroupIndex &index) const
void reorderAttributes(const DescriptorPtr &replacement)
void resetDescriptor(const DescriptorPtr &replacement, const bool allowMismatchingDescriptors=false)
MetaMap & getMetadata()
Retrieve metadata map.
void write(std::ostream &) const
Serialize this descriptor to the given stream.
void read(std::istream &)
Read the entire set from a stream.
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
const AttributeArray * get(const std::string &name) const
void pruneUnusedDefaultValues()
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:283