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 // Hexahedron ray intersection class
393 //________________________________________________________
394 //
395 
397 {
398 public:
399  GU_RayHexInfo(GEO_ConstPrimitiveP prim, int serialidx,
400  GA_Offset p0, GA_Offset p1,
401  GA_Offset p2, GA_Offset p3,
402  GA_Offset p4, GA_Offset p5,
403  GA_Offset p6, GA_Offset p7);
404  ~GU_RayHexInfo() override;
405 
406  int intersect(
407  const GEO_Detail &geo,
408  const UT_Vector3 &org,
409  const UT_Vector3 &dir,
410  GU_RayInfo &hitinfo) override;
411  int minimum(
412  const GEO_Detail &geo,
413  const UT_Vector3 &p,
414  GU_MinInfo &mininfo) override;
415 
416  int64 getMemoryUsage(bool inclusive) const override
417  {
418  int64 mem = inclusive ? sizeof(*this) : 0;
419  return mem;
420  }
421 
422 public:
423  GA_Offset myV[8]; // Eight corner vertices
424 };
425 
426 // These are hardened hexahedra:
428 {
429 public:
430  GU_RayHHexInfo(GEO_ConstPrimitiveP prim, int serialidx,
431  const UT_Vector3 &p1, const UT_Vector3 &p2,
432  const UT_Vector3 &p3, const UT_Vector3 &p4,
433  const UT_Vector3 &p5, const UT_Vector3 &p6,
434  const UT_Vector3 &p7, const UT_Vector3 &p8);
435  ~GU_RayHHexInfo() override;
436 
437  int intersect(
438  const GEO_Detail &geo,
439  const UT_Vector3 &org,
440  const UT_Vector3 &dir,
441  GU_RayInfo &hitinfo) override;
442  int minimum(
443  const GEO_Detail &geo,
444  const UT_Vector3 &p,
445  GU_MinInfo &mininfo) override;
446 
447  int64 getMemoryUsage(bool inclusive) const override
448  {
449  int64 mem = inclusive ? sizeof(*this) : 0;
450  return mem;
451  }
452 
453 public:
454  UT_Vector3 myV[8]; // Eight corner vertices
455 };
456 
457 
458 //___________________________________________________________________________
459 //
460 // Quad ray intersection classes - HQuad is for hardened points (i.e. NURBS)
461 //___________________________________________________________________________
462 //
463 template<bool ISHEX=false>
465 {
466 public:
467  GU_RayQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
468  GA_Offset p0, GA_Offset p1,
469  GA_Offset p2, GA_Offset p3,
470  float ustart = 0.0F, float ulength = 1.0F,
471  float vstart = 0.0F, float vlength = 1.0F,
472  bool revml = false, float w=0.0f);
473  ~GU_RayQuadInfo() override;
474 
475  void init(const GEO_Detail &geo) override;
476 
477  int intersect(
478  const GEO_Detail &geo,
479  const UT_Vector3 &org,
480  const UT_Vector3 &dir,
481  GU_RayInfo &hitinfo) override;
482  int minimum(
483  const GEO_Detail &geo,
484  const UT_Vector3 &p,
485  GU_MinInfo &mininfo) override;
486 
487  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
488  {
489  return nml;
490  }
491 
492  int64 getMemoryUsage(bool inclusive) const override
493  {
494  int64 mem = inclusive ? sizeof(*this) : 0;
495  return mem;
496  }
497 
498 public:
499  GA_Offset myV[4]; // Four corner vertices
500  UT_Vector3 nml; // Surface normal
501  bool myRevNml; // Do we reverse the normal?
502 
503  //float D; // Plane eqn constant
504  //int x, y; // Oriented to projected plane
505  float myUStart, myULength;
506  float myVStart, myVLength;
507  const float myW;
508 };
509 
510 template<bool ISHEX=false>
512 {
513 public:
514  GU_RayHQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
515  const UT_Vector3 &p0, const UT_Vector3 &p1,
516  const UT_Vector3 &p2, const UT_Vector3 &p3,
517  float ustart = 0.0f, float ulen = 1.0f,
518  float vstart = 0.0f, float vlen = 1.0f,
519  bool revnml = false, float w=0.0f);
520  ~GU_RayHQuadInfo() override;
521 
522  void init(const GEO_Detail &geo) override;
523 
524  int intersect(
525  const GEO_Detail &geo,
526  const UT_Vector3 &org,
527  const UT_Vector3 &dir,
528  GU_RayInfo &hitinfo) override;
529  int minimum(
530  const GEO_Detail &geo,
531  const UT_Vector3 &p,
532  GU_MinInfo &mininfo) override;
533 
534  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
535  {
536  return nml;
537  }
538 
539  int64 getMemoryUsage(bool inclusive) const override
540  {
541  int64 mem = inclusive ? sizeof(*this) : 0;
542  return mem;
543  }
544 
545 public:
546  UT_Vector3 myV[4]; // Four corner vertices
547  UT_Vector3 nml; // Surface normal
548  bool myRevNml; // Do we reverse the normal?
549 
550  // These numbers aren't needed by the bilinear code.
551  //float D; // Plane eqn constant
552  //int x, y; // Oriented to projected plane
553 
554  float myUStart, myULength;
555  float myVStart, myVLength;
556  const float myW;
557 };
558 
559 
560 //________________________________________________________
561 //
562 // General Face ray intersection class
563 //________________________________________________________
564 //
566 {
567 public:
568  GU_RayPolyInfo(GEO_ConstPrimitiveP prim, int serialidx,
569  const UT_Array<GA_Offset> &ipts, float w=0.0f);
570  ~GU_RayPolyInfo() override;
571 
572  int intersect(
573  const GEO_Detail &geo,
574  const UT_Vector3 &org,
575  const UT_Vector3 &dir,
576  GU_RayInfo &hitinfo) override;
577  int minimum(
578  const GEO_Detail &geo,
579  const UT_Vector3 &p,
580  GU_MinInfo &mininfo) override;
581 
582  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
583  {
584  return nml;
585  }
586 
587  int64 getMemoryUsage(bool inclusive) const override
588  {
589  int64 mem = inclusive ? sizeof(*this) : 0;
590  return mem;
591  }
592 
593 public:
595  float D;
596  int x, y;
598  const float myW;
599 };
600 
602 {
603 public:
605  GEO_ConstPrimitiveP prim,
606  int serialidx,
607  const UT_Vector4Array &p,
608  float w = 0.0f);
610  GEO_ConstPrimitiveP prim,
611  int serialidx,
612  const UT_Array<UT_Vector3> &p,
613  float w = 0.0f);
614  ~GU_RayHPolyInfo() override;
615 
616  template<typename ARRAY_TYPE>
617  void initPoly(GEO_ConstPrimitiveP p, const ARRAY_TYPE &pts);
618  int intersect(
619  const GEO_Detail &geo,
620  const UT_Vector3 &org,
621  const UT_Vector3 &dir,
622  GU_RayInfo &hitinfo) override;
623  int minimum(
624  const GEO_Detail &geo,
625  const UT_Vector3 &p,
626  GU_MinInfo &mininfo) override;
627 
628  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
629  {
630  return nml;
631  }
632 
633  int64 getMemoryUsage(bool inclusive) const override
634  {
635  int64 mem = inclusive ? sizeof(*this) : 0;
636  if (xval)
637  mem += npts * sizeof(xval[0]);
638  if (yval)
639  mem += npts * sizeof(yval[0]);
640  return mem;
641  }
642 
643 public:
645 
646  int npts;
650  float D;
651  int x, y;
652  const float myW;
653 };
654 
655 //________________________________________________________
656 //
657 // Meta-surface ray intersection class
658 //________________________________________________________
659 //
661 {
662 public:
663  GU_RayMetaInfo(const TS_MetaExpressionPtr &expr, int serialidx);
664  ~GU_RayMetaInfo() override;
665 
666  int intersect(
667  const GEO_Detail &geo,
668  const UT_Vector3 &org,
669  const UT_Vector3 &dir,
670  GU_RayInfo &hitinfo) override;
671 
672  int64 getMemoryUsage(bool inclusive) const override;
673 
674 public:
677 };
678 
679 //________________________________________________________
680 //
681 // VDB intersection class
682 //________________________________________________________
684 {
685 public:
686  GU_RayVDBInfo(GEO_ConstPrimitiveP vdb, int serialidx);
687  ~GU_RayVDBInfo() override;
688 
689  int intersect(
690  const GEO_Detail &geo,
691  const UT_Vector3 &org,
692  const UT_Vector3 &dir,
693  GU_RayInfo &hitinfo) override;
694 
695  int64 getMemoryUsage(bool inclusive) const override;
696 
697 public:
699  float myStepSize;
701  bool myFailed;
703 #ifdef OPENVDB_ENABLED
704  const openvdb::GridBase *myGridRawPtr;
705 #endif
706 
707 };
708 
709 //________________________________________________________
710 //
711 // HeightField intersection class
712 //________________________________________________________
714 {
715 public:
716  GU_RayHeightFieldInfo(const GEO_PrimVolume *vdb, int serialidx);
717  ~GU_RayHeightFieldInfo() override;
718 
719  int intersect(
720  const GEO_Detail &geo,
721  const UT_Vector3 &org,
722  const UT_Vector3 &dir,
723  GU_RayInfo &hitinfo) override;
724 
725  template<bool farthest,bool rm_backface,bool reverse,bool bidirectional,typename FUNCTOR>
726  bool intersect(
727  const UT_Vector3 &org,
728  const UT_Vector3 &dir,
729  const UT_Vector3 &inverse_dir,
730  int max_dir,
731  const UT_Vector3 &N0,
732  const UT_Vector3 &N1,
733  float &outer_tmin,
734  float &outer_tmax,
735  uint bvh_index,
736  FUNCTOR &functor) const;
737 
738  int minimum(
739  const GEO_Detail &geo,
740  const UT_Vector3 &p,
741  GU_MinInfo &mininfo) override;
742 
743  int64 getMemoryUsage(bool inclusive) const override;
744 
745 public:
746  int myAxis, myA1, myA2;
747  int myDim[3];
749  bool myFailed;
750  float myScale, myInvScale;
754 };
755 
756 //________________________________________________________
757 //
758 // Packed primitive intersection class
759 //________________________________________________________
760 
762 {
763 public:
764  GU_RayPackedInfo(GEO_ConstPrimitiveP prim, int serialidx, int picking,
765  int polyline, int harden, bool solidtet);
766  ~GU_RayPackedInfo() override;
767 
768  void init(const GEO_Detail &geo) override;
769 
770  int intersect(
771  const GEO_Detail &geo,
772  const UT_Vector3 &org,
773  const UT_Vector3 &dir,
774  GU_RayInfo &hitinfo) override;
775  int minimum(
776  const GEO_Detail &geo,
777  const UT_Vector3 &p,
778  GU_MinInfo &mininfo) override;
779 
780  int64 getMemoryUsage(bool inclusive) const override;
781 
782  void unpack(const GEO_Detail &geo);
783 
784 private:
785  const int myPicking;
786  const int myPolyLine;
787  const int myHarden;
788  const int mySolidTet;
789 
790  UT_UniquePtr<GEO_Detail> myUnpackedGdp;
791  UT_UniquePtr<GU_RayIntersect> myUnpackedIntersect;
792 };
793 
794 //________________________________________________________
795 //
796 // Polyline intersection class
797 //________________________________________________________
798 //
800 {
801 public:
803  GEO_ConstPrimitiveP prim,
804  int serialidx,
805  int span, int len);
806  ~GU_RayPolyLineInfo() override;
807 
808  int intersect(
809  const GEO_Detail &geo,
810  const UT_Vector3 &org,
811  const UT_Vector3 &dir,
812  GU_RayInfo &hitinfo) override;
813  int minimum(
814  const GEO_Detail &geo,
815  const UT_Vector3 &p,
816  GU_MinInfo &mininfo) override;
817  int intersectPrim(
818  const GEO_Detail &geo,
819  const GEO_Detail &prim_geo,
820  GU_RayPrimInfo *prim,
821  GU_RayInfo &hitInfo) override;
822  int minimumPrim(
823  const GEO_Detail &geo,
824  const GEO_Detail &prim_geo,
825  GU_RayPrimInfo *prim,
826  GU_MinInfo &mininfo) override;
827 
828  int64 getMemoryUsage(bool inclusive) const override
829  {
830  int64 mem = inclusive ? sizeof(*this) : 0;
831  return mem;
832  }
833 
834 public:
835  int mySpan; // What part of the poly
836  int myLen; // we are responsible for
837 };
838 
839 //________________________________________________________
840 //
841 // Curve intersection class
842 //
843 // Note: working in homogeneous coordinate
844 //________________________________________________________
845 //
846 
848 {
849 public:
851  GEO_ConstPrimitiveP curve,
852  int serialidx,
853  bool is_first_span,
854  bool is_last_span)
855  : GU_RayPrimInfo(curve, serialidx)
856  , myFirstSpanFlag(is_first_span)
857  , myLastSpanFlag(is_last_span)
858  {
859  }
860  ~GU_RayCurveInfo() override {}
861 
862 protected:
863  // checks the proximity of the ray to the end points of the curve,
864  // and compares it with the tolerance given in hit_info,
865  // but only for these endpoints
866  // of the curve for which first/last span flags (the member data) are true.
867  // If ray passes within the given tolerance, in the hemispherical cup
868  // at the end of the curve, that "seals" the cylidrical zone around
869  // the curve, it is considered as a hit, and 1 is returned.
870  // INPUTS:
871  // org, dir - the origin and direction of the ray
872  // curve - the curve endpoints we investigate
873  // hit_info - its tolerance is treated as a radius of a hemisphere at the
874  // endpoints, within which to test the ray's presence
875  // OUTPUT
876  // hit_info - if hit, a hit is added
877  // RETURN:
878  // 1 if hit: ray passes within tolerance radius of endpoint(s), otherwise 0
879  int intersectEndPointZone(
880  const GEO_Detail &geo,
881  const UT_Vector3 &org,
882  const UT_Vector3 &dir,
883  const GU_RayRBezCurve* curve,
884  GU_RayInfo &hit_info) const;
885 
886 public:
887  // usually a curve primitive is subdivided into several spans, whose
888  // info is encoded in GU_RayRBezCurveInfo and GU_RayNURBCurveInfo.
889  // Following flags indicate if this span is first or last on the curve.
890  bool myFirstSpanFlag : 1, // 1 if it's firsrt span on curve
891  myLastSpanFlag : 1; // 1 if it's last span on curve
892 };
893 
894 class GEO_PrimRBezCurve;
895 
897 {
898 public:
900  const GEO_PrimRBezCurve *curve,
901  int serialidx,
902  bool is_first_span,
903  bool is_last_span,
904  int span,
905  int nvtx,
906  int ord);
907  ~GU_RayRBezCurveInfo() override;
908 
909  static int count(const GEO_PrimRBezCurve *bezcurve)
910  {
911  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
912  return knots.size() - 1;
913  }
914  template<typename FUNCTOR>
915  static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
916  {
917  const int ord = bezcurve->getOrder();
918  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
919  const int last = knots.size() - 2;
920  const int s = bezcurve->getVertexCount();
921 
922  for (int j = last; j >= 0; --j)
923  {
924  const bool is_first = (j == 0);
925  const bool is_last = (j == last);
926  functor(new GU_RayRBezCurveInfo(bezcurve, (pinfonum ? *pinfonum : 0),
927  is_first, is_last, j, s, ord));
928  if (pinfonum)
929  ++(*pinfonum);
930  }
931  }
932 
933  int intersect(
934  const GEO_Detail &geo,
935  const UT_Vector3 &org,
936  const UT_Vector3 &dir,
937  GU_RayInfo &hitinfo) override;
938  int minimum(
939  const GEO_Detail &geo,
940  const UT_Vector3 &p,
941  GU_MinInfo &mininfo) override;
942  int intersectPrim(
943  const GEO_Detail &geo,
944  const GEO_Detail &prim_geo,
945  GU_RayPrimInfo *prim,
946  GU_RayInfo &hitInfo) override;
947  int minimumPrim(
948  const GEO_Detail &geo,
949  const GEO_Detail &prim_geo,
950  GU_RayPrimInfo *prim,
951  GU_MinInfo &mininfo) override;
952 
953  void init(const GEO_Detail &geo) override;
954  GU_RayRBezCurve *buildCurve(const GEO_Detail &geo);
955 
956  int64 getMemoryUsage(bool inclusive) const override
957  {
958  int64 mem = inclusive ? sizeof(*this) : 0;
959  if (myCurve)
960  mem += myCurve->getMemoryUsage(true);
961  return mem;
962  }
963 
964 public:
965  int mySpan;
967 };
968 
970 {
971 public:
973  GEO_ConstPrimitiveP curve,
974  int serialidx,
975  UT_Interval u,
976  const UT_RefMatrix<UT_Vector4> &patch_cv,
977  int ord,
978  bool is_rational);
979  ~GU_RayNURBCurveInfo() override;
980 
981  template<typename FUNCTOR>
982  static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
983  {
984  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbcurve->getBasis();
985  const int ord = ub->getOrder();
986  GA_PwHandleRO h(nurbcurve->getDetail());
987  GU_NURBPyramid<0> pyramid(ub, nurbcurve, h);
988  const bool rational = nurbcurve->isRational();
989 
990  bool first = true;
991  for (pyramid.rewind(ub); !pyramid.atEnd(); pyramid.advance())
992  {
993  GU_RayNURBCurveInfo *nurbcurveinfo = new GU_RayNURBCurveInfo(
994  nurbcurve, (pinfonum ? *pinfonum : 0),
995  pyramid.getInterval(), pyramid.getResult(),
996  ord, rational);
997  nurbcurveinfo->myFirstSpanFlag = first;
998  functor(nurbcurveinfo);
999 
1000  if (pinfonum)
1001  ++(*pinfonum);
1002 
1003  first = false;
1004  }
1005  }
1006 
1007  int intersect(
1008  const GEO_Detail &geo,
1009  const UT_Vector3 &org,
1010  const UT_Vector3 &dir,
1011  GU_RayInfo &hitinfo) override;
1012  int minimum(
1013  const GEO_Detail &geo,
1014  const UT_Vector3 &p,
1015  GU_MinInfo &mininfo) override;
1016  int intersectPrim(
1017  const GEO_Detail &geo,
1018  const GEO_Detail &prim_geo,
1019  GU_RayPrimInfo *prim,
1020  GU_RayInfo &hitInfo) override;
1021  int minimumPrim(
1022  const GEO_Detail &geo,
1023  const GEO_Detail &prim_geo,
1024  GU_RayPrimInfo *prim,
1025  GU_MinInfo &mininfo) override;
1026 
1027  int64 getMemoryUsage(bool inclusive) const override
1028  {
1029  int64 mem = inclusive ? sizeof(*this) : 0;
1030  mem += myCurve.getMemoryUsage(false);
1031  return mem;
1032  }
1033 
1034 public:
1036 };
1037 
1038 
1039 //________________________________________________________
1040 //
1041 // Surface intersection class
1042 //
1043 // Note: working in homogeneous coordinate
1044 //________________________________________________________
1045 //
1047 {
1048 public:
1050  const GEO_PrimRBezSurf *surf, int serialidx,
1051  int u_span, int v_span,
1052  int u_ord, int v_ord,
1053  float u_start, float u_length,
1054  float v_start, float v_length,
1055  int u_beg, int v_beg,
1056  int u_num, int v_num,
1057  bool is_rational);
1058  ~GU_RayRBezSurfInfo() override;
1059 
1060  static exint count(const GEO_PrimRBezSurf *bezsurf)
1061  {
1062  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1063  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1064  return exint(vknots.size()-1)*(uknots.size()-1);
1065  }
1066 
1067  template<typename FUNCTOR>
1068  static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
1069  {
1070  const int uord = bezsurf->getUOrder();
1071  const int vord = bezsurf->getVOrder();
1072  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1073  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1074  const int cols = bezsurf->getNumCols();
1075  const int rows = bezsurf->getNumRows();
1076  const bool rational = bezsurf->isRational();
1077 
1078  for (int r = vknots.size()-2; r >= 0; r--)
1079  {
1080  const int r1 = (vord-1)*r;
1081  for (int c = uknots.size()-2; c >= 0; c--)
1082  {
1083  const int c1 = (uord-1)*c;
1084  functor(new GU_RayRBezSurfInfo(
1085  bezsurf, (pinfonum ? *pinfonum : 0),
1086  c, r,
1087  uord, vord,
1088  uknots(c), uknots(c+1)-uknots(c),
1089  vknots(r), vknots(r+1)-vknots(r),
1090  c1, r1,
1091  cols, rows,
1092  rational));
1093 
1094  if (pinfonum)
1095  ++(*pinfonum);
1096  }
1097  }
1098  }
1099 
1100  int intersect(
1101  const GEO_Detail &geo,
1102  const UT_Vector3 &org,
1103  const UT_Vector3 &dir,
1104  GU_RayInfo &hitinfo) override;
1105  int minimum(
1106  const GEO_Detail &geo,
1107  const UT_Vector3 &p,
1108  GU_MinInfo &mininfo) override;
1109 
1110  int intersectPrim(
1111  const GEO_Detail &geo,
1112  const GEO_Detail &prim_geo,
1113  GU_RayPrimInfo *prim,
1114  GU_RayInfo &hitinfo) override;
1115  int minimumPrim(
1116  const GEO_Detail &geo,
1117  const GEO_Detail &prim_geo,
1118  GU_RayPrimInfo *prim,
1119  GU_MinInfo &hitinfo) override;
1120 
1121  void init(const GEO_Detail &geo) override;
1122  virtual GU_RayRBezSurf *buildSurf(const GEO_Detail &geo);
1123 
1124  int64 getMemoryUsage(bool inclusive) const override
1125  {
1126  int64 mem = inclusive ? sizeof(*this) : 0;
1127  if (mySurf)
1128  mem += mySurf->getMemoryUsage(true);
1129  return mem;
1130  }
1131 
1132 public:
1133  int myUSpan, myVSpan;
1135 };
1136 
1138 {
1139 public:
1141  GEO_ConstPrimitiveP surf, int serialidx,
1142  int u_ord, int v_ord,
1144  const UT_RefMatrix<UT_Vector4> &patch_cv,
1145  bool is_rational);
1146  ~GU_RayNURBSurfInfo() override;
1147 
1148  template<typename FUNCTOR>
1149  static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
1150  {
1151  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbsurf->getUBasis();
1152  const GA_NUBBasis *vb = (const GA_NUBBasis *)nurbsurf->getVBasis();
1153  const int uOrd = ub->getOrder();
1154  const int vOrd = vb->getOrder();
1155  GA_PwHandleRO h(nurbsurf->getDetail());
1156  GU_NURBPyramid<0> uPyramid(ub, nurbsurf, h);
1157  GU_NURBPyramid<1> vPyramid(vb, &uPyramid.getResult());
1158  const bool rational = nurbsurf->isRational();
1159 
1160  for (uPyramid.rewind(ub); !uPyramid.atEnd(); uPyramid.advance())
1161  {
1162  const UT_Interval &u = uPyramid.getInterval();
1163  for (vPyramid.rewind(vb); !vPyramid.atEnd(); vPyramid.advance())
1164  {
1165  functor(new GU_RayNURBSurfInfo(nurbsurf,
1166  (pinfonum ? *pinfonum : 0),
1167  uOrd, vOrd,
1168  u, vPyramid.getInterval(),
1169  vPyramid.getResult(),
1170  rational));
1171 
1172  if (pinfonum)
1173  ++(*pinfonum);
1174  }
1175  }
1176  }
1177 
1178  int intersect(
1179  const GEO_Detail &geo,
1180  const UT_Vector3 &org,
1181  const UT_Vector3 &dir,
1182  GU_RayInfo &hitinfo) override;
1183  int minimum(
1184  const GEO_Detail &geo,
1185  const UT_Vector3 &p,
1186  GU_MinInfo &mininfo) override;
1187  int intersectPrim(
1188  const GEO_Detail &geo,
1189  const GEO_Detail &prim_geo,
1190  GU_RayPrimInfo *prim,
1191  GU_RayInfo &hitinfo) override;
1192  int minimumPrim(
1193  const GEO_Detail &geo,
1194  const GEO_Detail &prim_geo,
1195  GU_RayPrimInfo *prim,
1196  GU_MinInfo &hitinfo) override;
1197 
1198  int64 getMemoryUsage(bool inclusive) const override
1199  {
1200  int64 mem = inclusive ? sizeof(*this) : 0;
1201  mem += mySurf.getMemoryUsage(false);
1202  return mem;
1203  }
1204 
1205 public:
1207 };
1208 
1209 //___________________________________________________________________________
1210 //
1211 // Moving triangle ray intersection classes
1212 // - HTriangle is for hardened points
1213 //___________________________________________________________________________
1214 //
1216 {
1217 public:
1219  GEO_ConstPrimitiveP prim0, int serialidx,
1220  GA_Offset p00, GA_Offset p01,
1221  GA_Offset p02,
1222  GEO_ConstPrimitiveP prim1,
1223  GA_Offset p10, GA_Offset p11,
1224  GA_Offset p12);
1225  ~GU_RayMovingTriangleInfo() override;
1226 
1227  void init(const GEO_Detail &geo) override;
1228 
1229  int intersect(
1230  const GEO_Detail &geo,
1231  const UT_Vector3 &org,
1232  const UT_Vector3 &dir,
1233  GU_RayInfo &hitinfo) override;
1234 
1235  int64 getMemoryUsage(bool inclusive) const override
1236  {
1237  int64 mem = inclusive ? sizeof(*this) : 0;
1238  return mem;
1239  }
1240 
1241 private:
1242  int insertHit(
1243  const GEO_Detail &geo,
1244  const UT_Vector3 &org,
1245  const UT_Vector3 &dir,
1246  GU_RayInfo &hitinfo,
1247  float t,
1248  float nt);
1249 
1250 public:
1252  GA_Offset myV0[3]; // Three corner vertices at t = 0
1253  GA_Offset myV1[3]; // Three corner vertices at t = 1
1254 
1255  double a2, a1, a0; // Coefficients of x comp of normal
1256  double b2, b1, b0; // Coefficients of y comp of normal
1257  double c2, c1, c0; // Coefficients of z comp of normal
1258 };
1259 
1260 
1261 #endif
GLenum query
Definition: glad.h:2772
GLint first
Definition: glcorearb.h:405
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
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
const UT_Array< GA_Offset > pts
const GLdouble * v
Definition: glcorearb.h:837
virtual int minimum(const GEO_Detail &geo, const UT_Vector3 &p, GU_MinInfo &mininfo)
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:73
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)
GLdouble s
Definition: glad.h:3009
GEO_PrimVolumeXform myXform
GU_RayCurveInfo(GEO_ConstPrimitiveP curve, int serialidx, bool is_first_span, bool is_last_span)
GLint y
Definition: glcorearb.h:103
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
UT_VDBType
Definition: UT_VDBUtils.h:11
unsigned getVOrder() const
Definition: GEO_TPSurf.h:389
float tscale
exint size() const
Definition: UT_Array.h:646
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:39
static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GA_Size GA_Offset
Definition: GA_Types.h:646
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)
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
UT_Vector3 org
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.
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
SYS_FORCE_INLINE int getNumRows() const
Definition: GEO_Hull.h:368
GEO_ConstPrimitiveP myPrim2
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GA_PrimitiveP_T< const GEO_Primitive, const GEO_Detail > GEO_ConstPrimitiveP
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
const float myW
#define GU_API
Definition: GU_API.h:14
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
GLint GLenum GLint x
Definition: glcorearb.h:409
const UT_VoxelArrayF * mySamples
GLdouble t
Definition: glad.h:2397
SYS_FORCE_INLINE GEO_ConstPrimitiveP primP(const GEO_Detail &geo) const
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
GEO_PrimVolumeXform myXform
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
const GA_Basis * getBasis() const
Definition: GEO_Curve.h:310
UT_VoxelMipMapF myMinMM
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GLint j
Definition: glad.h:2733
__hostdev__ uint64_t last(uint32_t i) const
Definition: NanoVDB.h:5976
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
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.
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GU_API UT_Vector3 GUfindPointInsideTet(float dots[4], const float A[4]) noexcept
FloatPtrArray xval
const GA_KnotVector & getVector() const
Definition: GA_Basis.h:372
unsigned getOrder() const override
~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.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
SYS_FORCE_INLINE int getNumCols() const
Definition: GEO_Hull.h:375
UT_ThreadSpecificValue< void * > myCache
int64 getMemoryUsage(bool inclusive) const override
Report approximate memory usage.
GU_RayRBezCurve myCurve
GLboolean r
Definition: glcorearb.h:1222
static exint count(const GEO_PrimRBezSurf *bezsurf)
unsigned getUOrder() const
Definition: GEO_TPSurf.h:388
SYS_AtomicCounter refCount
unsigned int uint
Definition: SYS_Types.h:45
GA_Basis * getUBasis() const
Definition: GEO_TPSurf.h:384
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
GA_Basis * getVBasis() const
Definition: GEO_TPSurf.h:385
UT_Vector3 getNormal(const UT_Vector3 &uvw) const override