HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataSourceAttributeColorSpace.h
Go to the documentation of this file.
1 //
2 // Copyright 2023 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_IMAGING_USD_IMAGING_DATA_SOURCE_ATTRIBUTE_COLORSPACE_H
8 #define PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_ATTRIBUTE_COLORSPACE_H
9 
10 #include "pxr/usd/usd/attribute.h"
15 
17 
18 /// \class UsdImagingDataSourceAttributeColorSpace
19 ///
20 /// A data source that represents the metadata on a USD Attribute
21 ///
23 {
24 public:
25 
27 
28  /// Returns the VtValue of the colorspace for the attribute
29  ///
30  VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
31  {
32  return VtValue(GetTypedValue(shutterOffset));
33  }
34 
35  /// Returns the extracted TfToken value of the color space for
36  /// the attribute.
37  ///
39  {
40  if (!_usdAttr) {
41  return {};
42  }
43 
44  TF_UNUSED(shutterOffset);
45 
46  // Special Case handling of UsdUVTexture Nodes which has an
47  // 'inputs:sourceColorSpace' that we want to consolidate on the
48  // 'inputs:file' parameter
49  TfToken sourceColorSpaceInput = _GetSourceColorSpaceInput();
50  if (!sourceColorSpaceInput.IsEmpty()) {
51  return sourceColorSpaceInput;
52  }
53 
54  // If there is no inputs:sourceColorSpace value authored, use the
55  // ColorspaceAPI to find the resolved color space for the attribute.
57  }
58 
59  /// Returns false since we do not expect the color space value to vary
60  /// over time.
61  ///
63  HdSampledDataSource::Time startTime,
65  std::vector<HdSampledDataSource::Time> *outSampleTimes) override
66  {
67  TF_UNUSED(startTime);
68  TF_UNUSED(endTime);
69  return false;
70  }
71 
72 private:
73 
74  /// Constructs a new UsdImagingDataSourceAttributeColorSpace for the given
75  /// \p usdAttr
76  ///
78 
79 
80  // Helper to get the TfToken authored to the 'inputs:sourceColorSpace'
81  // for the 'inputs:file' attribute
82  TfToken _GetSourceColorSpaceInput() {
83  static TfToken inputSourceColorSpace("inputs:sourceColorSpace");
84 
85  // Only add add the source color space to the file attribute
86  if (_usdAttr.GetName() != "inputs:file") {
87  return TfToken();
88  }
89 
90  TfToken sourceColorSpace;
91  UsdPrim prim = _usdAttr.GetPrim();
92  if (prim.HasAttribute(inputSourceColorSpace)) {
93  VtValue sourceCSValue;
94  prim.GetAttribute(inputSourceColorSpace).Get(&sourceCSValue);
95  if (sourceCSValue.IsHolding<TfToken>()) {
96  sourceColorSpace = sourceCSValue.UncheckedGet<TfToken>();
97  }
98  }
99  return sourceColorSpace;
100  }
101 
102 private:
103  UsdAttribute _usdAttr;
104 };
105 
106 
108 
109 #endif // PXR_USD_IMAGING_USD_IMAGING_DATA_SOURCE_ATTRIBUTE_COLORSPACE_H
T const & UncheckedGet() const &
Definition: value.h:1046
bool Get(T *value, UsdTimeCode time=UsdTimeCode::Default()) const
Definition: attribute.h:468
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
HD_DECLARE_DATASOURCE(UsdImagingDataSourceAttributeColorSpace)
TfToken GetTypedValue(HdSampledDataSource::Time shutterOffset) override
bool GetContributingSampleTimesForInterval(HdSampledDataSource::Time startTime, HdSampledDataSource::Time endTime, std::vector< HdSampledDataSource::Time > *outSampleTimes) override
Definition: token.h:70
USD_API bool HasAttribute(const TfToken &attrName) const
Definition: prim.h:116
const TfToken & GetName() const
Definition: object.h:222
UsdPrim GetPrim() const
Definition: prim.h:2806
#define TF_UNUSED(x)
Definition: tf.h:168
bool IsHolding() const
Definition: value.h:1002
static USD_API TfToken ComputeColorSpaceName(const UsdAttribute &attribute, ColorSpaceCache *cache=nullptr)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
USD_API UsdAttribute GetAttribute(const TfToken &attrName) const
Definition: value.h:89
bool IsEmpty() const
Returns true iff this token contains the empty string "".
Definition: token.h:288