HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
colorSpaceDefinitionAPI.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 USD_GENERATED_COLORSPACEDEFINITIONAPI_H
8 #define USD_GENERATED_COLORSPACEDEFINITIONAPI_H
9 
10 /// \file usd/colorSpaceDefinitionAPI.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/usd/usd/api.h"
15 #include "pxr/usd/usd/prim.h"
16 #include "pxr/usd/usd/stage.h"
17 #include "pxr/usd/usd/tokens.h"
18 
19 #include "pxr/base/gf/colorSpace.h"
20 
21 
22 #include "pxr/base/vt/value.h"
23 
24 #include "pxr/base/gf/vec3d.h"
25 #include "pxr/base/gf/vec3f.h"
26 #include "pxr/base/gf/matrix4d.h"
27 
28 #include "pxr/base/tf/token.h"
29 #include "pxr/base/tf/type.h"
30 
32 
33 class SdfAssetPath;
34 
35 // -------------------------------------------------------------------------- //
36 // COLORSPACEDEFINITIONAPI //
37 // -------------------------------------------------------------------------- //
38 
39 /// \class UsdColorSpaceDefinitionAPI
40 ///
41 /// UsdColorSpaceDefinitionAPI is an API schema for defining a custom
42 /// color space. Custom color spaces become available for use on prims or for
43 /// assignment to attributes via the colorSpace:name property on prims that have
44 /// applied `UsdColorSpaceAPI`. Since color spaces inherit hierarchically, a
45 /// custom color space defined on a prim will be available to all descendants of
46 /// that prim, unless overridden by a more local color space definition bearing
47 /// the same name. Locally redefining color spaces within the same layer could
48 /// be confusing, so that practice is discouraged.
49 ///
50 /// The default color space values are equivalent to an identity transform, so
51 /// applying this schema and invoking `UsdColorSpaceAPI::ComputeColorSpace()`
52 /// on a prim resolving to a defaulted color definition will return a color
53 /// space equivalent to the identity transform.
54 ///
55 ///
56 /// For any described attribute \em Fallback \em Value or \em Allowed \em Values below
57 /// that are text/tokens, the actual token is published and defined in \ref UsdTokens.
58 /// So to set an attribute to the value "rightHanded", use UsdTokens->rightHanded
59 /// as the value.
60 ///
62 {
63 public:
64  /// Compile time constant representing what kind of schema this class is.
65  ///
66  /// \sa UsdSchemaKind
68 
69  /// Construct a UsdColorSpaceDefinitionAPI on UsdPrim \p prim with
70  /// name \p name . Equivalent to
71  /// UsdColorSpaceDefinitionAPI::Get(
72  /// prim.GetStage(),
73  /// prim.GetPath().AppendProperty(
74  /// "colorSpaceDefinition:name"));
75  ///
76  /// for a \em valid \p prim, but will not immediately throw an error for
77  /// an invalid \p prim
79  const UsdPrim& prim=UsdPrim(), const TfToken &name=TfToken())
80  : UsdAPISchemaBase(prim, /*instanceName*/ name)
81  { }
82 
83  /// Construct a UsdColorSpaceDefinitionAPI on the prim held by \p schemaObj with
84  /// name \p name. Should be preferred over
85  /// UsdColorSpaceDefinitionAPI(schemaObj.GetPrim(), name), as it preserves
86  /// SchemaBase state.
88  const UsdSchemaBase& schemaObj, const TfToken &name)
89  : UsdAPISchemaBase(schemaObj, /*instanceName*/ name)
90  { }
91 
92  /// Destructor.
93  USD_API
95 
96  /// Return a vector of names of all pre-declared attributes for this schema
97  /// class and all its ancestor classes. Does not include attributes that
98  /// may be authored by custom/extended methods of the schemas involved.
99  USD_API
100  static const TfTokenVector &
101  GetSchemaAttributeNames(bool includeInherited=true);
102 
103  /// Return a vector of names of all pre-declared attributes for this schema
104  /// class and all its ancestor classes for a given instance name. Does not
105  /// include attributes that may be authored by custom/extended methods of
106  /// the schemas involved. The names returned will have the proper namespace
107  /// prefix.
108  USD_API
109  static TfTokenVector
110  GetSchemaAttributeNames(bool includeInherited, const TfToken &instanceName);
111 
112  /// Returns the name of this multiple-apply schema instance
113  TfToken GetName() const {
114  return _GetInstanceName();
115  }
116 
117  /// Return a UsdColorSpaceDefinitionAPI holding the prim adhering to this
118  /// schema at \p path on \p stage. If no prim exists at \p path on
119  /// \p stage, or if the prim at that path does not adhere to this schema,
120  /// return an invalid schema object. \p path must be of the format
121  /// <path>.colorSpaceDefinition:name .
122  ///
123  /// This is shorthand for the following:
124  ///
125  /// \code
126  /// TfToken name = SdfPath::StripNamespace(path.GetToken());
127  /// UsdColorSpaceDefinitionAPI(
128  /// stage->GetPrimAtPath(path.GetPrimPath()), name);
129  /// \endcode
130  ///
131  USD_API
133  Get(const UsdStagePtr &stage, const SdfPath &path);
134 
135  /// Return a UsdColorSpaceDefinitionAPI with name \p name holding the
136  /// prim \p prim. Shorthand for UsdColorSpaceDefinitionAPI(prim, name);
137  USD_API
139  Get(const UsdPrim &prim, const TfToken &name);
140 
141  /// Return a vector of all named instances of UsdColorSpaceDefinitionAPI on the
142  /// given \p prim.
143  USD_API
144  static std::vector<UsdColorSpaceDefinitionAPI>
145  GetAll(const UsdPrim &prim);
146 
147  /// Checks if the given name \p baseName is the base name of a property
148  /// of ColorSpaceDefinitionAPI.
149  USD_API
150  static bool
151  IsSchemaPropertyBaseName(const TfToken &baseName);
152 
153  /// Checks if the given path \p path is of an API schema of type
154  /// ColorSpaceDefinitionAPI. If so, it stores the instance name of
155  /// the schema in \p name and returns true. Otherwise, it returns false.
156  USD_API
157  static bool
159 
160  /// Returns true if this <b>multiple-apply</b> API schema can be applied,
161  /// with the given instance name, \p name, to the given \p prim. If this
162  /// schema can not be a applied the prim, this returns false and, if
163  /// provided, populates \p whyNot with the reason it can not be applied.
164  ///
165  /// Note that if CanApply returns false, that does not necessarily imply
166  /// that calling Apply will fail. Callers are expected to call CanApply
167  /// before calling Apply if they want to ensure that it is valid to
168  /// apply a schema.
169  ///
170  /// \sa UsdPrim::GetAppliedSchemas()
171  /// \sa UsdPrim::HasAPI()
172  /// \sa UsdPrim::CanApplyAPI()
173  /// \sa UsdPrim::ApplyAPI()
174  /// \sa UsdPrim::RemoveAPI()
175  ///
176  USD_API
177  static bool
178  CanApply(const UsdPrim &prim, const TfToken &name,
179  std::string *whyNot=nullptr);
180 
181  /// Applies this <b>multiple-apply</b> API schema to the given \p prim
182  /// along with the given instance name, \p name.
183  ///
184  /// This information is stored by adding "ColorSpaceDefinitionAPI:<i>name</i>"
185  /// to the token-valued, listOp metadata \em apiSchemas on the prim.
186  /// For example, if \p name is 'instance1', the token
187  /// 'ColorSpaceDefinitionAPI:instance1' is added to 'apiSchemas'.
188  ///
189  /// \return A valid UsdColorSpaceDefinitionAPI object is returned upon success.
190  /// An invalid (or empty) UsdColorSpaceDefinitionAPI object is returned upon
191  /// failure. See \ref UsdPrim::ApplyAPI() for
192  /// conditions resulting in failure.
193  ///
194  /// \sa UsdPrim::GetAppliedSchemas()
195  /// \sa UsdPrim::HasAPI()
196  /// \sa UsdPrim::CanApplyAPI()
197  /// \sa UsdPrim::ApplyAPI()
198  /// \sa UsdPrim::RemoveAPI()
199  ///
200  USD_API
202  Apply(const UsdPrim &prim, const TfToken &name);
203 
204 protected:
205  /// Returns the kind of schema this class belongs to.
206  ///
207  /// \sa UsdSchemaKind
208  USD_API
209  UsdSchemaKind _GetSchemaKind() const override;
210 
211 private:
212  // needs to invoke _GetStaticTfType.
213  friend class UsdSchemaRegistry;
214  USD_API
215  static const TfType &_GetStaticTfType();
216 
217  static bool _IsTypedSchema();
218 
219  // override SchemaBase virtuals.
220  USD_API
221  const TfType &_GetTfType() const override;
222 
223 public:
224  // --------------------------------------------------------------------- //
225  // NAME
226  // --------------------------------------------------------------------- //
227  /// The name of the color space defined on this prim.
228  ///
229  ///
230  /// | ||
231  /// | -- | -- |
232  /// | Declaration | `uniform token name = "custom"` |
233  /// | C++ Type | TfToken |
234  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Token |
235  /// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
236  USD_API
237  UsdAttribute GetNameAttr() const;
238 
239  /// See GetNameAttr(), and also
240  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
241  /// If specified, author \p defaultValue as the attribute's default,
242  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
243  /// the default for \p writeSparsely is \c false.
244  USD_API
245  UsdAttribute CreateNameAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
246 
247 public:
248  // --------------------------------------------------------------------- //
249  // REDCHROMA
250  // --------------------------------------------------------------------- //
251  /// Red chromaticity coordinates
252  ///
253  /// | ||
254  /// | -- | -- |
255  /// | Declaration | `float2 redChroma = (1, 0)` |
256  /// | C++ Type | GfVec2f |
257  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float2 |
258  USD_API
260 
261  /// See GetRedChromaAttr(), and also
262  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
263  /// If specified, author \p defaultValue as the attribute's default,
264  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
265  /// the default for \p writeSparsely is \c false.
266  USD_API
267  UsdAttribute CreateRedChromaAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
268 
269 public:
270  // --------------------------------------------------------------------- //
271  // GREENCHROMA
272  // --------------------------------------------------------------------- //
273  /// Green chromaticity coordinates
274  ///
275  /// | ||
276  /// | -- | -- |
277  /// | Declaration | `float2 greenChroma = (0, 1)` |
278  /// | C++ Type | GfVec2f |
279  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float2 |
280  USD_API
282 
283  /// See GetGreenChromaAttr(), and also
284  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
285  /// If specified, author \p defaultValue as the attribute's default,
286  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
287  /// the default for \p writeSparsely is \c false.
288  USD_API
289  UsdAttribute CreateGreenChromaAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
290 
291 public:
292  // --------------------------------------------------------------------- //
293  // BLUECHROMA
294  // --------------------------------------------------------------------- //
295  /// Blue chromaticity coordinates
296  ///
297  /// | ||
298  /// | -- | -- |
299  /// | Declaration | `float2 blueChroma = (0, 0)` |
300  /// | C++ Type | GfVec2f |
301  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float2 |
302  USD_API
304 
305  /// See GetBlueChromaAttr(), and also
306  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
307  /// If specified, author \p defaultValue as the attribute's default,
308  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
309  /// the default for \p writeSparsely is \c false.
310  USD_API
311  UsdAttribute CreateBlueChromaAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
312 
313 public:
314  // --------------------------------------------------------------------- //
315  // WHITEPOINT
316  // --------------------------------------------------------------------- //
317  /// Whitepoint chromaticity coordinates
318  ///
319  /// | ||
320  /// | -- | -- |
321  /// | Declaration | `float2 whitePoint = (0.33333334, 0.33333334)` |
322  /// | C++ Type | GfVec2f |
323  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float2 |
324  USD_API
326 
327  /// See GetWhitePointAttr(), and also
328  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
329  /// If specified, author \p defaultValue as the attribute's default,
330  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
331  /// the default for \p writeSparsely is \c false.
332  USD_API
333  UsdAttribute CreateWhitePointAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
334 
335 public:
336  // --------------------------------------------------------------------- //
337  // GAMMA
338  // --------------------------------------------------------------------- //
339  /// Gamma value of the log section
340  ///
341  /// | ||
342  /// | -- | -- |
343  /// | Declaration | `float gamma = 1` |
344  /// | C++ Type | float |
345  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float |
346  USD_API
347  UsdAttribute GetGammaAttr() const;
348 
349  /// See GetGammaAttr(), and also
350  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
351  /// If specified, author \p defaultValue as the attribute's default,
352  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
353  /// the default for \p writeSparsely is \c false.
354  USD_API
355  UsdAttribute CreateGammaAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
356 
357 public:
358  // --------------------------------------------------------------------- //
359  // LINEARBIAS
360  // --------------------------------------------------------------------- //
361  /// Linear bias of the log section
362  ///
363  /// | ||
364  /// | -- | -- |
365  /// | Declaration | `float linearBias = 0` |
366  /// | C++ Type | float |
367  /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float |
368  USD_API
370 
371  /// See GetLinearBiasAttr(), and also
372  /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
373  /// If specified, author \p defaultValue as the attribute's default,
374  /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
375  /// the default for \p writeSparsely is \c false.
376  USD_API
377  UsdAttribute CreateLinearBiasAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
378 
379 public:
380  // ===================================================================== //
381  // Feel free to add custom code below this line, it will be preserved by
382  // the code generator.
383  //
384  // Just remember to:
385  // - Close the class declaration with };
386  // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
387  // - Close the include guard with #endif
388  // ===================================================================== //
389  // --(BEGIN CUSTOM CODE)--
390 
391  /// Creates the color space attributes with the given values.
392  /// @param redChroma The red chromaticity coordinates.
393  /// @param greenChroma The green chromaticity coordinates.
394  /// @param blueChroma The blue chromaticity coordinates.
395  /// @param whitePoint The whitepoint chromaticity coordinates.
396  /// @param gamma The gamma value of the log section.
397  /// @param linearBias The linear bias of the log section.
398  USD_API
399  void CreateColorSpaceAttrsWithChroma(const GfVec2f& redChroma,
400  const GfVec2f& greenChroma,
401  const GfVec2f& blueChroma,
402  const GfVec2f& whitePoint,
403  float gamma, float linearBias);
404 
405  /// Create the color space attributes by deriving the color space from the
406  /// given RGB to XYZ matrix and linearization parameters.
407  /// @param rgbToXYZ The RGB to XYZ matrix.
408  /// @param gamma The gamma value of the log section.
409  /// @param linearBias The linear bias of the log section.
410  USD_API
411  void CreateColorSpaceAttrsWithMatrix(const GfMatrix3f& rgbToXYZ,
412  float gamma, float linearBias);
413 
414  /// Create a `GfColorSpace` object from the color space definition attributes.
415  USD_API
417 };
418 
420 
421 #endif
USD_API void CreateColorSpaceAttrsWithMatrix(const GfMatrix3f &rgbToXYZ, float gamma, float linearBias)
USD_API UsdAttribute CreateBlueChromaAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API UsdAttribute CreateGammaAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API UsdAttribute CreateWhitePointAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API UsdAttribute CreateRedChromaAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
#define USD_API
Definition: api.h:23
static USD_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
USD_API UsdAttribute CreateGreenChromaAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
static USD_API UsdColorSpaceDefinitionAPI Apply(const UsdPrim &prim, const TfToken &name)
static USD_API UsdColorSpaceDefinitionAPI Get(const UsdStagePtr &stage, const SdfPath &path)
virtual USD_API ~UsdColorSpaceDefinitionAPI()
Destructor.
USD_API UsdSchemaKind _GetSchemaKind() const override
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
static USD_API std::vector< UsdColorSpaceDefinitionAPI > GetAll(const UsdPrim &prim)
USD_API UsdAttribute CreateNameAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
const TfToken & _GetInstanceName() const
USD_API UsdAttribute GetWhitePointAttr() const
Definition: token.h:70
USD_API UsdAttribute CreateLinearBiasAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
USD_API UsdAttribute GetGreenChromaAttr() const
UsdColorSpaceDefinitionAPI(const UsdSchemaBase &schemaObj, const TfToken &name)
static USD_API bool IsSchemaPropertyBaseName(const TfToken &baseName)
Definition: prim.h:116
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
USD_API UsdAttribute GetNameAttr() const
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
USD_API UsdAttribute GetBlueChromaAttr() const
static USD_API bool IsColorSpaceDefinitionAPIPath(const SdfPath &path, TfToken *name)
USD_API UsdAttribute GetGammaAttr() const
UsdSchemaKind
Definition: common.h:112
static const UsdSchemaKind schemaKind
USD_API UsdAttribute GetRedChromaAttr() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
static USD_API bool CanApply(const UsdPrim &prim, const TfToken &name, std::string *whyNot=nullptr)
Definition: vec2f.h:45
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
UsdColorSpaceDefinitionAPI(const UsdPrim &prim=UsdPrim(), const TfToken &name=TfToken())
USD_API GfColorSpace ComputeColorSpaceFromDefinitionAttributes() const
Create a GfColorSpace object from the color space definition attributes.
Definition: type.h:47
USD_API void CreateColorSpaceAttrsWithChroma(const GfVec2f &redChroma, const GfVec2f &greenChroma, const GfVec2f &blueChroma, const GfVec2f &whitePoint, float gamma, float linearBias)
Definition: value.h:146
Multiple Apply API Schema.
TfToken GetName() const
Returns the name of this multiple-apply schema instance.
USD_API UsdAttribute GetLinearBiasAttr() const