Go to the documentation of this file.
37 #ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
41 #include <openvdb/version.h>
42 #include <openvdb/MetaMap.h>
49 class TestAttributeSet;
67 using Ptr = std::shared_ptr<AttributeSet>;
68 using ConstPtr = std::shared_ptr<const AttributeSet>;
82 : name(n), type(t), stride(s) {}
119 Descriptor& descriptor() {
return *mDescr; }
130 size_t size()
const {
return mAttrs.size(); }
137 size_t find(
const std::string& name)
const;
168 size_t groupOffset(
const Name& groupName)
const;
194 const Index strideOrTotalSize = 1,
195 const bool constantStride =
true,
202 const size_t pos,
const Index strideOrTotalSize = 1,
203 const bool constantStride =
true);
232 void write(std::ostream&,
bool outputTransient =
false)
const;
245 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
259 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
261 DescriptorPtr mDescr;
269 #if OPENVDB_ABI_VERSION_NUMBER >= 5
274 std::vector<std::shared_ptr<Element>> mElements;
290 using Ptr = std::shared_ptr<Descriptor>;
302 vec.push_back(nameAndType);
return *
this;
305 vec.emplace_back(name, type);
return *
this;
308 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
309 vec.emplace_back(it->name, it->type);
332 size_t size()
const {
return mTypes.size(); }
342 size_t find(
const std::string& name)
const;
345 size_t rename(
const std::string& fromName,
const std::string& toName);
359 template<
typename ValueType>
362 const size_t pos = find(name);
363 if (pos == INVALID_POS) {
367 std::stringstream ss;
368 ss <<
"default:" << name;
372 if (metadata)
return metadata->
value();
374 return zeroVal<ValueType>();
405 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
410 size_t groupOffset(
const Name& groupName)
const;
438 static void parseNames( std::vector<std::string>& includeNames,
439 std::vector<std::string>& excludeNames,
441 const std::string& nameStr);
445 static void parseNames( std::vector<std::string>& includeNames,
446 std::vector<std::string>& excludeNames,
447 const std::string& nameStr);
465 friend class ::TestAttributeSet;
468 std::vector<NamePair> mTypes;
471 #if OPENVDB_ABI_VERSION_NUMBER >= 5
476 int64_t mReserved[5];
478 int64_t mReserved[8];
486 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
const Name uniqueName(const Name &name) const
Return a unique name for an attribute array based on given name.
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...
void clearGroups()
Clear all groups.
void renameAttributes(const Descriptor &expected, const DescriptorPtr &replacement)
void appendTo(NameAndTypeVec &attrs) const
Append to a vector of names and types from this Descriptor in position order.
Index stride
Definition: AttributeSet.h:85
const AttributeArray * get(size_t pos) const
const Name uniqueGroupName(const Name &name) const
Return a unique name for a group based on given name.
void dropAttributes(const std::vector< size_t > &pos, const Descriptor &expected, DescriptorPtr &replacement)
void dropAttributes(const std::vector< size_t > &pos)
void readMetadata(std::istream &)
This will read the attribute metadata from a stream.
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
void write(std::ostream &, bool outputTransient=false) const
size_t memUsage() const
Return the number of bytes of memory used by this attribute set.
Util::GroupIndex groupIndex(const size_t offset) const
const Name & valueType(size_t pos) const
Return the name of the attribute array's type.
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...
void removeDefaultValue(const Name &name)
const Descriptor & descriptor() const
Definition: AttributeSet.h:122
static Ptr create(const NameAndTypeVec &, const NameToPosMap &, const MetaMap &)
size_t renameGroup(const std::string &fromName, const std::string &toName)
Rename a group.
Attribute and type name pair.
Definition: AttributeSet.h:80
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:130
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:90
size_t insert(const std::string &name, const NamePair &typeName)
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:296
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:73
GroupIndex groupIndex(const size_t offset) const
Ptr duplicateDrop(const std::vector< size_t > &pos) const
Create a new descriptor as a duplicate with existing attributes dropped.
Attribute Array storage templated on type and compression codec.
bool operator==(const AttributeSet &other) const
AttributeArray::Ptr appendAttribute(const Descriptor &expected, DescriptorPtr &replacement, const size_t pos, const Index strideOrTotalSize=1, const bool constantStride=true)
NameAndTypeVec vec
Definition: AttributeSet.h:300
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:360
const AttributeArray * get(const std::string &name) const
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:294
void writeAttributes(std::ostream &, bool outputTransient=false) const
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:89
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
Base class for storing attribute data.
Definition: AttributeArray.h:119
size_t replace(size_t pos, const AttributeArray::Ptr &)
Replace the attribute array stored at position pos in this container.
void reorderAttributes(const DescriptorPtr &replacement)
size_t count(const NamePair &type) const
Return the number of attributes with this attribute type.
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:301
void write(std::ostream &) const
Serialize this descriptor to the given stream.
Name name
Definition: AttributeSet.h:83
AttributeArray * get(const std::string &name)
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:81
static Ptr create(const NamePair &)
Create a new descriptor from a position attribute type and assumes "P" (for convenience).
Descriptor(const Descriptor &)
Copy constructor.
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:392
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:68
void readDescriptor(std::istream &)
This will read the attribute descriptor from a stream.
Definition: AttributeSet.h:78
bool isShared(size_t pos) const
Return true if the attribute array stored at position pos is shared.
void writeMetadata(std::ostream &, bool outputTransient=false, bool paged=false) const
void resetDescriptor(const DescriptorPtr &replacement, const bool allowMismatchingDescriptors=false)
static bool validName(const Name &name)
Return true if the name is valid.
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)
void read(std::istream &)
Read the entire set from a stream.
void makeUnique(size_t pos)
If the attribute array stored at position pos is shared, replace the array with a deep copy of itself...
const NamePair & type(size_t pos) const
Return the name of the attribute array's type.
void pruneUnusedDefaultValues()
size_t groupOffset(const Util::GroupIndex &index) const
bool hasGroup(const Name &group) const
Return true if group exists.
void readAttributes(std::istream &)
This will read the attribute data from a stream.
bool operator==(const Descriptor &) const
Return true if this descriptor is equal to the given one.
AttributeSet & operator=(const AttributeSet &)=delete
Disallow copy assignment, since it wouldn't be obvious whether the copy is deep or shallow.
Index32 Index
Definition: Types.h:61
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
AttributeSet(const DescriptorPtr &descriptor, Index arrayLength=1)
Util::GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
Definition: AttributeSet.h:272
size_t groupOffset(const GroupIndex &index) const
NamePair type
Definition: AttributeSet.h:84
MetaMap & getMetadata()
Retrieve metadata map.
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:304
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:386
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
Definition: Exceptions.h:87
void setGroup(const Name &group, const size_t offset)
Define a group name to offset mapping.
AttributeSet(const AttributeSet &attributeSet, Index arrayLength)
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:307
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:88
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:295
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:67
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
std::string Name
Definition: Name.h:44
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:63
size_t replace(const std::string &name, const AttributeArray::Ptr &)
Replace the attribute array whose name is name.
void dropGroup(const Name &group)
Drop any mapping keyed by group name.
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:394
bool hasDefaultValue(const Name &name) const
Return true if the attribute has a default value.
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:293
void setDefaultValue(const Name &name, const Metadata &defaultValue)
Set a default value for an existing attribute.
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:127
Definition: Exceptions.h:40
AttributeArray * get(size_t pos)
Ptr duplicateAppend(const Name &name, const NamePair &type) const
Create a new descriptor as a duplicate with a new attribute appended.
AttributeSet(const AttributeSet &)
Shallow copy constructor, the descriptor and attribute arrays will be shared.
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:256
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:299
bool hasSameAttributes(const Descriptor &rhs) const
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:488
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
GroupIndex groupIndex(const Name &groupName) const
Return the group index from the name of the group.
const MetaMap & getMetadata() const
void writeDescriptor(std::ostream &, bool outputTransient=false) const