37 #ifndef OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 45 #include <openvdb/tools/Prune.h> 46 #include <openvdb/tree/LeafManager.h> 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 {
106 template <
typename Po
intDataTreeT,
typename FilterT>
111 using LeafNodeT =
typename PointDataTreeT::LeafNodeType;
115 : mFilter(filter) { }
119 for (
auto leaf = range.begin(); leaf != range.end(); ++leaf) {
121 const size_t newSize =
122 iterCount(leaf->template beginIndexAll<FilterT>(mFilter));
126 leaf->clearAttributes();
132 const size_t currentSize = leaf->getLastValue();
133 if (newSize == currentSize)
continue;
135 const AttributeSet& existingAttributeSet = leaf->attributeSet();
137 existingAttributeSet, static_cast<Index>(newSize));
138 const size_t attributeSetSize = existingAttributeSet.
size();
142 std::vector<AttributeArray*> newAttributeArrays;
143 std::vector<const AttributeArray*> existingAttributeArrays;
145 for (
size_t i = 0; i < attributeSetSize; i++) {
151 "Transfer of attribute values for dynamic arrays not currently supported.");
156 "Cannot transfer attribute values with mis-matching strides.");
159 newAttributeArrays.push_back(newArray);
160 existingAttributeArrays.push_back(existingArray);
163 Index attributeIndex = 0;
164 std::vector<ValueType> endOffsets;
166 endOffsets.reserve(LeafNodeT::NUM_VALUES);
170 for (
auto voxel = leaf->cbeginValueAll(); voxel; ++voxel) {
171 for (
auto iter = leaf->beginIndexVoxel(voxel.getCoord(), mFilter);
173 for (
size_t i = 0; i < attributeSetSize; i++) {
174 newAttributeArrays[i]->set(attributeIndex, *(existingAttributeArrays[i]),
179 endOffsets.push_back(static_cast<ValueType>(attributeIndex));
182 leaf->replaceAttributeSet(newAttributeSet);
183 leaf->setOffsets(endOffsets);
188 const FilterT& mFilter;
197 template <
typename Po
intDataTreeT>
199 const std::vector<std::string>& groups,
203 const typename PointDataTreeT::LeafCIter leafIter = pointTree.cbeginLeaf();
205 if (!leafIter)
return;
207 const openvdb::points::AttributeSet& attributeSet = leafIter->attributeSet();
208 const AttributeSet::Descriptor& descriptor = attributeSet.descriptor();
209 std::vector<std::string> availableGroups;
214 for (
const auto& groupName : groups) {
215 if (descriptor.hasGroup(groupName)) {
216 availableGroups.push_back(groupName);
220 if (availableGroups.empty())
return;
222 std::vector<std::string> empty;
223 std::unique_ptr<MultiGroupFilter> filter;
225 filter.reset(
new MultiGroupFilter(groups, empty, leafIter->attributeSet()));
228 filter.reset(
new MultiGroupFilter(empty, groups, leafIter->attributeSet()));
233 tbb::parallel_for(leafManager.
leafRange(), deleteOp);
241 if (drop && !invert) {
246 template <
typename Po
intDataTreeT>
248 const std::string& group,
252 std::vector<std::string> groups(1, group);
262 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED 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...
virtual Index stride() const =0
typename LeafNodeT::ValueType ValueType
Definition: PointDelete.h:112
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
typename PointDataTreeT::LeafNodeType LeafNodeT
Definition: PointDelete.h:111
#define OPENVDB_THROW(exception, message)
Definition: Exceptions.h:109
Definition: Exceptions.h:87
typename LeafManagerT::LeafRange LeafRangeT
Definition: PointDelete.h:110
Definition: IndexFilter.h:163
Point group manipulation in a VDB Point Grid.
Index filters primarily designed to be used with a FilterIndexIter.
size_t size() const
Return the number of attributes in this set.
Definition: AttributeSet.h:130
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...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Definition: PointDelete.h:107
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:341
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:198
Definition: Exceptions.h:40
Index32 Index
Definition: Types.h:61
Base class for storing attribute data.
Definition: AttributeArray.h:118
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:247
bool hasConstantStride() const
Return true if this attribute has a constant stride.
Definition: AttributeArray.h:236
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: LeafManager.h:127
DeleteByFilterOp(const FilterT &filter)
Definition: PointDelete.h:114
void operator()(const LeafRangeT &range) const
Definition: PointDelete.h:117
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:578
Ordered collection of uniquely-named attribute arrays.
Definition: AttributeSet.h:62
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Definition: Exceptions.h:88