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(); }
110 size_t memUsage()
const;
114 size_t find(
const std::string& name)
const;
145 size_t groupOffset(
const Name& groupName)
const;
152 size_t groupOffset(
const Util::GroupIndex& index)
const;
156 Util::GroupIndex groupIndex(
const Name& groupName)
const;
159 Util::GroupIndex groupIndex(
const size_t offset)
const;
162 bool isShared(
size_t pos)
const;
166 void makeUnique(
size_t pos);
171 const Index strideOrTotalSize = 1,
172 const bool constantStride =
true,
180 const size_t pos,
const Index strideOrTotalSize = 1,
181 const bool constantStride =
true,
192 const Descriptor& expected, DescriptorPtr& replacement);
196 void renameAttributes(
const Descriptor& expected,
const DescriptorPtr& replacement);
200 void reorderAttributes(
const DescriptorPtr& replacement);
205 void resetDescriptor(
const DescriptorPtr& replacement,
const bool allowMismatchingDescriptors =
false);
208 void read(std::istream&);
211 void write(std::ostream&,
bool outputTransient =
false)
const;
214 void readDescriptor(std::istream&);
217 void writeDescriptor(std::ostream&,
bool outputTransient =
false)
const;
220 void readMetadata(std::istream&);
224 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
227 void readAttributes(std::istream&);
230 void writeAttributes(std::ostream&,
bool outputTransient =
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);
299 Descriptor(
const Descriptor&);
305 Ptr duplicateAppend(
const Name& name,
const NamePair& type)
const;
308 Ptr duplicateDrop(
const std::vector<size_t>& pos)
const;
311 size_t size()
const {
return mTypes.size(); }
314 size_t count(
const NamePair& type)
const;
317 size_t memUsage()
const;
321 size_t find(
const std::string& name)
const;
324 size_t rename(
const std::string& fromName,
const std::string& toName);
327 const Name& valueType(
size_t pos)
const;
329 const NamePair& type(
size_t pos)
const;
333 const MetaMap& getMetadata()
const;
336 bool hasDefaultValue(
const Name& name)
const;
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>();
356 void setDefaultValue(
const Name& name,
const Metadata& defaultValue);
358 void removeDefaultValue(
const Name& name);
360 void pruneUnusedDefaultValues();
368 bool hasSameAttributes(
const Descriptor& rhs)
const;
376 bool hasGroup(
const Name& group)
const;
384 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
386 const Name uniqueGroupName(
const Name& name)
const;
389 size_t groupOffset(
const Name& groupName)
const;
396 size_t groupOffset(
const GroupIndex& index)
const;
400 GroupIndex groupIndex(
const Name& groupName)
const;
403 GroupIndex groupIndex(
const size_t offset)
const;
406 const Name uniqueName(
const Name& name)
const;
409 static bool validName(
const Name& name);
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);
429 void write(std::ostream&)
const;
431 void read(std::istream&);
435 void appendTo(NameAndTypeVec& attrs)
const;
439 static Ptr create(
const NameAndTypeVec&,
const NameToPosMap&,
const MetaMap&);
441 size_t insert(
const std::string& name,
const NamePair& typeName);
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 const Descriptor & descriptor() const
Return a reference to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:99
Definition: AttributeSet.h:250
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:665
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:370
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:458
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:371
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:126
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:274
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82
std::string Name
Definition: Name.h:17
Attribute Array storage templated on type and compression codec.
Base class for storing attribute data.
Definition: AttributeArray.h:92
Definition: AttributeArray.h:119
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:242
Index stride
Definition: AttributeSet.h:58
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:62
NamePair type
Definition: AttributeSet.h:57
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:40
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:273
Attribute and type name pair.
Definition: AttributeSet.h:53
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:41
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:61
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:286
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:272
Definition: AttributeSet.h:50
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:46
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:373
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:280
Definition: Exceptions.h:13
NameAndTypeVec vec
Definition: AttributeSet.h:279
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:339
Library and file format version numbers.
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:45
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: Exceptions.h:60
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:283
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:107
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:63
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:278
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:275
void dropGroup(PointDataTree &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:519
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:365
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:54
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:35
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:235
Name name
Definition: AttributeSet.h:56
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets.
Definition: AttributeSet.h:104