37 #ifndef OPENVDB_POINTS_POINT_MASK_HAS_BEEN_INCLUDED 38 #define OPENVDB_POINTS_POINT_MASK_HAS_BEEN_INCLUDED 46 #include <tbb/combinable.h> 48 #include <type_traits> 63 template <
typename PointDataGridT,
64 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type,
65 typename FilterT = NullFilter>
66 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
67 typename MaskT::Ptr>::type
69 const FilterT& filter = NullFilter(),
70 bool threaded =
true);
79 template <
typename PointDataGridT,
80 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type,
81 typename FilterT = NullFilter>
82 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
83 typename MaskT::Ptr>::type
85 const openvdb::math::Transform& transform,
86 const FilterT& filter = NullFilter(),
87 bool threaded =
true);
93 template <
typename LeafT>
94 void reset(LeafT&,
size_t = 0) { }
96 template <
typename IterT>
102 template <
typename DeformerT>
105 static const bool IndexSpace =
false;
112 namespace point_mask_internal {
114 template <
typename LeafT>
115 void voxelSum(LeafT& leaf,
const Index offset,
const typename LeafT::ValueType& value)
123 template <
typename T, Index Log2Dim>
133 template<
typename Gr
idT>
138 using TreeT =
typename GridT::TreeType;
139 using LeafT =
typename TreeT::LeafNodeType;
144 : mTree(grid.tree()) {}
148 for (
auto leaf = grid.tree().beginLeaf(); leaf; ++leaf) {
149 auto* newLeaf = mTree.probeLeaf(leaf->origin());
152 auto& tree = const_cast<GridT&>(grid).tree();
153 mTree.addLeaf(tree.template stealNode<LeafT>(leaf->origin(),
154 zeroVal<ValueType>(),
false));
158 for (
auto iter = leaf->cbeginValueOn(); iter; ++iter) {
171 template <
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
174 using LeafT =
typename GridT::TreeType::LeafNodeType;
175 using ValueT =
typename LeafT::ValueType;
178 const FilterT& filter)
179 : mPointDataAccessor(grid.getConstAccessor())
180 , mFilter(filter) { }
184 const auto*
const pointLeaf =
185 mPointDataAccessor.probeConstLeaf(leaf.origin());
190 for (
auto value = leaf.beginValueOn(); value; ++value) {
192 pointLeaf->beginIndexVoxel(value.getCoord(), mFilter));
194 value.setValue(
ValueT(count));
197 value.setValueOn(
false);
203 const typename PointDataGridT::ConstAccessor mPointDataAccessor;
204 const FilterT& mFilter;
210 template <
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT,
typename DeformerT>
214 using ValueT =
typename GridT::TreeType::ValueType;
220 const FilterT& filter,
221 const DeformerT& deformer,
223 : mTargetTransform(targetTransform)
224 , mSourceTransform(sourceTransform)
226 , mDeformer(deformer)
227 , mCombinable(combinable) { }
231 DeformerT deformer(mDeformer);
233 auto& grid = mCombinable.local();
234 auto& countTree = grid.tree();
237 deformer.reset(leaf, idx);
239 auto handle = HandleT::create(leaf.constAttributeArray(
"P"));
241 for (
auto iter = leaf.beginIndexOn(mFilter); iter; iter++) {
245 Vec3d position = handle->get(*iter) + iter.getCoord().asVec3d();
251 deformer.template apply<decltype(iter)>(position, iter);
252 position = mSourceTransform.indexToWorld(position);
255 position = mSourceTransform.indexToWorld(position);
256 deformer.template apply<decltype(iter)>(position, iter);
261 const Coord ijk = mTargetTransform.worldToIndexCellCentered(position);
272 const openvdb::math::Transform& mTargetTransform;
273 const openvdb::math::Transform& mSourceTransform;
274 const FilterT& mFilter;
275 const DeformerT& mDeformer;
276 CombinableT& mCombinable;
280 template<
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
282 const PointDataGridT& points,
283 const FilterT& filter,
284 bool threaded =
true)
288 using GridTreeT =
typename GridT::TreeType;
289 using ValueT =
typename GridTreeT::ValueType;
293 typename GridTreeT::Ptr tree(
new GridTreeT(points.constTree(),
295 typename GridT::Ptr grid = GridT::create(tree);
296 grid->setTransform(points.transform().copy());
300 if (points.constTree().leafCount() == 0)
return grid;
304 if (std::is_same<ValueT, bool>::value && filter.state() ==
index::ALL)
return grid;
314 leafManager.
foreach(pointsToScalarOp, threaded);
319 leafManager.
foreach(pointsToScalarOp, threaded);
326 template<
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT,
typename DeformerT>
328 PointDataGridT& points,
329 const openvdb::math::Transform& transform,
330 const FilterT& filter,
331 const DeformerT& deformer,
332 bool threaded =
true)
342 const openvdb::math::Transform& pointsTransform = points.constTransform();
344 if (transform == pointsTransform && std::is_same<NullDeformer, DeformerT>()) {
345 return convertPointsToScalar<GridT>(points, filter, threaded);
348 typename GridT::Ptr grid = GridT::create();
349 grid->setTransform(transform.copy());
353 if (points.constTree().leafCount() == 0)
return grid;
357 CombinableT combiner;
364 transform, pointsTransform, nullFilter, deformer, combiner);
365 leafManager.foreach(pointsToScalarOp, threaded);
368 transform, pointsTransform, filter, deformer, combiner);
369 leafManager.foreach(pointsToScalarOp, threaded);
374 CombinerOpT combineOp(*grid);
375 combiner.combine_each(combineOp);
387 template<
typename Po
intDataGr
idT,
typename MaskT,
typename FilterT>
388 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
389 typename MaskT::Ptr>::type
391 const PointDataGridT& points,
392 const FilterT& filter,
395 return point_mask_internal::convertPointsToScalar<MaskT>(
396 points, filter, threaded);
400 template<
typename Po
intDataGr
idT,
typename MaskT,
typename FilterT>
401 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
402 typename MaskT::Ptr>::type
404 const PointDataGridT& points,
405 const openvdb::math::Transform& transform,
406 const FilterT& filter,
411 auto& nonConstPoints = const_cast<typename AdapterT::NonConstGridType&>(points);
414 return point_mask_internal::convertPointsToScalar<MaskT>(
415 nonConstPoints, transform, filter, deformer, threaded);
425 template <
typename PointDataGridT,
426 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type>
428 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
429 typename MaskT::Ptr>::type
431 const std::vector<Name>& includeGroups,
432 const std::vector<Name>& excludeGroups)
434 auto leaf = grid.tree().cbeginLeaf();
435 if (!leaf)
return MaskT::create();
436 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
441 template <
typename PointDataGridT,
442 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type>
444 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
445 typename MaskT::Ptr>::type
447 const openvdb::math::Transform& transform,
448 const std::vector<Name>& includeGroups,
449 const std::vector<Name>& excludeGroups)
451 auto leaf = grid.tree().cbeginLeaf();
452 if (!leaf)
return MaskT::create();
453 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
462 #endif // OPENVDB_POINTS_POINT_MASK_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
PointsToScalarOp(const PointDataGridT &grid, const FilterT &filter)
Definition: PointMask.h:177
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:77
Index32 Index
Definition: Types.h:61
uint64_t Index64
Definition: Types.h:60
typename LeafT::ValueType ValueT
Definition: PointMask.h:175
typename tbb::combinable< GridT > CombinableT
Definition: PointMask.h:136
Vec3< double > Vec3d
Definition: Vec3.h:679
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:518
typename GridT::TreeType TreeT
Definition: PointMask.h:138
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
Definition: PointDataGrid.h:212
Index filters primarily designed to be used with a FilterIndexIter.
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1087
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:136
typename TreeT::LeafNodeType LeafT
Definition: PointMask.h:139
void operator()(LeafT &leaf, size_t) const
Definition: PointMask.h:182
typename GridT::TreeType::LeafNodeType LeafT
Definition: PointMask.h:174
T ValueType
Definition: PointDataGrid.h:270
GridT::Ptr convertPointsToScalar(PointDataGridT &points, const openvdb::math::Transform &transform, const FilterT &filter, const DeformerT &deformer, bool threaded=true)
Definition: PointMask.h:327
Definition: Exceptions.h:40
void setOffsetOn(Index offset, const ValueType &val)
Definition: PointDataGrid.h:1129
Definition: IndexFilter.h:163
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
void voxelSum(PointDataLeafNode< T, Log2Dim > &leaf, const Index offset, const typename PointDataLeafNode< T, Log2Dim >::ValueType &value)
Definition: PointMask.h:124
GridCombinerOp(GridT &grid)
Definition: PointMask.h:143
Definition: ValueAccessor.h:220
LeafNodeT * touchLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists,...
Definition: ValueAccessor.h:386
OPENVDB_DEPRECATED std::enable_if< std::is_same< typename MaskT::ValueType, bool >::value, typename MaskT::Ptr >::type convertPointsToMask(const PointDataGridT &grid, const openvdb::math::Transform &transform, const std::vector< Name > &includeGroups, const std::vector< Name > &excludeGroups)
Definition: PointMask.h:446
Definition: AttributeArray.h:832
Definition: IndexIterator.h:70
Compute scalar grid from PointDataGrid while evaluating the point filter.
Definition: PointMask.h:172
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
typename TreeT::ValueType ValueType
Definition: PointMask.h:140
void operator()(const GridT &grid)
Definition: PointMask.h:146
Combines multiple grids into one by stealing leaf nodes and summing voxel values This class is design...
Definition: PointMask.h:134
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
void foreach(const LeafOp &op, bool threaded=true, size_t grainSize=1)
Threaded method that applies a user-supplied functor to each leaf node in the LeafManager.
Definition: LeafManager.h:524
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:341