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;
275 using Ptr = std::shared_ptr<Descriptor>;
287 vec.push_back(nameAndType);
return *
this;
290 vec.emplace_back(name, type);
return *
this;
293 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
294 vec.emplace_back(it->name, it->type);
305 Descriptor(
const Descriptor&);
311 Ptr duplicateAppend(
const Name& name,
const NamePair& type)
const;
314 Ptr duplicateDrop(
const std::vector<size_t>& pos)
const;
317 size_t size()
const {
return mTypes.size(); }
320 size_t count(
const NamePair& type)
const;
323 size_t memUsage()
const;
327 size_t find(
const std::string& name)
const;
330 size_t rename(
const std::string& fromName,
const std::string& toName);
333 const Name& valueType(
size_t pos)
const;
335 const NamePair& type(
size_t pos)
const;
339 const MetaMap& getMetadata()
const;
342 bool hasDefaultValue(
const Name& name)
const;
344 template<
typename ValueType>
347 const size_t pos = find(name);
348 if (pos == INVALID_POS) {
352 std::stringstream ss;
353 ss <<
"default:" << name;
357 if (metadata)
return metadata->
value();
359 return zeroVal<ValueType>();
364 void removeDefaultValue(
const Name& name);
366 void pruneUnusedDefaultValues();
374 bool hasSameAttributes(
const Descriptor& rhs)
const;
382 bool hasGroup(
const Name& group)
const;
390 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
392 const Name uniqueGroupName(
const Name& name)
const;
395 const Name uniqueName(
const Name& name)
const;
398 static bool validName(
const Name& name);
406 static void parseNames( std::vector<std::string>& includeNames,
407 std::vector<std::string>& excludeNames,
409 const std::string& nameStr);
413 static void parseNames( std::vector<std::string>& includeNames,
414 std::vector<std::string>& excludeNames,
415 const std::string& nameStr);
418 void write(std::ostream&)
const;
420 void read(std::istream&);
424 void appendTo(NameAndTypeVec& attrs)
const;
428 static Ptr create(
const NameAndTypeVec&,
const NameToPosMap&,
const MetaMap&);
430 size_t insert(
const std::string& name,
const NamePair& typeName);
433 friend class ::TestAttributeSet;
436 std::vector<NamePair> mTypes;
439 int64_t mReserved[8];
446 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:81
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:73
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:281
const Descriptor & descriptor() const
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:122
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:256
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:101
Attribute Array storage templated on type and compression codec.
NameAndTypeVec vec
Definition: AttributeSet.h:285
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:90
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:379
void renameAttributes(PointDataTree &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:691
Index32 Index
Definition: Types.h:57
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:72
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:284
std::string Name
Definition: Name.h:44
#define OPENVDB_VERSION_NAME
Definition: version.h:43
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:127
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:377
Index stride
Definition: AttributeSet.h:85
void dropGroup(PointDataTree &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:529
Name name
Definition: AttributeSet.h:83
void dropAttributes(PointDataTree &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:604
Definition: Exceptions.h:39
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:371
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:487
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:130
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:88
Definition: Exceptions.h:87
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:289
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:345
Attribute and type name pair.
Definition: AttributeSet.h:80
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:142
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:280
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:286
Base class for storing attribute data.
Definition: AttributeArray.h:118
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:279
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:292
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:65
void appendAttribute(PointDataTree &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:463
NamePair type
Definition: AttributeSet.h:84
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:673
ValueType defaultValue()
Definition: PointAttribute.h:56
Definition: AttributeSet.h:77
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:89
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:278
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:67
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:68