37 #ifndef OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED
38 #define OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED
40 #include <openvdb/openvdb.h>
46 #include <tbb/parallel_reduce.h>
62 template <
typename Po
intDataTreeT,
typename FilterT = NullFilter>
64 const FilterT& filter = NullFilter(),
65 const bool inCoreOnly =
false,
66 const bool threaded =
true);
76 template <
typename Po
intDataTreeT,
typename FilterT = NullFilter>
78 const PointDataTreeT& tree,
79 const FilterT& filter = NullFilter(),
80 const bool inCoreOnly =
false,
81 const bool threaded =
true);
88 template <
typename PointDataGridT,
90 typename FilterT = NullFilter>
91 inline typename GridT::Ptr
93 const FilterT& filter = NullFilter());
102 template <
typename PointDataGridT,
104 typename FilterT = NullFilter>
105 inline typename GridT::Ptr
107 const openvdb::math::Transform& transform,
108 const FilterT& filter = NullFilter());
114 template <
typename Po
intDataTreeT,
typename FilterT>
116 const FilterT& filter,
117 const bool inCoreOnly,
121 using LeafRangeT =
typename LeafManagerT::LeafRange;
124 [&filter, &inCoreOnly] (
const LeafRangeT& range,
Index64 sum) ->
Index64 {
125 for (
const auto& leaf : range) {
126 if (inCoreOnly && leaf.buffer().isOutOfCore())
continue;
127 auto state = filter.state(leaf);
129 sum += leaf.pointCount();
131 sum +=
iterCount(leaf.beginIndexAll(filter));
137 LeafManagerT leafManager(tree);
139 return tbb::parallel_reduce(leafManager.leafRange(),
Index64(0), countLambda,
143 return countLambda(leafManager.leafRange(),
Index64(0));
148 template <
typename Po
intDataTreeT,
typename FilterT>
150 const PointDataTreeT& tree,
151 const FilterT& filter,
152 const bool inCoreOnly,
155 using LeafT =
typename PointDataTreeT::LeafNodeType;
164 LeafManagerT leafManager(tree);
166 [&
pointOffsets, &filter, &inCoreOnly](
const LeafT& leaf,
size_t pos) {
167 if (inCoreOnly && leaf.buffer().isOutOfCore())
return;
168 auto state = filter.state(leaf);
189 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
192 const FilterT& filter)
194 static_assert( std::is_integral<typename GridT::ValueType>::value ||
195 std::is_floating_point<typename GridT::ValueType>::value,
196 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
200 auto& nonConstPoints = const_cast<typename AdapterT::NonConstGridType&>(points);
202 return point_mask_internal::convertPointsToScalar<GridT>(
203 nonConstPoints, filter);
207 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
210 const openvdb::math::Transform& transform,
211 const FilterT& filter)
213 static_assert( std::is_integral<typename GridT::ValueType>::value ||
214 std::is_floating_point<typename GridT::ValueType>::value,
215 "openvdb::points::pointCountGrid must return an integer or floating-point scalar grid");
219 auto& nonConstPoints = const_cast<typename AdapterT::NonConstGridType&>(points);
222 return point_mask_internal::convertPointsToScalar<GridT>(
223 nonConstPoints, transform, filter, deformer);
233 template <
typename Po
intDataTreeT>
242 template <
typename Po
intDataTreeT>
251 template <
typename Po
intDataTreeT>
260 template <
typename Po
intDataTreeT>
263 const bool inCoreOnly =
true)
265 auto iter = tree.cbeginLeaf();
266 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
274 template <
typename Po
intDataTreeT>
277 const bool inCoreOnly =
true)
279 auto iter = tree.cbeginLeaf();
280 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
288 template <
typename Po
intDataTreeT>
291 const bool inCoreOnly =
true)
293 auto iter = tree.cbeginLeaf();
294 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
302 template <
typename Po
intDataTreeT>
305 const std::vector<Name>& includeGroups,
306 const std::vector<Name>& excludeGroups,
307 const bool inCoreOnly =
false)
309 MultiGroupFilter filter(includeGroups, excludeGroups, tree.cbeginLeaf()->attributeSet());
314 template <
typename PointDataGridT,
317 inline typename GridT::Ptr
319 const std::vector<Name>& includeGroups,
320 const std::vector<Name>& excludeGroups)
322 auto leaf = grid.tree().cbeginLeaf();
323 if (!leaf)
return GridT::create(0);
324 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
329 template <
typename PointDataGridT,
332 inline typename GridT::Ptr
334 const openvdb::math::Transform& transform,
335 const std::vector<Name>& includeGroups,
336 const std::vector<Name>& excludeGroups)
338 auto leaf = grid.tree().cbeginLeaf();
339 if (!leaf)
return GridT::create(0);
340 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
352 #endif // OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED