HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GU_RayRBezSurf.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: RayIntersect objects handling surfaces.
9  *
10  */
11 
12 #ifndef __GU_RayRBezSurf_h__
13 #define __GU_RayRBezSurf_h__
14 
15 #include "GU_API.h"
16 #include <UT/UT_Matrix4.h>
17 #include <UT/UT_Matrix3.h>
18 #include <UT/UT_Vector3.h>
19 #include <UT/UT_Vector4Array.h>
20 #include <UT/UT_RefMatrix.h>
21 #include <UT/UT_Matrix.h>
22 #include <UT/UT_BoundingBox.h>
23 #include <UT/UT_BoundingRect.h>
24 
25 class GEO_Primitive;
26 class GU_RayInfo;
27 class GU_MinInfo;
28 class GU_RayRBezCurve;
29 class GU_RayRBezSurf;
30 class GU_IsectCurveSet;
31 class GU_IsectCurve;
32 
33 
34 //
35 // The actual functional unit of hulls, a single bezier patch.
36 //
38 {
39 public:
41  ~GU_RayRBezSurf();
42  void init(int uOrder, int vOrder,
43  float uStart, float uLength,
44  float vStart, float vLength, int isRational);
45 
46  void buildBBox();
47 
48  // Finds isection of bbox with specified ray
49  int intersectBBox(const UT_Vector3 &org, const UT_Vector3 &dir,
50  float tmax, float tol, float *t);
51 
52  // Finds intersection of this surface with ray/primitive.
53  int intersect(const UT_Vector3 &org,
54  const UT_Vector3 &dir,
55  GU_RayInfo &hitInfo, int depth,
56  int noBBoxTest = 0 );
57  int intersectQR(const UT_Vector3 &org,
58  const UT_Vector3 &dir,
59  GU_RayInfo &hitInfo, int depth,
60  int noBBoxTest = 0 );
61  int intersectAP(const UT_Vector3 &org,
62  const UT_Vector3 &dir,
63  GU_RayInfo &hitInfo);
64  int intersect(GU_RayRBezSurf &surf, GU_RayInfo &hitinfo);
65 
66  // Finds minimum point of this surface with specifed point/primitive.
67  int minimum(const UT_Vector3 &p,
68  GU_MinInfo &mininfo, int depth,
69  int noBBoxTest = 0 );
70  int minimum(GU_RayRBezSurf &surf, GU_MinInfo &mininfo,
71  int depth, int noBBoxTest = 0);
72 
73  // Finds closest point on the surface to p, returning in u, v.
74  // d2 is the resulting distance squared & tol is the maximum allowed.
75  int pointInvert(const UT_Vector3 &p, float &u, float &v,
76  float &d2, float tol);
77  // Cut the surface between the specified points, performing operation
78  // in place
79  void carveU(float ustart, float uend);
80  void carveV(float vstart, float vend);
81  // Split myself, locking to ensure no double splits
82  void splitMyself(int depth);
83  // Split the surface evenly into 4 quadrants.
84  void split(GU_RayRBezSurf *topLeft,
85  GU_RayRBezSurf *bottomLeft,
86  GU_RayRBezSurf *bottomRight,
87  GU_RayRBezSurf *topRight) const;
88  void evaluate(float u, float v, UT_Vector3 &pos) const;
89  void evaluateHomogeneous(float u, float v, UT_Vector4 &pos,
90  UT_Vector4 &derU, UT_Vector4 &derV) const;
91  void evaluate(float u, float v, UT_Vector3 &pos,
92  UT_Vector3 &derU, UT_Vector3 &derV,
93  UT_Vector3 &derUV,
94  UT_Vector3 &derUU, UT_Vector3 &derVV) const;
95  // patches will be initialized with topleft, bottomleft, bottomright, topright
96  // sortvalue should be 4 floats already having their sort values
97  // sortvalue will end up with the sort value for the corresponding
98  // patches[]
99  void sortSubPatches(GU_RayRBezSurf **patches, float *sortvalue) const;
100  void guessIntersection(const UT_Vector3 &org,
101  const UT_Vector3 &dir,
102  float &t, float &u, float &v) const;
103  void guessIntersection(const UT_Vector3 &org,
104  float &u, float &v) const;
105 
106  void buildImplicit();
107 
108  int64 getMemoryUsage(bool inclusive) const
109  {
110  int64 mem = inclusive ? sizeof(*this) : 0;
111  mem += myCV.getMemoryUsage(false);
112  mem += mySplitLock.getMemoryUsage(false);
113  mem += myXCoeff.getMemoryUsage(false);
114  mem += myYCoeff.getMemoryUsage(false);
115  mem += myZCoeff.getMemoryUsage(false);
116  mem += myWCoeff.getMemoryUsage(false);
117  if (myTopLeft)
118  {
119  mem += myTopLeft->getMemoryUsage(true);
120  mem += myBottomLeft->getMemoryUsage(true);
121  mem += myTopRight->getMemoryUsage(true);
122  mem += myBottomRight->getMemoryUsage(true);
123  }
124  return mem;
125  }
126 
127 private:
128  void buildPowerCoeffs(UT_MatrixF &A, int index) const;
129 
130  // The logic of all this is surf is intersected with this. Thus,
131  // in the point array the x, y are this' u,v coordinates and
132  // z, w are surf's u,v coords. Also, domain is in terms of
133  // surf's space, not this.
134  int domainDecomposition(GU_IsectCurveSet &curveset,
135  GU_RayRBezSurf &surf,
136  const UT_BoundingRect &domain,
137  UT_Vector4Array &points,
138  float intersecttol = 1e-6F,
139  float domaintol = 1e-2F,
140  float steprate = 1e-2F, int dividedir=0);
141  // Returns 0 if successfuly traces from start to finish. -1 if
142  // leaves source or base surface without converging, and -2 if
143  // hits a cusp which prevents further travel. Whatever portion
144  // of the curve is generated can be found in isectcurve.
145  // If trace fails, one should try again with opposite sign for
146  // direction.
147  int traceIsectCurve(GU_IsectCurve &isectcurve,
148  GU_RayRBezSurf &surf,
149  const UT_BoundingRect &domain,
150  const UT_Vector4 &start, const UT_Vector4 &end,
151  float tol = 1e-6F, float domaintol = 1e-2F,
152  float steprate = 1.0f/100.0f,
153  int canreverse = 1, int direction = 1);
154 
155  // Uses inverse power iterations to reconverge back to the isect
156  // curve from u, v by adjusting the v position.
157  // Return -1 if converging failed (Use smaller step size!)
158  int polishInV(GU_RayRBezSurf &surf, float u, float v,
159  float &vresult, float &invu, float &invv,
160  float tol = 1e-4F, int maxiter = 30);
161  int polishInU(GU_RayRBezSurf &surf, float u, float v,
162  float &uresult, float &invu, float &invv,
163  float tol = 1e-4F, int maxiter = 30);
164  int polishCurve(GU_RayRBezCurve &curve, float &t,
165  float &invu, float &invv, float tol,
166  int maxiter);
167  int polishCurveSlow(GU_RayRBezCurve &curve, float &t, float tol,
168  int maxiter);
169 
170  void extractUIsoparm(GU_RayRBezCurve &curve, float u) const;
171  void extractVIsoparm(GU_RayRBezCurve &curve, float v) const;
172 
173  void isectEdges(GU_RayRBezSurf &surf,
174  UT_Vector4Array &pointlist,
175  float tol = 1e-6F, float ttol = 1e-2F);
176  void isectIsoU(GU_RayRBezSurf &surf,
177  float u, float vstart, float vend,
178  UT_Vector4Array &pointlist,
179  float tol = 1e-6F, float ttol = 1e-2F, int useAP=1);
180  void isectIsoV(GU_RayRBezSurf &surf,
181  float v, float ustart, float uend,
182  UT_Vector4Array &pointlist,
183  float tol = 1e-6F, float ttol = 1e-2F, int useAP=1);
184 
185 public:
188  float myUStart, myULength;
189  float myVStart, myVLength;
190  float sortValue;
192  GU_RayRBezSurf *myTopLeft, *myBottomLeft;
193  GU_RayRBezSurf *myTopRight, *myBottomRight;
194 
196  volatile bool myHasSplit;
197 
199  // Is eigenvalues recoverable?
201  // Coeff arrays are:
202  // [a ba b2a ... b(2n-1)a] coeff [y ]
203  // [xy ]
204  // [... ]
205  // [x(2m-1)y]
206  // where a = [1 a ... a(m-1)] and
207  // y = [1 y ... y(n-1)]
208  // and m = udeg, n = vdeg
209  // This is only true if they are still the full size matrices!
210  // If they have been reduced to eliminate base points, this order
211  // is changed in an effectively uninvertable manner.
212  UT_MatrixF myXCoeff, myYCoeff, myZCoeff, myWCoeff;
213 };
214 
215 
216 #endif
217 
const GLdouble * v
Definition: glcorearb.h:836
IMF_EXPORT IMATH_NAMESPACE::V3f direction(const IMATH_NAMESPACE::Box2i &dataWindow, const IMATH_NAMESPACE::V2f &pixelPosition)
GLuint start
Definition: glcorearb.h:474
GU_RayRBezSurf * myTopLeft
UT_MatrixF myZCoeff
long long int64
Definition: SYS_Types.h:100
GLfloat f
Definition: glcorearb.h:1925
GLint GLint GLsizei GLsizei GLsizei depth
Definition: glcorearb.h:475
bool intersect(const Line3< T > &line, const Vec3< T > &v0, const Vec3< T > &v1, const Vec3< T > &v2, Vec3< T > &pt, Vec3< T > &barycentric, bool &front)
UT_BoundingBox myBBox
GLuint GLuint end
Definition: glcorearb.h:474
#define GU_API
Definition: GU_API.h:11
GLuint index
Definition: glcorearb.h:785
volatile bool myHasSplit
GU_RayRBezSurf * myTopRight
int64 getMemoryUsage(bool inclusive) const
UT_RefMatrix< UT_Vector4 > myCV