HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_PlaneImpl.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: UT_PlaneImpl.h (UT Library, C++)
7  *
8  * COMMENTS:
9  * A 3D plane.
10  *
11  */
12 
13 #ifndef __UT_PLANEIMPL_H_INCLUDED__
14 #define __UT_PLANEIMPL_H_INCLUDED__
15 
16 #include "UT_Assert.h"
17 #include "UT_Vector3.h"
18 #include "UT_Vector4.h"
19 #include "UT_Matrix3.h"
20 #include "UT_Matrix4.h"
21 #include <SYS/SYS_Math.h>
22 #include <limits>
23 
24 
25 template <typename T>
30 
31 template <typename T>
33  : myPoint(0, 0, 0)
34 {
35  setNormal(plane_type);
36 }
37 
38 template <typename T>
40  : myPoint(pt)
41 {
42  setNormal(plane_type);
43 }
44 
45 template <typename T>
47  const UT_Vector3T<T> &apoint,
48  const UT_Vector3T<T> &norm_dir,
49  bool norm
50  )
51  : myPoint(apoint)
52  , myNormal(norm_dir)
53 {
54  if (norm) myNormal.normalize();
55 }
56 
57 template <typename T>
59  : myPoint(0, 0, 0)
60  , myNormal(p.x(), p.y(), p.z())
61 {
62  if (p.z())
63  myPoint.z() = -p.w()/p.z();
64  else if (p.y())
65  myPoint.y() = -p.w()/p.y();
66  else if (p.x())
67  myPoint.x() = -p.w()/p.x();
68 }
69 
70 template <typename T>
72  const UT_Vector3T<T> &p0,
73  const UT_Vector3T<T> &p1,
74  const UT_Vector3T<T> &p2
75  )
76  : myPoint(p0)
77 {
78  UT_Vector3T<T> v = p1-p0;
79  myNormal = p2-p0;
80  myNormal.cross(v);
81  myNormal.normalize();
82 }
83 
84 template <typename T>
86 {
87  // Nothing else needed.
88 }
89 
90 template <typename T>
93 {
94  T tnom = dot( (myPoint-p), myNormal );
95  T tden = dot( v, myNormal );
96  if (SYSequalZero(tden))
97  {
98  UT_ASSERT( !"Line segment does not intersect with plane" );
99  return theInvalidHit;
100  }
101  else
102  {
103  return (p + tnom/tden * v);
104  }
105 }
106 
107 template <typename T>
108 int
110  const UT_Vector3T<T> &p,
111  const UT_Vector3T<T> &v,
112  UT_Vector3T<T> &hit
113  ) const
114 {
115  T tnom = dot( (myPoint-p), myNormal );
116  T tden = dot( v, myNormal );
117 
118  // If the numerator and the denominator don't have the same sign then
119  // the ray doesn't intersect with the plane.
120  if (SYSequalZero(tden))
121  {
122  hit = theInvalidHit;
123  return -1;
124  }
125  else
126  {
127  hit = (p + tnom/tden * v);
128  return 0;
129  }
130 }
131 
132 template <typename T>
133 int
135  const UT_Vector3T<T> &p,
136  const UT_Vector3T<T> &v,
137  UT_Vector3T<T> &hit
138  ) const
139 {
140  T tnom = dot( (myPoint-p), myNormal );
141  T tden = dot( v, myNormal );
142 
143  // If the numerator and the denominator don't have the same sign then
144  // the ray doesn't intersect with the plane.
145  if (SYSequalZero(tden) || (tnom/tden) < 0.)
146  {
147  hit = theInvalidHit;
148  return -1;
149  }
150  else
151  {
152  hit = (p + tnom/tden * v);
153  return 0;
154  }
155 }
156 
157 template <typename T>
158 int
160  const UT_Vector3T<T> &offset_pt,
161  const UT_Vector3T<T> &p,
162  const UT_Vector3T<T> &v,
163  UT_Vector3T<T> &hit
164  ) const
165 {
166  T tnom = dot( (offset_pt-p), myNormal );
167  T tden = dot( v, myNormal );
168 
169  if (SYSequalZero(tden))
170  {
171  hit = theInvalidHit;
172  return -1;
173  }
174  else
175  {
176  hit = (p + tnom/tden * v);
177  return 0;
178  }
179 }
180 
181 template <typename T>
182 int
184  const UT_Vector3T<T> &offset_pt,
185  const UT_Vector3T<T> &p,
186  const UT_Vector3T<T> &v,
187  UT_Vector3T<T> &hit
188  ) const
189 {
190  T tnom = dot( (offset_pt-p), myNormal );
191  T tden = dot( v, myNormal );
192 
193  // If the numerator and the denominator don't have the same sign then
194  // the ray doesn't intersect with the plane.
195  if (SYSequalZero(tden) || (tnom/tden) < 0.)
196  {
197  hit = theInvalidHit;
198  return -1;
199  }
200  else
201  {
202  hit = (p + tnom/tden * v);
203  return 0;
204  }
205 }
206 
207 template <typename T>
208 void
210 {
211  myNormal.negate();
212 }
213 
214 template <typename T>
215 void
217 {
218  T tnom = dot( (myPoint-p), myNormal );
219  p += 2.0 * tnom/myNormal.length2() * myNormal;
220 }
221 
222 template <typename T>
225 {
226  T tnom = dot( (myPoint-p), myNormal );
227  return (p + tnom/myNormal.length2() * myNormal);
228 }
229 
230 template <typename T>
231 T
233 {
234  T tnom = dot( (myPoint-p), myNormal );
235  projection = p + tnom/myNormal.length2() * myNormal;
236  return tnom;
237 }
238 
239 template <typename T>
240 void
241 UT_PlaneT<T>::rotate(UT_Vector3T<T> &axis, T theta, bool norm)
242 {
243  UT_Matrix3 rMat;
244  rMat = UT_Matrix3::rotationMat(axis, theta, norm);
245  myPoint *= rMat;
246  rMat.invert(); rMat.transpose();
247  myNormal *= rMat;
248  myNormal.normalize();
249 }
250 
251 template <typename T>
252 void
254 {
255  UT_Matrix3 rMat;
256  rMat = UT_Matrix3::rotationMat(a, theta);
257  myPoint *= rMat;
258  rMat.invert(); rMat.transpose();
259  myNormal *= rMat;
260  myNormal.normalize();
261 }
262 
263 template <typename T>
264 void
266 {
267  myPoint *= matx;
268  UT_Matrix4F nml_matx(matx);
269  nml_matx.invert(); nml_matx.transpose();
270  myNormal *= nml_matx;
271  myNormal.normalize();
272 }
273 
274 template <typename T>
275 void
277 {
278  myPoint *= matx;
279  matx.invert(); matx.transpose();
280  myNormal *= matx;
281  myNormal.normalize();
282 }
283 
284 template <typename T>
285 void
287 {
288  myPoint *= matx;
289  UT_Matrix4D nml_matx(matx);
290  nml_matx.invert(); nml_matx.transpose();
291  myNormal *= nml_matx;
292  myNormal.normalize();
293 }
294 
295 template <typename T>
296 void
298 {
299  myPoint *= matx;
300  matx.invert(); matx.transpose();
301  myNormal *= matx;
302  myNormal.normalize();
303 }
304 
305 template <typename T>
306 bool
308 {
309  return SYSequalZero(dot(p-myPoint, myNormal)) ? 1 : 0;
310 }
311 
312 template <typename T>
313 T
315 {
316  return dot(p-myPoint, myNormal);
317 }
318 
319 template <typename T>
320 int
322 {
323  return (dot(p-myPoint, myNormal) > 0) ? 1 : 0;
324 }
325 
326 #endif // __UT_PLANEIMPL_H_INCLUDED__
constexpr SYS_FORCE_INLINE T length2() const noexcept
Definition: UT_Vector3.h:356
UT_Vector3T< T > project(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:224
static UT_Matrix3T< float > rotationMat(UT_Vector3T< S > &axis, floattheta, int norm=1)
constexpr SYS_FORCE_INLINE T & y() noexcept
Definition: UT_Vector4.h:493
const GLdouble * v
Definition: glcorearb.h:837
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
GLint y
Definition: glcorearb.h:103
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:174
void transpose()
Definition: UT_Matrix3.h:653
void transform(const UT_Matrix4F &matx)
Definition: UT_PlaneImpl.h:265
UT_Vector3T< T > intersect(const UT_Vector3T< T > &p, const UT_Vector3T< T > &v) const
Definition: UT_PlaneImpl.h:92
constexpr SYS_FORCE_INLINE T & x() noexcept
Definition: UT_Vector4.h:491
constexpr SYS_FORCE_INLINE T & z() noexcept
Definition: UT_Vector4.h:495
bool contains(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:307
void setNormal(const UT_Vector3T< T > &n)
Definition: UT_Plane.h:115
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:130
int intersectLine(const UT_Vector3T< T > &p, const UT_Vector3T< T > &v, UT_Vector3T< T > &hit) const
Definition: UT_PlaneImpl.h:109
void rotate(UT_Vector3T< T > &axis, T theta, bool norm=true)
Definition: UT_PlaneImpl.h:241
GLint GLenum GLint x
Definition: glcorearb.h:409
void transformAndReturnNormalXform(UT_Matrix4F &matx)
Definition: UT_PlaneImpl.h:276
bool SYSequalZero(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:1069
int side(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:321
int intersectRay(const UT_Vector3T< T > &p, const UT_Vector3T< T > &v, UT_Vector3T< T > &hit) const
Definition: UT_PlaneImpl.h:134
void symmetry(UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:216
void negate()
Definition: UT_PlaneImpl.h:209
UT_PlaneType
Definition: UT_Plane.h:26
constexpr SYS_FORCE_INLINE T & w() noexcept
Definition: UT_Vector4.h:497
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int invert(T tol=0.0F)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
UT_PlaneT(UT_PlaneType plane_type=UT_PLANE_XY)
Definition: UT_PlaneImpl.h:32
T distance(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:314
void transpose()
Definition: UT_Matrix4.h:509