10 #ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED 14 #include <openvdb/version.h> 22 class TestAttributeSet;
43 using Ptr = std::shared_ptr<AttributeSet>;
44 using ConstPtr = std::shared_ptr<const AttributeSet>;
59 : name(n), type(t), stride(s) {}
111 size_t size()
const {
return mAttrs.size(); }
118 size_t find(
const std::string& name)
const;
155 size_t groupOffset(
const Name& groupName)
const;
166 std::vector<size_t> groupAttributeIndices()
const;
169 bool isShared(
size_t pos)
const;
173 void makeUnique(
size_t pos);
178 const Index strideOrTotalSize = 1,
179 const bool constantStride =
true,
180 const Metadata* defaultValue =
nullptr);
187 const size_t pos,
const Index strideOrTotalSize = 1,
188 const bool constantStride =
true,
189 const Metadata* defaultValue =
nullptr,
245 void resetDescriptor(
const DescriptorPtr& replacement,
const bool allowMismatchingDescriptors =
false);
248 void read(std::istream&);
251 void write(std::ostream&,
bool outputTransient =
false)
const;
254 void readDescriptor(std::istream&);
257 void writeDescriptor(std::ostream&,
bool outputTransient =
false)
const;
260 void readMetadata(std::istream&);
264 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
267 void readAttributes(std::istream&);
270 void writeAttributes(std::ostream&,
bool outputTransient =
false)
const;
278 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
292 std::vector<std::shared_ptr<Element>> mElements;
307 using Ptr = std::shared_ptr<Descriptor>;
319 vec.push_back(nameAndType);
return *
this;
322 vec.emplace_back(name, type);
return *
this;
325 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
326 vec.emplace_back(it->name, it->type);
337 Descriptor(
const Descriptor&);
346 Ptr duplicateDrop(
const std::vector<size_t>& pos)
const;
349 size_t size()
const {
return mTypes.size(); }
352 size_t count(
const NamePair& type)
const;
359 size_t find(
const std::string& name)
const;
362 size_t rename(
const std::string& fromName,
const std::string& toName);
365 const Name& valueType(
size_t pos)
const;
367 const NamePair& type(
size_t pos)
const;
371 const MetaMap& getMetadata()
const;
374 bool hasDefaultValue(
const Name& name)
const;
376 template<
typename ValueType>
379 const size_t pos = find(name);
380 if (pos == INVALID_POS) {
384 std::stringstream ss;
385 ss <<
"default:" << name;
389 if (metadata)
return metadata->
value();
391 return zeroVal<ValueType>();
394 void setDefaultValue(
const Name& name,
const Metadata& defaultValue);
396 void removeDefaultValue(
const Name& name);
398 void pruneUnusedDefaultValues();
406 bool hasSameAttributes(
const Descriptor& rhs)
const;
414 bool hasGroup(
const Name& group)
const;
420 const bool checkValidOffset =
false);
426 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
428 const Name uniqueGroupName(
const Name& name)
const;
437 size_t groupOffset(
const Name& groupName)
const;
438 size_t groupOffset(
const GroupIndex& index)
const;
445 GroupIndex groupIndex(
const size_t offset)
const;
452 size_t availableGroups()
const;
456 size_t unusedGroups()
const;
459 bool canCompactGroups()
const;
472 bool requiresGroupMove(
Name& sourceName,
size_t& sourceOffset,
size_t& targetOffset)
const;
478 bool groupIndexCollision(
const Descriptor& rhs)
const;
481 const Name uniqueName(
const Name& name)
const;
484 static bool validName(
const Name& name);
492 static void parseNames( std::vector<std::string>& includeNames,
493 std::vector<std::string>& excludeNames,
495 const std::string& nameStr);
499 static void parseNames( std::vector<std::string>& includeNames,
500 std::vector<std::string>& excludeNames,
501 const std::string& nameStr);
504 void write(std::ostream&)
const;
506 void read(std::istream&);
516 size_t insert(
const std::string& name,
const NamePair& typeName);
519 friend class ::TestAttributeSet;
522 std::vector<NamePair> mTypes;
529 int64_t mReserved[5];
536 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:38
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Util::NameToPosMap NameToPosMap
Definition: AttributeSet.h:312
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:108
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
Definition: AttributeSet.h:411
Attribute Array storage templated on type and compression codec.
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:102
Index stride
Definition: AttributeSet.h:62
std::shared_ptr< AttributeArray > Ptr
Definition: AttributeArray.h:125
NamePair type
Definition: AttributeSet.h:61
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Definition: AttributeSet.h:377
Base class for storing attribute data.
Definition: AttributeArray.h:92
void dropGroup(PointDataTreeT &tree, const Name &group, const bool compact=true)
Drops an existing group from the VDB tree.
Definition: PointGroup.h:406
static fileSize_t write(std::ostream &os, const GridHandle< BufferT > &handle, Codec codec)
Definition: Exceptions.h:60
Definition: AttributeArray.h:118
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize=1, const bool constantStride=true, const Metadata *defaultValue=nullptr, 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:245
std::map< std::string, size_t > NameToPosMap
Definition: AttributeSet.h:66
std::vector< NameAndType > NameAndTypeVec
Definition: AttributeSet.h:65
std::shared_ptr< const AttributeSet > ConstPtr
Definition: AttributeSet.h:44
static void read(std::istream &is, GridHandle< BufferT > &handle, Codec codec)
std::shared_ptr< AttributeSet > Ptr
Definition: AttributeSet.h:43
Util::GroupIndex GroupIndex
Definition: AttributeSet.h:311
Inserter & add(const NameAndTypeVec &other)
Definition: AttributeSet.h:324
Util::NameAndTypeVec NameAndTypeVec
Definition: AttributeSet.h:310
const NameToPosMap & map() const
Return a reference to the name-to-position map.
Definition: AttributeSet.h:409
std::string Name
Definition: Name.h:17
Inserter & add(const NameAndType &nameAndType)
Definition: AttributeSet.h:318
bool operator!=(const AttributeSet &other) const
Definition: AttributeSet.h:275
void replace(std::string &str, const std::string &oldStr, const std::string &newStr)
Definition: util.h:61
NameAndTypeVec vec
Definition: AttributeSet.h:317
uint8_t GroupType
Definition: AttributeSet.h:31
const Descriptor & descriptor() const
Return a reference to this attribute set's descriptor, which might be shared with other sets...
Definition: AttributeSet.h:103
Definition: Exceptions.h:13
std::shared_ptr< const Descriptor > DescriptorConstPtr
Definition: AttributeSet.h:50
Definition: AttributeSet.h:54
std::shared_ptr< Descriptor > DescriptorPtr
Definition: AttributeSet.h:49
Index32 Index
Definition: Types.h:54
Definition: AttributeSet.h:289
std::unique_ptr< AttributeSet > UniquePtr
Definition: AttributeSet.h:45
Inserter & add(const Name &name, const NamePair &type)
Definition: AttributeSet.h:321
std::pair< size_t, uint8_t > GroupIndex
Definition: AttributeSet.h:67
Utility method to construct a NameAndType sequence.
Definition: AttributeSet.h:316
NameToPosMap::const_iterator ConstIterator
Definition: AttributeSet.h:313
std::pair< Name, Name > NamePair
Definition: AttributeArray.h:39
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
Definition: PointAttribute.h:380
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
Definition: PointAttribute.h:468
Attribute and type name pair.
Definition: AttributeSet.h:57
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Definition: AttributeSet.h:403
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
Definition: AttributeSet.h:58
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
bool operator==(const Vec3< T0 > &v0, const Vec3< T1 > &v1)
Equality operator, does exact floating point comparisons.
Definition: Vec3.h:477
void setGroup(PointDataTreeT &tree, const PointIndexTreeT &indexTree, const std::vector< short > &membership, const Name &group, const bool remove=false)
Sets group membership from a PointIndexTree-ordered vector.
Definition: PointGroup.h:548
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:111
static size_t groupBits()
Return number of bits occupied by a group attribute array.
Definition: AttributeSet.h:448
Name name
Definition: AttributeSet.h:60
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202