xformCache.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_USD_USD_GEOM_XFORM_CACHE_H
25 #define PXR_USD_USD_GEOM_XFORM_CACHE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usdGeom/api.h"
29 #include "pxr/usd/usd/attributeQuery.h"
30 #include "pxr/usd/usd/prim.h"
31 
33 
34 #include "pxr/base/gf/matrix4d.h"
35 #include "pxr/base/tf/hash.h"
36 #include "pxr/base/tf/hashmap.h"
37 #include "pxr/base/tf/token.h"
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 
58 {
59 public:
61  USDGEOM_API
62  explicit UsdGeomXformCache(const UsdTimeCode time);
63 
65  USDGEOM_API
67 
73  USDGEOM_API
75 
81  USDGEOM_API
83 
89  USDGEOM_API
91  bool *resetsXformStack);
92 
102  USDGEOM_API
104  const UsdPrim &ancestor,
105  bool *resetXformStack);
106 
112  USDGEOM_API
114  const TfToken &attrName);
115 
120  USDGEOM_API
121  bool TransformMightBeTimeVarying(const UsdPrim &prim);
122 
127  USDGEOM_API
128  bool GetResetXformStack(const UsdPrim &prim);
129 
131  USDGEOM_API
132  void Clear();
133 
137  USDGEOM_API
138  void SetTime(UsdTimeCode time);
139 
141  UsdTimeCode GetTime() { return _time; }
142 
144  USDGEOM_API
145  void Swap(UsdGeomXformCache& other);
146 
147 private:
148 
149  // Traverses backwards the hierarchy starting from prim
150  // all the way to the root and computes the ctm
151  GfMatrix4d const* _GetCtm(const UsdPrim& prim);
152 
153  // Map of cached values.
154  struct _Entry {
155  _Entry() = default;
156  _Entry(const UsdGeomXformable::XformQuery & query_,
157  const GfMatrix4d& ctm_,
158  bool ctmIsValid_)
159  : query(query_)
160  , ctm(ctm_)
161  , ctmIsValid(ctmIsValid_)
162  { }
163 
165  GfMatrix4d ctm;
166  bool ctmIsValid;
167  };
168 
169  // Helper function to get or create a new entry for a prim in the ctm cache.
170  _Entry * _GetCacheEntryForPrim(const UsdPrim &prim);
171 
172  typedef TfHashMap<UsdPrim, _Entry, TfHash> _PrimHashMap;
173  _PrimHashMap _ctmCache;
174 
175  // The time at which this stack is querying and caching attribute values.
176  UsdTimeCode _time;
177 };
178 
179 #define USDGEOM_XFORM_CACHE_API_VERSION 1
180 
181 
182 PXR_NAMESPACE_CLOSE_SCOPE
183 
184 #endif // PXR_USD_USD_GEOM_XFORM_CACHE_H
USDGEOM_API bool GetResetXformStack(const UsdPrim &prim)
Whether the xform stack is reset at the given prim.
USDGEOM_API void Clear()
Clears all pre-cached values.
USDGEOM_API UsdGeomXformCache()
Construct a new XformCache for UsdTimeCode::Default().
USDGEOM_API bool IsAttributeIncludedInLocalTransform(const UsdPrim &prim, const TfToken &attrName)
Whether the attribute named attrName, belonging to the given prim affects the local transform value a...
Helper class that caches the ordered vector of UsGeomXformOps that contribute to the local transforma...
Definition: xformable.h:379
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:87
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:84
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:135
USDGEOM_API GfMatrix4d GetLocalToWorldTransform(const UsdPrim &prim)
Compute the transformation matrix for the given prim, including the transform authored on the Prim it...
UsdTimeCode GetTime()
Get the current time from which this cache is reading values.
Definition: xformCache.h:141
USDGEOM_API GfMatrix4d GetParentToWorldTransform(const UsdPrim &prim)
Compute the transformation matrix for the given prim, but do NOT include the transform authored on th...
USDGEOM_API GfMatrix4d ComputeRelativeTransform(const UsdPrim &prim, const UsdPrim &ancestor, bool *resetXformStack)
Returns the result of concatenating all transforms beneath ancestor that affect prim.
USDGEOM_API bool TransformMightBeTimeVarying(const UsdPrim &prim)
Whether the local transformation value at the prim may vary over time.
USDGEOM_API GfMatrix4d GetLocalTransformation(const UsdPrim &prim, bool *resetsXformStack)
Returns the local transformation of the prim.
USDGEOM_API void Swap(UsdGeomXformCache &other)
Swap the contents of this XformCache with other.
USDGEOM_API void SetTime(UsdTimeCode time)
Use the new time when computing values and may clear any existing values cached for the previous time...
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
A caching mechanism for transform matrices.
Definition: xformCache.h:57