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 usevisibility,
772  bool solidtet);
773  ~GU_RayPackedInfo() override;
774 
775  void init(const GEO_Detail &geo) override;
776 
777  int intersect(
778  const GEO_Detail &geo,
779  const UT_Vector3 &org,
780  const UT_Vector3 &dir,
781  GU_RayInfo &hitinfo) override;
782  int minimum(
783  const GEO_Detail &geo,
784  const UT_Vector3 &p,
785  GU_MinInfo &mininfo) override;
786 
787  int64 getMemoryUsage(bool inclusive) const override;
788 
789  void unpack(const GEO_Detail &geo);
790 
791 private:
792  const int myPicking;
793  const int myPolyLine;
794  const int myHarden;
795  const int myUseVisibility;
796  const int mySolidTet;
797 
798  UT_UniquePtr<GEO_Detail> myUnpackedGdp;
799  UT_UniquePtr<GU_RayIntersect> myUnpackedIntersect;
800 };
801 
802 //________________________________________________________
803 //
804 // Polyline intersection class
805 //________________________________________________________
806 //
808 {
809 public:
811  GEO_ConstPrimitiveP prim,
812  int serialidx,
813  int span, int len);
814  ~GU_RayPolyLineInfo() override;
815 
816  int intersect(
817  const GEO_Detail &geo,
818  const UT_Vector3 &org,
819  const UT_Vector3 &dir,
820  GU_RayInfo &hitinfo) override;
821  int minimum(
822  const GEO_Detail &geo,
823  const UT_Vector3 &p,
824  GU_MinInfo &mininfo) override;
825  int intersectPrim(
826  const GEO_Detail &geo,
827  const GEO_Detail &prim_geo,
828  GU_RayPrimInfo *prim,
829  GU_RayInfo &hitInfo) override;
830  int minimumPrim(
831  const GEO_Detail &geo,
832  const GEO_Detail &prim_geo,
833  GU_RayPrimInfo *prim,
834  GU_MinInfo &mininfo) override;
835 
836  int64 getMemoryUsage(bool inclusive) const override
837  {
838  int64 mem = inclusive ? sizeof(*this) : 0;
839  return mem;
840  }
841 
842 public:
843  int mySpan; // What part of the poly
844  int myLen; // we are responsible for
845 };
846 
847 //________________________________________________________
848 //
849 // Curve intersection class
850 //
851 // Note: working in homogeneous coordinate
852 //________________________________________________________
853 //
854 
856 {
857 public:
859  GEO_ConstPrimitiveP curve,
860  int serialidx,
861  bool is_first_span,
862  bool is_last_span)
863  : GU_RayPrimInfo(curve, serialidx)
864  , myFirstSpanFlag(is_first_span)
865  , myLastSpanFlag(is_last_span)
866  {
867  }
868  ~GU_RayCurveInfo() override {}
869 
870 protected:
871  // checks the proximity of the ray to the end points of the curve,
872  // and compares it with the tolerance given in hit_info,
873  // but only for these endpoints
874  // of the curve for which first/last span flags (the member data) are true.
875  // If ray passes within the given tolerance, in the hemispherical cup
876  // at the end of the curve, that "seals" the cylidrical zone around
877  // the curve, it is considered as a hit, and 1 is returned.
878  // INPUTS:
879  // org, dir - the origin and direction of the ray
880  // curve - the curve endpoints we investigate
881  // hit_info - its tolerance is treated as a radius of a hemisphere at the
882  // endpoints, within which to test the ray's presence
883  // OUTPUT
884  // hit_info - if hit, a hit is added
885  // RETURN:
886  // 1 if hit: ray passes within tolerance radius of endpoint(s), otherwise 0
887  int intersectEndPointZone(
888  const GEO_Detail &geo,
889  const UT_Vector3 &org,
890  const UT_Vector3 &dir,
891  const GU_RayRBezCurve* curve,
892  GU_RayInfo &hit_info) const;
893 
894 public:
895  // usually a curve primitive is subdivided into several spans, whose
896  // info is encoded in GU_RayRBezCurveInfo and GU_RayNURBCurveInfo.
897  // Following flags indicate if this span is first or last on the curve.
898  bool myFirstSpanFlag : 1, // 1 if it's firsrt span on curve
899  myLastSpanFlag : 1; // 1 if it's last span on curve
900 };
901 
902 class GEO_PrimRBezCurve;
903 
905 {
906 public:
908  const GEO_PrimRBezCurve *curve,
909  int serialidx,
910  bool is_first_span,
911  bool is_last_span,
912  int span,
913  int nvtx,
914  int ord);
915  ~GU_RayRBezCurveInfo() override;
916 
917  static int count(const GEO_PrimRBezCurve *bezcurve)
918  {
919  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
920  return knots.size() - 1;
921  }
922  template<typename FUNCTOR>
923  static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
924  {
925  const int ord = bezcurve->getOrder();
926  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
927  const int last = knots.size() - 2;
928  const int s = bezcurve->getVertexCount();
929 
930  for (int j = last; j >= 0; --j)
931  {
932  const bool is_first = (j == 0);
933  const bool is_last = (j == last);
934  functor(new GU_RayRBezCurveInfo(bezcurve, (pinfonum ? *pinfonum : 0),
935  is_first, is_last, j, s, ord));
936  if (pinfonum)
937  ++(*pinfonum);
938  }
939  }
940 
941  int intersect(
942  const GEO_Detail &geo,
943  const UT_Vector3 &org,
944  const UT_Vector3 &dir,
945  GU_RayInfo &hitinfo) override;
946  int minimum(
947  const GEO_Detail &geo,
948  const UT_Vector3 &p,
949  GU_MinInfo &mininfo) override;
950  int intersectPrim(
951  const GEO_Detail &geo,
952  const GEO_Detail &prim_geo,
953  GU_RayPrimInfo *prim,
954  GU_RayInfo &hitInfo) override;
955  int minimumPrim(
956  const GEO_Detail &geo,
957  const GEO_Detail &prim_geo,
958  GU_RayPrimInfo *prim,
959  GU_MinInfo &mininfo) override;
960 
961  void init(const GEO_Detail &geo) override;
962  GU_RayRBezCurve *buildCurve(const GEO_Detail &geo);
963 
964  int64 getMemoryUsage(bool inclusive) const override
965  {
966  int64 mem = inclusive ? sizeof(*this) : 0;
967  if (myCurve)
968  mem += myCurve->getMemoryUsage(true);
969  return mem;
970  }
971 
972 public:
973  int mySpan;
975 };
976 
978 {
979 public:
981  GEO_ConstPrimitiveP curve,
982  int serialidx,
983  UT_Interval u,
984  const UT_RefMatrix<UT_Vector4> &patch_cv,
985  int ord,
986  bool is_rational);
987  ~GU_RayNURBCurveInfo() override;
988 
989  template<typename FUNCTOR>
990  static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
991  {
992  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbcurve->getBasis();
993  const int ord = ub->getOrder();
994  GA_PwHandleRO h(nurbcurve->getDetail());
995  GU_NURBPyramid<0> pyramid(ub, nurbcurve, h);
996  const bool rational = nurbcurve->isRational();
997 
998  bool first = true;
999  for (pyramid.rewind(ub); !pyramid.atEnd(); pyramid.advance())
1000  {
1001  GU_RayNURBCurveInfo *nurbcurveinfo = new GU_RayNURBCurveInfo(
1002  nurbcurve, (pinfonum ? *pinfonum : 0),
1003  pyramid.getInterval(), pyramid.getResult(),
1004  ord, rational);
1005  nurbcurveinfo->myFirstSpanFlag = first;
1006  functor(nurbcurveinfo);
1007 
1008  if (pinfonum)
1009  ++(*pinfonum);
1010 
1011  first = false;
1012  }
1013  }
1014 
1015  int intersect(
1016  const GEO_Detail &geo,
1017  const UT_Vector3 &org,
1018  const UT_Vector3 &dir,
1019  GU_RayInfo &hitinfo) override;
1020  int minimum(
1021  const GEO_Detail &geo,
1022  const UT_Vector3 &p,
1023  GU_MinInfo &mininfo) override;
1024  int intersectPrim(
1025  const GEO_Detail &geo,
1026  const GEO_Detail &prim_geo,
1027  GU_RayPrimInfo *prim,
1028  GU_RayInfo &hitInfo) override;
1029  int minimumPrim(
1030  const GEO_Detail &geo,
1031  const GEO_Detail &prim_geo,
1032  GU_RayPrimInfo *prim,
1033  GU_MinInfo &mininfo) override;
1034 
1035  int64 getMemoryUsage(bool inclusive) const override
1036  {
1037  int64 mem = inclusive ? sizeof(*this) : 0;
1038  mem += myCurve.getMemoryUsage(false);
1039  return mem;
1040  }
1041 
1042 public:
1044 };
1045 
1046 
1047 //________________________________________________________
1048 //
1049 // Surface intersection class
1050 //
1051 // Note: working in homogeneous coordinate
1052 //________________________________________________________
1053 //
1055 {
1056 public:
1058  const GEO_PrimRBezSurf *surf, int serialidx,
1059  int u_span, int v_span,
1060  int u_ord, int v_ord,
1061  float u_start, float u_length,
1062  float v_start, float v_length,
1063  int u_beg, int v_beg,
1064  int u_num, int v_num,
1065  bool is_rational);
1066  ~GU_RayRBezSurfInfo() override;
1067 
1068  static exint count(const GEO_PrimRBezSurf *bezsurf)
1069  {
1070  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1071  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1072  return exint(vknots.size()-1)*(uknots.size()-1);
1073  }
1074 
1075  template<typename FUNCTOR>
1076  static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
1077  {
1078  const int uord = bezsurf->getUOrder();
1079  const int vord = bezsurf->getVOrder();
1080  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
1081  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
1082  const int cols = bezsurf->getNumCols();
1083  const int rows = bezsurf->getNumRows();
1084  const bool rational = bezsurf->isRational();
1085 
1086  for (int r = vknots.size()-2; r >= 0; r--)
1087  {
1088  const int r1 = (vord-1)*r;
1089  for (int c = uknots.size()-2; c >= 0; c--)
1090  {
1091  const int c1 = (uord-1)*c;
1092  functor(new GU_RayRBezSurfInfo(
1093  bezsurf, (pinfonum ? *pinfonum : 0),
1094  c, r,
1095  uord, vord,
1096  uknots(c), uknots(c+1)-uknots(c),
1097  vknots(r), vknots(r+1)-vknots(r),
1098  c1, r1,
1099  cols, rows,
1100  rational));
1101 
1102  if (pinfonum)
1103  ++(*pinfonum);
1104  }
1105  }
1106  }
1107 
1108  int intersect(
1109  const GEO_Detail &geo,
1110  const UT_Vector3 &org,
1111  const UT_Vector3 &dir,
1112  GU_RayInfo &hitinfo) override;
1113  int minimum(
1114  const GEO_Detail &geo,
1115  const UT_Vector3 &p,
1116  GU_MinInfo &mininfo) override;
1117 
1118  int intersectPrim(
1119  const GEO_Detail &geo,
1120  const GEO_Detail &prim_geo,
1121  GU_RayPrimInfo *prim,
1122  GU_RayInfo &hitinfo) override;
1123  int minimumPrim(
1124  const GEO_Detail &geo,
1125  const GEO_Detail &prim_geo,
1126  GU_RayPrimInfo *prim,
1127  GU_MinInfo &hitinfo) override;
1128 
1129  void init(const GEO_Detail &geo) override;
1130  virtual GU_RayRBezSurf *buildSurf(const GEO_Detail &geo);
1131 
1132  int64 getMemoryUsage(bool inclusive) const override
1133  {
1134  int64 mem = inclusive ? sizeof(*this) : 0;
1135  if (mySurf)
1136  mem += mySurf->getMemoryUsage(true);
1137  return mem;
1138  }
1139 
1140 public:
1141  int myUSpan, myVSpan;
1143 };
1144 
1146 {
1147 public:
1149  GEO_ConstPrimitiveP surf, int serialidx,
1150  int u_ord, int v_ord,
1152  const UT_RefMatrix<UT_Vector4> &patch_cv,
1153  bool is_rational);
1154  ~GU_RayNURBSurfInfo() override;
1155 
1156  template<typename FUNCTOR>
1157  static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
1158  {
1159  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbsurf->getUBasis();
1160  const GA_NUBBasis *vb = (const GA_NUBBasis *)nurbsurf->getVBasis();
1161  const int uOrd = ub->getOrder();
1162  const int vOrd = vb->getOrder();
1163  GA_PwHandleRO h(nurbsurf->getDetail());
1164  GU_NURBPyramid<0> uPyramid(ub, nurbsurf, h);
1165  GU_NURBPyramid<1> vPyramid(vb, &uPyramid.getResult());
1166  const bool rational = nurbsurf->isRational();
1167 
1168  for (uPyramid.rewind(ub); !uPyramid.atEnd(); uPyramid.advance())
1169  {
1170  const UT_Interval &u = uPyramid.getInterval();
1171  for (vPyramid.rewind(vb); !vPyramid.atEnd(); vPyramid.advance())
1172  {
1173  functor(new GU_RayNURBSurfInfo(nurbsurf,
1174  (pinfonum ? *pinfonum : 0),
1175  uOrd, vOrd,
1176  u, vPyramid.getInterval(),
1177  vPyramid.getResult(),
1178  rational));
1179 
1180  if (pinfonum)
1181  ++(*pinfonum);
1182  }
1183  }
1184  }
1185 
1186  int intersect(
1187  const GEO_Detail &geo,
1188  const UT_Vector3 &org,
1189  const UT_Vector3 &dir,
1190  GU_RayInfo &hitinfo) override;
1191  int minimum(
1192  const GEO_Detail &geo,
1193  const UT_Vector3 &p,
1194  GU_MinInfo &mininfo) override;
1195  int intersectPrim(
1196  const GEO_Detail &geo,
1197  const GEO_Detail &prim_geo,
1198  GU_RayPrimInfo *prim,
1199  GU_RayInfo &hitinfo) override;
1200  int minimumPrim(
1201  const GEO_Detail &geo,
1202  const GEO_Detail &prim_geo,
1203  GU_RayPrimInfo *prim,
1204  GU_MinInfo &hitinfo) override;
1205 
1206  int64 getMemoryUsage(bool inclusive) const override
1207  {
1208  int64 mem = inclusive ? sizeof(*this) : 0;
1209  mem += mySurf.getMemoryUsage(false);
1210  return mem;
1211  }
1212 
1213 public:
1215 };
1216 
1217 //___________________________________________________________________________
1218 //
1219 // Moving triangle ray intersection classes
1220 // - HTriangle is for hardened points
1221 //___________________________________________________________________________
1222 //
1224 {
1225 public:
1227  GEO_ConstPrimitiveP prim0, int serialidx,
1228  GA_Offset p00, GA_Offset p01,
1229  GA_Offset p02,
1230  GEO_ConstPrimitiveP prim1,
1231  GA_Offset p10, GA_Offset p11,
1232  GA_Offset p12);
1233  ~GU_RayMovingTriangleInfo() override;
1234 
1235  void init(const GEO_Detail &geo) override;
1236 
1237  int intersect(
1238  const GEO_Detail &geo,
1239  const UT_Vector3 &org,
1240  const UT_Vector3 &dir,
1241  GU_RayInfo &hitinfo) override;
1242 
1243  int64 getMemoryUsage(bool inclusive) const override
1244  {
1245  int64 mem = inclusive ? sizeof(*this) : 0;
1246  return mem;
1247  }
1248 
1249 private:
1250  int insertHit(
1251  const GEO_Detail &geo,
1252  const UT_Vector3 &org,
1253  const UT_Vector3 &dir,
1254  GU_RayInfo &hitinfo,
1255  float t,
1256  float nt);
1257 
1258 public:
1260  GA_Offset myV0[3]; // Three corner vertices at t = 0
1261  GA_Offset myV1[3]; // Three corner vertices at t = 1
1262 
1263  double a2, a1, a0; // Coefficients of x comp of normal
1264  double b2, b1, b0; // Coefficients of y comp of normal
1265  double c2, c1, c0; // Coefficients of z comp of normal
1266 };
1267 
1268 
1269 #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