HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GU_RayPrimitive.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: GU library (C++)
7  *
8  * COMMENTS: Ray info - cached information for each primitive type
9  *
10  */
11 
12 #ifndef __GU_RayPrimInfo_h__
13 #define __GU_RayPrimInfo_h__
14 
15 #include "GU_API.h"
16 #include "GU_NURBPyramid.h"
17 #include "GU_RayRBezCurve.h"
18 #include "GU_RayRBezSurf.h"
19 #include <GEO/GEO_Detail.h>
20 #include <GEO/GEO_PrimitiveP.h>
21 #include <GEO/GEO_PrimNURBCurve.h>
22 #include <GEO/GEO_PrimNURBSurf.h>
23 #include <GEO/GEO_PrimRBezCurve.h>
24 #include <GEO/GEO_PrimRBezSurf.h>
25 #include <GEO/GEO_PrimVolume.h>
26 #include <GA/GA_KnotVector.h>
27 #include <GA/GA_NUBBasis.h>
28 #include <GA/GA_Types.h>
29 #include <TS/TS_Expression.h>
30 
31 #include <UT/UT_BoundingBox.h>
32 #include <UT/UT_Matrix3.h>
33 #include <UT/UT_Matrix4.h>
35 #include <UT/UT_UniquePtr.h>
36 #include <UT/UT_VDBUtils.h>
37 #include <UT/UT_Vector3.h>
38 #include <UT/UT_Vector4Array.h>
39 #include <UT/UT_VoxelArray.h>
40 #include <SYS/SYS_Inline.h>
41 
42 #ifdef OPENVDB_ENABLED
43 #include <openvdb/openvdb.h>
44 #endif
45 
46 class GU_Detail;
47 class GU_MinInfo;
48 class GU_RayInfo;
49 class GU_RayIntersect;
50 class GEO_Primitive;
51 class GEO_PrimRBezSurf;
52 
54 {
55 public:
56  GU_Ray(const UT_Vector3 &o, const UT_Vector3 &d, const UT_Matrix4 *mat = 0);
57 
58  float globalDist(float t) const { return t / tscale; }
59  float localDist(float t) const { return t * tscale; }
60 
62  float tscale;
63 };
64 
65 // Finds intersection of ray & quad.
66 int
68  const UT_Vector3 &dir,
69  const UT_Vector3 &A, const UT_Vector3 &B,
70  const UT_Vector3 &C, const UT_Vector3 &D,
71  const UT_Vector3 &norm,
72  float &t, float &u, float &v, float &d2);
73 //________________________________________________________
74 //
75 // Base class for primitive info
76 //________________________________________________________
77 //
79 {
80 public:
81  GU_RayPrimInfo(GEO_ConstPrimitiveP prim, int serialidx);
82 
83  // TODO: Make pure virtual when compiler allows us
84  virtual int intersect(
85  const GEO_Detail &geo,
86  const UT_Vector3 &org,
87  const UT_Vector3 &dir,
88  GU_RayInfo &hitinfo)
89  {
90  return 0;
91  }
92  virtual int minimum(
93  const GEO_Detail &geo,
94  const UT_Vector3 &p,
95  GU_MinInfo &mininfo)
96  {
97  return 0;
98  }
99 
100  // NB: "t" value is position on this, (u,v,w) position
101  // on passed in primitive.
102  virtual int intersectPrim(
103  const GEO_Detail &geo,
104  const GEO_Detail &prim_geo,
105  GU_RayPrimInfo *prim,
106  GU_RayInfo &hitinfo)
107  {
108  return -1;
109  }
110  virtual int minimumPrim(
111  const GEO_Detail &geo,
112  const GEO_Detail &prim_geo,
113  GU_RayPrimInfo *prim,
114  GU_MinInfo &mininfo)
115  {
116  return 0;
117  }
118 
119  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
120  {
121  return UT_Vector3(0,0,0);
122  }
123 
124  void bumpRefCount(int dir);
125  static void getXYProjection(const UT_Vector3 &nml, int &x, int &y);
126 
127  // Checks the dirty bit, if set, initializes.
128  void ensureClean(const GEO_Detail &geo);
129  // Initializes.
130  virtual void init(const GEO_Detail &geo)
131  {
132  }
133 
136  {
137  return GEO_ConstPrimitiveP(&geo, myPrimOffset);
138  }
139 
140  /// Report approximate memory usage.
141  virtual int64 getMemoryUsage(bool inclusive) const = 0;
142 
143 protected:
144  void initBBox(GEO_ConstPrimitiveP prim);
145 
146 public:
149  float sortValue;
150  int mySerialIdx; // Our index into a serial table
151 
153  // it is cute how we carefully conserve bits here, when you consider
154  // things like the UT_BoundingBox and what shows up in the
155  // subclasses!
156  bool degenerate:1;
157  //bool subclassflag:1;
158  volatile int myDirty;
159 
160 protected:
161  virtual ~GU_RayPrimInfo();
162 };
163 
164 //________________________________________________________
165 //
166 // Quadric ray intersection class
167 //________________________________________________________
168 //
170 {
171 public:
172  GU_RayQuadricInfo(GEO_ConstPrimitiveP prim, int serialidx);
173  ~GU_RayQuadricInfo() override;
174 
175  int intersect(
176  const GEO_Detail &geo,
177  const UT_Vector3 &org,
178  const UT_Vector3 &dir,
179  GU_RayInfo &hitinfo) override;
180  int minimum(
181  const GEO_Detail &geo,
182  const UT_Vector3 &p,
183  GU_MinInfo &mininfo) override;
184 
185  int64 getMemoryUsage(bool inclusive) const override
186  {
187  int64 mem = inclusive ? sizeof(*this) : 0;
188  return mem;
189  }
190 
191 public:
192  static int circle(
193  GEO_ConstPrimitiveP prim,
194  const GU_Ray &ray,
195  GU_RayInfo &hi,
196  UT_Vector3 &nml);
197  static int sphere(
198  GEO_ConstPrimitiveP prim,
199  const GU_Ray &ray,
200  GU_RayInfo &hi,
201  UT_Vector3 &nml);
202  static int tube(
203  GEO_ConstPrimitiveP prim,
204  const GU_Ray &ray,
205  GU_RayInfo &hi,
206  UT_Vector3 &nml);
207 
208  static void minCircle(const UT_Vector3 &p, UT_Vector3 &minpt);
209  static void minSphere(const UT_Vector3 &p, UT_Vector3 &minpt);
210  static void minTube(
211  GEO_ConstPrimitiveP prim,
212  const UT_Vector3 &p,
213  UT_Vector3 &minpt,
214  float &u,
215  float &v);
216 
217  UT_Matrix4 xform; // Ray transform
218  UT_Matrix3 nmlXform; // Normal transform
219 };
220 
221 //________________________________________________________
222 //
223 // Triangle ray intersection class
224 //________________________________________________________
225 //
226 template<bool istet=false>
228 {
229 public:
230  GU_RayTriangleInfo(GEO_ConstPrimitiveP prim, int serialidx,
231  GA_Offset p0, GA_Offset p1,
232  GA_Offset p2, float w=0.0f);
233  ~GU_RayTriangleInfo() override;
234 
235  void init(const GEO_Detail &geo) override;
236 
237  int intersect(
238  const GEO_Detail &geo,
239  const UT_Vector3 &org,
240  const UT_Vector3 &dir,
241  GU_RayInfo &hitinfo) override;
242  int minimum(
243  const GEO_Detail &geo,
244  const UT_Vector3 &p,
245  GU_MinInfo &mininfo) override;
246 
247  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
248  {
249  return nml;
250  }
251 
252  int64 getMemoryUsage(bool inclusive) const override
253  {
254  int64 mem = inclusive ? sizeof(*this) : 0;
255  return mem;
256  }
257 
258 public:
259  GA_Offset myV[3]; // Three corner vertices
260  UT_Vector3 nml; // Surface normal
261  float D; // Plane eqn constant
262  int x, y; // Oriented to projected plane
263  const float myW;
264 };
265 
266 // These are hardened triangles:
267 template<bool istet=false>
269 {
270 public:
271  GU_RayHTriangleInfo(GEO_ConstPrimitiveP prim, int serialidx,
272  const UT_Vector3 &p1, const UT_Vector3 &p2,
273  const UT_Vector3 &p3, float w=0.0f);
274  ~GU_RayHTriangleInfo() override;
275 
276  void init(const GEO_Detail &geo) override;
277 
278  int intersect(
279  const GEO_Detail &geo,
280  const UT_Vector3 &org,
281  const UT_Vector3 &dir,
282  GU_RayInfo &hitinfo) override;
283  int minimum(
284  const GEO_Detail &geo,
285  const UT_Vector3 &p,
286  GU_MinInfo &mininfo) override;
287 
288  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
289  {
290  return nml;
291  }
292 
293  int64 getMemoryUsage(bool inclusive) const override
294  {
295  int64 mem = inclusive ? sizeof(*this) : 0;
296  return mem;
297  }
298 
299 public:
300  UT_Vector3 myV[3]; // Three corner verices
301  UT_Vector3 nml; // Surface normal
302  float D; // Plane eqn constant
303  int x, y; // Oriented to projected plane
304  const float myW;
305 };
306 
307 //________________________________________________________
308 //
309 // Tetrahedron ray intersection class
310 //________________________________________________________
311 //
312 
313 /// Checks if query is inside the tet specified by ps.
314 /// If the tet is inverted and it's inside, negated will be set to true.
315 /// It computes normals, areas, and sub tet volumes already, so that they
316 /// can be used afterward.
317 GU_API bool
319  const UT_Vector3 &query,
320  const UT_Vector3 *ps,
321  UT_Vector3 n[4],
322  bool &negated,
323  float dots[4],
324  float A[4]) noexcept;
325 
326 /// Computes the uvw coordinates of a query point inside a tet, based on
327 /// the values computed by GUisPointInsideTet.
330  float dots[4],
331  const float A[4]) noexcept;
332 
334 {
335 public:
336  GU_RayTetInfo(GEO_ConstPrimitiveP prim, int serialidx,
337  GA_Offset p0, GA_Offset p1,
338  GA_Offset p2, GA_Offset p3);
339  ~GU_RayTetInfo() override;
340 
341  int intersect(
342  const GEO_Detail &geo,
343  const UT_Vector3 &org,
344  const UT_Vector3 &dir,
345  GU_RayInfo &hitinfo) override;
346  int minimum(
347  const GEO_Detail &geo,
348  const UT_Vector3 &p,
349  GU_MinInfo &mininfo) override;
350 
351  int64 getMemoryUsage(bool inclusive) const override
352  {
353  int64 mem = inclusive ? sizeof(*this) : 0;
354  return mem;
355  }
356 
357 public:
358  GA_Offset myV[4]; // Four corner vertices
359 };
360 
361 // These are hardened triangles:
363 {
364 public:
365  GU_RayHTetInfo(GEO_ConstPrimitiveP prim, int serialidx,
366  const UT_Vector3 &p1, const UT_Vector3 &p2,
367  const UT_Vector3 &p3, const UT_Vector3 &p4);
368  ~GU_RayHTetInfo() override;
369 
370  int intersect(
371  const GEO_Detail &geo,
372  const UT_Vector3 &org,
373  const UT_Vector3 &dir,
374  GU_RayInfo &hitinfo) override;
375  int minimum(
376  const GEO_Detail &geo,
377  const UT_Vector3 &p,
378  GU_MinInfo &mininfo) override;
379 
380  int64 getMemoryUsage(bool inclusive) const override
381  {
382  int64 mem = inclusive ? sizeof(*this) : 0;
383  return mem;
384  }
385 
386 public:
387  UT_Vector3 myV[4]; // Four corner verices
388 };
389 
390 //___________________________________________________________________________
391 //
392 // Quad ray intersection classes - HQuad is for hardened points (i.e. NURBS)
393 //___________________________________________________________________________
394 //
396 {
397 public:
398  GU_RayQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
399  GA_Offset p0, GA_Offset p1,
400  GA_Offset p2, GA_Offset p3,
401  float ustart = 0.0F, float ulength = 1.0F,
402  float vstart = 0.0F, float vlength = 1.0F,
403  float w=0.0f);
404  ~GU_RayQuadInfo() override;
405 
406  void init(const GEO_Detail &geo) override;
407 
408  int intersect(
409  const GEO_Detail &geo,
410  const UT_Vector3 &org,
411  const UT_Vector3 &dir,
412  GU_RayInfo &hitinfo) override;
413  int minimum(
414  const GEO_Detail &geo,
415  const UT_Vector3 &p,
416  GU_MinInfo &mininfo) override;
417 
418  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
419  {
420  return nml;
421  }
422 
423  int64 getMemoryUsage(bool inclusive) const override
424  {
425  int64 mem = inclusive ? sizeof(*this) : 0;
426  return mem;
427  }
428 
429 public:
430  GA_Offset myV[4]; // Four corner vertices
431  UT_Vector3 nml; // Surface normal
432 
433  //float D; // Plane eqn constant
434  //int x, y; // Oriented to projected plane
435  float myUStart, myULength;
436  float myVStart, myVLength;
437  const float myW;
438 };
439 
441 {
442 public:
443  GU_RayHQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
444  const UT_Vector3 &p0, const UT_Vector3 &p1,
445  const UT_Vector3 &p2, const UT_Vector3 &p3,
446  float ustart = 0.0f, float ulen = 1.0f,
447  float vstart = 0.0f, float vlen = 1.0f,
448  bool revnml = false, float w=0.0f);
449  ~GU_RayHQuadInfo() override;
450 
451  void init(const GEO_Detail &geo) override;
452 
453  int intersect(
454  const GEO_Detail &geo,
455  const UT_Vector3 &org,
456  const UT_Vector3 &dir,
457  GU_RayInfo &hitinfo) override;
458  int minimum(
459  const GEO_Detail &geo,
460  const UT_Vector3 &p,
461  GU_MinInfo &mininfo) override;
462 
463  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
464  {
465  return nml;
466  }
467 
468  int64 getMemoryUsage(bool inclusive) const override
469  {
470  int64 mem = inclusive ? sizeof(*this) : 0;
471  return mem;
472  }
473 
474 public:
475  UT_Vector3 myV[4]; // Four corner vertices
476  UT_Vector3 nml; // Surface normal
477  bool myRevNml; // Do we reverse the normal?
478 
479  // These numbers aren't needed by the bilinear code.
480  //float D; // Plane eqn constant
481  //int x, y; // Oriented to projected plane
482 
483  float myUStart, myULength;
484  float myVStart, myVLength;
485  const float myW;
486 };
487 
488 //________________________________________________________
489 //
490 // General Face ray intersection class
491 //________________________________________________________
492 //
494 {
495 public:
496  GU_RayPolyInfo(GEO_ConstPrimitiveP prim, int serialidx,
497  const UT_Array<GA_Offset> &ipts, float w=0.0f);
498  ~GU_RayPolyInfo() override;
499 
500  int intersect(
501  const GEO_Detail &geo,
502  const UT_Vector3 &org,
503  const UT_Vector3 &dir,
504  GU_RayInfo &hitinfo) override;
505  int minimum(
506  const GEO_Detail &geo,
507  const UT_Vector3 &p,
508  GU_MinInfo &mininfo) override;
509 
510  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
511  {
512  return nml;
513  }
514 
515  int64 getMemoryUsage(bool inclusive) const override
516  {
517  int64 mem = inclusive ? sizeof(*this) : 0;
518  return mem;
519  }
520 
521 public:
523  float D;
524  int x, y;
526  const float myW;
527 };
528 
530 {
531 public:
533  GEO_ConstPrimitiveP prim,
534  int serialidx,
535  const UT_Vector4Array &p,
536  float w = 0.0f);
538  GEO_ConstPrimitiveP prim,
539  int serialidx,
540  const UT_Array<UT_Vector3> &p,
541  float w = 0.0f);
542  ~GU_RayHPolyInfo() override;
543 
544  template<typename ARRAY_TYPE>
545  void initPoly(GEO_ConstPrimitiveP p, const ARRAY_TYPE &pts);
546  int intersect(
547  const GEO_Detail &geo,
548  const UT_Vector3 &org,
549  const UT_Vector3 &dir,
550  GU_RayInfo &hitinfo) override;
551  int minimum(
552  const GEO_Detail &geo,
553  const UT_Vector3 &p,
554  GU_MinInfo &mininfo) override;
555 
556  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
557  {
558  return nml;
559  }
560 
561  int64 getMemoryUsage(bool inclusive) const override
562  {
563  int64 mem = inclusive ? sizeof(*this) : 0;
564  if (xval)
565  mem += npts * sizeof(xval[0]);
566  if (yval)
567  mem += npts * sizeof(yval[0]);
568  return mem;
569  }
570 
571 public:
573 
574  int npts;
578  float D;
579  int x, y;
580  const float myW;
581 };
582 
583 //________________________________________________________
584 //
585 // Meta-surface ray intersection class
586 //________________________________________________________
587 //
589 {
590 public:
591  GU_RayMetaInfo(const TS_MetaExpressionPtr &expr, int serialidx);
592  ~GU_RayMetaInfo() override;
593 
594  int intersect(
595  const GEO_Detail &geo,
596  const UT_Vector3 &org,
597  const UT_Vector3 &dir,
598  GU_RayInfo &hitinfo) override;
599 
600  int64 getMemoryUsage(bool inclusive) const override;
601 
602 public:
605 };
606 
607 //________________________________________________________
608 //
609 // VDB intersection class
610 //________________________________________________________
612 {
613 public:
614  GU_RayVDBInfo(GEO_ConstPrimitiveP vdb, int serialidx);
615  ~GU_RayVDBInfo() override;
616 
617  int intersect(
618  const GEO_Detail &geo,
619  const UT_Vector3 &org,
620  const UT_Vector3 &dir,
621  GU_RayInfo &hitinfo) override;
622 
623  int64 getMemoryUsage(bool inclusive) const override;
624 
625 public:
627  float myStepSize;
629  bool myFailed;
631 #ifdef OPENVDB_ENABLED
632  const openvdb::GridBase *myGridRawPtr;
633 #endif
634 
635 };
636 
637 //________________________________________________________
638 //
639 // HeightField intersection class
640 //________________________________________________________
642 {
643 public:
644  GU_RayHeightFieldInfo(const GEO_PrimVolume *vdb, int serialidx);
645  ~GU_RayHeightFieldInfo() override;
646 
647  int intersect(
648  const GEO_Detail &geo,
649  const UT_Vector3 &org,
650  const UT_Vector3 &dir,
651  GU_RayInfo &hitinfo) override;
652 
653  template<bool farthest,bool rm_backface,bool reverse,bool bidirectional,typename FUNCTOR>
654  bool intersect(
655  const UT_Vector3 &org,
656  const UT_Vector3 &dir,
657  const UT_Vector3 &inverse_dir,
658  int max_dir,
659  const UT_Vector3 &N0,
660  const UT_Vector3 &N1,
661  float &outer_tmin,
662  float &outer_tmax,
663  uint bvh_index,
664  FUNCTOR &functor) const;
665 
666  int minimum(
667  const GEO_Detail &geo,
668  const UT_Vector3 &p,
669  GU_MinInfo &mininfo) override;
670 
671  int64 getMemoryUsage(bool inclusive) const override;
672 
673 public:
674  int myAxis, myA1, myA2;
675  int myDim[3];
677  bool myFailed;
678  float myScale, myInvScale;
682 };
683 
684 //________________________________________________________
685 //
686 // Packed primitive intersection class
687 //________________________________________________________
688 
690 {
691 public:
692  GU_RayPackedInfo(GEO_ConstPrimitiveP prim, int serialidx, int picking,
693  int polyline, int harden, bool solidtet);
694  ~GU_RayPackedInfo() override;
695 
696  void init(const GEO_Detail &geo) override;
697 
698  int intersect(
699  const GEO_Detail &geo,
700  const UT_Vector3 &org,
701  const UT_Vector3 &dir,
702  GU_RayInfo &hitinfo) override;
703  int minimum(
704  const GEO_Detail &geo,
705  const UT_Vector3 &p,
706  GU_MinInfo &mininfo) override;
707 
708  int64 getMemoryUsage(bool inclusive) const override;
709 
710  void unpack(const GEO_Detail &geo);
711 
712 private:
713  const int myPicking;
714  const int myPolyLine;
715  const int myHarden;
716  const int mySolidTet;
717 
718  UT_UniquePtr<GEO_Detail> myUnpackedGdp;
719  UT_UniquePtr<GU_RayIntersect> myUnpackedIntersect;
720 };
721 
722 //________________________________________________________
723 //
724 // Polyline intersection class
725 //________________________________________________________
726 //
728 {
729 public:
731  GEO_ConstPrimitiveP prim,
732  int serialidx,
733  int span, int len);
734  ~GU_RayPolyLineInfo() override;
735 
736  int intersect(
737  const GEO_Detail &geo,
738  const UT_Vector3 &org,
739  const UT_Vector3 &dir,
740  GU_RayInfo &hitinfo) override;
741  int minimum(
742  const GEO_Detail &geo,
743  const UT_Vector3 &p,
744  GU_MinInfo &mininfo) override;
745  int intersectPrim(
746  const GEO_Detail &geo,
747  const GEO_Detail &prim_geo,
748  GU_RayPrimInfo *prim,
749  GU_RayInfo &hitInfo) override;
750  int minimumPrim(
751  const GEO_Detail &geo,
752  const GEO_Detail &prim_geo,
753  GU_RayPrimInfo *prim,
754  GU_MinInfo &mininfo) override;
755 
756  int64 getMemoryUsage(bool inclusive) const override
757  {
758  int64 mem = inclusive ? sizeof(*this) : 0;
759  return mem;
760  }
761 
762 public:
763  int mySpan; // What part of the poly
764  int myLen; // we are responsible for
765 };
766 
767 //________________________________________________________
768 //
769 // Curve intersection class
770 //
771 // Note: working in homogeneous coordinate
772 //________________________________________________________
773 //
774 
776 {
777 public:
779  GEO_ConstPrimitiveP curve,
780  int serialidx,
781  bool is_first_span,
782  bool is_last_span)
783  : GU_RayPrimInfo(curve, serialidx)
784  , myFirstSpanFlag(is_first_span)
785  , myLastSpanFlag(is_last_span)
786  {
787  }
788  ~GU_RayCurveInfo() override {}
789 
790 protected:
791  // checks the proximity of the ray to the end points of the curve,
792  // and compares it with the tolerance given in hit_info,
793  // but only for these endpoints
794  // of the curve for which first/last span flags (the member data) are true.
795  // If ray passes within the given tolerance, in the hemispherical cup
796  // at the end of the curve, that "seals" the cylidrical zone around
797  // the curve, it is considered as a hit, and 1 is returned.
798  // INPUTS:
799  // org, dir - the origin and direction of the ray
800  // curve - the curve endpoints we investigate
801  // hit_info - its tolerance is treated as a radius of a hemisphere at the
802  // endpoints, within which to test the ray's presence
803  // OUTPUT
804  // hit_info - if hit, a hit is added
805  // RETURN:
806  // 1 if hit: ray passes within tolerance radius of endpoint(s), otherwise 0
807  int intersectEndPointZone(
808  const GEO_Detail &geo,
809  const UT_Vector3 &org,
810  const UT_Vector3 &dir,
811  const GU_RayRBezCurve* curve,
812  GU_RayInfo &hit_info) const;
813 
814 public:
815  // usually a curve primitive is subdivided into several spans, whose
816  // info is encoded in GU_RayRBezCurveInfo and GU_RayNURBCurveInfo.
817  // Following flags indicate if this span is first or last on the curve.
818  bool myFirstSpanFlag : 1, // 1 if it's firsrt span on curve
819  myLastSpanFlag : 1; // 1 if it's last span on curve
820 };
821 
822 class GEO_PrimRBezCurve;
823 
825 {
826 public:
828  const GEO_PrimRBezCurve *curve,
829  int serialidx,
830  bool is_first_span,
831  bool is_last_span,
832  int span,
833  int nvtx,
834  int ord);
835  ~GU_RayRBezCurveInfo() override;
836 
837  static int count(const GEO_PrimRBezCurve *bezcurve)
838  {
839  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
840  return knots.size() - 1;
841  }
842  template<typename FUNCTOR>
843  static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
844  {
845  const int ord = bezcurve->getOrder();
846  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
847  const int last = knots.size() - 2;
848  const int s = bezcurve->getVertexCount();
849 
850  for (int j = last; j >= 0; --j)
851  {
852  const bool is_first = (j == 0);
853  const bool is_last = (j == last);
854  functor(new GU_RayRBezCurveInfo(bezcurve, (pinfonum ? *pinfonum : 0),
855  is_first, is_last, j, s, ord));
856  if (pinfonum)
857  ++(*pinfonum);
858  }
859  }
860 
861  int intersect(
862  const GEO_Detail &geo,
863  const UT_Vector3 &org,
864  const UT_Vector3 &dir,
865  GU_RayInfo &hitinfo) override;
866  int minimum(
867  const GEO_Detail &geo,
868  const UT_Vector3 &p,
869  GU_MinInfo &mininfo) override;
870  int intersectPrim(
871  const GEO_Detail &geo,
872  const GEO_Detail &prim_geo,
873  GU_RayPrimInfo *prim,
874  GU_RayInfo &hitInfo) override;
875  int minimumPrim(
876  const GEO_Detail &geo,
877  const GEO_Detail &prim_geo,
878  GU_RayPrimInfo *prim,
879  GU_MinInfo &mininfo) override;
880 
881  void init(const GEO_Detail &geo) override;
882  GU_RayRBezCurve *buildCurve(const GEO_Detail &geo);
883 
884  int64 getMemoryUsage(bool inclusive) const override
885  {
886  int64 mem = inclusive ? sizeof(*this) : 0;
887  if (myCurve)
888  mem += myCurve->getMemoryUsage(true);
889  return mem;
890  }
891 
892 public:
893  int mySpan;
895 };
896 
898 {
899 public:
901  GEO_ConstPrimitiveP curve,
902  int serialidx,
903  UT_Interval u,
904  const UT_RefMatrix<UT_Vector4> &patch_cv,
905  int ord,
906  bool is_rational);
907  ~GU_RayNURBCurveInfo() override;
908 
909  template<typename FUNCTOR>
910  static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
911  {
912  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbcurve->getBasis();
913  const int ord = ub->getOrder();
914  GA_PwHandleRO h(nurbcurve->getDetail());
915  GU_NURBPyramid<0> pyramid(ub, nurbcurve, h);
916  const bool rational = nurbcurve->isRational();
917 
918  bool first = true;
919  for (pyramid.rewind(ub); !pyramid.atEnd(); pyramid.advance())
920  {
921  GU_RayNURBCurveInfo *nurbcurveinfo = new GU_RayNURBCurveInfo(
922  nurbcurve, (pinfonum ? *pinfonum : 0),
923  pyramid.getInterval(), pyramid.getResult(),
924  ord, rational);
925  nurbcurveinfo->myFirstSpanFlag = first;
926  functor(nurbcurveinfo);
927 
928  if (pinfonum)
929  ++(*pinfonum);
930 
931  first = false;
932  }
933  }
934 
935  int intersect(
936  const GEO_Detail &geo,
937  const UT_Vector3 &org,
938  const UT_Vector3 &dir,
939  GU_RayInfo &hitinfo) override;
940  int minimum(
941  const GEO_Detail &geo,
942  const UT_Vector3 &p,
943  GU_MinInfo &mininfo) override;
944  int intersectPrim(
945  const GEO_Detail &geo,
946  const GEO_Detail &prim_geo,
947  GU_RayPrimInfo *prim,
948  GU_RayInfo &hitInfo) override;
949  int minimumPrim(
950  const GEO_Detail &geo,
951  const GEO_Detail &prim_geo,
952  GU_RayPrimInfo *prim,
953  GU_MinInfo &mininfo) override;
954 
955  int64 getMemoryUsage(bool inclusive) const override
956  {
957  int64 mem = inclusive ? sizeof(*this) : 0;
958  mem += myCurve.getMemoryUsage(false);
959  return mem;
960  }
961 
962 public:
964 };
965 
966 
967 //________________________________________________________
968 //
969 // Surface intersection class
970 //
971 // Note: working in homogeneous coordinate
972 //________________________________________________________
973 //
975 {
976 public:
978  const GEO_PrimRBezSurf *surf, int serialidx,
979  int u_span, int v_span,
980  int u_ord, int v_ord,
981  float u_start, float u_length,
982  float v_start, float v_length,
983  int u_beg, int v_beg,
984  int u_num, int v_num,
985  bool is_rational);
986  ~GU_RayRBezSurfInfo() override;
987 
988  static exint count(const GEO_PrimRBezSurf *bezsurf)
989  {
990  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
991  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
992  return exint(vknots.size()-1)*(uknots.size()-1);
993  }
994 
995  template<typename FUNCTOR>
996  static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
997  {
998  const int uord = bezsurf->getUOrder();
999  const int vord = bezsurf->getVOrder();
1000  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1001  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1002  const int cols = bezsurf->getNumCols();
1003  const int rows = bezsurf->getNumRows();
1004  const bool rational = bezsurf->isRational();
1005 
1006  for (int r = vknots.size()-2; r >= 0; r--)
1007  {
1008  const int r1 = (vord-1)*r;
1009  for (int c = uknots.size()-2; c >= 0; c--)
1010  {
1011  const int c1 = (uord-1)*c;
1012  functor(new GU_RayRBezSurfInfo(
1013  bezsurf, (pinfonum ? *pinfonum : 0),
1014  c, r,
1015  uord, vord,
1016  uknots(c), uknots(c+1)-uknots(c),
1017  vknots(r), vknots(r+1)-vknots(r),
1018  c1, r1,
1019  cols, rows,
1020  rational));
1021 
1022  if (pinfonum)
1023  ++(*pinfonum);
1024  }
1025  }
1026  }
1027 
1028  int intersect(
1029  const GEO_Detail &geo,
1030  const UT_Vector3 &org,
1031  const UT_Vector3 &dir,
1032  GU_RayInfo &hitinfo) override;
1033  int minimum(
1034  const GEO_Detail &geo,
1035  const UT_Vector3 &p,
1036  GU_MinInfo &mininfo) override;
1037 
1038  int intersectPrim(
1039  const GEO_Detail &geo,
1040  const GEO_Detail &prim_geo,
1041  GU_RayPrimInfo *prim,
1042  GU_RayInfo &hitinfo) override;
1043  int minimumPrim(
1044  const GEO_Detail &geo,
1045  const GEO_Detail &prim_geo,
1046  GU_RayPrimInfo *prim,
1047  GU_MinInfo &hitinfo) override;
1048 
1049  void init(const GEO_Detail &geo) override;
1050  virtual GU_RayRBezSurf *buildSurf(const GEO_Detail &geo);
1051 
1052  int64 getMemoryUsage(bool inclusive) const override
1053  {
1054  int64 mem = inclusive ? sizeof(*this) : 0;
1055  if (mySurf)
1056  mem += mySurf->getMemoryUsage(true);
1057  return mem;
1058  }
1059 
1060 public:
1061  int myUSpan, myVSpan;
1063 };
1064 
1066 {
1067 public:
1069  GEO_ConstPrimitiveP surf, int serialidx,
1070  int u_ord, int v_ord,
1072  const UT_RefMatrix<UT_Vector4> &patch_cv,
1073  bool is_rational);
1074  ~GU_RayNURBSurfInfo() override;
1075 
1076  template<typename FUNCTOR>
1077  static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
1078  {
1079  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbsurf->getUBasis();
1080  const GA_NUBBasis *vb = (const GA_NUBBasis *)nurbsurf->getVBasis();
1081  const int uOrd = ub->getOrder();
1082  const int vOrd = vb->getOrder();
1083  GA_PwHandleRO h(nurbsurf->getDetail());
1084  GU_NURBPyramid<0> uPyramid(ub, nurbsurf, h);
1085  GU_NURBPyramid<1> vPyramid(vb, &uPyramid.getResult());
1086  const bool rational = nurbsurf->isRational();
1087 
1088  for (uPyramid.rewind(ub); !uPyramid.atEnd(); uPyramid.advance())
1089  {
1090  const UT_Interval &u = uPyramid.getInterval();
1091  for (vPyramid.rewind(vb); !vPyramid.atEnd(); vPyramid.advance())
1092  {
1093  functor(new GU_RayNURBSurfInfo(nurbsurf,
1094  (pinfonum ? *pinfonum : 0),
1095  uOrd, vOrd,
1096  u, vPyramid.getInterval(),
1097  vPyramid.getResult(),
1098  rational));
1099 
1100  if (pinfonum)
1101  ++(*pinfonum);
1102  }
1103  }
1104  }
1105 
1106  int intersect(
1107  const GEO_Detail &geo,
1108  const UT_Vector3 &org,
1109  const UT_Vector3 &dir,
1110  GU_RayInfo &hitinfo) override;
1111  int minimum(
1112  const GEO_Detail &geo,
1113  const UT_Vector3 &p,
1114  GU_MinInfo &mininfo) override;
1115  int intersectPrim(
1116  const GEO_Detail &geo,
1117  const GEO_Detail &prim_geo,
1118  GU_RayPrimInfo *prim,
1119  GU_RayInfo &hitinfo) override;
1120  int minimumPrim(
1121  const GEO_Detail &geo,
1122  const GEO_Detail &prim_geo,
1123  GU_RayPrimInfo *prim,
1124  GU_MinInfo &hitinfo) override;
1125 
1126  int64 getMemoryUsage(bool inclusive) const override
1127  {
1128  int64 mem = inclusive ? sizeof(*this) : 0;
1129  mem += mySurf.getMemoryUsage(false);
1130  return mem;
1131  }
1132 
1133 public:
1135 };
1136 
1137 //___________________________________________________________________________
1138 //
1139 // Moving triangle ray intersection classes
1140 // - HTriangle is for hardened points
1141 //___________________________________________________________________________
1142 //
1144 {
1145 public:
1147  GEO_ConstPrimitiveP prim0, int serialidx,
1148  GA_Offset p00, GA_Offset p01,
1149  GA_Offset p02,
1150  GEO_ConstPrimitiveP prim1,
1151  GA_Offset p10, GA_Offset p11,
1152  GA_Offset p12);
1153  ~GU_RayMovingTriangleInfo() override;
1154 
1155  void init(const GEO_Detail &geo) override;
1156 
1157  int intersect(
1158  const GEO_Detail &geo,
1159  const UT_Vector3 &org,
1160  const UT_Vector3 &dir,
1161  GU_RayInfo &hitinfo) override;
1162 
1163  int64 getMemoryUsage(bool inclusive) const override
1164  {
1165  int64 mem = inclusive ? sizeof(*this) : 0;
1166  return mem;
1167  }
1168 
1169 private:
1170  int insertHit(
1171  const GEO_Detail &geo,
1172  const UT_Vector3 &org,
1173  const UT_Vector3 &dir,
1174  GU_RayInfo &hitinfo,
1175  float t,
1176  float nt);
1177 
1178 public:
1180  GA_Offset myV0[3]; // Three corner vertices at t = 0
1181  GA_Offset myV1[3]; // Three corner vertices at t = 1
1182 
1183  double a2, a1, a0; // Coefficients of x comp of normal
1184  double b2, b1, b0; // Coefficients of y comp of normal
1185  double c2, c1, c0; // Coefficients of z comp of normal
1186 };
1187 
1188 
1189 #endif
GLdouble s
Definition: glew.h:1390
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
UT_VDBType myVDBType
TS_MetaExpressionPtr myExprRef
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:141
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
UT_UniquePtr< float[]> FloatPtrArray
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
int isRational() const
SYS_FORCE_INLINE GA_Size getVertexCount() const
Return the number of vertices used by this primitive.
Definition: GA_Primitive.h:232
UT_BoundingBox bbox
const float myW
UT_VoxelArrayF myMinMap
volatile int myDirty
const UT_Array< GA_Offset > pts
virtual int minimum(const GEO_Detail &geo, const UT_Vector3 &p, GU_MinInfo &mininfo)
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
UT_UniquePtr< GU_RayRBezCurve > myCurve
virtual void init(const GEO_Detail &geo)
UT_Vector3T< float > UT_Vector3
UT_ThreadSpecificValue< TS_MetaExpressionPtr > myMetaExprCopies
Definition: span.h:47
virtual int minimumPrim(const GEO_Detail &geo, const GEO_Detail &prim_geo, GU_RayPrimInfo *prim, GU_MinInfo &mininfo)
int64 exint
Definition: SYS_Types.h:125
virtual int intersectPrim(const GEO_Detail &geo, const GEO_Detail &prim_geo, GU_RayPrimInfo *prim, GU_RayInfo &hitinfo)
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
const GLint * first
Definition: glew.h:1528
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
GLenum query
Definition: glew.h:5704
GEO_PrimVolumeXform myXform
GU_RayCurveInfo(GEO_ConstPrimitiveP curve, int serialidx, bool is_first_span, bool is_last_span)
const GLdouble * v
Definition: glew.h:1391
UT_VDBType
Definition: UT_VDBUtils.h:11
unsigned getVOrder() const
Definition: GEO_TPSurf.h:390
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
float tscale
exint size() const
Definition: UT_Array.h:458
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
int GU_getBilinearQuadIntersection(const UT_Vector3 &org, const UT_Vector3 &dir, const UT_Vector3 &A, const UT_Vector3 &B, const UT_Vector3 &C, const UT_Vector3 &D, const UT_Vector3 &norm, float &t, float &u, float &v, float &d2)
float globalDist(float t) const
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
GA_Size GA_Offset
Definition: GA_Types.h:639
UT_UniquePtr< GU_RayRBezSurf > mySurf
GU_API bool GUisPointInsideTet(const UT_Vector3 &query, const UT_Vector3 *ps, UT_Vector3 n[4], bool &negated, float dots[4], float A[4]) noexcept
static int count(const GEO_PrimRBezCurve *bezcurve)
UT_Vector3 org
GLclampf f
Definition: glew.h:3499
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
int isRational() const
const openvdb::GridBase * myGridRawPtr
GU_RayRBezSurf mySurf
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
const float myW
static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
SYS_FORCE_INLINE int getNumRows() const
Definition: GEO_Hull.h:365
GEO_ConstPrimitiveP myPrim2
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLubyte GLubyte GLubyte GLubyte w
Definition: glew.h:1890
GA_PrimitiveP_T< const GEO_Primitive, const GEO_Detail > GEO_ConstPrimitiveP
GLsizei n
Definition: glew.h:4040
const GLfloat * c
Definition: glew.h:16296
NURBS basis classes which maintain knot vectors.
Definition: GA_NUBBasis.h:44
long long int64
Definition: SYS_Types.h:116
float localDist(float t) const
#define GU_API
Definition: GU_API.h:14
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
const UT_VoxelArrayF * mySamples
SYS_FORCE_INLINE GEO_ConstPrimitiveP primP(const GEO_Detail &geo) const
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
GEO_PrimVolumeXform myXform
const GA_Basis * getBasis() const
Definition: GEO_Curve.h:295
UT_VoxelMipMapF myMinMM
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GLfloat GLfloat p
Definition: glew.h:16321
FloatPtrArray yval
static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GU_API UT_Vector3 GUfindPointInsideTet(float dots[4], const float A[4]) noexcept
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
FloatPtrArray xval
const GA_KnotVector & getVector() const
Definition: GA_Basis.h:372
unsigned getOrder() const override
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
~GU_RayCurveInfo() override
GA_Offset myPrimOffset
virtual int64 getMemoryUsage(bool inclusive) const =0
Report approximate memory usage.
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
SYS_FORCE_INLINE int getNumCols() const
Definition: GEO_Hull.h:372
UT_ThreadSpecificValue< void * > myCache
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GU_RayRBezCurve myCurve
static exint count(const GEO_PrimRBezSurf *bezsurf)
unsigned getUOrder() const
Definition: GEO_TPSurf.h:389
SYS_AtomicCounter refCount
unsigned int uint
Definition: SYS_Types.h:45
GLdouble GLdouble t
Definition: glew.h:1398
GA_Basis * getUBasis() const
Definition: GEO_TPSurf.h:385
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
int getOrder() const
Return the order of the basis.
Definition: GA_Basis.h:80
virtual int intersect(const GEO_Detail &geo, const UT_Vector3 &org, const UT_Vector3 &dir, GU_RayInfo &hitinfo)
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
GLenum GLsizei len
Definition: glew.h:7752
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GA_Basis * getVBasis() const
Definition: GEO_TPSurf.h:386