OpenVDB 13.0.0

Loading...
Searching...
No Matches
AttributeGroup.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: Apache-2.0
3
4/// @file points/AttributeGroup.h
5///
6/// @author Dan Bailey
7///
8/// @brief Attribute Group access and filtering for iteration.
9
10#ifndef OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
11#define OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
12
13#include "AttributeArray.h"
14#include "AttributeSet.h"
15#include <openvdb/util/Assert.h>
16#include <memory>
17
18 namespace openvdb {
19 OPENVDB_USE_VERSION_NAMESPACE
20 namespace OPENVDB_VERSION_NAME {
21 namespace points {
22
23
24////////////////////////////////////////
25
26
27 struct GroupCodec
28{
29 using StorageType = GroupType;
30 using ValueType = GroupType;
31
32 template <typename T>
33 struct Storage { using Type = StorageType; };
34
35 static void decode(const StorageType&, ValueType&);
36 static void encode(const ValueType&, StorageType&);
37 static const char* name() { return "grp"; }
38};
39
40
41 using GroupAttributeArray = TypedAttributeArray<GroupType, GroupCodec>;
42
43
44////////////////////////////////////////
45
46
47 inline void
48 GroupCodec::decode(const StorageType& data, ValueType& val)
49{
50 val = data;
51}
52
53
54 inline void
55 GroupCodec::encode(const ValueType& val, StorageType& data)
56{
57 data = val;
58}
59
60
61////////////////////////////////////////
62
63
64 inline bool isGroup(const AttributeArray& array)
65{
66 return array.isType<GroupAttributeArray>();
67}
68
69
70////////////////////////////////////////
71
72
73 class OPENVDB_API GroupHandle
74{
75 public:
76 using Ptr = std::shared_ptr<GroupHandle>;
77 using UniquePtr = std::unique_ptr<GroupHandle>;
78
79 // Dummy class that distinguishes an offset from a bitmask on construction
80 struct BitMask { };
81
82 using GroupIndex = std::pair<Index, uint8_t>;
83
84 GroupHandle(const GroupAttributeArray& array, const GroupType& offset);
85 GroupHandle(const GroupAttributeArray& array, const GroupType& bitMask, BitMask);
86
87 Index size() const { return mArray.size(); }
88 bool isUniform() const { return mArray.isUniform(); }
89
90 bool get(Index n) const;
91 bool getUnsafe(Index n) const;
92
93 protected:
94 const GroupAttributeArray& mArray;
95 const GroupType mBitMask;
96}; // class GroupHandle
97
98
99////////////////////////////////////////
100
101
102 class OPENVDB_API GroupWriteHandle : public GroupHandle
103{
104 public:
105 using Ptr = std::shared_ptr<GroupWriteHandle>;
106 using UniquePtr = std::unique_ptr<GroupWriteHandle>;
107
108 GroupWriteHandle(GroupAttributeArray& array, const GroupType& offset);
109
110 /// Set @a on at the given index @a n
111 void set(Index n, bool on);
112 /// Set @a on at the given index @a n (assumes in-core and non-uniform)
113 void setUnsafe(Index n, bool on);
114
115 /// @brief Set membership for the whole array and attempt to collapse
116 ///
117 /// @param on True or false for inclusion in group
118 ///
119 /// @note This method guarantees that all attributes will have group membership
120 /// changed according to the input bool, however compaction will not be performed
121 /// if other groups that share the same underlying array are non-uniform.
122 /// The return value indicates if the group array ends up being uniform.
123 bool collapse(bool on);
124
125 /// Compact the existing array to become uniform if all values are identical
126 bool compact();
127
128}; // class GroupWriteHandle
129
130
131////////////////////////////////////////
132
133
134/// Index filtering on group membership
135 class GroupFilter
136{
137 public:
138 GroupFilter(const Name& name, const AttributeSet& attributeSet)
139 : mIndex(attributeSet.groupIndex(name)) { }
140
141 explicit GroupFilter(const AttributeSet::Descriptor::GroupIndex& index)
142 : mIndex(index) { }
143
144 inline bool initialized() const { return bool(mHandle); }
145
146 static index::State state() { return index::PARTIAL; }
147 template <typename LeafT>
148 static index::State state(const LeafT&) { return index::PARTIAL; }
149
150 template <typename LeafT>
151 void reset(const LeafT& leaf) {
152 mHandle.reset(new GroupHandle(leaf.groupHandle(mIndex)));
153 }
154
155 template <typename IterT>
156 bool valid(const IterT& iter) const {
157 OPENVDB_ASSERT(mHandle);
158 return mHandle->getUnsafe(*iter);
159 }
160
161 private:
162 const AttributeSet::Descriptor::GroupIndex mIndex;
163 GroupHandle::Ptr mHandle;
164}; // class GroupFilter
165
166
167////////////////////////////////////////
168
169
170} // namespace points
171
172} // namespace OPENVDB_VERSION_NAME
173} // namespace openvdb
174
175
176#endif // OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
Assert.h
OPENVDB_ASSERT
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
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:291
openvdb::v13_0::points::AttributeArray
Base class for storing attribute data.
Definition AttributeArray.h:94
openvdb::v13_0::points::AttributeArray::isType
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition AttributeArray.h:215
openvdb::v13_0::points::AttributeSet::Descriptor::GroupIndex
Util::GroupIndex GroupIndex
Definition AttributeSet.h:317
openvdb::v13_0::points::AttributeSet
Ordered collection of uniquely-named attribute arrays.
Definition AttributeSet.h:40
openvdb::v13_0::points::GroupFilter::reset
void reset(const LeafT &leaf)
Definition AttributeGroup.h:151
openvdb::v13_0::points::GroupFilter::state
static index::State state()
Definition AttributeGroup.h:146
openvdb::v13_0::points::GroupFilter::state
static index::State state(const LeafT &)
Definition AttributeGroup.h:148
openvdb::v13_0::points::GroupFilter::GroupFilter
GroupFilter(const Name &name, const AttributeSet &attributeSet)
Definition AttributeGroup.h:138
openvdb::v13_0::points::GroupFilter::GroupFilter
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
Definition AttributeGroup.h:141
openvdb::v13_0::points::GroupFilter::valid
bool valid(const IterT &iter) const
Definition AttributeGroup.h:156
openvdb::v13_0::points::GroupFilter::initialized
bool initialized() const
Definition AttributeGroup.h:144
openvdb::v13_0::points::GroupHandle
Definition AttributeGroup.h:74
openvdb::v13_0::points::GroupHandle::size
Index size() const
Definition AttributeGroup.h:87
openvdb::v13_0::points::GroupHandle::get
bool get(Index n) const
openvdb::v13_0::points::GroupHandle::UniquePtr
std::unique_ptr< GroupHandle > UniquePtr
Definition AttributeGroup.h:77
openvdb::v13_0::points::GroupHandle::mArray
const GroupAttributeArray & mArray
Definition AttributeGroup.h:94
openvdb::v13_0::points::GroupHandle::GroupHandle
GroupHandle(const GroupAttributeArray &array, const GroupType &bitMask, BitMask)
openvdb::v13_0::points::GroupHandle::mBitMask
const GroupType mBitMask
Definition AttributeGroup.h:95
openvdb::v13_0::points::GroupHandle::GroupHandle
GroupHandle(const GroupAttributeArray &array, const GroupType &offset)
openvdb::v13_0::points::GroupHandle::GroupIndex
std::pair< Index, uint8_t > GroupIndex
Definition AttributeGroup.h:82
openvdb::v13_0::points::GroupHandle::Ptr
std::shared_ptr< GroupHandle > Ptr
Definition AttributeGroup.h:76
openvdb::v13_0::points::GroupHandle::getUnsafe
bool getUnsafe(Index n) const
openvdb::v13_0::points::GroupHandle::isUniform
bool isUniform() const
Definition AttributeGroup.h:88
openvdb::v13_0::points::GroupWriteHandle::compact
bool compact()
Compact the existing array to become uniform if all values are identical.
openvdb::v13_0::points::GroupWriteHandle::GroupWriteHandle
GroupWriteHandle(GroupAttributeArray &array, const GroupType &offset)
openvdb::v13_0::points::GroupWriteHandle::collapse
bool collapse(bool on)
Set membership for the whole array and attempt to collapse.
openvdb::v13_0::points::GroupWriteHandle::UniquePtr
std::unique_ptr< GroupWriteHandle > UniquePtr
Definition AttributeGroup.h:106
openvdb::v13_0::points::GroupWriteHandle::set
void set(Index n, bool on)
Set on at the given index n.
openvdb::v13_0::points::GroupWriteHandle::setUnsafe
void setUnsafe(Index n, bool on)
Set on at the given index n (assumes in-core and non-uniform).
openvdb::v13_0::points::GroupWriteHandle::Ptr
std::shared_ptr< GroupWriteHandle > Ptr
Definition AttributeGroup.h:105
openvdb::v13_0::points::TypedAttributeArray
Typed class for storing attribute data.
Definition AttributeArray.h:512
openvdb::v13_0::points::index
Definition IndexIterator.h:35
openvdb::v13_0::points::index::State
State
Definition IndexIterator.h:41
openvdb::v13_0::points::index::PARTIAL
@ PARTIAL
Definition IndexIterator.h:42
openvdb::v13_0::points::GroupType
uint8_t GroupType
Definition AttributeSet.h:32
openvdb::v13_0::points::isGroup
bool isGroup(const AttributeArray &array)
Definition AttributeGroup.h:64
openvdb::v13_0::points::GroupAttributeArray
TypedAttributeArray< GroupType, GroupCodec > GroupAttributeArray
Definition AttributeGroup.h:41
openvdb::v13_0::Name
std::string Name
Definition Name.h:19
openvdb::v13_0::Index
Index32 Index
Definition Types.h:34
openvdb
Definition Exceptions.h:13
openvdb::v13_0::points::GroupCodec::Storage
Definition AttributeGroup.h:33
openvdb::v13_0::points::GroupCodec::Storage::Type
StorageType Type
Definition AttributeGroup.h:33
openvdb::v13_0::points::GroupCodec
Definition AttributeGroup.h:28
openvdb::v13_0::points::GroupCodec::name
static const char * name()
Definition AttributeGroup.h:37
openvdb::v13_0::points::GroupCodec::StorageType
GroupType StorageType
Definition AttributeGroup.h:29
openvdb::v13_0::points::GroupCodec::ValueType
GroupType ValueType
Definition AttributeGroup.h:30
openvdb::v13_0::points::GroupCodec::decode
static void decode(const StorageType &, ValueType &)
Definition AttributeGroup.h:48
openvdb::v13_0::points::GroupCodec::encode
static void encode(const ValueType &, StorageType &)
Definition AttributeGroup.h:55
openvdb::v13_0::points::GroupHandle::BitMask
Definition AttributeGroup.h:80
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:218