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;
131 : mFilter(filter) { }
135 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf) {
137 const size_t newSize =
138 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
142 leaf->clearAttributes();
148 const size_t currentSize = leaf->getLastValue();
149 if (newSize == currentSize)
continue;
151 const AttributeSet& existingAttributeSet = leaf->attributeSet();
153 existingAttributeSet, static_cast<Index>(newSize));
154 const size_t attributeSetSize = existingAttributeSet.
size();
158 std::vector<AttributeArray*> newAttributeArrays;
159 std::vector<const AttributeArray*> existingAttributeArrays;
161 for (
size_t i = 0; i < attributeSetSize; i++) {
167 "Transfer of attribute values for dynamic arrays not currently supported.");
172 "Cannot transfer attribute values with mis-matching strides.");
175 newAttributeArrays.push_back(newArray);
176 existingAttributeArrays.push_back(existingArray);
179 Index attributeIndex = 0;
180 std::vector<ValueType> endOffsets;
182 endOffsets.reserve(LeafNodeT::NUM_VALUES);
186 #if OPENVDB_ABI_VERSION_NUMBER >= 6 187 std::vector<std::pair<Index, Index>> indexMapping;
188 indexMapping.reserve(newSize);
190 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
191 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
193 indexMapping.emplace_back(*iter, attributeIndex++);
195 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
198 for (
size_t i = 0; i < attributeSetSize; i++) {
200 newAttributeArrays[i]->copyValues(*(existingAttributeArrays[i]), indexMappingWrapper);
203 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
204 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
206 for (
size_t i = 0; i < attributeSetSize; i++) {
207 newAttributeArrays[i]->set(attributeIndex, *(existingAttributeArrays[i]),
212 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
216 leaf->replaceAttributeSet(newAttributeSet);
217 leaf->setOffsets(endOffsets);
222 const FilterT& mFilter;
231 template <
typename Po
intDataTreeT>
233 const std::vector<std::string>& groups,
237 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
239 if (!leafIter)
return;
241 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
242 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
243 std::vector<std::string> availableGroups;
248 for (
const auto& groupName : groups) {
249 if (descriptor.hasGroup(groupName)) {
250 availableGroups.push_back(groupName);
254 if (availableGroups.empty())
return;
256 std::vector<std::string> empty;
257 std::unique_ptr<MultiGroupFilter> filter;
259 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
262 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
267 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
275 if (drop && !invert) {
280 template <
typename Po
intDataTreeT>
282 const std::string& group,
286 std::vector<std::string> groups(1, group);
296 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED virtual Index stride() const =0
DeleteByFilterOp(const FilterT &filter)
Definition: PointDelete.h:130
Index32 Index
Definition: Types.h:61
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:232
typename LeafNodeT::ValueType ValueType
Definition: PointDelete.h:128
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:281
Index sourceIndex() const
Definition: PointDelete.h:113
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
std::vector< std::pair< Index, Index > > T
Definition: PointDelete.h:108
Defined various multi-threaded utility functions for trees.
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.
Point group manipulation in a VDB Point Grid.
Index filters primarily designed to be used with a FilterIndexIter.
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
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:578
Index targetIndex() const
Definition: PointDelete.h:114
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: LeafManager.h:127
VectorWrapper(const T &_data)
Definition: PointDelete.h:110
void operator()(const LeafRangeT &range) const
Definition: PointDelete.h:133
Definition: Exceptions.h:87
Definition: Exceptions.h:40
Definition: IndexFilter.h:163
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
Definition: PointDelete.h:106
Base class for storing attribute data.
Definition: AttributeArray.h:118
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:130
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:337
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: PointDelete.h:123
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointDelete.h:126
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
VectorWrapper & operator++()
Definition: PointDelete.h:112
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
typename PointDataTreeT::LeafNodeType LeafNodeT
Definition: PointDelete.h:127
Definition: Exceptions.h:88
const AttributeArray * get(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.
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:341