OpenVDB 12.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
18namespace openvdb {
20namespace OPENVDB_VERSION_NAME {
21namespace points {
22
23
24////////////////////////////////////////
25
26
28{
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
42
43
44////////////////////////////////////////
45
46
47inline void
49{
50 val = data;
51}
52
53
54inline void
56{
57 data = val;
58}
59
60
61////////////////////////////////////////
62
63
64inline bool isGroup(const AttributeArray& array)
65{
66 return array.isType<GroupAttributeArray>();
67}
68
69
70////////////////////////////////////////
71
72
74{
75public:
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
93protected:
96}; // class GroupHandle
97
98
99////////////////////////////////////////
100
101
103{
104public:
105 using Ptr = std::shared_ptr<GroupWriteHandle>;
106 using UniquePtr = std::unique_ptr<GroupWriteHandle>;
107
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
136{
137public:
138 GroupFilter(const Name& name, const AttributeSet& attributeSet)
139 : mIndex(attributeSet.groupIndex(name)) { }
140
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
161private:
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
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
Attribute Array storage templated on type and compression codec.
Set of Attribute Arrays which tracks metadata about each array.
#define OPENVDB_API
Definition Platform.h:268
Base class for storing attribute data.
Definition AttributeArray.h:94
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition AttributeArray.h:215
Util::GroupIndex GroupIndex
Definition AttributeSet.h:317
Ordered collection of uniquely-named attribute arrays.
Definition AttributeSet.h:40
void reset(const LeafT &leaf)
Definition AttributeGroup.h:151
static index::State state()
Definition AttributeGroup.h:146
static index::State state(const LeafT &)
Definition AttributeGroup.h:148
GroupFilter(const Name &name, const AttributeSet &attributeSet)
Definition AttributeGroup.h:138
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
Definition AttributeGroup.h:141
bool valid(const IterT &iter) const
Definition AttributeGroup.h:156
bool initialized() const
Definition AttributeGroup.h:144
Definition AttributeGroup.h:74
Index size() const
Definition AttributeGroup.h:87
std::unique_ptr< GroupHandle > UniquePtr
Definition AttributeGroup.h:77
const GroupAttributeArray & mArray
Definition AttributeGroup.h:94
GroupHandle(const GroupAttributeArray &array, const GroupType &bitMask, BitMask)
const GroupType mBitMask
Definition AttributeGroup.h:95
GroupHandle(const GroupAttributeArray &array, const GroupType &offset)
std::pair< Index, uint8_t > GroupIndex
Definition AttributeGroup.h:82
std::shared_ptr< GroupHandle > Ptr
Definition AttributeGroup.h:76
bool isUniform() const
Definition AttributeGroup.h:88
bool compact()
Compact the existing array to become uniform if all values are identical.
GroupWriteHandle(GroupAttributeArray &array, const GroupType &offset)
bool collapse(bool on)
Set membership for the whole array and attempt to collapse.
std::unique_ptr< GroupWriteHandle > UniquePtr
Definition AttributeGroup.h:106
void set(Index n, bool on)
Set on at the given index n.
void setUnsafe(Index n, bool on)
Set on at the given index n (assumes in-core and non-uniform)
std::shared_ptr< GroupWriteHandle > Ptr
Definition AttributeGroup.h:105
Typed class for storing attribute data.
Definition AttributeArray.h:512
Definition IndexIterator.h:35
State
Definition IndexIterator.h:41
@ PARTIAL
Definition IndexIterator.h:42
uint8_t GroupType
Definition AttributeSet.h:32
bool isGroup(const AttributeArray &array)
Definition AttributeGroup.h:64
TypedAttributeArray< GroupType, GroupCodec > GroupAttributeArray
Definition AttributeGroup.h:41
std::string Name
Definition Name.h:19
Index32 Index
Definition Types.h:54
Definition Exceptions.h:13
Definition AttributeGroup.h:33
StorageType Type
Definition AttributeGroup.h:33
Definition AttributeGroup.h:28
static const char * name()
Definition AttributeGroup.h:37
GroupType StorageType
Definition AttributeGroup.h:29
GroupType ValueType
Definition AttributeGroup.h:30
static void decode(const StorageType &, ValueType &)
Definition AttributeGroup.h:48
static void encode(const ValueType &, StorageType &)
Definition AttributeGroup.h:55
Definition AttributeGroup.h:80
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218