Go to the documentation of this file.
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 #if OPENVDB_ABI_VERSION_NUMBER >= 6
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++) {
175 newAttributeArrays[i]->copyValues(*(existingAttributeArrays[i]), indexMappingWrapper);
178 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
179 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
181 for (
size_t i = 0; i < attributeSetSize; i++) {
182 newAttributeArrays[i]->set(attributeIndex, *(existingAttributeArrays[i]),
187 endOffsets.push_back(
static_cast<ValueType>(attributeIndex));
191 leaf->replaceAttributeSet(newAttributeSet);
192 leaf->setOffsets(endOffsets);
197 const FilterT& mFilter;
207 template <
typename Po
intDataTreeT>
209 const std::vector<std::string>& groups,
213 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
215 if (!leafIter)
return;
217 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
218 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
219 std::vector<std::string> availableGroups;
224 for (
const auto& groupName : groups) {
225 if (descriptor.hasGroup(groupName)) {
226 availableGroups.push_back(groupName);
230 if (availableGroups.empty())
return;
232 std::vector<std::string> empty;
233 std::unique_ptr<MultiGroupFilter> filter;
235 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
238 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
248 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
257 if (drop && !invert) {
262 template <
typename Po
intDataTreeT>
264 const std::string& group,
268 std::vector<std::string> groups(1, group);
278 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED
void operator()(const LeafRangeT &range) const
Definition: PointDelete.h:108
virtual Index stride() const =0
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:111
Point group manipulation in a VDB Point Grid.
typename LeafNodeT::ValueType ValueType
Definition: PointDelete.h:101
Index32 Index
Definition: Types.h:31
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:263
Definition: IndexFilter.h:136
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:83
Index filters primarily designed to be used with a FilterIndexIter.
VectorWrapper(const T &_data)
Definition: PointDelete.h:83
DeleteByFilterOp(const FilterT &filter, const AttributeArray::ScopedRegistryLock *lock)
Definition: PointDelete.h:103
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointDelete.h:99
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: Exceptions.h:61
Definition: Exceptions.h:60
Defined various multi-threaded utility functions for trees.
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:321
Index targetIndex() const
Definition: PointDelete.h:87
Definition: PointDelete.h:97
const AttributeArray * get(const std::string &name) const
typename PointDataTreeT::LeafNodeType LeafNodeT
Definition: PointDelete.h:100
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:146
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.
Definition: LeafManager.h:100
Base class for storing attribute data.
Definition: AttributeArray.h:93
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:39
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:358
VectorWrapper & operator++()
Definition: PointDelete.h:85
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:94
Definition: AttributeArray.h:119
std::vector< std::pair< Index, Index > > T
Definition: PointDelete.h:81
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:437
Definition: PointDelete.h:80
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: PointDelete.h:208
Index sourceIndex() const
Definition: PointDelete.h:86
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:82