20 #ifndef OPENVEB_POINTS_TRANSFER_HAS_BEEN_INCLUDED
21 #define OPENVEB_POINTS_TRANSFER_HAS_BEEN_INCLUDED
31 #include <type_traits>
164 template <
typename PointDataTreeOrGridT,
166 typename FilterT = NullFilter,
167 typename InterrupterT = util::NullInterrupter>
171 const FilterT&
filter = NullFilter(),
172 InterrupterT* interrupter =
nullptr);
185 : mSourceTransform(st)
186 , mTargetTransform(tt) {}
188 template <
typename T>
195 template <
typename T>
214 template <
typename ...TreeTypes>
217 static const size_t Size =
sizeof...(TreeTypes);
231 : mTreeArray(other.mTreeArray)
235 mBuffers.fill(
nullptr);
236 mMasks.fill(
nullptr);
243 template <
size_t Idx>
249 template <
size_t Idx>
255 template <
size_t Idx>
259 template <
size_t Idx>
261 inline const NodeMaskT*
mask(
const size_t idx)
const {
return mMasks[idx]; }
263 template <
typename FunctorT>
264 inline void foreach(
const FunctorT& functor);
268 std::array<void*, Size> mBuffers;
269 std::array<NodeMaskT*, Size> mMasks;
274 template <
typename TreeT>
279 using NodeMaskT =
typename TreeType::LeafNodeType::NodeMaskType;
282 "One or more template arguments to VolumeTransfer "
283 "are not a valid openvdb::Tree type.");
305 if (
auto leaf = mTree->probeLeaf(origin)) {
306 mBuffer = leaf->buffer().data();
307 mMask = &(leaf->getValueMask());
332 namespace transfer_internal
334 template<
typename T,
typename F,
size_t... Is>
335 void foreach(T&&
t,
const F&
func, std::integer_sequence<size_t, Is...>)
337 auto init = { (
func(std::get<Is>(
t), Is), 0)... };
341 template<
typename T,
typename F,
size_t... Is>
342 void foreach(
void**
buffers,
const F& func, std::integer_sequence<size_t, Is...>)
344 int init[
sizeof...(Is)] = {
346 (*(buffers + Is)), Is), 0)...
350 template<
typename T,
template <
typename>
class R,
typename F,
size_t... Is>
351 void foreach(
void** buffers,
const F& func, std::integer_sequence<size_t, Is...>)
353 int init[
sizeof...(Is)] = {
355 (*(buffers + Is)), Is), 0)...
360 template <
typename ...TreeTypes>
362 : mTreeArray({ trees... })
369 "One or more template arguments to VolumeTransfer "
370 "are not a valid openvdb::Tree type.");
372 }, std::make_integer_sequence<size_t, Size>());
378 template <
typename ...TreeTypes>
382 [&](
auto&& tree,
const size_t i) {
384 if (
auto leaf = tree->probeLeaf(origin)) {
385 mBuffers[i] =
static_cast<void*
>(leaf->buffer().data());
386 mMasks[i] = &(leaf->getValueMask());
392 }, std::make_integer_sequence<size_t, Size>());
395 template <
typename ...TreeTypes>
396 template <
typename FunctorT>
399 transfer_internal::foreach<TreeTupleT, TypeResolver>(
mBuffers.data(), functor,
400 std::make_integer_sequence<size_t, Size>());
403 namespace transfer_internal
405 template <
typename TransferT,
407 typename PointFilterT = points::NullFilter,
414 static const Index DIM = TopologyT::LeafNodeType::DIM;
419 const TransferT& transfer,
420 const PointFilterT&
filter = PointFilterT(),
421 InterrupterT* interrupter =
nullptr)
422 : mPointAccessor(tree)
423 , mTransfer(transfer)
425 , mInterrupter(interrupter) {}
430 thread::cancelGroupExecution();
434 const Coord& origin = leaf.origin();
435 auto&
mask = leaf.getValueMask();
440 if (
mask.isConstant(state)) {
442 else bounds = leaf.getNodeBoundingBox();
447 leaf.evalActiveBoundingBox(bounds);
451 mTransfer.initialize(origin, idx, bounds);
454 this->transform<>(
search);
457 const Coord
min = (search.min() & ~(
DIM-1));
458 const Coord&
max = search.max();
459 PointFilterT localFilter(mFilter);
463 for (leafOrigin[0] = min[0]; leafOrigin[0] <= max[0]; leafOrigin[0]+=
DIM32) {
464 for (leafOrigin[1] = min[1]; leafOrigin[1] <= max[1]; leafOrigin[1]+=
DIM32) {
465 for (leafOrigin[2] = min[2]; leafOrigin[2] <= max[2]; leafOrigin[2]+=
DIM32) {
469 pbox.intersect(search);
470 if (pbox.empty())
continue;
473 const auto* pointLeaf = mPointAccessor.probeConstLeaf(leafOrigin);
474 if (!pointLeaf)
continue;
475 if (!mTransfer.startPointLeaf(*pointLeaf))
continue;
476 localFilter.reset(*pointLeaf);
479 const Coord& pmin(pbox.min());
480 const Coord& pmax(pbox.max());
481 for (Coord ijk = pmin; ijk.x() <= pmax.x(); ++ijk.x()) {
483 for (ijk.y() = pmin.y(); ijk.y() <= pmax.y(); ++ijk.y()) {
485 for (ijk.z() = pmin.z(); ijk.z() <= pmax.z(); ++ijk.z()) {
489 const Index end = pointLeaf->getValue(index);
490 Index id = (index == 0) ? 0 :
Index(pointLeaf->getValue(index - 1));
491 for (;
id <
end; ++
id) {
492 if (!localFilter.valid(&
id))
continue;
493 mTransfer.rasterizePoint(ijk,
id, bounds);
499 if (!mTransfer.endPointLeaf(*pointLeaf)) {
501 if (!mTransfer.finalize(origin, idx)) {
511 if (!mTransfer.finalize(origin, idx)) {
518 for (
auto leaf = range.
begin(); leaf; ++leaf) {
519 (*this)(*leaf, leaf.pos());
525 template <
typename EnableT = TransferT>
531 const BBoxd bbox(bounds.min().asVec3d(), bounds.max().asVec3d());
536 template <
typename EnableT = TransferT>
541 const PointDataGrid::ConstAccessor mPointAccessor;
542 mutable TransferT mTransfer;
543 const PointFilterT& mFilter;
544 InterrupterT* mInterrupter;
552 template <
typename PointDataTreeOrGridT,
555 typename InterrupterT>
560 InterrupterT* interrupter)
564 "Provided points to rasterize is not a derived TreeBase type.");
568 auto&
topology = transfer.topology();
572 raster(tree, transfer, filter, interrupter);
580 #endif //OPENVEB_POINTS_TRANSFER_HAS_BEEN_INCLUDED
VolumeTransfer(const VolumeTransfer &other)
const NodeMaskT * mask(const size_t idx) const
typename TreeType< 0 >::LeafNodeType::NodeMaskType NodeMaskT
VolumeTransfer(const VolumeTransfer &other)
GLdouble GLdouble GLint GLint const GLdouble * points
void rasterize(const PointDataTreeOrGridT &points, TransferT &transfer, const FilterT &filter=NullFilter(), InterrupterT *interrupter=nullptr)
Perform potentially complex rasterization from a user defined transfer scheme.
typename T::ValueType Type
typename LeafManagerT::LeafNodeType LeafNodeT
GLsizei const GLfloat * value
const ValueType * buffer() const
typename TreeType::LeafNodeType::NodeMaskType NodeMaskT
void foreach(const FunctorT &functor)
#define OPENVDB_USE_VERSION_NAMESPACE
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
**But if you need a result
Base class for interrupters.
NodeMaskT * mask(const size_t idx)
#define OPENVDB_ASSERT(X)
GLint GLint GLsizei GLint GLenum GLenum type
void initialize(const Coord &origin, const size_t, const CoordBBox &)
GT_API const UT_StringHolder topology
const NodeMaskT * mask() const
VolumeTransfer(TreeType &tree)
std::tuple< TreeTypes *...> TreeTupleT
void initialize(const Coord &origin, const size_t, const CoordBBox &)
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
HUSD_API const char * raster()
GridTypes::Transform< internal::ToTreeType > TreeTypes
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.
auto search(const T &set, const V &val) -> std::pair< bool, decltype(std::begin(detail::smart_deref(set)))>
A search function.
static NonConstTreeType & tree(NonConstTreeType &t)
const ValueType< Idx > * buffer() const
GT_API const UT_StringHolder st
typename std::tuple_element< Idx, std::tuple< TreeTypes...>>::type TreeType
ValueType< Idx > * buffer()
TreeType< 0 > & topology()
void foreach(T &&t, const F &func, std::integer_sequence< size_t, Is...>)
void operator()(LeafNodeT &leaf, const size_t idx) const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
VolumeTransfer(TreeType *tree)
void operator()(const typename LeafManagerT::LeafRange &range) const
const ValueType * buffer() const
The VolumeTransfer module provides methods to automatically setup and access destination buffers for ...
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 >>> PointDataTree
Point index tree configured to match the default VDB configurations.
const NodeMaskT * mask() const
typename TreeType< Idx >::ValueType ValueType
VolumeTransfer(TreeTypes &...trees)
bool wasInterrupted(T *i, int percent=-1)
const NodeMaskT * mask() const
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
VolumeTransfer(TreeTypes *...trees)
typename TreeType::ValueType ValueType
RasterizePoints(const points::PointDataTree &tree, const TransferT &transfer, const PointFilterT &filter=PointFilterT(), InterrupterT *interrupter=nullptr)
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
static const Index LOG2DIM