9 #ifndef OPENVDB_POINTS_POINT_DELETE_IMPL_HAS_BEEN_INCLUDED
10 #define OPENVDB_POINTS_POINT_DELETE_IMPL_HAS_BEEN_INCLUDED
19 namespace point_delete_internal {
23 using T = std::vector<std::pair<Index, Index>>;
25 VectorWrapper(
const T& _data) :
data(_data) { }
26 operator bool()
const {
return index <
data.size(); }
27 VectorWrapper& operator++() {
index++;
return *
this; }
28 Index sourceIndex()
const { assert(*
this);
return data[
index].first; }
29 Index targetIndex()
const { assert(*
this);
return data[
index].second; }
33 T::size_type
index = 0;
37 template <
typename Po
intDataTreeT,
typename FilterT>
38 struct DeleteByFilterOp
40 using LeafManagerT = tree::LeafManager<PointDataTreeT>;
41 using LeafRangeT =
typename LeafManagerT::LeafRange;
42 using LeafNodeT =
typename PointDataTreeT::LeafNodeType;
45 DeleteByFilterOp(
const FilterT&
filter,
46 const AttributeArray::ScopedRegistryLock* lock)
50 void operator()(
const LeafRangeT&
range)
const
52 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf) {
54 const size_t newSize =
55 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
59 leaf->clearAttributes(
true, mLock);
65 const size_t currentSize = leaf->getLastValue();
66 if (newSize == currentSize)
continue;
68 const AttributeSet& existingAttributeSet = leaf->attributeSet();
69 AttributeSet* newAttributeSet =
new AttributeSet(
70 existingAttributeSet, static_cast<Index>(newSize), mLock);
71 const size_t attributeSetSize = existingAttributeSet.size();
75 std::vector<AttributeArray*> newAttributeArrays;
76 std::vector<const AttributeArray*> existingAttributeArrays;
78 for (
size_t i = 0; i < attributeSetSize; i++) {
80 const AttributeArray* existingArray = existingAttributeSet.getConst(i);
82 if (!newArray->hasConstantStride() || !existingArray->hasConstantStride()) {
84 "Transfer of attribute values for dynamic arrays not currently supported.");
87 if (newArray->stride() != existingArray->stride()) {
89 "Cannot transfer attribute values with mis-matching strides.");
92 newAttributeArrays.push_back(newArray);
93 existingAttributeArrays.push_back(existingArray);
96 Index attributeIndex = 0;
97 std::vector<ValueType> endOffsets;
99 endOffsets.reserve(LeafNodeT::NUM_VALUES);
103 std::vector<std::pair<Index, Index>> indexMapping;
104 indexMapping.reserve(newSize);
106 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
107 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
109 indexMapping.emplace_back(*iter, attributeIndex++);
111 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
114 for (
size_t i = 0; i < attributeSetSize; i++) {
115 VectorWrapper indexMappingWrapper(indexMapping);
116 newAttributeArrays[i]->copyValues(*(existingAttributeArrays[i]), indexMappingWrapper);
119 leaf->replaceAttributeSet(newAttributeSet);
120 leaf->setOffsets(endOffsets);
125 const FilterT& mFilter;
126 const AttributeArray::ScopedRegistryLock* mLock;
135 template <
typename Po
intDataTreeT>
137 const std::vector<std::string>& groups,
141 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
143 if (!leafIter)
return;
145 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
147 std::vector<std::string> availableGroups;
152 for (
const auto& groupName : groups) {
153 if (descriptor.hasGroup(groupName)) {
154 availableGroups.push_back(groupName);
158 if (availableGroups.empty())
return;
160 std::vector<std::string> empty;
161 std::unique_ptr<MultiGroupFilter>
filter;
163 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
166 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
174 point_delete_internal::DeleteByFilterOp<PointDataTreeT, MultiGroupFilter> deleteOp(
185 if (drop && !invert) {
190 template <
typename Po
intDataTreeT>
196 std::vector<std::string> groups(1, group);
209 #endif // OPENVDB_POINTS_POINT_DELETE_IMPL_HAS_BEEN_INCLUDED
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
GLdouble GLdouble GLint GLint const GLdouble * points
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
GLsizei const GLchar *const * string
#define OPENVDB_USE_VERSION_NAMESPACE
void deleteFromGroup(PointDataTreeT &pointTree, const std::string &group, bool invert, bool drop)
Delete points that are members of a group.
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
void dropGroups(PointDataTreeT &tree, const std::vector< Name > &groups)
Drops existing groups from the VDB tree, the tree is compacted after dropping.
void deleteFromGroups(PointDataTreeT &pointTree, const std::vector< std::string > &groups, bool invert, bool drop)
Delete points that are members of specific groups.
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
#define OPENVDB_THROW(exception, message)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter