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; }
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;
43 using ValueType =
typename LeafNodeT::ValueType;
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();
146 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
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(
176 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
185 if (drop && !invert) {
190 template <
typename Po
intDataTreeT>
192 const std::string& group,
196 std::vector<std::string> groups(1, group);
209 #endif // OPENVDB_POINTS_POINT_DELETE_IMPL_HAS_BEEN_INCLUDED Definition: Exceptions.h:60
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:74
Definition: IndexFilter.h:138
Index32 Index
Definition: Types.h:54
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:315
void dropGroups(PointDataTreeT &tree, const std::vector< Name > &groups)
Drops existing groups from the VDB tree, the tree is compacted after dropping.
Definition: PointGroupImpl.h:329
#define OPENVDB_ASSERT(X)
Definition: Assert.h:41
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:346
bool empty(const char *str)
tests if a c-string str is empty, that is its first value is '\0'
Definition: Util.h:144
Definition: Exceptions.h:13
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: PointDeleteImpl.h:136
Definition: Exceptions.h:61
Definition: AttributeArray.h:119
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:85
void deleteFromGroup(PointDataTreeT &pointTree, const std::string &group, bool invert=false, bool drop=true)
Delete points that are members of a group.
Definition: PointDeleteImpl.h:191
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218