HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
resolveInfo.h
Go to the documentation of this file.
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_RESOLVE_INFO_H
8 #define PXR_USD_USD_RESOLVE_INFO_H
9 
10 /// \file usd/resolveInfo.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
14 #include "pxr/usd/usd/stage.h"
15 #include "pxr/base/ts/spline.h"
17 #include "pxr/usd/sdf/path.h"
18 #include "pxr/usd/pcp/node.h"
19 
21 
22 #include <limits>
23 #include <optional>
24 
26 
27 
29 
30 /// \enum UsdResolveInfoSource
31 ///
32 /// Describes the various sources of attribute values.
33 ///
34 /// For more details, see \ref Usd_ValueResolution.
35 ///
37 {
38  UsdResolveInfoSourceNone, ///< No value
39 
40  UsdResolveInfoSourceFallback, ///< Built-in fallback value
41  UsdResolveInfoSourceDefault, ///< Attribute default value
42  UsdResolveInfoSourceTimeSamples, ///< Attribute time samples
44  UsdResolveInfoSourceSpline, ///< Spline value
45 };
46 
47 /// \class UsdResolveInfo
48 ///
49 /// Container for information about the source of an attribute's value, i.e.
50 /// the 'resolved' location of the attribute.
51 ///
52 /// For more details, see \ref Usd_ValueResolution.
53 ///
55 {
56 public:
58  : _source(UsdResolveInfoSourceNone)
59  , _valueIsBlocked(false)
60  {
61  }
62 
63  /// Return the source of the associated attribute's value.
65  return _source;
66  }
67 
68  /// Return true if this UsdResolveInfo represents an attribute that has an
69  /// authored value opinion. This will return `true` if there is *any*
70  /// authored value opinion, including a \ref Usd_AttributeBlocking "block"
71  ///
72  /// This is equivalent to `HasAuthoredValue() || ValueIsBlocked()`
73  bool HasAuthoredValueOpinion() const {
74  return
75  _source == UsdResolveInfoSourceDefault ||
77  _source == UsdResolveInfoSourceValueClips ||
78  _source == UsdResolveInfoSourceSpline ||
79  _valueIsBlocked;
80  }
81 
82  /// Return true if this UsdResolveInfo represents an attribute that has an
83  /// authored value that is not \ref Usd_AttributeBlocking "blocked"
84  bool HasAuthoredValue() const {
85  return
86  _source == UsdResolveInfoSourceDefault ||
88  _source == UsdResolveInfoSourceValueClips ||
89  _source == UsdResolveInfoSourceSpline;
90  }
91 
92  /// Return the node within the containing PcpPrimIndex that provided
93  /// the resolved value opinion.
94  PcpNodeRef GetNode() const {
95  return _node;
96  }
97 
98  /// Return true if this UsdResolveInfo represents an attribute whose
99  /// value is blocked.
100  ///
101  /// \see UsdAttribute::Block()
102  bool ValueIsBlocked() const {
103  return _valueIsBlocked;
104  }
105 
106  /// Returns true if the resolve info source might be time-varying; false
107  /// otherwise.
108  ///
109  /// Note that this is different from UsdAttribute::ValueMightBeTimeVarying()
110  /// which provides more granular answer since it has additional context from
111  /// the attribute itself.
113  return _source == UsdResolveInfoSourceTimeSamples ||
114  _source == UsdResolveInfoSourceSpline ||
116  }
117 
118 private:
119  /// The LayerStack that provides the strongest value opinion.
120  ///
121  /// If \p source is either \p UsdResolveInfoSourceDefault
122  /// or \p UsdResolveInfoSourceTimeSamples or \p UsdResolveInfoSourceSpline,
123  /// the source will be a layer in this LayerStack (\sa _layer).
124  ///
125  /// If \p source is UsdResolveInfoSourceValueClips, the source clips
126  /// will have been introduced in this LayerStack.
127  ///
128  /// Otherwise, this LayerStack will be invalid.
129  PcpLayerStackPtr _layerStack;
130 
131  /// The layer in \p layerStack that provides the strongest time sample or
132  /// default opinion.
133  ///
134  /// This is valid only if \p source is either
135  /// \p UsdResolveInfoSourceDefault or \p UsdResolveInfoSourceTimeSamples or
136  /// \p UsdResolveInfoSourceSpline.
137  SdfLayerHandle _layer;
138 
139  /// The node within the containing PcpPrimIndex that provided
140  /// the strongest value opinion.
141  PcpNodeRef _node;
142 
143  /// If \p source is \p UsdResolveInfoTimeSamples, the time
144  /// offset that maps time in the strongest resolved layer
145  /// to the stage.
146  /// If no offset applies, this will be the identity offset.
147  SdfLayerOffset _layerToStageOffset;
148 
149  /// The path to the prim that owns the attribute to query in
150  /// \p layerStack to retrieve the strongest value opinion.
151  ///
152  /// If \p source is either \p UsdResolveInfoSourceDefault or
153  /// \p UsdResolveInfoTimeSamples or \p UsdResolveInfoSourceSpline, this is
154  /// the path to the prim specs in \p layerStack that own the attribute spec
155  /// containing strongest value opinion.
156  ///
157  /// If \p source is UsdResolveInfoSourceValueClips, this is the
158  /// path to the prim that should be used to query clips for attribute
159  /// values.
160  SdfPath _primPathInLayerStack;
161 
162  /// The source of the associated attribute's value.
163  UsdResolveInfoSource _source;
164 
165  /// If the source is UsdResolveInfoSourceSpline, then _spline represents the
166  /// underlying spline data. If not, this will be nullopt.
167  std::optional<TsSpline> _spline;
168 
169  /// If \p source is \p UsdResolveInfoSourceNone or
170  /// \p UsdResolveInfoSourceFallback, this indicates whether or not
171  /// this due to the value being blocked.
172  bool _valueIsBlocked;
173 
174  friend class UsdAttribute;
175  friend class UsdStage;
177  friend class UsdAttributeQuery;
178 };
179 
180 
182 
183 #endif // PXR_USD_USD_RESOLVE_INFO_H
bool ValueSourceMightBeTimeVarying() const
Definition: resolveInfo.h:112
Built-in fallback value.
Definition: resolveInfo.h:40
UsdResolveInfoSource
Definition: resolveInfo.h:36
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(PcpLayerStack)
Definition: path.h:273
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
Attribute time samples.
Definition: resolveInfo.h:42
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool HasAuthoredValue() const
Definition: resolveInfo.h:84
bool ValueIsBlocked() const
Definition: resolveInfo.h:102
UsdResolveInfoSource GetSource() const
Return the source of the associated attribute's value.
Definition: resolveInfo.h:64
friend class UsdStage_ResolveInfoAccess
Definition: resolveInfo.h:176
PcpNodeRef GetNode() const
Definition: resolveInfo.h:94
bool HasAuthoredValueOpinion() const
Definition: resolveInfo.h:73
Attribute default value.
Definition: resolveInfo.h:41