All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 USDGEOM_XFORMCACHE_H
25 #define USDGEOM_XFORMCACHE_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 
32 #include "pxr/usd/usdGeom/xformable.h"
33 
34 #include "pxr/base/gf/matrix4d.h"
35 #include "pxr/base/tf/hashmap.h"
36 #include "pxr/base/tf/token.h"
37 
38 #include <boost/functional/hash.hpp>
39 
40 PXR_NAMESPACE_OPEN_SCOPE
41 
42 
59 {
60 public:
62  USDGEOM_API
63  explicit UsdGeomXformCache(const UsdTimeCode time);
64 
66  USDGEOM_API
68 
74  USDGEOM_API
76 
82  USDGEOM_API
84 
90  USDGEOM_API
92  bool *resetsXformStack);
93 
103  USDGEOM_API
105  const UsdPrim &ancestor,
106  bool *resetXformStack);
107 
113  USDGEOM_API
115  const TfToken &attrName);
116 
121  USDGEOM_API
122  bool TransformMightBeTimeVarying(const UsdPrim &prim);
123 
128  USDGEOM_API
129  bool GetResetXformStack(const UsdPrim &prim);
130 
132  USDGEOM_API
133  void Clear();
134 
138  USDGEOM_API
139  void SetTime(UsdTimeCode time);
140 
142  UsdTimeCode GetTime() { return _time; }
143 
145  USDGEOM_API
146  void Swap(UsdGeomXformCache& other);
147 
148 private:
149 
150  // Traverses backwards the hierarchy starting from prim
151  // all the way to the root and computes the ctm
152  GfMatrix4d const* _GetCtm(const UsdPrim& prim);
153 
154  // Map of cached values.
155  struct _Entry {
156  _Entry() = default;
157  _Entry(const UsdGeomXformable::XformQuery & query_,
158  const GfMatrix4d& ctm_,
159  bool ctmIsValid_)
160  : query(query_)
161  , ctm(ctm_)
162  , ctmIsValid(ctmIsValid_)
163  { }
164 
166  GfMatrix4d ctm;
167  bool ctmIsValid;
168  };
169 
170  // Helper function to get or create a new entry for a prim in the ctm cache.
171  _Entry * _GetCacheEntryForPrim(const UsdPrim &prim);
172 
173  typedef TfHashMap<UsdPrim, _Entry, boost::hash<UsdPrim> > _PrimHashMap;
174  _PrimHashMap _ctmCache;
175 
176  // The time at which this stack is querying and caching attribute values.
177  UsdTimeCode _time;
178 };
179 
180 #define USDGEOM_XFORM_CACHE_API_VERSION 1
181 
182 
183 PXR_NAMESPACE_CLOSE_SCOPE
184 
185 #endif // USDGEOM_XFORMCACHE_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:377
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
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:142
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...
A caching mechanism for transform matrices.
Definition: xformCache.h:58