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 #if !GA_PRIMITIVE_VERTEXLIST
38  /// NOTE: The destructor should only be called from subclass
39  /// destructors.
40  virtual ~GEO_Quadric();
41 #endif
42 
43 public:
44 //
45 // Methods common to all primitives.
46  virtual int getBBox(UT_BoundingBox *bbox) const = 0;
47  /// @{
48  /// Enlarge a bounding box by the bounding box of the primitive. A
49  /// return value of false indicates an error in the operation, most
50  /// likely an invalid P. For any attribute other than the position
51  /// these methods simply enlarge the bounding box based on the vertex.
52  virtual bool enlargeBoundingBox(UT_BoundingRect &b,
53  const GA_Attribute *P) const;
54  virtual bool enlargeBoundingBox(UT_BoundingBox &b,
55  const GA_Attribute *P) const;
56  virtual void enlargePointBounds(UT_BoundingBox &e) const;
57  /// @}
58  /// Enlarge a bounding sphere to encompass the primitive. A return value
59  /// of false indicates an error in the operation, most likely an invalid
60  /// P. For any attribute other than the position this method simply
61  /// enlarges the sphere based on the vertex.
63  const GA_Attribute *P) const;
64  virtual UT_Vector3 baryCenter() const;
65  virtual UT_Vector3 computeNormal() const;
66  virtual bool saveH9(std::ostream &os, bool binary,
67  const UT_Array<GA_AttribSaveDataH9> &prim_attribs,
68  const UT_Array<GA_AttribSaveDataH9> &vtx_attribs)
69  const;
70  virtual bool loadH9(UT_IStream &is,
71  const UT_Array<GA_AttribLoadDataH9> &prim_attribs,
72  const UT_Array<GA_AttribLoadDataH9> &vtx_attribs);
73 
74  // Transforms the matrix associated with this primitive. The
75  // translate component is ignored: Translate the vertices of
76  // the primitive to translate the primitive.
77  // This only works with quadrics (sphere, tube, metaballs) and volumes.
78  virtual void transform(const UT_Matrix4 &mat);
79 
80  virtual GEO_Primitive *copy(int preserve_shared_pts = 0) const;
81  virtual void copyPrimitive(const GEO_Primitive *src);
82  virtual void copyUnwiredForMerge(const GA_Primitive *src,
83  const GA_MergeMap &map);
84 #if !GA_PRIMITIVE_VERTEXLIST
85  virtual void addPointRefToGroup(GA_PointGroup &grp) const;
86 
87  virtual bool vertexApply(bool (*apply)(GA_Offset vtx, void *),
88  void *data = 0) const;
89 #endif
90  virtual void reverse() {}
91 
92 #if GA_PRIMITIVE_VERTEXLIST
96 #else
97  virtual GA_Size getVertexCount() const;
98  virtual GA_Offset getVertexOffset(GA_Size index) const;
99 #endif
100 
101  /// NOTE: Getting the vertex count of a quadric is rather unnecessary.
104  { return 1; }
105  /// The fast vertex offset accessor
108 #if GA_PRIMITIVE_VERTEXLIST
109  { return getVertexOffset(0); }
110 #else
111  { return myVertex; }
112 #endif
113 
114  /// The fast vertex index accessor
117 #if GA_PRIMITIVE_VERTEXLIST
118  { return GEO_Primitive::getVertexIndex(0); }
119 #else
120  { return getDetail().vertexIndex(getVertexOffset()); }
121 #endif
122  /// The fast point offset accessor
125 #if GA_PRIMITIVE_VERTEXLIST
126  { return GEO_Primitive::getPointOffset(0); }
127 #else
128  { return getDetail().vertexPoint(myVertex); }
129 #endif
130 #if !GA_PRIMITIVE_VERTEXLIST
131  /// NOTE: This version is just here to avoid hiding
132  /// GA_Primitive::getPointOffset without a replacement.
134  {
135  UT_ASSERT_P(i == 0);
136  return getDetail().vertexPoint(myVertex);
137  }
138 #endif
139  /// The fast point index accessor
142 #if GA_PRIMITIVE_VERTEXLIST
143  { return GEO_Primitive::getPointIndex(0); }
144 #else
145  { return getDetail().pointIndex(getPointOffset()); }
146 #endif
147 #if !GA_PRIMITIVE_VERTEXLIST
148  /// NOTE: This version is just here to avoid hiding
149  /// GA_Primitive::getPointIndex without a replacement.
151  {
152  UT_ASSERT_P(i == 0);
153  return getDetail().pointIndex(getPointOffset());
154  }
155 #endif
156  /// The fast point position accessor
157 #if GA_PRIMITIVE_VERTEXLIST
159  UT_Vector3 getPos3() const
160  { return GEO_Primitive::getPos3(0); }
162  void setPos3(const UT_Vector3 &pos) const
163  { GEO_Primitive::setPos3(0, pos); }
165  UT_Vector4 getPos4() const
166  { return GEO_Primitive::getPos4(0); }
168  void setPos4(const UT_Vector4 &pos) const
169  { GEO_Primitive::setPos4(0, pos); }
171  void setPointOffset(GA_Offset ptoff)
172  { GEO_Primitive::setPointOffset(0, ptoff); }
173 #else
175  { return getDetail().getPos3(getPointOffset()); }
176  void setPos3(const UT_Vector3 &pos) const
177  { getDetail().setPos3(getPointOffset(), pos); }
179  { return getDetail().getPos4(getPointOffset()); }
180  void setPos4(const UT_Vector4 &pos) const
181  { getDetail().setPos4(getPointOffset(), pos); }
182  void setPointOffset(GA_Offset ptoff) const
184 #endif
185 
186  // Take the whole set of points into consideration when applying the
187  // point removal operation to this primitive. The method returns 0 if
188  // successful, -1 if it failed because it would have become degenerate,
189  // and -2 if it failed because it would have had to remove the primitive
190  // altogether.
191  virtual int detachPoints (GA_PointGroup &grp);
192 
193  /// Before a point is deleted, all primitives using the point will be
194  /// notified. The method should return "false" if it's impossible to
195  /// delete the point. Otherwise, the vertices should be removed.
196  virtual GA_DereferenceStatus dereferencePoint(GA_Offset point,
197  bool dry_run=false);
198  virtual GA_DereferenceStatus dereferencePoints(
199  const GA_RangeMemberQuery &pt_q,
200  bool dry_run=false);
201 
202  virtual bool isDegenerate() const;
203 
204 //
205 // Methods to set the space of a primitive
206  void getAxes(UT_Vector3 &x, UT_Vector3 &y,
207  UT_Vector3 &z) const;
208  void getXAxis(UT_Vector3 &x) const;
209  void getYAxis(UT_Vector3 &y) const;
210  void getZAxis(UT_Vector3 &z) const;
211 
212  void setAxes(const UT_Vector3 &x, const UT_Vector3 &y,
213  const UT_Vector3 &z);
214  void setXAxis(const UT_Vector3 &x);
215  void setYAxis(const UT_Vector3 &y);
216  void setZAxis(const UT_Vector3 &z);
217 
218  const UT_Matrix3 &getTransform(void) const { return myXform; }
219  void setTransform(const UT_Matrix3 &m) { myXform = m; }
220 
221  void getTransform4( UT_Matrix4 &matx) const;
222  void setTransform4(const UT_Matrix4 &matx);
223 
224  virtual void getLocalTransform(UT_Matrix3D &x) const;
225  virtual void setLocalTransform(const UT_Matrix3D &x);
226 
229  {
230  setPointOffset(pt);
231  }
232 
233  /// This method assigns a preallocated vertex to the quadric, optionally
234  /// creating the topological link between the primitive and new vertex.
235  void assignVertex(GA_Offset new_vtx, bool update_topology);
236 
237  /// Builds a quadric primitive of the specified type, with either the
238  /// specified point offset, or a new point if the provided offset
239  /// is invalid.
240  /// NOTE: type must be GA_PRIMSPHERE, GA_PRIMCIRCLE, GA_PRIMTUBE,
241  /// GA_PRIMMETABALL, or GA_PRIMMETASQUAD.
242  static GEO_Quadric *build(GA_Detail &detail,
244  GA_Offset existing_ptoff=GA_INVALID_OFFSET);
245 
246  /// Builds a contiguous block of nprims quadric primitives of the specified
247  /// type, appending a block of new points for them if append_points is true,
248  /// else leaving the vertices unwired.
249  /// NOTE: type must be GA_PRIMSPHERE, GA_PRIMCIRCLE, GA_PRIMTUBE,
250  /// GA_PRIMMETABALL, or GA_PRIMMETASQUAD.
251  static GA_Offset buildBlock(GA_Detail &detail,
253  GA_Size nprims,
254  bool append_points=true);
255 
256  // Have we been deactivated and stashed?
257  virtual void stashed(bool beingstashed,
259 
260  // Map the normalized length (distance value [0,1]) parameter to the unit
261  // parameterization of the primitve
262  virtual void unitLengthToUnitPair(float ulength, float vlength,
263  float &uparm, float &vparm)const;
264  virtual void unitLengthToUnitPair(float ulength, float vlength,
265  float &uparm, float &vparm, float tolerance)const;
266 
267  virtual void unitToUnitLengthPair(float uparm, float vparm,
268  float &ulength, float &vlength)
269  const;
270 
271  // Is this primitive a GEO_Quadric?
272  virtual bool isQuadric() const { return true; }
273 
274 protected:
275  /// Return the family mask for all quadric sub-classes
277  { return GEO_FAMILY_QUADRIC; }
278 
279  // Declare intrinsic attribute methods
281 
282 #if !GA_PRIMITIVE_VERTEXLIST
283  virtual void clearForDeletion();
284 #endif
285 
286  virtual bool savePrivateH9(std::ostream &os, bool binary) const;
287  virtual bool loadPrivateH9(UT_IStream &is);
288 
291  { return getPointOffset(); }
292 
293 #if !GA_PRIMITIVE_VERTEXLIST
294  /// Defragmentation
295  virtual void swapVertexOffsets(const GA_Defragment &defrag);
296 #endif
297 
298  virtual bool evaluateBaryCenterRefMap(GA_Offset result_vertex,
299  GA_AttributeRefMap &hlist) const;
300 
301 private:
302 #if !GA_PRIMITIVE_VERTEXLIST
303  GA_Offset myVertex; // My vertex
304 #endif
305  UT_Matrix3 myXform; // My transform
306 
307  friend std::ostream &operator<<(std::ostream &os, const GEO_Quadric &d)
308  {
309  d.saveH9(os, 0,
312  return os;
313  }
315 };
317 
318 #endif
UT_Vector4 getPos4() const
Definition: GEO_Quadric.h:178
virtual void copyUnwiredForMerge(const GA_Primitive *src, const GA_MergeMap &map)
void setTransform(const UT_Matrix3 &m)
Definition: GEO_Quadric.h:219
SYS_FORCE_INLINE void setPos3(GA_Offset ptoff, const UT_Vector3 &P)
Set P from a UT_Vector3.
Definition: GA_Detail.h:207
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
SYS_FORCE_INLINE GA_Detail & getDetail() const
Definition: GA_Primitive.h:133
virtual void copyPrimitive(const GEO_Primitive *src)=0
virtual void clearForDeletion()
Definition: GA_Primitive.h:595
SYS_FORCE_INLINE GA_Size getVertexCount() const
Return the number of vertices used by this primitive.
Definition: GA_Primitive.h:224
SYS_FORCE_INLINE GA_Index getPointIndex() const
The fast point index accessor.
Definition: GEO_Quadric.h:141
SYS_FORCE_INLINE GA_Index getVertexIndex(GA_Size primvertexnum) const
Definition: GA_Primitive.h:238
#define SYS_DEPRECATED_PUSH_DISABLE()
UT_Vector4 getPos4(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:252
#define SYS_DEPRECATED_POP_DISABLE()
const GLuint GLenum const void * binary
Definition: glcorearb.h:1923
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
void setPos4(const UT_Vector4 &pos) const
Definition: GEO_Quadric.h:180
The merge map keeps track of information when merging details.
Definition: GA_MergeMap.h:53
SYS_FORCE_INLINE void setPointOffset(GA_Size i, GA_Offset ptoff)
Definition: GA_Primitive.h:252
virtual bool enlargeBoundingBox(UT_BoundingRect &b, const GA_Attribute *P) const
const UT_Matrix3 & getTransform(void) const
Definition: GEO_Quadric.h:218
virtual GA_DereferenceStatus dereferencePoint(GA_Offset point, bool dry_run=false)=0
SYS_FORCE_INLINE void setVertexPoint(GA_Offset pt)
Definition: GEO_Quadric.h:228
#define GA_DECLARE_INTRINSICS(OVERRIDE)
Definition: GA_Primitive.h:80
GLint y
Definition: glcorearb.h:102
Abstract base class for a range membership query object.
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:174
#define GA_NO_OVERRIDE
Definition: GA_Primitive.h:76
void setPointOffset(GA_Offset ptoff) const
Definition: GEO_Quadric.h:182
png_uint_32 i
Definition: png.h:2877
virtual void swapVertexOffsets(const GA_Defragment &defrag)
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:211
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:654
SYS_FORCE_INLINE GA_Size getFastVertexCount() const
NOTE: Getting the vertex count of a quadric is rather unnecessary.
Definition: GEO_Quadric.h:103
virtual bool isDegenerate() const =0
Is the primitive degenerate.
GA_Size GA_Offset
Definition: GA_Types.h:617
virtual bool enlargeBoundingSphere(UT_BoundingSphere &b, const GA_Attribute *P) const
GA_Offset getPointOffset(GA_Size i) const
Definition: GEO_Quadric.h:133
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.
void wireVertexPoint(GA_Offset vtx, GA_Offset pt)
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:125
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
GLintptr offset
Definition: glcorearb.h:664
#define GEO_API
Definition: GEO_API.h:10
SYS_FORCE_INLINE UT_Vector4 getPos4(GA_Size i) const
Definition: GA_Primitive.h:278
A handle to simplify manipulation of multiple attributes.
SYS_FORCE_INLINE GA_Index vertexIndex(GA_Offset offset) const
Given a vertex's data offset, return its index.
Definition: GA_Detail.h:463
virtual int getBBox(UT_BoundingBox *bbox) const =0
#define GEO_FAMILY_QUADRIC
Definition: GEO_PrimType.h:76
Defragmentation of IndexMaps.
Definition: GA_Defragment.h:45
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Offset vertex) const
Given a vertex, return the point it references.
Definition: GA_Detail.h:473
void addPointRefToGroup(GA_PointGroup &grp) const
GLboolean * data
Definition: glcorearb.h:130
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
GA_Size GA_Index
Define the strictness of GA_Offset/GA_Index.
Definition: GA_Types.h:611
virtual void reverse()
Reverse the order of vertices.
Definition: GEO_Quadric.h:90
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
UT_Vector3 getPos3() const
The fast point position accessor.
Definition: GEO_Quadric.h:174
SYS_FORCE_INLINE GA_Index getPointIndex(GA_Size i) const
Definition: GA_Primitive.h:260
void setPos3(const UT_Vector3 &pos) const
Definition: GEO_Quadric.h:176
SYS_FORCE_INLINE void setPos3(GA_Size i, const UT_Vector3 &pos) const
Definition: GA_Primitive.h:272
GA_Topology & getTopology()
Definition: GA_Detail.h:734
virtual void unitLengthToUnitPair(float ulength, float vlength, float &uparm, float &vparm) const
virtual bool evaluateBaryCenterRefMap(GA_Offset result_vtx, GA_AttributeRefMap &map) const
SYS_FORCE_INLINE GA_Index pointIndex(GA_Offset offset) const
Given a point's data offset, return its index.
Definition: GA_Detail.h:300
SYS_FORCE_INLINE void setPos4(GA_Size i, const UT_Vector4 &pos) const
Definition: GA_Primitive.h:284
virtual void transform(const UT_Matrix4 &)
virtual void enlargePointBounds(UT_BoundingBox &box) const
virtual bool vertexApply(bool(*apply)(GA_Offset vtx, void *), void *data=0) 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:116
SYS_FORCE_INLINE GA_Offset vertexPoint() const
Definition: GEO_Quadric.h:290
GLuint index
Definition: glcorearb.h:785
static GA_PrimitiveFamilyMask buildFamilyMask()
Return the family mask for all quadric sub-classes.
Definition: GEO_Quadric.h:276
GLint GLenum GLint x
Definition: glcorearb.h:408
virtual bool isQuadric() const
Definition: GEO_Quadric.h:272
GA_Index getPointIndex(GA_Size i) const
Definition: GEO_Quadric.h:150
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:232
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:107
SYS_FORCE_INLINE GA_Offset getVertexOffset() const
The fast vertex offset accessor.
Definition: GEO_Quadric.h:107
Container class for all geometry.
Definition: GA_Detail.h:95
#define const
Definition: zconf.h:214
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:124
void setPos4(GA_Offset ptoff, const UT_Vector4 &P)
Set P from a UT_Vector4.
Definition: GA_Detail.h:258
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:307
GLenum src
Definition: glcorearb.h:1792