Go to the documentation of this file.
37 #ifndef OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED
73 template <
typename Po
intDataTreeT>
75 const std::vector<std::string>& groups,
93 template <
typename Po
intDataTreeT>
95 const std::string& group,
103 namespace point_delete_internal {
108 using T = std::vector<std::pair<Index, Index>>;
111 operator bool()
const {
return index < data.size(); }
118 T::size_type index = 0;
122 template <
typename Po
intDataTreeT,
typename FilterT>
127 using LeafNodeT =
typename PointDataTreeT::LeafNodeType;
137 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf) {
139 const size_t newSize =
140 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
144 leaf->clearAttributes(
true, mLock);
150 const size_t currentSize = leaf->getLastValue();
151 if (newSize == currentSize)
continue;
153 const AttributeSet& existingAttributeSet = leaf->attributeSet();
155 existingAttributeSet, static_cast<Index>(newSize), mLock);
156 const size_t attributeSetSize = existingAttributeSet.
size();
160 std::vector<AttributeArray*> newAttributeArrays;
161 std::vector<const AttributeArray*> existingAttributeArrays;
163 for (
size_t i = 0; i < attributeSetSize; i++) {
169 "Transfer of attribute values for dynamic arrays not currently supported.");
174 "Cannot transfer attribute values with mis-matching strides.");
177 newAttributeArrays.push_back(newArray);
178 existingAttributeArrays.push_back(existingArray);
181 Index attributeIndex = 0;
182 std::vector<ValueType> endOffsets;
184 endOffsets.reserve(LeafNodeT::NUM_VALUES);
188 #if OPENVDB_ABI_VERSION_NUMBER >= 6
189 std::vector<std::pair<Index, Index>> indexMapping;
190 indexMapping.reserve(newSize);
192 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
193 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
195 indexMapping.emplace_back(*iter, attributeIndex++);
197 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
200 for (
size_t i = 0; i < attributeSetSize; i++) {
202 newAttributeArrays[i]->copyValues(*(existingAttributeArrays[i]), indexMappingWrapper);
205 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
206 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
208 for (
size_t i = 0; i < attributeSetSize; i++) {
209 newAttributeArrays[i]->set(attributeIndex, *(existingAttributeArrays[i]),
214 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
218 leaf->replaceAttributeSet(newAttributeSet);
219 leaf->setOffsets(endOffsets);
224 const FilterT& mFilter;
234 template <
typename Po
intDataTreeT>
236 const std::vector<std::string>& groups,
240 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
242 if (!leafIter)
return;
244 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
245 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
246 std::vector<std::string> availableGroups;
251 for (
const auto& groupName : groups) {
252 if (descriptor.hasGroup(groupName)) {
253 availableGroups.push_back(groupName);
257 if (availableGroups.empty())
return;
259 std::vector<std::string> empty;
260 std::unique_ptr<MultiGroupFilter> filter;
262 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
265 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
275 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
284 if (drop && !invert) {
289 template <
typename Po
intDataTreeT>
291 const std::string& group,
295 std::vector<std::string> groups(1, group);
305 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED
DeleteByFilterOp(const FilterT &filter, const AttributeArray::ScopedRegistryLock *lock)
Definition: PointDelete.h:130
typename LeafNodeT::ValueType ValueType
Definition: PointDelete.h:128
VectorWrapper(const T &_data)
Definition: PointDelete.h:110
Point group manipulation in a VDB Point Grid.
Definition: Exceptions.h:88
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointDelete.h:126
typename PointDataTreeT::LeafNodeType LeafNodeT
Definition: PointDelete.h:127
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:369
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
Index targetIndex() const
Definition: PointDelete.h:114
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.
Index32 Index
Definition: Types.h:61
std::vector< std::pair< Index, Index > > T
Definition: PointDelete.h:108
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:134
Index filters primarily designed to be used with a FilterIndexIter.
const AttributeArray * get(const std::string &name) const
Definition: AttributeArray.h:145
Definition: Exceptions.h:87
Definition: PointDelete.h:123
Definition: IndexFilter.h:164
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
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:579
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:235
virtual Index stride() const =0
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:290
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:109
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:180
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Definition: PointDelete.h:106
Base class for storing attribute data.
Definition: AttributeArray.h:118
void operator()(const LeafRangeT &range) const
Definition: PointDelete.h:135
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:385
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:128
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:341
Definition: Exceptions.h:40
Definition: LeafManager.h:126
VectorWrapper & operator++()
Definition: PointDelete.h:112
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
Index sourceIndex() const
Definition: PointDelete.h:113