20#ifndef OPENVEB_POINTS_TRANSFER_HAS_BEEN_INCLUDED 
   21#define OPENVEB_POINTS_TRANSFER_HAS_BEEN_INCLUDED 
   29#include <openvdb/thread/Threading.h> 
  164template <
typename PointDataTreeOrGridT,
 
  166    typename FilterT = NullFilter,
 
  167    typename InterrupterT = util::NullInterrupter>
 
  169rasterize(
const PointDataTreeOrGridT& points,
 
  171          const FilterT& filter = NullFilter(),
 
  172          InterrupterT* interrupter = 
nullptr);
 
  185        : mSourceTransform(st)
 
  186        , mTargetTransform(tt) {}
 
 
  188    template <
typename T>
 
  191        const auto result = mSourceTransform.indexToWorld(value);
 
  192        return mTargetTransform.worldToIndex(result);
 
 
  195    template <
typename T>
 
  198        const auto result = mTargetTransform.indexToWorld(value);
 
  199        return mSourceTransform.worldToIndex(result);
 
 
 
  214template <
typename ...TreeTypes>
 
  217    static const size_t Size = 
sizeof...(TreeTypes);
 
  220    template <
size_t Idx> 
using TreeType = 
typename std::tuple_element<Idx, std::tuple<
TreeTypes...>>::type;
 
  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;
 
  274template <
typename TreeT>
 
  279    using NodeMaskT = 
typename TreeType::LeafNodeType::NodeMaskType;
 
  281    static_assert(std::is_base_of<TreeBase, TreeType>::value,
 
  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());
 
 
  327    TreeType* 
const mTree;
 
 
  334template<
typename T, 
typename F, 
size_t... Is>
 
  335void foreach(T&& t, 
const F& func, std::integer_sequence<size_t, Is...>)
 
  337    auto init = { (func(std::get<Is>(t), Is), 0)... };
 
 
  341template<
typename T, 
typename F, 
size_t... Is>
 
  342void foreach(
void** buffers, 
const F& func, std::integer_sequence<size_t, Is...>)
 
  344    int init[
sizeof...(Is)] = {
 
  345        (func(
static_cast<typename std::tuple_element<Is, T>::type*
> 
  346            (*(buffers + Is)), Is), 0)...
 
 
  350template<
typename T, 
template <
typename> 
class R, 
typename F, 
size_t... Is>
 
  351void foreach(
void** buffers, 
const F& func, std::integer_sequence<size_t, Is...>)
 
  353    int init[
sizeof...(Is)] = {
 
  354        (func(
static_cast<typename R<typename std::tuple_element<Is, T>::type
>::Type*>
 
  355           (*(buffers + Is)), Is), 0)...
 
 
 
  360template <
typename ...TreeTypes>
 
  362    : mTreeArray({ trees... })
 
  367        using TreeT = 
typename std::remove_pointer<
typename std::decay<
decltype(
tree)>::type>::type;
 
  368        static_assert(std::is_base_of<TreeBase, TreeT>::value,
 
  369            "One or more template arguments to VolumeTransfer " 
  370            "are not a valid openvdb::Tree type.");
 
  372    }, std::make_integer_sequence<size_t, Size>());
 
  374    mBuffers.fill(
nullptr);
 
  375    mMasks.fill(
nullptr);
 
 
  378template <
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());
 
  389                mBuffers[i] = 
nullptr;
 
  392        }, std::make_integer_sequence<size_t, Size>());
 
 
  395template <
typename ...TreeTypes>
 
  396template <
typename FunctorT>
 
  400        std::make_integer_sequence<size_t, Size>());
 
 
 
  405template <
