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 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
66 typename MaskT::Ptr>::type
68 const std::vector<Name>& includeGroups = std::vector<Name>(),
69 const std::vector<Name>& excludeGroups = std::vector<Name>());
78 template <
typename PointDataGridT,
79 typename MaskT =
typename PointDataGridT::template ValueConverter<bool>::Type>
80 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
81 typename MaskT::Ptr>::type
83 const openvdb::math::Transform& transform,
84 const std::vector<Name>& includeGroups = std::vector<Name>(),
85 const std::vector<Name>& excludeGroups = std::vector<Name>());
91 namespace point_mask_internal {
95 template<
typename Gr
idT>
100 using TreeT =
typename GridT::TreeType;
101 using LeafT =
typename TreeT::LeafNodeType;
106 : mTree(grid.tree()) {}
110 for (
auto leaf = grid.tree().beginLeaf(); leaf; ++leaf) {
111 auto* newLeaf = mTree.probeLeaf(leaf->origin());
114 auto& tree =
const_cast<GridT&
>(grid).tree();
115 mTree.addLeaf(tree.template stealNode<LeafT>(leaf->origin(),
116 zeroVal<ValueType>(),
false));
120 for (
auto iter = leaf->cbeginValueOn(); iter; ++iter) {
121 newLeaf->modifyValue(iter.getCoord(),
SumOp(*iter));
133 template <
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
136 using TreeT =
typename GridT::TreeType;
138 using ValueT =
typename TreeT::LeafNodeType::ValueType;
141 const FilterT& filter)
142 : mPointDataAccessor(grid.getConstAccessor())
143 , mFilter(filter) { }
145 void operator()(
const typename LeafManagerT::LeafRange& range)
const {
147 for (
auto leaf = range.begin(); leaf; ++leaf) {
149 const auto*
const pointLeaf =
150 mPointDataAccessor.probeConstLeaf(leaf->origin());
155 for (
auto value = leaf->beginValueOn(); value; ++value) {
157 pointLeaf->beginIndexVoxel(value.getCoord(), mFilter));
159 value.setValue(static_cast<ValueT>(count));}
162 value.setValueOn(
false);
169 const typename PointDataGridT::ConstAccessor mPointDataAccessor;
170 const FilterT& mFilter;
176 template <
typename Gr
idT,
typename Po
intDataGr
idT,
typename FilterT>
180 using ValueType =
typename GridT::TreeType::LeafNodeType::ValueType;
186 const FilterT& filter,
188 : mNewTransform(newTransform)
189 , mTransform(transform)
191 , mCombinable(combinable) { }
195 auto& grid = mCombinable.local();
196 auto& countTree = grid.tree();
199 for (
auto leaf = range.
begin(); leaf; ++leaf) {
201 auto handle = HandleT::create(leaf->constAttributeArray(
"P"));
203 for (
auto iter = leaf->beginIndexOn(mFilter); iter; iter++) {
204 const Vec3d position = mTransform.indexToWorld(handle->get(*iter) +
205 iter.getCoord().asVec3d());
206 const Coord ijk = mNewTransform.worldToIndexCellCentered(position);
214 const openvdb::math::Transform& mNewTransform;
215 const openvdb::math::Transform& mTransform;
216 const FilterT& mFilter;
221 template<
typename Po
intDataGr
idT,
typename Gr
idT>
223 const PointDataGridT& points,
224 const std::vector<Name>& includeGroups,
225 const std::vector<Name>& excludeGroups)
229 using GridTreeT =
typename GridT::TreeType;
230 using ValueT =
typename GridTreeT::ValueType;
234 typename GridTreeT::Ptr tree(
new GridTreeT(points.constTree(),
236 typename GridT::Ptr grid = GridT::create(tree);
237 grid->setTransform(points.transform().copy());
241 if (points.constTree().leafCount() == 0)
return grid;
243 const bool useGroup = !includeGroups.empty() || !excludeGroups.empty();
247 if (std::is_same<ValueT, bool>::value && !useGroup)
return grid;
255 const auto leaf = points.constTree().cbeginLeaf();
256 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
259 tbb::parallel_for(leafManager.
leafRange(), pointsToScalarOp);
265 tbb::parallel_for(leafManager.
leafRange(), pointsToScalarOp);
272 template<
typename Po
intDataGr
idT,
typename Gr
idT>
274 const PointDataGridT& points,
275 const openvdb::math::Transform& transform,
276 const std::vector<Name>& includeGroups,
277 const std::vector<Name>& excludeGroups)
287 const openvdb::math::Transform& pointsTransform = points.constTransform();
289 if (transform == pointsTransform) {
290 return convertPointsToScalar<PointDataGridT, GridT>(
291 points, includeGroups, excludeGroups);
294 typename GridT::Ptr grid = GridT::create();
295 grid->setTransform(transform.copy());
299 if (points.constTree().leafCount() == 0)
return grid;
303 CombinableT combiner;
307 const bool useGroup = !includeGroups.empty() || !excludeGroups.empty();
310 const auto leaf = points.constTree().cbeginLeaf();
311 MultiGroupFilter filter(includeGroups, excludeGroups, leaf->attributeSet());
313 transform, pointsTransform, filter, combiner);
314 tbb::parallel_for(leafManager.leafRange(), pointsToScalarOp);
319 transform, pointsTransform, filter, combiner);
320 tbb::parallel_for(leafManager.leafRange(), pointsToScalarOp);
325 CombinerOpT combineOp(*grid);
326 combiner.combine_each(combineOp);
338 template<
typename Po
intDataGr
idT,
typename MaskT>
339 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
340 typename MaskT::Ptr>::type
342 const PointDataGridT& points,
343 const std::vector<Name>& includeGroups,
344 const std::vector<Name>& excludeGroups)
346 return point_mask_internal::convertPointsToScalar<PointDataGridT, MaskT>(
347 points, includeGroups, excludeGroups);
351 template<
typename Po
intDataGr
idT,
typename MaskT>
352 inline typename std::enable_if<std::is_same<typename MaskT::ValueType, bool>::value,
353 typename MaskT::Ptr>::type
355 const PointDataGridT& points,
356 const openvdb::math::Transform& transform,
357 const std::vector<Name>& includeGroups,
358 const std::vector<Name>& excludeGroups)
360 return point_mask_internal::convertPointsToScalar<PointDataGridT, MaskT>(
361 points, transform, includeGroups, excludeGroups);
372 #endif // OPENVDB_POINTS_POINT_MASK_HAS_BEEN_INCLUDED PointsToScalarOp(const PointDataGridT &grid, const FilterT &filter)
Definition: PointMask.h:140
typename GridT::TreeType TreeT
Definition: PointMask.h:136
void modifyValue(const Coord &xyz, const ModifyOp &op)
Apply a functor to the value of the voxel at the given coordinates and mark the voxel as active...
Definition: ValueAccessor.h:321
typename TreeT::LeafNodeType LeafT
Definition: PointMask.h:101
uint64_t Index64
Definition: Types.h:59
LeafRange leafRange(size_t grainsize=1) const
Return a TBB-compatible LeafRange.
Definition: LeafManager.h:386
A no-op filter that can be used when iterating over all indices.
Definition: IndexIterator.h:62
Definition: ValueAccessor.h:219
typename tree::LeafManager< TreeT > LeafManagerT
Definition: PointMask.h:137
Vec3< double > Vec3d
Definition: Vec3.h:679
Signed (x, y, z) 32-bit integer coordinates.
Definition: Coord.h:51
GridCombinerOp(GridT &grid)
Definition: PointMask.h:105
Definition: LeafManager.h:127
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition: PointMask.h:145
Iterator begin() const
Definition: LeafManager.h:181
Compute scalar grid from PointDataGrid while evaluating the point filter.
Definition: PointMask.h:134
typename TreeT::LeafNodeType::ValueType ValueT
Definition: PointMask.h:138
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 iterCount(const IterT &iter)
Count up the number of times the iterator can iterate.
Definition: IndexIterator.h:313
Definition: Exceptions.h:39
typename GridT::TreeType TreeT
Definition: PointMask.h:100
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition: LeafManager.h:110
GridT::Ptr convertPointsToScalar(const PointDataGridT &points, const openvdb::math::Transform &transform, const std::vector< Name > &includeGroups, const std::vector< Name > &excludeGroups)
Definition: PointMask.h:273
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=std::vector< Name >(), const std::vector< Name > &excludeGroups=std::vector< Name >())
Extract a Mask Grid from a Point Data Grid using a new transform.
Definition: PointMask.h:354
Definition: IndexFilter.h:104
typename TreeT::ValueType ValueType
Definition: PointMask.h:102
Tag dispatch class that distinguishes topology copy constructors from deep copy constructors.
Definition: Types.h:508
Definition: AttributeArray.h:644
Attribute-owned data structure for points. Point attributes are stored in leaf nodes and ordered by v...
typename tbb::combinable< GridT > CombinableT
Definition: PointMask.h:98
Combines multiple grids into one by stealing leaf nodes and summing voxel values This class is design...
Definition: PointMask.h:96
#define OPENVDB_USE_VERSION_NAMESPACE
Definition: version.h:188
void operator()(const GridT &grid)
Definition: PointMask.h:108