8#ifndef OPENVDB_HOUDINI_UTILS_HAS_BEEN_INCLUDED
9#define OPENVDB_HOUDINI_UTILS_HAS_BEEN_INCLUDED
12#include <OP/OP_Node.h>
13#include <UT/UT_SharedPtr.h>
14#include <UT/UT_Interrupt.h>
22#ifdef OPENVDB_HOUDINI_API
23 #undef OPENVDB_HOUDINI_API
24 #define OPENVDB_HOUDINI_API
50 using FilterFunc = std::function<bool (
const GU_PrimVDB&)>;
61 explicit VdbPrimCIterator(
const GEO_Detail* gdp,
const GA_PrimitiveGroup* group =
nullptr,
76 const GU_PrimVDB*
operator*()
const {
return getPrimitive(); }
77 const GU_PrimVDB*
operator->()
const {
return getPrimitive(); }
81 GA_Offset
getOffset()
const {
return getPrimitive()->getMapOffset(); }
82 GA_Index
getIndex()
const {
return getPrimitive()->getMapIndex(); }
86 operator bool()
const {
return getPrimitive() !=
nullptr; }
111 UT_SharedPtr<GA_GBPrimitiveIterator>
mIter;
160 return const_cast<GU_PrimVDB*
>(VdbPrimCIterator::getPrimitive());
162 GU_PrimVDB*
operator*()
const {
return getPrimitive(); }
178 mUTI{UTgetInterrupt()}, mRunning{false}, mTitle{title ? title :
""}
187 void start(
const char* name =
nullptr) override final {
188 if (!mRunning) { mRunning =
true; mUTI->opStart(name ? name : mTitle.c_str()); }
191 void end() override final {
if (mRunning) { mUTI->opEnd(); mRunning =
false; } }
196 bool wasInterrupted(
int percent=-1) override final {
return mUTI->opInterrupt(percent); }
213 mInterrupt(title) { }
217 void start(
const char* name =
nullptr) { mInterrupt.
start(name); }
227 openvdb::util::NullInterrupter&
interrupter() {
return mInterrupt.interrupter(); }
262 const bool copyAttrs =
true,
const char* name =
nullptr);
340 openvdb::points::PointDataGrid>;
350template<
typename Gr
idTypeListT,
typename OpT>
354 if (
auto gridPtr = vdb.getConstGridPtr()) {
355 return gridPtr->apply<GridTypeListT>(op);
365template<
typename Gr
idTypeListT,
typename OpT>
370 auto gridPtr = vdb.getGridPtr();
372 auto treePtr = gridPtr->baseTreePtr();
373 if (treePtr.use_count() > 2) {
376 gridPtr->apply<GridTypeListT>(
377 [](
Grid& baseGrid) { baseGrid.setTree(baseGrid.constBaseTree().copy()); });
380 return gridPtr->apply<GridTypeListT>(op);
Abstract base class for typed grids.
Definition: Grid.h:78
Container class that associates a tree with a transform and metadata.
Definition: Grid.h:571
Axis-aligned bounding box of signed integer coordinates.
Definition: Coord.h:249
Wrapper class that adapts a Houdini UT_Interrupt object for use with OpenVDB library routines.
Definition: Utils.h:175
void end() override final
Signal the end of an interruptible operation.
Definition: Utils.h:191
HoudiniInterrupter & operator=(const HoudiniInterrupter &)=default
void start(const char *name=nullptr) override final
Signal the start of an interruptible operation.
Definition: Utils.h:187
~HoudiniInterrupter() override final
Definition: Utils.h:180
HoudiniInterrupter(const HoudiniInterrupter &)=default
HoudiniInterrupter(const char *title=nullptr)
Definition: Utils.h:177
bool wasInterrupted(int percent=-1) override final
Check if an interruptible operation should be aborted.
Definition: Utils.h:196
Deprecated wrapper class with the same interface as HoudiniInterrupter, however it does not derive fr...
Definition: Utils.h:209
bool wasInterrupted(int percent=-1)
Check if an interruptible operation should be aborted.
Definition: Utils.h:224
void end()
Signal the end of an interruptible operation.
Definition: Utils.h:219
openvdb::util::NullInterrupter & interrupter()
Return a reference to the base class of the stored interrupter.
Definition: Utils.h:227
void start(const char *name=nullptr)
Signal the start of an interruptible operation.
Definition: Utils.h:217
Iterator over const VDB primitives on a geometry detail.
Definition: Utils.h:48
const GU_PrimVDB * operator*() const
Definition: Utils.h:76
std::function< bool(const GU_PrimVDB &)> FilterFunc
Definition: Utils.h:50
UT_SharedPtr< GA_GBPrimitiveIterator > mIter
Definition: Utils.h:111
GA_Index getIndex() const
Definition: Utils.h:82
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:77
VdbPrimCIterator(const GEO_Detail *gdp, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
FilterFunc mFilter
Definition: Utils.h:112
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:70
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:81
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,...
Iterator over non-const VDB primitives on a geometry detail.
Definition: Utils.h:123
VdbPrimIterator & operator=(const VdbPrimIterator &)
GU_PrimVDB * operator->() const
Definition: Utils.h:163
VdbPrimIterator & operator++()
Advance to the next VDB primitive.
Definition: Utils.h:155
VdbPrimIterator(const VdbPrimIterator &)
GU_PrimVDB * operator*() const
Definition: Utils.h:162
VdbPrimIterator(GEO_Detail *gdp, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
Definition: Utils.h:134
GU_PrimVDB * getPrimitive() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:159
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:147
Grid< FloatTree > FloatGrid
Definition: openvdb.h:75
Grid< Vec3DTree > Vec3DGrid
Definition: openvdb.h:79
Grid< BoolTree > BoolGrid
Common grid types.
Definition: openvdb.h:73
Grid< Vec3STree > Vec3SGrid
Definition: openvdb.h:81
Grid< Int32Tree > Int32Grid
Definition: openvdb.h:76
Grid< DoubleTree > DoubleGrid
Definition: openvdb.h:74
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_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:35
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:344
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_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.
ScalarGridTypes::Append< Vec3GridTypes > VolumeGridTypes
Definition: Utils.h:342
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:352
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:36
A list of types (not necessarily unique)
Definition: TypeList.h:484
typename typelist_internal::TSAppendImpl< Self, TypesToAppend... >::type Append
Append types, or the members of another TypeList, to this list.
Definition: TypeList.h:560