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