OpenVDB: AttributeGroup.h Source File

OpenVDB 4.0.2

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 <memory>
42
43 namespace openvdb {
44 OPENVDB_USE_VERSION_NAMESPACE
45 namespace OPENVDB_VERSION_NAME {
46 namespace points {
47
48
49 using GroupType = uint8_t;
50
51
53
54
55 struct GroupCodec
56 {
57 using StorageType = GroupType;
58 using ValueType = GroupType;
59
60 template <typename T>
61 struct Storage { using Type = StorageType; };
62
63 static void decode(const StorageType&, ValueType&);
64 static void encode(const ValueType&, StorageType&);
65 static const char* name() { return "grp"; }
66 };
67
68
69 using GroupAttributeArray = TypedAttributeArray<GroupType, GroupCodec>;
70
71
73
74
75 inline void
76 GroupCodec::decode(const StorageType& data, ValueType& val)
77 {
78 val = data;
79 }
80
81
82 inline void
83 GroupCodec::encode(const ValueType& val, StorageType& data)
84 {
85 data = val;
86 }
87
88
90
91
92 inline bool isGroup(const AttributeArray& array)
93 {
94 return array.isType<GroupAttributeArray>();
95 }
96
97
99
100
101 class OPENVDB_API GroupHandle
102 {
103 public:
104 using Ptr = std::shared_ptr<GroupHandle>;
105
106 // Dummy class that distinguishes an offset from a bitmask on construction
107 struct BitMask { };
108
109 using GroupIndex = std::pair<Index, uint8_t>;
110
111 GroupHandle(const GroupAttributeArray& array, const GroupType& offset);
112 GroupHandle(const GroupAttributeArray& array, const GroupType& bitMask, BitMask);
113
114 Index size() const { return mArray.size(); }
115 bool isUniform() const { return mArray.isUniform(); }
116
117 bool get(Index n) const;
118
119 protected:
120 const GroupAttributeArray& mArray;
121 const GroupType mBitMask;
122 }; // class GroupHandle
123
124
126
127
128 class OPENVDB_API GroupWriteHandle : public GroupHandle
129 {
130 public:
131 using Ptr = std::shared_ptr<GroupWriteHandle>;
132
133 GroupWriteHandle(GroupAttributeArray& array, const GroupType& offset);
134
135 void set(Index n, bool on);
136
145 bool collapse(bool on);
146
148 bool compact();
149
150 }; // class GroupWriteHandle
151
152
154
155
157 class GroupFilter
158 {
159 public:
160 explicit GroupFilter(const Name& attribute)
161 : mAttribute(attribute) { }
162
163 inline bool initialized() const { return bool(mHandle); }
164
165 template <typename LeafT>
166 void reset(const LeafT& leaf) {
167 mHandle.reset(new GroupHandle(leaf.groupHandle(mAttribute)));
168 }
169
170 template <typename IterT>
171 bool valid(const IterT& iter) const {
172 assert(mHandle);
173 return mHandle->get(*iter);
174 }
175
176 private:
177 const Name mAttribute;
178 GroupHandle::Ptr mHandle;
179 }; // class GroupFilter
180
181
183
184
185 } // namespace points
186
187 } // namespace OPENVDB_VERSION_NAME
188 } // namespace openvdb
189
190
191 #endif // OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
192
193 // Copyright (c) 2012-2017 DreamWorks Animation LLC
194 // All rights reserved. This software is distributed under the
195 // 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::v4_0_2::points::isGroup
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:92
openvdb::v4_0_2::points::GroupHandle::isUniform
bool isUniform() const
Definition: AttributeGroup.h:115
AttributeArray.h
Attribute Array storage templated on type and compression codec.
data
T * data
Definition: LeafBuffer.h:71
openvdb::v4_0_2::points::GroupFilter
Index filtering on group membership.
Definition: AttributeGroup.h:157
openvdb::v4_0_2::points::GroupCodec::ValueType
GroupType ValueType
Definition: AttributeGroup.h:58
openvdb::v4_0_2::Index
Index32 Index
Definition: Types.h:57
openvdb::v4_0_2::points::GroupFilter::valid
bool valid(const IterT &iter) const
Definition: AttributeGroup.h:171
openvdb::v4_0_2::points::GroupHandle::size
Index size() const
Definition: AttributeGroup.h:114
openvdb::v4_0_2::points::GroupCodec::name
static const char * name()
Definition: AttributeGroup.h:65
openvdb::v4_0_2::Name
std::string Name
Definition: Name.h:44
openvdb::v4_0_2::points::GroupCodec::Storage
Definition: AttributeGroup.h:61
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
Definition: version.h:43
openvdb::v4_0_2::points::GroupCodec
Definition: AttributeGroup.h:55
openvdb
Definition: Exceptions.h:39
openvdb::v4_0_2::points::GroupHandle::mBitMask
const GroupType mBitMask
Definition: AttributeGroup.h:121
openvdb::v4_0_2::points::GroupHandle::GroupIndex
std::pair< Index, uint8_t > GroupIndex
Definition: AttributeGroup.h:109
openvdb::v4_0_2::points::TypedAttributeArray
Typed class for storing attribute data.
Definition: AttributeArray.h:437
openvdb::v4_0_2::points::GroupFilter::GroupFilter
GroupFilter(const Name &attribute)
Definition: AttributeGroup.h:160
openvdb::v4_0_2::points::GroupType
uint8_t GroupType
Definition: AttributeGroup.h:49
openvdb::v4_0_2::points::GroupFilter::reset
void reset(const LeafT &leaf)
Definition: AttributeGroup.h:166
openvdb::v4_0_2::points::GroupFilter::initialized
bool initialized() const
Definition: AttributeGroup.h:163
openvdb::v4_0_2::points::GroupWriteHandle
Definition: AttributeGroup.h:128
openvdb::v4_0_2::points::GroupHandle::mArray
const GroupAttributeArray & mArray
Definition: AttributeGroup.h:120
openvdb::v4_0_2::points::GroupHandle::BitMask
Definition: AttributeGroup.h:107
openvdb::v4_0_2::points::AttributeArray
Base class for storing attribute data.
Definition: AttributeArray.h:118
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
openvdb::v4_0_2::points::GroupHandle
Definition: AttributeGroup.h:101
openvdb::v4_0_2::points::GroupHandle::Ptr
std::shared_ptr< GroupHandle > Ptr
Definition: AttributeGroup.h:104
openvdb::v4_0_2::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::v4_0_2::points::GroupCodec::StorageType
GroupType StorageType
Definition: AttributeGroup.h:57
openvdb::v4_0_2::points::GroupCodec::Storage::Type
StorageType Type
Definition: AttributeGroup.h:61