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;
132 void getValuesAtIndices(
double *
f,
int stride,
const exint *ix,
const exint *iy,
const exint *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;
275 fpreal getVoxelDiameter()
const;
281 fpreal calcMinimum()
const;
282 fpreal calcMaximum()
const;
283 fpreal calcAverage()
const;
307 const openvdb::CoordBBox& bbox,
311 activateIndexBBoxAdapter(
312 &bbox, operation, setvalue, value);
320 ActivateOperation operation,
322 bool ignore_transform=
false);
330 void stashed(
bool beingstashed,
391 myVis.myMode = vismode;
393 myVis.myDensity = density;
408 bool as_shmem =
false)
const;
410 bool as_shmem =
false);
413 bool saveVisualization(
416 bool loadVisualization(
435 fpreal calcPositiveDensity()
const;
438 bool hasGrid()
const {
return myGridAccessor.hasGrid(); }
445 { myGridAccessor.makeGridUnique(); }
450 {
return myGridAccessor.isGridUnique(); }
456 {
return myGridAccessor.getConstGrid(*
this); }
461 {
return getConstGrid(); }
469 return myGridAccessor.getGrid(*
this);
477 {
return myGridAccessor.getConstGridPtr(*
this); }
483 {
return getConstGridPtr(); }
492 return myGridAccessor.getGridPtr(*
this);
498 void setGrid(
const openvdb::GridBase &grid,
bool copyPosition=
true)
501 myGridAccessor.setGrid(grid, *
this, copyPosition);
507 {
return getConstGrid(); }
511 {
return getConstGrid(); }
517 incrMetadataUniqueId();
518 return myGridAccessor.getGrid(*
this);
523 const char * getGridName()
const;
528 {
return static_cast<UniqueId>(myUniqueId.relaxedLoad()); }
535 {
return static_cast<UniqueId>(myTreeUniqueId.relaxedLoad()); }
541 {
return static_cast<UniqueId>(myMetadataUniqueId.relaxedLoad()); }
547 {
return static_cast<UniqueId>(myTransformUniqueId.relaxedLoad()); }
562 template<
typename Gr
idTypeListT,
typename OpT>
564 {
return hasGrid() ? getConstGrid().apply<GridTypeListT>(op) :
false; }
584 template<
typename Gr
idTypeListT,
typename OpT>
585 bool apply(OpT& op,
bool makeUnique =
true)
588 auto& grid = myGridAccessor.getGrid(*
this);
590 auto treePtr = grid.baseTreePtr();
591 if (treePtr.use_count() > 2) {
594 grid.apply<GridTypeListT>([
this](openvdb::GridBase& baseGrid) {
595 baseGrid.setTree(baseGrid.constBaseTree().copy());
596 this->incrTreeUniqueId();
600 if (grid.apply<GridTypeListT>(op)) {
615 static
bool isIntrinsicMetadata(
const char *
name);
631 static UniqueId nextUniqueId();
634 { myTreeUniqueId.maximum(nextUniqueId()); }
636 { myMetadataUniqueId.maximum(nextUniqueId()); }
638 { myTransformUniqueId.maximum(nextUniqueId()); }
642 incrMetadataUniqueId();
643 incrTransformUniqueId();
648 void copyGridFrom(
const GEO_PrimVDB&,
bool copyPosition=
true);
680 { updateGridTranslates(prim);
return *myGrid; }
683 const openvdb::GridBase &
685 { updateGridTranslates(prim);
return *myGrid; }
688 openvdb::GridBase::Ptr
690 { updateGridTranslates(prim);
return myGrid; }
693 openvdb::GridBase::ConstPtr
695 { updateGridTranslates(prim);
return myGrid; }
701 { setGridAdapter(&grid, prim, copyPosition); }
704 const openvdb::math::Transform &xform,
706 { setTransformAdapter(&xform, prim); }
708 void makeGridUnique();
709 bool isGridUnique()
const;
718 void updateGridTranslates(
const GEO_PrimVDB &prim)
const;
721 void setVertexPosition(
722 const openvdb::math::Transform &xform,
724 { setVertexPositionAdapter(&xform, prim); }
726 void setGridAdapter(
const void* grid,
GEO_PrimVDB&,
bool copyPosition);
727 void setTransformAdapter(
const void* xform,
GEO_PrimVDB&);
728 void setVertexPositionAdapter(
const void* xform,
GEO_PrimVDB&);
731 openvdb::GridBase::Ptr myGrid;
736 void activateIndexBBoxAdapter(
742 GridAccessor myGridAccessor;
747 mutable bool myCEGridAuthorative;
748 mutable bool myCEGridIsOwned;
750 AtomicUniqueId myUniqueId;
751 AtomicUniqueId myTreeUniqueId;
752 AtomicUniqueId myMetadataUniqueId;
753 AtomicUniqueId myTransformUniqueId;
758 #if 0 // ndef SESI_OPENVDB
759 namespace openvdb_houdini {
760 using ::GEO_VolumeOptions;
769 namespace UT_VDBUtils {
776 template<
typename Gr
idType,
typename OpType>
785 template<
typename Gr
idType,
typename OpType>
806 template <typename OpT>
809 return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
812 template <
typename OpT>
818 template <
typename OpT>
824 template <
typename OpT>
830 template <
typename OpT>
836 template <
typename OpT>
850 template <
typename OpT>
853 if (makeUnique)
return UTvdbProcessTypedGrid(vdb.
getStorageType(), vdb, op);
857 template <
typename OpT>
860 if (makeUnique)
return UTvdbProcessTypedGridReal(vdb.
getStorageType(), vdb, op);
864 template <
typename OpT>
867 if (makeUnique)
return UTvdbProcessTypedGridScalar(vdb.
getStorageType(), vdb, op);
871 template <
typename OpT>
874 if (makeUnique)
return UTvdbProcessTypedGridTopology(vdb.
getStorageType(), vdb, op);
878 template <
typename OpT>
881 if (makeUnique)
return UTvdbProcessTypedGridVec3(vdb.
getStorageType(), vdb, op);
885 template <
typename OpT>
888 if (makeUnique)
return UTvdbProcessTypedGridPoint(vdb.
getStorageType(), vdb, op);
893 #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
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)
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
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.
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.
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 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
GLubyte GLubyte GLubyte GLubyte w
static GA_PrimitiveFamilyMask buildFamilyMask()
void callTypedGrid(GEO_PrimVDB &prim, OpType &op)
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.