HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_PrimVolume.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_PrimVolume.h ( GEO Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GEO_PrimVolume__
12 #define __GEO_PrimVolume__
13 
14 #include <UT/UT_BoundingRect.h>
15 #include <UT/UT_VoxelArray.h>
16 
17 #include "GEO_API.h"
18 #include "GEO_Primitive.h"
19 #include "GEO_VolumeOptions.h"
20 
21 class UT_JSONWriter;
22 class UT_JSONParser;
23 class GA_SaveMap;
24 class GA_LoadMap;
25 class CE_Grid;
26 
27 ///
28 /// Stores the transform associated with a volume, allowing the
29 /// to/from code to be inlined outside of this library.
30 ///
32 {
33 public:
34  // Converts from world space to [0,1] space.
36  {
37  pos -= myCenter;
38  pos *= myInverseXform;
39 
40  // Undo any taper effect.
41  if (myHasTaper)
42  {
43  fpreal zscale = (1 - pos.z()) * 0.5f;
44  fpreal taperx = 1 + (-1 + myTaperX) * zscale;
45  fpreal tapery = 1 + (-1 + myTaperY) * zscale;
46 
47  if (taperx == 0.0f)
48  pos.x() = 0.0;
49  else
50  pos.x() /= taperx;
51  if (tapery == 0.0f)
52  pos.y() = 0.0;
53  else
54  pos.y() /= tapery;
55  }
56 
57  // This gets us a value in the -1 to 1 box. We need to evaluate
58  // in the 0 to 1 box, however.
59  pos.x() += 1;
60  pos.y() += 1;
61  pos.z() += 1;
62  pos *= 0.5;
63 
64  return pos;
65  }
66 
67  // Converts from [0,1] space over the voxels to world space
69  {
70  // convert to -1 to 1 box.
71  pos.x() -= 0.5;
72  pos.y() -= 0.5;
73  pos.z() -= 0.5;
74  pos *= 2;
75 
76  // Apply the taper effect.
77  if (myHasTaper)
78  {
79  fpreal zscale = (1 - pos.z()) * 0.5f;
80  fpreal taperx = 1 + (-1 + myTaperX) * zscale;
81  fpreal tapery = 1 + (-1 + myTaperY) * zscale;
82 
83  pos.x() *= taperx;
84  pos.y() *= tapery;
85  }
86  // Convert to world space.
87  pos *= myXform;
88  pos += myCenter;
89 
90  return pos;
91  }
92 
93  inline void toVoxelSpace(UT_BoundingBox &box) const
94  {
95  int i;
96  UT_Vector3 v[8] = {
97  UT_Vector3(box.xmin(), box.ymin(), box.zmin()),
98  UT_Vector3(box.xmin(), box.ymin(), box.zmax()),
99  UT_Vector3(box.xmin(), box.ymax(), box.zmin()),
100  UT_Vector3(box.xmin(), box.ymax(), box.zmax()),
101  UT_Vector3(box.xmax(), box.ymin(), box.zmin()),
102  UT_Vector3(box.xmax(), box.ymin(), box.zmax()),
103  UT_Vector3(box.xmax(), box.ymax(), box.zmin()),
104  UT_Vector3(box.xmax(), box.ymax(), box.zmax()),
105  };
106 
107  box.initBounds();
108  for (i = 0; i < 8; i++)
109  {
110  box.enlargeBounds(toVoxelSpace(v[i]));
111  }
112  }
113 
114  inline void fromVoxelSpace(UT_BoundingBox &box) const
115  {
116  int i;
117  UT_Vector3 v[8] = {
118  UT_Vector3(box.xmin(), box.ymin(), box.zmin()),
119  UT_Vector3(box.xmin(), box.ymin(), box.zmax()),
120  UT_Vector3(box.xmin(), box.ymax(), box.zmin()),
121  UT_Vector3(box.xmin(), box.ymax(), box.zmax()),
122  UT_Vector3(box.xmax(), box.ymin(), box.zmin()),
123  UT_Vector3(box.xmax(), box.ymin(), box.zmax()),
124  UT_Vector3(box.xmax(), box.ymax(), box.zmin()),
125  UT_Vector3(box.xmax(), box.ymax(), box.zmax()),
126  };
127 
128  box.initBounds();
129  for (i = 0; i < 8; i++)
130  {
131  box.enlargeBounds(fromVoxelSpace(v[i]));
132  }
133  }
134 
135  /// Returns the *un-tapered* matrix4 corresponding to fromVoxelSpace().
136  /// @{
137  void getTransform4(UT_Matrix4F &matx) const;
138  void getTransform4(UT_Matrix4D &matx) const;
139  /// @}
140 
141  /// Compute the size for this transform (relative to myCenter)
142  UT_Vector3R computeSize() const;
143 
144  // NOTE: This ordering is saved in .hip files!
146  {
147  NON_SQUARE = 0,
152  BY_SIZE
153  };
154 
155  /// Convert the "uniformsamples" parm menu item index to a sampling type
157  { return SamplingType(i); }
158 
159  /// Compute the resolution (and size) from a common set of parameters.
160  /// If twod_axis is one of [0,1,2], then that axis clamped to a divisions
161  /// of 1 and a size of 0. The number of divisions is returned with size
162  /// set to div_size multiplied by divisions before the z_div_scale.
163  static UT_Vector3R computeResolution(
164  SamplingType sampling_type,
165  const UT_Vector3R &non_uniform_divs,
166  fpreal uniform_divs,
167  fpreal div_size,
168  fpreal z_div_scale,
169  UT_Vector3R &size_inout,
170  int twod_axis = -1);
171 
172  /// Compute a space transform from center, size, and taper
173  static GEO_PrimVolumeXform frustumSpaceTransform(
174  const UT_Vector3R &size,
175  const UT_Vector3R &center,
176  fpreal taper_x, fpreal taper_y);
177 
178  /// Compute a space transform from camera settings.
179  /// The ortho_zoom parameter is only used when is_ortho = true.
180  static GEO_PrimVolumeXform cameraFrustum(
181  fpreal focal,
182  fpreal aperture,
183  const UT_Vector2R &image_res,
184  fpreal pixel_aspect,
185  bool is_ortho,
186  fpreal ortho_zoom,
187  fpreal clip_near,
188  fpreal clip_far,
189  bool use_cam_window,
190  const UT_BoundingRectR &cam_window,
191  const UT_BoundingRectR &cam_crop,
192  const UT_BoundingRectR &window,
193  const UT_Matrix4R &post_xform,
194  const GEO_Detail *match_src);
195 
196 public:
197  // @{
198  void save(std::ostream &os, bool binary = false) const;
199  bool load(UT_IStream &is);
200  // @}
201 
202  void init()
203  {
204  myCenter.assign(0, 0, 0);
205  myXform.identity();
206  myInverseXform.identity();
207  myHasTaper = false;
208  myTaperX = 1.0;
209  myTaperY = 1.0;
210  }
211 
212  bool operator==(const GEO_PrimVolumeXform &x) const
213  {
214  return
215  myXform == x.myXform &&
216  myCenter == x.myCenter &&
217  myHasTaper == x.myHasTaper &&
218  myTaperX == x.myTaperX &&
219  myTaperY == x.myTaperY;
220  }
221 
222  UT_Matrix3 myXform, myInverseXform;
225  float myTaperX, myTaperY;
226 };
227 
229 {
230 protected:
231  /// NOTE: The constructor should only be called from subclass
232  /// constructors.
234 
235  /// NOTE: The destructor should only be called from subclass
236  /// destructors.
237  virtual ~GEO_PrimVolume();
238 
239 public:
240 //
241 // Methods common to all primitives.
242  virtual int evaluateNormalVector(UT_Vector3 &nml, float u,
243  float v = 0, float w = 0) const;
244  virtual int getBBox(UT_BoundingBox *bbox) const;
245  virtual void addToBSphere(UT_BoundingSphere *bsphere) const;
246  virtual void enlargePointBounds(UT_BoundingBox &box) const;
247  /// @{
248  /// Enlarge a bounding box by the bounding box of the primitive. A
249  /// return value of false indicates an error in the operation, most
250  /// likely an invalid P. For any attribute other than the position
251  /// these methods simply enlarge the bounding box based on the vertex.
252  virtual bool enlargeBoundingBox(UT_BoundingRect &b,
253  const GA_Attribute *P) const;
254  virtual bool enlargeBoundingBox(UT_BoundingBox &b,
255  const GA_Attribute *P) const;
256  /// @}
257  /// Enlarge a bounding sphere to encompass the primitive. A return value
258  /// of false indicates an error in the operation, most likely an invalid
259  /// P. For any attribute other than the position this method simply
260  /// enlarges the sphere based on the vertex.
262  const GA_Attribute *P) const;
263  /// For a volume the barycenter is the same as the point.
264  virtual UT_Vector3 baryCenter() const;
265  virtual UT_Vector3 computeNormal() const;
266  virtual bool saveH9(std::ostream &os, bool binary,
267  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
268  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs)
269  const;
270  virtual bool loadH9(UT_IStream &is,
271  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
272  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs);
273 
274  bool saveVoxelArray(UT_JSONWriter &w,
275  const GA_SaveMap &map) const;
276  bool loadVoxelArray(UT_JSONParser &p,
277  const GA_LoadMap &map);
278 
279  bool loadRes(const UT_JSONValue &jval);
280  bool saveBorder(UT_JSONWriter &w,
281  const GA_SaveMap &map) const;
282  bool loadBorder(UT_JSONParser &p,
283  const GA_LoadMap &map);
284  bool saveCompression(UT_JSONWriter &w,
285  const GA_SaveMap &map) const;
286  bool loadCompression(UT_JSONParser &p,
287  const GA_LoadMap &map);
288  bool saveVisualization(UT_JSONWriter &w,
289  const GA_SaveMap &map) const;
290  bool loadVisualization(UT_JSONParser &p,
291  const GA_LoadMap &map);
292 
293  /// @{
294  /// Methods to save/load shared voxel data
295  static const int theSharedVoxelMagic=('V'<<24)|('o'<<16)|('x'<<8)|('l');
296  virtual bool registerSharedLoadData(int dtype, GA_SharedDataHandlePtr data);
297  virtual bool saveSharedLoadData(UT_JSONWriter &w,
298  GA_SaveMap &save, GA_GeometryIndex* geometryIndex) const;
299  bool getSharedVoxelKey(UT_WorkBuffer &key) const;
301  allocateSharedDataLoader();
302  /// @}
303 
304  // Transforms the matrix associated with this primitive. The
305  // translate component is ignored: Translate the vertices of
306  // the primitive to translate the primitive.
307  // This only works with quadrics (sphere, tube, metaballs) and volumes.
308  virtual void transform(const UT_Matrix4 &mat);
309 
310  virtual void reverse() {}
311  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
312  virtual void copyPrimitive(const GEO_Primitive *src);
313  virtual void copyUnwiredForMerge(const GA_Primitive *src,
314  const GA_MergeMap &map);
315 #if !GA_PRIMITIVE_VERTEXLIST
316  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
317 
318  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
319  void *data = 0) const;
320 
321  virtual GA_Size getVertexCount() const;
322  virtual GA_Offset getVertexOffset(GA_Size index) const;
323 #endif
324 #if GA_PRIMITIVE_VERTEXLIST
326 #endif
330 
333  {
334  return getVertexOffset(0);
335  }
338  {
339  return getPointOffset(0);
340  }
343  {
344  return getPos3(0);
345  }
347  void setPos3(const UT_Vector3 &pos)
348  {
349  return setPos3(0, pos);
350  }
351 
352  // Take the whole set of points into consideration when applying the
353  // point removal operation to this primitive. The method returns 0 if
354  // successful, -1 if it failed because it would have become degenerate,
355  // and -2 if it failed because it would have had to remove the primitive
356  // altogether.
357  virtual int detachPoints (GA_PointGroup &grp);
358 
359  /// Before a point is deleted, all primitives using the point will be
360  /// notified. The method should return "false" if it's impossible to
361  /// delete the point. Otherwise, the vertices should be removed.
362  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
363  bool dry_run=false);
364  virtual GA_DereferenceStatus dereferencePoints(
365  const GA_RangeMemberQuery &pt_q,
366  bool dry_run=false);
367 
368  virtual bool isDegenerate() const;
369 
370  // Map the normalized length (distance value [0,1]) parameter to the unit
371  // parameterization of the primitve
372  virtual void unitLengthToUnitPair(float ulength, float vlength,
373  float &uparm, float &vparm)const;
374  virtual void unitLengthToUnitPair(float ulength, float vlength,
375  float &uparm, float &vparm, float tolerance)const;
376 
377  virtual void unitToUnitLengthPair(float uparm, float vparm,
378  float &ulength, float &vlength)
379  const;
380 
381  virtual fpreal calcVolume(const UT_Vector3 &refpt) const;
382  virtual fpreal calcArea() const;
383 
384 //
385 // Methods unique to PrimVolume.
386 
387 #if GA_PRIMITIVE_VERTEXLIST
389  void setVertexPoint(GA_Offset pt)
390  {
392  }
393 #else
395  {
396  wireVertex(myVertex, pt);
397  }
398 #endif
399 
400  /// This method assigns a preallocated vertex to the quadric, optionally
401  /// creating the topological link between the primitive and new vertex.
402  void assignVertex(GA_Offset new_vtx, bool update_topology);
403 
404  // Have we been deactivated and stashed?
405  virtual void stashed(bool beingstashed,
407 
408  const UT_Matrix3 &getTransform(void) const { return myXform; }
409  void setTransform(const UT_Matrix3 &m)
410  { myXform = m;
411  myInverseXform = m;
412  myInverseXform.invert();
413  }
414 
415  void getTransform4( UT_Matrix4 &matx) const;
416  void getTransform4( UT_DMatrix4 &matx) const;
417  void setTransform4(const UT_Matrix4 &matx);
418  void setTransform4(const UT_DMatrix4 &matx);
419 
420  virtual void getLocalTransform(UT_Matrix3D &x) const;
421  virtual void setLocalTransform(const UT_Matrix3D &x);
422 
423  /// Converts from world space to local space.
424  const UT_Matrix3 &getInverseTransform() const { return myInverseXform; }
425  void getInverseTransform4(UT_Matrix4 &matx) const;
426 
427  float getTaperX(void) const { return myTaperX; }
428  void setTaperX(float t) { myTaperX = t; }
429  float getTaperY(void) const { return myTaperY; }
430  void setTaperY(float t) { myTaperY = t; }
431 
432  /// True if the two volumes have same resolution and map the
433  /// same indices to the same positions.
434  bool isAligned(const GEO_PrimVolume *vol) const;
435 
436  /// True if we are aligned with the world axes. Ie, all our
437  /// off diagonals are zero and our diagonal is positive.
438  bool isWorldAxisAligned() const;
439 
440  /// Returns the POD class which can convert to and from
441  /// 0..1 voxel space coordinates.
442  GEO_PrimVolumeXform getSpaceTransform() const;
443  void setSpaceTransform(GEO_PrimVolumeXform xform);
444 
445  /// Returns the POD class which can convert to and from
446  /// voxel index space coordinates.
447  GEO_PrimVolumeXform getIndexSpaceTransform() const;
448  GEO_PrimVolumeXform getIndexSpaceTransform(const UT_VoxelArrayF &vox) const;
449 
450  /// Converts from world space to 0..1 voxel space.
451  UT_Vector3 toVoxelSpace(const UT_Vector3 &pos) const;
452  /// Converts from 0..1 voxel space to world space.
453  UT_Vector3 fromVoxelSpace(const UT_Vector3 &pos) const;
454 
455  /// Converts from world space to 0..1 voxel space.
456  void toVoxelSpace(UT_BoundingBox &box) const;
457  /// Converts from 0..1 voxel space to world space.
458  void fromVoxelSpace(UT_BoundingBox &box) const;
459 
460  /// Copies the given voxel array and makes it our own voxel array.
461  void setVoxels(const UT_VoxelArrayF *vox);
462  void setVoxels(UT_VoxelArrayHandleF handle);
463 
464  /// Takes ownership of the voxel array, caller should not refer
465  /// to vox any more.
466  void stealVoxels(UT_VoxelArrayF *vox);
467 
468  /// Returns a handle to a voxel array containing our data.
469  /// This is should be thought of a copy of the data - changing
470  /// it will not change the underlying data, casting this to
471  /// a write handle will write to the newly created handle, not
472  /// the one stored in this volume.
473  UT_VoxelArrayHandleF getVoxelHandle() const;
474 
475  /// Returns a voxel handle without trying to load the shared data
476  /// This should only be used for the loader
477  /// DO NOT USE! IF YOU THINK YOU SHOULD YOUR PROBABLY WRONG
479  {
480  return myVoxelHandle;
481  }
482 
483  /// This is a handle that you can write to and affect the volume.
484  UT_VoxelArrayWriteHandleF getVoxelWriteHandle();
485 
486  /// Convert an index in the voxel array into the corresponding worldspace
487  /// location
488  bool indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
489  void findexToPos(UT_Vector3 index, UT_Vector3 &pos) const;
490 
491  /// Returns true if the given point is entirely inside the volume's
492  /// definition, ie, if posToIndex would return true.
493  bool isInside(UT_Vector3 pos) const;
494 
495  /// Returns true only if strictly inside. This means only actual
496  /// voxel samples will be used for interpolation, so the boundary
497  /// conditions will be unused
498  bool isInsideStrict(UT_Vector3 pos) const;
499  /// By passing in a specific read handle, we can accelerate
500  /// isInsideStrict()
501  bool isInsideStrict(const UT_Vector3 &opos, const UT_VoxelArrayReadHandleF &vox) const;
502 
503  /// Convert a 3d position into the closest index value. Returns
504  /// false if the resulting index was out of range (but still sets it)
505  bool posToIndex(UT_Vector3 pos, int &x, int &y, int &z) const;
506  bool posToIndex(UT_Vector3 pos, UT_Vector3 &index) const;
507 
508  /// Evaluate the voxel value at the given world space position.
509  fpreal getValue(const UT_Vector3 &pos) const;
510  void getValues(float *f, int stride, const UT_Vector3 *p, int num) const;
511  // Only works with scalar grids.
512  UT_Vector3 getGradient(const UT_Vector3 &pos) const;
513  UT_Vector3 getGradient(const UT_Vector3 &pos, const UT_VoxelArrayReadHandleF &handle) const;
514 
515  /// By passing in a specific read handle and inverse transform
516  /// we can accelerate the getValue()
517  fpreal getValue(const UT_Vector3 &pos, const UT_VoxelArrayReadHandleF &handle) const;
518 
519  /// Evaluate the specific voxel indexed from 0,0,0.
520  fpreal getValueAtIndex(int ix, int iy, int iz) const;
521  void getValuesAtIndices(float *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
522  void getValuesAtIndices(int *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
523  /// Returns the resolution of the voxel array.
524  void getRes(int &rx, int &ry, int &rz) const;
525  /// Computes the voxel diameter by taking a step in x, y, and z
526  /// converting to world space and taking the length of that vector.
527  fpreal getVoxelDiameter() const;
528 
529  /// Returns the length of the voxel when you take an x, y, and z step
530  UT_Vector3 getVoxelSize() const;
531 
532  /// Computes the total density of the volume, scaled by
533  /// the volume's size. Negative values will be ignored.
534  fpreal calcPositiveDensity() const;
535 
536  /// Compute useful aggregate properties of the volume.
537  fpreal calcMinimum() const;
538  fpreal calcMaximum() const;
539  fpreal calcAverage() const;
540 
541  /// Determines if we should be treated as an SDF. This means
542  /// our function will continue to increase outside of the bounding
543  /// box according to the distance to the bounding box.
544  bool isSDF() const { return myIsSDF; }
545 
546  /// Determine our orientation if we are to be considered a heightfield.
547  /// Returns false if we shouldn't be treated as a heightfield.
548  bool computeHeightFieldProperties(int &a1, int &a2, int &axis, fpreal &scale) const;
549  bool computeHeightFieldProperties(int &a1, int &a2, int &axis, fpreal &scale, const UT_VoxelArrayF &vox, const GEO_PrimVolumeXform &indexxform) const;
550 
551  /// Get the border options in terms of GEO's values.
552  static const char *getBorderToken(GEO_VolumeBorder border);
553  static GEO_VolumeBorder getBorderEnum(const char *token,
555  void setBorder(GEO_VolumeBorder border, fpreal val);
556  GEO_VolumeBorder getBorder() const;
557  fpreal getBorderValue() const;
558 
559  /// Control the compression of these objects.
560  fpreal getCompressionTolerance() const;
561  void setCompressionTolerance(fpreal tol);
562  void recompress();
563 
564  /// Control how we display this in the viewport
565  static const char *getVisualizationToken(GEO_VolumeVis vis);
566  static GEO_VolumeVis getVisualizationEnum(const char *vis,
568  const GEO_VolumeOptions &getVisOptions() const { return myVis; }
569  void setVisualization(GEO_VolumeVis vis, fpreal iso, fpreal density);
570  fpreal getVisIso() const { return myVis.myIso; }
571  fpreal getVisDensity() const { return myVis.myDensity; }
572  GEO_VolumeVis getVisualization() const { return myVis.myMode; }
573 
574  virtual const GA_PrimitiveJSON *getJSON() const;
575 
576  /// Voxel traverser. This serializes the voxels into a linear array of
577  /// scalar data.
578  class serialize
579  {
580  public:
582  : myVoxels()
583  , myBorder(0)
584  , myXres(0)
585  , myYres(0)
586  , myZres(0)
587  , myEntries(0)
588  , myCurr(0)
589  {}
591  : myVoxels(src.myVoxels)
592  , myBorder(src.myBorder)
593  , myXres(src.myXres)
594  , myYres(src.myYres)
595  , myZres(src.myZres)
596  , myEntries(src.myEntries)
597  , myCurr(src.myCurr)
598  {}
600  {
601  myVoxels = src.myVoxels;
602  myBorder = src.myBorder;
603  myXres = src.myXres;
604  myYres = src.myYres;
605  myZres = src.myZres;
606  myEntries = src.myEntries;
607  myCurr = src.myCurr;
608  return *this;
609  }
610  /// Random access of a voxel value
612  {
613  if (index >= 0 && index < myEntries)
614  {
615  exint x, y, z;
616  x = index % myXres;
617  index = (index - x) / myXres;
618  y = index % myYres;
619  index = (index - y) / myYres;
620  z = index % myZres;
621  return (*myVoxels)(x, y, z);
622  }
623  return myBorder;
624  }
625 
626  /// @{
627  /// Iterator interface
628  bool atEnd() const { return myCurr >= myEntries; }
629  void rewind() { myCurr = 0; }
630  void advance() { myCurr++; }
631  serialize &operator++() { advance(); return *this; }
632  /// No post increment as it is harmful.
633  /// @}
634  /// Iterator access methods
635  exint entries() const { return myEntries; }
636  exint index() const { return myCurr; }
637  fpreal voxel() const { return getVoxel(myCurr); }
638  private:
639  serialize(const GEO_PrimVolume &prim)
640  : myVoxels(prim.getVoxelHandle())
641  , myCurr(0)
642  {
643  prim.getRes(myXres, myYres, myZres);
644  myBorder = prim.getBorderValue();
645  myEntries = myXres*myYres*myZres;
646  }
647  UT_VoxelArrayReadHandleF myVoxels;
648  fpreal myBorder;
649  exint myCurr, myEntries;
650  int myXres, myYres, myZres;
651  friend class GEO_PrimVolume;
652  };
653  serialize getSerialize() const { return serialize(*this); }
654 
655 
656  /// Acquire a CE grid and cache it on the GPU. If marked for
657  /// writing, the CPU version will be overwritten.
658  /// Note that the getVoxelHandle does *NOT* auto-flush these!
659  /// NOTE: If someone else fetches a non-read grid, and you fetch it
660  /// as a read grid, you will not get any copied data.
661  CE_Grid *getCEGrid(bool read, bool write);
662 
663  /// Any modified CE cache on the GPU will be copied back to the
664  /// CPU. Will leave result on GPU.
665  virtual void flushCEWriteCaches();
666 
667  /// Remove all CE caches from the GPU, possibly writing back
668  /// if necessary.
669  virtual void flushCECaches();
670 
671 protected:
673  { return GA_FAMILY_NONE; }
674 
675 #if !GA_PRIMITIVE_VERTEXLIST
676  virtual void clearForDeletion();
677 #endif
678 
679 #if !GA_PRIMITIVE_VERTEXLIST
680  /// Defragmentation
681  virtual void swapVertexOffsets(const GA_Defragment &defrag);
682 #endif
683 
685 
686  virtual bool savePrivateH9(std::ostream &os, bool binary) const;
687  virtual bool loadPrivateH9(UT_IStream &is);
688 
689  // A versioned loading method.
690  bool loadVoxelDataH9(UT_IStream &is,
692  int version);
693 
695  { return getPointOffset(); }
696 
697  /// Gets the handle to our voxels
699 
700  // All accesses of myVoxelHandle should go though getMyVoxelHandle
701  // so that the voxels are loaded from shared data before access
706 
707  mutable CE_Grid *myCEGrid;
708  mutable bool myCEGridAuthorative;
709 
710  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
711  GA_AttributeRefMap &hlist,
712  fpreal u, fpreal v, uint du, uint dv) const;
713  virtual int evaluatePointV4( UT_Vector4 &pos, float u, float v = 0,
714  unsigned du=0, unsigned dv=0) const
715  {
716  return GEO_Primitive::evaluatePointV4(pos, u, v,
717  du, dv);
718  }
719  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
720  GA_AttributeRefMap &hlist) const;
721 
722  virtual bool evaluateInteriorPointRefMap(GA_Offset result_vtx,
723  GA_AttributeRefMap &map,
724  fpreal u, fpreal v, fpreal w = 0) const;
725  virtual int evaluateInteriorPointV4(UT_Vector4 &pos,
726  fpreal u, fpreal v, fpreal w = 0) const;
727 
728 private:
729 #if !GA_PRIMITIVE_VERTEXLIST
730  GA_Offset myVertex; // My vertex
731 #endif
732  UT_Matrix3 myXform; // My Transform
733  UT_Matrix3 myInverseXform; // My inverse transform
734  bool myIsSDF : 1; // Are we a signed distance field?
735 
736  GEO_VolumeOptions myVis;
737 
738  // The taper is the radius of the bottom half, z-minus, of the default box
739  // The top half's radius is one. These radii are then modified by
740  // myXform.
741  fpreal myTaperX, myTaperY;
742 
743  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimVolume &d)
744  {
745  d.saveH9(os, 0,
748  return os;
749  }
751 };
753 
754 #endif
void fromVoxelSpace(UT_BoundingBox &box) const
virtual void flushCEWriteCaches()
Copy any modified caches from the GPU back to CPU cache.
Definition: GA_Primitive.h:720
void setTaperX(float t)
virtual void flushCECaches()
Definition: GA_Primitive.h:724
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
serialize getSerialize() const
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
GEO_VolumeVis getVisualization() const
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:246
virtual UT_Vector3 baryCenter() const
virtual void copyPrimitive(const GEO_Primitive *src)=0
virtual void clearForDeletion()
Definition: GA_Primitive.h:595
UT_VoxelArrayHandleF myVoxelHandle
Used to pass options and map offset values during saving.
Definition: GA_SaveMap.h:48
bool loadVoxelDataH9(UT_IStream &is, UT_VoxelArrayWriteHandleF voxels, int version)
SYS_FORCE_INLINE GA_Size getVertexCount() const
Return the number of vertices used by this primitive.
Definition: GA_Primitive.h:224
#define SYS_DEPRECATED_PUSH_DISABLE()
const GLdouble * v
Definition: glcorearb.h:836
virtual void reverse()
Reverse the order of vertices.
#define SYS_DEPRECATED_POP_DISABLE()
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
UT_Vector3T< float > UT_Vector3
float getTaperY(void) const
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
SYS_FORCE_INLINE UT_Vector3 getPos3() const
serialize & operator=(const serialize &src)
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
fpreal getVisDensity() const
const GEO_VolumeOptions & getVisOptions() const
static GA_PrimitiveFamilyMask buildFamilyMask()
virtual bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const
GA_Offset vertexPoint() const
GA_SharedDataHandlePtr mySharedVoxelData
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
JSON reader class which handles parsing of JSON or bJSON files.
Definition: UT_JSONParser.h:75
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
GLint y
Definition: glcorearb.h:102
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:32
Abstract base class for a range membership query object.
virtual bool savePrivateH9(std::ostream &os, bool binary) const
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:498
2D Vector class.
Definition: UT_Vector2.h:138
UT_SharedPtr< GA_SharedDataHandle > GA_SharedDataHandlePtr
void read(T &in, bool &v)
Definition: ImfXdr.h:611
png_uint_32 i
Definition: png.h:2877
virtual void swapVertexOffsets(const GA_Defragment &defrag)
UT_Vector3 fromVoxelSpace(UT_Vector3 pos) const
virtual void unitToUnitLengthPair(float uparm, float vparm, float &ulength, float &vlength) const
void wireVertex(GA_Offset vertex, GA_Offset point)
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:211
virtual bool loadH9(UT_IStream &is, const UT_Array< GA_AttribLoadDataH9 > &prim_attribs, const UT_Array< GA_AttribLoadDataH9 > &vtx_attribs)
GA_PrimitiveFamilyMask
GLsizeiptr size
Definition: glcorearb.h:663
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
virtual bool saveSharedLoadData(UT_JSONWriter &w, GA_SaveMap &save, GA_GeometryIndex *geometryIndex) const
#define GA_INVALID_OFFSET
Definition: GA_Types.h:654
friend std::ostream & operator<<(std::ostream &os, const GEO_PrimVolume &d)
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:617
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:502
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
GA_API const UT_StringHolder scale
int invert()
Invert this matrix and return 0 if OK, 1 if singular.
UT_Vector3 toVoxelSpace(UT_Vector3 pos) const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
Definition: GA_Primitive.h:266
GLfloat f
Definition: glcorearb.h:1925
virtual void setLocalTransform(const UT_Matrix3D &matrix)
Set the local transform. The default implementation does nothing.
GEO_VolumeBorder
virtual int evaluateInteriorPointV4(UT_Vector4 &pos, fpreal u, fpreal v, fpreal w=0) const
UT_VoxelArrayHandleF & getMyVoxelHandle() const
Gets the handle to our voxels.
void setTransform(const UT_Matrix3 &m)
virtual fpreal calcArea() const
int64 exint
Definition: SYS_Types.h:116
GLint GLenum GLboolean GLsizei stride
Definition: glcorearb.h:871
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
const UT_Matrix3 & getInverseTransform() const
Converts from world space to local space.
virtual int evaluatePointV4(UT_Vector4 &pos, float u, float v=0, unsigned du=0, unsigned dv=0) const
virtual const GA_PrimitiveJSON * getJSON() const =0
fpreal getVoxel(exint index) const
Random access of a voxel value.
GLintptr offset
Definition: glcorearb.h:664
Provide a JSON interface to a primitive.
fpreal getVisIso() const
#define GEO_API
Definition: GEO_API.h:10
GEO_VolumeVis
const UT_Matrix3 & getTransform(void) const
fpreal getBorderValue() const
A handle to simplify manipulation of multiple attributes.
Options during loading.
Definition: GA_LoadMap.h:42
virtual int getBBox(UT_BoundingBox *bbox) const =0
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
void addPointRefToGroup(GA_PointGroup &grp) const
GLboolean * data
Definition: glcorearb.h:130
void toVoxelSpace(UT_BoundingBox &box) const
UT_Lock mySharedDataLock
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
void enlargeBounds(const UT_Vector3T< T > &min, const UT_Vector3T< T > &max)
SYS_FORCE_INLINE void setPos3(const UT_Vector3 &pos)
bool mySharedDataHandleLoaded
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
static SamplingType samplingType(int i)
Convert the "uniformsamples" parm menu item index to a sampling type.
unsigned int uint
Definition: SYS_Types.h:40
bool isSDF() const
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:272
serialize(const serialize &src)
virtual void unitLengthToUnitPair(float ulength, float vlength, float &uparm, float &vparm) const
GT_API const UT_StringHolder version
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
virtual bool evaluateInteriorPointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v, fpreal w=0) const
virtual void transform(const UT_Matrix4 &)
virtual void enlargePointBounds(UT_BoundingBox &box) const
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) const
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:500
virtual void getLocalTransform(UT_Matrix3D &matrix) const
double fpreal
Definition: SYS_Types.h:270
virtual bool loadPrivateH9(UT_IStream &is)
void setVertexPoint(GA_Offset pt)
virtual int detachPoints(GA_PointGroup &grp)=0
GLint GLint GLsizei GLint border
Definition: glcorearb.h:107
float getTaperX(void) const
void setTaperY(float t)
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
GLuint index
Definition: glcorearb.h:785
bool operator==(const GEO_PrimVolumeXform &x) const
GLint GLenum GLint x
Definition: glcorearb.h:408
GLuint GLfloat * val
Definition: glcorearb.h:1607
SYS_FORCE_INLINE void initBounds()
virtual fpreal calcVolume(const UT_Vector3 &) const
virtual int evaluateNormalVector(UT_Vector3 &nml, float u, float v=0, float w=0) const
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:232
Class to store JSON objects as C++ objects.
Definition: UT_JSONValue.h:75
virtual bool evaluatePointRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map, fpreal u, fpreal v=0, uint du=0, uint dv=0) const =0
virtual void addToBSphere(UT_BoundingSphere *bsphere) const
SYS_FORCE_INLINE GA_Offset getPointOffset() const
CE_Grid * myCEGrid
png_infop png_uint_32 int num
Definition: png.h:2158
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
#define const
Definition: zconf.h:214
void write(T &out, bool v)
Definition: ImfXdr.h:332
virtual bool registerSharedLoadData(int load_data_type, GA_SharedDataHandlePtr item)
CE_Grid * getCEGrid(bool read, bool write)
void getRes(int &rx, int &ry, int &rz) const
Returns the resolution of the voxel array.
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)
UT_VoxelArrayHandleF getHandleToVoxelsWithoutLoading() const
GLenum src
Definition: glcorearb.h:1792