OpenVDB  6.1.0
AttributeGroup.h
Go to the documentation of this file.
1 //
3 // Copyright (c) 2012-2018 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 {
46 namespace OPENVDB_VERSION_NAME {
47 namespace points {
48 
49 
50 using GroupType = uint8_t;
51 
52 
54 
55 
56 struct GroupCodec
57 {
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 
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 
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:
124 }; // class GroupHandle
125 
126 
128 
129 
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 
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  static index::State state() { return index::PARTIAL; }
171  template <typename LeafT>
172  static index::State state(const LeafT&) { return index::PARTIAL; }
173 
174  template <typename LeafT>
175  void reset(const LeafT& leaf) {
176  mHandle.reset(new GroupHandle(leaf.groupHandle(mIndex)));
177  }
178 
179  template <typename IterT>
180  bool valid(const IterT& iter) const {
181  assert(mHandle);
182  return mHandle->getUnsafe(*iter);
183  }
184 
185 private:
186  const AttributeSet::Descriptor::GroupIndex mIndex;
187  GroupHandle::Ptr mHandle;
188 }; // class GroupFilter
189 
190 
192 
193 
194 } // namespace points
195 
196 } // namespace OPENVDB_VERSION_NAME
197 } // namespace openvdb
198 
199 
200 #endif // OPENVDB_POINTS_ATTRIBUTE_GROUP_HAS_BEEN_INCLUDED
201 
202 // Copyright (c) 2012-2018 DreamWorks Animation LLC
203 // All rights reserved. This software is distributed under the
204 // 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:288
const GroupType mBitMask
Definition: AttributeGroup.h:123
std::shared_ptr< GroupHandle > Ptr
Definition: AttributeGroup.h:105
bool isUniform() const
Definition: AttributeGroup.h:116
Typed class for storing attribute data.
Definition: AttributeArray.h:584
StorageType Type
Definition: AttributeGroup.h:62
Definition: AttributeGroup.h:56
Attribute Array storage templated on type and compression codec.
Definition: AttributeGroup.h:102
const GroupAttributeArray & mArray
Definition: AttributeGroup.h:122
Base class for storing attribute data.
Definition: AttributeArray.h:118
std::string Name
Definition: Name.h:44
Definition: AttributeGroup.h:130
void reset(const LeafT &leaf)
Definition: AttributeGroup.h:175
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:125
static const char * name()
Definition: AttributeGroup.h:66
Index32 Index
Definition: Types.h:61
bool valid(const IterT &iter) const
Definition: AttributeGroup.h:180
Definition: Exceptions.h:40
GroupType StorageType
Definition: AttributeGroup.h:58
bool isGroup(const AttributeArray &array)
Definition: AttributeGroup.h:93
Index size() const
Definition: AttributeGroup.h:115
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
Definition: AttributeGroup.h:165
uint8_t GroupType
Definition: AttributeGroup.h:50
bool isType() const
Return true if this attribute is of the same type as the template parameter.
Definition: AttributeArray.h:259
std::pair< Index, uint8_t > GroupIndex
Definition: AttributeGroup.h:110
Definition: AttributeGroup.h:62
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:177
static index::State state()
Definition: AttributeGroup.h:170
GroupType ValueType
Definition: AttributeGroup.h:59
State
Definition: IndexIterator.h:66
Definition: IndexIterator.h:68
bool initialized() const
Definition: AttributeGroup.h:168
Index filtering on group membership.
Definition: AttributeGroup.h:159
Set of Attribute Arrays which tracks metadata about each array.
static index::State state(const LeafT &)
Definition: AttributeGroup.h:172
Definition: AttributeGroup.h:108
GroupFilter(const Name &name, const AttributeSet &attributeSet)
Definition: AttributeGroup.h:162