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  static int plane(
208  GEO_ConstPrimitiveP prim,
209  const GU_Ray &ray,
210  GU_RayInfo &hi,
211  UT_Vector3 &nml);
212 
213  static void minCircle(const UT_Vector3 &p, UT_Vector3 &minpt);
214  static void minSphere(const UT_Vector3 &p, UT_Vector3 &minpt);
215  static void minPlane(const UT_Vector3 &p, UT_Vector3 &minpt);
216  static void minTube(
217  GEO_ConstPrimitiveP prim,
218  const UT_Vector3 &p,
219  UT_Vector3 &minpt,
220  float &u,
221  float &v);
222 
223  UT_Matrix4 xform; // Ray transform
224  UT_Matrix3 nmlXform; // Normal transform
225 };
226 
227 //________________________________________________________
228 //
229 // Triangle ray intersection class
230 //________________________________________________________
231 //
232 template<bool ISTET=false>
234 {
235 public:
236  GU_RayTriangleInfo(GEO_ConstPrimitiveP prim, int serialidx,
237  GA_Offset p0, GA_Offset p1,
238  GA_Offset p2, float w=0.0f);
239  ~GU_RayTriangleInfo() override;
240 
241  void init(const GEO_Detail &geo) override;
242 
243  int intersect(
244  const GEO_Detail &geo,
245  const UT_Vector3 &org,
246  const UT_Vector3 &dir,
247  GU_RayInfo &hitinfo) override;
248  int minimum(
249  const GEO_Detail &geo,
250  const UT_Vector3 &p,
251  GU_MinInfo &mininfo) override;
252 
253  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
254  {
255  return nml;
256  }
257 
258  int64 getMemoryUsage(bool inclusive) const override
259  {
260  int64 mem = inclusive ? sizeof(*this) : 0;
261  return mem;
262  }
263 
264 public:
265  GA_Offset myV[3]; // Three corner vertices
266  UT_Vector3 nml; // Surface normal
267  float D; // Plane eqn constant
268  int x, y; // Oriented to projected plane
269  const float myW;
270 };
271 
272 // These are hardened triangles:
273 template<bool ISTET=false>
275 {
276 public:
277  GU_RayHTriangleInfo(GEO_ConstPrimitiveP prim, int serialidx,
278  const UT_Vector3 &p1, const UT_Vector3 &p2,
279  const UT_Vector3 &p3, float w=0.0f);
280  ~GU_RayHTriangleInfo() override;
281 
282  void init(const GEO_Detail &geo) override;
283 
284  int intersect(
285  const GEO_Detail &geo,
286  const UT_Vector3 &org,
287  const UT_Vector3 &dir,
288  GU_RayInfo &hitinfo) override;
289  int minimum(
290  const GEO_Detail &geo,
291  const UT_Vector3 &p,
292  GU_MinInfo &mininfo) override;
293 
294  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
295  {
296  return nml;
297  }
298 
299  int64 getMemoryUsage(bool inclusive) const override
300  {
301  int64 mem = inclusive ? sizeof(*this) : 0;
302  return mem;
303  }
304 
305 public:
306  UT_Vector3 myV[3]; // Three corner verices
307  UT_Vector3 nml; // Surface normal
308  float D; // Plane eqn constant
309  int x, y; // Oriented to projected plane
310  const float myW;
311 };
312 
313 //________________________________________________________
314 //
315 // Tetrahedron ray intersection class
316 //________________________________________________________
317 //
318 
319 /// Checks if query is inside the tet specified by ps.
320 /// If the tet is inverted and it's inside, negated will be set to true.
321 /// It computes normals, areas, and sub tet volumes already, so that they
322 /// can be used afterward.
323 GU_API bool
325  const UT_Vector3 &query,
326  const UT_Vector3 *ps,
327  UT_Vector3 n[4],
328  bool &negated,
329  float dots[4],
330  float A[4]) noexcept;
331 
332 /// Computes the uvw coordinates of a query point inside a tet, based on
333 /// the values computed by GUisPointInsideTet.
336  float dots[4],
337  const float A[4]) noexcept;
338 
340 {
341 public:
342  GU_RayTetInfo(GEO_ConstPrimitiveP prim, int serialidx,
343  GA_Offset p0, GA_Offset p1,
344  GA_Offset p2, GA_Offset p3);
345  ~GU_RayTetInfo() override;
346 
347  int intersect(
348  const GEO_Detail &geo,
349  const UT_Vector3 &org,
350  const UT_Vector3 &dir,
351  GU_RayInfo &hitinfo) override;
352  int minimum(
353  const GEO_Detail &geo,
354  const UT_Vector3 &p,
355  GU_MinInfo &mininfo) override;
356 
357  int64 getMemoryUsage(bool inclusive) const override
358  {
359  int64 mem = inclusive ? sizeof(*this) : 0;
360  return mem;
361  }
362 
363 public:
364  GA_Offset myV[4]; // Four corner vertices
365 };
366 
367 // These are hardened triangles:
369 {
370 public:
371  GU_RayHTetInfo(GEO_ConstPrimitiveP prim, int serialidx,
372  const UT_Vector3 &p1, const UT_Vector3 &p2,
373  const UT_Vector3 &p3, const UT_Vector3 &p4);
374  ~GU_RayHTetInfo() override;
375 
376  int intersect(
377  const GEO_Detail &geo,
378  const UT_Vector3 &org,
379  const UT_Vector3 &dir,
380  GU_RayInfo &hitinfo) override;
381  int minimum(
382  const GEO_Detail &geo,
383  const UT_Vector3 &p,
384  GU_MinInfo &mininfo) override;
385 
386  int64 getMemoryUsage(bool inclusive) const override
387  {
388  int64 mem = inclusive ? sizeof(*this) : 0;
389  return mem;
390  }
391 
392 public:
393  UT_Vector3 myV[4]; // Four corner verices
394 };
395 
396 //________________________________________________________
397 //
398 // Hexahedron ray intersection class
399 //________________________________________________________
400 //
401 
403 {
404 public:
405  GU_RayHexInfo(GEO_ConstPrimitiveP prim, int serialidx,
406  GA_Offset p0, GA_Offset p1,
407  GA_Offset p2, GA_Offset p3,
408  GA_Offset p4, GA_Offset p5,
409  GA_Offset p6, GA_Offset p7);
410  ~GU_RayHexInfo() override;
411 
412  int intersect(
413  const GEO_Detail &geo,
414  const UT_Vector3 &org,
415  const UT_Vector3 &dir,
416  GU_RayInfo &hitinfo) override;
417  int minimum(
418  const GEO_Detail &geo,
419  const UT_Vector3 &p,
420  GU_MinInfo &mininfo) override;
421 
422  int64 getMemoryUsage(bool inclusive) const override
423  {
424  int64 mem = inclusive ? sizeof(*this) : 0;
425  return mem;
426  }
427 
428 public:
429  GA_Offset myV[8]; // Eight corner vertices
430 };
431 
432 // These are hardened hexahedra:
434 {
435 public:
436  GU_RayHHexInfo(GEO_ConstPrimitiveP prim, int serialidx,
437  const UT_Vector3 &p1, const UT_Vector3 &p2,
438  const UT_Vector3 &p3, const UT_Vector3 &p4,
439  const UT_Vector3 &p5, const UT_Vector3 &p6,
440  const UT_Vector3 &p7, const UT_Vector3 &p8);
441  ~GU_RayHHexInfo() override;
442 
443  int intersect(
444  const GEO_Detail &geo,
445  const UT_Vector3 &org,
446  const UT_Vector3 &dir,
447  GU_RayInfo &hitinfo) override;
448  int minimum(
449  const GEO_Detail &geo,
450  const UT_Vector3 &p,
451  GU_MinInfo &mininfo) override;
452 
453  int64 getMemoryUsage(bool inclusive) const override
454  {
455  int64 mem = inclusive ? sizeof(*this) : 0;
456  return mem;
457  }
458 
459 public:
460  UT_Vector3 myV[8]; // Eight corner vertices
461 };
462 
463 
464 //___________________________________________________________________________
465 //
466 // Quad ray intersection classes - HQuad is for hardened points (i.e. NURBS)
467 //___________________________________________________________________________
468 //
469 template<bool ISHEX=false>
471 {
472 public:
473  GU_RayQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
474  GA_Offset p0, GA_Offset p1,
475  GA_Offset p2, GA_Offset p3,
476  float ustart = 0.0F, float ulength = 1.0F,
477  float vstart = 0.0F, float vlength = 1.0F,
478  bool revml = false, float w=0.0f);
479  ~GU_RayQuadInfo() override;
480 
481  void init(const GEO_Detail &geo) override;
482 
483  int intersect(
484  const GEO_Detail &geo,
485  const UT_Vector3 &org,
486  const UT_Vector3 &dir,
487  GU_RayInfo &hitinfo) override;
488  int minimum(
489  const GEO_Detail &geo,
490  const UT_Vector3 &p,
491  GU_MinInfo &mininfo) override;
492 
493  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
494  {
495  return nml;
496  }
497 
498  int64 getMemoryUsage(bool inclusive) const override
499  {
500  int64 mem = inclusive ? sizeof(*this) : 0;
501  return mem;
502  }
503 
504 public:
505  GA_Offset myV[4]; // Four corner vertices
506  UT_Vector3 nml; // Surface normal
507  bool myRevNml; // Do we reverse the normal?
508 
509  //float D; // Plane eqn constant
510  //int x, y; // Oriented to projected plane
511  float myUStart, myULength;
512  float myVStart, myVLength;
513  const float myW;
514 };
515 
516 template<bool ISHEX=false>
518 {
519 public:
520  GU_RayHQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
521  const UT_Vector3 &p0, const UT_Vector3 &p1,
522  const UT_Vector3 &p2, const UT_Vector3 &p3,
523  float ustart = 0.0f, float ulen = 1.0f,
524  float vstart = 0.0f, float vlen = 1.0f,
525  bool revnml = false, float w=0.0f);
526  ~GU_RayHQuadInfo() override;
527 
528  void init(const GEO_Detail &geo) override;
529 
530  int intersect(
531  const GEO_Detail &geo,
532  const UT_Vector3 &org,
533  const UT_Vector3 &dir,
534  GU_RayInfo &hitinfo) override;
535  int minimum(
536  const GEO_Detail &geo,
537  const UT_Vector3 &p,
538  GU_MinInfo &mininfo) override;
539 
540  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
541  {
542  return nml;
543  }
544 
545  int64 getMemoryUsage(bool inclusive) const override
546  {
547  int64 mem = inclusive ? sizeof(*this) : 0;
548  return mem;
549  }
550 
551 public:
552  UT_Vector3 myV[4]; // Four corner vertices
553  UT_Vector3 nml; // Surface normal
554  bool myRevNml; // Do we reverse the normal?
555 
556  // These numbers aren't needed by the bilinear code.
557  //float D; // Plane eqn constant
558  //int x, y; // Oriented to projected plane
559 
560  float myUStart, myULength;
561  float myVStart, myVLength;
562  const float myW;
563 };
564 
565 
566 //________________________________________________________
567 //
568 // General Face ray intersection class
569 //________________________________________________________
570 //
572 {
573 public:
574  GU_RayPolyInfo(GEO_ConstPrimitiveP prim, int serialidx,
575  const UT_Array<GA_Offset> &ipts, float w=0.0f);
576  ~GU_RayPolyInfo() override;
577 
578  int intersect(
579  const GEO_Detail &geo,
580  const UT_Vector3 &org,
581  const UT_Vector3 &dir,
582  GU_RayInfo &hitinfo) override;
583  int minimum(
584  const GEO_Detail &geo,
585  const UT_Vector3 &p,
586  GU_MinInfo &mininfo) override;
587 
588  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
589  {
590  return nml;
591  }
592 
593  int64 getMemoryUsage(bool inclusive) const override
594  {
595  int64 mem = inclusive ? sizeof(*this) : 0;
596  return mem;
597  }
598 
599 public:
601  float D;
602  int x, y;
604  const float myW;
605 };
606 
608 {
609 public:
611  GEO_ConstPrimitiveP prim,
612  int serialidx,
613  const UT_Vector4Array &p,
614  float w = 0.0f);
616  GEO_ConstPrimitiveP prim,
617  int serialidx,
618  const UT_Array<UT_Vector3> &p,
619  float w = 0.0f);
620  ~GU_RayHPolyInfo() override;
621 
622  template<typename ARRAY_TYPE>
623  void initPoly(GEO_ConstPrimitiveP p, const ARRAY_TYPE &pts);
624  int intersect(
625  const GEO_Detail &geo,
626  const UT_Vector3 &org,
627  const UT_Vector3 &dir,
628  GU_RayInfo &hitinfo) override;
629  int minimum(
630  const GEO_Detail &geo,
631  const UT_Vector3 &p,
632  GU_MinInfo &mininfo) override;
633 
634  UT_Vector3 getNormal(const UT_Vector3 &uvw) const override
635  {
636  return nml;
637  }
638 
639  int64 getMemoryUsage(bool inclusive) const override
640  {
641  int64 mem = inclusive ? sizeof(*this) : 0;
642  if (xval)
643  mem += npts * sizeof(xval[0]);
644  if (yval)
645  mem += npts * sizeof(yval[0]);
646  return mem;
647  }
648 
649 public:
651 
652  int npts;
656  float D;
657  int x, y;
658  const float myW;
659 };
660 
661 //________________________________________________________
662 //
663 // Meta-surface ray intersection class
664 //________________________________________________________
665 //
667 {
668 public:
669  GU_RayMetaInfo(const TS_MetaExpressionPtr &expr, int serialidx);
670  ~GU_RayMetaInfo() override;
671 
672  int intersect(
673  const GEO_Detail &geo,
674  const UT_Vector3 &org,
675  const UT_Vector3 &dir,
676  GU_RayInfo &hitinfo) override;
677 
678  int64 getMemoryUsage(bool inclusive) const override;
679 
680 public:
683 };
684 
685 //________________________________________________________
686 //
687 // VDB intersection class
688 //________________________________________________________
690 {
691 public:
692  GU_RayVDBInfo(GEO_ConstPrimitiveP vdb, int serialidx);
693  ~GU_RayVDBInfo() override;
694 
695  int intersect(
696  const GEO_Detail &geo,
697  const UT_Vector3 &org,
698  const UT_Vector3 &dir,
699  GU_RayInfo &hitinfo) override;
700 
701  int64 getMemoryUsage(bool inclusive) const override;
702 
703 public:
705  float myStepSize;
707  bool myFailed;
709 #ifdef OPENVDB_ENABLED
710  const openvdb::GridBase *myGridRawPtr;
711 #endif
712 
713 };
714 
715 //________________________________________________________
716 //
717 // HeightField intersection class
718 //________________________________________________________
720 {
721 public:
722  GU_RayHeightFieldInfo(const GEO_PrimVolume *vdb, int serialidx);
723  ~GU_RayHeightFieldInfo() override;
724 
725  int intersect(
726  const GEO_Detail &geo,
727  const UT_Vector3 &org,
728  const UT_Vector3 &dir,
729  GU_RayInfo &hitinfo) override;
730 
731  template<bool farthest,bool rm_backface,bool reverse,bool bidirectional,typename FUNCTOR>
732  bool intersect(
733  const UT_Vector3 &org,
734  const UT_Vector3 &dir,
735  const UT_Vector3 &inverse_dir,
736  int max_dir,
737  const UT_Vector3 &N0,
738  const UT_Vector3 &N1,
739  float &outer_tmin,
740  float &outer_tmax,
741  uint bvh_index,
742  FUNCTOR &functor) const;
743 
744  int minimum(
745  const GEO_Detail &geo,
746  const UT_Vector3 &p,
747  GU_MinInfo &mininfo) override;
748 
749  int64 getMemoryUsage(bool inclusive) const override;
750 
751 public:
752  int myAxis, myA1, myA2;
753  int myDim[3];
755  bool myFailed;
756  float myScale, myInvScale;
760 };
761 
762 //________________________________________________________
763 //
764 // Packed primitive intersection class
765 //________________________________________________________
766 
768 {
769 public:
770  GU_RayPackedInfo(GEO_ConstPrimitiveP prim, int serialidx, int picking,
771  int polyline, int harden, bool solidtet);
772  ~GU_RayPackedInfo() override;
773 
774  void init(const GEO_Detail &geo) override;
775 
776  int intersect(
777  const GEO_Detail &geo,
778  const UT_Vector3 &org,
779  const UT_Vector3 &dir,
780  GU_RayInfo &hitinfo) override;
781  int minimum(
782  const GEO_Detail &geo,
783  const UT_Vector3 &p,
784  GU_MinInfo &mininfo) override;
785 
786  int64 getMemoryUsage(bool inclusive) const override;
787 
788  void unpack(const GEO_Detail &geo);
789 
790 private:
791  const int myPicking;
792  const int myPolyLine;
793  const int myHarden;
794  const int mySolidTet;
795 
796  UT_UniquePtr<GEO_Detail> myUnpackedGdp;
797  UT_UniquePtr<GU_RayIntersect> myUnpackedIntersect;
798 };
799 
800 //________________________________________________________
801 //
802 // Polyline intersection class
803 //________________________________________________________
804 //
806 {
807 public:
809  GEO_ConstPrimitiveP prim,
810  int serialidx,
811  int span, int len);
812  ~GU_RayPolyLineInfo() override;
813 
814  int intersect(
815  const GEO_Detail &geo,
816  const UT_Vector3 &org,
817  const UT_Vector3 &dir,
818  GU_RayInfo &hitinfo) override;
819  int minimum(
820  const GEO_Detail &geo,
821  const UT_Vector3 &p,
822  GU_MinInfo &mininfo) override;
823  int intersectPrim(
824  const GEO_Detail &geo,
825  const GEO_Detail &prim_geo,
826  GU_RayPrimInfo *prim,
827  GU_RayInfo &hitInfo) override;
828  int minimumPrim(
829  const GEO_Detail &geo,
830  const GEO_Detail &prim_geo,
831  GU_RayPrimInfo *prim,
832  GU_MinInfo &mininfo) override;
833 
834  int64 getMemoryUsage(bool inclusive) const override
835  {
836  int64 mem = inclusive ? sizeof(*this) : 0;
837  return mem;
838  }
839 
840 public:
841  int mySpan; // What part of the poly
842  int myLen; // we are responsible for
843 };
844 
845 //________________________________________________________
846 //
847 // Curve intersection class
848 //
849 // Note: working in homogeneous coordinate
850 //________________________________________________________
851 //
852 
854 {
855 public:
857  GEO_ConstPrimitiveP curve,
858  int serialidx,
859  bool is_first_span,
860  bool is_last_span)
861  : GU_RayPrimInfo(curve, serialidx)
862  , myFirstSpanFlag(is_first_span)
863  , myLastSpanFlag(is_last_span)
864  {
865  }
866  ~GU_RayCurveInfo() override {}
867 
868 protected:
869  // checks the proximity of the ray to the end points of the curve,
870  // and compares it with the tolerance given in hit_info,
871  // but only for these endpoints
872  // of the curve for which first/last span flags (the member data) are true.
873  // If ray passes within the given tolerance, in the hemispherical cup
874  // at the end of the curve, that "seals" the cylidrical zone around
875  // the curve, it is considered as a hit, and 1 is returned.
876  // INPUTS:
877  // org, dir - the origin and direction of the ray
878  // curve - the curve endpoints we investigate
879  // hit_info - its tolerance is treated as a radius of a hemisphere at the
880  // endpoints, within which to test the ray's presence
881  // OUTPUT
882  // hit_info - if hit, a hit is added
883  // RETURN:
884  // 1 if hit: ray passes within tolerance radius of endpoint(s), otherwise 0
885  int intersectEndPointZone(
886  const GEO_Detail &geo,
887  const UT_Vector3 &org,
888  const UT_Vector3 &dir,
889  const GU_RayRBezCurve* curve,
890  GU_RayInfo &hit_info) const;
891 
892 public:
893  // usually a curve primitive is subdivided into several spans, whose
894  // info is encoded in GU_RayRBezCurveInfo and GU_RayNURBCurveInfo.
895  // Following flags indicate if this span is first or last on the curve.
896  bool myFirstSpanFlag : 1, // 1 if it's firsrt span on curve
897  myLastSpanFlag : 1; // 1 if it's last span on curve
898 };
899 
900 class GEO_PrimRBezCurve;
901 
903 {
904 public:
906  const GEO_PrimRBezCurve *curve,
907  int serialidx,
908  bool is_first_span,
909  bool is_last_span,
910  int span,
911  int nvtx,
912  int ord);
913  ~GU_RayRBezCurveInfo() override;
914 
915  static int count(const GEO_PrimRBezCurve *bezcurve)
916  {
917  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
918  return knots.size() - 1;
919  }
920  template<typename FUNCTOR>
921  static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
922  {
923  const int ord = bezcurve->getOrder();
924  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
925  const int last = knots.size() - 2;
926  const int s = bezcurve->getVertexCount();
927 
928  for (int j = last; j >= 0; --j)
929  {
930  const bool is_first = (j == 0);
931  const bool is_last = (j == last);
932  functor(new GU_RayRBezCurveInfo(bezcurve, (pinfonum ? *pinfonum : 0),
933  is_first, is_last, j, s, ord));
934  if (pinfonum)
935  ++(*pinfonum);
936  }
937  }
938 
939  int intersect(
940  const GEO_Detail &geo,
941  const UT_Vector3 &org,
942  const UT_Vector3 &dir,
943  GU_RayInfo &hitinfo) override;
944  int minimum(
945  const GEO_Detail &geo,
946  const UT_Vector3 &p,
947  GU_MinInfo &mininfo) override;
948  int intersectPrim(
949  const GEO_Detail &geo,
950  const GEO_Detail &prim_geo,
951  GU_RayPrimInfo *prim,
952  GU_RayInfo &hitInfo) override;
953  int minimumPrim(
954  const GEO_Detail &geo,
955  const GEO_Detail &prim_geo,
956  GU_RayPrimInfo *prim,
957  GU_MinInfo &mininfo) override;
958 
959  void init(const GEO_Detail &geo) override;
960  GU_RayRBezCurve *buildCurve(const GEO_Detail &geo);
961 
962  int64 getMemoryUsage(bool inclusive) const override
963  {
964  int64 mem = inclusive ? sizeof(*this) : 0;
965  if (myCurve)
966  mem += myCurve->getMemoryUsage(true);
967  return mem;
968  }
969 
970 public:
971  int mySpan;
973 };
974 
976 {
977 public:
979  GEO_ConstPrimitiveP curve,
980  int serialidx,
981  UT_Interval u,
982  const UT_RefMatrix<UT_Vector4> &patch_cv,
983  int ord,
984  bool is_rational);
985  ~GU_RayNURBCurveInfo() override;
986 
987  template<typename FUNCTOR>
988  static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
989  {
990  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbcurve->getBasis();
991  const int ord = ub->getOrder();
992  GA_PwHandleRO h(nurbcurve->getDetail());
993  GU_NURBPyramid<0> pyramid(ub, nurbcurve, h);
994  const bool rational = nurbcurve->isRational();
995 
996  bool first = true;
997  for (pyramid.rewind(ub); !pyramid.atEnd(); pyramid.advance())
998  {
999  GU_RayNURBCurveInfo *nurbcurveinfo = new GU_RayNURBCurveInfo(
1000  nurbcurve, (pinfonum ? *pinfonum : 0),
1001  pyramid.getInterval(), pyramid.getResult(),
1002  ord, rational);
1003  nurbcurveinfo->myFirstSpanFlag = first;
1004  functor(nurbcurveinfo);
1005 
1006  if (pinfonum)
1007  ++(*pinfonum);
1008 
1009  first = false;
1010  }
1011  }
1012 
1013  int intersect(
1014  const GEO_Detail &geo,
1015  const UT_Vector3 &org,
1016  const UT_Vector3 &dir,
1017  GU_RayInfo &hitinfo) override;
1018  int minimum(
1019  const GEO_Detail &geo,
1020  const UT_Vector3 &p,
1021  GU_MinInfo &mininfo) override;
1022  int intersectPrim(
1023  const GEO_Detail &geo,
1024  const GEO_Detail &prim_geo,
1025  GU_RayPrimInfo *prim,
1026  GU_RayInfo &hitInfo) override;
1027  int minimumPrim(
1028  const GEO_Detail &geo,
1029  const GEO_Detail &prim_geo,
1030  GU_RayPrimInfo *prim,
1031  GU_MinInfo &mininfo) override;
1032 
1033  int64 getMemoryUsage(bool inclusive) const override
1034  {
1035  int64 mem = inclusive ? sizeof(*this) : 0;
1036  mem += myCurve.getMemoryUsage(false);
1037  return mem;
1038  }
1039 
1040 public:
1042 };
1043 
1044 
1045 //________________________________________________________
1046 //
1047 // Surface intersection class
1048 //
1049 // Note: working in homogeneous coordinate
1050 //________________________________________________________
1051 //
1053 {
1054 public:
1056  const GEO_PrimRBezSurf *surf, int serialidx,
1057  int u_span, int v_span,
1058  int u_ord, int v_ord,
1059  float u_start, float u_length,
1060  float v_start, float v_length,
1061  int u_beg, int v_beg,
1062  int u_num, int v_num,
1063  bool is_rational);
1064  ~GU_RayRBezSurfInfo() override;
1065 
1066  static exint count(const GEO_PrimRBezSurf *bezsurf)
1067  {
1068  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1069  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1070  return exint(vknots.size()-1)*(uknots.size()-1);
1071  }
1072 
1073  template<typename FUNCTOR>
1074  static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
1075  {
1076  const int uord = bezsurf->getUOrder();
1077  const int vord = bezsurf->getVOrder();
1078  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1079  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1080  const int cols = bezsurf->getNumCols();
1081  const int rows = bezsurf->getNumRows();
1082  const bool rational = bezsurf->isRational();
1083 
1084  for (int r = vknots.size()-2; r >= 0; r--)
1085  {
1086  const int r1 = (vord-1)*r;
1087  for (int c = uknots.size()-2; c >= 0; c--)
1088  {
1089  const int c1 = (uord-1)*c;
1090  functor(new GU_RayRBezSurfInfo(
1091  bezsurf, (pinfonum ? *pinfonum : 0),
1092  c, r,
1093  uord, vord,
1094  uknots(c), uknots(c+1)-uknots(c),
1095  vknots(r), vknots(r+1)-vknots(r),
1096  c1, r1,
1097  cols, rows,
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 
1116  int intersectPrim(
1117  const GEO_Detail &geo,
1118  const GEO_Detail &prim_geo,
1119  GU_RayPrimInfo *prim,
1120  GU_RayInfo &hitinfo) override;
1121  int minimumPrim(
1122  const GEO_Detail &geo,
1123  const GEO_Detail &prim_geo,
1124  GU_RayPrimInfo *prim,
1125  GU_MinInfo &hitinfo) override;
1126 
1127  void init(const GEO_Detail &geo) override;
1128  virtual GU_RayRBezSurf *buildSurf(const GEO_Detail &geo);
1129 
1130  int64 getMemoryUsage(bool inclusive) const override
1131  {
1132  int64 mem = inclusive ? sizeof(*this) : 0;
1133  if (mySurf)
1134  mem += mySurf->getMemoryUsage(true);
1135  return mem;
1136  }
1137 
1138 public:
1139  int myUSpan, myVSpan;
1141 };
1142 
1144 {
1145 public:
1147  GEO_ConstPrimitiveP surf, int serialidx,
1148  int u_ord, int v_ord,
1150  const UT_RefMatrix<UT_Vector4> &patch_cv,
1151  bool is_rational);
1152  ~GU_RayNURBSurfInfo() override;
1153 
1154  template<typename FUNCTOR>
1155  static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
1156  {
1157  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbsurf->getUBasis();
1158  const GA_NUBBasis *vb = (const GA_NUBBasis *)nurbsurf->getVBasis();
1159  const int uOrd = ub->getOrder();
1160  const int vOrd = vb->getOrder();
1161  GA_PwHandleRO h(nurbsurf->getDetail());
1162  GU_NURBPyramid<0> uPyramid(ub, nurbsurf, h);
1163  GU_NURBPyramid<1> vPyramid(vb, &uPyramid.getResult());
1164  const bool rational = nurbsurf->isRational();
1165 
1166  for (uPyramid.rewind(ub); !uPyramid.atEnd(); uPyramid.advance())
1167  {
1168  const UT_Interval &u = uPyramid.getInterval();
1169  for (vPyramid.rewind(vb); !vPyramid.atEnd(); vPyramid.advance())
1170  {
1171  functor(new GU_RayNURBSurfInfo(nurbsurf,
1172  (pinfonum ? *pinfonum : 0),
1173  uOrd, vOrd,
1174  u, vPyramid.getInterval(),
1175  vPyramid.getResult(),
1176  rational));
1177 
1178  if (pinfonum)
1179  ++(*pinfonum);
1180  }
1181  }
1182  }
1183 
1184  int intersect(
1185  const GEO_Detail &geo,
1186  const UT_Vector3 &org,
1187  const UT_Vector3 &dir,
1188  GU_RayInfo &hitinfo) override;
1189  int minimum(
1190  const GEO_Detail &geo,
1191  const UT_Vector3 &p,
1192  GU_MinInfo &mininfo) override;
1193  int intersectPrim(
1194  const GEO_Detail &geo,
1195  const GEO_Detail &prim_geo,
1196  GU_RayPrimInfo *prim,
1197  GU_RayInfo &hitinfo) override;
1198  int minimumPrim(
1199  const GEO_Detail &geo,
1200  const GEO_Detail &prim_geo,
1201  GU_RayPrimInfo *prim,
1202  GU_MinInfo &hitinfo) override;
1203 
1204  int64 getMemoryUsage(bool inclusive) const override
1205  {
1206  int64 mem = inclusive ? sizeof(*this) : 0;
1207  mem += mySurf.getMemoryUsage(false);
1208  return mem;
1209  }
1210 
1211 public:
1213 };
1214 
1215 //___________________________________________________________________________
1216 //
1217 // Moving triangle ray intersection classes
1218 // - HTriangle is for hardened points
1219 //___________________________________________________________________________
1220 //
1222 {
1223 public:
1225  GEO_ConstPrimitiveP prim0, int serialidx,
1226  GA_Offset p00, GA_Offset p01,
1227  GA_Offset p02,
1228  GEO_ConstPrimitiveP prim1,
1229  GA_Offset p10, GA_Offset p11,
1230  GA_Offset p12);
1231  ~GU_RayMovingTriangleInfo() override;
1232 
1233  void init(const GEO_Detail &geo) override;
1234 
1235  int intersect(
1236  const GEO_Detail &geo,
1237  const UT_Vector3 &org,
1238  const UT_Vector3 &dir,
1239  GU_RayInfo &hitinfo) override;
1240 
1241  int64 getMemoryUsage(bool inclusive) const override
1242  {
1243  int64 mem = inclusive ? sizeof(*this) : 0;
1244  return mem;
1245  }
1246 
1247 private:
1248  int insertHit(
1249  const GEO_Detail &geo,
1250  const UT_Vector3 &org,
1251  const UT_Vector3 &dir,
1252  GU_RayInfo &hitinfo,
1253  float t,
1254  float nt);
1255 
1256 public:
1258  GA_Offset myV0[3]; // Three corner vertices at t = 0
1259  GA_Offset myV1[3]; // Three corner vertices at t = 1
1260 
1261  double a2, a1, a0; // Coefficients of x comp of normal
1262  double b2, b1, b0; // Coefficients of y comp of normal
1263  double c2, c1, c0; // Coefficients of z comp of normal
1264 };
1265 
1266 
1267 #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:236
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:74
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:25
unsigned getVOrder() const
Definition: GEO_TPSurf.h:389
float tscale
exint size() const
Definition: UT_Array.h:667
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:653
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