OpenVDB 7.0.0

AttributeGroup.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3
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 <memory>
16
17 namespace openvdb {
18 OPENVDB_USE_VERSION_NAMESPACE
19 namespace OPENVDB_VERSION_NAME {
20 namespace points {
21
22
23 using GroupType = uint8_t;
24
25
27
28
29 struct GroupCodec
30 {
31 using StorageType = GroupType;
32 using ValueType = GroupType;
33
34 template <typename T>
35 struct Storage { using Type = StorageType; };
36
37 static void decode(const StorageType&, ValueType&);
38 static void encode(const ValueType&, StorageType&);
39 static const char* name() { return "grp"; }
40 };
41
42
43 using GroupAttributeArray = TypedAttributeArray<GroupType, GroupCodec>;
44
45
47
48
49 inline void
50 GroupCodec::decode(const StorageType& data, ValueType& val)
51 {
52 val = data;
53 }
54
55
56 inline void
57 GroupCodec::encode(const ValueType& val, StorageType& data)
58 {
59 data = val;
60 }
61
62
64
65
66 inline bool isGroup(const AttributeArray& array)
67 {
68 return array.isType<GroupAttributeArray>();
69 }
70
71
73
74
75 class OPENVDB_API GroupHandle
76 {
77 public:
78 using Ptr = std::shared_ptr<GroupHandle>;
79
80 // Dummy class that distinguishes an offset from a bitmask on construction
81 struct BitMask { };
82
83 using GroupIndex = std::pair<Index, uint8_t>;
84
85 GroupHandle(const GroupAttributeArray& array, const GroupType& offset);
86 GroupHandle(const GroupAttributeArray& array, const GroupType& bitMask, BitMask);
87
88 Index size() const { return mArray.size(); }
89 bool isUniform() const { return mArray.isUniform(); }
90
91 bool get(Index n) const;
92 bool getUnsafe(Index n) const;
93
94 protected:
95 const GroupAttributeArray& mArray;
96 const GroupType mBitMask;
97 }; // class GroupHandle
98
99
101
102
103 class OPENVDB_API GroupWriteHandle : public GroupHandle
104 {
105 public:
106 using Ptr = std::shared_ptr<GroupWriteHandle>;
107
108 GroupWriteHandle(GroupAttributeArray& array, const GroupType& offset);
109
110 void set(Index n, bool on);
111
120 bool collapse(bool on);
121
123 bool compact();
124
125 }; // class GroupWriteHandle
126
127
129
130
132 class GroupFilter
133 {
134 public:
135 GroupFilter(const Name& name, const AttributeSet& attributeSet)
136 : mIndex(attributeSet.groupIndex(name)) { }
137
138 explicit GroupFilter(const AttributeSet::Descriptor::GroupIndex& index)
139 : mIndex(index) { }
140
141 inline bool initialized() const { return bool(mHandle); }
142
143 static index::State state() { return index::PARTIAL; }
144 template <typename LeafT>
145 static index::State state(const LeafT&) { return index::PARTIAL; }
146
147 template <typename LeafT>
148 void reset(const LeafT& leaf) {
149 mHandle.reset(new GroupHandle(leaf.groupHandle(mIndex)));
150 }
151
152 template <typename IterT>
153 bool valid(const IterT& iter) const {
154 assert(mHandle);
155 return mHandle->getUnsafe(*iter);
156 }
157
158 private:
159 const AttributeSet::Descriptor::GroupIndex mIndex;
160 GroupHandle::Ptr mHandle;
161 }; // class GroupFilter
162
163
165
166
167 } // namespace points
168
169 } // namespace OPENVDB_VERSION_NAME
170 } // namespace openvdb
171
172
173 #endif // OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
openvdb::v7_0::points::GroupCodec::Storage::Type
StorageType Type
Definition: AttributeGroup.h:35
AttributeSet.h
Set of Attribute Arrays which tracks metadata about each array.
openvdb::v7_0::points::GroupCodec::name
static const char * name()
Definition: AttributeGroup.h:39
openvdb::v7_0::points::GroupCodec::ValueType
GroupType ValueType
Definition: AttributeGroup.h:32
openvdb::v7_0::points::GroupHandle::mBitMask
const GroupType mBitMask
Definition: AttributeGroup.h:96
openvdb::v7_0::points::AttributeArray
Base class for storing attribute data.
Definition: AttributeArray.h:92
openvdb::v7_0::points::GroupHandle::BitMask
Definition: AttributeGroup.h:81
openvdb::v7_0::points::GroupHandle::size
Index size() const
Definition: AttributeGroup.h:88
openvdb::v7_0::points::GroupFilter::valid
bool valid(const IterT &iter) const
Definition: AttributeGroup.h:153
openvdb::v7_0::points::GroupHandle::Ptr
std::shared_ptr< GroupHandle > Ptr
Definition: AttributeGroup.h:78
openvdb::v7_0::points::GroupFilter::state
static index::State state()
Definition: AttributeGroup.h:143
openvdb::v7_0::points::GroupFilter::GroupFilter
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
Definition: AttributeGroup.h:138
AttributeArray.h
Attribute Array storage templated on type and compression codec.
openvdb::v7_0::points::index::PARTIAL
Definition: IndexIterator.h:41
openvdb::v7_0::points::isGroup
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:66
openvdb::v7_0::points::GroupCodec
Definition: AttributeGroup.h:29
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:230
openvdb::v7_0::points::GroupCodec::Storage
Definition: AttributeGroup.h:35
openvdb::v7_0::points::GroupFilter::state
static index::State state(const LeafT &)
Definition: AttributeGroup.h:145
openvdb::v7_0::points::GroupFilter::initialized
bool initialized() const
Definition: AttributeGroup.h:141
openvdb::v7_0::points::GroupHandle::mArray
const GroupAttributeArray & mArray
Definition: AttributeGroup.h:95
openvdb::v7_0::points::TypedAttributeArray
Typed class for storing attribute data.
Definition: AttributeArray.h:566
openvdb::v7_0::points::GroupHandle
Definition: AttributeGroup.h:75
openvdb::v7_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_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
openvdb::v7_0::points::AttributeSet
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:35
openvdb::v7_0::Index
Index32 Index
Definition: Types.h:31
openvdb::v7_0::Name
std::string Name
Definition: Name.h:17
openvdb::v7_0::points::GroupHandle::GroupIndex
std::pair< Index, uint8_t > GroupIndex
Definition: AttributeGroup.h:83
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
openvdb::v7_0::points::GroupFilter::reset
void reset(const LeafT &leaf)
Definition: AttributeGroup.h:148
openvdb
Definition: Exceptions.h:13
openvdb::v7_0::points::GroupCodec::StorageType
GroupType StorageType
Definition: AttributeGroup.h:31
openvdb::v7_0::points::GroupFilter::GroupFilter
GroupFilter(const Name &name, const AttributeSet &attributeSet)
Definition: AttributeGroup.h:135
openvdb::v7_0::points::GroupType
uint8_t GroupType
Definition: AttributeGroup.h:23
openvdb::v7_0::points::index::State
State
Definition: IndexIterator.h:39
openvdb::v7_0::points::GroupWriteHandle
Definition: AttributeGroup.h:103
openvdb::v7_0::points::GroupFilter
Index filtering on group membership.
Definition: AttributeGroup.h:132
openvdb::v7_0::points::GroupHandle::isUniform
bool isUniform() const
Definition: AttributeGroup.h:89