Loading...
Searching...
No Matches
mapFunction.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_PCP_MAP_FUNCTION_H
8#define PXR_USD_PCP_MAP_FUNCTION_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/pcp/api.h"
12#include "pxr/usd/sdf/path.h"
14#include "pxr/usd/sdf/pathExpression.h"
15
16#include <atomic>
17#include <memory>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
65{
66public:
68 typedef std::map<SdfPath, SdfPath, SdfPath::FastLessThan> PathMap;
69
71 PCP_API
73
80 PCP_API
81 static PcpMapFunction
82 Create(const PathMap &sourceToTargetMap,
83 const SdfLayerOffset &offset);
84
93 PCP_API
94 static PcpMapFunction
96
102 PCP_API
103 static PcpMapFunction
104 ImpliedClass(const PcpMapFunction& transferFunc,
105 const PcpMapFunction& classArc);
106
108 PCP_API
109 static const PcpMapFunction &Identity();
110
112 PCP_API
113 static const PathMap &IdentityPathMap();
114
116 PCP_API
118 void swap(PcpMapFunction &map) { Swap(map); }
119
121 PCP_API
122 bool operator==(const PcpMapFunction &map) const;
123
125 PCP_API
126 bool operator!=(const PcpMapFunction &map) const;
127
130 PCP_API
131 bool IsNull() const;
132
135 PCP_API
137
140 PCP_API
141 bool IsIdentity() const;
142
146 PCP_API
148
151 PCP_API
152 bool HasRootIdentity() const;
153
156 PCP_API
158
161 PCP_API
163
177 PCP_API
180 const SdfPathExpression &pathExpr,
181 std::vector<SdfPathExpression::PathPattern>
182 *unmappedPatterns = nullptr,
183 std::vector<SdfPathExpression::ExpressionReference>
184 *unmappedRefs = nullptr
185 ) const;
186
200 PCP_API
203 const SdfPathExpression &pathExpr,
204 std::vector<SdfPathExpression::PathPattern>
205 *unmappedPatterns = nullptr,
206 std::vector<SdfPathExpression::ExpressionReference>
207 *unmappedRefs = nullptr
208 ) const;
209
226 PCP_API
228
232 PCP_API
234
238 PCP_API
240
242 PCP_API
244
246 const SdfLayerOffset &GetTimeOffset() const { return _offset; }
247
250 PCP_API
251 std::string GetString() const;
252
254 PCP_API
255 size_t Hash() const;
256
257private:
258 struct _Mappings;
259
261 std::shared_ptr<_Mappings>&& mappings,
262 SdfLayerOffset offset);
263
264 SdfPath
265 _MapPathImpl(
266 bool invert,
267 const SdfPath& path) const;
268
270 _MapPathExpressionImpl(
271 bool invert,
272 const SdfPathExpression &pathExpr,
273 std::vector<SdfPathExpression::PathPattern> *unmappedPatterns,
274 std::vector<SdfPathExpression::ExpressionReference> *unmappedRefs
275 ) const;
276
277 // Return a "normalized" map function created from the mappings in
278 // this map function. This may return *this if this map function is
279 // already in normalized form.
280 //
281 // A normalized map function always contains a single set of
282 // source-to-target path mappings; all deferred-composition mappings
283 // are composed together. The resulting map function can be used
284 // for comparisons with other normalized map functions, or in
285 // cases where the fully-composed set of mappings is needed.
286 PcpMapFunction _GetNormalized() const;
287
288 // Return number of mapping sets in this map function. A map function
289 // may have more than 1 mapping set if it was composed from a
290 // deferred-composition map function.
291 PCP_API size_t _GetNumMappingSets() const;
292
293private:
294 friend PcpMapFunction *Pcp_MakeIdentity();
295 friend class Pcp_MapFunctionPyAccess;
296
297 // Specialize TfHashAppend for PcpMapFunction.
298 template <typename HashState>
299 friend inline
300 void TfHashAppend(HashState& h, const PcpMapFunction& x){
301 h.Append(x.Hash());
302 }
303
304 std::shared_ptr<_Mappings> _mappings;
305 SdfLayerOffset _offset;
306};
307
308// Specialize hash_value for PcpMapFunction.
309inline
310size_t hash_value(const PcpMapFunction& x)
311{
312 return TfHash{}(x);
313}
314
315PXR_NAMESPACE_CLOSE_SCOPE
316
317#endif // PXR_USD_PCP_MAP_FUNCTION_H
A function that maps values from one namespace (and time domain) to another.
Definition mapFunction.h:65
PCP_API PcpMapFunction()
Construct a null function.
std::map< SdfPath, SdfPath, SdfPath::FastLessThan > PathMap
A mapping from path to path.
Definition mapFunction.h:68
static PCP_API PcpMapFunction Create(const PathMap &sourceToTargetMap, const SdfLayerOffset &offset)
Constructs a map function with the given arguments.
PCP_API void Swap(PcpMapFunction &map)
Swap the contents of this map function with map.
PCP_API SdfPathExpression MapTargetToSource(const SdfPathExpression &pathExpr, std::vector< SdfPathExpression::PathPattern > *unmappedPatterns=nullptr, std::vector< SdfPathExpression::ExpressionReference > *unmappedRefs=nullptr) const
Map all path pattern prefix paths and expression reference paths in the target namespace to the sourc...
PCP_API SdfPath MapSourceToTarget(const SdfPath &path) const
Map a path in the source namespace to the target.
static PCP_API PcpMapFunction ImpliedClass(const PcpMapFunction &transferFunc, const PcpMapFunction &classArc)
Constructs a map function that is equivalent to.
PCP_API bool IsIdentity() const
Return true if the map function is the identity function.
PCP_API bool HasRootIdentity() const
Return true if the map function maps the absolute root path to the absolute root path,...
PCP_API size_t Hash() const
Return a size_t hash for this map function.
PCP_API SdfPathExpression MapSourceToTarget(const SdfPathExpression &pathExpr, std::vector< SdfPathExpression::PathPattern > *unmappedPatterns=nullptr, std::vector< SdfPathExpression::ExpressionReference > *unmappedRefs=nullptr) const
Map all path pattern prefix paths and expression reference paths in the source namespace to the targe...
PCP_API std::string GetString() const
Returns a string representation of this mapping for debugging purposes.
static PCP_API const PathMap & IdentityPathMap()
Returns an identity path mapping.
PCP_API SdfPath MapTargetToSource(const SdfPath &path) const
Map a path in the target namespace to the source.
PCP_API bool operator!=(const PcpMapFunction &map) const
Inequality.
const SdfLayerOffset & GetTimeOffset() const
The time offset of the mapping.
static PCP_API const PcpMapFunction & Identity()
Construct an identity map function.
PCP_API bool IsDeferredComposition() const
Return true if the map function is a defered-composition function.
PCP_API PcpMapFunction ComposeOffset(const SdfLayerOffset &newOffset) const
Compose this map function over a hypothetical map function that has an identity path mapping and offs...
PCP_API PcpMapFunction GetInverse() const
Return the inverse of this map function.
PCP_API PcpMapFunction Compose(const PcpMapFunction &f) const
Compose this map over the given map function.
PCP_API bool IsIdentityPathMapping() const
Return true if the map function uses the identity path mapping.
PCP_API bool operator==(const PcpMapFunction &map) const
Equality.
PCP_API bool IsNull() const
Return true if this map function is the null function.
PCP_API PathMap GetSourceToTargetMap() const
The set of path mappings, from source to target.
static PCP_API PcpMapFunction DeferredComposition(const PcpMapFunction &mapFn)
Constructs a "deferred-composition" map function from the given source mapFn.
Represents a time offset and scale between layers.
Definition layerOffset.h:44
Objects of this class represent a logical expression syntax tree consisting of SdfPathPattern s,...
A path value used to locate objects in layers or scenegraphs.
Definition path.h:281
A user-extensible hashing mechanism for use with runtime hash tables.
Definition hash.h:472
size_t hash_value(const TfToken &x)
Overload hash_value for TfToken.
Definition token.h:437