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,
76 namespace point_delete_internal {
81 using T = std::vector<std::pair<Index, Index>>;
84 operator bool()
const {
return index < data.size(); }
91 T::size_type index = 0;
95 template <
typename Po
intDataTreeT,
typename FilterT>
100 using LeafNodeT =
typename PointDataTreeT::LeafNodeType;
110 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf) {
112 const size_t newSize =
113 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
117 leaf->clearAttributes(
true, mLock);
123 const size_t currentSize = leaf->getLastValue();
124 if (newSize == currentSize)
continue;
126 const AttributeSet& existingAttributeSet = leaf->attributeSet();
128 existingAttributeSet,
static_cast<Index>(newSize), mLock);
129 const size_t attributeSetSize = existingAttributeSet.
size();
133 std::vector<AttributeArray*> newAttributeArrays;
134 std::vector<const AttributeArray*> existingAttributeArrays;
136 for (
size_t i = 0; i < attributeSetSize; i++) {
142 "Transfer of attribute values for dynamic arrays not currently supported.");
147 "Cannot transfer attribute values with mis-matching strides.");
150 newAttributeArrays.push_back(newArray);
151 existingAttributeArrays.push_back(existingArray);
154 Index attributeIndex = 0;
155 std::vector<ValueType> endOffsets;
157 endOffsets.reserve(LeafNodeT::NUM_VALUES);
161 std::vector<std::pair<Index, Index>> indexMapping;
162 indexMapping.reserve(newSize);
164 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
165 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
167 indexMapping.emplace_back(*iter, attributeIndex++);
169 endOffsets.push_back(
static_cast<ValueType>(attributeIndex));
172 for (
size_t i = 0; i < attributeSetSize; i++) {
174 newAttributeArrays[i]->copyValues(*(existingAttributeArrays[i]), indexMappingWrapper);
177 leaf->replaceAttributeSet(newAttributeSet);
178 leaf->setOffsets(endOffsets);
183 const FilterT& mFilter;
193 template <
typename Po
intDataTreeT>
195 const std::vector<std::string>& groups,
199 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
201 if (!leafIter)
return;
203 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
204 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
205 std::vector<std::string> availableGroups;
210 for (
const auto& groupName : groups) {
211 if (descriptor.hasGroup(groupName)) {
212 availableGroups.push_back(groupName);
216 if (availableGroups.empty())
return;
218 std::vector<std::string> empty;
219 std::unique_ptr<MultiGroupFilter> filter;
221 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
224 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
234 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
243 if (drop && !invert) {
248 template <
typename Po
intDataTreeT>
250 const std::string& group,
254 std::vector<std::string> groups(1, group);
Index filters primarily designed to be used with a FilterIndexIter.
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Point group manipulation in a VDB Point Grid.
Defined various multi-threaded utility functions for trees.
Definition: openvdb/Exceptions.h:60
Definition: openvdb/Exceptions.h:61
Definition: AttributeArray.h:119
Base class for storing attribute data.
Definition: AttributeArray.h:93
virtual Index stride() const =0
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:303
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
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.
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:111
const AttributeArray * get(const std::string &name) const
Definition: IndexFilter.h:136
Definition: LeafManager.h:102
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:85
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:345
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:437
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:194
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
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:249
Index32 Index
Definition: openvdb/Types.h:50
Definition: openvdb/Exceptions.h:13
#define OPENVDB_THROW(exception, message)
Definition: openvdb/Exceptions.h:74
Definition: PointDelete.h:97
typename LeafNodeT::ValueType ValueType
Definition: PointDelete.h:101
DeleteByFilterOp(const FilterT &filter, const AttributeArray::ScopedRegistryLock *lock)
Definition: PointDelete.h:103
void operator()(const LeafRangeT &range) const
Definition: PointDelete.h:108
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointDelete.h:99
typename PointDataTreeT::LeafNodeType LeafNodeT
Definition: PointDelete.h:100
Definition: PointDelete.h:80
Index targetIndex() const
Definition: PointDelete.h:87
std::vector< std::pair< Index, Index > > T
Definition: PointDelete.h:81
VectorWrapper(const T &_data)
Definition: PointDelete.h:83
Index sourceIndex() const
Definition: PointDelete.h:86
VectorWrapper & operator++()
Definition: PointDelete.h:85
#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:178