10 #ifndef OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 46 template <
typename Po
intDataTreeT>
48 const std::vector<std::string>& groups,
66 template <
typename Po
intDataTreeT>
68 const std::string& group,
77 namespace point_delete_internal {
82 using T = std::vector<std::pair<Index, Index>>;
84 VectorWrapper(
const T& _data) : data(_data) { }
85 operator bool()
const {
return index < data.size(); }
86 VectorWrapper& operator++() { index++;
return *
this; }
87 Index sourceIndex()
const { assert(*
this);
return data[index].first; }
88 Index targetIndex()
const { assert(*
this);
return data[index].second; }
92 T::size_type index = 0;
96 template <
typename Po
intDataTreeT,
typename FilterT>
97 struct DeleteByFilterOp
99 using LeafManagerT = tree::LeafManager<PointDataTreeT>;
100 using LeafRangeT =
typename LeafManagerT::LeafRange;
101 using LeafNodeT =
typename PointDataTreeT::LeafNodeType;
102 using ValueType =
typename LeafNodeT::ValueType;
104 DeleteByFilterOp(
const FilterT& filter,
105 const AttributeArray::ScopedRegistryLock* lock)
109 void operator()(
const LeafRangeT& range)
const 111 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf) {
113 const size_t newSize =
114 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
118 leaf->clearAttributes(
true, mLock);
124 const size_t currentSize = leaf->getLastValue();
125 if (newSize == currentSize)
continue;
127 const AttributeSet& existingAttributeSet = leaf->attributeSet();
128 AttributeSet* newAttributeSet =
new AttributeSet(
129 existingAttributeSet, static_cast<Index>(newSize), mLock);
130 const size_t attributeSetSize = existingAttributeSet.size();
134 std::vector<AttributeArray*> newAttributeArrays;
135 std::vector<const AttributeArray*> existingAttributeArrays;
137 for (
size_t i = 0; i < attributeSetSize; i++) {
139 const AttributeArray* existingArray = existingAttributeSet.getConst(i);
141 if (!newArray->hasConstantStride() || !existingArray->hasConstantStride()) {
143 "Transfer of attribute values for dynamic arrays not currently supported.");
146 if (newArray->stride() != existingArray->stride()) {
148 "Cannot transfer attribute values with mis-matching strides.");
151 newAttributeArrays.push_back(newArray);
152 existingAttributeArrays.push_back(existingArray);
155 Index attributeIndex = 0;
156 std::vector<ValueType> endOffsets;
158 endOffsets.reserve(LeafNodeT::NUM_VALUES);
162 std::vector<std::pair<Index, Index>> indexMapping;
163 indexMapping.reserve(newSize);
165 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
166 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
168 indexMapping.emplace_back(*iter, attributeIndex++);
170 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
173 for (
size_t i = 0; i < attributeSetSize; i++) {
174 VectorWrapper indexMappingWrapper(indexMapping);
175 newAttributeArrays[i]->copyValues(*(existingAttributeArrays[i]), indexMappingWrapper);
178 leaf->replaceAttributeSet(newAttributeSet);
179 leaf->setOffsets(endOffsets);
184 const FilterT& mFilter;
185 const AttributeArray::ScopedRegistryLock* mLock;
195 template <
typename Po
intDataTreeT>
197 const std::vector<std::string>& groups,
201 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
203 if (!leafIter)
return;
205 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
206 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
207 std::vector<std::string> availableGroups;
212 for (
const auto& groupName : groups) {
213 if (descriptor.hasGroup(groupName)) {
214 availableGroups.push_back(groupName);
218 if (availableGroups.empty())
return;
220 std::vector<std::string> empty;
221 std::unique_ptr<MultiGroupFilter> filter;
223 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
226 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
234 point_delete_internal::DeleteByFilterOp<PointDataTreeT, MultiGroupFilter> deleteOp(
236 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
245 if (drop && !invert) {
250 template <
typename Po
intDataTreeT>
252 const std::string& group,
256 std::vector<std::string> groups(1, group);
266 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED Definition: Exceptions.h:61
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:345
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Definition: Exceptions.h:60
Definition: AttributeArray.h:118
Defined various multi-threaded utility functions for trees.
void deleteFromGroups(PointDataTreeT &pointTree, const std::vector< std::string > &groups, bool invert=false, bool drop=true)
Delete points that are members of specific groups.
Definition: PointDelete.h:196
Point group manipulation in a VDB Point Grid.
Index filters primarily designed to be used with a FilterIndexIter.
Definition: Exceptions.h:13
Definition: IndexFilter.h:137
void dropGroups(PointDataTreeT &tree, const std::vector< Name > &groups)
Drops existing groups from the VDB tree, the tree is compacted after dropping.
Definition: PointGroup.h:439
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:84
Index32 Index
Definition: Types.h:54
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
void deleteFromGroup(PointDataTreeT &pointTree, const std::string &group, bool invert=false, bool drop=true)
Delete points that are members of a group.
Definition: PointDelete.h:251
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202