HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PrimVDB.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: GEO_PrimVDB.h ( GEO Library, C++)
7  *
8  * COMMENTS: VDB primitive
9  * Implemented in:
10  * GEO_PrimVDB.C
11  * GEO_PrimVDB_Activate.C,
12  * GEO_PrimVDB_Sample.C,
13  * GEO_PrimVDB_Stats.C,
14  */
15 
16 #ifndef __GEO_PrimVDB__
17 #define __GEO_PrimVDB__
18 
19 #include "GEO_API.h"
20 #include "GEO_Primitive.h"
21 #include "GEO_VolumeOptions.h"
22 
23 #include <GA/GA_Defines.h>
24 
25 #include <SYS/SYS_AtomicInt.h> // for SYS_AtomicCounter
26 
27 #include <UT/UT_BoundingBox.h>
28 #include <UT/UT_VDBUtils.h>
29 
30 #include <IMX/IMX_VDB.h>
31 
32 #include <openvdb/Platform.h>
33 #include <openvdb/openvdb.h>
34 
35 
36 class GEO_Detail;
37 class GEO_PrimVolume;
38 class GA_PrimVolumeXform;
40 class UT_MemoryCounter;
41 
42 class CE_VDBGrid;
43 
45 {
46 public:
47  typedef uint64 UniqueId;
48 
49 protected:
50  /// NOTE: The constructor should only be called from subclass
51  /// constructors.
53 
54  ~GEO_PrimVDB() override;
55 public:
57  { return GA_FAMILY_NONE; }
58 
59  /// @{
60  /// Required interface methods
61  bool isDegenerate() const override;
62  bool getBBox(UT_BoundingBox *bbox) const override;
63  void reverse() override;
64  UT_Vector3 computeNormal() const override;
65  UT_Vector3D computeNormalD() const override;
66  void copyPrimitive(const GEO_Primitive *src) override;
67  void copySubclassData(const GA_Primitive *source) override;
68 
69  int64 getDeviceMemoryUsage() const override;
70 
71  /// Acquire a CE grid and cache it on the GPU. If marked for
72  /// writing, the CPU version will be overwritten.
73  /// Note that the getVoxelHandle does *NOT* auto-flush these!
74  /// NOTE: If someone else fetches a non-read grid, and you fetch it
75  /// as a read grid, you will not get any copied data.
76  CE_VDBGrid *getCEGrid(bool read, bool write) const;
77 
78  /// Acquire an IMX layer for this volume. If marked for reading, it will
79  /// have identical data to this volume. If marked for writing, this volume's
80  /// data will be overwritten.
81  /// Note that the getGrid does *NOT* auto-flush these!
82  IMX_VDBPtr getIMXVDB(bool read, bool write) const;
83  /// Set a proxy compute vdb that we may reference for our data.
84  /// Upon first cpu request, the data is then copied to the main VDB
85  /// structure.
86  void setBorrowedIMXVDB(const UT_SharedPtr<IMX_VDB> &v);
87 
88  /// Any modified CE cache on the GPU will be copied back to the
89  /// CPU. Will leave result on GPU.
90  void flushCEWriteCaches() override;
91 
92  /// Remove all CE caches from the GPU, possibly writing back
93  /// if necessary.
94  void flushCECaches() override;
95 
96  /// Steal the underlying CE buffer from the source.
97  void stealCEBuffers(const GA_Primitive *src) override;
98 
106  { return getVertexOffset(0); }
109  { return getPointOffset(0); }
112  { setPointOffset(0, pt); }
115  { return getPos3(0); }
117  void setPos3(const UT_Vector3 &pos)
118  { setPos3(0, pos); }
119 
120  /// Convert an index in the voxel array into the corresponding worldspace
121  /// location
122  void indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
123  void findexToPos(UT_Vector3 index, UT_Vector3 &pos) const;
124  void indexToPos(exint x, exint y, exint z, UT_Vector3D &pos) const;
125  void findexToPos(UT_Vector3D index, UT_Vector3D &pos) const;
126 
127  /// Convert a 3d position into the closest index value.
128  void posToIndex(UT_Vector3 pos, int &x, int &y, int &z) const;
129  void posToIndex(UT_Vector3 pos, UT_Vector3 &index) const;
130  void posToIndex(UT_Vector3D pos, exint &x, exint &y, exint &z) const;
131  void posToIndex(UT_Vector3D pos, UT_Vector3D &index) const;
132 
133  /// Evaluate the voxel value at the given world space position.
134  /// Note that depending on the underlying VDB type, this may not
135  /// be sensible, in which case a zero will silently be returned
136  fpreal getValueF(const UT_Vector3 &pos) const;
137  fpreal getValueAtIndexF(int ix, int iy, int iz) const;
138  UT_Vector3D getValueV3(const UT_Vector3 &pos) const;
139  UT_Vector3D getValueAtIndexV3(int ix, int iy, int iz) const;
140 
141  void getValues(float *f, int stride, const UT_Vector3 *pos, int num) const;
142  void getValues(int *f, int stride, const UT_Vector3 *pos, int num) const;
143  void getValuesAtIndices(float *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
144  void getValuesAtIndices(int *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
145 
146  /// Vector grid variants.
147  void getValues(UT_Vector3 *f, int stride, const UT_Vector3 *pos, int num) const;
148  void getValuesAtIndices(UT_Vector3 *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
149 
150  void getValues(double *f, int stride, const UT_Vector3D *pos, int num) const;
151  void getValues(exint *f, int stride, const UT_Vector3D *pos, int num) const;
152  void getValuesAtIndices(double *f, int stride, const exint *ix, const exint *iy, const exint *iz, int num) const;
153  void getValuesAtIndices(exint *f, int stride, const exint *ix, const exint *iy, const exint *iz, int num) const;
154 
155  /// Vector grid variants.
156  void getValues(UT_Vector3D *f, int stride, const UT_Vector3D *pos, int num) const;
157  void getValuesAtIndices(UT_Vector3D *f, int stride, const exint *ix, const exint *iy, const exint *iz, int num) const;
158 
159  // Worldspace gradient at the given position
160  UT_Vector3 getGradient(const UT_Vector3 &pos) const;
161 
162  /// Evaluate this grid's gradients at the given world space positions.
163  /// Does nothing and returns false if grid is non-scalar.
164  /// If normalize is true, then the gradients will be normalized to be unit
165  /// length.
166  bool evalGradients(
167  UT_Vector3 *gradients,
168  int gradients_stride,
169  const UT_Vector3 *positions,
170  int num_positions,
171  bool normalize = false) const;
172 
173  /// Get the storage type of the grid
176  { return myGridAccessor.getStorageType(); }
177  /// Get the tuple size, usually 1 or 3
179  int getTupleSize() const
180  { return UTvdbGetGridTupleSize(getStorageType()); }
181 
182  bool isSDF() const;
183 
184  /// True if the two volumes map the same indices to the same positions.
185  bool isAligned(const GEO_PrimVDB *vdb) const;
186  /// True if the two volumes have the same active regions
187  bool isActiveRegionMatched(const GEO_PrimVDB *vdb) const;
188 
189  /// True if we are aligned with the world axes. Ie, all our
190  /// off diagonals are zero and our diagonal is positive.
191  bool isWorldAxisAligned() const;
192 
193  // Transform the matrix associated with this primitive. Translate is
194  // ignored.
195  void transform(const UT_Matrix4 &mat) override;
196 
197 
198  /// True if the underlying grid has no voxels.
199  bool isEmpty() const { return getGridPtr()->empty(); }
200 
201  /// Background value of the grid as a scalar or vector.
202  fpreal backgroundF() const;
203  UT_Vector3D backgroundV3() const;
204 
205  /// Accessors for the 4x4 matrix representing the affine transform that
206  /// converts from index space voxel coordinates to world space. For frustum
207  /// maps, this will be transform as if the taper value is set to 1.
208  /// @{
209  void setTransform4(const UT_DMatrix4 &xform4);
210  void setTransform4(const UT_Matrix4 &xform4);
211  UT_Matrix4D getTransform4() const;
212  /// @}
213 
214  // Take the whole set of points into consideration when applying the
215  // point removal operation to this primitive. The method returns 0 if
216  // successful, -1 if it failed because it would have become degenerate,
217  // and -2 if it failed because it would have had to remove the primitive
218  // altogether.
219  int detachPoints(GA_PointGroup &grp) override;
220  /// Before a point is deleted, all primitives using the point will be
221  /// notified. The method should return "false" if it's impossible to
222  /// delete the point. Otherwise, the vertices should be removed.
223  GA_DereferenceStatus dereferencePoint(GA_Offset point,
224  bool dry_run=false) override;
225  GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q,
226  bool dry_run=false) override;
227  const GA_PrimitiveJSON *getJSON() const override;
228 
229  /// This method assigns a preallocated vertex to the quadric, optionally
230  /// creating the topological link between the primitive and new vertex.
231  void assignVertex(GA_Offset new_vtx, bool update_topology);
232 
233  /// Evalaute a point given a u,v coordinate (with derivatives)
234  bool evaluatePointRefMap(
235  GA_Offset result_vtx,
236  GA_AttributeRefMap &hlist,
237  fpreal u, fpreal v,
238  uint du, uint dv) const override;
239  /// Evalaute position given a u,v coordinate (with derivatives)
241  UT_Vector4 &pos,
242  float u, float v = 0,
243  unsigned du=0, unsigned dv=0) const override
244  {
245  return GEO_Primitive::evaluatePointV4(pos, u, v,
246  du, dv);
247  }
248  /// @}
249 
250  /// Convert transforms between native volumes and VDBs
251  /// @{
252 
253  /// Get a GEO_PrimVolumeXform which represent's the grid's full transform.
254  /// The returned space's fromVoxelSpace() method will convert index space
255  /// voxel coordinates to world space positions (and the vice versa for
256  /// toVoxelSpace()).
257  /// Note: The transformation is not the same as `posToIndex`
258  /// getIndexSpaceTransform().toVoxelSpace(pos) == posToIndex(pos) + {0.5, 0.5, 0.5}
259  GEO_PrimVolumeXform getIndexSpaceTransform() const;
260 
261  /// Equivalent to getSpaceTransform(getGrid().evalActiveVoxelBoundingBox()).
262  /// The returned space's fromVoxelSpace() method will convert 0-1
263  /// coordinates over the active voxel bounding box to world space (and vice
264  /// versa for toVoxelSpace()).
265  GEO_PrimVolumeXform getSpaceTransform() const;
266 
267  /// Gives the equivalent to GEO_PrimVolume's getSpaceTransform() by using
268  /// the given bounding box to determine the bounds of the transform.
269  /// The resulting world space sample points will be offset by half a voxel
270  /// so that they match GEO_PrimVolume.
271  /// The returned space's fromVoxelSpace() method will convert 0-1
272  /// coordinates over the bbox extents to world space (and vice versa for
273  /// toVoxelSpace()).
274  GEO_PrimVolumeXform getSpaceTransform(const UT_BoundingBoxD &bbox) const;
275 
276  /// Sets the transform from a GEO_PrimVolume's getSpaceTransform() by using
277  /// the index space [(0,0,0), resolution] bbox. If force_taper is true,
278  /// then the resulting transform will always be a NonlinearFrustumMap even
279  /// if there is no tapering.
280  void setSpaceTransform(const GEO_PrimVolumeXform &space,
281  const UT_Vector3R &resolution,
282  bool force_taper = false);
283 
284  /// @}
285 
286  fpreal getTaper() const;
287 
288  /// Returns the resolution of the active voxel array.
289  /// Does *not* mean the indices go from 0..rx, however!
290  void getRes(int &rx, int &ry, int &rz) const;
291  void getRes(int64 &rx, int64 &ry, int64 &rz) const;
292 
293  /// Computes the voxel diameter by taking a step in x, y, and z
294  /// converting to world space and taking the length of that vector.
295  fpreal getVoxelDiameter() const;
296 
297  /// Returns the length of the voxel when you take an x, y, and z step
298  UT_Vector3 getVoxelSize() const;
299 
300  /// Compute useful aggregate properties of the volume.
301  fpreal calcMinimum() const;
302  fpreal calcMaximum() const;
303  fpreal calcAverage() const;
304 
305  /// VDBs may either be unbounded, or created with a specific frustum
306  /// range. The latter is important for tapered VDBs that otherwise
307  /// have a singularity at the camera location. Tools can use the
308  /// presence of an idxbox as a clipping box in index space.
309  /// This does *NOT* relate to getRes - it may be much larger or
310  /// even in some cases smaller.
311  bool getFrustumBounds(UT_BoundingBox &idxbox) const;
312 
314  {
315  ACTIVATE_UNION, // Activate anything in source
316  ACTIVATE_INTERSECT, // Deactivate anything not in source
317  ACTIVATE_SUBTRACT, // Deactivate anything in source
318  ACTIVATE_COPY // Set our activation to match source
319  };
320 
321  /// Densify a VDB. This converts all active tiles into active leaves
322  /// This can greatly increase memory, so it is better that algorithms
323  /// can pre-activate only the leaves they will expand into.
324  void densify();
325 
326  /// Activates voxels given an *index* space bounding box. This
327  /// is an inclusive box.
328  /// If this is Frustum VDB, the activation will be clipped by that.
329  /// Setting the value only takes effect if the voxels are activated,
330  /// deactivated voxels are set to the background.
332  const openvdb::CoordBBox& bbox,
333  ActivateOperation operation,
334  bool setvalue, fpreal value)
335  {
336  activateIndexBBoxAdapter(
337  &bbox, operation, setvalue, value);
338  }
339 
340  /// Activates all of the voxels in this VDB that are touched
341  /// by active voxels in the source.
342  /// If ignore_transform is true, voxels will be activated
343  /// by grid index instead of world space position.
344  void activateByVDB(const GEO_PrimVDB *vdb,
345  ActivateOperation operation,
346  bool setvalue, fpreal value,
347  bool ignore_transform=false);
348 
349  /// @{
350  /// Though not strictly required (i.e. not pure virtual), these methods
351  /// should be implemented for proper behaviour.
352  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
353 
354  // Have we been deactivated and stashed?
355  void stashed(bool beingstashed,
357 
358  /// @}
359 
360  /// @{
361  /// Optional interface methods. Though not required, implementing these
362  /// will give better behaviour for the new primitive.
363  UT_Vector3 baryCenter() const override;
364  fpreal calcVolume(const UT_Vector3 &refpt) const override;
365  /// Calculate the surface area of the active voxels where
366  /// a voxel face contributes if it borders an inactive voxel.
367  fpreal calcArea() const override;
368  /// @}
369 
370  /// @{
371  /// Enlarge a bounding box by the bounding box of the primitive. A
372  /// return value of false indicates an error in the operation, most
373  /// likely an invalid P. For any attribute other than the position
374  /// these methods simply enlarge the bounding box based on the vertex.
375  bool enlargeBoundingBox(
377  const GA_Attribute *P) const override;
378  bool enlargeBoundingBox(
379  UT_BoundingBox &b,
380  const GA_Attribute *P) const override;
381  void enlargePointBounds(UT_BoundingBox &e) const override;
382  /// @}
383  /// Enlarge a bounding sphere to encompass the primitive. A return value
384  /// of false indicates an error in the operation, most likely an invalid
385  /// P. For any attribute other than the position this method simply
386  /// enlarges the sphere based on the vertex.
389  const GA_Attribute *P) const override;
390 
391  /// Accessor for the local 3x3 affine transform matrix for the primitive.
392  /// For frustum maps, this will be transform as if the taper value is set
393  /// to 1.
394  /// @{
395  void getLocalTransform(UT_Matrix3D &result) const override;
396  void setLocalTransform(const UT_Matrix3D &new_mat3) override;
397  /// @}
398 
399  /// @internal Hack to condition 4x4 matrices that we avoid creating what
400  /// OpenVDB erroneously thinks are singular matrices. Returns true if mat4
401  /// was modified.
402  static bool conditionMatrix(UT_Matrix4D &mat4);
403 
404  /// Visualization accessors
405  /// @{
406  const GEO_VolumeOptions &getVisOptions() const { return myVis; }
408  { setVisualization(vis.myMode, vis.myIso, vis.myDensity, vis.myLod); }
409 
411  GEO_VolumeVis vismode,
412  fpreal iso,
413  fpreal density,
415  {
416  myVis.myMode = vismode;
417  myVis.myIso = iso;
418  myVis.myDensity = density;
419  myVis.myLod = lod;
420  }
421  GEO_VolumeVis getVisualization() const { return myVis.myMode; }
422  fpreal getVisIso() const { return myVis.myIso; }
423  fpreal getVisDensity() const { return myVis.myDensity; }
424  GEO_VolumeVisLod getVisLod() const { return myVis.myLod; }
425  GEO_VolumeTypeInfo getTypeInfo() const { return myVis.myTypeInfo; }
426  void setTypeInfo(GEO_VolumeTypeInfo info) { myVis.myTypeInfo = info; }
427  /// @}
428 
429  /// Load the order from a JSON value
430  bool loadOrder(const UT_JSONValue &p);
431 
432  /// @{
433  /// Save/Load vdb to a JSON stream
434  bool saveVDB(UT_JSONWriter &w, const GA_SaveMap &sm,
435  bool as_shmem = false) const;
436  bool loadVDB(UT_JSONParser &p,
437  bool as_shmem = false);
438  /// @}
439 
440  bool saveVisualization(
441  UT_JSONWriter &w,
442  const GA_SaveMap &map) const;
443  bool loadVisualization(
444  UT_JSONParser &p,
445  const GA_LoadMap &map);
446 
447  /// Method to perform quick lookup of vertex without the virtual call
449  {
450  UT_ASSERT_P(index < 1);
451  return getVertexOffset();
452  }
453 
454  void setVertexPoint(int i, GA_Offset pt)
455  {
456  if (i == 0)
457  setPointOffset(pt);
458  }
459 
460  /// @brief Computes the total density of the volume, scaled by
461  /// the volume's size. Negative values will be ignored.
462  fpreal calcPositiveDensity() const;
463 
465  bool hasGrid() const { return myGridAccessor.hasGrid(); }
466 
467  /// @brief If this primitive's grid's voxel data (i.e., its tree)
468  /// is shared, replace the tree with a deep copy of itself that is
469  /// not shared with anyone else.
472  { myGridAccessor.makeGridUnique(); }
473 
474  /// @brief Returns true if the tree is not shared. If it is not shared,
475  /// one can make destructive edits without makeGridUnique.
476  bool isGridUnique() const
477  { return myGridAccessor.isGridUnique(); }
478 
479  /// @brief Return a reference to this primitive's grid.
480  /// @note Calling setGrid() invalidates all references previously returned.
482  const openvdb::GridBase & getConstGrid() const
483  { return myGridAccessor.getConstGrid(*this); }
484  /// @brief Return a reference to this primitive's grid.
485  /// @note Calling setGrid() invalidates all references previously returned.
487  const openvdb::GridBase & getGrid() const
488  { return getConstGrid(); }
489  /// @brief Return a reference to this primitive's grid.
490  /// @note Calling setGrid() invalidates all references previously returned.
491  /// @warning Call makeGridUnique() before modifying the grid's voxel data.
493  openvdb::GridBase & getGrid()
494  {
495  incrGridUniqueIds();
496  return myGridAccessor.getGrid(*this);
497  }
498 
499  /// @brief Return a shared pointer to this primitive's grid.
500  /// @note Calling setGrid() causes the grid to which the shared pointer
501  /// refers to be disassociated with this primitive.
503  openvdb::GridBase::ConstPtr getConstGridPtr() const
504  { return myGridAccessor.getConstGridPtr(*this); }
505  /// @brief Return a shared pointer to this primitive's grid.
506  /// @note Calling setGrid() causes the grid to which the shared pointer
507  /// refers to be disassociated with this primitive.
509  openvdb::GridBase::ConstPtr getGridPtr() const
510  { return getConstGridPtr(); }
511  /// @brief Return a shared pointer to this primitive's grid.
512  /// @note Calling setGrid() causes the grid to which the shared pointer
513  /// refers to be disassociated with this primitive.
514  /// @warning Call makeGridUnique() before modifying the grid's voxel data.
516  openvdb::GridBase::Ptr getGridPtr()
517  {
518  incrGridUniqueIds();
519  return myGridAccessor.getGridPtr(*this);
520  }
521 
522  /// @brief Set this primitive's grid to a shallow copy of the given grid.
523  /// @note Invalidates all previous getGrid() and getConstGrid() references
525  void setGrid(const openvdb::GridBase &grid, bool copyPosition=true)
526  {
527  incrGridUniqueIds();
528  myGridAccessor.setGrid(grid, *this, copyPosition);
529  }
530 
531  /// @brief Return a reference to this primitive's grid metadata.
532  /// @note Calling setGrid() invalidates all references previously returned.
533  const openvdb::MetaMap& getConstMetadata() const
534  { return getConstGrid(); }
535  /// @brief Return a reference to this primitive's grid metadata.
536  /// @note Calling setGrid() invalidates all references previously returned.
537  const openvdb::MetaMap& getMetadata() const
538  { return getConstGrid(); }
539  /// @brief Return a reference to this primitive's grid metadata.
540  /// @note Calling setGrid() invalidates all references previously returned.
542  openvdb::MetaMap& getMetadata()
543  {
544  incrMetadataUniqueId();
545  return myGridAccessor.getGrid(*this);
546  }
547 
548  /// @brief Return the value of this primitive's "name" attribute
549  /// in the given detail.
550  const char * getGridName() const;
551 
552  /// @brief Return this primitive's serial number.
553  /// @details A primitive's serial number never changes.
555  { return static_cast<UniqueId>(myUniqueId.relaxedLoad()); }
556 
557  /// @brief Return the serial number of this primitive's voxel data.
558  /// @details The serial number is incremented whenever a non-const
559  /// reference or pointer to this primitive's grid is requested
560  /// (whether or not the voxel data is ultimately modified).
562  { return static_cast<UniqueId>(myTreeUniqueId.relaxedLoad()); }
563  /// @brief Return the serial number of this primitive's grid metadata.
564  /// @details The serial number is incremented whenever a non-const
565  /// reference to the metadata or non-const access to the grid is requested
566  /// (whether or not the metadata is ultimately modified).
568  { return static_cast<UniqueId>(myMetadataUniqueId.relaxedLoad()); }
569  /// @brief Return the serial number of this primitive's transform.
570  /// @details The serial number is incremented whenever the transform
571  /// is modified or non-const access to this primitive's grid is requested
572  /// (whether or not the transform is ultimately modified).
574  { return static_cast<UniqueId>(myTransformUniqueId.relaxedLoad()); }
575 
576 
577  /// @brief If this primitive's grid resolves to one of the listed grid types,
578  /// invoke the functor @a op on the resolved grid.
579  /// @return @c true if the functor was invoked, @c false otherwise
580  ///
581  /// @par Example:
582  /// @code
583  /// auto printOp = [](const openvdb::GridBase& grid) { grid.print(); };
584  /// const GEO_PrimVDB* prim = ...;
585  /// using RealGridTypes = openvdb::TypeList<openvdb::FloatGrid, openvdb::DoubleGrid>;
586  /// // Print info about the primitive's grid if it is a floating-point grid.
587  /// prim->apply<RealGridTypes>(printOp);
588  /// @endcode
589  template<typename GridTypeListT, typename OpT>
590  bool apply(OpT& op) const
591  { return hasGrid() ? getConstGrid().apply<GridTypeListT>(op) : false; }
592 
593  /// @brief If this primitive's grid resolves to one of the listed grid types,
594  /// invoke the functor @a op on the resolved grid.
595  /// @return @c true if the functor was invoked, @c false otherwise
596  /// @details If @a makeUnique is true, deep copy the grid's tree before
597  /// invoking the functor if the tree is shared with other grids.
598  ///
599  /// @par Example:
600  /// @code
601  /// auto fillOp = [](const auto& grid) { // C++14
602  /// // Convert voxels in the given bounding box into background voxels.
603  /// grid.fill(openvdb::CoordBBox(openvdb::Coord(0), openvdb::Coord(99)),
604  /// grid.background(), /*active=*/false);
605  /// };
606  /// GEO_PrimVDB* prim = ...;
607  /// // Set background voxels in the primitive's grid if it is a floating-point grid.
608  /// using RealGridTypes = openvdb::TypeList<openvdb::FloatGrid, openvdb::DoubleGrid>;
609  /// prim->apply<RealGridTypes>(fillOp);
610  /// @endcode
611  template<typename GridTypeListT, typename OpT>
612  bool apply(OpT& op, bool makeUnique = true)
613  {
614  if (hasGrid()) {
615  auto& grid = myGridAccessor.getGrid(*this);
616  if (makeUnique) {
617  auto treePtr = grid.baseTreePtr();
618  if (treePtr.use_count() > 2) { // grid + treePtr = 2
619  // If the grid resolves to one of the listed types and its tree
620  // is shared with other grids, replace the tree with a deep copy.
621  grid.apply<GridTypeListT>([this](openvdb::GridBase& baseGrid) {
622  baseGrid.setTree(baseGrid.constBaseTree().copy());
623  this->incrTreeUniqueId();
624  });
625  }
626  }
627  if (grid.apply<GridTypeListT>(op)) {
628  incrGridUniqueIds();
629  return true;
630  }
631  }
632  return false;
633  }
634 
635 protected:
637 
638  /// Register intrinsic attributes
639  GA_DECLARE_INTRINSICS(override)
640 
641  /// Return true if the given metadata token is an intrinsic
642  static bool isIntrinsicMetadata(const char *name);
643 
644  /// @warning vertexPoint() doesn't check the bounds. Use with caution.
645  GA_Offset vertexPoint(GA_Size) const
646  { return getPointOffset(); }
647 
648  /// Report approximate memory usage, excluding sizeof(*this),
649  /// because the subclass doesn't have access to myGridAccessor.
650  int64 getBaseMemoryUsage() const;
651 
652  // This is called by the subclasses to count the
653  // memory used by this, excluding sizeof(*this).
654  void countBaseMemory(UT_MemoryCounter &counter) const;
655 
656  /// @brief Return an ID number that is guaranteed to be unique across
657  /// all VDB primitives.
658  static UniqueId nextUniqueId();
659 
661  { myTreeUniqueId.maximum(nextUniqueId()); }
663  { myMetadataUniqueId.maximum(nextUniqueId()); }
665  { myTransformUniqueId.maximum(nextUniqueId()); }
667  {
668  incrTreeUniqueId();
669  incrMetadataUniqueId();
670  incrTransformUniqueId();
671  }
672 
673  /// @brief Replace this primitive's grid with a shallow copy
674  /// of another primitive's grid.
675  void copyGridFrom(const GEO_PrimVDB&, bool copyPosition=true);
676 
677  /// @brief GridAccessor manages access to a GEO_PrimVDB's grid.
678  /// @details In keeping with OpenVDB library conventions, the grid
679  /// is stored internally by shared pointer. However, grid objects
680  /// are never shared among primitives, though their voxel data
681  /// (i.e., their trees) may be shared.
682  /// <p>Among other things, GridAccessor
683  /// - ensures that each primitive's transform and metadata are unique
684  /// (i.e., not shared with anyone else)
685  /// - allows primitives to share voxel data but, via makeGridUnique(),
686  /// provides a way to break the connection
687  /// - ensures that the primitive's transform and the grid's transform
688  /// are in sync (specifically, the translation component, which is
689  /// stored independently as a vertex offset).
691  {
692  public:
694  GridAccessor() : myStorageType(UT_VDB_INVALID)
695  { }
696 
698  void clear()
699  {
700  myGrid.reset();
701  myStorageType = UT_VDB_INVALID;
702  }
703 
705  openvdb::GridBase &
706  getGrid(const GEO_PrimVDB &prim)
707  { updateGridTranslates(prim); return *myGrid; }
708 
710  const openvdb::GridBase &
711  getConstGrid(const GEO_PrimVDB &prim) const
712  { updateGridTranslates(prim); return *myGrid; }
713 
715  openvdb::GridBase::Ptr
716  getGridPtr(const GEO_PrimVDB &prim)
717  { updateGridTranslates(prim); return myGrid; }
718 
720  openvdb::GridBase::ConstPtr
721  getConstGridPtr(const GEO_PrimVDB &prim) const
722  { updateGridTranslates(prim); return myGrid; }
723 
724  // These accessors will ensure the transform's translate is set into
725  // the vertex position.
727  void setGrid(const openvdb::GridBase& grid, GEO_PrimVDB& prim, bool copyPosition=true)
728  { setGridAdapter(&grid, prim, copyPosition); }
731  const openvdb::math::Transform &xform,
732  GEO_PrimVDB &prim)
733  { setTransformAdapter(&xform, prim); }
734 
735  void makeGridUnique();
736  bool isGridUnique() const;
737 
739  UT_VDBType getStorageType() const { return myStorageType; }
740 
742  bool hasGrid() const { return myGrid != 0; }
743 
745  { myStorageType = storage; myGrid.reset(); }
746 
747  private:
748  void updateGridTranslates(const GEO_PrimVDB &prim) const;
749 
751  void setVertexPosition(
752  const openvdb::math::Transform &xform,
753  GEO_PrimVDB &prim)
754  { setVertexPositionAdapter(&xform, prim); }
755 
756  void setGridAdapter(const void* grid, GEO_PrimVDB&, bool copyPosition);
757  void setTransformAdapter(const void* xform, GEO_PrimVDB&);
758  void setVertexPositionAdapter(const void* xform, GEO_PrimVDB&);
759 
760  private:
761  openvdb::GridBase::Ptr myGrid;
762  UT_VDBType myStorageType;
763  };
764 
765 private:
766  void activateIndexBBoxAdapter(
767  const void* bbox,
768  ActivateOperation,
769  bool setvalue, fpreal value);
770 
771 
772  GridAccessor myGridAccessor;
773 
774  GEO_VolumeOptions myVis;
775 
776  // While this is a shared pointer, we never actually share it
777  // Sharing of actual grid data is done at a lower level, so this
778  // the IMX_VDB should be copied by value between primitives.
779  mutable IMX_VDBPtr myCEGrid;
780  mutable bool myCEGridAuthorative;
781 
782  AtomicUniqueId myUniqueId;
783  AtomicUniqueId myTreeUniqueId;
784  AtomicUniqueId myMetadataUniqueId;
785  AtomicUniqueId myTransformUniqueId;
786 
787 }; // class GEO_PrimVDB
788 
789 
790 #if 0 // ndef SESI_OPENVDB
791 namespace openvdb_houdini {
792 using ::GEO_VolumeOptions;
793 using ::GEO_PrimVDB;
794 }
795 #endif
796 
797 
798 ////////////////////////////////////////
799 
800 
801 namespace UT_VDBUtils {
802 
803 // This overload of UT_VDBUtils::callTypedGrid(), for GridBaseType = GEO_PrimVDB,
804 // calls makeGridUnique() on the primitive just before instantiating and
805 // invoking the functor on the primitive's grid. This delays the call
806 // to makeGridUnique() until it is known to be necessary and thus avoids
807 // making deep copies of grids of types that won't be processed.
808 template<typename GridType, typename OpType>
809 inline void
810 callTypedGrid(GEO_PrimVDB& prim, OpType& op)
811 {
812  prim.makeGridUnique();
813  op.template operator()<GridType>(*(UTverify_cast<GridType*>(&prim.getGrid())));
814 }
815 
816 // Overload of callTypedGrid() for GridBaseType = const GEO_PrimVDB
817 template<typename GridType, typename OpType>
818 inline void
819 callTypedGrid(const GEO_PrimVDB& prim, OpType& op)
820 {
821  op.template operator()<GridType>(*(UTverify_cast<const GridType*>(&prim.getConstGrid())));
822 }
823 
824 } // namespace UT_VDBUtils
825 
826 // Define UTvdbProcessTypedGrid*() (see UT_VDBUtils.h) for grids
827 // belonging to primitives, for various subsets of grid types.
830 
831 
832 ////////////////////////////////////////
833 
834 
835 /// @brief Utility function to process the grid of a const primitive using functor @a op.
836 /// @details It will invoke @code op.operator()<GridT>(const GridT &grid) @endcode
837 /// @{
838 template <typename OpT>
839 inline bool GEOvdbProcessTypedGrid(const GEO_PrimVDB &vdb, OpT &op)
840 {
841  return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
842 }
843 
844 template <typename OpT>
845 inline bool GEOvdbProcessTypedGridReal(const GEO_PrimVDB &vdb, OpT &op)
846 {
847  return UTvdbProcessTypedGridReal(vdb.getStorageType(), vdb.getGrid(), op);
848 }
849 
850 template <typename OpT>
851 inline bool GEOvdbProcessTypedGridScalar(const GEO_PrimVDB &vdb, OpT &op)
852 {
853  return UTvdbProcessTypedGridScalar(vdb.getStorageType(), vdb.getGrid(), op);
854 }
855 
856 template <typename OpT>
857 inline bool GEOvdbProcessTypedGridTopology(const GEO_PrimVDB &vdb, OpT &op)
858 {
859  return UTvdbProcessTypedGridTopology(vdb.getStorageType(), vdb.getGrid(), op);
860 }
861 
862 template <typename OpT>
863 inline bool GEOvdbProcessTypedGridVec3(const GEO_PrimVDB &vdb, OpT &op)
864 {
865  return UTvdbProcessTypedGridVec3(vdb.getStorageType(), vdb.getGrid(), op);
866 }
867 
868 template <typename OpT>
869 inline bool GEOvdbProcessTypedGridPoint(const GEO_PrimVDB &vdb, OpT &op)
870 {
871  return UTvdbProcessTypedGridPoint(vdb.getStorageType(), vdb.getGrid(), op);
872 }
873 /// @}
874 
875 /// @brief Utility function to process the grid of a primitive using functor @a op.
876 /// @param vdb the primitive whose grid is to be processed
877 /// @param op a functor with a call operator of the form
878 /// @code op.operator()<GridT>(GridT &grid) @endcode
879 /// @param makeUnique if @c true, call <tt>vdb.makeGridUnique()</tt> before
880 /// invoking the functor
881 /// @{
882 template <typename OpT>
883 inline bool GEOvdbProcessTypedGrid(GEO_PrimVDB &vdb, OpT &op, bool makeUnique = true)
884 {
885  if (makeUnique) return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb, op);
886  return UTvdbProcessTypedGrid(vdb.getStorageType(), vdb.getGrid(), op);
887 }
888 
889 template <typename OpT>
890 inline bool GEOvdbProcessTypedGridReal(GEO_PrimVDB &vdb, OpT &op, bool makeUnique = true)
891 {
892  if (makeUnique) return UTvdbProcessTypedGridReal(vdb.getStorageType(), vdb, op);
893  return UTvdbProcessTypedGridReal(vdb.getStorageType(), vdb.getGrid(), op);
894 }
895 
896 template <typename OpT>
897 inline bool GEOvdbProcessTypedGridScalar(GEO_PrimVDB &vdb, OpT &op, bool makeUnique = true)
898 {
899  if (makeUnique) return UTvdbProcessTypedGridScalar(vdb.getStorageType(), vdb, op);
900  return UTvdbProcessTypedGridScalar(vdb.getStorageType(), vdb.getGrid(), op);
901 }
902 
903 template <typename OpT>
904 inline bool GEOvdbProcessTypedGridTopology(GEO_PrimVDB &vdb, OpT &op, bool makeUnique = true)
905 {
906  if (makeUnique) return UTvdbProcessTypedGridTopology(vdb.getStorageType(), vdb, op);
907  return UTvdbProcessTypedGridTopology(vdb.getStorageType(), vdb.getGrid(), op);
908 }
909 
910 template <typename OpT>
911 inline bool GEOvdbProcessTypedGridVec3(GEO_PrimVDB &vdb, OpT &op, bool makeUnique = true)
912 {
913  if (makeUnique) return UTvdbProcessTypedGridVec3(vdb.getStorageType(), vdb, op);
914  return UTvdbProcessTypedGridVec3(vdb.getStorageType(), vdb.getGrid(), op);
915 }
916 
917 template <typename OpT>
918 inline bool GEOvdbProcessTypedGridPoint(GEO_PrimVDB &vdb, OpT &op, bool makeUnique = true)
919 {
920  if (makeUnique) return UTvdbProcessTypedGridPoint(vdb.getStorageType(), vdb, op);
921  return UTvdbProcessTypedGridPoint(vdb.getStorageType(), vdb.getGrid(), op);
922 }
923 /// @}
924 
925 #endif // __GEO_PrimVDB__
virtual void flushCEWriteCaches()
Copy any modified caches from the GPU back to CPU cache.
Definition: GA_Primitive.h:816
virtual void flushCECaches()
Definition: GA_Primitive.h:820
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GridAccessor manages access to a GEO_PrimVDB's grid.
Definition: GEO_PrimVDB.h:690
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:258
void clearGridAndSetStorageType(UT_VDBType storage)
Definition: GEO_PrimVDB.h:744
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.
Definition: GEO_PrimVDB.h:448
virtual void copyPrimitive(const GEO_Primitive *src)=0
SYS_FORCE_INLINE UT_VDBType getStorageType() const
Get the storage type of the grid.
Definition: GEO_PrimVDB.h:175
bool GEOvdbProcessTypedGridTopology(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
Definition: GEO_PrimVDB.h:857
SYS_FORCE_INLINE void setPos3(const UT_Vector3 &pos)
Definition: GEO_PrimVDB.h:117
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
SYS_FORCE_INLINE openvdb::MetaMap & getMetadata()
Return a reference to this primitive's grid metadata.
Definition: GEO_PrimVDB.h:542
SYS_FORCE_INLINE GridAccessor()
Definition: GEO_PrimVDB.h:694
GridType
List of types that are currently supported by NanoVDB.
Definition: NanoVDB.h:294
virtual UT_Vector3D computeNormalD() const =0
getFileOption("OpenEXR:storage") storage
Definition: HDK_Image.dox:276
SYS_FORCE_INLINE void clear()
Definition: GEO_PrimVDB.h:698
const GLdouble * v
Definition: glcorearb.h:837
SYS_FORCE_INLINE openvdb::GridBase::ConstPtr getConstGridPtr() const
Return a shared pointer to this primitive's grid.
Definition: GEO_PrimVDB.h:503
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:512
GLsizei const GLfloat * value
Definition: glcorearb.h:824
bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *p) const override
SYS_AtomicCounter AtomicUniqueId
Definition: GEO_PrimVDB.h:636
const openvdb::MetaMap & getMetadata() const
Return a reference to this primitive's grid metadata.
Definition: GEO_PrimVDB.h:537
fpreal calcVolume(const UT_Vector3 &) const override
SYS_FORCE_INLINE const openvdb::GridBase & getConstGrid() const
Return a reference to this primitive's grid.
Definition: GEO_PrimVDB.h:482
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
Definition: GA_Primitive.h:264
int64 exint
Definition: SYS_Types.h:125
UniqueId getUniqueId() const
Return this primitive's serial number.
Definition: GEO_PrimVDB.h:554
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
void incrTransformUniqueId()
Definition: GEO_PrimVDB.h:664
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:87
void reverse() override=0
Reverse the order of vertices.
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
GEO_VolumeVis myMode
GLint y
Definition: glcorearb.h:103
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
Abstract base class for a range membership query object.
SYS_FORCE_INLINE TO_T UTverify_cast(FROM_T from)
Definition: UT_Assert.h:229
**But if you need a result
Definition: thread.h:622
UT_VDBType
Definition: UT_VDBUtils.h:25
const GEO_VolumeOptions & getVisOptions() const
Definition: GEO_PrimVDB.h:406
unsigned long long uint64
Definition: SYS_Types.h:117
#define UT_IF_ASSERT_P(ZZ)
Definition: UT_Assert.h:182
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.
Definition: GEO_PrimVDB.h:869
SYS_FORCE_INLINE openvdb::GridBase::ConstPtr getConstGridPtr(const GEO_PrimVDB &prim) const
Definition: GEO_PrimVDB.h:721
UniqueId getMetadataUniqueId() const
Return the serial number of this primitive's grid metadata.
Definition: GEO_PrimVDB.h:567
void incrGridUniqueIds()
Definition: GEO_PrimVDB.h:666
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:236
SYS_FORCE_INLINE int64 getBaseMemoryUsage() const
Report approximate memory usage for myVertexList for subclasses.
Definition: GA_Primitive.h:849
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...
Definition: GEO_PrimVDB.h:590
GA_PrimitiveFamilyMask
void setVisualization(GEO_VolumeVis vismode, fpreal iso, fpreal density, GEO_VolumeVisLod lod=GEO_VOLUMEVISLOD_FULL)
Definition: GEO_PrimVDB.h:410
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:687
SYS_FORCE_INLINE UT_Vector3 getPos3() const
Definition: GEO_PrimVDB.h:114
bool GEOvdbProcessTypedGridReal(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
Definition: GEO_PrimVDB.h:845
bool GEOvdbProcessTypedGridVec3(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
Definition: GEO_PrimVDB.h:863
uint64 UniqueId
Definition: GEO_PrimVDB.h:47
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:646
SYS_FORCE_INLINE bool hasGrid() const
Definition: GEO_PrimVDB.h:742
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
SYS_FORCE_INLINE GA_Offset getPointOffset() const
Definition: GEO_PrimVDB.h:108
#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...
Definition: UT_VDBUtils.h:243
SYS_FORCE_INLINE UT_VDBType getStorageType() const
Definition: GEO_PrimVDB.h:739
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
Definition: GA_Primitive.h:278
GLfloat f
Definition: glcorearb.h:1926
virtual void setLocalTransform(const UT_Matrix3D &matrix)
Set the local transform. The default implementation does nothing.
GLintptr offset
Definition: glcorearb.h:665
SYS_FORCE_INLINE openvdb::GridBase::Ptr getGridPtr()
Return a shared pointer to this primitive's grid.
Definition: GEO_PrimVDB.h:516
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
bool GEOvdbProcessTypedGridScalar(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
Definition: GEO_PrimVDB.h:851
GEO_VolumeVisLod myLod
BBox< Coord > CoordBBox
Definition: NanoVDB.h:2516
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:155
GEO_VolumeTypeInfo
void incrMetadataUniqueId()
Definition: GEO_PrimVDB.h:662
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
virtual const GA_PrimitiveJSON * getJSON() const =0
void setVertexPoint(int i, GA_Offset pt)
Definition: GEO_PrimVDB.h:454
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
Provide a JSON interface to a primitive.
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:872
#define GEO_API
Definition: GEO_API.h:14
void activateIndexBBox(const openvdb::CoordBBox &bbox, ActivateOperation operation, bool setvalue, fpreal value)
Definition: GEO_PrimVDB.h:331
SYS_FORCE_INLINE void setTransform(const openvdb::math::Transform &xform, GEO_PrimVDB &prim)
Definition: GEO_PrimVDB.h:730
GEO_VolumeVis
SYS_FORCE_INLINE int getTupleSize() const
Get the tuple size, usually 1 or 3.
Definition: GEO_PrimVDB.h:179
long long int64
Definition: SYS_Types.h:116
A handle to simplify manipulation of multiple attributes.
UniqueId getTreeUniqueId() const
Return the serial number of this primitive's voxel data.
Definition: GEO_PrimVDB.h:561
SYS_FORCE_INLINE bool hasGrid() const
Definition: GEO_PrimVDB.h:465
Options during loading.
Definition: GA_LoadMap.h:42
HUSD_API const char * resolution()
GLuint const GLchar * name
Definition: glcorearb.h:786
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
SYS_FORCE_INLINE void setGrid(const openvdb::GridBase &grid, GEO_PrimVDB &prim, bool copyPosition=true)
Definition: GEO_PrimVDB.h:727
SYS_FORCE_INLINE openvdb::GridBase & getGrid(const GEO_PrimVDB &prim)
Definition: GEO_PrimVDB.h:706
GLint GLenum GLint x
Definition: glcorearb.h:409
SYS_FORCE_INLINE openvdb::GridBase::Ptr getGridPtr(const GEO_PrimVDB &prim)
Definition: GEO_PrimVDB.h:716
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)
Definition: GEO_PrimVDB.h:240
virtual int64 getDeviceMemoryUsage() const
Definition: GA_Primitive.h:213
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
Definition: GEO_PrimVDB.h:105
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.
Definition: GEO_PrimVDB.h:525
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:290
UniqueId getTransformUniqueId() const
Return the serial number of this primitive's transform.
Definition: GEO_PrimVDB.h:573
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
Definition: GEO_PrimVDB.h:711
virtual void getLocalTransform(UT_Matrix3D &matrix) const
virtual int detachPoints(GA_PointGroup &grp)=0
fpreal getVisDensity() const
Definition: GEO_PrimVDB.h:423
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...
Definition: GEO_PrimVDB.h:471
bool isGridUnique() const
Returns true if the tree is not shared. If it is not shared, one can make destructive edits without m...
Definition: GEO_PrimVDB.h:476
GEO_VolumeTypeInfo getTypeInfo() const
Definition: GEO_PrimVDB.h:425
int UTvdbGetGridTupleSize(UT_VDBType type)
Returns the tuple size of a grid given its value type.
Definition: UT_VDBUtils.h:114
fpreal64 fpreal
Definition: SYS_Types.h:278
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.
Definition: GEO_PrimVDB.h:509
GLuint index
Definition: glcorearb.h:786
FMT_CONSTEXPR basic_fp< F > normalize(basic_fp< F > value)
Definition: format.h:1701
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:244
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:715
virtual void stealCEBuffers(const GA_Primitive *src)
Steal the underlying CE buffer from the source.
Definition: GA_Primitive.h:823
void setVisOptions(const GEO_VolumeOptions &vis)
Definition: GEO_PrimVDB.h:407
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:99
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
Definition: GEO_PrimVDB.h:424
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
static GA_PrimitiveFamilyMask buildFamilyMask()
Definition: GEO_PrimVDB.h:56
void setTypeInfo(GEO_VolumeTypeInfo info)
Definition: GEO_PrimVDB.h:426
void callTypedGrid(GEO_PrimVDB &prim, OpType &op)
Definition: GEO_PrimVDB.h:810
GEO_VolumeVisLod
SYS_FORCE_INLINE const openvdb::GridBase & getGrid() const
Return a reference to this primitive's grid.
Definition: GEO_PrimVDB.h:487
UT_SharedPtr< IMX_VDB > IMX_VDBPtr
Definition: IMX_VDB.h:33
fpreal getVisIso() const
Definition: GEO_PrimVDB.h:422
SYS_FORCE_INLINE void setPointOffset(GA_Offset pt)
Definition: GEO_PrimVDB.h:111
void countBaseMemory(UT_MemoryCounter &counter) const
unsigned int uint
Definition: SYS_Types.h:45
GEO_VolumeVis getVisualization() const
Definition: GEO_PrimVDB.h:421
SYS_FORCE_INLINE openvdb::GridBase & getGrid()
Return a reference to this primitive's grid.
Definition: GEO_PrimVDB.h:493
bool GEOvdbProcessTypedGrid(const GEO_PrimVDB &vdb, OpT &op)
Utility function to process the grid of a const primitive using functor op.
Definition: GEO_PrimVDB.h:839
GLint lod
Definition: glcorearb.h:2765
void incrTreeUniqueId()
Definition: GEO_PrimVDB.h:660
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.
Definition: GEO_PrimVDB.h:199
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...
Definition: GEO_PrimVDB.h:612
const openvdb::MetaMap & getConstMetadata() const
Return a reference to this primitive's grid metadata.
Definition: GEO_PrimVDB.h:533
GLenum src
Definition: glcorearb.h:1793