37 #ifndef OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 45 #include <tbb/parallel_reduce.h> 57 template <
typename Po
intDataTreeT>
64 template <
typename Po
intDataTreeT>
71 template <
typename Po
intDataTreeT>
82 template <
typename Po
intDataTreeT>
84 const std::vector<Name>& includeGroups = std::vector<Name>(),
85 const std::vector<Name>& excludeGroups = std::vector<Name>(),
86 const bool inCoreOnly =
false);
93 template <
typename Po
intDataTreeT>
101 template <
typename Po
intDataTreeT>
109 template <
typename Po
intDataTreeT>
116 namespace point_count_internal {
118 template <
typename PointDataTreeT,
126 const bool inCoreOnly =
false)
128 , mInCoreOnly(inCoreOnly) { }
132 for (
auto leaf = range.begin(); leaf; ++leaf) {
133 if (mInCoreOnly && leaf->buffer().isOutOfCore())
continue;
134 auto iter = leaf->template beginIndex<ValueIterT, FilterT>(mFilter);
142 return size1 + size2;
146 const FilterT& mFilter;
147 const bool mInCoreOnly;
151 template <
typename Po
intDataTreeT,
typename FilterT,
typename ValueIterT>
153 const FilterT& filter,
154 const bool inCoreOnly =
false)
160 return tbb::parallel_reduce(leafManager.
leafRange(),
Index64(0), pointCountOp, PointCountOp::join);
164 template <
typename Po
intDataTreeT,
typename FilterT>
166 const FilterT& filter,
167 const bool inCoreOnly =
false)
169 using ValueIterT =
typename PointDataTreeT::LeafNodeType::ValueAllCIter;
170 return threadedFilterPointCount< PointDataTreeT, FilterT, ValueIterT>(tree, filter, inCoreOnly);
174 template <
typename Po
intDataTreeT,
typename FilterT>
176 const FilterT& filter,
177 const bool inCoreOnly =
false)
179 using ValueIterT =
typename PointDataTreeT::LeafNodeType::ValueOnCIter;
180 return threadedFilterPointCount< PointDataTreeT, FilterT, ValueIterT>(tree, filter, inCoreOnly);
184 template <
typename Po
intDataTreeT,
typename FilterT>
186 const FilterT& filter,
187 const bool inCoreOnly =
false)
189 using ValueIterT =
typename PointDataTreeT::LeafNodeType::ValueOffCIter;
190 return threadedFilterPointCount< PointDataTreeT, FilterT, ValueIterT>(tree, filter, inCoreOnly);
197 template <
typename Po
intDataTreeT>
202 for (
auto iter = tree.cbeginLeaf(); iter; ++iter) {
203 if (inCoreOnly && iter->buffer().isOutOfCore())
continue;
204 size += iter->pointCount();
210 template <
typename Po
intDataTreeT>
215 for (
auto iter = tree.cbeginLeaf(); iter; ++iter) {
216 if (inCoreOnly && iter->buffer().isOutOfCore())
continue;
217 size += iter->onPointCount();
223 template <
typename Po
intDataTreeT>
228 for (
auto iter = tree.cbeginLeaf(); iter; ++iter) {
229 if (inCoreOnly && iter->buffer().isOutOfCore())
continue;
230 size += iter->offPointCount();
236 template <
typename Po
intDataTreeT>
240 return point_count_internal::filterPointCount<PointDataTreeT, GroupFilter>(tree, groupFilter, inCoreOnly);
244 template <
typename Po
intDataTreeT>
248 return point_count_internal::filterActivePointCount<PointDataTreeT, GroupFilter>(tree, groupFilter, inCoreOnly);
252 template <
typename Po
intDataTreeT>
256 return point_count_internal::filterInactivePointCount<PointDataTreeT, GroupFilter>(tree, groupFilter, inCoreOnly);
260 template <
typename Po
intDataTreeT>
262 const std::vector<Name>& includeGroups,
const std::vector<Name>& excludeGroups,
263 const bool inCoreOnly)
265 using LeafNode =
typename PointDataTreeT::LeafNodeType;
267 const bool useGroup = includeGroups.size() > 0 || excludeGroups.size() > 0;
270 const size_t leafCount = leafManager.
leafCount();
272 pointOffsets.reserve(leafCount);
275 for (
size_t n = 0; n < leafCount; n++)
277 const LeafNode& leaf = leafManager.
leaf(n);
280 if (inCoreOnly && leaf.buffer().isOutOfCore()) {
281 pointOffsets.push_back(pointOffset);
286 auto iter = leaf.beginValueOn();
290 pointOffset +=
iterCount(filterIndexIter);
293 pointOffset += leaf.onPointCount();
295 pointOffsets.push_back(pointOffset);
308 #endif // OPENVDB_POINTS_POINT_COUNT_HAS_BEEN_INCLUDED 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:261
Index64 filterActivePointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:175
size_t leafCount() const
Return the number of leaf nodes.
Definition: LeafManager.h:333
Index64 groupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total points in the group in the PointDataTree.
Definition: PointCount.h:237
Definition: PointCount.h:121
Index64 operator()(const typename LeafManagerT::LeafRange &range, Index64 size) const
Definition: PointCount.h:130
LeafType & leaf(size_t leafIdx) const
Return a pointer to the leaf node at index leafIdx in the array.
Definition: LeafManager.h:364
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:115
Index64 filterInactivePointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:185
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
Point attribute manipulation in a VDB Point Grid.
Definition: IndexFilter.h:103
Index filters primarily designed to be used with a FilterIndexIter.
Index64 activeGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total active points in the group in the PointDataTree.
Definition: PointCount.h:245
Index64 inactivePointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total inactive points in the PointDataTree.
Definition: PointCount.h:224
#define OPENVDB_VERSION_NAME
Definition: version.h:43
Index64 activePointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total active points in the PointDataTree.
Definition: PointCount.h:211
A forward iterator over array indices with filtering IteratorT can be either IndexIter or ValueIndexI...
Definition: IndexIterator.h:144
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:391
Definition: Exceptions.h:39
Index64 pointCount(const PointDataTreeT &tree, const bool inCoreOnly=false)
Total points in the PointDataTree.
Definition: PointCount.h:198
uint64_t Index64
Definition: Types.h:56
std::string Name
Definition: Name.h:44
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Index64 threadedFilterPointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:152
Index filtering on group membership.
Definition: AttributeGroup.h:157
typename tree::LeafManager< const PointDataTreeT > LeafManagerT
Definition: PointCount.h:123
PointCountOp(const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:125
Index64 inactiveGroupPointCount(const PointDataTreeT &tree, const Name &name, const bool inCoreOnly=false)
Total inactive points in the group in the PointDataTree.
Definition: PointCount.h:253
void reset(const LeafT &leaf)
Definition: IndexFilter.h:124
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:71
Set of Attribute Arrays which tracks metadata about each array.
Index64 filterPointCount(const PointDataTreeT &tree, const FilterT &filter, const bool inCoreOnly=false)
Definition: PointCount.h:165
static Index64 join(Index64 size1, Index64 size2)
Definition: PointCount.h:141