HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 
375  virtual void unitToUnitLengthPair(float uparm, float vparm,
376  float &ulength, float &vlength)
377  const;
378 
379  virtual fpreal calcVolume(const UT_Vector3 &refpt) const;
380  virtual fpreal calcArea() const;
381 
382 //
383 // Methods unique to PrimVolume.
384 
385 #if GA_PRIMITIVE_VERTEXLIST
387  void setVertexPoint(GA_Offset pt)
388  {
390  }
391 #else
393  {
394  wireVertex(myVertex, pt);
395  }
396 #endif
397 
398  /// This method assigns a preallocated vertex to the quadric, optionally
399  /// creating the topological link between the primitive and new vertex.
400  void assignVertex(GA_Offset new_vtx, bool update_topology);
401 
402  // Have we been deactivated and stashed?
403  virtual void stashed(bool beingstashed,
405 
406  const UT_Matrix3 &getTransform(void) const { return myXform; }
407  void setTransform(const UT_Matrix3 &m)
408  { myXform = m;
409  myInverseXform = m;
410  myInverseXform.invert();
411  }
412 
413  void getTransform4( UT_Matrix4 &matx) const;
414  void getTransform4( UT_DMatrix4 &matx) const;
415  void setTransform4(const UT_Matrix4 &matx);
416  void setTransform4(const UT_DMatrix4 &matx);
417 
418  virtual void getLocalTransform(UT_Matrix3D &x) const;
419  virtual void setLocalTransform(const UT_Matrix3D &x);
420 
421  /// Converts from world space to local space.
422  const UT_Matrix3 &getInverseTransform() const { return myInverseXform; }
423  void getInverseTransform4(UT_Matrix4 &matx) const;
424 
425  float getTaperX(void) const { return myTaperX; }
426  void setTaperX(float t) { myTaperX = t; }
427  float getTaperY(void) const { return myTaperY; }
428  void setTaperY(float t) { myTaperY = t; }
429 
430  /// True if the two volumes have same resolution and map the
431  /// same indices to the same positions.
432  bool isAligned(const GEO_PrimVolume *vol) const;
433 
434  /// True if we are aligned with the world axes. Ie, all our
435  /// off diagonals are zero and our diagonal is positive.
436  bool isWorldAxisAligned() const;
437 
438  /// Returns the POD class which can convert to and from
439  /// 0..1 voxel space coordinates.
440  GEO_PrimVolumeXform getSpaceTransform() const;
441  void setSpaceTransform(GEO_PrimVolumeXform xform);
442 
443  /// Returns the POD class which can convert to and from
444  /// voxel index space coordinates.
445  GEO_PrimVolumeXform getIndexSpaceTransform() const;
446  GEO_PrimVolumeXform getIndexSpaceTransform(const UT_VoxelArrayF &vox) const;
447 
448  /// Converts from world space to 0..1 voxel space.
449  UT_Vector3 toVoxelSpace(const UT_Vector3 &pos) const;
450  /// Converts from 0..1 voxel space to world space.
451  UT_Vector3 fromVoxelSpace(const UT_Vector3 &pos) const;
452 
453  /// Converts from world space to 0..1 voxel space.
454  void toVoxelSpace(UT_BoundingBox &box) const;
455  /// Converts from 0..1 voxel space to world space.
456  void fromVoxelSpace(UT_BoundingBox &box) const;
457 
458  /// Copies the given voxel array and makes it our own voxel array.
459  void setVoxels(const UT_VoxelArrayF *vox);
460  void setVoxels(UT_VoxelArrayHandleF handle);
461 
462  /// Takes ownership of the voxel array, caller should not refer
463  /// to vox any more.
464  void stealVoxels(UT_VoxelArrayF *vox);
465 
466  /// Returns a handle to a voxel array containing our data.
467  /// This is should be thought of a copy of the data - changing
468  /// it will not change the underlying data, casting this to
469  /// a write handle will write to the newly created handle, not
470  /// the one stored in this volume.
471  UT_VoxelArrayHandleF getVoxelHandle() const;
472 
473  /// Returns a voxel handle without trying to load the shared data
474  /// This should only be used for the loader
475  /// DO NOT USE! IF YOU THINK YOU SHOULD YOUR PROBABLY WRONG
477  {
478  return myVoxelHandle;
479  }
480 
481  /// This is a handle that you can write to and affect the volume.
482  UT_VoxelArrayWriteHandleF getVoxelWriteHandle();
483 
484  /// Convert an index in the voxel array into the corresponding worldspace
485  /// location
486  bool indexToPos(int x, int y, int z, UT_Vector3 &pos) const;
487  void findexToPos(UT_Vector3 index, UT_Vector3 &pos) const;
488 
489  /// Returns true if the given point is entirely inside the volume's
490  /// definition, ie, if posToIndex would return true.
491  bool isInside(UT_Vector3 pos) const;
492 
493  /// Returns true only if strictly inside. This means only actual
494  /// voxel samples will be used for interpolation, so the boundary
495  /// conditions will be unused
496  bool isInsideStrict(UT_Vector3 pos) const;
497 
498  /// Convert a 3d position into the closest index value. Returns
499  /// false if the resulting index was out of range (but still sets it)
500  bool posToIndex(UT_Vector3 pos, int &x, int &y, int &z) const;
501  bool posToIndex(UT_Vector3 pos, UT_Vector3 &index) const;
502 
503  /// Evaluate the voxel value at the given world space position.
504  fpreal getValue(const UT_Vector3 &pos) const;
505  void getValues(float *f, int stride, const UT_Vector3 *p, int num) const;
506  // Only works with scalar grids.
507  UT_Vector3 getGradient(const UT_Vector3 &pos) const;
508  UT_Vector3 getGradient(const UT_Vector3 &pos, const UT_VoxelArrayReadHandleF &handle) const;
509 
510  /// By passing in a specific read handle and inverse transform
511  /// we can accelerate the getValue()
512  fpreal getValue(const UT_Vector3 &pos, const UT_VoxelArrayReadHandleF &handle) const;
513 
514  /// Evaluate the specific voxel indexed from 0,0,0.
515  fpreal getValueAtIndex(int ix, int iy, int iz) const;
516  void getValuesAtIndices(float *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
517  void getValuesAtIndices(int *f, int stride, const int *ix, const int *iy, const int *iz, int num) const;
518  /// Returns the resolution of the voxel array.
519  void getRes(int &rx, int &ry, int &rz) const;
520  /// Computes the voxel diameter by taking a step in x, y, and z
521  /// converting to world space and taking the length of that vector.
522  fpreal getVoxelDiameter() const;
523 
524  /// Returns the length of the voxel when you take an x, y, and z step
525  UT_Vector3 getVoxelSize() const;
526 
527  /// Computes the total density of the volume, scaled by
528  /// the volume's size. Negative values will be ignored.
529  fpreal calcPositiveDensity() const;
530 
531  /// Compute useful aggregate properties of the volume.
532  fpreal calcMinimum() const;
533  fpreal calcMaximum() const;
534  fpreal calcAverage() const;
535 
536  /// Determines if we should be treated as an SDF. This means
537  /// our function will continue to increase outside of the bounding
538  /// box according to the distance to the bounding box.
539  bool isSDF() const { return myIsSDF; }
540 
541  /// Determine our orientation if we are to be considered a heightfield.
542  /// Returns false if we shouldn't be treated as a heightfield.
543  bool computeHeightFieldProperties(int &a1, int &a2, int &axis, fpreal &scale) const;
544  bool computeHeightFieldProperties(int &a1, int &a2, int &axis, fpreal &scale, const UT_VoxelArrayF &vox, const GEO_PrimVolumeXform &indexxform) const;
545 
546  /// Get the border options in terms of GEO's values.
547  static const char *getBorderToken(GEO_VolumeBorder border);
548  static GEO_VolumeBorder getBorderEnum(const char *token,
550  void setBorder(GEO_VolumeBorder border, fpreal val);
551  GEO_VolumeBorder getBorder() const;
552  fpreal getBorderValue() const;
553 
554  /// Control the compression of these objects.
555  fpreal getCompressionTolerance() const;
556  void setCompressionTolerance(fpreal tol);
557  void recompress();
558 
559  /// Control how we display this in the viewport
560  static const char *getVisualizationToken(GEO_VolumeVis vis);
561  static GEO_VolumeVis getVisualizationEnum(const char *vis,
563  const GEO_VolumeOptions &getVisOptions() const { return myVis; }
564  void setVisualization(GEO_VolumeVis vis, fpreal iso, fpreal density);
565  fpreal getVisIso() const { return myVis.myIso; }
566  fpreal getVisDensity() const { return myVis.myDensity; }
567  GEO_VolumeVis getVisualization() const { return myVis.myMode; }
568 
569  virtual const GA_PrimitiveJSON *getJSON() const;
570 
571  /// Voxel traverser. This serializes the voxels into a linear array of
572  /// scalar data.
573  class serialize
574  {
575  public:
577  : myVoxels()
578  , myBorder(0)
579  , myXres(0)
580  , myYres(0)
581  , myZres(0)
582  , myEntries(0)
583  , myCurr(0)
584  {}
586  : myVoxels(src.myVoxels)
587  , myBorder(src.myBorder)
588  , myXres(src.myXres)
589  , myYres(src.myYres)
590  , myZres(src.myZres)
591  , myEntries(src.myEntries)
592  , myCurr(src.myCurr)
593  {}
595  {
596  myVoxels = src.myVoxels;
597  myBorder = src.myBorder;
598  myXres = src.myXres;
599  myYres = src.myYres;
600  myZres = src.myZres;
601  myEntries = src.myEntries;
602  myCurr = src.myCurr;
603  return *this;
604  }
605  /// Random access of a voxel value
607  {
608  if (index >= 0 && index < myEntries)
609  {
610  exint x, y, z;
611  x = index % myXres;
612  index = (index - x) / myXres;
613  y = index % myYres;
614  index = (index - y) / myYres;
615  z = index % myZres;
616  return (*myVoxels)(x, y, z);
617  }
618  return myBorder;
619  }
620 
621  /// @{
622  /// Iterator interface
623  bool atEnd() const { return myCurr >= myEntries; }
624  void rewind() { myCurr = 0; }
625  void advance() { myCurr++; }
626  serialize &operator++() { advance(); return *this; }
627  /// No post increment as it is harmful.
628  /// @}
629  /// Iterator access methods
630  exint entries() const { return myEntries; }
631  exint index() const { return myCurr; }
632  fpreal voxel() const { return getVoxel(myCurr); }
633  private:
634  serialize(const GEO_PrimVolume &prim)
635  : myVoxels(prim.getVoxelHandle())
636  , myCurr(0)
637  {
638  prim.getRes(myXres, myYres, myZres);
639  myBorder = prim.getBorderValue();
640  myEntries = myXres*myYres*myZres;
641  }
642  UT_VoxelArrayReadHandleF myVoxels;
643  fpreal myBorder;
644  exint myCurr, myEntries;
645  int myXres, myYres, myZres;
646  friend class GEO_PrimVolume;
647  };
648  serialize getSerialize() const { return serialize(*this); }
649 
650 
651  /// Acquire a CE grid and cache it on the GPU. If marked for
652  /// writing, the CPU version will be overwritten.
653  /// Note that the getVoxelHandle does *NOT* auto-flush these!
654  /// NOTE: If someone else fetches a non-read grid, and you fetch it
655  /// as a read grid, you will not get any copied data.
656  CE_Grid *getCEGrid(bool read, bool write);
657 
658  /// Any modified CE cache on the GPU will be copied back to the
659  /// CPU. Will leave result on GPU.
660  virtual void flushCEWriteCaches();
661 
662  /// Remove all CE caches from the GPU, possibly writing back
663  /// if necessary.
664  virtual void flushCECaches();
665 
666 protected:
668  { return GA_FAMILY_NONE; }
669 
670 #if !GA_PRIMITIVE_VERTEXLIST
671  virtual void clearForDeletion();
672 #endif
673 
674 #if !GA_PRIMITIVE_VERTEXLIST
675  /// Defragmentation
676  virtual void swapVertexOffsets(const GA_Defragment &defrag);
677 #endif
678 
680 
681  virtual bool savePrivateH9(std::ostream &os, bool binary) const;
682  virtual bool loadPrivateH9(UT_IStream &is);
683 
684  // A versioned loading method.
685  bool loadVoxelDataH9(UT_IStream &is,
687  int version);
688 
690  { return getPointOffset(); }
691 
692  /// Gets the handle to our voxels
694 
695  // All accesses of myVoxelHandle should go though getMyVoxelHandle
696  // so that the voxels are loaded from shared data before access
701 
702  mutable CE_Grid *myCEGrid;
703  mutable bool myCEGridAuthorative;
704 
705  virtual bool evaluatePointRefMap(GA_Offset result_vtx,
706  GA_AttributeRefMap &hlist,
707  fpreal u, fpreal v, uint du, uint dv) const;
708  virtual int evaluatePointV4( UT_Vector4 &pos, float u, float v = 0,
709  unsigned du=0, unsigned dv=0) const
710  {
711  return GEO_Primitive::evaluatePointV4(pos, u, v,
712  du, dv);
713  }
714  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
715  GA_AttributeRefMap &hlist) const;
716 
717  virtual bool evaluateInteriorPointRefMap(GA_Offset result_vtx,
718  GA_AttributeRefMap &map,
719  fpreal u, fpreal v, fpreal w = 0) const;
720  virtual int evaluateInteriorPointV4(UT_Vector4 &pos,
721  fpreal u, fpreal v, fpreal w = 0) const;
722 
723 private:
724 #if !GA_PRIMITIVE_VERTEXLIST
725  GA_Offset myVertex; // My vertex
726 #endif
727  UT_Matrix3 myXform; // My Transform
728  UT_Matrix3 myInverseXform; // My inverse transform
729  bool myIsSDF : 1; // Are we a signed distance field?
730 
731  GEO_VolumeOptions myVis;
732 
733  // The taper is the radius of the bottom half, z-minus, of the default box
734  // The top half's radius is one. These radii are then modified by
735  // myXform.
736  fpreal myTaperX, myTaperY;
737 
738  friend std::ostream &operator<<(std::ostream &os, const GEO_PrimVolume &d)
739  {
740  d.saveH9(os, 0,
743  return os;
744  }
746 };
748 
749 #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:723
void setTaperX(float t)
virtual void flushCECaches()
Definition: GA_Primitive.h:727
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
serialize getSerialize() const
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
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:249
virtual UT_Vector3 baryCenter() const
virtual void copyPrimitive(const GEO_Primitive *src)=0
virtual void clearForDeletion()
Definition: GA_Primitive.h:598
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:227
#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:72
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:79
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:75
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:581
2D Vector class.
Definition: UT_Vector2.h:137
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:585
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:269
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:115
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:39
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:275
serialize(const serialize &src)
virtual void unitLengthToUnitPair(float ulength, float vlength, float &uparm, float &vparm) const
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:583
virtual void getLocalTransform(UT_Matrix3D &matrix) const
double fpreal
Definition: SYS_Types.h:269
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:235
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