Loading...
Searching...
No Matches
labelsQuery.h
1//
2// Copyright 2024 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_USDSEMANTICS_LABELSQUERY_H
8#define PXR_USDSEMANTICS_LABELSQUERY_H
9
10#include "pxr/pxr.h"
11
13#include "pxr/usd/usd/timeCode.h"
15#include "pxr/base/tf/token.h"
16
17#include <shared_mutex>
18#include <set>
19#include <unordered_map>
20#include <variant>
21
22
23PXR_NAMESPACE_OPEN_SCOPE
24
34{
35public:
37 UsdSemanticsLabelsQuery& operator=(
38 const UsdSemanticsLabelsQuery&) = delete;
39
43 USDSEMANTICS_API UsdSemanticsLabelsQuery(const TfToken& taxonomy,
44 UsdTimeCode timeCode);
45
53 USDSEMANTICS_API UsdSemanticsLabelsQuery(const TfToken& taxonomy,
54 const GfInterval& interval);
55
67 USDSEMANTICS_API
68 VtTokenArray ComputeUniqueDirectLabels(const UsdPrim& prim) const;
69
81 USDSEMANTICS_API
82 VtTokenArray ComputeUniqueInheritedLabels(const UsdPrim& prim) const;
83
88 USDSEMANTICS_API
89 bool HasDirectLabel(const UsdPrim& prim, const TfToken& label) const;
90
95 USDSEMANTICS_API
96 bool HasInheritedLabel(const UsdPrim& prim, const TfToken& label) const;
97
99 const std::variant<GfInterval, UsdTimeCode>& GetTime() const & {
100 return _time; }
101
103 std::variant<GfInterval, UsdTimeCode> GetTime() && {
104 return std::move(_time); }
105
107 const TfToken& GetTaxonomy() const & { return _taxonomy; }
108
110 TfToken GetTaxonomy() && { return std::move(_taxonomy); }
111
112private:
113 // Return true if the prim has an entry in the cache
114 bool _PopulateLabels(const UsdPrim& prim) const;
115
116 // Return true if any of the prim's ancestors have an entry in the cache
117 bool _PopulateInheritedLabels(const UsdPrim& prim) const;
118
119 TfToken _taxonomy;
120 std::variant<GfInterval, UsdTimeCode> _time;
121
122 mutable std::shared_mutex _cachedLabelsMutex;
123 using _UnorderedTokenSet = std::unordered_set<TfToken, TfHash>;
124 mutable std::unordered_map<SdfPath, _UnorderedTokenSet, TfHash> _cachedLabels;
125};
126
127PXR_NAMESPACE_CLOSE_SCOPE
128
129#endif
A basic mathematical interval class.
Definition: interval.h:33
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
The UsdSemanticsLabelsQuery can be used to query a prim's labels for a specified taxonomy and time fr...
Definition: labelsQuery.h:34
TfToken GetTaxonomy() &&
Returns the taxonomy used by this query when computing a prim's labels.
Definition: labelsQuery.h:110
USDSEMANTICS_API VtTokenArray ComputeUniqueInheritedLabels(const UsdPrim &prim) const
Computes the values for semantics:labels:<taxonomy> including any labels inherited from ancestors.
USDSEMANTICS_API UsdSemanticsLabelsQuery(const TfToken &taxonomy, const GfInterval &interval)
Construct a query for a taxonomy over an interval.
const std::variant< GfInterval, UsdTimeCode > & GetTime() const &
Returns the time used by this query when computing a prim's labels.
Definition: labelsQuery.h:99
USDSEMANTICS_API bool HasDirectLabel(const UsdPrim &prim, const TfToken &label) const
Return true if a label has been specified directly on this prim for this query's taxonomy and time.
USDSEMANTICS_API UsdSemanticsLabelsQuery(const TfToken &taxonomy, UsdTimeCode timeCode)
Constructs a query for a taxonomy at a single timeCode.
std::variant< GfInterval, UsdTimeCode > GetTime() &&
Returns the time used by this query when computing a prim's labels.
Definition: labelsQuery.h:103
USDSEMANTICS_API bool HasInheritedLabel(const UsdPrim &prim, const TfToken &label) const
Return true if a label has been specified for a prim or its ancestors for this query's taxonomy and t...
USDSEMANTICS_API VtTokenArray ComputeUniqueDirectLabels(const UsdPrim &prim) const
Computes the values for semantics:labels:<taxonomy> directly applied to this prim.
const TfToken & GetTaxonomy() const &
Returns the taxonomy used by this query when computing a prim's labels.
Definition: labelsQuery.h:107
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:72
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...