10 #ifndef OPENVDB_POINTS_POINT_MASK_HAS_BEEN_INCLUDED
11 #define OPENVDB_POINTS_POINT_MASK_HAS_BEEN_INCLUDED
19 #include <tbb/combinable.h>
21 #include <type_traits>
36 template <
typename PointDataGridT,
37 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type,
38 typename FilterT = NullFilter>
39 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
40 typename MaskT::Ptr>::type
42 const FilterT& filter = NullFilter(),
43 bool threaded =
true);
52 template <
typename PointDataGridT,
53 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type,
54 typename FilterT = NullFilter>
55 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
56 typename MaskT::Ptr>::type
58 const openvdb::math::Transform& transform,
59 const FilterT& filter = NullFilter(),
60 bool threaded =
true);
66 template <
typename LeafT>
67 void reset(LeafT&,
size_t = 0) { }
69 template <
typename IterT>
75 template <
typename DeformerT>
78 static const bool IndexSpace =
false;
85 namespace point_mask_internal {
87 template <
typename LeafT>
88 void voxelSum(LeafT& leaf,
const Index offset,
const typename LeafT::ValueType& value)
96 template <
typename T, Index Log2Dim>
106 template<
typename Gr
idT>
111 using TreeT =
typename GridT::TreeType;
112 using LeafT =
typename TreeT::LeafNodeType;
117 : mTree(grid.tree()) {}
121 for (
auto leaf = grid.tree().beginLeaf(); leaf; ++leaf) {
122 auto* newLeaf = mTree.probeLeaf(leaf->origin());
125 auto& tree =
const_cast<GridT&
>(grid).tree();
126 mTree.addLeaf(tree.template stealNode<LeafT>(leaf->origin(),
127 zeroVal<ValueType>(),
false));
131 for (
auto iter = leaf->cbeginValueOn(); iter; ++iter) {
144 template <
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
147 using LeafT =
typename GridT::TreeType::LeafNodeType;
148 using ValueT =
typename LeafT::ValueType;
151 const FilterT& filter)
152 : mPointDataAccessor(grid.getConstAccessor())
153 , mFilter(filter) { }
157 const auto*
const pointLeaf =
158 mPointDataAccessor.probeConstLeaf(leaf.origin());
163 for (
auto value = leaf.beginValueOn(); value; ++value) {
165 pointLeaf->beginIndexVoxel(value.getCoord(), mFilter));
167 value.setValue(
ValueT(count));
170 value.setValueOn(
false);
176 const typename PointDataGridT::ConstAccessor mPointDataAccessor;
177 const FilterT& mFilter;
183 template <
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT,
typename DeformerT>
187 using ValueT =
typename GridT::TreeType::ValueType;
193 const FilterT& filter,
194 const DeformerT& deformer,
196 : mTargetTransform(targetTransform)
197 , mSourceTransform(sourceTransform)
199 , mDeformer(deformer)
200 , mCombinable(combinable) { }
204 DeformerT deformer(mDeformer);
206 auto& grid = mCombinable.local();
207 auto& countTree = grid.tree();
210 deformer.reset(leaf, idx);
212 auto handle = HandleT::create(leaf.constAttributeArray(
"P"));
214 for (
auto iter = leaf.beginIndexOn(mFilter); iter; iter++) {
218 Vec3d position = handle->get(*iter) + iter.getCoord().asVec3d();
224 deformer.template apply<decltype(iter)>(position, iter);
225 position = mSourceTransform.indexToWorld(position);
228 position = mSourceTransform.indexToWorld(position);
229 deformer.template apply<decltype(iter)>(position, iter);
234 const Coord ijk = mTargetTransform.worldToIndexCellCentered(position);
245 const openvdb::math::Transform& mTargetTransform;
246 const openvdb::math::Transform& mSourceTransform;
247 const FilterT& mFilter;
248 const DeformerT& mDeformer;
249 CombinableT& mCombinable;
253 template<
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
255 const PointDataGridT& points,
256 const FilterT& filter,
257 bool threaded =
true)
261 using GridTreeT =
typename GridT::TreeType;
262 using ValueT =
typename GridTreeT::ValueType;
266 typename GridTreeT::Ptr tree(
new GridTreeT(points.constTree(),
268 typename GridT::Ptr grid = GridT::create(tree);
269 grid->setTransform(points.transform().copy());
273 if (points.constTree().leafCount() == 0)
return grid;
277 if (std::is_same<ValueT, bool>::value && filter.state() ==
index::ALL)
return grid;
287 leafManager.
foreach(pointsToScalarOp, threaded);
292 leafManager.
foreach(pointsToScalarOp, threaded);
299 template<
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT,
typename DeformerT>
301 PointDataGridT& points,
302 const openvdb::math::Transform& transform,
303 const FilterT& filter,
304 const DeformerT& deformer,
305 bool threaded =
true)
315 const openvdb::math::Transform& pointsTransform = points.constTransform();
317 if (transform == pointsTransform && std::is_same<NullDeformer, DeformerT>()) {
318 return convertPointsToScalar<GridT>(points, filter, threaded);
321 typename GridT::Ptr grid = GridT::create();
322 grid->setTransform(transform.copy());
326 if (points.constTree().leafCount() == 0)
return grid;
330 CombinableT combiner;
337 transform, pointsTransform, nullFilter, deformer, combiner);
338 leafManager.
foreach(pointsToScalarOp, threaded);
341 transform, pointsTransform, filter, deformer, combiner);
342 leafManager.
foreach(pointsToScalarOp, threaded);
347 CombinerOpT combineOp(*grid);
348 combiner.combine_each(combineOp);
360 template<
typename Po
intDataGr
idT,
typename MaskT,
typename FilterT>
361 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
362 typename MaskT::Ptr>::type
364 const PointDataGridT& points,
365 const FilterT& filter,
368 return point_mask_internal::convertPointsToScalar<MaskT>(
369 points, filter, threaded);
373 template<
typename Po
intDataGr
idT,
typename MaskT,
typename FilterT>
374 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
375 typename MaskT::Ptr>::type
377 const PointDataGridT& points,
378 const openvdb::math::Transform& transform,
379 const FilterT& filter,
384 auto& nonConstPoints =
const_cast<typename AdapterT::NonConstGridType&
>(points);
387 return point_mask_internal::convertPointsToScalar<MaskT>(
388 nonConstPoints, transform, filter, deformer, threaded);
Index filters primarily designed to be used with a FilterIndexIter.
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: openvdb/Types.h:542
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:26
Definition: AttributeArray.h:844
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:51
Definition: PointDataGrid.h:233
void setOffsetOn(Index offset, const ValueType &val)
Definition: PointDataGrid.h:1098
T ValueType
Definition: PointDataGrid.h:239
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:85
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:483
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
Definition: LeafNode.h:1063
Definition: ValueAccessor.h:183
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:348
Vec3< double > Vec3d
Definition: Vec3.h:668
@ ALL
Definition: IndexIterator.h:43
void voxelSum(PointDataLeafNode< T, Log2Dim > &leaf, const Index offset, const typename PointDataLeafNode< T, Log2Dim >::ValueType &value)
Definition: PointMask.h:97
GridT::Ptr convertPointsToScalar(PointDataGridT &points, const openvdb::math::Transform &transform, const FilterT &filter, const DeformerT &deformer, bool threaded=true)
Definition: PointMask.h:300
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:314
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 FilterT &filter=NullFilter(), bool threaded=true)
Extract a Mask Grid from a Point Data Grid using a new transform.
Definition: PointMask.h:376
Index32 Index
Definition: openvdb/Types.h:32
uint64_t Index64
Definition: openvdb/Types.h:31
Definition: openvdb/Exceptions.h:13
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
Definition: Grid.h:1078
Combines multiple grids into one by stealing leaf nodes and summing voxel values This class is design...
Definition: PointMask.h:108
typename TreeT::ValueType ValueType
Definition: PointMask.h:113
typename GridT::TreeType TreeT
Definition: PointMask.h:111
typename TreeT::LeafNodeType LeafT
Definition: PointMask.h:112
GridCombinerOp(GridT &grid)
Definition: PointMask.h:116
void operator()(const GridT &grid)
Definition: PointMask.h:119
typename tbb::combinable< GridT > CombinableT
Definition: PointMask.h:109
Compute scalar grid from PointDataGrid while evaluating the point filter.
Definition: PointMask.h:146
void operator()(LeafT &leaf, size_t) const
Definition: PointMask.h:155
PointsToScalarOp(const PointDataGridT &grid, const FilterT &filter)
Definition: PointMask.h:150
typename GridT::TreeType::LeafNodeType LeafT
Definition: PointMask.h:147
typename LeafT::ValueType ValueT
Definition: PointMask.h:148
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition: version.h:101
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:153