10 #ifndef OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 11 #define OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 19 #include <tbb/parallel_reduce.h> 35 template <
typename Po
intDataTreeT,
typename FilterT = NullFilter>
37 const FilterT& filter = NullFilter(),
38 const bool inCoreOnly =
false,
39 const bool threaded =
true);
49 template <
typename Po
intDataTreeT,
typename FilterT = NullFilter>
51 const PointDataTreeT& tree,
52 const FilterT& filter = NullFilter(),
53 const bool inCoreOnly =
false,
54 const bool threaded =
true);
61 template <
typename PointDataGridT,
63 typename FilterT = NullFilter>
64 inline typename GridT::Ptr
66 const FilterT& filter = NullFilter());
75 template <
typename PointDataGridT,
77 typename FilterT = NullFilter>
78 inline typename GridT::Ptr
80 const openvdb::math::Transform& transform,
81 const FilterT& filter = NullFilter());
87 template <
typename Po
intDataTreeT,
typename FilterT>
89 const FilterT& filter,
90 const bool inCoreOnly,
94 using LeafRangeT =
typename LeafManagerT::LeafRange;
97 [&filter, &inCoreOnly] (
const LeafRangeT& range,
Index64 sum) ->
Index64 {
98 for (
const auto& leaf : range) {
99 if (inCoreOnly && leaf.buffer().isOutOfCore())
continue;
100 auto state = filter.state(leaf);
102 sum += leaf.pointCount();
104 sum +=
iterCount(leaf.beginIndexAll(filter));
110 LeafManagerT leafManager(tree);
112 return tbb::parallel_reduce(leafManager.leafRange(),
Index64(0), countLambda,
116 return countLambda(leafManager.leafRange(),
Index64(0));
121 template <
typename Po
intDataTreeT,
typename FilterT>
123 const PointDataTreeT& tree,
124 const FilterT& filter,
125 const bool inCoreOnly,
128 using LeafT =
typename PointDataTreeT::LeafNodeType;
137 LeafManagerT leafManager(tree);
139 [&
pointOffsets, &filter, &inCoreOnly](
const LeafT& leaf,
size_t pos) {
140 if (inCoreOnly && leaf.buffer().isOutOfCore())
return;
141 auto state = filter.state(leaf);
162 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
165 const FilterT& filter)
167 static_assert( std::is_integral<typename GridT::ValueType>::value ||
168 std::is_floating_point<typename GridT::ValueType>::value,
169 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
173 auto& nonConstPoints = const_cast<typename AdapterT::NonConstGridType&>(points);
175 return point_mask_internal::convertPointsToScalar<GridT>(
176 nonConstPoints, filter);
180 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
183 const openvdb::math::Transform& transform,
184 const FilterT& filter)
186 static_assert( std::is_integral<typename GridT::ValueType>::value ||
187 std::is_floating_point<typename GridT::ValueType>::value,
188 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
192 auto& nonConstPoints = const_cast<typename AdapterT::NonConstGridType&>(points);
195 return point_mask_internal::convertPointsToScalar<GridT>(
196 nonConstPoints, transform, filter, deformer);
206 template <
typename Po
intDataTreeT>
215 template <
typename Po
intDataTreeT>
224 template <
typename Po
intDataTreeT>
233 template <
typename Po
intDataTreeT>
236 const bool inCoreOnly =
true)
238 auto iter = tree.cbeginLeaf();
239 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
247 template <
typename Po
intDataTreeT>
250 const bool inCoreOnly =
true)
252 auto iter = tree.cbeginLeaf();
253 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
261 template <
typename Po
intDataTreeT>
264 const bool inCoreOnly =
true)
266 auto iter = tree.cbeginLeaf();
267 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
275 template <
typename Po
intDataTreeT>
278 const std::vector<Name>& includeGroups,
279 const std::vector<Name>& excludeGroups,
280 const bool inCoreOnly =
false)
282 MultiGroupFilter filter(includeGroups, excludeGroups, tree.cbeginLeaf()->attributeSet());
287 template <
typename PointDataGridT,
290 inline typename GridT::Ptr
292 const std::vector<Name>& includeGroups,
293 const std::vector<Name>& excludeGroups)
295 auto leaf = grid.tree().cbeginLeaf();
296 if (!leaf)
return GridT::create(0);
297 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
302 template <
typename PointDataGridT,
305 inline typename GridT::Ptr
307 const openvdb::math::Transform& transform,
308 const std::vector<Name>& includeGroups,
309 const std::vector<Name>& excludeGroups)
311 auto leaf = grid.tree().cbeginLeaf();
312 if (!leaf)
return GridT::create(0);
313 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
325 #endif // OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED OPENVDB_DEPRECATED GridT::Ptr pointCountGrid(const PointDataGridT &grid, const openvdb::math::Transform &transform, const std::vector< Name > &includeGroups, const std::vector< Name > &excludeGroups)
Definition: PointCount.h:306
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:50
Index64 pointOffsets(std::vector< Index64 > &pointOffsets, const PointDataTreeT &tree, const FilterT &filter=NullFilter(), const bool inCoreOnly=false, const bool threaded=true)
Populate an array of cumulative point offsets per leaf node.
Definition: PointCount.h:122
OPENVDB_DEPRECATED Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly)
Definition: PointCount.h:208
std::string Name
Definition: Name.h:17
OPENVDB_DEPRECATED Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=true)
Definition: PointCount.h:235
OPENVDB_DEPRECATED Index64 inactiveGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=true)
Definition: PointCount.h:263
Definition: IndexIterator.h:42
OPENVDB_DEPRECATED Index64 activeGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=true)
Definition: PointCount.h:249
Definition: IndexIterator.h:43
Definition: IndexFilter.h:501
ValueMaskFilter< true > ActiveFilter
Definition: IndexFilter.h:128
Index filters primarily designed to be used with a FilterIndexIter.
ValueMaskFilter< false > InactiveFilter
Definition: IndexFilter.h:129
Tree< typename RootNodeType::template ValueConverter< Int32 >::Type > Type
Definition: Tree.h:197
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:102
OPENVDB_DEPRECATED Index64 activePointCount(const PointDataTreeT &tree, const bool inCoreOnly=true)
Definition: PointCount.h:217
OPENVDB_DEPRECATED Index64 getPointOffsets(std::vector< Index64 > &offsets, const PointDataTreeT &tree, const std::vector< Name > &includeGroups, const std::vector< Name > &excludeGroups, const bool inCoreOnly=false)
Definition: PointCount.h:277
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1065
Definition: IndexFilter.h:135
Definition: Exceptions.h:13
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:82
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
Index filtering on active / inactive state of host voxel.
Definition: IndexFilter.h:103
Methods for extracting masks from VDB Point grids.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
OPENVDB_DEPRECATED Index64 inactivePointCount(const PointDataTreeT &tree, const bool inCoreOnly=true)
Definition: PointCount.h:226
uint64_t Index64
Definition: Types.h:30
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:154
Index filtering on group membership.
Definition: AttributeGroup.h:132