All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
xformStack.h
1 // Copyright 2017 Pixar
2 //
3 // Licensed under the Apache License, Version 2.0 (the "Apache License")
4 // with the following modification; you may not use this file except in
5 // compliance with the Apache License and the following modification to it:
6 // Section 6. Trademarks. is deleted and replaced with:
7 //
8 // 6. Trademarks. This License does not grant permission to use the trade
9 // names, trademarks, service marks, or product names of the Licensor
10 // and its affiliates, except as required to comply with Section 4(c) of
11 // the License and to reproduce the content of the NOTICE file.
12 //
13 // You may obtain a copy of the Apache License at
14 //
15 // http://www.apache.org/licenses/LICENSE-2.0
16 //
17 // Unless required by applicable law or agreed to in writing, software
18 // distributed under the Apache License with the above modification is
19 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20 // KIND, either express or implied. See the Apache License for the specific
21 // language governing permissions and limitations under the Apache License.
22 //
23 
24 #ifndef PXRUSDMAYA_XFORM_STACK_H
25 #define PXRUSDMAYA_XFORM_STACK_H
26 
27 #include "pxr/pxr.h"
28 #include "usdMaya/api.h"
29 #include "pxr/base/tf/refPtr.h"
30 #include "pxr/base/tf/token.h"
31 #include "pxr/usd/usdGeom/xformOp.h"
32 
33 #include <maya/MTransformationMatrix.h>
34 
35 #include <limits>
36 #include <vector>
37 #include <unordered_map>
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 // Note: pivotTranslate is currently not used in MayaXformStack,
42 // CommonXformStack, or MatrixStack, so it should never occur
43 // at present, but there was some support for reading it, thus
44 // why it's here
45 
47 #define PXRUSDMAYA_XFORM_STACK_TOKENS \
48  (translate) \
49  (rotatePivotTranslate) \
50  (rotatePivot) \
51  (rotate) \
52  (rotateAxis) \
53  (scalePivotTranslate) \
54  (scalePivot) \
55  (shear) \
56  (scale) \
57  (pivot) \
58  (pivotTranslate) \
59  (transform)
60 
61 TF_DECLARE_PUBLIC_TOKENS(UsdMayaXformStackTokens,
62  PXRUSDMAYA_API,
63  PXRUSDMAYA_XFORM_STACK_TOKENS);
64 
72 {
73 public:
75  UsdGeomXformOp::Type opType,
76  bool isInvertedTwin=false);
77 
79 
80  static UsdMayaXformOpClassification const & NullInstance();
81 
82  PXRUSDMAYA_API
83  TfToken const &GetName() const;
84 
85  PXRUSDMAYA_API
86  UsdGeomXformOp::Type GetOpType() const;
87 
88  PXRUSDMAYA_API
89  bool IsInvertedTwin() const;;
90 
94  PXRUSDMAYA_API
95  bool IsCompatibleType(UsdGeomXformOp::Type otherType) const;
96 
97  PXRUSDMAYA_API
98  bool operator ==(const UsdMayaXformOpClassification& other) const;
99 
100  PXRUSDMAYA_API
101  bool IsNull() const;
102 
103  PXRUSDMAYA_API
104  std::vector<TfToken> CompatibleAttrNames() const;
105 
106 private:
107  class _Data;
108 
109  // Because this is an immutable type, we keep a pointer to shared
110  // data; this allows us to only have overhead associated with
111  // a RefPtr, while having easy-python-wrapping (without overhead
112  // of WeakPtr)
114  _DataRefPtr _sharedData;
115 };
116 
123 {
124 public:
126  typedef std::vector<OpClass> OpClassList;
127  typedef std::pair<const OpClass, const OpClass> OpClassPair;
128 
129  // Internally, we use indices, because position sometimes matters...
130  // should be safe, since _ops is const.
131  static constexpr size_t NO_INDEX = std::numeric_limits<size_t>::max();
132  typedef std::pair<size_t, size_t> IndexPair;
133  typedef std::unordered_map<TfToken, IndexPair, TfToken::HashFunctor>
134  TokenIndexPairMap;
135  typedef std::unordered_map<size_t, size_t> IndexMap;
136 
137 
138  // Templated because we want it to work with both MEulerRotation::RotationOrder
139  // and MTransformationMatrix::RotationOrder
140  template<typename RotationOrder>
141  static RotationOrder RotateOrderFromOpType(
142  UsdGeomXformOp::Type opType,
143  RotationOrder defaultRotOrder=RotationOrder::kXYZ)
144  {
145  switch(opType) {
147  return RotationOrder::kXYZ;
148  break;
150  return RotationOrder::kXZY;
151  break;
153  return RotationOrder::kYXZ;
154  break;
156  return RotationOrder::kYZX;
157  break;
159  return RotationOrder::kZXY;
160  break;
162  return RotationOrder::kZYX;
163  break;
164  default:
165  return defaultRotOrder;
166  break;
167  }
168  }
169 
171  const OpClassList& ops,
172  const std::vector<IndexPair>& inversionTwins,
173  bool nameMatters=true);
174 
175  // Don't want to accidentally make a copy, since the only instances are supposed
176  // to be static!
177  explicit UsdMayaXformStack(const UsdMayaXformStack& other) = default;
178  explicit UsdMayaXformStack(UsdMayaXformStack&& other) = default;
179 
180  PXRUSDMAYA_API
181  OpClassList const & GetOps() const;
182 
183  PXRUSDMAYA_API
184  const std::vector<IndexPair>& GetInversionTwins() const;
185 
186  PXRUSDMAYA_API
187  bool GetNameMatters() const;
188 
189  PXRUSDMAYA_API
190  UsdMayaXformOpClassification const & operator[] (const size_t index) const;
191 
192  PXRUSDMAYA_API
193  size_t GetSize() const;
194 
195 
203  PXRUSDMAYA_API
204  size_t FindOpIndex(const TfToken& opName, bool isInvertedTwin=false) const;
205 
215  PXRUSDMAYA_API
216  const OpClass& FindOp(const TfToken& opName, bool isInvertedTwin=false) const;
217 
226  PXRUSDMAYA_API
227  const IndexPair& FindOpIndexPair(const TfToken& opName) const;
228 
237  PXRUSDMAYA_API
238  const OpClassPair FindOpPair(const TfToken& opName) const;
239 
251  PXRUSDMAYA_API
252  OpClassList
254  const std::vector<UsdGeomXformOp>& xformops) const;
255 
270  PXRUSDMAYA_API
271  static const UsdMayaXformStack& MayaStack();
272 
273 
282  PXRUSDMAYA_API
283  static const UsdMayaXformStack& CommonStack();
284 
291  PXRUSDMAYA_API
292  static const UsdMayaXformStack& MatrixStack();
293 
298  PXRUSDMAYA_API
299  static OpClassList
301  const std::vector<UsdMayaXformStack const *>& stacks,
302  const std::vector<UsdGeomXformOp>& xformops);
303 
304 private:
305  class _Data;
306 
307  // Because this is an immutable type, we keep a pointer to shared
308  // data; this allows us to only have overhead associated with
309  // a RefPtr, while having easy-python-wrapping (without overhead
310  // of WeakPtr)
312  _DataRefPtr _sharedData;
313 };
314 
315 PXR_NAMESPACE_CLOSE_SCOPE
316 
317 #endif
Set of 3 canonical Euler rotations in ZYX order.
Definition: xformOp.h:133
PXRUSDMAYA_API const IndexPair & FindOpIndexPair(const TfToken &opName) const
Finds the indices of Op Classification(s) with the given name in this stack.
Set of 3 canonical Euler rotations in ZXY order.
Definition: xformOp.h:131
PXRUSDMAYA_API const OpClassPair FindOpPair(const TfToken &opName) const
Finds the Op Classification(s) with the given name in this stack.
static PXRUSDMAYA_API const UsdMayaXformStack & MayaStack()
The standard Maya xform stack.
Type
Enumerates the set of all transformation operation types.
Definition: xformOp.h:116
PXRUSDMAYA_API OpClassList MatchingSubstack(const std::vector< UsdGeomXformOp > &xformops) const
Returns a list of matching XformOpDefinitions for this stack.
PXRUSDMAYA_API const OpClass & FindOp(const TfToken &opName, bool isInvertedTwin=false) const
Finds the Op Classification with the given name in this stack.
Set of 3 canonical Euler rotations in XZY order.
Definition: xformOp.h:125
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
static PXRUSDMAYA_API OpClassList FirstMatchingSubstack(const std::vector< UsdMayaXformStack const * > &stacks, const std::vector< UsdGeomXformOp > &xformops)
Runs MatchingSubstack against the given list of stacks.
PXRUSDMAYA_API bool IsCompatibleType(UsdGeomXformOp::Type otherType) const
Return True if the given op type is compatible with this OpClassification (ie, is the same...
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
Defines a named &quot;class&quot; of xform operation.
Definition: xformStack.h:71
Defines a standard list of xform operations.
Definition: xformStack.h:122
PXRUSDMAYA_API size_t FindOpIndex(const TfToken &opName, bool isInvertedTwin=false) const
Finds the index of the Op Classification with the given name in this stack.
Set of 3 canonical Euler rotations in YZX order.
Definition: xformOp.h:129
Set of 3 canonical Euler rotations in YXZ order.
Definition: xformOp.h:127
static PXRUSDMAYA_API const UsdMayaXformStack & CommonStack()
The Common API xform stack.
Set of 3 canonical Euler rotations in XYZ order.
Definition: xformOp.h:123
static PXRUSDMAYA_API const UsdMayaXformStack & MatrixStack()
xform &quot;stack&quot; consisting of only a single matrix xform