All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
attributeQuery.h
1 //
2 // Copyright 2016 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 USD_ATTRIBUTE_QUERY_H
25 #define USD_ATTRIBUTE_QUERY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/usd/usd/api.h"
29 #include "pxr/usd/usd/attribute.h"
30 #include "pxr/usd/usd/common.h"
31 #include "pxr/usd/usd/prim.h"
32 #include "pxr/usd/usd/resolveInfo.h"
33 #include "pxr/usd/usd/timeCode.h"
34 
35 #include "pxr/base/tf/token.h"
36 
37 #include <vector>
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 
67 {
68 public:
70  USD_API
72 
74  USD_API
75  explicit UsdAttributeQuery(const UsdAttribute& attr);
76 
79  USD_API
80  UsdAttributeQuery(const UsdPrim& prim, const TfToken& attrName);
81 
85  USD_API
86  static std::vector<UsdAttributeQuery> CreateQueries(
87  const UsdPrim& prim, const TfTokenVector& attrNames);
88 
89  // --------------------------------------------------------------------- //
91  // --------------------------------------------------------------------- //
92 
94 
96  USD_API
97  const UsdAttribute& GetAttribute() const;
98 
101  bool IsValid() const {
102  return GetAttribute().IsValid();
103  }
104 
105 public:
107  explicit operator bool() const {
108  return IsValid();
109  }
110 
112 
113  // --------------------------------------------------------------------- //
115  // --------------------------------------------------------------------- //
116 
118 
123  template <typename T>
124  bool Get(T* value, UsdTimeCode time = UsdTimeCode::Default()) const {
125  static_assert(SdfValueTypeTraits<T>::IsValueType,
126  "T must be an SdfValueType.");
127  return _Get(value, time);
128  }
131  USD_API
132  bool Get(VtValue* value, UsdTimeCode time = UsdTimeCode::Default()) const;
133 
136  //
140  USD_API
141  bool GetTimeSamples(std::vector<double>* times) const;
142 
147  USD_API
148  bool GetTimeSamplesInInterval(const GfInterval& interval,
149  std::vector<double>* times) const;
150 
163  USD_API
164  static bool GetUnionedTimeSamples(
165  const std::vector<UsdAttributeQuery> &attrQueries,
166  std::vector<double> *times);
167 
179  USD_API
181  const std::vector<UsdAttributeQuery> &attrQueries,
182  const GfInterval &interval,
183  std::vector<double> *times);
184 
188  USD_API
189  size_t GetNumTimeSamples() const;
190 
195  USD_API
196  bool GetBracketingTimeSamples(double desiredTime,
197  double* lower,
198  double* upper,
199  bool* hasTimeSamples) const;
200 
206  USD_API
207  bool HasValue() const;
208 
218  USD_API
219  bool HasAuthoredValueOpinion() const;
220 
225  USD_API
226  bool HasAuthoredValue() const;
227 
232  USD_API
233  bool HasFallbackValue() const;
234 
239  USD_API
240  bool ValueMightBeTimeVarying() const;
241 
243 
244 private:
245  void _Initialize(const UsdAttribute& attr);
246 
247  template <typename T>
248  USD_API
249  bool _Get(T* value, UsdTimeCode time) const;
250 
251 private:
252  UsdAttribute _attr;
253  UsdResolveInfo _resolveInfo;
254 };
255 
256 PXR_NAMESPACE_CLOSE_SCOPE
257 
258 #endif // USD_ATTRIBUTE_QUERY_H
USD_API size_t GetNumTimeSamples() const
Returns the number of time samples that have been authored.
USD_API UsdAttributeQuery()
Construct an invalid query object.
bool IsValid() const
Return true if this is a valid object, false otherwise.
Definition: object.h:140
USD_API bool HasFallbackValue() const
Return true if the attribute associated with this query has a fallback value provided by a registered...
Object for efficiently making repeated queries for attribute values.
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 bool ValueMightBeTimeVarying() const
Return true if it is possible, but not certain, that this attribute&#39;s value changes over time...
Container for information about the source of an attribute&#39;s value, i.e.
Definition: resolveInfo.h:69
Scenegraph object for authoring and retrieving numeric, string, and array valued data, sampled over time.
Definition: attribute.h:176
USD_API bool HasValue() const
Return true if the attribute associated with this query has an authored default value, authored time samples or a fallback value provided by a registered schema.
USD_API bool GetTimeSamples(std::vector< double > *times) const
Populates a vector with authored sample times.
bool IsValid() const
Return true if this query is valid (i.e.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
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.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:85
USD_API bool HasAuthoredValueOpinion() const
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.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a &quot;Prim&quot; as ...
Definition: prim.h:131
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:438
A basic mathematical interval class.
Definition: interval.h:50
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...
static constexpr UsdTimeCode Default()
Produce a UsdTimeCode representing the sentinel value for &#39;default&#39;.
Definition: timeCode.h:113
USD_API bool GetTimeSamplesInInterval(const GfInterval &interval, std::vector< double > *times) const
Populates a vector with authored sample times in interval.
USD_API bool HasAuthoredValue() const
Return true if this attribute has either an authored default value or authored time samples...
USD_API const UsdAttribute & GetAttribute() const
Return the attribute associated with this query.
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...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182