HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GT_PrimQuadric.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_PrimQuadric.h ( GT Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __GT_PrimQuadric__
12 #define __GT_PrimQuadric__
13 
14 #include "GT_API.h"
15 #include "GT_Primitive.h"
16 #include "GT_Parametric.h"
17 #include "GT_Transform.h"
18 
20 {
21 public:
23  : myAttributes()
24  , myUV()
25  {}
29  : myAttributes(attribs)
30  {
31  setPrimitiveTransform(transform);
32  }
34  : myAttributes(src.myAttributes)
35  , myUV(src.myUV)
36  , GT_Primitive(src)
37  {
38  }
39  /// Copy the quadric, but with a different parametric range
41  : myAttributes(src.myAttributes)
42  , myUV(uv)
43  , GT_Primitive(src)
44  {
45  }
46  ~GT_PrimQuadric() override;
47 
48  const char *className() const override { return "GT_PrimQuadric"; }
49  bool saveQuadric(UT_JSONWriter &w, const char *name) const
50  {
51  jsonWriter j(w, name);
52  return myUV.save(*j) &&
53  getPrimitiveTransform()->save(*j) &&
55  }
56 
57  /// @{
58  /// Methods defined on GT_Primitive
59  void enlargeBounds(UT_BoundingBox boxes[],
60  int nsegments) const override;
61  int getMotionSegments() const override;
62  int64 getMemoryUsage() const override;
63  /// @}
64 
65  /// Initialize the quadric.
66  /// - @c attribs @n The attributes attached to the sphere
67  /// - @c transfrom @n An optional transform attribute.
68  /// The transform should be a 4x4 matrix.
69  bool init(const GT_AttributeListHandle &attribs,
70  const GT_TransformHandle &transform,
71  const GT_Parametric &uv);
72 
73  /// @{
74  /// Query state
76  { return myAttributes; }
78  { return myUV; }
79  /// @}
80 
81  /// @{
82  /// Access attributes
84  { return myAttributes; }
85  /// @}
86 
87  /// @{
88  /// Split in U or V
90  {
91  GT_Parametric right = myUV.splitU();
92  return GT_PrimitiveHandle(clone(right));
93  }
95  {
96  GT_Parametric top = myUV.splitV();
97  return GT_PrimitiveHandle(clone(top));
98  }
99  /// @}
100 
101  /// Method defined on GT_Primitive
102  bool refine(GT_Refine &refiner,
103  const GT_RefineParms *parms) const override;
104 
105  /// Viewport refinement options
106  const GT_ViewportRefineOptions &viewportRefineOptions() const override;
107 
108  /// Convenience method to refine to a polygon mesh
109  virtual GT_PrimitiveHandle refineToPolygonMesh(
110  const GT_RefineParms *parms) const;
111 
112  /// @{
113  /// Convert from parametric coordinates to position/normal. These methods
114  /// invoke the optimized "row" methods.
115  void getQP(UT_Vector3F &P, fpreal u, fpreal v) const
116  { fillQP(&P, 1, &u, v); }
117  void getQP(UT_Vector3D &P, fpreal u, fpreal v) const
118  { fillQP(&P, 1, &u, v); }
119  void getQN(UT_Vector3F &N, fpreal u, fpreal v) const
120  { fillQN(&N, 1, &u, v); }
121  void getQN(UT_Vector3D &N, fpreal u, fpreal v) const
122  { fillQN(&N, 1, &u, v); }
123  /// @}
124 
125  /// ------------- Sub-class methods ---------------------
126  /// Sub-class method to get the bounding box
127  virtual void getQBounds(UT_BoundingBox &box) const = 0;
128 
129  /// @{
130  /// Evaluate a "row" of position/normal data. The @c u data will have been
131  /// processed by @c prepareParametricU().
132  virtual void fillQP(UT_Vector3F *P, GT_Size n,
133  const fpreal *u, fpreal v) const=0;
134  virtual void fillQP(UT_Vector3D *P, GT_Size n,
135  const fpreal *u, fpreal v) const=0;
136  virtual void fillQN(UT_Vector3F *P, GT_Size n,
137  const fpreal *u, fpreal v) const=0;
138  virtual void fillQN(UT_Vector3D *P, GT_Size n,
139  const fpreal *u, fpreal v) const=0;
140  /// @}
141 
142  /// Given the u/v tesselation parameters, the sub-class can alter them if
143  /// it chooses.
144  virtual void adjustTesselationCounts(GT_Size &nu,
145  GT_Size &nv) const;
146 
147 protected:
148  /// Create a split primitive
149  virtual GT_PrimQuadric *clone(const GT_Parametric &uv) const = 0;
150 
151  /// Harden attributes etc.
152  void hardenAttributes();
153 
154  /// This method is called by the quadric refiner and may be called if you
155  /// choose to override the refine() method on the sub-class.
156  virtual GT_PrimitiveHandle createMesh(GT_Size nu, GT_Size nv,
157  fpreal u0, fpreal u1,
158  fpreal v0, fpreal v1,
159  bool create_normals=true,
160  bool create_uv=true,
161  GT_Storage Pstorage=GT_STORE_REAL32,
162  GT_Storage Nstorage=GT_STORE_REAL32) const;
163 
164  /// Extract refinement parameters
165  static void extractRefineParms(const GT_RefineParms *parms,
166  GT_Size &nu, GT_Size &nv,
167  fpreal &u0, fpreal &u1,
168  fpreal &v0, fpreal &v1);
169 
170  GT_AttributeListHandle myAttributes; // Uniform attributes
172 };
173 
174 #endif
GT_Parametric splitV()
Definition: GT_Parametric.h:51
void getQP(UT_Vector3D &P, fpreal u, fpreal v) const
GT_Storage
Definition: GT_Types.h:19
GT_PrimitiveHandle clone() const
Definition: GT_Primitive.h:119
virtual int getMotionSegments() const =0
const GT_AttributeListHandle & getDetailAttributes() const override
GT_PrimitiveHandle splitU()
virtual bool refine(GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
virtual const GT_ViewportRefineOptions & viewportRefineOptions() const
GT_Parametric myUV
GT_PrimitiveHandle splitV()
GT_Parametric splitU()
Definition: GT_Parametric.h:43
GA_API const UT_StringHolder uv
const GLdouble * v
Definition: glcorearb.h:837
GLdouble right
Definition: glad.h:2817
Class to keep track for a 2D parametric interval.
Definition: GT_Parametric.h:20
#define GT_API
Definition: GT_API.h:13
GT_AttributeListHandle myAttributes
const GT_AttributeListHandle & getAttributes() const
Class which writes ASCII or binary JSON streams.
Definition: UT_JSONWriter.h:37
GLdouble u1
Definition: glad.h:2676
void getQP(UT_Vector3F &P, fpreal u, fpreal v) const
GLdouble n
Definition: glcorearb.h:2008
GT_PrimQuadric(const GT_PrimQuadric &src, const GT_Parametric &uv)
Copy the quadric, but with a different parametric range.
long long int64
Definition: SYS_Types.h:116
const GT_TransformHandle & getPrimitiveTransform() const
Definition: GT_Primitive.h:111
GLuint const GLchar * name
Definition: glcorearb.h:786
GA_API const UT_StringHolder transform
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
virtual int64 getMemoryUsage() const =0
bool saveQuadric(UT_JSONWriter &w, const char *name) const
GLfloat v0
Definition: glcorearb.h:816
const char * className() const override
Processes primitives generated by refinement process.
Definition: GT_Refine.h:20
void setPrimitiveTransform(const GT_TransformHandle &x)
Set the transform for a the primitive.
Definition: GT_Primitive.h:114
GLint j
Definition: glad.h:2733
int64 GT_Size
Definition: GT_Types.h:128
const GT_Parametric & getParametric() const
GT_PrimQuadric(const GT_AttributeListHandle &attribs, const GT_TransformHandle &transform, const GT_Parametric &uv=GT_Parametric())
fpreal64 fpreal
Definition: SYS_Types.h:277
bool saveAttributeLists(UT_JSONWriter &w) const
GLfloat GLfloat v1
Definition: glcorearb.h:817
GT_PrimQuadric(const GT_PrimQuadric &src)
void getQN(UT_Vector3F &N, fpreal u, fpreal v) const
GA_API const UT_StringHolder N
GLdouble GLdouble GLdouble top
Definition: glad.h:2817
void getQN(UT_Vector3D &N, fpreal u, fpreal v) const
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:857
UT_IntrusivePtr< GT_Primitive > GT_PrimitiveHandle
Definition: GT_Handles.h:33
virtual void enlargeBounds(UT_BoundingBox boxes[], int nsegments) const =0
GLenum src
Definition: glcorearb.h:1793