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  virtual ~GU_RayQuadricInfo();
174 
175  virtual int intersect(
176  const GEO_Detail &geo,
177  const UT_Vector3 &org,
178  const UT_Vector3 &dir,
179  GU_RayInfo &hitinfo);
180  virtual int minimum(
181  const GEO_Detail &geo,
182  const UT_Vector3 &p,
183  GU_MinInfo &mininfo);
184 
185  virtual int64 getMemoryUsage(bool inclusive) const
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  virtual ~GU_RayTriangleInfo();
234 
235  virtual void init(const GEO_Detail &geo);
236 
237  virtual int intersect(
238  const GEO_Detail &geo,
239  const UT_Vector3 &org,
240  const UT_Vector3 &dir,
241  GU_RayInfo &hitinfo);
242  virtual int minimum(
243  const GEO_Detail &geo,
244  const UT_Vector3 &p,
245  GU_MinInfo &mininfo);
246 
247  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
248  {
249  return nml;
250  }
251 
252  virtual int64 getMemoryUsage(bool inclusive) const
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  virtual ~GU_RayHTriangleInfo();
275 
276  virtual void init(const GEO_Detail &geo);
277 
278  virtual int intersect(
279  const GEO_Detail &geo,
280  const UT_Vector3 &org,
281  const UT_Vector3 &dir,
282  GU_RayInfo &hitinfo);
283  virtual int minimum(
284  const GEO_Detail &geo,
285  const UT_Vector3 &p,
286  GU_MinInfo &mininfo);
287 
288  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
289  {
290  return nml;
291  }
292 
293  virtual int64 getMemoryUsage(bool inclusive) const
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  virtual ~GU_RayTetInfo();
340 
341  virtual int intersect(
342  const GEO_Detail &geo,
343  const UT_Vector3 &org,
344  const UT_Vector3 &dir,
345  GU_RayInfo &hitinfo);
346  virtual int minimum(
347  const GEO_Detail &geo,
348  const UT_Vector3 &p,
349  GU_MinInfo &mininfo);
350 
351  virtual int64 getMemoryUsage(bool inclusive) const
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  virtual ~GU_RayHTetInfo();
369 
370  virtual int intersect(
371  const GEO_Detail &geo,
372  const UT_Vector3 &org,
373  const UT_Vector3 &dir,
374  GU_RayInfo &hitinfo);
375  virtual int minimum(
376  const GEO_Detail &geo,
377  const UT_Vector3 &p,
378  GU_MinInfo &mininfo);
379 
380  virtual int64 getMemoryUsage(bool inclusive) const
381  {
382  int64 mem = inclusive ? sizeof(*this) : 0;
383  return mem;
384  }
385 
386 public:
387  UT_Vector3 myV[4]; // Four corner verices
388 };
389 
390 //___________________________________________________________________________
391 //
392 // Quad ray intersection classes - HQuad is for hardened points (i.e. NURBS)
393 //___________________________________________________________________________
394 //
396 {
397 public:
398  GU_RayQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
399  GA_Offset p0, GA_Offset p1,
400  GA_Offset p2, GA_Offset p3,
401  float ustart = 0.0F, float ulength = 1.0F,
402  float vstart = 0.0F, float vlength = 1.0F,
403  float w=0.0f);
404  virtual ~GU_RayQuadInfo();
405 
406  virtual void init(const GEO_Detail &geo);
407 
408  virtual int intersect(
409  const GEO_Detail &geo,
410  const UT_Vector3 &org,
411  const UT_Vector3 &dir,
412  GU_RayInfo &hitinfo);
413  virtual int minimum(
414  const GEO_Detail &geo,
415  const UT_Vector3 &p,
416  GU_MinInfo &mininfo);
417 
418  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
419  {
420  return nml;
421  }
422 
423  virtual int64 getMemoryUsage(bool inclusive) const
424  {
425  int64 mem = inclusive ? sizeof(*this) : 0;
426  return mem;
427  }
428 
429 public:
430  GA_Offset myV[4]; // Four corner vertices
431  UT_Vector3 nml; // Surface normal
432 
433  //float D; // Plane eqn constant
434  //int x, y; // Oriented to projected plane
435  float myUStart, myULength;
436  float myVStart, myVLength;
437  const float myW;
438 };
439 
441 {
442 public:
443  GU_RayHQuadInfo(GEO_ConstPrimitiveP prim, int serialidx,
444  const UT_Vector3 &p0, const UT_Vector3 &p1,
445  const UT_Vector3 &p2, const UT_Vector3 &p3,
446  float ustart = 0.0f, float ulen = 1.0f,
447  float vstart = 0.0f, float vlen = 1.0f,
448  bool revnml = false, float w=0.0f);
449  virtual ~GU_RayHQuadInfo();
450 
451  virtual void init(const GEO_Detail &geo);
452 
453  virtual int intersect(
454  const GEO_Detail &geo,
455  const UT_Vector3 &org,
456  const UT_Vector3 &dir,
457  GU_RayInfo &hitinfo);
458  virtual int minimum(
459  const GEO_Detail &geo,
460  const UT_Vector3 &p,
461  GU_MinInfo &mininfo);
462 
463  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
464  {
465  return nml;
466  }
467 
468  virtual int64 getMemoryUsage(bool inclusive) const
469  {
470  int64 mem = inclusive ? sizeof(*this) : 0;
471  return mem;
472  }
473 
474 public:
475  UT_Vector3 myV[4]; // Four corner vertices
476  UT_Vector3 nml; // Surface normal
477  bool myRevNml; // Do we reverse the normal?
478 
479  // These numbers aren't needed by the bilinear code.
480  //float D; // Plane eqn constant
481  //int x, y; // Oriented to projected plane
482 
483  float myUStart, myULength;
484  float myVStart, myVLength;
485  const float myW;
486 };
487 
488 //________________________________________________________
489 //
490 // General Face ray intersection class
491 //________________________________________________________
492 //
494 {
495 public:
496  GU_RayPolyInfo(GEO_ConstPrimitiveP prim, int serialidx,
497  const UT_Array<GA_Offset> &ipts, float w=0.0f);
498  virtual ~GU_RayPolyInfo();
499 
500  virtual int intersect(
501  const GEO_Detail &geo,
502  const UT_Vector3 &org,
503  const UT_Vector3 &dir,
504  GU_RayInfo &hitinfo);
505  virtual int minimum(
506  const GEO_Detail &geo,
507  const UT_Vector3 &p,
508  GU_MinInfo &mininfo);
509 
510  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
511  {
512  return nml;
513  }
514 
515  virtual int64 getMemoryUsage(bool inclusive) const
516  {
517  int64 mem = inclusive ? sizeof(*this) : 0;
518  return mem;
519  }
520 
521 public:
523  float D;
524  int x, y;
526  const float myW;
527 };
528 
530 {
531 public:
533  GEO_ConstPrimitiveP prim,
534  int serialidx,
535  const UT_Vector4Array &p,
536  float w = 0.0f);
538  GEO_ConstPrimitiveP prim,
539  int serialidx,
540  const UT_Array<UT_Vector3> &p,
541  float w = 0.0f);
542  virtual ~GU_RayHPolyInfo();
543 
544  template<typename ARRAY_TYPE>
545  void initPoly(GEO_ConstPrimitiveP p, const ARRAY_TYPE &pts);
546  virtual int intersect(
547  const GEO_Detail &geo,
548  const UT_Vector3 &org,
549  const UT_Vector3 &dir,
550  GU_RayInfo &hitinfo);
551  virtual int minimum(
552  const GEO_Detail &geo,
553  const UT_Vector3 &p,
554  GU_MinInfo &mininfo);
555 
556  virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
557  {
558  return nml;
559  }
560 
561  virtual int64 getMemoryUsage(bool inclusive) const
562  {
563  int64 mem = inclusive ? sizeof(*this) : 0;
564  if (xval)
565  mem += npts * sizeof(xval[0]);
566  if (yval)
567  mem += npts * sizeof(yval[0]);
568  return mem;
569  }
570 
571 public:
573 
574  int npts;
578  float D;
579  int x, y;
580  const float myW;
581 };
582 
583 //________________________________________________________
584 //
585 // Meta-surface ray intersection class
586 //________________________________________________________
587 //
589 {
590 public:
591  GU_RayMetaInfo(const TS_MetaExpressionPtr &expr, int serialidx);
592  virtual ~GU_RayMetaInfo();
593 
594  virtual int intersect(
595  const GEO_Detail &geo,
596  const UT_Vector3 &org,
597  const UT_Vector3 &dir,
598  GU_RayInfo &hitinfo);
599 
600  virtual int64 getMemoryUsage(bool inclusive) const;
601 
602 public:
605 };
606 
607 //________________________________________________________
608 //
609 // VDB intersection class
610 //________________________________________________________
612 {
613 public:
614  GU_RayVDBInfo(GEO_ConstPrimitiveP vdb, int serialidx);
615  virtual ~GU_RayVDBInfo();
616 
617  virtual int intersect(
618  const GEO_Detail &geo,
619  const UT_Vector3 &org,
620  const UT_Vector3 &dir,
621  GU_RayInfo &hitinfo);
622 
623  virtual int64 getMemoryUsage(bool inclusive) const;
624 
625 public:
627  float myStepSize;
629  bool myFailed;
631 #ifdef OPENVDB_ENABLED
632  const openvdb::GridBase *myGridRawPtr;
633 #endif
634 
635 };
636 
637 //________________________________________________________
638 //
639 // HeightField intersection class
640 //________________________________________________________
642 {
643 public:
644  GU_RayHeightFieldInfo(const GEO_PrimVolume *vdb, int serialidx);
645  virtual ~GU_RayHeightFieldInfo();
646 
647  virtual int intersect(
648  const GEO_Detail &geo,
649  const UT_Vector3 &org,
650  const UT_Vector3 &dir,
651  GU_RayInfo &hitinfo);
652  virtual int minimum(
653  const GEO_Detail &geo,
654  const UT_Vector3 &p,
655  GU_MinInfo &mininfo);
656 
657  virtual int64 getMemoryUsage(bool inclusive) const;
658 
659 public:
660  int myAxis, myA1, myA2;
661  int myDim[3];
663  bool myFailed;
664  float myScale, myInvScale;
668 };
669 
670 //________________________________________________________
671 //
672 // Packed primitive intersection class
673 //________________________________________________________
674 
676 {
677 public:
678  GU_RayPackedInfo(GEO_ConstPrimitiveP prim, int serialidx, int picking,
679  int polyline, int harden, bool solidtet);
680  virtual ~GU_RayPackedInfo();
681 
682  virtual void init(const GEO_Detail &geo);
683 
684  virtual int intersect(
685  const GEO_Detail &geo,
686  const UT_Vector3 &org,
687  const UT_Vector3 &dir,
688  GU_RayInfo &hitinfo);
689  virtual int minimum(
690  const GEO_Detail &geo,
691  const UT_Vector3 &p,
692  GU_MinInfo &mininfo);
693 
694  virtual int64 getMemoryUsage(bool inclusive) const;
695 
696  void unpack(const GEO_Detail &geo);
697 
698 private:
699  const int myPicking;
700  const int myPolyLine;
701  const int myHarden;
702  const int mySolidTet;
703 
704  UT_UniquePtr<GEO_Detail> myUnpackedGdp;
705  UT_UniquePtr<GU_RayIntersect> myUnpackedIntersect;
706 };
707 
708 //________________________________________________________
709 //
710 // Polyline intersection class
711 //________________________________________________________
712 //
714 {
715 public:
717  GEO_ConstPrimitiveP prim,
718  int serialidx,
719  int span, int len);
720  virtual ~GU_RayPolyLineInfo();
721 
722  virtual int intersect(
723  const GEO_Detail &geo,
724  const UT_Vector3 &org,
725  const UT_Vector3 &dir,
726  GU_RayInfo &hitinfo);
727  virtual int minimum(
728  const GEO_Detail &geo,
729  const UT_Vector3 &p,
730  GU_MinInfo &mininfo);
731  virtual int intersectPrim(
732  const GEO_Detail &geo,
733  const GEO_Detail &prim_geo,
734  GU_RayPrimInfo *prim,
735  GU_RayInfo &hitInfo);
736  virtual int minimumPrim(
737  const GEO_Detail &geo,
738  const GEO_Detail &prim_geo,
739  GU_RayPrimInfo *prim,
740  GU_MinInfo &mininfo);
741 
742  virtual int64 getMemoryUsage(bool inclusive) const
743  {
744  int64 mem = inclusive ? sizeof(*this) : 0;
745  return mem;
746  }
747 
748 public:
749  int mySpan; // What part of the poly
750  int myLen; // we are responsible for
751 };
752 
753 //________________________________________________________
754 //
755 // Curve intersection class
756 //
757 // Note: working in homogeneous coordinate
758 //________________________________________________________
759 //
760 
762 {
763 public:
765  GEO_ConstPrimitiveP curve,
766  int serialidx,
767  bool is_first_span,
768  bool is_last_span)
769  : GU_RayPrimInfo(curve, serialidx)
770  , myFirstSpanFlag(is_first_span)
771  , myLastSpanFlag(is_last_span)
772  {
773  }
774  virtual ~GU_RayCurveInfo() {}
775 
776 protected:
777  // checks the proximity of the ray to the end points of the curve,
778  // and compares it with the tolerance given in hit_info,
779  // but only for these endpoints
780  // of the curve for which first/last span flags (the member data) are true.
781  // If ray passes within the given tolerance, in the hemispherical cup
782  // at the end of the curve, that "seals" the cylidrical zone around
783  // the curve, it is considered as a hit, and 1 is returned.
784  // INPUTS:
785  // org, dir - the origin and direction of the ray
786  // curve - the curve endpoints we investigate
787  // hit_info - its tolerance is treated as a radius of a hemisphere at the
788  // endpoints, within which to test the ray's presence
789  // OUTPUT
790  // hit_info - if hit, a hit is added
791  // RETURN:
792  // 1 if hit: ray passes within tolerance radius of endpoint(s), otherwise 0
793  int intersectEndPointZone(
794  const GEO_Detail &geo,
795  const UT_Vector3 &org,
796  const UT_Vector3 &dir,
797  const GU_RayRBezCurve* curve,
798  GU_RayInfo &hit_info) const;
799 
800 public:
801  // usually a curve primitive is subdivided into several spans, whose
802  // info is encoded in GU_RayRBezCurveInfo and GU_RayNURBCurveInfo.
803  // Following flags indicate if this span is first or last on the curve.
804  bool myFirstSpanFlag : 1, // 1 if it's firsrt span on curve
805  myLastSpanFlag : 1; // 1 if it's last span on curve
806 };
807 
808 class GEO_PrimRBezCurve;
809 
811 {
812 public:
814  const GEO_PrimRBezCurve *curve,
815  int serialidx,
816  bool is_first_span,
817  bool is_last_span,
818  int span,
819  int nvtx,
820  int ord);
821  virtual ~GU_RayRBezCurveInfo();
822 
823  static int count(const GEO_PrimRBezCurve *bezcurve)
824  {
825  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
826  return knots.size() - 1;
827  }
828  template<typename FUNCTOR>
829  static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
830  {
831  const int ord = bezcurve->getOrder();
832  const GA_KnotVector &knots = bezcurve->getBasis()->getVector();
833  const int last = knots.size() - 2;
834  const int s = bezcurve->getVertexCount();
835 
836  for (int j = last; j >= 0; --j)
837  {
838  const bool is_first = (j == 0);
839  const bool is_last = (j == last);
840  functor(new GU_RayRBezCurveInfo(bezcurve, (pinfonum ? *pinfonum : 0),
841  is_first, is_last, j, s, ord));
842  if (pinfonum)
843  ++(*pinfonum);
844  }
845  }
846 
847  virtual int intersect(
848  const GEO_Detail &geo,
849  const UT_Vector3 &org,
850  const UT_Vector3 &dir,
851  GU_RayInfo &hitinfo);
852  virtual int minimum(
853  const GEO_Detail &geo,
854  const UT_Vector3 &p,
855  GU_MinInfo &mininfo);
856  virtual int intersectPrim(
857  const GEO_Detail &geo,
858  const GEO_Detail &prim_geo,
859  GU_RayPrimInfo *prim,
860  GU_RayInfo &hitInfo);
861  virtual int minimumPrim(
862  const GEO_Detail &geo,
863  const GEO_Detail &prim_geo,
864  GU_RayPrimInfo *prim,
865  GU_MinInfo &mininfo);
866 
867  virtual void init(const GEO_Detail &geo);
868  GU_RayRBezCurve *buildCurve(const GEO_Detail &geo);
869 
870  virtual int64 getMemoryUsage(bool inclusive) const
871  {
872  int64 mem = inclusive ? sizeof(*this) : 0;
873  if (myCurve)
874  mem += myCurve->getMemoryUsage(true);
875  return mem;
876  }
877 
878 public:
879  int mySpan;
881 };
882 
884 {
885 public:
887  GEO_ConstPrimitiveP curve,
888  int serialidx,
889  UT_Interval u,
890  const UT_RefMatrix<UT_Vector4> &patch_cv,
891  int ord,
892  bool is_rational);
893  virtual ~GU_RayNURBCurveInfo();
894 
895  template<typename FUNCTOR>
896  static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
897  {
898  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbcurve->getBasis();
899  const int ord = ub->getOrder();
900  GA_PwHandleRO h(nurbcurve->getDetail());
901  GU_NURBPyramid<0> pyramid(ub, nurbcurve, h);
902  const bool rational = nurbcurve->isRational();
903 
904  bool first = true;
905  for (pyramid.rewind(ub); !pyramid.atEnd(); pyramid.advance())
906  {
907  GU_RayNURBCurveInfo *nurbcurveinfo = new GU_RayNURBCurveInfo(
908  nurbcurve, (pinfonum ? *pinfonum : 0),
909  pyramid.getInterval(), pyramid.getResult(),
910  ord, rational);
911  nurbcurveinfo->myFirstSpanFlag = first;
912  functor(nurbcurveinfo);
913 
914  if (pinfonum)
915  ++(*pinfonum);
916 
917  first = false;
918  }
919  }
920 
921  virtual int intersect(
922  const GEO_Detail &geo,
923  const UT_Vector3 &org,
924  const UT_Vector3 &dir,
925  GU_RayInfo &hitinfo);
926  virtual int minimum(
927  const GEO_Detail &geo,
928  const UT_Vector3 &p,
929  GU_MinInfo &mininfo);
930  virtual int intersectPrim(
931  const GEO_Detail &geo,
932  const GEO_Detail &prim_geo,
933  GU_RayPrimInfo *prim,
934  GU_RayInfo &hitInfo);
935  virtual int minimumPrim(
936  const GEO_Detail &geo,
937  const GEO_Detail &prim_geo,
938  GU_RayPrimInfo *prim,
939  GU_MinInfo &mininfo);
940 
941  virtual int64 getMemoryUsage(bool inclusive) const
942  {
943  int64 mem = inclusive ? sizeof(*this) : 0;
944  mem += myCurve.getMemoryUsage(false);
945  return mem;
946  }
947 
948 public:
950 };
951 
952 
953 //________________________________________________________
954 //
955 // Surface intersection class
956 //
957 // Note: working in homogeneous coordinate
958 //________________________________________________________
959 //
961 {
962 public:
964  const GEO_PrimRBezSurf *surf, int serialidx,
965  int u_span, int v_span,
966  int u_ord, int v_ord,
967  float u_start, float u_length,
968  float v_start, float v_length,
969  int u_beg, int v_beg,
970  int u_num, int v_num,
971  bool is_rational);
972  virtual ~GU_RayRBezSurfInfo();
973 
974  static exint count(const GEO_PrimRBezSurf *bezsurf)
975  {
976  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
977  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
978  return exint(vknots.size()-1)*(uknots.size()-1);
979  }
980 
981  template<typename FUNCTOR>
982  static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
983  {
984  const int uord = bezsurf->getUOrder();
985  const int vord = bezsurf->getVOrder();
986  const GA_KnotVector &uknots = bezsurf->getUBasis()->getVector();
987  const GA_KnotVector &vknots = bezsurf->getVBasis()->getVector();
988  const int cols = bezsurf->getNumCols();
989  const int rows = bezsurf->getNumRows();
990  const bool rational = bezsurf->isRational();
991 
992  for (int r = vknots.size()-2; r >= 0; r--)
993  {
994  const int r1 = (vord-1)*r;
995  for (int c = uknots.size()-2; c >= 0; c--)
996  {
997  const int c1 = (uord-1)*c;
998  functor(new GU_RayRBezSurfInfo(
999  bezsurf, (pinfonum ? *pinfonum : 0),
1000  c, r,
1001  uord, vord,
1002  uknots(c), uknots(c+1)-uknots(c),
1003  vknots(r), vknots(r+1)-vknots(r),
1004  c1, r1,
1005  cols, rows,
1006  rational));
1007 
1008  if (pinfonum)
1009  ++(*pinfonum);
1010  }
1011  }
1012  }
1013 
1014  virtual int intersect(
1015  const GEO_Detail &geo,
1016  const UT_Vector3 &org,
1017  const UT_Vector3 &dir,
1018  GU_RayInfo &hitinfo);
1019  virtual int minimum(
1020  const GEO_Detail &geo,
1021  const UT_Vector3 &p,
1022  GU_MinInfo &mininfo);
1023 
1024  virtual int intersectPrim(
1025  const GEO_Detail &geo,
1026  const GEO_Detail &prim_geo,
1027  GU_RayPrimInfo *prim,
1028  GU_RayInfo &hitinfo);
1029  virtual int minimumPrim(
1030  const GEO_Detail &geo,
1031  const GEO_Detail &prim_geo,
1032  GU_RayPrimInfo *prim,
1033  GU_MinInfo &hitinfo);
1034 
1035  virtual void init(const GEO_Detail &geo);
1036  virtual GU_RayRBezSurf *buildSurf(const GEO_Detail &geo);
1037 
1038  virtual int64 getMemoryUsage(bool inclusive) const
1039  {
1040  int64 mem = inclusive ? sizeof(*this) : 0;
1041  if (mySurf)
1042  mem += mySurf->getMemoryUsage(true);
1043  return mem;
1044  }
1045 
1046 public:
1047  int myUSpan, myVSpan;
1049 };
1050 
1052 {
1053 public:
1055  GEO_ConstPrimitiveP surf, int serialidx,
1056  int u_ord, int v_ord,
1058  const UT_RefMatrix<UT_Vector4> &patch_cv,
1059  bool is_rational);
1060  virtual ~GU_RayNURBSurfInfo();
1061 
1062  template<typename FUNCTOR>
1063  static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
1064  {
1065  const GA_NUBBasis *ub = (const GA_NUBBasis *)nurbsurf->getUBasis();
1066  const GA_NUBBasis *vb = (const GA_NUBBasis *)nurbsurf->getVBasis();
1067  const int uOrd = ub->getOrder();
1068  const int vOrd = vb->getOrder();
1069  GA_PwHandleRO h(nurbsurf->getDetail());
1070  GU_NURBPyramid<0> uPyramid(ub, nurbsurf, h);
1071  GU_NURBPyramid<1> vPyramid(vb, &uPyramid.getResult());
1072  const bool rational = nurbsurf->isRational();
1073 
1074  for (uPyramid.rewind(ub); !uPyramid.atEnd(); uPyramid.advance())
1075  {
1076  const UT_Interval &u = uPyramid.getInterval();
1077  for (vPyramid.rewind(vb); !vPyramid.atEnd(); vPyramid.advance())
1078  {
1079  functor(new GU_RayNURBSurfInfo(nurbsurf,
1080  (pinfonum ? *pinfonum : 0),
1081  uOrd, vOrd,
1082  u, vPyramid.getInterval(),
1083  vPyramid.getResult(),
1084  rational));
1085 
1086  if (pinfonum)
1087  ++(*pinfonum);
1088  }
1089  }
1090  }
1091 
1092  virtual int intersect(
1093  const GEO_Detail &geo,
1094  const UT_Vector3 &org,
1095  const UT_Vector3 &dir,
1096  GU_RayInfo &hitinfo);
1097  virtual int minimum(
1098  const GEO_Detail &geo,
1099  const UT_Vector3 &p,
1100  GU_MinInfo &mininfo);
1101  virtual int intersectPrim(
1102  const GEO_Detail &geo,
1103  const GEO_Detail &prim_geo,
1104  GU_RayPrimInfo *prim,
1105  GU_RayInfo &hitinfo);
1106  virtual int minimumPrim(
1107  const GEO_Detail &geo,
1108  const GEO_Detail &prim_geo,
1109  GU_RayPrimInfo *prim,
1110  GU_MinInfo &hitinfo);
1111 
1112  virtual int64 getMemoryUsage(bool inclusive) const
1113  {
1114  int64 mem = inclusive ? sizeof(*this) : 0;
1115  mem += mySurf.getMemoryUsage(false);
1116  return mem;
1117  }
1118 
1119 public:
1121 };
1122 
1123 //___________________________________________________________________________
1124 //
1125 // Moving triangle ray intersection classes
1126 // - HTriangle is for hardened points
1127 //___________________________________________________________________________
1128 //
1130 {
1131 public:
1133  GEO_ConstPrimitiveP prim0, int serialidx,
1134  GA_Offset p00, GA_Offset p01,
1135  GA_Offset p02,
1136  GEO_ConstPrimitiveP prim1,
1137  GA_Offset p10, GA_Offset p11,
1138  GA_Offset p12);
1139  virtual ~GU_RayMovingTriangleInfo();
1140 
1141  virtual void init(const GEO_Detail &geo);
1142 
1143  virtual int intersect(
1144  const GEO_Detail &geo,
1145  const UT_Vector3 &org,
1146  const UT_Vector3 &dir,
1147  GU_RayInfo &hitinfo);
1148 
1149  virtual int64 getMemoryUsage(bool inclusive) const
1150  {
1151  int64 mem = inclusive ? sizeof(*this) : 0;
1152  return mem;
1153  }
1154 
1155 private:
1156  int insertHit(
1157  const GEO_Detail &geo,
1158  const UT_Vector3 &org,
1159  const UT_Vector3 &dir,
1160  GU_RayInfo &hitinfo,
1161  float t,
1162  float nt);
1163 
1164 public:
1166  GA_Offset myV0[3]; // Three corner vertices at t = 0
1167  GA_Offset myV1[3]; // Three corner vertices at t = 1
1168 
1169  double a2, a1, a0; // Coefficients of x comp of normal
1170  double b2, b1, b0; // Coefficients of y comp of normal
1171  double c2, c1, c0; // Coefficients of z comp of normal
1172 };
1173 
1174 
1175 #endif
GLint first
Definition: glcorearb.h:404
UT_VDBType myVDBType
TS_MetaExpressionPtr myExprRef
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:133
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
static void build(const FUNCTOR &functor, const GEO_PrimNURBSurf *nurbsurf, int *pinfonum=nullptr)
int isRational() const
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
UT_BoundingBox bbox
const float myW
UT_VoxelArrayF myMinMap
volatile int myDirty
unsigned getUOrder(void) const
Definition: GEO_TPSurf.h:382
const UT_Array< GA_Offset > pts
virtual int minimum(const GEO_Detail &geo, const UT_Vector3 &p, GU_MinInfo &mininfo)
const GLdouble * v
Definition: glcorearb.h:836
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
UT_UniquePtr< GU_RayRBezCurve > myCurve
virtual void init(const GEO_Detail &geo)
UT_Vector3T< float > UT_Vector3
UT_ThreadSpecificValue< TS_MetaExpressionPtr > myMetaExprCopies
virtual int minimumPrim(const GEO_Detail &geo, const GEO_Detail &prim_geo, GU_RayPrimInfo *prim, GU_MinInfo &mininfo)
virtual int intersectPrim(const GEO_Detail &geo, const GEO_Detail &prim_geo, GU_RayPrimInfo *prim, GU_RayInfo &hitinfo)
GEO_PrimVolumeXform myXform
GU_RayCurveInfo(GEO_ConstPrimitiveP curve, int serialidx, bool is_first_span, bool is_last_span)
GLint y
Definition: glcorearb.h:102
UT_VDBType
Definition: UT_VDBUtils.h:11
float tscale
exint size() const
Definition: UT_Array.h:451
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
static void build(const FUNCTOR &functor, const GEO_PrimRBezSurf *bezsurf, int *pinfonum=nullptr)
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
long long int64
Definition: SYS_Types.h:107
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:2007
GLfloat f
Definition: glcorearb.h:1925
unsigned getVOrder(void) const
Definition: GEO_TPSurf.h:383
UT_Vector3 org
int isRational() const
const openvdb::GridBase * myGridRawPtr
GU_RayRBezSurf mySurf
int64 exint
Definition: SYS_Types.h:116
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
GA_Basis * getVBasis(void) const
Definition: GEO_TPSurf.h:379
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
const float myW
static void build(const FUNCTOR &functor, const GEO_PrimRBezCurve *bezcurve, int *pinfonum=nullptr)
SYS_FORCE_INLINE int getNumRows() const
Definition: GEO_Hull.h:365
GEO_ConstPrimitiveP myPrim2
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GA_PrimitiveP_T< const GEO_Primitive, const GEO_Detail > GEO_ConstPrimitiveP
NURBS basis classes which maintain knot vectors.
Definition: GA_NUBBasis.h:44
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
virtual ~GU_RayCurveInfo()
float localDist(float t) const
#define GU_API
Definition: GU_API.h:12
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
const UT_VoxelArrayF * mySamples
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
SYS_FORCE_INLINE GEO_ConstPrimitiveP primP(const GEO_Detail &geo) const
GEO_PrimVolumeXform myXform
UT_VoxelMipMapF myMinMM
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
FloatPtrArray yval
static void build(const FUNCTOR &functor, const GEO_PrimNURBCurve *nurbcurve, int *pinfonum=nullptr)
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
GU_API UT_Vector3 GUfindPointInsideTet(float dots[4], const float A[4]) noexcept
const GA_Basis * getBasis(void) const
Definition: GEO_Curve.h:293
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
FloatPtrArray xval
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
const GA_KnotVector & getVector() const
Definition: GA_Basis.h:372
GLint GLenum GLint x
Definition: glcorearb.h:408
virtual GA_Size getVertexCount() const final
Definition: GEO_TriMesh.h:142
GA_Offset myPrimOffset
virtual int64 getMemoryUsage(bool inclusive) const =0
Report approximate memory usage.
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
SYS_FORCE_INLINE int getNumCols() const
Definition: GEO_Hull.h:372
UT_ThreadSpecificValue< void * > myCache
GU_RayRBezCurve myCurve
GLboolean r
Definition: glcorearb.h:1221
static exint count(const GEO_PrimRBezSurf *bezsurf)
virtual unsigned getOrder(void) const
SYS_AtomicCounter refCount
GA_Basis * getUBasis(void) const
Definition: GEO_TPSurf.h:378
virtual UT_Vector3 getNormal(const UT_Vector3 &uvw) const
virtual int64 getMemoryUsage(bool inclusive) const
Report approximate memory usage.
virtual int64 getMemoryUsage(bool inclusive) const
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)