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,
38 typename FilterT = NullFilter>
42 const FilterT&
filter = NullFilter(),
43 bool threaded =
true);
52 template <
typename PointDataGridT,
54 typename FilterT = NullFilter>
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>
85 namespace point_mask_internal {
87 template <
typename LeafT>
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;
152 : mPointDataAccessor(grid.getConstAccessor())
153 , mFilter(filter) { }
157 const auto*
const pointLeaf =
158 mPointDataAccessor.probeConstLeaf(leaf.origin());
165 pointLeaf->beginIndexVoxel(
value.getCoord(), mFilter));
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;
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;
253 template<
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
255 const PointDataGridT&
points,
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(),
267 false, openvdb::TopologyCopy()));
268 typename GridT::Ptr grid = GridT::create(tree);
269 grid->setTransform(points.transform().copy());
273 if (points.constTree().leafCount() == 0)
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>
302 const openvdb::math::Transform& transform,
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>
362 typename MaskT::Ptr>
::type
364 const PointDataGridT&
points,
368 return point_mask_internal::convertPointsToScalar<MaskT>(
373 template<
typename Po
intDataGr
idT,
typename MaskT,
typename FilterT>
375 typename MaskT::Ptr>
::type
377 const PointDataGridT&
points,
378 const openvdb::math::Transform& transform,
384 auto& nonConstPoints =
const_cast<typename AdapterT::NonConstGridType&
>(
points);
387 return point_mask_internal::convertPointsToScalar<MaskT>(
399 #endif // OPENVDB_POINTS_POINT_MASK_HAS_BEEN_INCLUDED
Compute scalar grid from PointDataGrid using a different transform and while evaluating the point fil...
typename TreeT::ValueType ValueType
typename TreeT::LeafNodeType LeafT
void operator()(const PointDataLeafT &leaf, size_t idx) const
PointsToTransformedScalarOp(const math::Transform &targetTransform, const math::Transform &sourceTransform, const FilterT &filter, const DeformerT &deformer, CombinableT &combinable)
void operator()(LeafT &leaf, size_t) const
const ValueType & getValue(const Coord &xyz) const
Return the value of the voxel at the given coordinates.
GLuint GLenum GLenum transform
std::enable_if< std::is_same< typename MaskT::ValueType, bool >::value, typename MaskT::Ptr >::type convertPointsToMask(const PointDataGridT &grid, const FilterT &filter=NullFilter(), bool threaded=true)
Extract a Mask Grid from a Point Data Grid.
#define OPENVDB_USE_VERSION_NAMESPACE
Index filters primarily designed to be used with a FilterIndexIter.
typename LeafT::ValueType ValueT
A no-op filter that can be used when iterating over all indices.
typename PointDataGridT::TreeType::LeafNodeType PointDataLeafT
This adapter allows code that is templated on a Tree type to accept either a Tree type or a Grid type...
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
LeafNodeT * touchLeaf(const Coord &xyz)
Return a pointer to the leaf node that contains voxel (x, y, z). If no such node exists, create one, but preserve the values and active states of all voxels.
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
typename tbb::combinable< GridT > CombinableT
void setOffsetOn(Index offset, const ValueType &val)
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.
GridT::Ptr convertPointsToScalar(const PointDataGridT &points, const FilterT &filter, bool threaded=true)
GLuint GLuint GLsizei GLenum type
PointsToScalarOp(const PointDataGridT &grid, const FilterT &filter)
Combines multiple grids into one by stealing leaf nodes and summing voxel values This class is design...
typename GridT::TreeType::LeafNodeType LeafT
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
GLuint GLuint GLsizei count
typename GridCombinerOp< GridT >::CombinableT CombinableT
void voxelSum(LeafT &leaf, const Index offset, const typename LeafT::ValueType &value)
typename GridT::TreeType TreeT
GridCombinerOp(GridT &grid)
Compute scalar grid from PointDataGrid while evaluating the point filter.
typename GridT::TreeType::ValueType ValueT
Index64 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
GLsizei const GLfloat * value
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
void operator()(const GridT &grid)