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> 19 #include <type_traits> 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,
84 const GU_PrimVDB* getPrimitive()
const;
85 const GU_PrimVDB*
operator*()
const {
return getPrimitive(); }
86 const GU_PrimVDB*
operator->()
const {
return getPrimitive(); }
90 GA_Offset
getOffset()
const {
return getPrimitive()->getMapOffset(); }
91 GA_Index
getIndex()
const {
return getPrimitive()->getMapIndex(); }
95 operator bool()
const {
return getPrimitive() !=
nullptr; }
101 UT_String getPrimitiveName(
const UT_String& defaultName =
"")
const;
105 UT_String getPrimitiveNameOrIndex()
const;
113 UT_String getPrimitiveIndexAndName(
bool keepEmptyName =
true)
const;
120 UT_SharedPtr<GA_GBPrimitiveIterator>
mIter;
171 GU_PrimVDB*
operator*()
const {
return getPrimitive(); }
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); }
222 mInterrupt(title) { }
226 void start(
const char* name =
nullptr) { mInterrupt.start(name); }
228 void end() { mInterrupt.end(); }
233 bool wasInterrupted(
int percent=-1) {
return mInterrupt.wasInterrupted(percent); }
236 openvdb::util::NullInterrupter&
interrupter() {
return mInterrupt.interrupter(); }
271 const bool copyAttrs =
true,
const char* name =
nullptr);
282 openvdb::CoordBBox
makeCoordBBox(
const UT_BoundingBox&,
const openvdb::math::Transform&);
341 openvdb::DoubleGrid>;
359 template<
typename Gr
idTypeListT,
typename OpT>
363 if (
auto gridPtr = vdb.getConstGridPtr()) {
364 return gridPtr->apply<GridTypeListT>(
op);
374 template<
typename Gr
idTypeListT,
typename OpT>
379 auto gridPtr = vdb.getGridPtr();
381 auto treePtr = gridPtr->baseTreePtr();
382 if (treePtr.use_count() > 2) {
385 gridPtr->apply<GridTypeListT>(
386 [](
Grid& baseGrid) { baseGrid.setTree(baseGrid.constBaseTree().copy()); });
389 return gridPtr->apply<GridTypeListT>(
op);
396 #endif // OPENVDB_HOUDINI_UTILS_HAS_BEEN_INCLUDED VdbPrimIterator & operator++()
Advance to the next VDB primitive.
Definition: Utils.h:164
std::function< bool(const GU_PrimVDB &)> FilterFunc
Definition: Utils.h:59
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
GU_PrimVDB * getPrimitive() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:168
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.
Grid< Vec3DTree > Vec3DGrid
Definition: openvdb.h:79
OPENVDB_HOUDINI_API void startLogForwarding(OP_OpTypeId)
Start forwarding OpenVDB log messages to the Houdini error manager for all operators of the given typ...
HoudiniInterrupter(const char *title=nullptr)
Definition: Utils.h:186
openvdb::util::NullInterrupter & interrupter()
Return a reference to the base class of the stored interrupter.
Definition: Utils.h:236
Grid< FloatTree > FloatGrid
Definition: openvdb.h:75
void start(const char *name=nullptr)
Signal the start of an interruptible operation.
Definition: Utils.h:226
A list of types (not necessarily unique)
Definition: TypeList.h:577
~HoudiniInterrupter() override final
Definition: Utils.h:189
GU_PrimVDB * operator*() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:171
GA_Offset getOffset() const
Definition: Utils.h:90
openvdb::GridBase::Ptr GridPtr
Definition: Utils.h:44
Grid< Int32Tree > Int32Grid
Definition: openvdb.h:76
const GU_PrimVDB * operator->() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:86
void end()
Signal the end of an interruptible operation.
Definition: Utils.h:228
OPENVDB_HOUDINI_API openvdb::CoordBBox makeCoordBBox(const UT_BoundingBox &, const openvdb::math::Transform &)
Construct an index-space CoordBBox from a UT_BoundingBox.
VdbPrimCIterator & operator++()
Advance to the next VDB primitive.
Definition: Utils.h:79
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...
Iterator over non-const VDB primitives on a geometry detail.
Definition: Utils.h:131
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
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).
Grid< DoubleTree > DoubleGrid
Definition: openvdb.h:74
bool wasInterrupted(int percent=-1)
Check if an interruptible operation should be aborted.
Definition: Utils.h:233
ScalarGridTypes::Append< Vec3GridTypes > VolumeGridTypes
Definition: Utils.h:351
Iterator over const VDB primitives on a geometry detail.
Definition: Utils.h:56
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.
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:361
VolumeGridTypes::Append< PointGridTypes > AllGridTypes
Definition: Utils.h:353
Abstract base class for typed grids.
Definition: Grid.h:77
Deprecated wrapper class with the same interface as HoudiniInterrupter, however it does not derive fr...
Definition: Utils.h:217
unsigned OP_OutputIdx
Definition: Utils.h:38
Definition: AttributeTransferUtil.h:34
FilterFunc mFilter
Definition: Utils.h:121
typename typelist_internal::TSAppendImpl< Self, TypesToAppend... >::type Append
Append types, or the members of another TypeList, to this list.
Definition: TypeList.h:656
openvdb::GridBase::ConstPtr GridCPtr
Definition: Utils.h:45
unsigned OP_InputIdx
Definition: Utils.h:37
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
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.
void start(const char *name=nullptr) override final
Signal the start of an interruptible operation.
Definition: Utils.h:196
Grid< Vec3STree > Vec3SGrid
Definition: openvdb.h:81
UT_SharedPtr< GA_GBPrimitiveIterator > mIter
Definition: Utils.h:120
VdbPrimIterator(GEO_Detail *gdp, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
Definition: Utils.h:143
OPENVDB_HOUDINI_API void stopLogForwarding(OP_OpTypeId)
Stop forwarding OpenVDB log messages to the Houdini error manager for all operators of the given type...
bool wasInterrupted(int percent=-1) override final
Check if an interruptible operation should be aborted.
Definition: Utils.h:205
void end() override final
Signal the end of an interruptible operation.
Definition: Utils.h:200
const GU_PrimVDB * operator*() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:85
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:28
GU_PrimVDB * operator->() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:172
Wrapper class that adapts a Houdini UT_Interrupt object for use with OpenVDB library routines...
Definition: Utils.h:183
Grid< BoolTree > BoolGrid
Common grid types.
Definition: openvdb.h:73
Grid< PointDataTree > PointDataGrid
Point data grid.
Definition: PointDataGrid.h:195