HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AttributeGroup.h
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////
2 //
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 //
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 <memory>
42 
43 namespace openvdb {
45 namespace OPENVDB_VERSION_NAME {
46 namespace points {
47 
48 
49 using GroupType = uint8_t;
50 
51 
52 ////////////////////////////////////////
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 
72 ////////////////////////////////////////
73 
74 
75 inline void
77 {
78  val = data;
79 }
80 
81 
82 inline void
84 {
85  data = val;
86 }
87 
88 
89 ////////////////////////////////////////
90 
91 
92 inline bool isGroup(const AttributeArray& array)
93 {
94  return array.isType<GroupAttributeArray>();
95 }
96 
97 
98 ////////////////////////////////////////
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 
125 ////////////////////////////////////////
126 
127 
129 {
130 public:
131  using Ptr = std::shared_ptr<GroupWriteHandle>;
132 
134 
135  void set(Index n, bool on);
136 
137  /// @brief Set membership for the whole array and attempt to collapse
138  ///
139  /// @param on True or false for inclusion in group
140  ///
141  /// @note This method guarantees that all attributes will have group membership
142  /// changed according to the input bool, however compaction will not be performed
143  /// if other groups that share the same underlying array are non-uniform.
144  /// The return value indicates if the group array ends up being uniform.
145  bool collapse(bool on);
146 
147  /// Compact the existing array to become uniform if all values are identical
148  bool compact();
149 
150 }; // class GroupWriteHandle
151 
152 
153 ////////////////////////////////////////
154 
155 
156 /// Index filtering on group membership
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 
182 ////////////////////////////////////////
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/ )
Definition: ImfName.h:53
static void encode(const ValueType &, StorageType &)
bool isGroup(const AttributeArray &array)
GLdouble n
Definition: glcorearb.h:2007
Base class for storing attribute data.
#define OPENVDB_API
Helper macros for defining library symbol visibility.
Definition: Platform.h:194
#define OPENVDB_VERSION_NAME
Definition: version.h:43
GLintptr offset
Definition: glcorearb.h:664
GLboolean * data
Definition: glcorearb.h:130
Index filtering on group membership.
Typed class for storing attribute data.
GLuint GLfloat * val
Definition: glcorearb.h:1607
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
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.
static void decode(const StorageType &, ValueType &)