11 #ifndef __GEO_PrimVDB__
12 #define __GEO_PrimVDB__
69 CE_VDBGrid *getCEGrid(
bool read,
bool write)
const;
111 void posToIndex(
UT_Vector3 pos,
int &
x,
int &
y,
int &
z)
const;
120 fpreal getValueAtIndexF(
int ix,
int iy,
int iz)
const;
122 UT_Vector3D getValueAtIndexV3(
int ix,
int iy,
int iz)
const;
126 void getValuesAtIndices(
float *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
127 void getValuesAtIndices(
int *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
131 void getValuesAtIndices(
UT_Vector3 *
f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
135 void getValuesAtIndices(
double *
f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
151 int gradients_stride,
159 {
return myGridAccessor.getStorageType(); }
170 bool isActiveRegionMatched(
const GEO_PrimVDB *vdb)
const;
174 bool isWorldAxisAligned()
const;
182 bool isEmpty()
const {
return getGridPtr()->empty(); }
185 fpreal backgroundF()
const;
207 bool dry_run=
false)
override;
209 bool dry_run=
false)
override;
214 void assignVertex(
GA_Offset new_vtx,
bool update_topology);
225 float u,
float v = 0,
226 unsigned du=0,
unsigned dv=0)
const override
265 bool force_taper =
false);
273 void getRes(
int &rx,
int &ry,
int &rz)
const;
278 fpreal getVoxelDiameter()
const;
284 fpreal calcMinimum()
const;
285 fpreal calcMaximum()
const;
286 fpreal calcAverage()
const;
314 activateIndexBBoxAdapter(
315 &bbox, operation, setvalue, value);
323 ActivateOperation operation,
325 bool ignore_transform=
false);
333 void stashed(
bool beingstashed,
394 myVis.myMode = vismode;
396 myVis.myDensity = density;
411 bool as_shmem =
false)
const;
413 bool as_shmem =
false);
416 bool saveVisualization(
419 bool loadVisualization(
438 fpreal calcPositiveDensity()
const;
441 bool hasGrid()
const {
return myGridAccessor.hasGrid(); }
448 { myGridAccessor.makeGridUnique(); }
453 {
return myGridAccessor.isGridUnique(); }
459 {
return myGridAccessor.getConstGrid(*
this); }
464 {
return getConstGrid(); }
472 return myGridAccessor.getGrid(*
this);
480 {
return myGridAccessor.getConstGridPtr(*
this); }
486 {
return getConstGridPtr(); }
495 return myGridAccessor.getGridPtr(*
this);
501 void setGrid(
const openvdb::GridBase &grid,
bool copyPosition=
true)
504 myGridAccessor.setGrid(grid, *
this, copyPosition);
510 {
return getConstGrid(); }
514 {
return getConstGrid(); }
520 incrMetadataUniqueId();
521 return myGridAccessor.getGrid(*
this);
526 const char * getGridName()
const;
531 {
return static_cast<UniqueId>(myUniqueId.relaxedLoad()); }
538 {
return static_cast<UniqueId>(myTreeUniqueId.relaxedLoad()); }
544 {
return static_cast<UniqueId>(myMetadataUniqueId.relaxedLoad()); }
550 {
return static_cast<UniqueId>(myTransformUniqueId.relaxedLoad()); }
565 template<
typename Gr
idTypeListT,
typename OpT>
567 {
return hasGrid() ? getConstGrid().apply<GridTypeListT>(op) :
false; }
587 template<
typename Gr
idTypeListT,
typename OpT>
588 bool apply(OpT& op,
bool makeUnique =
true)
591 auto& grid = myGridAccessor.getGrid(*
this);
593 auto treePtr = grid.baseTreePtr();
594 if (treePtr.use_count() > 2) {
597 grid.apply<GridTypeListT>([
this](openvdb::GridBase& baseGrid) {
598 baseGrid.setTree(baseGrid.constBaseTree().copy());
599 this->incrTreeUniqueId();
603 if (grid.apply<GridTypeListT>(op)) {
618 static
bool isIntrinsicMetadata(const
char *
name);
634 static UniqueId nextUniqueId();
637 { myTreeUniqueId.maximum(nextUniqueId()); }
639 { myMetadataUniqueId.maximum(nextUniqueId()); }
641 { myTransformUniqueId.maximum(nextUniqueId()); }
645 incrMetadataUniqueId();
646 incrTransformUniqueId();
651 void copyGridFrom(
const GEO_PrimVDB&,
bool copyPosition=
true);
683 { updateGridTranslates(prim);
return *myGrid; }
686 const openvdb::GridBase &
688 { updateGridTranslates(prim);
return *myGrid; }
691 openvdb::GridBase::Ptr
693 { updateGridTranslates(prim);
return myGrid; }
696 openvdb::GridBase::ConstPtr
698 { updateGridTranslates(prim);
return myGrid; }
704 { setGridAdapter(&grid, prim, copyPosition); }
707 const openvdb::math::Transform &xform,
709 { setTransformAdapter(&xform, prim); }
711 void makeGridUnique();
712 bool isGridUnique()
const;
721 void updateGridTranslates(
const GEO_PrimVDB &prim)
const;
724 void setVertexPosition(
725 const openvdb::math::Transform &xform,
727 { setVertexPositionAdapter(&xform, prim); }
729 void setGridAdapter(
const void* grid,
GEO_PrimVDB&,
bool copyPosition);
730 void setTransformAdapter(
const void* xform,
GEO_PrimVDB&);
731 void setVertexPositionAdapter(
const void* xform,
GEO_PrimVDB&);
734 openvdb::GridBase::Ptr myGrid;
739 void activateIndexBBoxAdapter(
745 GridAccessor myGridAccessor;
750 mutable bool myCEGridAuthorative;
751 mutable bool myCEGridIsOwned;
753 AtomicUniqueId myUniqueId;
754 AtomicUniqueId myTreeUniqueId;
755 AtomicUniqueId myMetadataUniqueId;
756 AtomicUniqueId myTransformUniqueId;
761 #if 0 // ndef SESI_OPENVDB
762 namespace openvdb_houdini {
763 using ::GEO_VolumeOptions;
772 namespace UT_VDBUtils {
779 template<
typename Gr
idType,
typename OpType>
788 template<
typename Gr
idType,
typename OpType>
809 template <typename OpT>
812 return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
815 template <
typename OpT>
821 template <
typename OpT>
827 template <
typename OpT>
833 template <
typename OpT>
839 template <
typename OpT>
853 template <
typename OpT>
856 if (makeUnique)
return UTvdbProcessTypedGrid(vdb.
getStorageType(), vdb, op);
860 template <
typename OpT>
863 if (makeUnique)
return UTvdbProcessTypedGridReal(vdb.
getStorageType(), vdb, op);
867 template <
typename OpT>
870 if (makeUnique)
return UTvdbProcessTypedGridScalar(vdb.
getStorageType(), vdb, op);
874 template <
typename OpT>
877 if (makeUnique)
return UTvdbProcessTypedGridTopology(vdb.
getStorageType(), vdb, op);
881 template <
typename OpT>
884 if (makeUnique)
return UTvdbProcessTypedGridVec3(vdb.
getStorageType(), vdb, op);
888 template <
typename OpT>
891 if (makeUnique)
return UTvdbProcessTypedGridPoint(vdb.
getStorageType(), vdb, op);
896 #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()
GridType
List of types that are currently supported by NanoVDB.
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
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
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()
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 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.