Loading...
Searching...
No Matches
attributeQuery.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_ATTRIBUTE_QUERY_H
8#define PXR_USD_USD_ATTRIBUTE_QUERY_H
9
10#include "pxr/pxr.h"
11#include "pxr/usd/usd/api.h"
12#include "pxr/usd/usd/attribute.h"
13#include "pxr/usd/usd/common.h"
14#include "pxr/usd/usd/prim.h"
16#include "pxr/usd/usd/resolveTarget.h"
17#include "pxr/usd/usd/timeCode.h"
18
19#include "pxr/base/tf/token.h"
20
21#include <vector>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25class TsSpline;
26
61{
62public:
64 USD_API
66
68 USD_API
70
72 USD_API
74
76 USD_API
77 explicit UsdAttributeQuery(const UsdAttribute& attr);
78
81 USD_API
82 UsdAttributeQuery(const UsdPrim& prim, const TfToken& attrName);
83
89 USD_API
91 const UsdResolveTarget &resolveTarget);
92
96 USD_API
97 static std::vector<UsdAttributeQuery> CreateQueries(
98 const UsdPrim& prim, const TfTokenVector& attrNames);
99
100 // --------------------------------------------------------------------- //
102 // --------------------------------------------------------------------- //
103
105
107 USD_API
109
112 bool IsValid() const {
113 return GetAttribute().IsValid();
114 }
115
116public:
118 explicit operator bool() const {
119 return IsValid();
120 }
121
123 USD_API
125
127 USD_API
129
131
132 // --------------------------------------------------------------------- //
134 // --------------------------------------------------------------------- //
135
137
142 template <typename T>
143 bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
144 static_assert(SdfValueTypeTraits<T>::IsValueType,
145 "T must be an SdfValueType.");
146 return _Get(value, time);
147 }
150 USD_API
151 bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
152
155 //
159 USD_API
160 bool GetTimeSamples(std::vector<double>* times) const;
161
166 USD_API
168
173 USD_API
175 std::vector<double>* times) const;
176
189 USD_API
191 const std::vector<UsdAttributeQuery> &attrQueries,
192 std::vector<double> *times);
193
205 USD_API
207 const std::vector<UsdAttributeQuery> &attrQueries,
208 const GfInterval &interval,
209 std::vector<double> *times);
210
214 USD_API
215 size_t GetNumTimeSamples() const;
216
221 USD_API
222 bool GetBracketingTimeSamples(double desiredTime,
223 double* lower,
224 double* upper,
225 bool* hasTimeSamples) const;
226
232 USD_API
233 bool HasValue() const;
234
241 USD_API
242 bool HasSpline() const;
243
253 USD_API
255
260 USD_API
261 bool HasAuthoredValue() const;
262
267 USD_API
268 bool HasFallbackValue() const;
269
274 USD_API
276
278
279private:
280 void _Initialize();
281
282 void _Initialize(const UsdResolveTarget &resolveTarget);
283
284 template <typename T>
285 USD_API
286 bool _Get(T* value, UsdTimeCode time) const;
287
288private:
289 UsdAttribute _attr;
290 UsdResolveInfo _resolveInfo;
291 std::unique_ptr<UsdResolveTarget> _resolveTarget;
292};
293
294PXR_NAMESPACE_CLOSE_SCOPE
295
296#endif // PXR_USD_USD_ATTRIBUTE_QUERY_H
A basic mathematical interval class.
Definition: interval.h:33
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A mathematical description of a curved function from time to value.
Definition: spline.h:59
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:183
Object for efficiently making repeated queries for attribute values.
USD_API UsdAttributeQuery()
Construct an invalid query object.
USD_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times.
USD_API bool GetBracketingTimeSamples(double desiredTime, double *lower, double *upper, bool *hasTimeSamples) const
Populate lower and upper with the next greater and lesser value relative to the desiredTime.
USD_API UsdAttributeQuery(const UsdAttributeQuery &other)
Copy constructor.
USD_API UsdAttributeQuery(UsdAttributeQuery &&other)=default
Move constructor.
USD_API UsdAttributeQuery(const UsdAttribute &attr, const UsdResolveTarget &resolveTarget)
Construct a new query for the attribute attr with the given resolve target resolveTarget.
USD_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
static USD_API bool GetUnionedTimeSamples(const std::vector< UsdAttributeQuery > &attrQueries, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times on all of the given...
USD_API UsdAttributeQuery & operator=(UsdAttributeQuery &&other)=default
Move assignment.
USD_API UsdAttributeQuery(const UsdPrim &prim, const TfToken &attrName)
Construct a new query for the attribute named attrName under the prim prim.
USD_API bool HasSpline() const
Return true if the attribute associated with this query has an a spline value as the strongest opinio...
USD_API bool HasAuthoredValueOpinion() const
USD_API const UsdAttribute & GetAttribute() const
Return the attribute associated with this query.
USD_API TsSpline GetSpline() const
Returns a copy of the TsSpline associated with the resolved value.
USD_API bool HasValue() const
Return true if the attribute associated with this query has an authored default value,...
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Perform value resolution to fetch the value of the attribute associated with this query at the reques...
USD_API bool Get(VtValue *value, UsdTimeCode time=UsdTimeCode::Default()) const
This is an overloaded member function, provided for convenience. It differs from the above function o...
static USD_API std::vector< UsdAttributeQuery > CreateQueries(const UsdPrim &prim, const TfTokenVector &attrNames)
Construct new queries for the attributes named in attrNames under the prim prim.
USD_API bool HasFallbackValue() const
Return true if the attribute associated with this query has a fallback value provided by a registered...
USD_API UsdAttributeQuery & operator=(const UsdAttributeQuery &other)
Copy assignment.
USD_API UsdAttributeQuery(const UsdAttribute &attr)
Construct a new query for the attribute attr.
bool IsValid() const
Return true if this query is valid (i.e.
static USD_API bool GetUnionedTimeSamplesInInterval(const std::vector< UsdAttributeQuery > &attrQueries, const GfInterval &interval, std::vector< double > *times)
Populates the given vector, times with the union of all the authored sample times in the GfInterval,...
USD_API size_t GetNumTimeSamples() const
Returns the number of time samples that have been authored.
USD_API bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this attribute's value changes over time,...
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples.
bool IsValid() const
Return true if this is a valid object, false otherwise.
Definition: object.h:126
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
Container for information about the source of an attribute's value, i.e.
Definition: resolveInfo.h:55
Defines a subrange of nodes and layers within a prim's prim index to consider when performing value r...
Definition: resolveTarget.h:56
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for 'default'.
Definition: timeCode.h:113
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:152
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440