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,
76 typename GridT =
typename PointDataGridT::template ValueConverter<Int32>::Type,
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;
133 pointOffsets.assign(tree.leafCount(),
Index64(0));
134 if (pointOffsets.empty())
return 0;
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);
144 pointOffsets[pos] = leaf.pointCount();
146 pointOffsets[pos] =
iterCount(leaf.beginIndexAll(filter));
153 Index64 pointOffset(pointOffsets[0]);
154 for (
size_t n = 1; n < pointOffsets.size(); n++) {
155 pointOffset += pointOffsets[n];
156 pointOffsets[n] = pointOffset;
163 template <
typename Po
intDataGr
idT,
typename Gr
idT,
typename FilterT>
166 const FilterT& filter)
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)
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 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: PointCount.h:88
GridT::Ptr pointCountGrid(const PointDataGridT &grid, const openvdb::math::Transform &transform, const FilterT &filter=NullFilter())
Generate a new grid that uses the supplied transform with voxel values to store the number of points ...
Definition: PointCount.h:183
Index filters primarily designed to be used with a FilterIndexIter.
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
uint64_t Index64
Definition: Types.h:53
Definition: Exceptions.h:13
ValueT value
Definition: GridBuilder.h:1287
Definition: IndexIterator.h:43
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:84
Methods for extracting masks from VDB Point grids.
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
Tree< typename RootNodeType::template ValueConverter< Int32 >::Type > Type
Definition: Tree.h:196
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h.in:116
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1070
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h.in:202
Definition: IndexIterator.h:42