16 #ifndef __GEO_PrimVDB__
17 #define __GEO_PrimVDB__
76 CE_VDBGrid *getCEGrid(
bool read,
bool write)
const;
82 IMX_VDBPtr getIMXVDB(
bool read,
bool write)
const;
134 void posToIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
143 fpreal getValueAtIndexF(
int ix,
int iy,
int iz)
const;
145 UT_Vector3D getValueAtIndexV3(
int ix,
int iy,
int iz)
const;
149 void getValuesAtIndices(
float *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
150 void getValuesAtIndices(
int *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
154 void getValuesAtIndices(
UT_Vector3 *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
158 void getValuesAtIndices(
double *
f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
174 int gradients_stride,
182 {
return myGridAccessor.getStorageType(); }
193 bool isActiveRegionMatched(
const GEO_PrimVDB *vdb)
const;
197 bool isWorldAxisAligned()
const;
205 bool isEmpty()
const {
return getGridPtr()->empty(); }
208 fpreal backgroundF()
const;
230 bool dry_run=
false)
override;
232 bool dry_run=
false)
override;
237 void assignVertex(
GA_Offset new_vtx,
bool update_topology);
248 float u,
float v = 0,
249 unsigned du=0,
unsigned dv=0)
const override
288 bool force_taper =
false);
296 void getRes(
int &rx,
int &ry,
int &rz)
const;
301 fpreal getVoxelDiameter()
const;
307 fpreal calcMinimum()
const;
308 fpreal calcMaximum()
const;
309 fpreal calcAverage()
const;
342 activateIndexBBoxAdapter(
343 &bbox, operation, setvalue, value);
351 ActivateOperation operation,
353 bool ignore_transform=
false);
361 void stashed(
bool beingstashed,
422 myVis.myMode = vismode;
424 myVis.myDensity = density;
441 bool as_shmem =
false)
const;
443 bool as_shmem =
false);
446 bool saveVisualization(
449 bool loadVisualization(
468 fpreal calcPositiveDensity()
const;
471 bool hasGrid()
const {
return myGridAccessor.hasGrid(); }
478 { myGridAccessor.makeGridUnique(); }
483 {
return myGridAccessor.isGridUnique(); }
489 {
return myGridAccessor.getConstGrid(*
this); }
494 {
return getConstGrid(); }
502 return myGridAccessor.getGrid(*
this);
510 {
return myGridAccessor.getConstGridPtr(*
this); }
516 {
return getConstGridPtr(); }
525 return myGridAccessor.getGridPtr(*
this);
531 void setGrid(
const openvdb::GridBase &grid,
bool copyPosition=
true)
534 myGridAccessor.setGrid(grid, *
this, copyPosition);
540 {
return getConstGrid(); }
544 {
return getConstGrid(); }
550 incrMetadataUniqueId();
551 return myGridAccessor.getGrid(*
this);
556 const char * getGridName()
const;
561 {
return static_cast<UniqueId>(myUniqueId.relaxedLoad()); }
568 {
return static_cast<UniqueId>(myTreeUniqueId.relaxedLoad()); }
574 {
return static_cast<UniqueId>(myMetadataUniqueId.relaxedLoad()); }
580 {
return static_cast<UniqueId>(myTransformUniqueId.relaxedLoad()); }
595 template<
typename Gr
idTypeListT,
typename OpT>
597 {
return hasGrid() ? getConstGrid().apply<GridTypeListT>(
op) :
false; }
617 template<
typename Gr
idTypeListT,
typename OpT>
621 auto& grid = myGridAccessor.getGrid(*
this);
623 auto treePtr = grid.baseTreePtr();
624 if (treePtr.use_count() > 2) {
627 grid.apply<GridTypeListT>([
this](openvdb::GridBase& baseGrid) {
628 baseGrid.setTree(baseGrid.constBaseTree().copy());
629 this->incrTreeUniqueId();
633 if (grid.apply<GridTypeListT>(op)) {
648 static
bool isIntrinsicMetadata(const
char *
name);
664 static UniqueId nextUniqueId();
667 { myTreeUniqueId.maximum(nextUniqueId()); }
669 { myMetadataUniqueId.maximum(nextUniqueId()); }
671 { myTransformUniqueId.maximum(nextUniqueId()); }
675 incrMetadataUniqueId();
676 incrTransformUniqueId();
681 void copyGridFrom(
const GEO_PrimVDB&,
bool copyPosition=
true);
713 { updateGridTranslates(prim);
return *myGrid; }
716 const openvdb::GridBase &
718 { updateGridTranslates(prim);
return *myGrid; }
721 openvdb::GridBase::Ptr
723 { updateGridTranslates(prim);
return myGrid; }
726 openvdb::GridBase::ConstPtr
728 { updateGridTranslates(prim);
return myGrid; }
734 { setGridAdapter(&grid, prim, copyPosition); }
737 const openvdb::math::Transform &
xform,
739 { setTransformAdapter(&xform, prim); }
741 void makeGridUnique();
742 bool isGridUnique()
const;
751 { myStorageType =
storage; myGrid.reset(); }
754 void updateGridTranslates(
const GEO_PrimVDB &prim)
const;
757 void setVertexPosition(
758 const openvdb::math::Transform &
xform,
760 { setVertexPositionAdapter(&xform, prim); }
762 void setGridAdapter(
const void* grid,
GEO_PrimVDB&,
bool copyPosition);
767 openvdb::GridBase::Ptr myGrid;
772 void activateIndexBBoxAdapter(
778 GridAccessor myGridAccessor;
786 mutable bool myCEGridAuthorative;
788 AtomicUniqueId myUniqueId;
789 AtomicUniqueId myTreeUniqueId;
790 AtomicUniqueId myMetadataUniqueId;
791 AtomicUniqueId myTransformUniqueId;
796 #if 0 // ndef SESI_OPENVDB
797 namespace openvdb_houdini {
798 using ::GEO_VolumeOptions;
807 namespace UT_VDBUtils {
814 template<
typename Gr
idType,
typename OpType>
823 template<
typename Gr
idType,
typename OpType>
844 template <typename OpT>
847 return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(),
op);
850 template <
typename OpT>
856 template <
typename OpT>
862 template <
typename OpT>
868 template <
typename OpT>
874 template <
typename OpT>
888 template <
typename OpT>
891 if (makeUnique)
return UTvdbProcessTypedGrid(vdb.
getStorageType(), vdb,
op);
895 template <
typename OpT>
898 if (makeUnique)
return UTvdbProcessTypedGridReal(vdb.
getStorageType(), vdb,
op);
902 template <
typename OpT>
905 if (makeUnique)
return UTvdbProcessTypedGridScalar(vdb.
getStorageType(), vdb,
op);
909 template <
typename OpT>
912 if (makeUnique)
return UTvdbProcessTypedGridTopology(vdb.
getStorageType(), vdb,
op);
916 template <
typename OpT>
919 if (makeUnique)
return UTvdbProcessTypedGridVec3(vdb.
getStorageType(), vdb,
op);
923 template <
typename OpT>
926 if (makeUnique)
return UTvdbProcessTypedGridPoint(vdb.
getStorageType(), vdb,
op);
931 #endif // __GEO_PrimVDB__
virtual void flushCEWriteCaches()
Copy any modified caches from the GPU back to CPU cache.
virtual void flushCECaches()
Definition of a geometry attribute.
GridAccessor manages access to a GEO_PrimVDB's grid.
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
void clearGridAndSetStorageType(UT_VDBType storage)
virtual UT_Vector3 baryCenter() const
GA_Offset fastVertexOffset(GA_Size UT_IF_ASSERT_P(index)) const
Method to perform quick lookup of vertex without the virtual call.
virtual void copyPrimitive(const GEO_Primitive *src)=0
SYS_FORCE_INLINE UT_VDBType getStorageType() const
Get the storage type of the grid.
bool GEOvdbProcessTypedGridTopology(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
SYS_FORCE_INLINE void setPos3(const UT_Vector3 &pos)
Used to pass options and map offset values during saving.
SYS_FORCE_INLINE openvdb::MetaMap & getMetadata()
Return a reference to this primitive's grid metadata.
SYS_FORCE_INLINE GridAccessor()
GridType
List of types that are currently supported by NanoVDB.
virtual UT_Vector3D computeNormalD() const =0
getFileOption("OpenEXR:storage") storage
SYS_FORCE_INLINE void clear()
SYS_FORCE_INLINE openvdb::GridBase::ConstPtr getConstGridPtr() const
Return a shared pointer to this primitive's grid.
virtual void copySubclassData(const GA_Primitive *source)
GLsizei const GLfloat * value
bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *p) const override
SYS_AtomicCounter AtomicUniqueId
const openvdb::MetaMap & getMetadata() const
Return a reference to this primitive's grid metadata.
fpreal calcVolume(const UT_Vector3 &) const override
SYS_FORCE_INLINE const openvdb::GridBase & getConstGrid() const
Return a reference to this primitive's grid.
GLdouble GLdouble GLdouble z
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
UniqueId getUniqueId() const
Return this primitive's serial number.
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
void incrTransformUniqueId()
JSON reader class which handles parsing of JSON or bJSON files.
void reverse() override=0
Reverse the order of vertices.
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Class which writes ASCII or binary JSON streams.
Abstract base class for a range membership query object.
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
**But if you need a result
const GEO_VolumeOptions & getVisOptions() const
unsigned long long uint64
#define UT_IF_ASSERT_P(ZZ)
fpreal calcArea() const override
bool GEOvdbProcessTypedGridPoint(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
SYS_FORCE_INLINE openvdb::GridBase::ConstPtr getConstGridPtr(const GEO_PrimVDB &prim) const
UniqueId getMetadataUniqueId() const
Return the serial number of this primitive's grid metadata.
exint GA_Size
Defines the bit width for index and offset types in GA.
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
bool apply(OpT &op) const
If this primitive's grid resolves to one of the listed grid types, invoke the functor op on the resol...
void setVisualization(GEO_VolumeVis vismode, fpreal iso, fpreal density, GEO_VolumeVisLod lod=GEO_VOLUMEVISLOD_FULL)
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
SYS_FORCE_INLINE UT_Vector3 getPos3() const
bool GEOvdbProcessTypedGridReal(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
bool GEOvdbProcessTypedGridVec3(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
virtual bool isDegenerate() const =0
Is the primitive degenerate.
SYS_FORCE_INLINE bool hasGrid() const
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
virtual void clearCECaches()
Clear all caches from the GPU, without copying any data to the CPU.
SYS_FORCE_INLINE GA_Offset getPointOffset() const
#define UT_VDB_DECL_PROCESS_TYPED_GRID(GRID_BASE_T)
Utility function that, given a generic grid pointer, calls a functor on the fully-resolved grid...
SYS_FORCE_INLINE UT_VDBType getStorageType() const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
virtual void setLocalTransform(const UT_Matrix3D &matrix)
Set the local transform. The default implementation does nothing.
SYS_FORCE_INLINE openvdb::GridBase::Ptr getGridPtr()
Return a shared pointer to this primitive's grid.
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
bool GEOvdbProcessTypedGridScalar(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
void incrMetadataUniqueId()
virtual const GA_PrimitiveJSON * getJSON() const =0
void setVertexPoint(int i, GA_Offset pt)
GLsizei GLsizei GLchar * source
Provide a JSON interface to a primitive.
GLint GLenum GLboolean GLsizei stride
void activateIndexBBox(const openvdb::CoordBBox &bbox, ActivateOperation operation, bool setvalue, fpreal value)
SYS_FORCE_INLINE void setTransform(const openvdb::math::Transform &xform, GEO_PrimVDB &prim)
SYS_FORCE_INLINE int getTupleSize() const
Get the tuple size, usually 1 or 3.
A handle to simplify manipulation of multiple attributes.
UniqueId getTreeUniqueId() const
Return the serial number of this primitive's voxel data.
SYS_FORCE_INLINE bool hasGrid() const
HUSD_API const char * resolution()
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
SYS_FORCE_INLINE void setGrid(const openvdb::GridBase &grid, GEO_PrimVDB &prim, bool copyPosition=true)
SYS_FORCE_INLINE openvdb::GridBase & getGrid(const GEO_PrimVDB &prim)
SYS_FORCE_INLINE openvdb::GridBase::Ptr getGridPtr(const GEO_PrimVDB &prim)
int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const override
Evalaute position given a u,v coordinate (with derivatives)
virtual int64 getDeviceMemoryUsage() const
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
SYS_FORCE_INLINE void setGrid(const openvdb::GridBase &grid, bool copyPosition=true)
Set this primitive's grid to a shallow copy of the given grid.
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
UniqueId getTransformUniqueId() const
Return the serial number of this primitive's transform.
virtual void transform(const UT_Matrix4 &)
virtual void enlargePointBounds(UT_BoundingBox &box) const
SYS_FORCE_INLINE const openvdb::GridBase & getConstGrid(const GEO_PrimVDB &prim) const
virtual void getLocalTransform(UT_Matrix3D &matrix) const
virtual int detachPoints(GA_PointGroup &grp)=0
fpreal getVisDensity() const
SYS_FORCE_INLINE void makeGridUnique()
If this primitive's grid's voxel data (i.e., its tree) is shared, replace the tree with a deep copy o...
bool isGridUnique() const
Returns true if the tree is not shared. If it is not shared, one can make destructive edits without m...
GEO_VolumeTypeInfo getTypeInfo() const
int UTvdbGetGridTupleSize(UT_VDBType type)
Returns the tuple size of a grid given its value type.
virtual bool getBBox(UT_BoundingBox *bbox) const =0
SYS_FORCE_INLINE openvdb::GridBase::ConstPtr getGridPtr() const
Return a shared pointer to this primitive's grid.
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
bool hasGrid(const std::string &fileName, const std::string &gridName)
Return true if the file contains a grid with the specified name.
virtual void stealCEBuffers(const GA_Primitive *src)
Steal the underlying CE buffer from the source.
void setVisOptions(const GEO_VolumeOptions &vis)
Class to store JSON objects as C++ objects.
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
GEO_VolumeVisLod getVisLod() const
GLubyte GLubyte GLubyte GLubyte w
static GA_PrimitiveFamilyMask buildFamilyMask()
virtual void copyCEBuffers(const GA_Primitive *src)
Copy the underlying CE buffer from the source.
void setTypeInfo(GEO_VolumeTypeInfo info)
void callTypedGrid(GEO_PrimVDB &prim, OpType &op)
SYS_FORCE_INLINE const openvdb::GridBase & getGrid() const
Return a reference to this primitive's grid.
UT_SharedPtr< IMX_VDB > IMX_VDBPtr
SYS_FORCE_INLINE void setPointOffset(GA_Offset pt)
void countBaseMemory(UT_MemoryCounter &counter) const
GEO_VolumeVis getVisualization() const
SYS_FORCE_INLINE openvdb::GridBase & getGrid()
Return a reference to this primitive's grid.
bool GEOvdbProcessTypedGrid(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
bool isEmpty() const
True if the underlying grid has no voxels.
bool apply(OpT &op, bool makeUnique=true)
If this primitive's grid resolves to one of the listed grid types, invoke the functor op on the resol...
const openvdb::MetaMap & getConstMetadata() const
Return a reference to this primitive's grid metadata.