HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
transform.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_BASE_GF_TRANSFORM_H
8 #define PXR_BASE_GF_TRANSFORM_H
9 
10 /// \file gf/transform.h
11 /// \ingroup group_gf_LinearAlgebra
12 
13 #include "pxr/pxr.h"
14 #include "pxr/base/gf/rotation.h"
15 #include "pxr/base/gf/vec3d.h"
16 #include "pxr/base/gf/api.h"
17 
18 #include <iosfwd>
19 
21 
22 class GfMatrix4d;
23 
24 /// \class GfTransform
25 /// \ingroup group_gf_LinearAlgebra
26 ///
27 /// Basic type: Compound linear transformation.
28 ///
29 /// This class represents a linear transformation specified as a series of
30 /// individual components: a \em translation, a \em rotation, a \em scale, a
31 /// \em pivotPosition, and a \em pivotOrientation. When applied to a point,
32 /// the point will be transformed as follows (in order):
33 ///
34 /// \li Scaled by the \em scale with respect to \em pivotPosition and the
35 /// orientation specified by the \em pivotOrientation.
36 /// \li Rotated by the \em rotation about \em pivotPosition.
37 /// \li Translated by \em Translation
38 ///
39 /// That is, the cumulative matrix that this represents looks like this.
40 ///
41 /// \code
42 /// M = -P * -O * S * O * R * P * T
43 /// \endcode
44 ///
45 /// where
46 /// \li \em T is the \em translation matrix
47 /// \li \em P is the matrix that translates by \em pivotPosition
48 /// \li \em R is the \em rotation matrix
49 /// \li \em O is the matrix that rotates to \em pivotOrientation
50 /// \li \em S is the \em scale matrix
51 ///
52 class GfTransform {
53 
54  public:
55 
56  /// The default constructor sets the component values to the
57  /// identity transformation.
59  SetIdentity();
60  }
61 
62  /// This constructor initializes the transformation from all
63  /// component values. This is the constructor used by 2x code.
65  const GfRotation &pivotOrientation,
66  const GfRotation &rotation,
67  const GfVec3d &pivotPosition,
68  const GfVec3d &translation) {
69  Set(scale, pivotOrientation, rotation, pivotPosition, translation);
70  }
71 
72  /// This constructor initializes the transformation from all
73  /// component values. This is the constructor used by 3x code.
74  GfTransform(const GfVec3d &translation,
75  const GfRotation &rotation,
76  const GfVec3d &scale,
77  const GfVec3d &pivotPosition,
78  const GfRotation &pivotOrientation) {
79  Set(translation, rotation, scale, pivotPosition, pivotOrientation);
80  }
81 
82  /// This constructor initializes the transformation with a matrix. See
83  /// SetMatrix() for more information.
84  GfTransform(const GfMatrix4d &m) {
85  SetIdentity();
86  SetMatrix(m);
87  }
88 
89  /// Sets the transformation from all component values.
90  /// This constructor orders its arguments the way that 2x expects.
91  GF_API
92  GfTransform & Set(const GfVec3d &scale,
93  const GfRotation &pivotOrientation,
94  const GfRotation &rotation,
95  const GfVec3d &pivotPosition,
96  const GfVec3d &translation);
97 
98  /// Sets the transformation from all component values.
99  /// This constructor orders its arguments the way that 3x expects.
100  GfTransform & Set(const GfVec3d &translation,
101  const GfRotation &rotation,
102  const GfVec3d &scale,
103  const GfVec3d &pivotPosition,
104  const GfRotation &pivotOrientation) {
105  return Set(scale, pivotOrientation, rotation,
106  pivotPosition, translation);
107  }
108 
109  /// Sets the transform components to implement the transformation
110  /// represented by matrix \p m , ignoring any projection. This tries to
111  /// leave the current center unchanged.
112  GF_API
113  GfTransform & SetMatrix(const GfMatrix4d &m);
114 
115  /// Sets the transformation to the identity transformation.
116  GF_API
118 
119  /// Sets the scale component, leaving all others untouched.
120  void SetScale(const GfVec3d &scale) {
121  _scale = scale;
122  }
123 
124  /// Sets the pivot orientation component, leaving all others untouched.
125  void SetPivotOrientation(const GfRotation &pivotOrient) {
126  _pivotOrientation = pivotOrient;
127  }
128 
129  /// Sets the pivot orientation component, leaving all others untouched.
130  void SetScaleOrientation(const GfRotation &pivotOrient) {
131  SetPivotOrientation(pivotOrient);
132  }
133 
134  /// Sets the rotation component, leaving all others untouched.
136  _rotation = rotation;
137  }
138 
139  /// Sets the pivot position component, leaving all others untouched.
140  void SetPivotPosition(const GfVec3d &pivPos) {
141  _pivotPosition = pivPos;
142  }
143 
144  /// Sets the pivot position component, leaving all others untouched.
145  void SetCenter(const GfVec3d &pivPos) {
146  SetPivotPosition(pivPos);
147  }
148 
149  /// Sets the translation component, leaving all others untouched.
150  void SetTranslation(const GfVec3d &translation) {
151  _translation = translation;
152  }
153 
154  /// Returns the scale component.
155  const GfVec3d & GetScale() const {
156  return _scale;
157  }
158 
159  /// Returns the pivot orientation component.
160  const GfRotation & GetPivotOrientation() const {
161  return _pivotOrientation;
162  }
163 
164  /// Returns the scale orientation component.
165  const GfRotation & GetScaleOrientation() const {
166  return GetPivotOrientation();
167  }
168 
169  /// Returns the rotation component.
170  const GfRotation & GetRotation() const {
171  return _rotation;
172  }
173 
174  /// Returns the pivot position component.
175  const GfVec3d & GetPivotPosition() const {
176  return _pivotPosition;
177  }
178 
179  /// Returns the pivot position component.
180  const GfVec3d & GetCenter() const {
181  return GetPivotPosition();
182  }
183 
184  /// Returns the translation component.
185  const GfVec3d & GetTranslation() const {
186  return _translation;
187  }
188 
189  /// Returns a \c GfMatrix4d that implements the cumulative transformation.
190  GF_API
191  GfMatrix4d GetMatrix() const;
192 
193  /// Component-wise transform equality test. All components must match
194  /// exactly for transforms to be considered equal.
195  GF_API
196  bool operator ==(const GfTransform &xf) const;
197 
198  /// Component-wise transform inequality test. All components must match
199  /// exactly for transforms to be considered equal.
200  bool operator !=(const GfTransform &xf) const {
201  return ! (*this == xf);
202  }
203 
204  /// Post-multiplies transform \p xf into this transform.
205  GF_API
206  GfTransform & operator *=(const GfTransform &xf);
207 
208  /// Returns the product of transforms \p xf1 and \p xf2.
209  friend GfTransform operator *(const GfTransform &xf1,
210  const GfTransform &xf2) {
211  GfTransform xf = xf1;
212  return xf *= xf2;
213  }
214 
215  private:
216  /// translation
217  GfVec3d _translation;
218  /// rotation
219  GfRotation _rotation;
220  /// scale factors
221  GfVec3d _scale;
222  /// orientation used for scaling and rotation
223  GfRotation _pivotOrientation;
224  /// center of rotation and scaling
225  GfVec3d _pivotPosition;
226 };
227 
228 /// Output a GfTransform using the format
229 /// [scale, scaleorientation, rotation, center, translation].
230 /// \ingroup group_gf_DebuggingOutput
231 GF_API std::ostream& operator<<(std::ostream&, const GfTransform&);
232 
234 
235 #endif // PXR_BASE_GF_TRANSFORM_H
void SetPivotOrientation(const GfRotation &pivotOrient)
Sets the pivot orientation component, leaving all others untouched.
Definition: transform.h:125
GF_API GfTransform & operator*=(const GfTransform &xf)
Post-multiplies transform xf into this transform.
GF_API GfTransform & Set(const GfVec3d &scale, const GfRotation &pivotOrientation, const GfRotation &rotation, const GfVec3d &pivotPosition, const GfVec3d &translation)
GfTransform(const GfVec3d &scale, const GfRotation &pivotOrientation, const GfRotation &rotation, const GfVec3d &pivotPosition, const GfVec3d &translation)
Definition: transform.h:64
GF_API GfTransform & SetMatrix(const GfMatrix4d &m)
const GfVec3d & GetTranslation() const
Returns the translation component.
Definition: transform.h:185
GF_API GfTransform & SetIdentity()
Sets the transformation to the identity transformation.
const GfVec3d & GetPivotPosition() const
Returns the pivot position component.
Definition: transform.h:175
void SetScale(const GfVec3d &scale)
Sets the scale component, leaving all others untouched.
Definition: transform.h:120
GF_API GfMatrix4d GetMatrix() const
Returns a GfMatrix4d that implements the cumulative transformation.
const GfVec3d & GetScale() const
Returns the scale component.
Definition: transform.h:155
GA_API const UT_StringHolder scale
void SetScaleOrientation(const GfRotation &pivotOrient)
Sets the pivot orientation component, leaving all others untouched.
Definition: transform.h:130
GfTransform & Set(const GfVec3d &translation, const GfRotation &rotation, const GfVec3d &scale, const GfVec3d &pivotPosition, const GfRotation &pivotOrientation)
Definition: transform.h:100
SIM_API const UT_StringHolder rotation
const GfVec3d & GetCenter() const
Returns the pivot position component.
Definition: transform.h:180
GfTransform(const GfVec3d &translation, const GfRotation &rotation, const GfVec3d &scale, const GfVec3d &pivotPosition, const GfRotation &pivotOrientation)
Definition: transform.h:74
friend GfTransform operator*(const GfTransform &xf1, const GfTransform &xf2)
Returns the product of transforms xf1 and xf2.
Definition: transform.h:209
bool operator!=(const GfTransform &xf) const
Definition: transform.h:200
const GfRotation & GetScaleOrientation() const
Returns the scale orientation component.
Definition: transform.h:165
GfTransform(const GfMatrix4d &m)
Definition: transform.h:84
GF_API std::ostream & operator<<(std::ostream &, const GfTransform &)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
Definition: vec3d.h:45
void SetRotation(const GfRotation &rotation)
Sets the rotation component, leaving all others untouched.
Definition: transform.h:135
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void SetPivotPosition(const GfVec3d &pivPos)
Sets the pivot position component, leaving all others untouched.
Definition: transform.h:140
void SetTranslation(const GfVec3d &translation)
Sets the translation component, leaving all others untouched.
Definition: transform.h:150
void SetCenter(const GfVec3d &pivPos)
Sets the pivot position component, leaving all others untouched.
Definition: transform.h:145
const GfRotation & GetRotation() const
Returns the rotation component.
Definition: transform.h:170
#define GF_API
Definition: api.h:23
GF_API bool operator==(const GfTransform &xf) const
const GfRotation & GetPivotOrientation() const
Returns the pivot orientation component.
Definition: transform.h:160