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