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>
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();
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()));
257 if (drop && !invert) {
262 template <
typename Po
intDataTreeT>
268 std::vector<std::string>
groups(1, group);
278 #endif // OPENVDB_POINTS_POINT_DELETE_HAS_BEEN_INCLUDED
std::vector< std::pair< Index, Index >> T
void parallel_for(int64_t start, int64_t end, std::function< void(int64_t index)> &&task, parallel_options opt=parallel_options(0, Split_Y, 1))
DeleteByFilterOp(const FilterT &filter, const AttributeArray::ScopedRegistryLock *lock)
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
virtual Index stride() const =0
typename PointDataTreeT::LeafNodeType LeafNodeT
typename LeafNodeT::ValueType ValueType
Point group manipulation in a VDB Point Grid.
#define OPENVDB_USE_VERSION_NAMESPACE
Index filters primarily designed to be used with a FilterIndexIter.
bool hasConstantStride() const
Return true if this attribute has a constant stride.
void operator()(const LeafRangeT &range) const
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...
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
void deleteFromGroup(PointDataTreeT &pointTree, const std::string &group, bool invert=false, bool drop=true)
Delete points that are members of a group.
Base class for storing attribute data.
GLint GLenum GLsizei GLint GLsizei const void * data
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...
Defined various multi-threaded utility functions for trees.
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
VectorWrapper(const T &_data)
void deleteFromGroups(PointDataTreeT &pointTree, const std::vector< std::string > &groups, bool invert=false, bool drop=true)
Delete points that are members of specific groups.
GLsizei const GLchar *const * string
typename LeafManagerT::LeafRange LeafRangeT
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
void dropGroups(PointDataTree &tree, const std::vector< Name > &groups)
Drops existing groups from the VDB tree, the tree is compacted after dropping.
size_t size() const
Return the number of attributes in this set.
Ordered collection of uniquely-named attribute arrays.
Index targetIndex() const
A LeafManager manages a linear array of pointers to a given tree's leaf nodes, as well as optional au...
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Index sourceIndex() const
VectorWrapper & operator++()
#define OPENVDB_THROW(exception, message)