HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GA_AttributeInstanceMatrix.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: GA_AttributeInstanceMatrix.h ( GA Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #pragma once
12 
13 #ifndef __GA_AttributeInstanceMatrix__
14 #define __GA_AttributeInstanceMatrix__
15 
16 #include "GA_API.h"
17 #include "GA_Attribute.h"
18 #include "GA_Handle.h"
19 #include "GA_Names.h"
20 #include "GA_Types.h"
21 
22 #include <UT/UT_SharedPtr.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_VectorTypes.h>
25 #include <SYS/SYS_Types.h>
26 
27 class GA_AttributeDict;
28 
29 /// @brief Compute an instance transform given a set of attributes
30 ///
31 /// Given a normal (or velocity) attribute, along with attributes for the up
32 /// vector, a translation offset, a uniform scale, a 3-tuple scale, a rotation
33 /// quaternion and an orientation quaternion, compute a 4x4 transform matrix
34 /// for a given position.
35 ///
36 /// This transform is the same as the one generated by the copy SOP or by SOHO
37 /// instancing.
38 ///
39 /// @see UT_Matrix4::instance()
41 {
42 public:
43  /// Default c-tor
45  : myRemoveScales(false)
46  {}
47 
48  /// Construct given the explicit attributes
49  ///
50  /// All attributes must be bound to the same owner (GA_AttributeOwner).
51  /// The offset passed into @c getMatrix() determines which element is used
52  /// to build the matrix. The owner does not have to be GA_ATTRIB_POINT,
53  /// though that is the most common case.
55  const GA_Attribute *N,
56  const GA_Attribute *v,
57  const GA_Attribute *up,
58  const GA_Attribute *trans,
59  const GA_Attribute *pscale,
60  const GA_Attribute *pscale3,
61  const GA_Attribute *rot,
62  const GA_Attribute *orient,
63  const GA_Attribute *pivot,
64  const GA_Attribute *xform3,
65  const GA_Attribute *xform4
66  )
67  : myN(N ? N : v)
68  , myPscale(pscale)
69  , myPscale3(pscale3)
70  , myUp(up)
71  , myTrans(trans)
72  , myRot(rot)
73  , myOrient(orient)
74  , myPivot(pivot)
75  , myXform3(xform3)
76  , myXform4(xform4)
77  , myRemoveScales(false)
78  {
79  validate();
80  }
81 
83  const UT_StringRef &N_name = GA_Names::N,
84  const UT_StringRef &v_name = GA_Names::v)
85  {
86  initialize(dict, N_name, v_name);
87  }
88 
90  const GA_Attribute *N)
91  {
92  initialize(dict, N);
93  }
94 
96 
97  /// Initialize attribute lookups based on an attribute dictionary
98  /// This method scans for:
99  /// - "vector v" or "vector N" (z-axis)
100  /// - "vector up" (up vector for orientation)
101  /// - "vector trans" (translation offset)
102  /// - "vector scale" (per-axis scale)
103  /// - "float pscale" (uniform scale)
104  /// - "vector4 rot" (quaternion)
105  /// - "vector4 orient" (quaternion)
106  /// - "vector pivot" (pivot)
107  /// @c N_name defines the name of the attribute to look up to determine
108  /// orientation. If there is no attribute of the given name, then an
109  /// attribute named @c v_name will be searched for.
110  ///
111  void initialize(const GA_AttributeDict &dict,
112  const UT_StringRef &N_name = GA_Names::N,
113  const UT_StringRef &v_name = GA_Names::v);
114  /// Initialize with a provided, possilby detached N.
115  void initialize(const GA_AttributeDict &dict,
116  const GA_Attribute *N);
117 
118 
119  /// Clear out any attribute handles
120  void reset();
121 
122  /// Resets only the scale attributes.
123  void resetScales();
124 
125  /// Make invalid
126  void makeInvalid() { reset(); }
127 
128  /// @{
129  /// Create a 4x4 transform matrix given a position (@c P) and an attribute
130  /// element for which the GA_ROHandle objects are valid.
131  ///
132  /// If the "pscale" attribute is invalid, the @c default_pscale will be
133  /// used.
134  ///
135  /// @note The position (@c P) is passed in since the attribute handles may
136  /// not be bound to point attributes.
137  void getMatrix(UT_Matrix4 &xform,
138  const UT_Vector3 &P,
140  float default_pscale=1) const;
141  void getMatrix(UT_Matrix4D &xform,
142  const UT_Vector3D &P,
144  fpreal default_pscale=1) const;
145  void getInverseMatrix(UT_Matrix4 &xform,
146  const UT_Vector3 &P,
148  float default_pscale=1) const;
149  void getInverseMatrix(UT_Matrix4D &xform,
150  const UT_Vector3D &P,
152  fpreal default_pscale=1) const;
153  /// @}
154 
155  /// Create a 3x3 transform matrix ignoring translate components
156  /// Will include scale if still present!
157  void getMatrix(UT_Matrix3 &xform,
158  GA_Offset offset) const;
159  void getMatrix(UT_DMatrix3 &xform,
160  GA_Offset offset) const;
161  void getInverseMatrix(UT_Matrix3 &xform,
162  GA_Offset offset) const;
163  void getInverseMatrix(UT_DMatrix3 &xform,
164  GA_Offset offset) const;
165 
166  /// @{
167  /// Create a 4x4 transform matrix given a position (@c P),
168  /// an orientaiton (@c orient), and an attribute
169  /// element for which the GA_ROHandle objects are valid.
170  ///
171  /// The provided orientation will be used instead of any rotation
172  /// attributes on the geometry, but the translation and pivot attributes
173  /// will still be used.
174  ///
175  /// If the "pscale" attribute is invalid, the @c default_pscale will be
176  /// used.
177  ///
178  /// @note The position (@c P) is passed in since the attribute handles may
179  /// not be bound to point attributes.
180  void getMatrix(UT_Matrix4 &xform,
181  const UT_Vector3 &P,
182  const UT_Quaternion &orient,
184  float default_pscale=1) const;
185  void getMatrix(UT_Matrix4D &xform,
186  const UT_Vector3D &P,
187  const UT_QuaternionD &orient,
189  fpreal default_pscale=1) const;
190  void getInverseMatrix(UT_Matrix4 &xform,
191  const UT_Vector3 &P,
192  const UT_Quaternion &orient,
194  float default_pscale=1) const;
195  void getInverseMatrix(UT_Matrix4D &xform,
196  const UT_Vector3D &P,
197  const UT_QuaternionD &orient,
199  fpreal default_pscale=1) const;
200  /// @}
201 
202  /// Returns true if there are any attributes bound
203  bool hasAnyAttribs() const;
204 
205  /// Returns true if there are any attributes bound to
206  /// anything other than myPscale or myPscale3
207  bool hasNonScales() const;
208 
209  /// Returns true if myPscale or myPscale3 is bound
210  bool hasScales() const;
211 
212  /// Returns just the product of myPscale and myPscale3
213  UT_Vector3D getScales(GA_Offset offset) const;
214 
215  /// @{
216  /// Accessors
217  const GA_ROHandleV3D &getN() const { return myN; }
218  const GA_ROHandleV3D &getUp() const { return myUp; }
219  const GA_ROHandleV3D &getTrans() const { return myTrans; }
220  const GA_ROHandleD &getPscale() const { return myPscale; }
221  const GA_ROHandleV3D &getPscale3() const { return myPscale3; }
222  const GA_ROHandleQD &getRot() const { return myRot; }
223  const GA_ROHandleQD &getOrient() const { return myOrient; }
224  const GA_ROHandleV3D &getPivot() const { return myPivot; }
225  const GA_ROHandleM3D &getXform3() const { return myXform3; }
226  const GA_ROHandleM4D &getXform4() const { return myXform4; }
227  bool getRemoveScales() const { return myRemoveScales; }
228  /// @}
229 
230  /// Overrides the N attribute with the specified attribute.
231  void setN(const GA_Attribute *N)
232  { myN.bind(N); }
233 
234  /// The number of attributes cached for use with transforms by this class.
235  /// If an attribute gets added, be sure to update this and the getDataIds
236  /// function implementation.
237  static constexpr int theNumAttribs = 10;
238 
239  /// This uses GA_DataId(-2) to indicate an attribute not being present,
240  /// to distinguish it from GA_DataId(-1), which is usually considered
241  /// unequal even to itself.
242  static constexpr GA_DataId theAttribNotPresentDataId = GA_DataId(-2);
243 
244  /// Get all data IDs of attributes used by this class.
245  /// This uses a value of theAttribNotPresentDataId for attributes
246  /// that aren't present.
247  void getDataIds(GA_DataId data_ids[theNumAttribs]) const;
248 
249 private:
250  void validate();
251 
252 public:
264 };
265 
267 
268 #endif
Definition of a geometry attribute.
Definition: GA_Attribute.h:198
GA_AttributeInstanceMatrix(const GA_Attribute *N, const GA_Attribute *v, const GA_Attribute *up, const GA_Attribute *trans, const GA_Attribute *pscale, const GA_Attribute *pscale3, const GA_Attribute *rot, const GA_Attribute *orient, const GA_Attribute *pivot, const GA_Attribute *xform3, const GA_Attribute *xform4)
UT_SharedPtr< GA_AttributeInstanceMatrix > GA_AttributeInstanceMatrixPtr
int64 GA_DataId
Definition: GA_Types.h:696
const GLdouble * v
Definition: glcorearb.h:837
GA_API const UT_StringHolder rot
#define GA_API
Definition: GA_API.h:14
const GA_ROHandleV3D & getPivot() const
const GA_ROHandleD & getPscale() const
GA_API const UT_StringHolder v
GA_AttributeInstanceMatrix(const GA_AttributeDict &dict, const GA_Attribute *N)
A string map of attributes to ease backward compatibility In the GB/GEO/GU library code would often p...
GA_AttributeInstanceMatrix(const GA_AttributeDict &dict, const UT_StringRef &N_name=GA_Names::N, const UT_StringRef &v_name=GA_Names::v)
GA_Size GA_Offset
Definition: GA_Types.h:646
const GA_ROHandleM3D & getXform3() const
const GA_ROHandleV3D & getN() const
GLintptr offset
Definition: glcorearb.h:665
GLboolean reset
Definition: glad.h:5138
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
GA_API const UT_StringHolder trans
const GA_ROHandleV3D & getPscale3() const
const GA_ROHandleQD & getOrient() const
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
GA_API const UT_StringHolder orient
const GA_ROHandleM4D & getXform4() const
GA_API const UT_StringHolder up
fpreal64 fpreal
Definition: SYS_Types.h:277
Compute an instance transform given a set of attributes.
GA_API const UT_StringHolder pscale
const GA_ROHandleV3D & getUp() const
GA_API const UT_StringHolder N
const GA_ROHandleQD & getRot() const
GA_API const UT_StringHolder pivot
const GA_ROHandleV3D & getTrans() const
void setN(const GA_Attribute *N)
Overrides the N attribute with the specified attribute.