This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
xformCache.h
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_USD_USD_GEOM_XFORM_CACHE_H
8#define PXR_USD_USD_GEOM_XFORM_CACHE_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usdGeom/api.h"
12#include "pxr/usd/usd/attributeQuery.h"
13#include "pxr/usd/usd/prim.h"
14
16
18#include "pxr/base/tf/hash.h"
19#include "pxr/base/tf/hashmap.h"
20#include "pxr/base/tf/token.h"
21
22PXR_NAMESPACE_OPEN_SCOPE
23
24
41{
42public:
44 USDGEOM_API
45 explicit UsdGeomXformCache(const UsdTimeCode time);
46
48 USDGEOM_API
50
56 USDGEOM_API
58
64 USDGEOM_API
66
72 USDGEOM_API
74 bool *resetsXformStack);
75
85 USDGEOM_API
87 const UsdPrim &ancestor,
88 bool *resetXformStack);
89
95 USDGEOM_API
97 const TfToken &attrName);
98
103 USDGEOM_API
105
110 USDGEOM_API
111 bool GetResetXformStack(const UsdPrim &prim);
112
114 USDGEOM_API
115 void Clear();
116
120 USDGEOM_API
122
124 UsdTimeCode GetTime() { return _time; }
125
127 USDGEOM_API
129
130private:
131
132 // Traverses backwards the hierarchy starting from prim
133 // all the way to the root and computes the ctm
134 GfMatrix4d const* _GetCtm(const UsdPrim& prim);
135
136 // Map of cached values.
137 struct _Entry {
138 _Entry() = default;
139 _Entry(const UsdGeomXformable::XformQuery & query_,
140 const GfMatrix4d& ctm_,
141 bool ctmIsValid_)
142 : query(query_)
143 , ctm(ctm_)
144 , ctmIsValid(ctmIsValid_)
145 { }
146
148 GfMatrix4d ctm;
149 bool ctmIsValid;
150 };
151
152 // Helper function to get or create a new entry for a prim in the ctm cache.
153 _Entry * _GetCacheEntryForPrim(const UsdPrim &prim);
154
155 typedef TfHashMap<UsdPrim, _Entry, TfHash> _PrimHashMap;
156 _PrimHashMap _ctmCache;
157
158 // The time at which this stack is querying and caching attribute values.
159 UsdTimeCode _time;
160};
161
162#define USDGEOM_XFORM_CACHE_API_VERSION 1
163
164
165PXR_NAMESPACE_CLOSE_SCOPE
166
167#endif // PXR_USD_USD_GEOM_XFORM_CACHE_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A caching mechanism for transform matrices.
Definition: xformCache.h:41
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 IsAttributeIncludedInLocalTransform(const UsdPrim &prim, const TfToken &attrName)
Whether the attribute named attrName, belonging to the given prim affects the local transform value a...
USDGEOM_API GfMatrix4d GetLocalTransformation(const UsdPrim &prim, bool *resetsXformStack)
Returns the local transformation of the prim.
UsdTimeCode GetTime()
Get the current time from which this cache is reading values.
Definition: xformCache.h:124
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 UsdGeomXformCache()
Construct a new XformCache for UsdTimeCode::Default().
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...
USDGEOM_API GfMatrix4d GetLocalToWorldTransform(const UsdPrim &prim)
Compute the transformation matrix for the given prim, including the transform authored on the Prim it...
USDGEOM_API bool TransformMightBeTimeVarying(const UsdPrim &prim)
Whether the local transformation value at the prim may vary over time.
USDGEOM_API void Clear()
Clears all pre-cached values.
USDGEOM_API bool GetResetXformStack(const UsdPrim &prim)
Whether the xform stack is reset at the given prim.
USDGEOM_API UsdGeomXformCache(const UsdTimeCode time)
Construct a new XformCache for the specified time.
Helper class that caches the ordered vector of UsGeomXformOps that contribute to the local transforma...
Definition: xformable.h:362
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:67
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...