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