typename TransferT,
 
  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);
 
  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) {
 
  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);
 
  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()) {
 
  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)) {
 
 
  516    void operator()(
const typename LeafManagerT::LeafRange& range)
 const 
  518        for (
auto leaf = range.begin(); leaf; ++leaf) {
 
  519            (*this)(*leaf, leaf.pos());
 
 
  525    template <
typename EnableT = TransferT>
 
  526    typename std::enable_if<std::is_base_of<TransformTransfer, EnableT>::value>::type
 
  536    template <
typename EnableT = TransferT>
 
  537    typename std::enable_if<!std::is_base_of<TransformTransfer, EnableT>::value>::type
 
  542    mutable TransferT mTransfer;
 
  543    const PointFilterT& mFilter;
 
  544    InterrupterT* mInterrupter;
 
 
  552template <
typename PointDataTreeOrGridT,
 
  555    typename InterrupterT>
 
  559          const FilterT& filter,
 
  560          InterrupterT* interrupter)
 
  563    static_assert(std::is_base_of<TreeBase, PointTreeT>::value,
 
  564        "Provided points to rasterize is not a derived TreeBase type.");
 
  568    auto& topology = transfer.topology();
 
  569    using TreeT = 
typename std::decay<
decltype(topology)>::type;
 
  572        raster(
tree, transfer, filter, interrupter);
 
  573    manager.foreach(raster);
 
 
 
 
 
#define OPENVDB_ASSERT(X)
Definition Assert.h:41
static CoordBBox createCube(const Coord &min, ValueType dim)
Definition Coord.h:316
typename PointDataTree::ConstAccessor ConstAccessor
Definition Grid.h:590
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
bool empty() const
Return true if this bounding box is empty (i.e., encloses no coordinates).
Definition Coord.h:359
const Coord & min() const
Definition Coord.h:324
const Coord & max() const
Definition Coord.h:325
CoordBBox expandBy(ValueType padding) const
Return a new instance that is expanded by the specified padding.
Definition Coord.h:428
void intersect(const CoordBBox &bbox)
Intersect this bounding box with the given bounding box.
Definition Coord.h:447
Signed (x, y, z) 32-bit integer coordinates.
Definition Coord.h:26
Vec3d asVec3d() const
Definition Coord.h:144
Int32 y() const
Definition Coord.h:132
Int32 x() const
Definition Coord.h:131
Int32 z() const
Definition Coord.h:133
A no-op filter that can be used when iterating over all indices.
Definition IndexIterator.h:52
This class manages a linear array of pointers to a given tree's leaf nodes, as well as optional auxil...
Definition LeafManager.h:86
LeafType LeafNodeType
Definition LeafManager.h:93
Definition IndexIterator.h:35
Definition PointTransfer.h:333
void foreach(T &&t, const F &func, std::integer_sequence< size_t, Is... >)
Definition PointTransfer.h:335
Definition AttributeArray.h:42
tree::Tree< tree::RootNode< tree::InternalNode< tree::InternalNode< PointDataLeafNode< PointDataIndex32, 3 >, 4 >, 5 > > > PointDataTree
Point index tree configured to match the default VDB configurations.
Definition PointDataGrid.h:190
void rasterize(const PointDataTreeOrGridT &points, TransferT &transfer, const FilterT &filter=NullFilter(), InterrupterT *interrupter=nullptr)
Perform potentially complex rasterization from a user defined transfer scheme.
Definition PointTransfer.h:557
Definition PointDataGrid.h:170
bool wasInterrupted(T *i, int percent=-1)
Definition NullInterrupter.h:49
Index32 Index
Definition Types.h:54
GridTypes::Transform< internal::ToTreeType > TreeTypes
Definition openvdb.h:123
math::BBox< Vec3d > BBoxd
Definition Types.h:84
int32_t Int32
Definition Types.h:56
Definition Exceptions.h:13
static NonConstTreeType & tree(NonConstTreeType &t)
Definition Grid.h:1076
_TreeType TreeType
Definition Grid.h:1061
Definition PointTransfer.h:222
typename T::ValueType Type
Definition PointTransfer.h:222
const NodeMaskT * mask() const
Definition PointTransfer.h:324
typename TreeType::ValueType ValueType
Definition PointTransfer.h:278
void initialize(const Coord &origin, const size_t, const CoordBBox &)
Definition PointTransfer.h:302
const ValueType * buffer() const
Definition PointTransfer.h:322
const NodeMaskT * mask() const
Definition PointTransfer.h:318
ValueType * buffer()
Definition PointTransfer.h:321
VolumeTransfer(TreeType &tree)
Definition PointTransfer.h:292
NodeMaskT * mask()
Definition PointTransfer.h:317
VolumeTransfer(TreeType *tree)
Definition PointTransfer.h:285
VolumeTransfer(const VolumeTransfer &other)
Definition PointTransfer.h:295
const ValueType * buffer() const
Definition PointTransfer.h:316
NodeMaskT * mask()
Definition PointTransfer.h:323
typename TreeType::LeafNodeType::NodeMaskType NodeMaskT
Definition PointTransfer.h:279
ValueType * buffer()
Definition PointTransfer.h:315
TreeType & topology()
Definition PointTransfer.h:300
TreeT TreeType
Definition PointTransfer.h:277
const NodeMaskT * mask() const
Definition PointTransfer.h:260
VolumeTransfer(TreeTypes *... trees)
Definition PointTransfer.h:361
void initialize(const Coord &origin, const size_t, const CoordBBox &)
Definition PointTransfer.h:379
const ValueType< Idx > * buffer() const
Definition PointTransfer.h:250
ValueType< Idx > * buffer()
Definition PointTransfer.h:244
typename std::tuple_element< Idx, std::tuple< TreeTypes... > >::type TreeType
Definition PointTransfer.h:220
TreeType< 0 > & topology()
Definition PointTransfer.h:239
typename TreeType< 0 >::LeafNodeType::NodeMaskType NodeMaskT
Definition PointTransfer.h:223
VolumeTransfer(const VolumeTransfer &other)
Definition PointTransfer.h:230
std::tuple< TreeTypes *... > TreeTupleT
Definition PointTransfer.h:218
NodeMaskT * mask()
Definition PointTransfer.h:256
void foreach(const FunctorT &functor)
Definition PointTransfer.h:397
NodeMaskT * mask(const size_t idx)
Definition PointTransfer.h:257
const NodeMaskT * mask(const size_t idx) const
Definition PointTransfer.h:261
static const size_t Size
Definition PointTransfer.h:217
VolumeTransfer(TreeTypes &... trees)
Definition PointTransfer.h:227
typename TreeType< Idx >::ValueType ValueType
Definition PointTransfer.h:221
Definition PointTransfer.h:410
static const Index DIM
Definition PointTransfer.h:414
tree::LeafManager< TopologyT > LeafManagerT
Definition PointTransfer.h:411
void operator()(const typename LeafManagerT::LeafRange &range) const
Definition PointTransfer.h:516
static const Int32 DIM32
Definition PointTransfer.h:415
typename LeafManagerT::LeafNodeType LeafNodeT
Definition PointTransfer.h:412
RasterizePoints(const points::PointDataTree &tree, const TransferT &transfer, const PointFilterT &filter=PointFilterT(), InterrupterT *interrupter=nullptr)
Definition PointTransfer.h:418
static const Index LOG2DIM
Definition PointTransfer.h:416
void operator()(LeafNodeT &leaf, const size_t idx) const
Definition PointTransfer.h:427
Base class for interrupters.
Definition NullInterrupter.h:26
#define OPENVDB_VERSION_NAME
The version namespace name for this library version.
Definition version.h.in:121
#define OPENVDB_USE_VERSION_NAMESPACE
Definition version.h.in:218