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  int getBBox(UT_BoundingBox *bbox) const override = 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.
47  const GA_Attribute *P) const override;
49  const GA_Attribute *P) const override;
50  void enlargePointBounds(UT_BoundingBox &e) const override;
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 override;
58  UT_Vector3 baryCenter() const override;
59  UT_Vector3 computeNormal() const override;
60  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 override;
64  bool loadH9(UT_IStream &is,
65  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
66  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs
67  ) override;
68 
69  // Transforms the matrix associated with this primitive. The
70  // translate component is ignored: Translate the vertices of
71  // the primitive to translate the primitive.
72  // This only works with quadrics (sphere, tube, metaballs) and volumes.
73  void transform(const UT_Matrix4 &mat) override;
74 
75  GEO_Primitive *copy(int preserve_shared_pts = 0) const override;
76  void copyPrimitive(const GEO_Primitive *src) override;
77  void copySubclassData(const GA_Primitive *source) override;
78  void reverse() override {}
79 
83 
84  /// NOTE: Getting the vertex count of a quadric is rather unnecessary.
87  { return 1; }
88  /// The fast vertex offset accessor
91  { return getVertexOffset(0); }
92 
93  /// The fast vertex index accessor
96  { return GEO_Primitive::getVertexIndex(0); }
97 
98  /// The fast point offset accessor
101  { return GEO_Primitive::getPointOffset(0); }
102 
103  /// The fast point index accessor
106  { return GEO_Primitive::getPointIndex(0); }
107 
108  /// The fast point position accessor
111  { return GEO_Primitive::getPos3(0); }
113  void setPos3(const UT_Vector3 &pos) const
114  { GEO_Primitive::setPos3(0, pos); }
117  { return GEO_Primitive::getPos4(0); }
119  void setPos4(const UT_Vector4 &pos) const
120  { GEO_Primitive::setPos4(0, pos); }
123  { GEO_Primitive::setPointOffset(0, ptoff); }
124 
125  // Take the whole set of points into consideration when applying the
126  // point removal operation to this primitive. The method returns 0 if
127  // successful, -1 if it failed because it would have become degenerate,
128  // and -2 if it failed because it would have had to remove the primitive
129  // altogether.
130  int detachPoints(GA_PointGroup &grp) override;
131 
132  /// Before a point is deleted, all primitives using the point will be
133  /// notified. The method should return "false" if it's impossible to
134  /// delete the point. Otherwise, the vertices should be removed.
135  GA_DereferenceStatus dereferencePoint(
136  GA_Offset point,
137  bool dry_run=false) override;
138  GA_DereferenceStatus dereferencePoints(
139  const GA_RangeMemberQuery &pt_q,
140  bool dry_run=false) override;
141 
142  bool isDegenerate() const override;
143 
144 //
145 // Methods to set the space of a primitive
146  void getAxes(UT_Vector3 &x, UT_Vector3 &y,
147  UT_Vector3 &z) const;
148  void getXAxis(UT_Vector3 &x) const;
149  void getYAxis(UT_Vector3 &y) const;
150  void getZAxis(UT_Vector3 &z) const;
151 
152  void setAxes(const UT_Vector3 &x, const UT_Vector3 &y,
153  const UT_Vector3 &z);
154  void setXAxis(const UT_Vector3 &x);
155  void setYAxis(const UT_Vector3 &y);
156  void setZAxis(const UT_Vector3 &z);
157 
158  const UT_Matrix3 &getTransform() const { return myXform; }
159  void setTransform(const UT_Matrix3 &m) { myXform = m; }
160 
161  void getTransform4( UT_Matrix4 &matx) const;
162  void setTransform4(const UT_Matrix4 &matx);
163 
164  void getLocalTransform(UT_Matrix3D &x) const override;
165  void setLocalTransform(const UT_Matrix3D &x) override;
166 
169  {
170  setPointOffset(pt);
171  }
172 
173  /// This method assigns a preallocated vertex to the quadric, optionally
174  /// creating the topological link between the primitive and new vertex.
175  void assignVertex(GA_Offset new_vtx, bool update_topology);
176 
177  /// Builds a quadric primitive of the specified type, with either the
178  /// specified point offset, or a new point if the provided offset
179  /// is invalid.
180  /// NOTE: type must be GA_PRIMSPHERE, GA_PRIMCIRCLE, GA_PRIMTUBE,
181  /// GA_PRIMMETABALL, or GA_PRIMMETASQUAD.
182  static GEO_Quadric *build(GA_Detail &detail,
184  GA_Offset existing_ptoff=GA_INVALID_OFFSET);
185 
186  /// Builds a contiguous block of nprims quadric primitives of the specified
187  /// type, appending a block of new points for them if append_points is true,
188  /// else leaving the vertices unwired.
189  /// NOTE: type must be GA_PRIMSPHERE, GA_PRIMCIRCLE, GA_PRIMTUBE,
190  /// GA_PRIMMETABALL, or GA_PRIMMETASQUAD.
191  static GA_Offset buildBlock(GA_Detail &detail,
193  GA_Size nprims,
194  bool append_points=true);
195 
196  // Have we been deactivated and stashed?
197  void stashed(bool beingstashed,
198  GA_Offset offset = GA_INVALID_OFFSET) override;
199 
200  // Map the normalized length (distance value [0,1]) parameter to the unit
201  // parameterization of the primitve
203  float ulength, float vlength,
204  float &uparm, float &vparm) const override;
206  float ulength, float vlength,
207  float &uparm, float &vparm,
208  float tolerance) const override;
209 
211  float uparm, float vparm,
212  float &ulength, float &vlength) const override;
213 
214  // Is this primitive a GEO_Quadric?
215  bool isQuadric() const override { return true; }
216 
217 protected:
218  /// Return the family mask for all quadric sub-classes
220 
221  // Declare intrinsic attribute methods
222  GA_DECLARE_INTRINSICS(override);
223 
224  virtual bool savePrivateH9(std::ostream &os, bool binary) const;
225  virtual bool loadPrivateH9(UT_IStream &is);
226 
229  { return getPointOffset(); }
230 
232  GA_Offset result_vertex,
233  GA_AttributeRefMap &hlist) const override;
234 
235 private:
236  UT_Matrix3 myXform; // My transform
237 
238  friend std::ostream &operator<<(std::ostream &os, const GEO_Quadric &d)
239  {
240  d.saveH9(os, 0,
243  return os;
244  }
246 };
248 
249 #endif
void setTransform(const UT_Matrix3 &m)
Definition: GEO_Quadric.h:159
Definition of a geometry attribute.
Definition: GA_Attribute.h:196
virtual GEO_Primitive * copy(int preserve_shared_pts=0) const
SYS_FORCE_INLINE GA_Offset getPointOffset(GA_Size i) const
Definition: GA_Primitive.h:254
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:105
SYS_FORCE_INLINE GA_Index getVertexIndex(GA_Size primvertexnum) const
Definition: GA_Primitive.h:246
#define SYS_DEPRECATED_PUSH_DISABLE()
#define SYS_DEPRECATED_POP_DISABLE()
virtual void copySubclassData(const GA_Primitive *source)
Definition: GA_Primitive.h:484
SYS_FORCE_INLINE void setPos4(const UT_Vector4 &pos) const
Definition: GEO_Quadric.h:119
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
Definition: GA_Primitive.h:260
SYS_FORCE_INLINE void setPos3(const UT_Vector3 &pos) const
Definition: GEO_Quadric.h:113
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:168
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const override
const GLdouble * m
Definition: glew.h:9124
Abstract base class for a range membership query object.
const UT_Matrix3 & getTransform() const
Definition: GEO_Quadric.h:158
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:233
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:676
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:86
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:639
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:274
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:286
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:633
GLuint GLuint GLsizei GLenum type
Definition: glew.h:1253
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:268
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:280
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:110
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:292
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().
void reverse() override
Reverse the order of vertices.
Definition: GEO_Quadric.h:78
bool saveH9(std::ostream &os, bool binary, const UT_Array< GA_AttribSaveDataH9 > &prim_attribs, const UT_Array< GA_AttribSaveDataH9 > &vtx_attribs) const override
SYS_FORCE_INLINE GA_Index getVertexIndex() const
The fast vertex index accessor.
Definition: GEO_Quadric.h:95
SYS_FORCE_INLINE GA_Offset vertexPoint() const
Definition: GEO_Quadric.h:228
static GA_PrimitiveFamilyMask buildFamilyMask()
Return the family mask for all quadric sub-classes.
Definition: GEO_Quadric.h:219
SYS_FORCE_INLINE void setPointOffset(GA_Offset ptoff)
Definition: GEO_Quadric.h:122
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:240
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
The fast vertex offset accessor.
Definition: GEO_Quadric.h:90
Container class for all geometry.
Definition: GA_Detail.h:95
bool isQuadric() const override
Definition: GEO_Quadric.h:215
SYS_FORCE_INLINE UT_Vector4 getPos4() const
Definition: GEO_Quadric.h:116
SYS_FORCE_INLINE GA_Offset getPointOffset() const
The fast point offset accessor.
Definition: GEO_Quadric.h:100
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:238
GLintptr offset
Definition: glew.h:1682