HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_Plane.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_Plane.h (UT Library, C++)
7  *
8  * COMMENTS:
9  * A 3D plane.
10  *
11  */
12 
13 #ifndef __UT_Plane_h__
14 #define __UT_Plane_h__
15 
16 #include "UT_API.h"
17 #include "UT_Assert.h"
18 #include "UT_Axis.h"
19 #include "UT_Vector3.h"
20 #include "UT_VectorTypes.h"
21 #include <SYS/SYS_Deprecated.h>
22 #include <SYS/SYS_Types.h>
23 
24 // The 3 classic types of planes. Evidently, a UT_PlaneT object can be
25 // an arbitrary plane, but it helps to have some defaults.
27 {
31 };
32 
33 template <typename T>
34 class UT_PlaneT
35 {
36 public:
37 
38  // Several constructors that define a plane as (X - point)*normal = 0
39  UT_PlaneT(
40  UT_PlaneType plane_type = UT_PLANE_XY);
41  UT_PlaneT(
42  const UT_Vector3T<T> &pt,
43  UT_PlaneType plane_type = UT_PLANE_XY);
44  UT_PlaneT(
45  const UT_Vector3T<T> &apoint,
46  const UT_Vector3T<T> &norm_dir,
47  bool norm = true);
48  UT_PlaneT(
49  const UT_Vector3T<T> &p0,
50  const UT_Vector3T<T> &p1,
51  const UT_Vector3T<T> &p2);
52  UT_PlaneT(
53  const UT_Vector4T<T> &p);
54 
55  ~UT_PlaneT();
56 
57  // Intersect a line defined parametrically as 'p + t*v' with this plane.
58  // If the line runs parallel to the plane, both methods return "max"
59  // as the intersection point. The second method also returns -1; if not
60  // parallel, it returns 0.
62  const UT_Vector3T<T> &p,
63  const UT_Vector3T<T> &v) const;
64  int intersectLine(
65  const UT_Vector3T<T> &p,
66  const UT_Vector3T<T> &v,
67  UT_Vector3T<T> &hit) const;
68  int intersectRay(
69  const UT_Vector3T<T> &p,
70  const UT_Vector3T<T> &v,
71  UT_Vector3T<T> &hit) const;
72 
73  // We occasionally need to find the intersection of a line with this
74  // plane shifted to another position (ie. myPoint changes but myNormal
75  // doesn't). offset_pt is a point on the shifted plane.
76  int intersectLine(
77  const UT_Vector3T<T> &offset_pt,
78  const UT_Vector3T<T> &p,
79  const UT_Vector3T<T> &v,
80  UT_Vector3T<T> &hit) const;
81  int intersectRay(
82  const UT_Vector3T<T> &offset_pt,
83  const UT_Vector3T<T> &p,
84  const UT_Vector3T<T> &v,
85  UT_Vector3T<T> &hit) const;
86 
87  // Find the projection of point p on the plane. The second method
88  // returns the signed distance to the plane.
89  UT_Vector3T<T> project(const UT_Vector3T<T> &p) const;
90  T project(
91  const UT_Vector3T<T> &p,
92  UT_Vector3T<T> &projection) const;
93 
94  // Find the point symmetric to p and store it in p:
95  void symmetry(UT_Vector3T<T> &p) const;
96 
97  // Find out if the plane contains the point p and return true or false.
98  bool contains(const UT_Vector3T<T> &p) const;
99 
100  // Finds if the given point is on one side or the other. The side
101  // in direction of the normal is 1, the other is 0.
102  int side(const UT_Vector3T<T> &p) const;
103 
104  // Query the point and the normal;
105  const UT_Vector3T<T> & point() const
106  { return myPoint; }
107  void setPoint(const UT_Vector3T<T> &p)
108  { myPoint = p; }
109  const UT_Vector3T<T> & normal() const
110  { return myNormal; }
112  {
113  myNormal = n;
114  UT_ASSERT(SYSisEqual(myNormal.length2(), 1));
115  }
117  {
118  myNormal = n;
119  myNormal.normalize();
120  }
121  void setNormal(UT_PlaneType plane_type)
122  {
123  switch (plane_type)
124  {
125  case UT_PLANE_XY:
126  myNormal.assign(0.0, 0.0, 1.0);
127  break;
128  case UT_PLANE_YZ:
129  myNormal.assign(1.0, 0.0, 0.0);
130  break;
131  default:
132  UT_ASSERT(!"Invalid plane type");
134  case UT_PLANE_XZ:
135  myNormal.assign(0.0, 1.0, 0.0);
136  break;
137  }
138  }
139 
140  // Flip by 180 degrees:
141  void negate();
142 
143  // Rotate by a given angle, expressed in radians:
144  void rotate(
145  UT_Vector3T<T> &axis,
146  T theta,
147  bool norm = true);
148  void rotate(UT_Axis3::axis a, T theta);
149 
150  // Only rotate the point or normal
151  void rotatePoint(const UT_Matrix3T<T> &rot_matx)
152  {
153  myPoint *= rot_matx;
154  }
155  void rotateNormal(const UT_Matrix3T<T> &rot_matx,
156  bool norm = true)
157  {
158  myNormal *= rot_matx;
159  if (norm)
160  myNormal.normalize();
161  }
162 
163  // Apply an invertible transformation to the plane: the method that takes
164  // a non-const matrix returns the inverted and transposed matrix but will
165  // be removed in the future. Use transformAndReturnNormalXform() if that
166  // is really what you want, otherwise cast to a const reference.
167  void transform(const UT_Matrix4F &matx);
168  SYS_DEPRECATED(17.0)
169  void transform( UT_Matrix4F &matx);
170  void transform(const UT_Matrix4D &matx);
171  SYS_DEPRECATED(17.0)
172  void transform( UT_Matrix4D &matx);
173 
174  // Apply an invertible transformation to the plane and return the inverted
175  // and transposed matrix in the non-const argument.
178 
179  // Translate the plane along the normal by the given factor.
180  void shiftOffset(T by_factor)
181  {
182  myPoint += (myNormal * by_factor);
183  }
184 
186  {
187  myPoint += offset;
188  }
189 
190 private:
191  static const UT_Vector3T<T> theInvalidHit;
192 
193  // The defining point and normal:
194  UT_Vector3T<T> myPoint;
195  UT_Vector3T<T> myNormal;
196 };
197 
201 typedef UT_PlaneT<float> UT_Plane; // deprecated
202 
203 #include "UT_PlaneImpl.h"
204 
205 #endif // __UT_Plane_h__
UT_Vector3T< T > project(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:224
UT_PlaneT< fpreal32 > UT_PlaneF
Definition: UT_Plane.h:199
void setVectorAsNormal(const UT_Vector3T< T > &n)
Definition: UT_Plane.h:116
UT_PlaneT< fpreal > UT_PlaneR
Definition: UT_Plane.h:198
#define SYS_DEPRECATED(__V__)
const GLdouble * v
Definition: glcorearb.h:836
void rotatePoint(const UT_Matrix3T< T > &rot_matx)
Definition: UT_Plane.h:151
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1221
void setNormal(UT_PlaneType plane_type)
Definition: UT_Plane.h:121
3D Vector class.
4D Vector class.
Definition: UT_Vector4.h:155
void transform(const UT_Matrix4F &matx)
Definition: UT_PlaneImpl.h:265
const UT_Vector3T< T > & normal() const
Definition: UT_Plane.h:109
UT_Vector3T< T > intersect(const UT_Vector3T< T > &p, const UT_Vector3T< T > &v) const
Definition: UT_PlaneImpl.h:92
void setPoint(const UT_Vector3T< T > &p)
Definition: UT_Plane.h:107
GLdouble n
Definition: glcorearb.h:2007
UT_PlaneT< float > UT_Plane
Definition: UT_Plane.h:201
bool contains(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:321
void setNormal(const UT_Vector3T< T > &n)
Definition: UT_Plane.h:111
#define SYS_FALLTHROUGH
Definition: SYS_Compiler.h:75
GLintptr offset
Definition: glcorearb.h:664
void rotateNormal(const UT_Matrix3T< T > &rot_matx, bool norm=true)
Definition: UT_Plane.h:155
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
void transformAndReturnNormalXform(UT_Matrix4F &matx)
Definition: UT_PlaneImpl.h:276
void translate(const UT_Vector3T< T > &offset)
Definition: UT_Plane.h:185
int side(const UT_Vector3T< T > &p) const
Definition: UT_PlaneImpl.h:328
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
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:126
const UT_Vector3T< T > & point() const
Definition: UT_Plane.h:105
#define const
Definition: zconf.h:214
UT_PlaneT(UT_PlaneType plane_type=UT_PLANE_XY)
Definition: UT_PlaneImpl.h:32
void shiftOffset(T by_factor)
Definition: UT_Plane.h:180
UT_PlaneT< fpreal64 > UT_PlaneD
Definition: UT_Plane.h:200