25 #if !defined(SESI_OPENVDB) && !defined(SESI_OPENVDB_PRIM) 27 #include <GEO/GEO_PrimVDB.h> 30 using ::GEO_VolumeOptions;
34 #else // SESI_OPENVDB || SESI_OPENVDB_PRIM 36 #ifndef __HDK_GEO_PrimVDB__ 37 #define __HDK_GEO_PrimVDB__ 39 #include <GEO/GEO_Primitive.h> 40 #include <GEO/GEO_VolumeOptions.h> 41 #include <GA/GA_Defines.h> 43 #include <SYS/SYS_AtomicInt.h> 45 #include <UT/UT_BoundingBox.h> 54 class GEO_PrimVolumeXform;
55 class UT_MemoryCounter;
62 typedef uint64 UniqueId;
67 GEO_PrimVDB(GEO_Detail *d, GA_Offset offset = GA_INVALID_OFFSET);
69 ~GEO_PrimVDB()
override;
71 static GA_PrimitiveFamilyMask buildFamilyMask()
72 {
return GA_FAMILY_NONE; }
76 bool isDegenerate()
const override;
77 int getBBox(UT_BoundingBox *bbox)
const override;
78 void reverse()
override;
79 UT_Vector3 computeNormal()
const override;
80 void copyPrimitive(
const GEO_Primitive *src)
override;
81 void copySubclassData(
const GA_Primitive *source)
override;
88 CE_VDBGrid *getCEGrid(
bool read,
bool write)
const;
92 void flushCEWriteCaches()
override;
96 void flushCECaches()
override;
99 void stealCEBuffers(
const GA_Primitive *src)
override;
101 using GEO_Primitive::getVertexOffset;
102 using GEO_Primitive::getPointOffset;
103 using GEO_Primitive::setPointOffset;
104 using GEO_Primitive::getPos3;
105 using GEO_Primitive::setPos3;
107 GA_Offset getVertexOffset()
const 108 {
return getVertexOffset(0); }
110 GA_Offset getPointOffset()
const 111 {
return getPointOffset(0); }
113 void setPointOffset(GA_Offset pt)
114 { setPointOffset(0, pt); }
116 UT_Vector3 getPos3()
const 117 {
return getPos3(0); }
119 void setPos3(
const UT_Vector3 &pos)
124 void indexToPos(
int x,
int y,
int z, UT_Vector3 &pos)
const;
125 void findexToPos(UT_Vector3 index, UT_Vector3 &pos)
const;
126 void indexToPos(exint x, exint y, exint z, UT_Vector3D &pos)
const;
127 void findexToPos(UT_Vector3D index, UT_Vector3D &pos)
const;
130 void posToIndex(UT_Vector3 pos,
int &x,
int &y,
int &z)
const;
131 void posToIndex(UT_Vector3 pos, UT_Vector3 &index)
const;
132 void posToIndex(UT_Vector3D pos, exint &x, exint &y, exint &z)
const;
133 void posToIndex(UT_Vector3D pos, UT_Vector3D &index)
const;
138 fpreal getValueF(
const UT_Vector3 &pos)
const;
139 fpreal getValueAtIndexF(
int ix,
int iy,
int iz)
const;
140 UT_Vector3D getValueV3(
const UT_Vector3 &pos)
const;
141 UT_Vector3D getValueAtIndexV3(
int ix,
int iy,
int iz)
const;
143 void getValues(
float *f,
int stride,
const UT_Vector3 *pos,
int num)
const;
144 void getValues(
int *f,
int stride,
const UT_Vector3 *pos,
int num)
const;
145 void getValuesAtIndices(
float *f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
146 void getValuesAtIndices(
int *f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
149 void getValues(UT_Vector3 *f,
int stride,
const UT_Vector3 *pos,
int num)
const;
150 void getValuesAtIndices(UT_Vector3 *f,
int stride,
const int *ix,
const int *iy,
const int *iz,
int num)
const;
152 void getValues(
double *f,
int stride,
const UT_Vector3D *pos,
int num)
const;
153 void getValues(exint *f,
int stride,
const UT_Vector3D *pos,
int num)
const;
154 void getValuesAtIndices(
double *f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
155 void getValuesAtIndices(exint *f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
158 void getValues(UT_Vector3D *f,
int stride,
const UT_Vector3D *pos,
int num)
const;
159 void getValuesAtIndices(UT_Vector3D *f,
int stride,
const exint *ix,
const exint *iy,
const exint *iz,
int num)
const;
162 UT_Vector3 getGradient(
const UT_Vector3 &pos)
const;
169 UT_Vector3 *gradients,
170 int gradients_stride,
171 const UT_Vector3 *positions,
177 UT_VDBType getStorageType()
const 178 {
return myGridAccessor.getStorageType(); }
181 int getTupleSize()
const 182 {
return UTvdbGetGridTupleSize(getStorageType()); }
187 bool isAligned(
const GEO_PrimVDB *vdb)
const;
189 bool isActiveRegionMatched(
const GEO_PrimVDB *vdb)
const;
193 bool isWorldAxisAligned()
const;
197 void transform(
const UT_Matrix4 &mat)
override;
203 void setTransform4(
const UT_DMatrix4 &xform4);
204 void setTransform4(
const UT_Matrix4 &xform4);
205 UT_Matrix4D getTransform4()
const;
213 int detachPoints(GA_PointGroup &grp)
override;
217 GA_DereferenceStatus dereferencePoint(GA_Offset point,
218 bool dry_run=
false)
override;
219 GA_DereferenceStatus dereferencePoints(
const GA_RangeMemberQuery &pt_q,
220 bool dry_run=
false)
override;
221 const GA_PrimitiveJSON *getJSON()
const override;
225 void assignVertex(GA_Offset new_vtx,
bool update_topology);
228 bool evaluatePointRefMap(
229 GA_Offset result_vtx,
230 GA_AttributeRefMap &hlist,
232 uint du, uint dv)
const override;
236 float u,
float v = 0,
237 unsigned du=0,
unsigned dv=0)
const override 239 return GEO_Primitive::evaluatePointV4(pos, u, v,
253 GEO_PrimVolumeXform getIndexSpaceTransform()
const;
259 GEO_PrimVolumeXform getSpaceTransform()
const;
268 GEO_PrimVolumeXform getSpaceTransform(
const UT_BoundingBoxD &bbox)
const;
274 void setSpaceTransform(
const GEO_PrimVolumeXform &space,
275 const UT_Vector3R &resolution,
276 bool force_taper =
false);
280 fpreal getTaper()
const;
284 void getRes(
int &rx,
int &ry,
int &rz)
const;
288 fpreal getVoxelDiameter()
const;
291 UT_Vector3 getVoxelSize()
const;
294 fpreal calcMinimum()
const;
295 fpreal calcMaximum()
const;
296 fpreal calcAverage()
const;
304 bool getFrustumBounds(UT_BoundingBox &idxbox)
const;
306 enum ActivateOperation
319 void activateIndexBBox(
321 ActivateOperation operation,
322 bool setvalue, fpreal
value)
324 activateIndexBBoxAdapter(
325 &bbox, operation, setvalue, value);
332 void activateByVDB(
const GEO_PrimVDB *vdb,
333 ActivateOperation operation,
334 bool setvalue, fpreal
value,
335 bool ignore_transform=
false);
340 GEO_Primitive *copy(
int preserve_shared_pts = 0)
const override;
343 void stashed(
bool beingstashed,
344 GA_Offset offset=GA_INVALID_OFFSET)
override;
351 UT_Vector3 baryCenter()
const override;
352 fpreal calcVolume(
const UT_Vector3 &refpt)
const override;
355 fpreal calcArea()
const override;
363 bool enlargeBoundingBox(
365 const GA_Attribute *P)
const override;
366 bool enlargeBoundingBox(
368 const GA_Attribute *P)
const override;
369 void enlargePointBounds(UT_BoundingBox &e)
const override;
375 bool enlargeBoundingSphere(
376 UT_BoundingSphere &b,
377 const GA_Attribute *P)
const override;
383 void getLocalTransform(UT_Matrix3D &result)
const override;
384 void setLocalTransform(
const UT_Matrix3D &new_mat3)
override;
390 static bool conditionMatrix(UT_Matrix4D &mat4);
394 const GEO_VolumeOptions &getVisOptions()
const {
return myVis; }
395 void setVisOptions(
const GEO_VolumeOptions &vis)
396 { setVisualization(vis.myMode, vis.myIso, vis.myDensity, vis.myLod); }
398 void setVisualization(
399 GEO_VolumeVis vismode,
402 GEO_VolumeVisLod lod = GEO_VOLUMEVISLOD_FULL)
404 myVis.myMode = vismode;
406 myVis.myDensity = density;
409 GEO_VolumeVis getVisualization()
const {
return myVis.myMode; }
410 fpreal getVisIso()
const {
return myVis.myIso; }
411 fpreal getVisDensity()
const {
return myVis.myDensity; }
412 GEO_VolumeVisLod getVisLod()
const {
return myVis.myLod; }
416 bool loadOrder(
const UT_JSONValue &p);
420 bool saveVDB(UT_JSONWriter &w,
const GA_SaveMap &sm,
421 bool as_shmem =
false)
const;
422 bool loadVDB(UT_JSONParser &p,
423 bool as_shmem =
false);
426 bool saveVisualization(
428 const GA_SaveMap &map)
const;
429 bool loadVisualization(
431 const GA_LoadMap &map);
434 GA_Offset fastVertexOffset(GA_Size UT_IF_ASSERT_P(index))
const 436 UT_ASSERT_P(index < 1);
437 return getVertexOffset();
440 void setVertexPoint(
int i, GA_Offset pt)
448 fpreal calcPositiveDensity()
const;
451 bool hasGrid()
const {
return myGridAccessor.hasGrid(); }
457 void makeGridUnique()
458 { myGridAccessor.makeGridUnique(); }
462 bool isGridUnique()
const 463 {
return myGridAccessor.isGridUnique(); }
469 {
return myGridAccessor.getConstGrid(*
this); }
474 {
return getConstGrid(); }
482 return myGridAccessor.getGrid(*
this);
490 {
return myGridAccessor.getConstGridPtr(*
this); }
496 {
return getConstGridPtr(); }
505 return myGridAccessor.getGridPtr(*
this);
514 myGridAccessor.setGrid(grid, *
this, copyPosition);
520 {
return getConstGrid(); }
524 {
return getConstGrid(); }
530 incrMetadataUniqueId();
531 return myGridAccessor.getGrid(*
this);
536 const char * getGridName()
const;
540 UniqueId getUniqueId()
const 541 {
return static_cast<UniqueId
>(myUniqueId.relaxedLoad()); }
547 UniqueId getTreeUniqueId()
const 548 {
return static_cast<UniqueId
>(myTreeUniqueId.relaxedLoad()); }
553 UniqueId getMetadataUniqueId()
const 554 {
return static_cast<UniqueId
>(myMetadataUniqueId.relaxedLoad()); }
559 UniqueId getTransformUniqueId()
const 560 {
return static_cast<UniqueId
>(myTransformUniqueId.relaxedLoad()); }
575 template<
typename Gr
idTypeListT,
typename OpT>
576 bool apply(OpT& op)
const 577 {
return hasGrid() ? getConstGrid().apply<GridTypeListT>(op) :
false; }
597 template<
typename Gr
idTypeListT,
typename OpT>
598 bool apply(OpT& op,
bool makeUnique =
true)
601 auto& grid = myGridAccessor.getGrid(*
this);
604 if (treePtr.use_count() > 2) {
608 baseGrid.setTree(baseGrid.constBaseTree().copy());
609 this->incrTreeUniqueId();
613 if (grid.
apply<GridTypeListT>(op)) {
622 typedef SYS_AtomicCounter AtomicUniqueId;
625 GA_DECLARE_INTRINSICS(
override)
628 static
bool isIntrinsicMetadata(const
char *name);
631 GA_Offset vertexPoint(GA_Size)
const 632 {
return getPointOffset(); }
636 int64 getBaseMemoryUsage()
const;
640 void countBaseMemory(UT_MemoryCounter &counter)
const;
644 static UniqueId nextUniqueId();
646 void incrTreeUniqueId()
647 { myTreeUniqueId.maximum(nextUniqueId()); }
648 void incrMetadataUniqueId()
649 { myMetadataUniqueId.maximum(nextUniqueId()); }
650 void incrTransformUniqueId()
651 { myTransformUniqueId.maximum(nextUniqueId()); }
652 void incrGridUniqueIds()
655 incrMetadataUniqueId();
656 incrTransformUniqueId();
661 void copyGridFrom(
const GEO_PrimVDB&,
bool copyPosition=
true);
680 GridAccessor() : myStorageType(UT_VDB_INVALID)
687 myStorageType = UT_VDB_INVALID;
692 getGrid(
const GEO_PrimVDB &prim)
693 { updateGridTranslates(prim);
return *myGrid; }
697 getConstGrid(
const GEO_PrimVDB &prim)
const 698 { updateGridTranslates(prim);
return *myGrid; }
702 getGridPtr(
const GEO_PrimVDB &prim)
703 { updateGridTranslates(prim);
return myGrid; }
707 getConstGridPtr(
const GEO_PrimVDB &prim)
const 708 { updateGridTranslates(prim);
return myGrid; }
713 void setGrid(
const openvdb::GridBase& grid, GEO_PrimVDB& prim,
bool copyPosition=
true)
714 { setGridAdapter(&grid, prim, copyPosition); }
717 const openvdb::math::Transform &xform,
719 { setTransformAdapter(&xform, prim); }
721 void makeGridUnique();
722 bool isGridUnique()
const;
725 UT_VDBType getStorageType()
const {
return myStorageType; }
728 bool hasGrid()
const {
return myGrid != 0; }
731 void updateGridTranslates(
const GEO_PrimVDB &prim)
const;
734 void setVertexPosition(
735 const openvdb::math::Transform &xform,
737 { setVertexPositionAdapter(&xform, prim); }
739 void setGridAdapter(
const void* grid, GEO_PrimVDB&,
bool copyPosition);
740 void setTransformAdapter(
const void* xform, GEO_PrimVDB&);
741 void setVertexPositionAdapter(
const void* xform, GEO_PrimVDB&);
745 UT_VDBType myStorageType;
749 void activateIndexBBoxAdapter(
752 bool setvalue, fpreal
value);
755 GridAccessor myGridAccessor;
757 GEO_VolumeOptions myVis;
759 mutable CE_VDBGrid *myCEGrid;
760 mutable bool myCEGridAuthorative;
761 mutable bool myCEGridIsOwned;
763 AtomicUniqueId myUniqueId;
764 AtomicUniqueId myTreeUniqueId;
765 AtomicUniqueId myMetadataUniqueId;
766 AtomicUniqueId myTransformUniqueId;
773 using ::GEO_VolumeOptions;
782 namespace UT_VDBUtils {
789 template<
typename Gr
idType,
typename OpType>
791 callTypedGrid(GEO_PrimVDB& prim, OpType& op)
793 prim.makeGridUnique();
794 op.template operator()<
GridType>(*(UTverify_cast<
GridType*>(&prim.getGrid())));
798 template<
typename Gr
idType,
typename OpType>
800 callTypedGrid(
const GEO_PrimVDB& prim, OpType& op)
802 op.template operator()<
GridType>(*(UTverify_cast<
const GridType*>(&prim.getConstGrid())));
809 UT_VDB_DECL_PROCESS_TYPED_GRID(GEO_PrimVDB&)
810 UT_VDB_DECL_PROCESS_TYPED_GRID(const GEO_PrimVDB&)
819 template <typename OpT>
820 inline
bool GEOvdbProcessTypedGrid(const GEO_PrimVDB &vdb, OpT &op)
822 return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
825 template <
typename OpT>
826 inline bool GEOvdbProcessTypedGridReal(
const GEO_PrimVDB &vdb, OpT &op)
828 return UTvdbProcessTypedGridReal(vdb.getStorageType(), vdb.getGrid(), op);
831 template <
typename OpT>
832 inline bool GEOvdbProcessTypedGridScalar(
const GEO_PrimVDB &vdb, OpT &op)
834 return UTvdbProcessTypedGridScalar(vdb.getStorageType(), vdb.getGrid(), op);
837 template <
typename OpT>
838 inline bool GEOvdbProcessTypedGridTopology(
const GEO_PrimVDB &vdb, OpT &op)
840 return UTvdbProcessTypedGridTopology(vdb.getStorageType(), vdb.getGrid(), op);
843 template <
typename OpT>
844 inline bool GEOvdbProcessTypedGridVec3(
const GEO_PrimVDB &vdb, OpT &op)
846 return UTvdbProcessTypedGridVec3(vdb.getStorageType(), vdb.getGrid(), op);
849 template <
typename OpT>
850 inline bool GEOvdbProcessTypedGridPoint(
const GEO_PrimVDB &vdb, OpT &op)
852 return UTvdbProcessTypedGridPoint(vdb.getStorageType(), vdb.getGrid(), op);
863 template <
typename OpT>
864 inline bool GEOvdbProcessTypedGrid(GEO_PrimVDB &vdb, OpT &op,
bool makeUnique =
true)
866 if (makeUnique)
return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb, op);
867 return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
870 template <
typename OpT>
871 inline bool GEOvdbProcessTypedGridReal(GEO_PrimVDB &vdb, OpT &op,
bool makeUnique =
true)
873 if (makeUnique)
return UTvdbProcessTypedGridReal(vdb.getStorageType(), vdb, op);
874 return UTvdbProcessTypedGridReal(vdb.getStorageType(), vdb.getGrid(), op);
877 template <
typename OpT>
878 inline bool GEOvdbProcessTypedGridScalar(GEO_PrimVDB &vdb, OpT &op,
bool makeUnique =
true)
880 if (makeUnique)
return UTvdbProcessTypedGridScalar(vdb.getStorageType(), vdb, op);
881 return UTvdbProcessTypedGridScalar(vdb.getStorageType(), vdb.getGrid(), op);
884 template <
typename OpT>
885 inline bool GEOvdbProcessTypedGridTopology(GEO_PrimVDB &vdb, OpT &op,
bool makeUnique =
true)
887 if (makeUnique)
return UTvdbProcessTypedGridTopology(vdb.getStorageType(), vdb, op);
888 return UTvdbProcessTypedGridTopology(vdb.getStorageType(), vdb.getGrid(), op);
891 template <
typename OpT>
892 inline bool GEOvdbProcessTypedGridVec3(GEO_PrimVDB &vdb, OpT &op,
bool makeUnique =
true)
894 if (makeUnique)
return UTvdbProcessTypedGridVec3(vdb.getStorageType(), vdb, op);
895 return UTvdbProcessTypedGridVec3(vdb.getStorageType(), vdb.getGrid(), op);
898 template <
typename OpT>
899 inline bool GEOvdbProcessTypedGridPoint(GEO_PrimVDB &vdb, OpT &op,
bool makeUnique =
true)
901 if (makeUnique)
return UTvdbProcessTypedGridPoint(vdb.getStorageType(), vdb, op);
902 return UTvdbProcessTypedGridPoint(vdb.getStorageType(), vdb.getGrid(), op);
906 #endif // __HDK_GEO_PrimVDB__ 908 #endif // SESI_OPENVDB || SESI_OPENVDB_PRIM SharedPtr< const GridBase > ConstPtr
Definition: Grid.h:81
bool hasGrid(const std::string &fileName, const std::string &gridName)
Return true if the file contains a grid with the specified name.
Definition: IO.h:707
Abstract base class for typed grids.
Definition: Grid.h:77
SharedPtr< GridBase > Ptr
Definition: Grid.h:80
static fileSize_t write(std::ostream &os, const GridHandle< BufferT > &handle, Codec codec)
static void read(std::istream &is, GridHandle< BufferT > &handle, Codec codec)
BBox< Coord > CoordBBox
Definition: NanoVDB.h:1658
TreeBase::Ptr baseTreePtr()
Return a pointer to this grid's tree, which might be shared with other grids. The pointer is guarante...
Definition: Grid.h:1240
ValueT value
Definition: GridBuilder.h:1287
bool apply(OpT &) const
If this grid resolves to one of the listed grid types, invoke the given functor on the resolved grid...
Definition: Grid.h:1811
Definition: AttributeTransferUtil.h:34
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:216