HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEO_Point.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  *
10  */
11 
12 #ifndef __GEO_Point_H__
13 #define __GEO_Point_H__
14 
15 #include "GEO_API.h"
16 #include <GA/GA_GBElement.h>
17 #include <UT/UT_SmallObject.h>
18 #include <UT/UT_Vector4.h>
19 
20 class GA_Detail;
21 class GEO_Primitive;
22 
24 
25 /// Base class for GEO_Point.
26 ///
28 {
29 public:
30  /// Protect the constructors as this is only a base class and cannot itself
31  /// be instantiated.
33  : GA_GBElement(index_map, offset) { }
35  : GA_GBElement(src) { }
37  : GA_GBElement()
38  {}
39 
40  SYS_DEPRECATED_HDK(13.0)
42  {
44  return *this;
45  }
46 
47  /// We protect the destructor as nobody has any business using a reference
48  /// to this class to delete an instance of a class derived from us.
50 
51 public:
52  // --------------------------------------------------------------------
53  //
54  // Methods from GEO_Point
55  //
56  // --------------------------------------------------------------------
57  SYS_DEPRECATED_HDK(13.0)
58  void copyPoint(const GA_GBElement &src,
59  const GA_AttributeSet &src_dict,
60  const GA_AttributeSet &dest_dict)
61  {
62  copyAttribData(src, src_dict, dest_dict, true);
63  }
64  SYS_DEPRECATED_HDK(13.0)
65  void copyPoint(const GA_GBElement &src,
66  const GA_AttributeDict &src_dict,
67  const GA_AttributeDict &dest_dict)
68  {
69  copyAttribData(src, src_dict.getSet(), dest_dict.getSet(), true);
70  }
71  SYS_DEPRECATED_HDK(13.0)
72  void copyPoint(const GA_GBElement &src, const GA_AttributeSet &dict)
73  {
74  copyAttribData(src, dict, true);
75  }
76  SYS_DEPRECATED_HDK(13.0)
77  void copyPoint(const GA_GBElement &src, const GA_AttributeDict &dict)
78  {
79  copyAttribData(src, dict.getSet(), true);
80  }
81 
82 
83  // Methods which don't have any support in GA
84  // int saveASCII(ostream &os) const;
85  // int saveBinary(ostream &os) const;
86  // bool load(UT_IStream &is);
87 
88 protected:
89  /// @{
90  /// Get de-homogenized position (that is, without the homogeneous coordinate
91  /// multiplied through).
92  const UT_Vector4 getPos3D() const;
93  const UT_Vector3 getPos2D() const;
94  const UT_Vector2 getPos2() const;
95  float getPw() const;
96  /// @}
97 
98  void setPos3D(const UT_Vector4 &P);
99  void setPos3D(const UT_Vector3 &P);
100  void setPos3D(const UT_Vector3 &P, float w);
101  void setPos3D(float x, float y, float z, float w);
102 
103  void setPos2D(const UT_Vector3 &P);
104  void setPos2D(const UT_Vector2 &P);
105  void setPos2D(const UT_Vector2 &P, float w);
106  void setPos2D(float x, float y, float w);
107 
108  void setPw(float w);
109 };
110 
111 inline const UT_Vector4
113 {
114  UT_ASSERT_P(getIndexMap().getOwner() == GA_ATTRIB_POINT);
115  return getDetail().getPos4(getMapOffset());
116 }
117 inline const UT_Vector3
119 {
120  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
121  return getDetail().getPos3(getMapOffset());
122 }
123 inline const UT_Vector2
125 {
126  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
127  return getDetail().getPos2(getMapOffset());
128 }
129 inline float
131 {
132  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
133  return getDetail().getPw(getMapOffset());
134 }
135 inline void
137 {
138  UT_ASSERT_P(getIndexMap().getOwner() == GA_ATTRIB_POINT);
140 }
141 inline void
143 {
144  UT_ASSERT_P(getIndexMap().getOwner() == GA_ATTRIB_POINT);
146 }
147 inline void
149 {
150  UT_ASSERT_P(getIndexMap().getOwner() == GA_ATTRIB_POINT);
151  UT_Vector4 P4(P.x(), P.y(), P.z(), w);
152  getDetail().setPos4(getMapOffset(), P4);
153 }
154 inline void
155 GA_GBPoint::setPos3D(float x, float y, float z, float w)
156 {
157  UT_ASSERT_P(getIndexMap().getOwner() == GA_ATTRIB_POINT);
158  UT_Vector4 P4(x, y, z, w);
159  getDetail().setPos4(getMapOffset(), P4);
160 }
161 inline void
163 {
164  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
166 }
167 inline void
169 {
170  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
172 }
173 inline void
175 {
176  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
177  getDetail().setPos3(getMapOffset(), P.x(), P.y(), w);
178 }
179 inline void
180 GA_GBPoint::setPos2D(float x, float y, float w)
181 {
182  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
183  getDetail().setPos3(getMapOffset(), x, y, w);
184 }
185 inline void
187 {
188  UT_ASSERT(getIndexMap().getOwner() == GA_ATTRIB_POINT);
189  getDetail().setPw(getMapOffset(), w);
190 }
191 
192 /// DO NOT USE THIS CLASS!!!
194 {
195 public:
196  SYS_DEPRECATED_HDK(13.0)
198  : myPoint()
199  {}
200  SYS_DEPRECATED_HDK(13.0)
202  : myPoint(gdp->getPointMap(), offset)
203  {}
204  SYS_DEPRECATED_HDK(13.0)
206  : myPoint(gdp.getPointMap(), offset)
207  {}
208  SYS_DEPRECATED_HDK(13.0)
210  : myPoint(that.myPoint)
211  {}
212  SYS_DEPRECATED_HDK(13.0)
214  : myPoint()
215  {
216  if (that)
217  myPoint = GA_GBPoint(*that);
218  }
219  SYS_DEPRECATED_HDK(13.0)
220  bool operator!() const
221  {
222  return !myPoint.isGAValid();
223  }
224  SYS_DEPRECATED_HDK(13.0)
225  operator bool() const
226  {
227  return myPoint.isGAValid();
228  }
229  SYS_DEPRECATED_HDK(13.0)
230  operator GA_GBPoint() const
231  {
232  return myPoint;
233  }
234  SYS_DEPRECATED_HDK(13.0)
235  operator GA_Offset() const
236  {
237  return myPoint.getMapOffset();
238  }
239  SYS_DEPRECATED_HDK(13.0)
240  GA_GBPointP &operator=(const GA_GBPointP &that)
241  {
242  myPoint = GA_GBPoint(that.myPoint);
243  return *this;
244  }
245  SYS_DEPRECATED_HDK(13.0)
246  GA_GBPointP &operator=(const GA_GBPoint *that)
247  {
248  if (that)
249  myPoint = GA_GBPoint(*that);
250  else
251  myPoint = GA_GBPoint();
252  return *this;
253  }
254  SYS_DEPRECATED_HDK(13.0)
255  GA_GBPoint &operator*() const
256  {
257  return SYSconst_cast(myPoint);
258  }
259  SYS_DEPRECATED_HDK(13.0)
260  bool operator==(const GA_GBPointP &that)
261  {
262  if (!(*this))
263  return !that;
264  if (!that)
265  return false;
266  return (myPoint.getMapOffset() == that->getMapOffset()) &&
267  (&myPoint.getDetail() == &that->getDetail());
268  }
269  SYS_DEPRECATED_HDK(13.0)
270  bool operator!=(const GA_GBPointP &that)
271  {
272  return !((*this)==that);
273  }
274  SYS_DEPRECATED_HDK(13.0)
275  bool operator==(const GA_GBPoint *that)
276  {
277  if (!(*this))
278  return !that || !that->isGAValid();
279  if (!that || !that->isGAValid())
280  return false;
281  return (myPoint.getMapOffset() == that->getMapOffset()) &&
282  (&myPoint.getDetail() == &that->getDetail());
283  }
284  SYS_DEPRECATED_HDK(13.0)
285  bool operator!=(const GA_GBPoint *that)
286  {
287  return !((*this)==that);
288  }
289  SYS_DEPRECATED_HDK(13.0)
290  GA_GBPoint *operator->() const
291  {
292  return SYSconst_cast(&myPoint);
293  }
294 public:
296 };
297 
299 {
300 public:
301  /// Class constructors and destructors. The one that takes an attribute
302  /// data "steals" the data from adata and sets adata's data pointer to 0.
303  // @{
304  SYS_DEPRECATED_HDK(13.0)
306  : GA_GBPoint() {}
307  SYS_DEPRECATED_HDK(13.0)
309  : GA_GBPoint(index_map, offset) {}
310  SYS_DEPRECATED_HDK(13.0)
312  // @}
313 
314  /// @{
315  /// Get de-homogenized position (that is, without the homogeneous coordinate
316  /// multiplied through).
317  SYS_DEPRECATED_HDK(13.0)
318  const UT_Vector4 getPos() const { return GA_GBPoint::getPos3D(); }
319  /// @}
320 
321  /// @{
322  /// Get and set the homogeneous coordinate
323  SYS_DEPRECATED_HDK(13.0)
324  float getPw() const { return GA_GBPoint::getPw(); }
325  SYS_DEPRECATED_HDK(13.0)
326  void setPw(float w) { return GA_GBPoint::setPw(w); }
327  /// @}
328 
329  SYS_DEPRECATED_HDK(13.0)
331  SYS_DEPRECATED_HDK(13.0)
332  void setPos(const UT_Vector3 &P, float w=1)
333  { GA_GBPoint::setPos3D(P, w); }
334  SYS_DEPRECATED_HDK(13.0)
335  void setPos(float x, float y, float z)
336  { GA_GBPoint::setPos3D(x,y,z,1); }
337  SYS_DEPRECATED_HDK(13.0)
338  void setPos(float x, float y, float z, float w)
339  { GA_GBPoint::setPos3D(x,y,z,w); }
340 
341  /// New GA methods which support getting/setting positons without affecting
342  /// the w (homogeneous) coordinate.
343  /// @{
344  SYS_DEPRECATED_HDK(13.0)
345  const UT_Vector3 getPos3() const
346  { return GA_GBPoint::getPos2D(); }
347  SYS_DEPRECATED_HDK(13.0)
348  void setPos3(const UT_Vector3 &P)
349  { GA_GBPoint::setPos2D(P); }
350  /// @}
351 
352  SYS_DEPRECATED_HDK(14.0)
354  int index = 0) const
355  {
356  const GA_Attribute *attrib = h.getAttribute();
357  if (!attrib)
359  const GA_AIFSharedStringTuple *aif =
360  attrib->getAIFSharedStringTuple();
361  if (!aif)
363  UT_ASSERT( h.getAttribute() &&
364  &h.getAttribute()->getDetail() == &getDetail());
365  return aif->getHandle(attrib, getMapOffset(), index);
366  }
367 
368  SYS_DEPRECATED_HDK(14.0)
370  int index = 0) const
371  {
372  const GA_Attribute *attrib = h.getAttribute();
373  if (!attrib)
375  const GA_AIFSharedStringTuple *aif =
376  attrib->getAIFSharedStringTuple();
377  if (!aif)
379  UT_ASSERT( h.getAttribute() &&
380  &h.getAttribute()->getDetail() == &getDetail());
381  return aif->getHandle(attrib, getMapOffset(), index);
382  }
383 
385 
386 };
387 
388 /// DO NOT USE THIS CLASS!!!
390 {
391 public:
392  SYS_DEPRECATED_HDK(13.0)
394  : GA_GBPointP()
395  {}
396  SYS_DEPRECATED_HDK(13.0)
398  : GA_GBPointP(gdp, offset)
399  {}
400  SYS_DEPRECATED_HDK(13.0)
402  : GA_GBPointP(gdp, offset)
403  {}
404  SYS_DEPRECATED_HDK(13.0)
406  : GA_GBPointP(that)
407  {}
408  SYS_DEPRECATED_HDK(13.0)
410  : GA_GBPointP(that)
411  {}
412  SYS_DEPRECATED_HDK(13.0)
413  GEO_Point *operator->() const
414  {
415  return static_cast<GEO_Point*>((*this).GA_GBPointP::operator->());
416  }
417  SYS_DEPRECATED_HDK(13.0)
418  GEO_Point &operator*() const
419  {
420  return static_cast<GEO_Point&>((*this).GA_GBPointP::operator*());
421  }
422  SYS_DEPRECATED_HDK(13.0)
423  operator GEO_Point() const
424  {
425  return GEO_Point((*this)->getIndexMap(), (*this)->getMapOffset());
426  }
427 };
428 
430 
431 #endif
UT_Vector2 getPos2(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:163
A class to manage an ordered array which has fixed offset handles.
Definition: GA_IndexMap.h:63
SYS_FORCE_INLINE void setPos3(GA_Offset ptoff, const UT_Vector3 &P)
Set P from a UT_Vector3.
Definition: GA_Detail.h:203
Definition of a geometry attribute.
Definition: GA_Attribute.h:189
void setPos3D(const UT_Vector4 &P)
Definition: GEO_Point.h:136
GA_Offset getMapOffset() const
Definition: GA_GBElement.h:103
#define SYS_DEPRECATED_PUSH_DISABLE()
UT_Vector4 getPos4(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:248
#define SYS_DEPRECATED_POP_DISABLE()
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
SYS_FORCE_INLINE T * SYSconst_cast(const T *foo)
Definition: SYS_Types.h:126
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
T & x(void)
Definition: UT_Vector2.h:284
GLint y
Definition: glcorearb.h:102
GA_GBElement & operator=(const GA_GBElement &src)
Definition: GA_GBElement.h:81
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:170
SYS_FORCE_INLINE T & x(void)
Definition: UT_Vector3.h:581
3D Vector class.
void setPos2D(const UT_Vector3 &P)
Definition: GEO_Point.h:162
#define UT_ASSERT_P(ZZ)
Definition: UT_Assert.h:101
A string map of attributes to ease backward compatibility In the GB/GEO/GU library code would often p...
GA_Size GA_Offset
Definition: GA_Types.h:617
void setPw(float w)
Definition: GEO_Point.h:186
SYS_FORCE_INLINE T & z(void)
Definition: UT_Vector3.h:585
This class provides a way to manage a reference to an attribute permitting Read-Write access...
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
fpreal getPw(GA_Offset ptoff) const
Get the homogeneous coordinate for a point.
This class provides a way to manage a reference to an attribute permitting Read-Only access...
void setPw(GA_Offset ptoff, fpreal w)
Set the homogeneous coordinate for a point.
GLintptr offset
Definition: glcorearb.h:664
GA_GBPoint()
Definition: GEO_Point.h:36
#define GEO_API
Definition: GEO_API.h:10
virtual const GA_AIFSharedStringTuple * getAIFSharedStringTuple() const
Return the attribute's shared string tuple interface or NULL.
GA_Detail & getDetail() const
Provide access to the GA_Detail containing this element.
Definition: GA_GBElement.h:97
#define GA_INVALID_STRING_INDEX
GA_Detail DetailType
Definition: GEO_Point.h:384
DO NOT USE THIS CLASS!!!
Definition: GEO_Point.h:193
#define SYS_DEPRECATED_HDK(__V__)
~GA_GBPoint()
Definition: GEO_Point.h:49
GA_GBPoint myPoint
Definition: GEO_Point.h:295
~GEO_Point()
Definition: GEO_Point.h:311
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
SYS_FORCE_INLINE T & y(void)
Definition: UT_Vector3.h:583
GLuint index
Definition: glcorearb.h:785
const UT_Vector2 getPos2() const
Definition: GEO_Point.h:124
A specialization of GA_AIFStringTuple to access "shared strings".
GLint GLenum GLint x
Definition: glcorearb.h:408
float getPw() const
Definition: GEO_Point.h:130
GA_BlobIndex GA_StringIndexType
Container class for all geometry.
Definition: GA_Detail.h:96
GA_GBPoint(const GA_GBPoint &src)
Definition: GEO_Point.h:34
T & y(void)
Definition: UT_Vector2.h:286
GLubyte GLubyte GLubyte GLubyte w
Definition: glcorearb.h:856
const UT_Vector4 getPos3D() const
Definition: GEO_Point.h:112
GA_GBPoint(const GA_IndexMap &index_map, GA_Offset offset)
Definition: GEO_Point.h:32
const UT_Vector3 getPos2D() const
Definition: GEO_Point.h:118
#define const
Definition: zconf.h:214
DO NOT USE THIS CLASS!!!
Definition: GEO_Point.h:389
void setPos2(GA_Offset ptoff, const UT_Vector2 &P)
Set P from a UT_Vector2.
Definition: GA_Detail.h:196
virtual GA_StringIndexType getHandle(const GA_Attribute *attrib, GA_Offset ai, int tuple_index=0) const =0
Get the handle from the array for a single tuple of an element.
void setPos4(GA_Offset ptoff, const UT_Vector4 &P)
Set P from a UT_Vector4.
Definition: GA_Detail.h:254
GLenum src
Definition: glcorearb.h:1792
const GA_IndexMap & getIndexMap() const
Provide access to the GA_IndexMap containing this element.
Definition: GA_GBElement.h:99