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 {
45 namespace OPENVDB_VERSION_NAME {
46 namespace points {
47 
48 
49 using GroupType = uint8_t;
50 
51 
53 
54 
55 struct GroupCodec
56 {
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 
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 
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:
122 }; // class GroupHandle
123 
124 
126 
127 
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 
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/ )
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:92
bool isUniform() const
Definition: AttributeGroup.h:115
Attribute Array storage templated on type and compression codec.
T * data
Definition: LeafBuffer.h:71
Index filtering on group membership.
Definition: AttributeGroup.h:157
GroupType ValueType
Definition: AttributeGroup.h:58
Index32 Index
Definition: Types.h:57
bool valid(const IterT &iter) const
Definition: AttributeGroup.h:171
Index size() const
Definition: AttributeGroup.h:114
static const char * name()
Definition: AttributeGroup.h:65
std::string Name
Definition: Name.h:44
Definition: AttributeGroup.h:61
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Definition: AttributeGroup.h:55
Definition: Exceptions.h:39
const GroupType mBitMask
Definition: AttributeGroup.h:121
std::pair< Index, uint8_t > GroupIndex
Definition: AttributeGroup.h:109
Typed class for storing attribute data.
Definition: AttributeArray.h:437
GroupFilter(const Name &attribute)
Definition: AttributeGroup.h:160
uint8_t GroupType
Definition: AttributeGroup.h:49
void reset(const LeafT &leaf)
Definition: AttributeGroup.h:166
bool initialized() const
Definition: AttributeGroup.h:163
Definition: AttributeGroup.h:128
const GroupAttributeArray & mArray
Definition: AttributeGroup.h:120
Definition: AttributeGroup.h:107
Base class for storing attribute data.
Definition: AttributeArray.h:118
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Definition: AttributeGroup.h:101
std::shared_ptr< GroupHandle > Ptr
Definition: AttributeGroup.h:104
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:186
GroupType StorageType
Definition: AttributeGroup.h:57
StorageType Type
Definition: AttributeGroup.h:61