37 #ifndef OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 45 #include <openvdb/tree/LeafManager.h> 65 template <
typename Po
intDataTree>
81 template <
typename Po
intDataTree>
89 namespace point_delete_internal {
92 template <
typename Po
intDataTreeT,
typename FilterT>
97 using LeafNodeT =
typename PointDataTreeT::LeafNodeType;
101 : mFilter(filter) { }
105 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf)
108 const size_t size =
iterCount(leaf->beginIndexAll());
109 if (size == 0)
continue;
111 const size_t newSize =
112 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
116 leaf->clearAttributes();
120 const AttributeSet& existingAttributeSet = leaf->attributeSet();
122 existingAttributeSet, static_cast<Index>(newSize));
123 const size_t attributeSetSize = existingAttributeSet.
size();
127 std::vector<AttributeArray*> newAttributeArrays;
128 std::vector<const AttributeArray*> existingAttributeArrays;
130 for (
size_t i = 0; i < attributeSetSize; i++) {
131 newAttributeArrays.push_back(newAttributeSet->
get(i));
132 existingAttributeArrays.push_back(existingAttributeSet.
getConst(i));
135 typename ValueType::IntType attributeIndex = 0;
136 std::vector<ValueType> endOffsets;
138 endOffsets.reserve(LeafNodeT::NUM_VALUES);
142 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
143 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter); iter; ++iter) {
144 for (
size_t i = 0; i < attributeSetSize; i++) {
145 newAttributeArrays[i]->set(static_cast<Index>(attributeIndex),
146 *(existingAttributeArrays[i]), *iter);
150 endOffsets.push_back(
ValueType(attributeIndex));
153 leaf->replaceAttributeSet(newAttributeSet);
154 leaf->setOffsets(endOffsets);
159 const FilterT& mFilter;
168 template <
typename Po
intDataTreeT>
169 inline void deleteFromGroups(PointDataTreeT& pointTree,
const std::vector<std::string>& groups,
172 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
174 if (!leafIter)
return;
176 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
177 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
178 std::vector<std::string> availableGroups;
183 for (
const auto& groupName : groups) {
184 if (descriptor.hasGroup(groupName)) {
185 availableGroups.push_back(groupName);
189 if (availableGroups.empty())
return;
191 std::vector<std::string> empty;
192 std::unique_ptr<MultiGroupFilter> filter;
194 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
197 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
202 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
211 template <
typename Po
intDataTreeT>
212 inline void deleteFromGroup(PointDataTreeT& pointTree,
const std::string& group,
bool invert)
214 std::vector<std::string> groups(1, group);
224 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED typename PointDataTreeT::LeafNodeType LeafNodeT
Definition: PointDelete.h:97
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
void deleteFromGroups(PointDataTreeT &pointTree, const std::vector< std::string > &groups, bool invert)
Definition: PointDelete.h:169
typename LeafNodeT::ValueType ValueType
Definition: PointDelete.h:98
Definition: PointDelete.h:93
Definition: LeafManager.h:127
Point group manipulation in a VDB Point Grid.
Index filters primarily designed to be used with a FilterIndexIter.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
const AttributeArray * getConst(const std::string &name) const
Return a pointer to the attribute array whose name is name or a null pointer if no match is found...
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
Definition: Exceptions.h:39
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
Definition: IndexFilter.h:104
void deleteFromGroup(PointDataTreeT &pointTree, const std::string &group, bool invert)
Definition: PointDelete.h:212
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
void operator()(const LeafRangeT &range) const
Definition: PointDelete.h:103
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:130
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
void dropGroups(PointDataTree &tree, const std::vector< Name > &groups)
Drops existing groups from the VDB tree, the tree is compacted after dropping.
Definition: PointGroup.h:568
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
DeleteByFilterOp(const FilterT &filter)
Definition: PointDelete.h:100
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointDelete.h:96
const AttributeArray * get(const std::string &name) const
Return a pointer to the attribute array whose name is name or a null pointer if no match is found...
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 > >> PointDataTree
Point index tree configured to match the default VDB configurations.
Definition: PointDataGrid.h:216