OpenVDB  8.1.0
PointLeafLocalData.h
Go to the documentation of this file.
1 // Copyright Contributors to the OpenVDB Project
2 // SPDX-License-Identifier: MPL-2.0
3 
10 
11 #ifndef OPENVDB_AX_COMPILER_LEAF_LOCAL_DATA_HAS_BEEN_INCLUDED
12 #define OPENVDB_AX_COMPILER_LEAF_LOCAL_DATA_HAS_BEEN_INCLUDED
13 
14 #include <openvdb/openvdb.h>
15 #include <openvdb/version.h>
20 
21 namespace openvdb {
23 namespace OPENVDB_VERSION_NAME {
24 
25 namespace ax {
26 namespace codegen {
27 
28 namespace codegen_internal {
29 
30 
44 {
45  using UniquePtr = std::unique_ptr<PointLeafLocalData>;
47  using GroupHandleT = openvdb::points::GroupWriteHandle;
48 
49  using PointStringMap = std::map<uint64_t, std::string>;
50  using StringArrayMap = std::map<points::AttributeArray*, PointStringMap>;
51 
52  using LeafNode = openvdb::points::PointDataTree::LeafNodeType;
53 
60  PointLeafLocalData(const size_t count)
61  : mPointCount(count)
62  , mArrays()
63  , mOffset(0)
64  , mHandles()
65  , mStringMap() {}
66 
68 
70 
78  inline GroupHandleT* getOrInsert(const std::string& name)
79  {
80  GroupHandleT* ptr = get(name);
81  if (ptr) return ptr;
82 
83  static const size_t maxGroupsInArray =
84 #if (OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER > 7 || \
85  (OPENVDB_LIBRARY_MAJOR_VERSION_NUMBER >= 7 && \
86  OPENVDB_LIBRARY_MINOR_VERSION_NUMBER >= 1))
87  points::AttributeSet::Descriptor::groupBits();
88 #else
89  // old removed method
90  points::point_group_internal::GroupInfo::groupBits();
91 #endif
92 
93  if (mArrays.empty() || mOffset == maxGroupsInArray) {
94  assert(mPointCount < static_cast<size_t>(std::numeric_limits<openvdb::Index>::max()));
95  mArrays.emplace_back(new GroupArrayT(static_cast<openvdb::Index>(mPointCount)));
96  mOffset = 0;
97  }
98 
99  GroupArrayT* array = mArrays.back().get();
100  assert(array);
101 
102  std::unique_ptr<GroupHandleT>& handle = mHandles[name];
103  handle.reset(new GroupHandleT(*array, mOffset++));
104  return handle.get();
105  }
106 
112  inline GroupHandleT* get(const std::string& name) const
113  {
114  const auto iter = mHandles.find(name);
115  if (iter == mHandles.end()) return nullptr;
116  return iter->second.get();
117  }
118 
123  inline bool hasGroup(const std::string& name) const {
124  return mHandles.find(name) != mHandles.end();
125  }
126 
133  inline void getGroups(std::set<std::string>& groups) const {
134  for (const auto& iter : mHandles) {
135  groups.insert(iter.first);
136  }
137  }
138 
142  inline void compact() {
143  for (auto& array : mArrays) array->compact();
144  }
145 
146 
148 
150 
159  inline bool
160  getNewStringData(const points::AttributeArray* array, const uint64_t idx, std::string& data) const {
161  const auto arrayMapIter = mStringMap.find(const_cast<points::AttributeArray*>(array));
162  if (arrayMapIter == mStringMap.end()) return false;
163  const auto iter = arrayMapIter->second.find(idx);
164  if (iter == arrayMapIter->second.end()) return false;
165  data = iter->second;
166  return true;
167  }
168 
176  inline void
177  setNewStringData(points::AttributeArray* array, const uint64_t idx, const std::string& data) {
178  mStringMap[array][idx] = data;
179  }
180 
187  inline void
188  removeNewStringData(points::AttributeArray* array, const uint64_t idx) {
189  const auto arrayMapIter = mStringMap.find(array);
190  if (arrayMapIter == mStringMap.end()) return;
191  arrayMapIter->second.erase(idx);
192  if (arrayMapIter->second.empty()) mStringMap.erase(arrayMapIter);
193  }
194 
201  inline bool
203  for (const auto& arrayIter : mStringMap) {
204  for (const auto& iter : arrayIter.second) {
205  inserter.insert(iter.second);
206  }
207  }
208  return !mStringMap.empty();
209  }
210 
213  inline const StringArrayMap& getStringArrayMap() const {
214  return mStringMap;
215  }
216 
217 private:
218 
219  const size_t mPointCount;
220  std::vector<std::unique_ptr<GroupArrayT>> mArrays;
221  points::GroupType mOffset;
222  std::map<std::string, std::unique_ptr<GroupHandleT>> mHandles;
223  StringArrayMap mStringMap;
224 };
225 
226 } // codegen_internal
227 
228 } // namespace compiler
229 } // namespace ax
230 } // namespace OPENVDB_VERSION_NAME
231 } // namespace openvdb
232 
233 #endif // OPENVDB_AX_COMPILER_LEAF_LOCAL_DATA_HAS_BEEN_INCLUDED
234 
openvdb::v8_1::points::GroupAttributeArray
TypedAttributeArray< GroupType, GroupCodec > GroupAttributeArray
Definition: AttributeGroup.h:40
OPENVDB_VERSION_NAME
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
OPENVDB_USE_VERSION_NAMESPACE
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:178
PointGroup.h
Point group manipulation in a VDB Point Grid.
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::UniquePtr
std::unique_ptr< PointLeafLocalData > UniquePtr
Definition: PointLeafLocalData.h:45
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::PointLeafLocalData
PointLeafLocalData(const size_t count)
Construct a new data object to keep track of various data objects created per leaf by the point compu...
Definition: PointLeafLocalData.h:60
openvdb::v8_1::points::StringMetaInserter
Class to help with insertion of keyed string values into metadata.
Definition: AttributeArrayString.h:88
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::getNewStringData
bool getNewStringData(const points::AttributeArray *array, const uint64_t idx, std::string &data) const
String methods.
Definition: PointLeafLocalData.h:160
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::getStringArrayMap
const StringArrayMap & getStringArrayMap() const
Returns a const reference to the string array map.
Definition: PointLeafLocalData.h:213
AttributeArray.h
Attribute Array storage templated on type and compression codec.
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::GroupArrayT
openvdb::points::GroupAttributeArray GroupArrayT
Definition: PointLeafLocalData.h:46
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::getGroups
void getGroups(std::set< std::string > &groups) const
Populate a set with all the groups which have been inserted into this object. Used to compute a final...
Definition: PointLeafLocalData.h:133
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::setNewStringData
void setNewStringData(points::AttributeArray *array, const uint64_t idx, const std::string &data)
Set new string data associated with a particular point on a particular string attribute array.
Definition: PointLeafLocalData.h:177
openvdb::v8_1::points::GroupType
uint8_t GroupType
Definition: AttributeSet.h:31
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::removeNewStringData
void removeNewStringData(points::AttributeArray *array, const uint64_t idx)
Remove any new string data associated with a particular point on a particular string attribute array....
Definition: PointLeafLocalData.h:188
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::StringArrayMap
std::map< points::AttributeArray *, PointStringMap > StringArrayMap
Definition: PointLeafLocalData.h:50
openvdb::v8_1::Index
Index32 Index
Definition: openvdb/Types.h:50
PointAttribute.h
Point attribute manipulation in a VDB Point Grid.
openvdb::v8_1::points::AttributeArray
Base class for storing attribute data.
Definition: AttributeArray.h:92
PointDataGrid.h
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::insertNewStrings
bool insertNewStrings(points::StringMetaInserter &inserter) const
Insert all new point strings stored across all collected string attribute arrays into a StringMetaIns...
Definition: PointLeafLocalData.h:202
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::get
GroupHandleT * get(const std::string &name) const
Return a group write handle to a specific group name if it exists. Returns a nullptr if no group exis...
Definition: PointLeafLocalData.h:112
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::GroupHandleT
openvdb::points::GroupWriteHandle GroupHandleT
Definition: PointLeafLocalData.h:47
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::compact
void compact()
Compact all arrays stored on this object. This does not invalidate any active write handles.
Definition: PointLeafLocalData.h:142
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData
Various functions can request the use and initialization of point data from within the kernel that do...
Definition: PointLeafLocalData.h:43
openvdb::v8_1::tools::composite::max
const std::enable_if<!VecTraits< T >::IsVec, T >::type & max(const T &a, const T &b)
Definition: Composite.h:107
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::getOrInsert
GroupHandleT * getOrInsert(const std::string &name)
Group methods.
Definition: PointLeafLocalData.h:78
openvdb
Definition: openvdb/Exceptions.h:13
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::LeafNode
openvdb::points::PointDataTree::LeafNodeType LeafNode
Definition: PointLeafLocalData.h:52
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::hasGroup
bool hasGroup(const std::string &name) const
Return true if a valid group handle exists.
Definition: PointLeafLocalData.h:123
openvdb.h
openvdb::v8_1::points::StringMetaInserter::insert
Index insert(const Name &name, Index hint=Index(0))
Insert the string into the metadata using the hint if non-zero.
openvdb::v8_1::ax::codegen::codegen_internal::PointLeafLocalData::PointStringMap
std::map< uint64_t, std::string > PointStringMap
Definition: PointLeafLocalData.h:49