HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GEO_Quadric.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: Geometry Library (C++)
7  *
8  * COMMENTS:
9  * This is the base class for Quadratics (Sphere, Tube, Cone, Blob, etc.)
10  * Since these quadrics may have any rotation, there are axes kept
11  * for the orientation. These axes are maintained by the base class.
12  * This class doesn't really mean quadric/quadratic functions. In practice,
13  * it has come to mean "this primitive has a transform."
14  *
15  */
16 
17 #ifndef __GEO_Quadric_H__
18 #define __GEO_Quadric_H__
19 
20 #include "GEO_API.h"
21 #include <UT/UT_Matrix3.h>
22 #include "GEO_Primitive.h"
23 
24 #include <UT/UT_VectorTypes.h>
25 
26 class GEO_Detail;
27 
28 // For the for loop, we can use getFastVertex since we know the index is valid
29 
31 {
32 protected:
33  /// NOTE: The constructor should only be called from subclass
34  /// constructors.
36 
37 public:
38 //
39 // Methods common to all primitives.
40  virtual int getBBox(UT_BoundingBox *bbox) const = 0;
41  /// @{
42  /// Enlarge a bounding box by the bounding box of the primitive. A
43  /// return value of false indicates an error in the operation, most
44  /// likely an invalid P. For any attribute other than the position
45  /// these methods simply enlarge the bounding box based on the vertex.
46  virtual bool enlargeBoundingBox(UT_BoundingRect &b,
47  const GA_Attribute *P) const;
48  virtual bool enlargeBoundingBox(UT_BoundingBox &b,
49  const GA_Attribute *P) const;
50  virtual void enlargePointBounds(UT_BoundingBox &e) const;
51  /// @}
52  /// Enlarge a bounding sphere to encompass the primitive. A return value
53  /// of false indicates an error in the operation, most likely an invalid
54  /// P. For any attribute other than the position this method simply
55  /// enlarges the sphere based on the vertex.
57  const GA_Attribute *P) const;
58  virtual UT_Vector3 baryCenter() const;
59  virtual UT_Vector3 computeNormal() const;
60  virtual bool saveH9(std::ostream &os, bool binary,
61  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
62  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs)
63  const;
64  virtual bool loadH9(UT_IStream &is,
65  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
66  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs);
67 
68  // Transforms the matrix associated with this primitive. The
69  // translate component is ignored: Translate the vertices of
70  // the primitive to translate the primitive.
71  // This only works with quadrics (sphere, tube, metaballs) and volumes.
72  virtual void transform(const UT_Matrix4 &mat);
73 
74  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
75  virtual void copyPrimitive(const GEO_Primitive *src);
76  virtual void copySubclassData(const GA_Primitive *source);
77  virtual void reverse() {}
78 
82 
83  /// NOTE: Getting the vertex count of a quadric is rather unnecessary.
86  { return 1; }
87  /// The fast vertex offset accessor
90  { return getVertexOffset(0); }
91 
92  /// The fast vertex index accessor
95  { return GEO_Primitive::getVertexIndex(0); }
96 
97  /// The fast point offset accessor
100  { return GEO_Primitive::getPointOffset(0); }
101 
102  /// The fast point index accessor
105  { return GEO_Primitive::getPointIndex(0); }
106 
107  /// The fast point position accessor
110  { return GEO_Primitive::getPos3(0); }
112  void setPos3(const UT_Vector3 &pos) const
113  { GEO_Primitive::setPos3(0, pos); }
116  { return GEO_Primitive::getPos4(0); }
118  void setPos4(const UT_Vector4 &pos) const
119  { GEO_Primitive::setPos4(0, pos); }
122  { GEO_Primitive::setPointOffset(0, ptoff); }
123 
124  // Take the whole set of points into consideration when applying the
125  // point removal operation to this primitive. The method returns 0 if
126  // successful, -1 if it failed because it would have become degenerate,
127  // and -2 if it failed because it would have had to remove the primitive
128  // altogether.
129  virtual int detachPoints (GA_PointGroup &grp);
130 
131  /// Before a point is deleted, all primitives using the point will be
132  /// notified. The method should return "false" if it's impossible to
133  /// delete the point. Otherwise, the vertices should be removed.
134  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
135  bool dry_run=false);
136  virtual GA_DereferenceStatus dereferencePoints(
137  const GA_RangeMemberQuery &pt_q,
138  bool dry_run=false);
139 
140  virtual bool isDegenerate() const;
141 
142 //
143 // Methods to set the space of a primitive
144  void getAxes(UT_Vector3 &x, UT_Vector3 &y,
145  UT_Vector3 &z) const;
146  void getXAxis(UT_Vector3 &x) const;
147  void getYAxis(UT_Vector3 &y) const;
148  void getZAxis(UT_Vector3 &z) const;
149 
150  void setAxes(const UT_Vector3 &x, const UT_Vector3 &y,
151  const UT_Vector3 &z);
152  void setXAxis(const UT_Vector3 &x);
153  void setYAxis(const UT_Vector3 &y);
154  void setZAxis(const UT_Vector3 &z);
155 
156  const UT_Matrix3 &getTransform(void) const { return myXform; }
157  void setTransform(const UT_Matrix3 &m) { myXform = m; }
158 
159  void getTransform4( UT_Matrix4 &matx) const;
160  void setTransform4(const UT_Matrix4 &matx);
161 
162  virtual void getLocalTransform(UT_Matrix3D &x) const;
163  virtual void setLocalTransform(const UT_Matrix3D &x);
164 
167  {
168  setPointOffset(pt);
169  }
170 
171  /// This method assigns a preallocated vertex to the quadric, optionally
172  /// creating the topological link between the primitive and new vertex.
173  void assignVertex(GA_Offset new_vtx, bool update_topology);
174 
175  /// Builds a quadric primitive of the specified type, with either the
176  /// specified point offset, or a new point if the provided offset
177  /// is invalid.
178  /// NOTE: type must be GA_PRIMSPHERE, GA_PRIMCIRCLE, GA_PRIMTUBE,
179  /// GA_PRIMMETABALL, or GA_PRIMMETASQUAD.
180  static GEO_Quadric *build(GA_Detail &detail,
182  GA_Offset existing_ptoff=GA_INVALID_OFFSET);
183 
184  /// Builds a contiguous block of nprims quadric primitives of the specified
185  /// type, appending a block of new points for them if append_points is true,
186  /// else leaving the vertices unwired.
187  /// NOTE: type must be GA_PRIMSPHERE, GA_PRIMCIRCLE, GA_PRIMTUBE,
188  /// GA_PRIMMETABALL, or GA_PRIMMETASQUAD.
189  static GA_Offset buildBlock(GA_Detail &detail,
191  GA_Size nprims,
192  bool append_points=true);
193 
194  // Have we been deactivated and stashed?
195  virtual void stashed(bool beingstashed,
197 
198  // Map the normalized length (distance value [0,1]) parameter to the unit
199  // parameterization of the primitve
200  virtual void unitLengthToUnitPair(float ulength, float vlength,
201  float &uparm, float &vparm)const;
202  virtual void unitLengthToUnitPair(float ulength, float vlength,
203  float &uparm, float &vparm, float tolerance)const;
204 
205  virtual void unitToUnitLengthPair(float uparm, float vparm,
206  float &ulength, float &vlength)
207  const;
208 
209  // Is this primitive a GEO_Quadric?
210  virtual bool isQuadric() const { return true; }
211 
212 protected:
213  /// Return the family mask for all quadric sub-classes
215 
216  // Declare intrinsic attribute methods
218 
219  virtual bool savePrivateH9(std::ostream &os, bool binary) const;
220  virtual bool loadPrivateH9(UT_IStream &is);
221 
224  { return getPointOffset(); }
225 
226  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
227  GA_AttributeRefMap &hlist) const;
228 
229 private:
230  UT_Matrix3 myXform; // My transform
231 
232  friend std::ostream &operator<<(std::ostream &os, const GEO_Quadric &d)
233  {
234  d.saveH9(os, 0,
237  return os;
238  }
240 };
242 
243 #endif
void setTransform(const UT_Matrix3 &m)
Definition: GEO_Quadric.h:157
Definition of a geometry attribute.
Definition: GA_Attribute.h:190
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:246
virtual UT_Vector3 baryCenter() const
GLenum src
Definition: glew.h:2410
virtual void copyPrimitive(const GEO_Primitive *src)=0
SYS_FORCE_INLINE GA_Index getPointIndex() const
The fast point index accessor.
Definition: GEO_Quadric.h:104
SYS_FORCE_INLINE GA_Index getVertexIndex(GA_Size primvertexnum) const
Definition: GA_Primitive.h:238
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:476
SYS_FORCE_INLINE void setPos4(const UT_Vector4 &pos) const
Definition: GEO_Quadric.h:118
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
Definition: GA_Primitive.h:252
SYS_FORCE_INLINE void setPos3(const UT_Vector3 &pos) const
Definition: GEO_Quadric.h:112
virtual bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const
const UT_Matrix3 & getTransform(void) const
Definition: GEO_Quadric.h:156
GLsizei GLsizei GLchar * source
Definition: glew.h:1832
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
SYS_FORCE_INLINE void setVertexPoint(GA_Offset pt)
Definition: GEO_Quadric.h:166
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
const GLdouble * m
Definition: glew.h:9124
Abstract base class for a range membership query object.
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
virtual void unitToUnitLengthPair(float uparm, float vparm, float &ulength, float &vlength) const
exint GA_Size
Defines the bit width for index and offset types in GA.
Definition: GA_Types.h:231
virtual bool loadH9(UT_IStream &is, const UT_Array< GA_AttribLoadDataH9 > &prim_attribs, const UT_Array< GA_AttribLoadDataH9 > &vtx_attribs)
GA_PrimitiveFamilyMask
virtual UT_Vector3 computeNormal() const =0
Return a normal vector for the primitive.
#define GA_INVALID_OFFSET
Definition: GA_Types.h:674
GLdouble GLdouble z
Definition: glew.h:1559
SYS_FORCE_INLINE GA_Size getFastVertexCount() const
NOTE: Getting the vertex count of a quadric is rather unnecessary.
Definition: GEO_Quadric.h:85
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:637
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Size i) const
Definition: GA_Primitive.h:266
virtual void setLocalTransform(const UT_Matrix3D &matrix)
Set the local transform. The default implementation does nothing.
GLint GLint GLint GLint GLint x
Definition: glew.h:1252
GLint GLint GLint GLint GLint GLint y
Definition: glew.h:1252
const GLuint GLenum const void * binary
Definition: glew.h:3502
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
#define GEO_API
Definition: GEO_API.h:14
SYS_FORCE_INLINE UT_Vector4 getPos4(GA_Size i) const
Definition: GA_Primitive.h:278
A handle to simplify manipulation of multiple attributes.
virtual int getBBox(UT_BoundingBox *bbox) const =0
#define GEO_FAMILY_QUADRIC
Definition: GEO_PrimType.h:76
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:631
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
virtual void reverse()
Reverse the order of vertices.
Definition: GEO_Quadric.h:77
virtual GA_DereferenceStatus dereferencePoints(const GA_RangeMemberQuery &pt_q, bool dry_run=false)=0
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
SYS_FORCE_INLINE GA_Index getPointIndex(GA_Size i) const
Definition: GA_Primitive.h:260
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:272
virtual void unitLengthToUnitPair(float ulength, float vlength, float &uparm, float &vparm) const
SYS_FORCE_INLINE UT_Vector3 getPos3() const
The fast point position accessor.
Definition: GEO_Quadric.h:109
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
SYS_FORCE_INLINE void setPos4(GA_Size i, const UT_Vector4 &pos) const
Definition: GA_Primitive.h:284
virtual void transform(const UT_Matrix4 &)
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
virtual void enlargePointBounds(UT_BoundingBox &box) const
virtual void getLocalTransform(UT_Matrix3D &matrix) const
virtual int detachPoints(GA_PointGroup &grp)=0
static const UT_Array< GA_AttribSaveDataH9 > & theEmptySaveAttribs
Convience objects to pass as arguments to saveH9()/loadH9().
SYS_FORCE_INLINE GA_Index getVertexIndex() const
The fast vertex index accessor.
Definition: GEO_Quadric.h:94
SYS_FORCE_INLINE GA_Offset vertexPoint() const
Definition: GEO_Quadric.h:223
static GA_PrimitiveFamilyMask buildFamilyMask()
Return the family mask for all quadric sub-classes.
Definition: GEO_Quadric.h:214
SYS_FORCE_INLINE void setPointOffset(GA_Offset ptoff)
Definition: GEO_Quadric.h:121
virtual bool isQuadric() const
Definition: GEO_Quadric.h:210
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:232
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
The fast vertex offset accessor.
Definition: GEO_Quadric.h:89
Container class for all geometry.
Definition: GA_Detail.h:95
SYS_FORCE_INLINE UT_Vector4 getPos4() const
Definition: GEO_Quadric.h:115
virtual bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const
SYS_FORCE_INLINE GA_Offset getPointOffset() const
The fast point offset accessor.
Definition: GEO_Quadric.h:99
virtual void stashed(bool beingstashed, GA_Offset offset=GA_INVALID_OFFSET)
friend std::ostream & operator<<(std::ostream &os, const GEO_Quadric &d)
Definition: GEO_Quadric.h:232
GLintptr offset
Definition: glew.h:1682