OpenVDB: AttributeGroup.h Source File

OpenVDB 5.0.0

AttributeGroup.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2017 DreamWorks Animation LLC
4 //
5 // All rights reserved. This software is distributed under the
6 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
7 //
8 // Redistributions of source code must retain the above copyright
9 // and license notice and the following restrictions and disclaimer.
10 //
11 // * Neither the name of DreamWorks Animation nor the names of
12 // its contributors may be used to endorse or promote products derived
13 // from this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 // IN NO EVENT SHALL THE COPYRIGHT HOLDERS' AND CONTRIBUTORS' AGGREGATE
27 // LIABILITY FOR ALL CLAIMS REGARDLESS OF THEIR BASIS EXCEED US$250.00.
28 //
30
36
37 #ifndef OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
39
40 #include "AttributeArray.h"
41 #include "AttributeSet.h"
42 #include <memory>
43
44 namespace openvdb {
45 OPENVDB_USE_VERSION_NAMESPACE
46 namespace OPENVDB_VERSION_NAME {
47 namespace points {
48
49
50 using GroupType = uint8_t;
51
52
54
55
56 struct GroupCodec
57 {
58 using StorageType = GroupType;
59 using ValueType = GroupType;
60
61 template <typename T>
62 struct Storage { using Type = StorageType; };
63
64 static void decode(const StorageType&, ValueType&);
65 static void encode(const ValueType&, StorageType&);
66 static const char* name() { return "grp"; }
67 };
68
69
70 using GroupAttributeArray = TypedAttributeArray<GroupType, GroupCodec>;
71
72
74
75
76 inline void
77 GroupCodec::decode(const StorageType& data, ValueType& val)
78 {
79 val = data;
80 }
81
82
83 inline void
84 GroupCodec::encode(const ValueType& val, StorageType& data)
85 {
86 data = val;
87 }
88
89
91
92
93 inline bool isGroup(const AttributeArray& array)
94 {
95 return array.isType<GroupAttributeArray>();
96 }
97
98
100
101
102 class OPENVDB_API GroupHandle
103 {
104 public:
105 using Ptr = std::shared_ptr<GroupHandle>;
106
107 // Dummy class that distinguishes an offset from a bitmask on construction
108 struct BitMask { };
109
110 using GroupIndex = std::pair<Index, uint8_t>;
111
112 GroupHandle(const GroupAttributeArray& array, const GroupType& offset);
113 GroupHandle(const GroupAttributeArray& array, const GroupType& bitMask, BitMask);
114
115 Index size() const { return mArray.size(); }
116 bool isUniform() const { return mArray.isUniform(); }
117
118 bool get(Index n) const;
119 bool getUnsafe(Index n) const;
120
121 protected:
122 const GroupAttributeArray& mArray;
123 const GroupType mBitMask;
124 }; // class GroupHandle
125
126
128
129
130 class OPENVDB_API GroupWriteHandle : public GroupHandle
131 {
132 public:
133 using Ptr = std::shared_ptr<GroupWriteHandle>;
134
135 GroupWriteHandle(GroupAttributeArray& array, const GroupType& offset);
136
137 void set(Index n, bool on);
138
147 bool collapse(bool on);
148
150 bool compact();
151
152 }; // class GroupWriteHandle
153
154
156
157
159 class GroupFilter
160 {
161 public:
162 GroupFilter(const Name& name, const AttributeSet& attributeSet)
163 : mIndex(attributeSet.groupIndex(name)) { }
164
165 explicit GroupFilter(const AttributeSet::Descriptor::GroupIndex& index)
166 : mIndex(index) { }
167
168 inline bool initialized() const { return bool(mHandle); }
169
170 template <typename LeafT>
171 void reset(const LeafT& leaf) {
172 mHandle.reset(new GroupHandle(leaf.groupHandle(mIndex)));
173 }
174
175 template <typename IterT>
176 bool valid(const IterT& iter) const {
177 assert(mHandle);
178 return mHandle->getUnsafe(*iter);
179 }
180
181 private:
182 const AttributeSet::Descriptor::GroupIndex mIndex;
183 GroupHandle::Ptr mHandle;
184 }; // class GroupFilter
185
186
188
189
190 } // namespace points
191
192 } // namespace OPENVDB_VERSION_NAME
193 } // namespace openvdb
194
195
196 #endif // OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
197
198 // Copyright (c) 2012-2017 DreamWorks Animation LLC
199 // All rights reserved. This software is distributed under the
200 // Mozilla Public License 2.0 ( http://www.mozilla.org/MPL/2.0/ )
OPENVDB_API
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
openvdb::v5_0::points::GroupHandle::size
Index size() const
Definition: AttributeGroup.h:115
openvdb::v5_0::points::TypedAttributeArray
Typed class for storing attribute data.
Definition: AttributeArray.h:441
openvdb::v5_0::points::GroupWriteHandle
Definition: AttributeGroup.h:130
openvdb::v5_0::points::GroupFilter::GroupFilter
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
Definition: AttributeGroup.h:165
AttributeArray.h
Attribute Array storage templated on type and compression codec.
openvdb::v5_0::points::GroupCodec::Storage::Type
StorageType Type
Definition: AttributeGroup.h:62
openvdb::v5_0::points::GroupHandle
Definition: AttributeGroup.h:102
openvdb::v5_0::points::GroupFilter::valid
bool valid(const IterT &iter) const
Definition: AttributeGroup.h:176
openvdb::v5_0::points::GroupHandle::Ptr
std::shared_ptr< GroupHandle > Ptr
Definition: AttributeGroup.h:105
openvdb::v5_0::points::GroupCodec
Definition: AttributeGroup.h:56
openvdb::v5_0::points::GroupType
uint8_t GroupType
Definition: AttributeGroup.h:50
openvdb::v5_0::points::GroupFilter::initialized
bool initialized() const
Definition: AttributeGroup.h:168
openvdb::v5_0::Index
Index32 Index
Definition: Types.h:60
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
openvdb::v5_0::points::GroupCodec::Storage
Definition: AttributeGroup.h:62
openvdb::v5_0::points::AttributeArray
Base class for storing attribute data.
Definition: AttributeArray.h:118
openvdb::v5_0::points::GroupHandle::mArray
const GroupAttributeArray & mArray
Definition: AttributeGroup.h:122
openvdb
Definition: Exceptions.h:39
openvdb::v5_0::points::GroupCodec::name
static const char * name()
Definition: AttributeGroup.h:66
openvdb::v5_0::points::GroupCodec::StorageType
GroupType StorageType
Definition: AttributeGroup.h:58
openvdb::v5_0::Name
std::string Name
Definition: Name.h:44
openvdb::v5_0::points::GroupCodec::ValueType
GroupType ValueType
Definition: AttributeGroup.h:59
openvdb::v5_0::points::AttributeArray::isType
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:186
openvdb::v5_0::points::GroupFilter::GroupFilter
GroupFilter(const Name &name, const AttributeSet &attributeSet)
Definition: AttributeGroup.h:162
openvdb::v5_0::points::GroupFilter::reset
void reset(const LeafT &leaf)
Definition: AttributeGroup.h:171
openvdb::v5_0::points::GroupFilter
Index filtering on group membership.
Definition: AttributeGroup.h:159
openvdb::v5_0::points::GroupHandle::GroupIndex
std::pair< Index, uint8_t > GroupIndex
Definition: AttributeGroup.h:110
openvdb::v5_0::points::AttributeSet
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
openvdb::v5_0::points::GroupHandle::BitMask
Definition: AttributeGroup.h:108
AttributeSet.h
Set of Attribute Arrays which tracks metadata about each array.
openvdb::v5_0::points::isGroup
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
openvdb::v5_0::points::GroupHandle::isUniform
bool isUniform() const
Definition: AttributeGroup.h:116
openvdb::v5_0::points::GroupHandle::mBitMask
const GroupType mBitMask
Definition: AttributeGroup.h:123