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 <memory>
24 #include <optional>
25 
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  , _defaultCanCompose(false)
61  , _defaultCanComposeOverWeakerTimeVaryingSources(false)
62  {
63  }
64 
65  /// Return some information about the source of the associated attribute's
66  /// value. Note that if the attribute's value composes over other values,
67  /// there may be more than a single source that varies over time. For
68  /// example, a VtArray-valued attribute may have a resolved value composed
69  /// of a stronger VtArrayEdit over a weaker VtArray.
70  ///
71  /// A call to UsdAttribute::GetResolveInfo() with no arguments produces a
72  /// UsdResolveInfo that only contains the proximal potential value source.
73  /// In many cases this is the only source, but for more complex scenarios,
74  /// call the overload of UsdAttribute::GetResolveInfo() that takes a time.
75  /// Then if there is more than one source, the weaker sources can by
76  /// accessed by calling HasWeakerInfo() and GetNextWeakerInfo().
77  ///
78  /// Spline value types (scalar floating point values) can never compose, so
79  /// UsdResolveInfoSourceSpline instances never have weaker resolve info.
81  return _source;
82  }
83 
84  /// Return true if this UsdResolveInfo represents an attribute that has an
85  /// authored value opinion. This will return `true` if there is *any*
86  /// authored value opinion, including a \ref Usd_AttributeBlocking "block"
87  ///
88  /// This is equivalent to `HasAuthoredValue() || ValueIsBlocked()`
89  bool HasAuthoredValueOpinion() const {
90  return
91  _source == UsdResolveInfoSourceDefault ||
93  _source == UsdResolveInfoSourceValueClips ||
94  _source == UsdResolveInfoSourceSpline ||
95  _valueIsBlocked;
96  }
97 
98  /// Return true if this UsdResolveInfo represents an attribute that has an
99  /// authored value that is not \ref Usd_AttributeBlocking "blocked"
100  bool HasAuthoredValue() const {
101  return
102  _source == UsdResolveInfoSourceDefault ||
103  _source == UsdResolveInfoSourceTimeSamples ||
104  _source == UsdResolveInfoSourceValueClips ||
105  _source == UsdResolveInfoSourceSpline;
106  }
107 
108  /// Return the node within the containing PcpPrimIndex that provided
109  /// the resolved value opinion.
110  PcpNodeRef GetNode() const {
111  return _node;
112  }
113 
114  /// Return true if this UsdResolveInfo represents an attribute whose
115  /// value is blocked.
116  ///
117  /// \see UsdAttribute::Block()
118  bool ValueIsBlocked() const {
119  return _valueIsBlocked;
120  }
121 
122  /// Return true if the resolve info value source might be time-varying;
123  /// false otherwise. A return of true means that the value may or may not
124  /// actually be time-varying. A return of false means the the value is
125  /// definitely not time-varying. This is meant to enable optimizations for
126  /// scene-data consumers like renderers, when they can handle non-varying
127  /// values more efficiently.
128  ///
129  /// Note that this is different from UsdAttribute::ValueMightBeTimeVarying()
130  /// which provides more granular answer since it has additional context from
131  /// the attribute itself.
133  if (_source == UsdResolveInfoSourceTimeSamples ||
134  _source == UsdResolveInfoSourceSpline ||
135  _source == UsdResolveInfoSourceValueClips) {
136  return true;
137  }
138  if (HasNextWeakerInfo()) {
140  }
141  return _source == UsdResolveInfoSourceDefault &&
142  _defaultCanComposeOverWeakerTimeVaryingSources;
143  }
144 
145  /// If this object was returned by a call to the UsdAttribute::GetResolve()
146  /// overload that takes a `time`, then this function returns true if the
147  /// attribute's value comes from more than a single source. For example, a
148  /// VtIntArray-valued attribute that has a default authored in a weaker
149  /// layer, and a VtIntArrayEdit default authored in a stronger layer will
150  /// return true. This object's value source will indicate the stronger
151  /// array edit source, and calling GetNextWeakerInfo() will return a pointer
152  /// to a resolve info indicating the weaker VtArray source.
153  bool HasNextWeakerInfo() const {
154  return static_cast<bool>(_nextWeaker);
155  }
156 
157  /// If this object was returned by a call to the UsdAttribute::GetResolve()
158  /// overload that takes a `time` and the attribute's value comes from more
159  /// than a single source, return a pointer to a UsdResolveInfo indicating
160  /// the next weaker source. If many sources are involved, the chain will
161  /// continue to indicate all the value sources.
163  return _nextWeaker.get();
164  }
165 
166 private:
167 
168  // Helper to chain an additional weaker info onto this one.
169  USD_API
170  UsdResolveInfo *_AddNextWeakerInfo();
171 
172  /// The LayerStack that provides the strongest value opinion.
173  ///
174  /// If \p source is either \p UsdResolveInfoSourceDefault
175  /// or \p UsdResolveInfoSourceTimeSamples or \p UsdResolveInfoSourceSpline,
176  /// the source will be a layer in this LayerStack (\sa _layer).
177  ///
178  /// If \p source is UsdResolveInfoSourceValueClips, the source clips
179  /// will have been introduced in this LayerStack.
180  ///
181  /// Otherwise, this LayerStack will be invalid.
182  PcpLayerStackPtr _layerStack;
183 
184  /// The layer in \p layerStack that provides the strongest time sample or
185  /// default opinion.
186  ///
187  /// This is valid only if \p source is either
188  /// \p UsdResolveInfoSourceDefault or \p UsdResolveInfoSourceTimeSamples or
189  /// \p UsdResolveInfoSourceSpline.
190  SdfLayerHandle _layer;
191 
192  /// The node within the containing PcpPrimIndex that provided
193  /// the strongest value opinion.
194  PcpNodeRef _node;
195 
196  /// If \p source is \p UsdResolveInfoTimeSamples, the time
197  /// offset that maps time in the strongest resolved layer
198  /// to the stage.
199  /// If no offset applies, this will be the identity offset.
200  SdfLayerOffset _layerToStageOffset;
201 
202  /// The path to the prim that owns the attribute to query in
203  /// \p layerStack to retrieve the strongest value opinion.
204  ///
205  /// If \p source is either \p UsdResolveInfoSourceDefault or
206  /// \p UsdResolveInfoTimeSamples or \p UsdResolveInfoSourceSpline, this is
207  /// the path to the prim specs in \p layerStack that own the attribute spec
208  /// containing strongest value opinion.
209  ///
210  /// If \p source is UsdResolveInfoSourceValueClips, this is the
211  /// path to the prim that should be used to query clips for attribute
212  /// values.
213  SdfPath _primPathInLayerStack;
214 
215  /// If the source is UsdResolveInfoSourceSpline, then _spline represents the
216  /// underlying spline data. If not, this will be nullopt.
217  std::optional<TsSpline> _spline;
218 
219  /// If the resolved value is possibly composed from several authored values,
220  /// this points to the next weaker source of values.
221  std::shared_ptr<UsdResolveInfo> _nextWeaker;
222 
223  /// The source of the associated attribute's value.
224  UsdResolveInfoSource _source;
225 
226  /// If \p source is \p UsdResolveInfoSourceNone or
227  /// \p UsdResolveInfoSourceFallback, this indicates whether or not
228  /// this due to the value being blocked.
229  bool _valueIsBlocked;
230 
231  /// Set to true if \p source is \p UsdResolveInfoSourceDefault and the
232  /// default value can compose.
233  bool _defaultCanCompose;
234 
235  /// Set to true if \p source is \p UsdResolveInfoSourceDefault and the
236  /// default value can compose, and there were weaker time varying sources
237  /// (clips or samples).
238  bool _defaultCanComposeOverWeakerTimeVaryingSources;
239 
240  friend class UsdAttribute;
241  friend class UsdAttributeQuery;
242  friend class UsdStage;
244  friend class Usd_Resolver;
245 };
246 
247 
249 
250 #endif // PXR_USD_USD_RESOLVE_INFO_H
bool ValueSourceMightBeTimeVarying() const
Definition: resolveInfo.h:132
Built-in fallback value.
Definition: resolveInfo.h:40
#define USD_API
Definition: api.h:23
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
UsdResolveInfo const * GetNextWeakerInfo() const
Definition: resolveInfo.h:162
UsdResolveInfoSource
Definition: resolveInfo.h:36
PXR_NAMESPACE_OPEN_SCOPE TF_DECLARE_WEAK_PTRS(PcpLayerStack)
Definition: path.h:280
Attribute time samples.
Definition: resolveInfo.h:42
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool HasAuthoredValue() const
Definition: resolveInfo.h:100
bool ValueIsBlocked() const
Definition: resolveInfo.h:118
bool HasNextWeakerInfo() const
Definition: resolveInfo.h:153
UsdResolveInfoSource GetSource() const
Definition: resolveInfo.h:80
friend class UsdStage_ResolveInfoAccess
Definition: resolveInfo.h:243
PcpNodeRef GetNode() const
Definition: resolveInfo.h:110
bool HasAuthoredValueOpinion() const
Definition: resolveInfo.h:89
Attribute default value.
Definition: resolveInfo.h:41