11 #ifndef __GEO_PrimVDB__
12 #define __GEO_PrimVDB__
108 void posToIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
117 fpreal getValueAtIndexF(
int ix,
int iy,
int iz)
const;
119 UT_Vector3D getValueAtIndexV3(
int ix,
int iy,
int iz)
const;
123 void getValuesAtIndices(
float *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
124 void getValuesAtIndices(
int *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
128 void getValuesAtIndices(
UT_Vector3 *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
148 int gradients_stride,
156 {
return myGridAccessor.getStorageType(); }
167 bool isActiveRegionMatched(
const GEO_PrimVDB *vdb)
const;
171 bool isWorldAxisAligned()
const;
179 bool isEmpty()
const {
return getGridPtr()->empty(); }
182 fpreal backgroundF()
const;
204 bool dry_run=
false)
override;
206 bool dry_run=
false)
override;
211 void assignVertex(
GA_Offset new_vtx,
bool update_topology);
222 float u,
float v = 0,
223 unsigned du=0,
unsigned dv=0)
const override
262 bool force_taper =
false);
270 void getRes(
int &rx,
int &ry,
int &rz)
const;
274 fpreal getVoxelDiameter()
const;
280 fpreal calcMinimum()
const;
281 fpreal calcMaximum()
const;
282 fpreal calcAverage()
const;
306 const openvdb::CoordBBox& bbox,
310 activateIndexBBoxAdapter(
311 &bbox, operation, setvalue, value);
319 ActivateOperation operation,
321 bool ignore_transform=
false);
329 void stashed(
bool beingstashed,
390 myVis.myMode = vismode;
392 myVis.myDensity = density;
407 bool as_shmem =
false)
const;
409 bool as_shmem =
false);
412 bool saveVisualization(
415 bool loadVisualization(
434 fpreal calcPositiveDensity()
const;
437 bool hasGrid()
const {
return myGridAccessor.hasGrid(); }
444 { myGridAccessor.makeGridUnique(); }
449 {
return myGridAccessor.isGridUnique(); }
455 {
return myGridAccessor.getConstGrid(*
this); }
460 {
return getConstGrid(); }
468 return myGridAccessor.getGrid(*
this);
476 {
return myGridAccessor.getConstGridPtr(*
this); }
482 {
return getConstGridPtr(); }
491 return myGridAccessor.getGridPtr(*
this);
497 void setGrid(
const openvdb::GridBase &grid,
bool copyPosition=
true)
500 myGridAccessor.setGrid(grid, *
this, copyPosition);
506 {
return getConstGrid(); }
510 {
return getConstGrid(); }
516 incrMetadataUniqueId();
517 return myGridAccessor.getGrid(*
this);
522 const char * getGridName()
const;
527 {
return static_cast<UniqueId>(myUniqueId.relaxedLoad()); }
534 {
return static_cast<UniqueId>(myTreeUniqueId.relaxedLoad()); }
540 {
return static_cast<UniqueId>(myMetadataUniqueId.relaxedLoad()); }
546 {
return static_cast<UniqueId>(myTransformUniqueId.relaxedLoad()); }
561 template<
typename Gr
idTypeListT,
typename OpT>
563 {
return hasGrid() ? getConstGrid().apply<GridTypeListT>(op) :
false; }
583 template<
typename Gr
idTypeListT,
typename OpT>
584 bool apply(OpT& op,
bool makeUnique =
true)
587 auto& grid = myGridAccessor.getGrid(*
this);
589 auto treePtr = grid.baseTreePtr();
590 if (treePtr.use_count() > 2) {
593 grid.apply<GridTypeListT>([
this](openvdb::GridBase& baseGrid) {
594 baseGrid.setTree(baseGrid.constBaseTree().copy());
595 this->incrTreeUniqueId();
599 if (grid.apply<GridTypeListT>(op)) {
614 static
bool isIntrinsicMetadata(
const char *
name);
630 static UniqueId nextUniqueId();
633 { myTreeUniqueId.maximum(nextUniqueId()); }
635 { myMetadataUniqueId.maximum(nextUniqueId()); }
637 { myTransformUniqueId.maximum(nextUniqueId()); }
641 incrMetadataUniqueId();
642 incrTransformUniqueId();
647 void copyGridFrom(
const GEO_PrimVDB&,
bool copyPosition=
true);
679 { updateGridTranslates(prim);
return *myGrid; }
682 const openvdb::GridBase &
684 { updateGridTranslates(prim);
return *myGrid; }
687 openvdb::GridBase::Ptr
689 { updateGridTranslates(prim);
return myGrid; }
692 openvdb::GridBase::ConstPtr
694 { updateGridTranslates(prim);
return myGrid; }
700 { setGridAdapter(&grid, prim, copyPosition); }
703 const openvdb::math::Transform &xform,
705 { setTransformAdapter(&xform, prim); }
707 void makeGridUnique();
708 bool isGridUnique()
const;
717 void updateGridTranslates(
const GEO_PrimVDB &prim)
const;
720 void setVertexPosition(
721 const openvdb::math::Transform &xform,
723 { setVertexPositionAdapter(&xform, prim); }
725 void setGridAdapter(
const void* grid,
GEO_PrimVDB&,
bool copyPosition);
726 void setTransformAdapter(
const void* xform,
GEO_PrimVDB&);
727 void setVertexPositionAdapter(
const void* xform,
GEO_PrimVDB&);
730 openvdb::GridBase::Ptr myGrid;
735 void activateIndexBBoxAdapter(
741 GridAccessor myGridAccessor;
746 mutable bool myCEGridAuthorative;
747 mutable bool myCEGridIsOwned;
749 AtomicUniqueId myUniqueId;
750 AtomicUniqueId myTreeUniqueId;
751 AtomicUniqueId myMetadataUniqueId;
752 AtomicUniqueId myTransformUniqueId;
757 #if 0 // ndef SESI_OPENVDB
758 namespace openvdb_houdini {
759 using ::GEO_VolumeOptions;
768 namespace UT_VDBUtils {
775 template<
typename Gr
idType,
typename OpType>
784 template<
typename Gr
idType,
typename OpType>
805 template <typename OpT>
808 return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
811 template <
typename OpT>
817 template <
typename OpT>
823 template <
typename OpT>
829 template <
typename OpT>
835 template <
typename OpT>
849 template <
typename OpT>
852 if (makeUnique)
return UTvdbProcessTypedGrid(vdb.
getStorageType(), vdb, op);
856 template <
typename OpT>
859 if (makeUnique)
return UTvdbProcessTypedGridReal(vdb.
getStorageType(), vdb, op);
863 template <
typename OpT>
866 if (makeUnique)
return UTvdbProcessTypedGridScalar(vdb.
getStorageType(), vdb, op);
870 template <
typename OpT>
873 if (makeUnique)
return UTvdbProcessTypedGridTopology(vdb.
getStorageType(), vdb, op);
877 template <
typename OpT>
880 if (makeUnique)
return UTvdbProcessTypedGridVec3(vdb.
getStorageType(), vdb, op);
884 template <
typename OpT>
887 if (makeUnique)
return UTvdbProcessTypedGridPoint(vdb.
getStorageType(), vdb, op);
892 #endif // __GEO_PrimVDB__
virtual void flushCEWriteCaches()
Copy any modified caches from the GPU back to CPU cache.
virtual void flushCECaches()
GLboolean GLboolean GLboolean b
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
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()
virtual UT_Vector3D computeNormalD() const =0
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)
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.
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)
bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const 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)
GLuint const GLchar * name
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
void read(T &in, bool &v)
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.
GLubyte GLubyte GLubyte GLubyte w
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
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.
bool GEOvdbProcessTypedGridScalar(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
GLsizei GLsizei GLchar * source
void incrMetadataUniqueId()
virtual const GA_PrimitiveJSON * getJSON() const =0
void setVertexPoint(int i, GA_Offset pt)
Provide a JSON interface to a primitive.
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)
GLdouble GLdouble GLdouble z
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()
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 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...
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
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
static GA_PrimitiveFamilyMask buildFamilyMask()
void callTypedGrid(GEO_PrimVDB &prim, OpType &op)
GLint GLenum GLboolean GLsizei stride
SYS_FORCE_INLINE const openvdb::GridBase & getGrid() const
Return a reference to this primitive's grid.
SYS_FORCE_INLINE void setPointOffset(GA_Offset pt)
void write(T &out, bool v)
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)
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept
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.