37 #ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED 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(); }
133 size_t memUsage()
const;
137 size_t find(
const std::string& name)
const;
168 size_t groupOffset(
const Name& groupName)
const;
175 size_t groupOffset(
const Util::GroupIndex& index)
const;
179 Util::GroupIndex groupIndex(
const Name& groupName)
const;
182 Util::GroupIndex groupIndex(
const size_t offset)
const;
185 bool isShared(
size_t pos)
const;
189 void makeUnique(
size_t pos);
194 const Index strideOrTotalSize = 1,
195 const bool constantStride =
true,
202 const size_t pos,
const Index strideOrTotalSize = 1,
203 const bool constantStride =
true);
213 const Descriptor& expected, DescriptorPtr& replacement);
217 void renameAttributes(
const Descriptor& expected,
const DescriptorPtr& replacement);
221 void reorderAttributes(
const DescriptorPtr& replacement);
226 void resetDescriptor(
const DescriptorPtr& replacement,
const bool allowMismatchingDescriptors =
false);
229 void read(std::istream&);
232 void write(std::ostream&,
bool outputTransient =
false)
const;
235 void readDescriptor(std::istream&);
238 void writeDescriptor(std::ostream&,
bool outputTransient =
false)
const;
241 void readMetadata(std::istream&);
245 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
248 void readAttributes(std::istream&);
251 void writeAttributes(std::ostream&,
bool outputTransient =
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);
320 Descriptor(
const Descriptor&);
326 Ptr duplicateAppend(
const Name& name,
const NamePair& type)
const;
329 Ptr duplicateDrop(
const std::vector<size_t>& pos)
const;
332 size_t size()
const {
return mTypes.size(); }
335 size_t count(
const NamePair& type)
const;
338 size_t memUsage()
const;
342 size_t find(
const std::string& name)
const;
345 size_t rename(
const std::string& fromName,
const std::string& toName);
348 const Name& valueType(
size_t pos)
const;
350 const NamePair& type(
size_t pos)
const;
354 const MetaMap& getMetadata()
const;
357 bool hasDefaultValue(
const Name& name)
const;
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>();
377 void setDefaultValue(
const Name& name,
const Metadata& defaultValue);
379 void removeDefaultValue(
const Name& name);
381 void pruneUnusedDefaultValues();
389 bool hasSameAttributes(
const Descriptor& rhs)
const;
397 bool hasGroup(
const Name& group)
const;
405 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
407 const Name uniqueGroupName(
const Name& name)
const;
410 size_t groupOffset(
const Name& groupName)
const;
417 size_t groupOffset(
const GroupIndex& index)
const;
421 GroupIndex groupIndex(
const Name& groupName)
const;
424 GroupIndex groupIndex(
const size_t offset)
const;
427 const Name uniqueName(
const Name& name)
const;
430 static bool validName(
const Name& name);
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);
450 void write(std::ostream&)
const;
452 void read(std::istream&);
456 void appendTo(NameAndTypeVec& attrs)
const;
460 static Ptr create(
const NameAndTypeVec&,
const NameToPosMap&,
const MetaMap&);
462 size_t insert(
const std::string& name,
const NamePair& typeName);
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
Index32 Index
Definition: Types.h:61
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:295
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:392
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:89
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
Attribute Array storage templated on type and compression codec.
Index stride
Definition: AttributeSet.h:85
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:88
NamePair type
Definition: AttributeSet.h:84
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
Definition: AttributeSet.h:271
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:67
Definition: AttributeSet.h:77
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:301
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:294
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:68
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
NameAndTypeVec vec
Definition: AttributeSet.h:300
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:488
void setGroup(PointDataTree &tree, const PointIndexTree &indexTree, const std::vector< short > &membership, const Name &group, const bool remove=false)
Sets group membership from a PointIndexTree-ordered vector.
Definition: PointGroup.h:691
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:529
void dropGroup(PointDataTree &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:545
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:293
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:394
Definition: Exceptions.h:87
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:73
Definition: Exceptions.h:40
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:618
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:144
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:360
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:307
Library and file format version numbers.
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
Base class for storing attribute data.
Definition: AttributeArray.h:118
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:130
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:299
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, Metadata::Ptr metaDefaultValue=Metadata::Ptr(), 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:409
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:296
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Attribute and type name pair.
Definition: AttributeSet.h:80
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:81
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:386
std::string Name
Definition: Name.h:44
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:256
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:90
Name name
Definition: AttributeSet.h:83
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:127
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:304
const Descriptor & descriptor() const
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:122