9 #ifndef OPENVDB_POINTS_POINT_COUNT_IMPL_HAS_BEEN_INCLUDED 10 #define OPENVDB_POINTS_POINT_COUNT_IMPL_HAS_BEEN_INCLUDED 17 template <
typename Po
intDataTreeT,
typename FilterT>
19 const FilterT& filter,
20 const bool inCoreOnly,
24 using LeafRangeT =
typename LeafManagerT::LeafRange;
27 [&filter, &inCoreOnly] (
const LeafRangeT& range,
Index64 sum) ->
Index64 {
28 for (
const auto& leaf : range) {
29 if (inCoreOnly && leaf.buffer().isOutOfCore())
continue;
30 auto state = filter.state(leaf);
32 sum += leaf.pointCount();
34 sum +=
iterCount(leaf.beginIndexAll(filter));
40 LeafManagerT leafManager(tree);
42 return tbb::parallel_reduce(leafManager.leafRange(),
Index64(0), countLambda,
46 return countLambda(leafManager.leafRange(),
Index64(0));
51 template <
typename Po
intDataTreeT,
typename FilterT>
53 const PointDataTreeT& tree,
54 const FilterT& filter,
55 const bool inCoreOnly,
58 using LeafT =
typename PointDataTreeT::LeafNodeType;
63 pointOffsets.assign(tree.leafCount(),
Index64(0));
64 if (pointOffsets.empty())
return 0;
68 LeafManagerT leafManager(tree);
70 [&pointOffsets, &filter, &inCoreOnly](
const LeafT& leaf,
size_t pos) {
71 if (inCoreOnly && leaf.buffer().isOutOfCore())
return;
72 auto state = filter.state(leaf);
74 pointOffsets[pos] = leaf.pointCount();
76 pointOffsets[pos] =
iterCount(leaf.beginIndexAll(filter));
83 Index64 pointOffset(pointOffsets[0]);
84 for (
size_t n = 1; n < pointOffsets.size(); n++) {
85 pointOffset += pointOffsets[n];
86 pointOffsets[n] = pointOffset;
93 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
96 const FilterT& filter)
98 static_assert(std::is_integral<typename GridT::ValueType>::value ||
99 std::is_floating_point<typename GridT::ValueType>::value,
100 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
102 using PointDataTreeT =
typename PointDataGridT::TreeType;
103 using TreeT =
typename GridT::TreeType;
105 typename TreeT::Ptr tree =
106 point_mask_internal::convertPointsToScalar<TreeT, PointDataTreeT, FilterT>
107 (points.tree(), filter);
109 typename GridT::Ptr grid(
new GridT(tree));
110 grid->setTransform(points.transform().copy());
115 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
118 const openvdb::math::Transform& transform,
119 const FilterT& filter)
121 static_assert( std::is_integral<typename GridT::ValueType>::value ||
122 std::is_floating_point<typename GridT::ValueType>::value,
123 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
127 auto& nonConstPoints =
const_cast<typename AdapterT::NonConstGridType&
>(points);
130 return point_mask_internal::convertPointsToScalar<GridT>(
131 nonConstPoints, transform, filter, deformer);
142 #endif // OPENVDB_POINTS_POINT_COUNT_IMPL_HAS_BEEN_INCLUDED 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: PointCountImpl.h:52
uint64_t Index64
Definition: Types.h:53
Definition: IndexIterator.h:44
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:315
Definition: IndexIterator.h:43
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1059
Index64 pointCount(const PointDataTreeT &tree, const FilterT &filter=NullFilter(), const bool inCoreOnly=false, const bool threaded=true)
Count the total number of points in a PointDataTree.
Definition: PointCountImpl.h:18
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:85
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:121
GridT::Ptr pointCountGrid(const PointDataGridT &grid, const FilterT &filter=NullFilter())
Generate a new grid with voxel values to store the number of points per voxel.
Definition: PointCountImpl.h:95
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:218