HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
USD_XformCache.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 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 _GUSD_USD_XFORMCACHE_H_
25 #define _GUSD_USD_XFORMCACHE_H_
26 
27 #include "gusd/api.h"
28 
29 #include "gusd/defaultArray.h"
30 #include "gusd/UT_CappedCache.h"
31 #include "gusd/USD_DataCache.h"
32 #include "gusd/USD_Utils.h"
33 
34 #include "pxr/pxr.h"
36 
38 
39 /** Concurrent memory-capped cache for primitive transforms.*/
41 {
42 public:
43 
44  GUSD_API
46 
49 
50  ~GusdUSD_XformCache() override {}
51 
52  bool GetLocalTransformation(const UsdPrim& prim,
54  UT_Matrix4D& xform);
55 
56  bool GetLocalToWorldTransform(const UsdPrim& prim,
58  UT_Matrix4D& xform);
59 
60  /** Compute multiple local transforms in parallel. */
62  const UT_Array<UsdPrim>& prims,
63  const GusdDefaultArray<UsdTimeCode>& times,
64  UT_Matrix4D* xfroms);
65 
66  /** Compute multiple world transforms in parallel.*/
68  const UT_Array<UsdPrim>& prims,
69  const GusdDefaultArray<UsdTimeCode>& times,
70  UT_Matrix4D* xforms);
71 
72  /* Compute constraint transforms given a common constraint name
73  for all prims. Constraint transforms not cached.*/
75  const TfToken& constraint,
76  const UT_Array<UsdPrim>& prims,
77  const GusdDefaultArray<UsdTimeCode>& times,
78  UT_Matrix4D* xforms);
79 
80  /* Given tokens representing *full* names of attributes
81  (I.e., including the namespace), compute constraint transforms.
82  Constraint transforms not cached.*/
84  const UT_Array<TfToken>& constraints,
85  const UT_Array<UsdPrim>& prims,
86  const GusdDefaultArray<UsdTimeCode>& times,
87  UT_Matrix4D* xforms);
88 
89  struct XformInfo : public UT_CappedItem
90  {
91  enum Flags
92  {
96  };
97 
99  : UT_CappedItem(), query(xf), _flags(0) {}
100 
101  ~XformInfo() override {}
102 
103  int64 getMemoryUsage() const override
104  { return sizeof(*this); }
105 
106  void ComputeFlags(const UsdPrim& prim,
107  GusdUSD_XformCache& cache);
108 
110  { return _flags&FLAGS_LOCAL_MAYBE_TIMEVARYING; }
111 
113  { return _flags&FLAGS_WORLD_MAYBE_TIMEVARYING; }
114 
116  { return _flags&FLAGS_HAS_PARENT_XFORM; }
117 
119  private:
120  int _flags;
121  };
123 
124 
125  GUSD_API
126  XformInfoHandle GetXformInfo(const UsdPrim& prim);
127 
128  GUSD_API
129  void Clear() override;
130 
131  GUSD_API
132  int64 Clear(const UT_StringSet& paths) override;
133 
134 private:
135  bool _GetLocalTransformation(const UsdPrim& prim,
137  UT_Matrix4D& xform,
138  const XformInfoHandle& info);
139 
140 
141 
142 private:
143  GusdUT_CappedCache _xforms, _worldXforms, _xformInfos;
144 };
145 
147 
148 #endif /*_GUSD_USD_XFORMCACHE_H_*/
GLenum query
Definition: glad.h:2772
SYS_FORCE_INLINE bool WorldXformIsMaybeTimeVarying() const
GT_API const UT_StringHolder time
int64 getMemoryUsage() const override
UT_IntrusivePtr< const XformInfo > XformInfoHandle
bool GetConstraintTransforms(const TfToken &constraint, const UT_Array< UsdPrim > &prims, const GusdDefaultArray< UsdTimeCode > &times, UT_Matrix4D *xforms)
SYS_FORCE_INLINE bool HasParentXform() const
Definition: token.h:87
bool GetLocalToWorldTransforms(const UT_Array< UsdPrim > &prims, const GusdDefaultArray< UsdTimeCode > &times, UT_Matrix4D *xforms)
bool GetLocalTransformations(const UT_Array< UsdPrim > &prims, const GusdDefaultArray< UsdTimeCode > &times, UT_Matrix4D *xfroms)
static GUSD_API GusdUSD_XformCache & GetInstance()
#define SYS_FORCE_INLINE
Definition: SYS_Inline.h:45
Wrapper around hboost::intrusive_ptr.
long long int64
Definition: SYS_Types.h:116
Definition: prim.h:133
XformInfo(const UsdGeomXformable &xf)
Definition: oidn.hpp:29
bool GetLocalTransformation(const UsdPrim &prim, UsdTimeCode time, UT_Matrix4D &xform)
~GusdUSD_XformCache() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
GUSD_API void Clear() override
Clear all caches.
void ComputeFlags(const UsdPrim &prim, GusdUSD_XformCache &cache)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
SYS_FORCE_INLINE bool LocalXformIsMaybeTimeVarying() const
const UsdGeomXformable::XformQuery query
#define GUSD_API
Definition: api.h:40
Base class for items in the UT_CappedCache.
bool GetLocalToWorldTransform(const UsdPrim &prim, UsdTimeCode time, UT_Matrix4D &xform)
GUSD_API XformInfoHandle GetXformInfo(const UsdPrim &prim)