HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimHyperboloid.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: GT_PrimHyperboloid.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_PrimHyperboloid__
12 #define __GT_PrimHyperboloid__
13 
14 #include "GT_API.h"
15 #include "GT_PrimQuadric.h"
16 #include <UT/UT_VectorTypes.h>
17 
18 /// Generic hyperboloid primitive
19 ///
20 /// The hyperboloid primitive is a parametric surface defined by revolving a
21 /// line segment around the z azis.
22 /// Given the hyperboloid is defined by points <em>p0</em>, <em>p1</em> and
23 /// parametric coordinates <em>u</em> and <em>v</em>: @code
24 /// fpreal theta = u * 2 * PI;
25 /// UT_Vector3D P = lerp(p0, p1, v);
26 /// x = P.x() * cos(theta) - P.y() * sin(theta);
27 /// y = P.z() * sin(theta) + P.y() * cos(theta);
28 /// z = P.z();
29 /// @endcode
30 ///
31 /// Examples:
32 /// - A tube @code
33 /// PrimHyperboloid( UT_Vector3(1, 0, -.5), UT_Vector3(1, 0, .5), ...);
34 /// @endcode
35 /// - A cone @code
36 /// PrimHyperboloid( UT_Vector3(0, 0, -.5), UT_Vector3(1, 0, .5), ...);
37 /// @endcode
38 /// - A circle @code
39 /// PrimHyperboloid( UT_Vector3(0, 0, 0), UT_Vector3(1, 0, 0), ...);
40 /// @endcode
41 ///
43 {
44 public:
46  { }
48  const UT_Vector3D &p1,
52  : GT_PrimQuadric(attribs, transform, uv)
53  , myP0(p0)
54  , myDP(p1 - p0)
55  { }
57  : GT_PrimQuadric(src)
58  , myP0(src.myP0)
59  , myDP(src.myDP)
60  { }
62  : GT_PrimQuadric(src, uv)
63  , myP0(src.myP0)
64  , myDP(src.myDP)
65  { }
66  ~GT_PrimHyperboloid() override;
67 
68  const char *className() const override
69  { return "GT_PrimHyperboloid"; }
70  bool save(UT_JSONWriter &w) const override
71  {
72  jsonWriter j(w, "Hyperboloid");
73  bool ok = true;
74  ok = ok && getP0().save(w);
75  ok = ok && getP1().save(w);
76  ok = ok && myUV.save(w);
77  ok = ok && getPrimitiveTransform()->save(w);
78  return ok && saveAttributeLists(w);
79  }
80 
81  /// @{
82  /// Methods defined on GT_Primitive
83  int getPrimitiveType() const override;
84  GT_PrimitiveHandle doHarden() const override;
85  GT_PrimitiveHandle doSoftCopy() const override
86  { return new GT_PrimHyperboloid(*this); }
87  /// @}
88 
89  /// Initialize hyperboloid with
90  /// @param p0 @n
91  /// First point defining hyperboloid axis
92  /// @param p1 @n
93  /// Second point defining hyperboloid axis
94  /// @param attribs @n
95  /// Attributes defined on the hyperboloid
96  /// @param transform @n
97  /// Transform on the hyperboloid
98  /// @param uv @n
99  /// The parametric range for the hyperboloid. For the hyperboloid, @b u
100  /// coordinate represents the rotation, while @b v represents the
101  /// interpolant between @c p0 and @c p1.
102  bool init(const UT_Vector3D &p0,
103  const UT_Vector3D &p1,
104  const GT_AttributeListHandle &attribs,
105  const GT_TransformHandle &transform,
106  const GT_Parametric &uv=GT_Parametric())
107  {
108  if (!GT_PrimQuadric::init(attribs, transform, uv))
109  return false;
110  myP0 = p0;
111  myDP = p1 - p0;
112  return true;
113  }
114 
115  /// @{
116  /// Accessor
117  const UT_Vector3D getP0() const { return myP0; }
118  const UT_Vector3D getP1() const { return myP0 + myDP; }
119  const UT_Vector3D getDP() const { return myDP; }
120  /// @}
121 
122 protected:
123  /// Clone a new hyperbolic sheet with a different parametric range
124  GT_PrimQuadric *clone(const GT_Parametric &uv) const override
125  {
126  return new GT_PrimHyperboloid(*this, uv);
127  }
128 
129  /// Hyperboloids can be evaluated with just 2 rows of data
131  GT_Size &nu, GT_Size &nv) const override;
132  /// @{
133  /// Methods defined on GT_PrimQuadric
134  void getQBounds(UT_BoundingBox &box) const override;
135  void fillQP(UT_Vector3F *P, GT_Size n,
136  const fpreal *u, fpreal v) const override;
137  void fillQP(UT_Vector3D *P, GT_Size n,
138  const fpreal *u, fpreal v) const override;
139  void fillQN(UT_Vector3F *N, GT_Size n,
140  const fpreal *u, fpreal v) const override;
141  void fillQN(UT_Vector3D *N, GT_Size n,
142  const fpreal *u, fpreal v) const override;
143  /// @}
144 
145 private:
146  UT_Vector3D myP0;
147  UT_Vector3D myDP;
148 };
149 
150 #endif
151 
const UT_Vector3D getDP() const
virtual void fillQN(UT_Vector3F *P, GT_Size n, const fpreal *u, fpreal v) const =0
virtual void adjustTesselationCounts(GT_Size &nu, GT_Size &nv) const
virtual int getPrimitiveType() const
GT_PrimitiveHandle doSoftCopy() const override
GA_API const UT_StringHolder uv
GT_PrimHyperboloid(const GT_PrimHyperboloid &src, const GT_Parametric &uv)
const char * className() const override
Class to keep track for a 2D parametric interval.
Definition: GT_Parametric.h:20
#define GT_API
Definition: GT_API.h:11
bool save(UT_JSONWriter &w) const override
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:35
GLenum src
Definition: glcorearb.h:1793
bool init(const GT_AttributeListHandle &attribs, const GT_TransformHandle &transform, const GT_Parametric &uv)
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
GLuint GLenum GLenum transform
Definition: glew.h:15055
const GLint * attribs
Definition: glew.h:14698
const GLdouble * v
Definition: glcorearb.h:837
GT_PrimQuadric * clone(const GT_Parametric &uv) const override
Clone a new hyperbolic sheet with a different parametric range.
GT_PrimHyperboloid(const GT_PrimHyperboloid &src)
const GT_TransformHandle & getPrimitiveTransform() const
Definition: GT_Primitive.h:111
virtual void fillQP(UT_Vector3F *P, GT_Size n, const fpreal *u, fpreal v) const =0
virtual GT_PrimitiveHandle doHarden() const
GLdouble n
Definition: glcorearb.h:2008
int64 GT_Size
Definition: GT_Types.h:123
const UT_Vector3D getP1() const
GLsizei const GLint box[]
Definition: glew.h:11654
fpreal64 fpreal
Definition: SYS_Types.h:277
const UT_Vector3D getP0() const
virtual void getQBounds(UT_BoundingBox &box) const =0
bool saveAttributeLists(UT_JSONWriter &w) const
GT_PrimHyperboloid(const UT_Vector3D &p0, const UT_Vector3D &p1, const GT_AttributeListHandle &attribs, const GT_TransformHandle &transform, const GT_Parametric &uv=GT_Parametric())
GA_API const UT_StringHolder N
bool init(const UT_Vector3D &p0, const UT_Vector3D &p1, const GT_AttributeListHandle &attribs, const GT_TransformHandle &transform, const GT_Parametric &uv=GT_Parametric())