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> 48 #include <type_traits> 61 template <
typename Po
intDataTreeT>
68 template <
typename Po
intDataTreeT>
75 template <
typename Po
intDataTreeT>
86 template <
typename Po
intDataTreeT>
88 const std::vector<Name>& includeGroups = std::vector<Name>(),
89 const std::vector<Name>& excludeGroups = std::vector<Name>(),
90 const bool inCoreOnly =
false);
97 template <
typename Po
intDataTreeT>
99 const bool inCoreOnly =
false);
106 template <
typename Po
intDataTreeT>
108 const bool inCoreOnly =
false);
115 template <
typename Po
intDataTreeT>
117 const bool inCoreOnly =
false);
125 template <
typename PointDataGridT,
127 inline typename std::enable_if< std::is_integral<typename GridT::ValueType>::value ||
128 std::is_floating_point<typename GridT::ValueType>::value,
129 typename GridT::Ptr>::type
131 const std::vector<Name>& includeGroups = std::vector<Name>(),
132 const std::vector<Name>& excludeGroups = std::vector<Name>());
142 template <
typename PointDataGridT,
144 inline typename std::enable_if< std::is_integral<typename GridT::ValueType>::value ||
145 std::is_floating_point<typename GridT::ValueType>::value,
146 typename GridT::Ptr>::type
148 const openvdb::math::Transform& transform,
149 const std::vector<Name>& includeGroups = std::vector<Name>(),
150 const std::vector<Name>& excludeGroups = std::vector<Name>());
156 namespace point_count_internal {
158 template <
typename PointDataTreeT,
166 const bool inCoreOnly =
false)
168 , mInCoreOnly(inCoreOnly) { }
172 for (
auto leaf = range.begin(); leaf; ++leaf) {
173 if (mInCoreOnly && leaf->buffer().isOutOfCore())
continue;
174 auto iter = leaf->template beginIndex<ValueIterT, FilterT>(mFilter);
182 return size1 + size2;
186 const FilterT& mFilter;
187 const bool mInCoreOnly;
191 template <
typename Po
intDataTreeT,
typename FilterT,
typename ValueIterT>
193 const FilterT& filter,
194 const bool inCoreOnly =
false)
200 return tbb::parallel_reduce(leafManager.
leafRange(),
Index64(0), pointCountOp, PointCountOp::join);
204 template <
typename Po
intDataTreeT,
typename FilterT>
206 const FilterT& filter,
207 const bool inCoreOnly =
false)
209 using ValueIterT =
typename PointDataTreeT::LeafNodeType::ValueAllCIter;
210 return threadedFilterPointCount< PointDataTreeT, FilterT, ValueIterT>(tree, filter, inCoreOnly);
214 template <
typename Po
intDataTreeT,
typename FilterT>
216 const FilterT& filter,
217 const bool inCoreOnly =
false)
219 using ValueIterT =
typename PointDataTreeT::LeafNodeType::ValueOnCIter;
220 return threadedFilterPointCount< PointDataTreeT, FilterT, ValueIterT>(tree, filter, inCoreOnly);
224 template <
typename Po
intDataTreeT,
typename FilterT>
226 const FilterT& filter,
227 const bool inCoreOnly =
false)
229 using ValueIterT =
typename PointDataTreeT::LeafNodeType::ValueOffCIter;
230 return threadedFilterPointCount< PointDataTreeT, FilterT, ValueIterT>(tree, filter, inCoreOnly);
240 template <
typename Po
intDataTreeT>
245 for (
auto iter = tree.cbeginLeaf(); iter; ++iter) {
246 if (inCoreOnly && iter->buffer().isOutOfCore())
continue;
247 size += iter->pointCount();
253 template <
typename Po
intDataTreeT>
258 for (
auto iter = tree.cbeginLeaf(); iter; ++iter) {
259 if (inCoreOnly && iter->buffer().isOutOfCore())
continue;
260 size += iter->onPointCount();
266 template <
typename Po
intDataTreeT>
271 for (
auto iter = tree.cbeginLeaf(); iter; ++iter) {
272 if (inCoreOnly && iter->buffer().isOutOfCore())
continue;
273 size += iter->offPointCount();
279 template <
typename Po
intDataTreeT>
282 auto iter = tree.cbeginLeaf();
283 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
286 GroupFilter groupFilter(name, iter->attributeSet());
287 return point_count_internal::filterPointCount<PointDataTreeT, GroupFilter>(tree, groupFilter, inCoreOnly);
291 template <
typename Po
intDataTreeT>
294 auto iter = tree.cbeginLeaf();
295 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
298 GroupFilter groupFilter(name, iter->attributeSet());
299 return point_count_internal::filterActivePointCount<PointDataTreeT, GroupFilter>(tree, groupFilter, inCoreOnly);
303 template <
typename Po
intDataTreeT>
306 auto iter = tree.cbeginLeaf();
307 if (!iter || !iter->attributeSet().descriptor().hasGroup(name)) {
310 GroupFilter groupFilter(name, iter->attributeSet());
311 return point_count_internal::filterInactivePointCount<PointDataTreeT, GroupFilter>(tree, groupFilter, inCoreOnly);
315 template <
typename Po
intDataTreeT>
317 const std::vector<Name>& includeGroups,
const std::vector<Name>& excludeGroups,
318 const bool inCoreOnly)
320 using LeafNode =
typename PointDataTreeT::LeafNodeType;
322 const bool useGroup = includeGroups.size() > 0 || excludeGroups.size() > 0;
325 const size_t leafCount = leafManager.
leafCount();
327 pointOffsets.reserve(leafCount);
330 for (
size_t n = 0; n < leafCount; n++)
332 const LeafNode& leaf = leafManager.
leaf(n);
335 if (inCoreOnly && leaf.buffer().isOutOfCore()) {
336 pointOffsets.push_back(pointOffset);
341 auto iter = leaf.beginValueOn();
345 pointOffset +=
iterCount(filterIndexIter);
348 pointOffset += leaf.onPointCount();
350 pointOffsets.push_back(pointOffset);
356 template <
typename Po
intDataGr
idT,
typename Gr
idT>
357 inline typename std::enable_if< std::is_integral<typename GridT::ValueType>::value ||
358 std::is_floating_point<typename GridT::ValueType>::value,
359 typename GridT::Ptr>::type
361 const std::vector<Name>& includeGroups,
362 const std::vector<Name>& excludeGroups)
364 return point_mask_internal::convertPointsToScalar<PointDataGridT, GridT>(
365 points, includeGroups, excludeGroups);
369 template <
typename Po
intDataGr
idT,
typename Gr
idT>
370 inline typename std::enable_if< std::is_integral<typename GridT::ValueType>::value ||
371 std::is_floating_point<typename GridT::ValueType>::value,
372 typename GridT::Ptr>::type
374 const openvdb::math::Transform& transform,
375 const std::vector<Name>& includeGroups,
376 const std::vector<Name>& excludeGroups)
378 return point_mask_internal::convertPointsToScalar<PointDataGridT, GridT>(
379 points, transform, includeGroups, excludeGroups);
390 #endif // OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:241
typename tree::LeafManager< const PointDataTreeT > LeafManagerT
Definition: PointCount.h:163
Index64 filterInactivePointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:225
Index64 inactiveGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total inactive points in the group in the PointDataTree.
Definition: PointCount.h:304
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:328
uint64_t Index64
Definition: Types.h:59
Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total points in the group in the PointDataTree.
Definition: PointCount.h:280
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
Index64 threadedFilterPointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:192
Index64 inactivePointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total inactive points in the PointDataTree.
Definition: PointCount.h:267
Tree< typename RootNodeType::template ValueConverter< Int32 >::Type > Type
Definition: Tree.h:224
Index filters primarily designed to be used with a FilterIndexIter.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
Index64 activeGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total active points in the group in the PointDataTree.
Definition: PointCount.h:292
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
Definition: Exceptions.h:39
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:359
std::enable_if< std::is_integral< typename GridT::ValueType >::value||std::is_floating_point< typename GridT::ValueType >::value, typename GridT::Ptr >::type pointCountGrid(const PointDataGridT &grid, const openvdb::math::Transform &transform, const std::vector< Name > &includeGroups=std::vector< Name >(), const std::vector< Name > &excludeGroups=std::vector< Name >())
Generate a new grid that uses the supplied transform with voxel values to store the number of points ...
Definition: PointCount.h:373
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:144
Definition: PointCount.h:161
Methods for extracting masks from VDB Point grids.
std::string Name
Definition: Name.h:44
Definition: IndexFilter.h:104
PointCountOp(const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:165
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Index filtering on group membership.
Definition: AttributeGroup.h:159
Index64 filterActivePointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:215
void reset(const LeafT &leaf)
Definition: IndexFilter.h:146
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
Index64 filterPointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:205
Index64 operator()(const typename LeafManagerT::LeafRange &range, Index64 size) const
Definition: PointCount.h:170
Index64 activePointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total active points in the PointDataTree.
Definition: PointCount.h:254
Index64 getPointOffsets(std::vector< Index64 > &pointOffsets, const PointDataTreeT &tree, const std::vector< Name > &includeGroups=std::vector< Name >(), const std::vector< Name > &excludeGroups=std::vector< Name >(), const bool inCoreOnly=false)
Populate an array of cumulative point offsets per leaf node.
Definition: PointCount.h:316
static Index64 join(Index64 size1, Index64 size2)
Definition: PointCount.h:181