Loading...
Searching...
No Matches
AttributeGroup.h
Go to the documentation of this file.
// Copyright Contributors to the OpenVDB Project
// SPDX-License-Identifier: MPL-2.0
/// @file points/AttributeGroup.h
///
/// @author Dan Bailey
///
/// @brief Attribute Group access and filtering for iteration.
#ifndef OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
#define OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
#include "AttributeArray.h"
#include "AttributeSet.h"
#include <memory>
namespace openvdb {
OPENVDB_USE_VERSION_NAMESPACE
namespace OPENVDB_VERSION_NAME {
namespace points {
////////////////////////////////////////
struct GroupCodec
{
using StorageType = GroupType;
using ValueType = GroupType;
template <typename T>
struct Storage { using Type = StorageType; };
static void decode(const StorageType&, ValueType&);
static void encode(const ValueType&, StorageType&);
static const char* name() { return "grp"; }
};
using GroupAttributeArray = TypedAttributeArray<GroupType, GroupCodec>;
////////////////////////////////////////
inline void
GroupCodec::decode(const StorageType& data, ValueType& val)
{
val = data;
}
inline void
GroupCodec::encode(const ValueType& val, StorageType& data)
{
data = val;
}
////////////////////////////////////////
inline bool isGroup(const AttributeArray& array)
{
return array.isType<GroupAttributeArray>();
}
////////////////////////////////////////
class OPENVDB_API GroupHandle
{
public:
using Ptr = std::shared_ptr<GroupHandle>;
using UniquePtr = std::unique_ptr<GroupHandle>;
// Dummy class that distinguishes an offset from a bitmask on construction
struct BitMask { };
using GroupIndex = std::pair<Index, uint8_t>;
GroupHandle(const GroupAttributeArray& array, const GroupType& offset);
GroupHandle(const GroupAttributeArray& array, const GroupType& bitMask, BitMask);
Index size() const { return mArray.size(); }
bool isUniform() const { return mArray.isUniform(); }
bool get(Index n) const;
bool getUnsafe(Index n) const;
protected:
const GroupAttributeArray& mArray;
const GroupType mBitMask;
}; // class GroupHandle
////////////////////////////////////////
class OPENVDB_API GroupWriteHandle : public GroupHandle
{
public:
using Ptr = std::shared_ptr<GroupWriteHandle>;
using UniquePtr = std::unique_ptr<GroupWriteHandle>;
GroupWriteHandle(GroupAttributeArray& array, const GroupType& offset);
/// Set @a on at the given index @a n
void set(Index n, bool on);
/// Set @a on at the given index @a n (assumes in-core and non-uniform)
void setUnsafe(Index n, bool on);
/// @brief Set membership for the whole array and attempt to collapse
///
/// @param on True or false for inclusion in group
///
/// @note This method guarantees that all attributes will have group membership
/// changed according to the input bool, however compaction will not be performed
/// if other groups that share the same underlying array are non-uniform.
/// The return value indicates if the group array ends up being uniform.
bool collapse(bool on);
/// Compact the existing array to become uniform if all values are identical
bool compact();
}; // class GroupWriteHandle
////////////////////////////////////////
/// Index filtering on group membership
class GroupFilter
{
public:
GroupFilter(const Name& name, const AttributeSet& attributeSet)
: mIndex(attributeSet.groupIndex(name)) { }
explicit GroupFilter(const AttributeSet::Descriptor::GroupIndex& index)
: mIndex(index) { }
inline bool initialized() const { return bool(mHandle); }
static index::State state() { return index::PARTIAL; }
template <typename LeafT>
static index::State state(const LeafT&) { return index::PARTIAL; }
template <typename LeafT>
void reset(const LeafT& leaf) {
mHandle.reset(new GroupHandle(leaf.groupHandle(mIndex)));
}
template <typename IterT>
bool valid(const IterT& iter) const {
assert(mHandle);
return mHandle->getUnsafe(*iter);
}
private:
const AttributeSet::Descriptor::GroupIndex mIndex;
GroupHandle::Ptr mHandle;
}; // class GroupFilter
////////////////////////////////////////
} // namespace points
} // namespace OPENVDB_VERSION_NAME
} // namespace openvdb
#endif // OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
AttributeArray.h
Attribute Array storage templated on type and compression codec.
AttributeSet.h
Set of Attribute Arrays which tracks metadata about each array.
OPENVDB_API
#define OPENVDB_API
Definition Platform.h:251
openvdb::v10_0::points::AttributeArray
Base class for storing attribute data.
Definition AttributeArray.h:93
openvdb::v10_0::points::AttributeArray::isType
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition AttributeArray.h:224
openvdb::v10_0::points::AttributeSet::Descriptor::GroupIndex
Util::GroupIndex GroupIndex
Definition AttributeSet.h:318
openvdb::v10_0::points::AttributeSet
Ordered collection of uniquely-named attribute arrays.
Definition AttributeSet.h:39
openvdb::v10_0::points::GroupFilter::reset
void reset(const LeafT &leaf)
Definition AttributeGroup.h:150
openvdb::v10_0::points::GroupFilter::state
static index::State state()
Definition AttributeGroup.h:145
openvdb::v10_0::points::GroupFilter::state
static index::State state(const LeafT &)
Definition AttributeGroup.h:147
openvdb::v10_0::points::GroupFilter::GroupFilter
GroupFilter(const Name &name, const AttributeSet &attributeSet)
Definition AttributeGroup.h:137
openvdb::v10_0::points::GroupFilter::GroupFilter
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
Definition AttributeGroup.h:140
openvdb::v10_0::points::GroupFilter::valid
bool valid(const IterT &iter) const
Definition AttributeGroup.h:155
openvdb::v10_0::points::GroupFilter::initialized
bool initialized() const
Definition AttributeGroup.h:143
openvdb::v10_0::points::GroupHandle
Definition AttributeGroup.h:73
openvdb::v10_0::points::GroupHandle::size
Index size() const
Definition AttributeGroup.h:86
openvdb::v10_0::points::GroupHandle::get
bool get(Index n) const
openvdb::v10_0::points::GroupHandle::UniquePtr
std::unique_ptr< GroupHandle > UniquePtr
Definition AttributeGroup.h:76
openvdb::v10_0::points::GroupHandle::mArray
const GroupAttributeArray & mArray
Definition AttributeGroup.h:93
openvdb::v10_0::points::GroupHandle::GroupHandle
GroupHandle(const GroupAttributeArray &array, const GroupType &bitMask, BitMask)
openvdb::v10_0::points::GroupHandle::mBitMask
const GroupType mBitMask
Definition AttributeGroup.h:94
openvdb::v10_0::points::GroupHandle::GroupHandle
GroupHandle(const GroupAttributeArray &array, const GroupType &offset)
openvdb::v10_0::points::GroupHandle::GroupIndex
std::pair< Index, uint8_t > GroupIndex
Definition AttributeGroup.h:81
openvdb::v10_0::points::GroupHandle::Ptr
std::shared_ptr< GroupHandle > Ptr
Definition AttributeGroup.h:75
openvdb::v10_0::points::GroupHandle::getUnsafe
bool getUnsafe(Index n) const
openvdb::v10_0::points::GroupHandle::isUniform
bool isUniform() const
Definition AttributeGroup.h:87
openvdb::v10_0::points::GroupWriteHandle::compact
bool compact()
Compact the existing array to become uniform if all values are identical.
openvdb::v10_0::points::GroupWriteHandle::GroupWriteHandle
GroupWriteHandle(GroupAttributeArray &array, const GroupType &offset)
openvdb::v10_0::points::GroupWriteHandle::collapse
bool collapse(bool on)
Set membership for the whole array and attempt to collapse.
openvdb::v10_0::points::GroupWriteHandle::UniquePtr
std::unique_ptr< GroupWriteHandle > UniquePtr
Definition AttributeGroup.h:105
openvdb::v10_0::points::GroupWriteHandle::set
void set(Index n, bool on)
Set on at the given index n.
openvdb::v10_0::points::GroupWriteHandle::setUnsafe
void setUnsafe(Index n, bool on)
Set on at the given index n (assumes in-core and non-uniform).
openvdb::v10_0::points::GroupWriteHandle::Ptr
std::shared_ptr< GroupWriteHandle > Ptr
Definition AttributeGroup.h:104
openvdb::v10_0::points::TypedAttributeArray
Typed class for storing attribute data.
Definition AttributeArray.h:545
openvdb::v10_0::points::index
Definition IndexIterator.h:34
openvdb::v10_0::points::index::State
State
Definition IndexIterator.h:40
openvdb::v10_0::points::index::PARTIAL
@ PARTIAL
Definition IndexIterator.h:41
openvdb::v10_0::points::GroupType
uint8_t GroupType
Definition AttributeSet.h:31
openvdb::v10_0::points::isGroup
bool isGroup(const AttributeArray &array)
Definition AttributeGroup.h:63
openvdb::v10_0::points::GroupAttributeArray
TypedAttributeArray< GroupType, GroupCodec > GroupAttributeArray
Definition AttributeGroup.h:40
openvdb::v10_0::Name
std::string Name
Definition Name.h:17
openvdb::v10_0::Index
Index32 Index
Definition Types.h:54
openvdb
Definition Exceptions.h:13
openvdb::v10_0::points::GroupCodec::Storage
Definition AttributeGroup.h:32
openvdb::v10_0::points::GroupCodec::Storage::Type
StorageType Type
Definition AttributeGroup.h:32
openvdb::v10_0::points::GroupCodec
Definition AttributeGroup.h:27
openvdb::v10_0::points::GroupCodec::name
static const char * name()
Definition AttributeGroup.h:36
openvdb::v10_0::points::GroupCodec::StorageType
GroupType StorageType
Definition AttributeGroup.h:28
openvdb::v10_0::points::GroupCodec::ValueType
GroupType ValueType
Definition AttributeGroup.h:29
openvdb::v10_0::points::GroupCodec::decode
static void decode(const StorageType &, ValueType &)
Definition AttributeGroup.h:47
openvdb::v10_0::points::GroupCodec::encode
static void encode(const ValueType &, StorageType &)
Definition AttributeGroup.h:54
openvdb::v10_0::points::GroupHandle::BitMask
Definition AttributeGroup.h:79
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:212