10 #ifndef OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_ATTRIBUTE_SET_HAS_BEEN_INCLUDED
23 class TestAttributeSet;
44 using Ptr = std::shared_ptr<AttributeSet>;
45 using ConstPtr = std::shared_ptr<const AttributeSet>;
112 size_t size()
const {
return mAttrs.size(); }
115 size_t memUsage()
const;
124 size_t find(
const std::string&
name)
const;
161 size_t groupOffset(
const Name& groupName)
const;
162 size_t groupOffset(
const Util::GroupIndex&
index)
const;
166 Util::GroupIndex groupIndex(
const Name& groupName)
const;
169 Util::GroupIndex groupIndex(
const size_t offset)
const;
172 std::vector<size_t> groupAttributeIndices()
const;
175 bool isShared(
size_t pos)
const;
179 void makeUnique(
size_t pos);
184 const Index strideOrTotalSize = 1,
185 const bool constantStride =
true,
186 const Metadata* defaultValue =
nullptr);
193 const size_t pos,
const Index strideOrTotalSize = 1,
194 const bool constantStride =
true,
195 const Metadata* defaultValue =
nullptr,
238 const Descriptor& expected, DescriptorPtr& replacement);
242 void renameAttributes(
const Descriptor& expected,
const DescriptorPtr& replacement);
246 void reorderAttributes(
const DescriptorPtr& replacement);
251 void resetDescriptor(
const DescriptorPtr& replacement,
const bool allowMismatchingDescriptors =
false);
254 void read(std::istream&);
257 void write(std::ostream&,
bool outputTransient =
false)
const;
260 void readDescriptor(std::istream&);
263 void writeDescriptor(std::ostream&,
bool outputTransient =
false)
const;
266 void readMetadata(std::istream&);
270 void writeMetadata(std::ostream&,
bool outputTransient =
false,
bool paged =
false)
const;
273 void readAttributes(std::istream&);
276 void writeAttributes(std::ostream&,
bool outputTransient =
false)
const;
284 using AttrArrayVec = std::vector<AttributeArray::Ptr>;
286 DescriptorPtr mDescr;
298 std::vector<std::shared_ptr<Element>> mElements;
313 using Ptr = std::shared_ptr<Descriptor>;
325 vec.push_back(nameAndType);
return *
this;
328 vec.emplace_back(name, type);
return *
this;
331 for (NameAndTypeVec::const_iterator it = other.begin(), itEnd = other.end(); it != itEnd; ++it) {
332 vec.emplace_back(it->name, it->type);
343 Descriptor(
const Descriptor&);
352 Ptr duplicateDrop(
const std::vector<size_t>& pos)
const;
355 size_t size()
const {
return mTypes.size(); }
361 size_t memUsage()
const;
365 size_t find(
const std::string&
name)
const;
368 size_t rename(
const std::string& fromName,
const std::string& toName);
371 const Name& valueType(
size_t pos)
const;
377 const MetaMap& getMetadata()
const;
380 bool hasDefaultValue(
const Name&
name)
const;
382 template<
typename ValueType>
385 const size_t pos =
find(name);
386 if (pos == INVALID_POS) {
387 OPENVDB_THROW(LookupError,
"Cannot find attribute name to set default value.")
390 std::stringstream ss;
391 ss <<
"default:" << name;
395 if (metadata)
return metadata->
value();
397 return zeroVal<ValueType>();
402 void removeDefaultValue(
const Name&
name);
404 void pruneUnusedDefaultValues();
412 bool hasSameAttributes(
const Descriptor& rhs)
const;
420 bool hasGroup(
const Name& group)
const;
426 const bool checkValidOffset =
false);
432 size_t renameGroup(
const std::string& fromName,
const std::string& toName);
443 size_t groupOffset(
const Name& groupName)
const;
444 size_t groupOffset(
const GroupIndex&
index)
const;
448 GroupIndex groupIndex(
const Name& groupName)
const;
451 GroupIndex groupIndex(
const size_t offset)
const;
458 size_t availableGroups()
const;
462 size_t unusedGroups()
const;
465 bool canCompactGroups()
const;
478 bool requiresGroupMove(
Name& sourceName,
size_t& sourceOffset,
size_t& targetOffset)
const;
484 bool groupIndexCollision(
const Descriptor& rhs)
const;
490 static bool validName(
const Name&
name);
498 static void parseNames( std::vector<std::string>& includeNames,
499 std::vector<std::string>& excludeNames,
501 const std::string& nameStr);
505 static void parseNames( std::vector<std::string>& includeNames,
506 std::vector<std::string>& excludeNames,
507 const std::string& nameStr);
510 void write(std::ostream&)
const;
512 void read(std::istream&);
516 void appendTo(NameAndTypeVec& attrs)
const;
520 static Ptr create(
const NameAndTypeVec&,
const NameToPosMap&,
const MetaMap&);
525 friend class ::TestAttributeSet;
528 std::vector<NamePair> mTypes;
535 int64_t mReserved[5];
542 #endif // OPENVDB_POINTS_ATTRIBUTE_ARRAY_HAS_BEEN_INCLUDED
Util::NameAndTypeVec NameAndTypeVec
ValueType getDefaultValue(const Name &name) const
Get a default value for an existing attribute.
Descriptor & descriptor()
Return a reference to this attribute set's descriptor, which might be shared with other sets...
std::shared_ptr< Descriptor > DescriptorPtr
Attribute and type name pair.
const Descriptor & descriptor() const
Return a reference to this attribute set's descriptor, which might be shared with other sets...
GLdouble GLdouble GLint GLint const GLdouble * points
Inserter & add(const NameAndTypeVec &other)
bool operator!=(const Descriptor &rhs) const
Return true if this descriptor is not equal to the given one.
Util::NameToPosMap NameToPosMap
std::shared_ptr< AttributeSet > Ptr
#define OPENVDB_USE_VERSION_NAMESPACE
std::shared_ptr< const AttributeSet > ConstPtr
FMT_CONSTEXPR auto find(Ptr first, Ptr last, T value, Ptr &out) -> bool
bool operator!=(const AttributeSet &other) const
OIIO_FORCEINLINE vbool4 insert(const vbool4 &a, bool val)
Helper: substitute val for a[i].
Utility method to construct a NameAndType sequence.
void renameAttributes(PointDataTreeT &tree, const std::vector< Name > &oldNames, const std::vector< Name > &newNames)
Rename attributes in a VDB tree.
void dropGroup(PointDataTreeT &tree, const Name &group, const bool compact)
Drops an existing group from the VDB tree.
bool operator==(const BaseDimensions< T > &a, const BaseDimensions< Y > &b)
void appendAttribute(PointDataTreeT &tree, const Name &name, const NamePair &type, const Index strideOrTotalSize, const bool constantStride, const Metadata *defaultValue, const bool hidden, const bool transient)
Appends a new attribute to the VDB tree (this method does not require a templated AttributeType) ...
GLint GLint GLsizei GLint GLenum GLenum type
Base class for storing attribute data.
std::string OIIO_UTIL_API replace(string_view str, string_view pattern, string_view replacement, bool global=false)
GLint GLenum GLboolean GLsizei stride
std::shared_ptr< const Descriptor > DescriptorConstPtr
std::shared_ptr< AttributeArray > Ptr
void dropAttributes(PointDataTreeT &tree, const std::vector< size_t > &indices)
Drops attributes from the VDB tree.
const NameToPosMap & groupMap() const
Return a reference to the name-to-position group map.
GLuint const GLchar * name
NameAndType(const std::string &n, const NamePair &t, const Index s=1)
std::pair< Name, Name > NamePair
std::map< std::string, size_t > NameToPosMap
Inserter & add(const NameAndType &nameAndType)
Element(ElementPtr parent, const string &category, const string &name)
void setGroup(PointDataTreeT &tree, const PointIndexTreeT &indexTree, const std::vector< short > &membership, const Name &group, const bool remove)
Sets group membership from a PointIndexTree-ordered vector.
std::unique_ptr< AttributeSet > UniquePtr
Library and file format version numbers.
OIIO_UTIL_API bool rename(string_view from, string_view to, std::string &err)
LeafData & operator=(const LeafData &)=delete
std::vector< NameAndType > NameAndTypeVec
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
size_t size() const
Return the number of attributes in this set.
Ordered collection of uniquely-named attribute arrays.
Inserter & add(const Name &name, const NamePair &type)
Util::GroupIndex GroupIndex
std::pair< size_t, uint8_t > GroupIndex
static size_t groupBits()
Return number of bits occupied by a group attribute array.
Attribute Array storage templated on type and compression codec.
NameToPosMap::const_iterator ConstIterator
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
DescriptorPtr descriptorPtr() const
Return a pointer to this attribute set's descriptor, which might be shared with other sets...
#define OPENVDB_THROW(exception, message)
const NameToPosMap & map() const
Return a reference to the name-to-position map.