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