8#ifndef OPENVDB_HOUDINI_UTILS_HAS_BEEN_INCLUDED
9#define OPENVDB_HOUDINI_UTILS_HAS_BEEN_INCLUDED
11#include <GU/GU_PrimVDB.h>
12#include <OP/OP_Node.h>
13#include <UT/UT_SharedPtr.h>
14#include <UT/UT_Interrupt.h>
15#include <UT/UT_Version.h>
23#ifdef OPENVDB_HOUDINI_API
24 #undef OPENVDB_HOUDINI_API
25 #define OPENVDB_HOUDINI_API
36#if SYS_VERSION_MAJOR_INT < 21
59 using FilterFunc = std::function<bool (
const GU_PrimVDB&)>;
70 explicit VdbPrimCIterator(
const GEO_Detail* gdp,
const GA_PrimitiveGroup* group =
nullptr,
120 UT_SharedPtr<GA_GBPrimitiveIterator>
mIter;
187 mUTI{UTgetInterrupt()}, mRunning{false}, mTitle{title ? title :
""}
196 void start(
const char* name =
nullptr) override final {
197 if (!mRunning) { mRunning =
true; mUTI->opStart(name ? name : mTitle.c_str()); }
200 void end() override final {
if (mRunning) { mUTI->opEnd(); mRunning =
false; } }
205 bool wasInterrupted(
int percent=-1) override final {
return mUTI->opInterrupt(percent); }
242 const bool copyAttrs =
true,
const char* name =
nullptr);
320 openvdb::points::PointDataGrid>;
330template<
typename Gr
idTypeListT,
typename OpT>
334 if (
auto gridPtr = vdb.getConstGridPtr()) {
335 return gridPtr->apply<GridTypeListT>(op);
345template<
typename Gr
idTypeListT,
typename OpT>
350 auto gridPtr = vdb.getGridPtr();
352 auto treePtr = gridPtr->baseTreePtr();
353 if (treePtr.use_count() > 2) {
356 gridPtr->apply<GridTypeListT>(
357 [](
Grid& baseGrid) { baseGrid.setTree(baseGrid.constBaseTree().copy()); });
360 return gridPtr->apply<GridTypeListT>(op);
Abstract base class for typed grids.
Definition Grid.h:78
Axis-aligned bounding box of signed integer coordinates.
Definition Coord.h:252
void end() override final
Signal the end of an interruptible operation.
Definition Utils.h:200
HoudiniInterrupter & operator=(const HoudiniInterrupter &)=default
void start(const char *name=nullptr) override final
Signal the start of an interruptible operation.
Definition Utils.h:196
~HoudiniInterrupter() override final
Definition Utils.h:189
HoudiniInterrupter(const HoudiniInterrupter &)=default
HoudiniInterrupter(const char *title=nullptr)
Definition Utils.h:186
bool wasInterrupted(int percent=-1) override final
Check if an interruptible operation should be aborted.
Definition Utils.h:205
const GU_PrimVDB * operator*() const
Definition Utils.h:85
std::function< bool(const GU_PrimVDB &)> FilterFunc
Definition Utils.h:59
UT_SharedPtr< GA_GBPrimitiveIterator > mIter
Definition Utils.h:120
GA_Index getIndex() const
Definition Utils.h:91
const GU_PrimVDB * getPrimitive() const
Return a pointer to the current VDB primitive (nullptr if at end).
const GU_PrimVDB * operator->() const
Definition Utils.h:86
VdbPrimCIterator(const GEO_Detail *gdp, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
FilterFunc mFilter
Definition Utils.h:121
void advance()
Advance to the next VDB primitive.
VdbPrimCIterator & operator=(const VdbPrimCIterator &)
VdbPrimCIterator(const GEO_Detail *, GA_Range::safedeletions, const GA_PrimitiveGroup *=nullptr, FilterFunc=FilterFunc())
Allow primitives to be deleted during iteration.
VdbPrimCIterator & operator++()
Definition Utils.h:79
UT_String getPrimitiveIndexAndName(bool keepEmptyName=true) const
Return a string of the form "N (NAME)", where N is the current VDB primitive's index and NAME is the ...
GA_Offset getOffset() const
Definition Utils.h:90
UT_String getPrimitiveName(const UT_String &defaultName="") const
Return the value of the current VDB primitive's name attribute.
VdbPrimCIterator(const VdbPrimCIterator &)
UT_String getPrimitiveNameOrIndex() const
Return the value of the current VDB primitive's name attribute or, if the name is empty,...
VdbPrimIterator & operator=(const VdbPrimIterator &)
GU_PrimVDB * operator->() const
Definition Utils.h:172
VdbPrimIterator & operator++()
Advance to the next VDB primitive.
Definition Utils.h:164
VdbPrimIterator(const VdbPrimIterator &)
GU_PrimVDB * operator*() const
Definition Utils.h:171
VdbPrimIterator(GEO_Detail *gdp, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
Definition Utils.h:143
GU_PrimVDB * getPrimitive() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition Utils.h:168
VdbPrimIterator(GEO_Detail *gdp, GA_Range::safedeletions, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
Allow primitives to be deleted during iteration.
Definition Utils.h:156
Grid< FloatTree > FloatGrid
Definition openvdb.h:76
Grid< Vec3DTree > Vec3DGrid
Definition openvdb.h:81
Grid< BoolTree > BoolGrid
Common grid types.
Definition openvdb.h:74
Grid< Vec3ITree > Vec3IGrid
Definition openvdb.h:82
Grid< Int64Tree > Int64Grid
Definition openvdb.h:79
Grid< Vec3STree > Vec3SGrid
Definition openvdb.h:83
Grid< Int32Tree > Int32Grid
Definition openvdb.h:78
Grid< DoubleTree > DoubleGrid
Definition openvdb.h:75
Definition AttributeTransferUtil.h:34
OPENVDB_HOUDINI_API bool evalGridBBox(GridCRef grid, UT_Vector3 corners[8], bool expandHalfVoxel=false)
Return in corners the corners of the given grid's active voxel bounding box.
openvdb::TypeList< openvdb::FloatGrid, openvdb::DoubleGrid > RealGridTypes
Definition Utils.h:310
openvdb::TypeList< openvdb::FloatGrid, openvdb::DoubleGrid, openvdb::Int32Grid, openvdb::Int64Grid > NumericGridTypes
Definition Utils.h:304
OPENVDB_HOUDINI_API bool isLogForwarding(OP_OpTypeId)
Return true if OpenVDB messages logged by operators of the given type are forwarded to the Houdini er...
openvdb::GridBase::Ptr GridPtr
Definition Utils.h:44
openvdb::TypeList< openvdb::Vec3SGrid, openvdb::Vec3DGrid, openvdb::Vec3IGrid > Vec3GridTypes
Definition Utils.h:314
OPENVDB_HOUDINI_API void stopLogForwarding(OP_OpTypeId)
Stop forwarding OpenVDB log messages to the Houdini error manager for all operators of the given type...
VolumeGridTypes::Append< PointGridTypes > AllGridTypes
Definition Utils.h:324
const openvdb::GridBase & GridCRef
Definition Utils.h:47
OPENVDB_HOUDINI_API void startLogForwarding(OP_OpTypeId)
Start forwarding OpenVDB log messages to the Houdini error manager for all operators of the given typ...
openvdb::GridBase & GridRef
Definition Utils.h:46
OPENVDB_HOUDINI_API GU_PrimVDB * createVdbPrimitive(GU_Detail &gdp, GridPtr grid, const char *name=nullptr)
Store a VDB grid in a new VDB primitive and add the primitive to a geometry detail.
openvdb::GridBase Grid
Definition Utils.h:43
openvdb::TypeList< openvdb::BoolGrid, openvdb::FloatGrid, openvdb::DoubleGrid, openvdb::Int32Grid, openvdb::Int64Grid > ScalarGridTypes
Definition Utils.h:297
openvdb::TypeList< openvdb::points::PointDataGrid > PointGridTypes
Definition Utils.h:319
ScalarGridTypes::Append< Vec3GridTypes > VolumeGridTypes
Definition Utils.h:322
bool GEOvdbApply(const GEO_PrimVDB &vdb, OpT &op)
If the given primitive's grid resolves to one of the listed grid types, invoke the functor op on the ...
Definition Utils.h:332
OPENVDB_HOUDINI_API GU_PrimVDB * replaceVdbPrimitive(GU_Detail &gdp, GridPtr grid, GEO_PrimVDB &src, const bool copyAttrs=true, const char *name=nullptr)
Replace an existing VDB primitive with a new primitive that contains the given grid.
OPENVDB_HOUDINI_API openvdb::CoordBBox makeCoordBBox(const UT_BoundingBox &, const openvdb::math::Transform &)
Construct an index-space CoordBBox from a UT_BoundingBox.
openvdb::GridBase::ConstPtr GridCPtr
Definition Utils.h:45
unsigned OP_InputIdx
Definition Utils.h:37
unsigned OP_OutputIdx
Definition Utils.h:38
A list of types (not necessarily unique)
Definition TypeList.h:576
typename typelist_internal::TSAppendImpl< Self, TypesToAppend... >::type Append
Definition TypeList.h:654