37 #ifndef OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 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 This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:944
ValueMaskFilter< false > InactiveFilter
Definition: IndexFilter.h:157
Definition: IndexIterator.h:69
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:77
uint64_t Index64
Definition: Types.h:60
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:333
OPENVDB_DEPRECATED Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly)
Definition: PointCount.h:235
Tree< typename RootNodeType::template ValueConverter< Int32 >::Type > Type
Definition: Tree.h:224
Index filters primarily designed to be used with a FilterIndexIter.
Index filtering on group membership.
Definition: AttributeGroup.h:159
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:304
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
OPENVDB_DEPRECATED Index64 inactiveGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=true)
Definition: PointCount.h:290
Definition: Exceptions.h:40
Definition: IndexFilter.h:163
OPENVDB_DEPRECATED Index64 activeGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=true)
Definition: PointCount.h:276
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
Index filtering on active / inactive state of host voxel.
Definition: IndexFilter.h:131
Methods for extracting masks from VDB Point grids.
OPENVDB_DEPRECATED Index64 inactivePointCount(const PointDataTreeT &tree, const bool inCoreOnly=true)
Definition: PointCount.h:253
Definition: IndexIterator.h:70
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:149
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Definition: IndexFilter.h:529
OPENVDB_DEPRECATED Index64 activePointCount(const PointDataTreeT &tree, const bool inCoreOnly=true)
Definition: PointCount.h:244
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
ValueMaskFilter< true > ActiveFilter
Definition: IndexFilter.h:156
std::string Name
Definition: Name.h:44
OPENVDB_DEPRECATED Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=true)
Definition: PointCount.h:262
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:341