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> 18 #include <type_traits> 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,
75 const GU_PrimVDB* getPrimitive()
const;
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; }
92 UT_String getPrimitiveName(
const UT_String& defaultName =
"")
const;
96 UT_String getPrimitiveNameOrIndex()
const;
104 UT_String getPrimitiveIndexAndName(
bool keepEmptyName =
true)
const;
111 UT_SharedPtr<GA_GBPrimitiveIterator>
mIter;
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); }
219 void end() { mInterrupt.end(); }
224 bool wasInterrupted(
int percent=-1) {
return mInterrupt.wasInterrupted(percent); }
227 openvdb::util::NullInterrupter&
interrupter() {
return mInterrupt.interrupter(); }
262 const bool copyAttrs =
true,
const char* name =
nullptr);
273 openvdb::CoordBBox
makeCoordBBox(
const UT_BoundingBox&,
const openvdb::math::Transform&);
332 openvdb::DoubleGrid>;
350 template<
typename Gr
idTypeListT,
typename OpT>
354 if (
auto gridPtr = vdb.getConstGridPtr()) {
355 return gridPtr->apply<GridTypeListT>(
op);
365 template<
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);
387 #endif // OPENVDB_HOUDINI_UTILS_HAS_BEEN_INCLUDED VdbPrimIterator & operator++()
Advance to the next VDB primitive.
Definition: Utils.h:155
std::function< bool(const GU_PrimVDB &)> FilterFunc
Definition: Utils.h:50
GU_PrimVDB * getPrimitive() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:159
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 void startLogForwarding(OP_OpTypeId)
Start forwarding OpenVDB log messages to the Houdini error manager for all operators of the given typ...
A list of types (not necessarily unique)
Definition: TypeList.h:577
HoudiniInterrupter(const char *title=nullptr)
Definition: Utils.h:177
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
Grid< Int32Tree > Int32Grid
Definition: openvdb.h:76
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
~HoudiniInterrupter() override final
Definition: Utils.h:180
GU_PrimVDB * operator*() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:162
GA_Offset getOffset() const
Definition: Utils.h:81
openvdb::GridBase::Ptr GridPtr
Definition: Utils.h:35
const GU_PrimVDB * operator->() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:77
void end()
Signal the end of an interruptible operation.
Definition: Utils.h:219
Grid< Vec3DTree > Vec3DGrid
Definition: openvdb.h:79
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:70
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:122
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
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).
bool wasInterrupted(int percent=-1)
Check if an interruptible operation should be aborted.
Definition: Utils.h:224
ScalarGridTypes::Append< Vec3GridTypes > VolumeGridTypes
Definition: Utils.h:342
Grid< DoubleTree > DoubleGrid
Definition: openvdb.h:74
Iterator over const VDB primitives on a geometry detail.
Definition: Utils.h:47
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:352
VolumeGridTypes::Append< PointGridTypes > AllGridTypes
Definition: Utils.h:344
SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
Deprecated wrapper class with the same interface as HoudiniInterrupter, however it does not derive fr...
Definition: Utils.h:208
Definition: AttributeTransferUtil.h:34
FilterFunc mFilter
Definition: Utils.h:112
openvdb::GridBase::ConstPtr GridCPtr
Definition: Utils.h:36
Grid< Vec3STree > Vec3SGrid
Definition: openvdb.h:81
typename typelist_internal::TSAppendImpl< Self, TypesToAppend... >::type Append
Append types, or the members of another TypeList, to this list.
Definition: TypeList.h:656
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:187
UT_SharedPtr< GA_GBPrimitiveIterator > mIter
Definition: Utils.h:111
VdbPrimIterator(GEO_Detail *gdp, const GA_PrimitiveGroup *group=nullptr, FilterFunc filter=FilterFunc())
Definition: Utils.h:134
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:196
Grid< BoolTree > BoolGrid
Common grid types.
Definition: openvdb.h:73
void end() override final
Signal the end of an interruptible operation.
Definition: Utils.h:191
const GU_PrimVDB * operator*() const
Return a pointer to the current VDB primitive (nullptr if at end).
Definition: Utils.h:76
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:163
Wrapper class that adapts a Houdini UT_Interrupt object for use with OpenVDB library routines...
Definition: Utils.h:174
Grid< PointDataTree > PointDataGrid
Point data grid.
Definition: PointDataGrid.h:195
Abstract base class for typed grids.
Definition: Grid.h:77
Grid< FloatTree > FloatGrid
Definition: openvdb.h:75