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;
138 LeafManagerT leafManager(tree);
140 [&
pointOffsets, &filter, &inCoreOnly](
const LeafT& leaf,
size_t pos) {
141 if (inCoreOnly && leaf.buffer().isOutOfCore())
return;
142 auto state = filter.state(leaf);
163 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
166 const FilterT& filter)
168 static_assert( std::is_integral<typename GridT::ValueType>::value ||
169 std::is_floating_point<typename GridT::ValueType>::value,
170 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
174 auto& nonConstPoints =
const_cast<typename AdapterT::NonConstGridType&
>(points);
176 return point_mask_internal::convertPointsToScalar<GridT>(
177 nonConstPoints, filter);
181 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
184 const openvdb::math::Transform& transform,
185 const FilterT& filter)
187 static_assert( std::is_integral<typename GridT::ValueType>::value ||
188 std::is_floating_point<typename GridT::ValueType>::value,
189 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
193 auto& nonConstPoints =
const_cast<typename AdapterT::NonConstGridType&
>(points);
196 return point_mask_internal::convertPointsToScalar<GridT>(
197 nonConstPoints, transform, filter, deformer);
208 #endif // OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED