HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AttributeGroup.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 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 //
29 ///////////////////////////////////////////////////////////////////////////
30 
31 /// @file points/AttributeGroup.h
32 ///
33 /// @author Dan Bailey
34 ///
35 /// @brief Attribute Group access and filtering for iteration.
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 
53 ////////////////////////////////////////
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 
73 ////////////////////////////////////////
74 
75 
76 inline void
78 {
79  val = data;
80 }
81 
82 
83 inline void
85 {
86  data = val;
87 }
88 
89 
90 ////////////////////////////////////////
91 
92 
93 inline bool isGroup(const AttributeArray& array)
94 {
95  return array.isType<GroupAttributeArray>();
96 }
97 
98 
99 ////////////////////////////////////////
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 
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 
127 ////////////////////////////////////////
128 
129 
131 {
132 public:
133  using Ptr = std::shared_ptr<GroupWriteHandle>;
134 
136 
137  void set(Index n, bool on);
138 
139  /// @brief Set membership for the whole array and attempt to collapse
140  ///
141  /// @param on True or false for inclusion in group
142  ///
143  /// @note This method guarantees that all attributes will have group membership
144  /// changed according to the input bool, however compaction will not be performed
145  /// if other groups that share the same underlying array are non-uniform.
146  /// The return value indicates if the group array ends up being uniform.
147  bool collapse(bool on);
148 
149  /// Compact the existing array to become uniform if all values are identical
150  bool compact();
151 
152 }; // class GroupWriteHandle
153 
154 
155 ////////////////////////////////////////
156 
157 
158 /// Index filtering on group membership
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 
191 ////////////////////////////////////////
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) 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/ )
Definition: ImfName.h:53
GLuint const GLchar * name
Definition: glew.h:1814
static void encode(const ValueType &, StorageType &)
GLuint index
Definition: glew.h:1814
GLuint const GLfloat * val
Definition: glew.h:2794
static index::State state(const LeafT &)
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:200
bool isGroup(const AttributeArray &array)
Base class for storing attribute data.
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:288
GroupFilter(const AttributeSet::Descriptor::GroupIndex &index)
GLint GLenum GLsizei GLint GLsizei const void * data
Definition: glew.h:1379
GLsizei n
Definition: glew.h:4040
Index filtering on group membership.
Typed class for storing attribute data.
Set of Attribute Arrays which tracks metadata about each array.
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3446
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
GLenum array
Definition: glew.h:9066
Attribute Array storage templated on type and compression codec.
bool isType() const
Return true if this attribute is of the same type as the template parameter.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:146
GroupFilter(const Name &name, const AttributeSet &attributeSet)
static void decode(const StorageType &, ValueType &)
GLintptr offset
Definition: glew.h:1682