Loading...
Searching...
No Matches
colorSpaceAPI.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_COLORSPACEAPI_H
8#define USD_GENERATED_COLORSPACEAPI_H
9
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#include "pxr/base/tf/bigRWMutex.h"
21
22
23#include "pxr/base/vt/value.h"
24
25#include "pxr/base/gf/vec3d.h"
26#include "pxr/base/gf/vec3f.h"
28
29#include "pxr/base/tf/token.h"
30#include "pxr/base/tf/type.h"
31
32PXR_NAMESPACE_OPEN_SCOPE
33
34class SdfAssetPath;
35
36// -------------------------------------------------------------------------- //
37// COLORSPACEAPI //
38// -------------------------------------------------------------------------- //
39
94{
95public:
99 static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI;
100
105 explicit UsdColorSpaceAPI(const UsdPrim& prim=UsdPrim())
106 : UsdAPISchemaBase(prim)
107 {
108 }
109
113 explicit UsdColorSpaceAPI(const UsdSchemaBase& schemaObj)
114 : UsdAPISchemaBase(schemaObj)
115 {
116 }
117
119 USD_API
121
125 USD_API
126 static const TfTokenVector &
127 GetSchemaAttributeNames(bool includeInherited=true);
128
138 USD_API
139 static UsdColorSpaceAPI
140 Get(const UsdStagePtr &stage, const SdfPath &path);
141
142
159 USD_API
160 static bool
161 CanApply(const UsdPrim &prim, std::string *whyNot=nullptr);
162
178 USD_API
179 static UsdColorSpaceAPI
180 Apply(const UsdPrim &prim);
181
182protected:
186 USD_API
188
189private:
190 // needs to invoke _GetStaticTfType.
191 friend class UsdSchemaRegistry;
192 USD_API
193 static const TfType &_GetStaticTfType();
194
195 static bool _IsTypedSchema();
196
197 // override SchemaBase virtuals.
198 USD_API
199 const TfType &_GetTfType() const override;
200
201public:
202 // --------------------------------------------------------------------- //
203 // COLORSPACENAME
204 // --------------------------------------------------------------------- //
215 USD_API
217
223 USD_API
224 UsdAttribute CreateColorSpaceNameAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
225
226public:
227 // ===================================================================== //
228 // Feel free to add custom code below this line, it will be preserved by
229 // the code generator.
230 //
231 // Just remember to:
232 // - Close the class declaration with };
233 // - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
234 // - Close the include guard with #endif
235 // ===================================================================== //
236 // --(BEGIN CUSTOM CODE)--
237
245 public:
246 ColorSpaceCache() = default;
247 virtual ~ColorSpaceCache() = default;
248
249 virtual TfToken Find(const SdfPath& prim) = 0;
250 virtual void Insert(const SdfPath& prim, const TfToken& colorSpace) = 0;
251 };
252
270 protected:
271 TfHashMap<SdfPath, TfToken, SdfPath::Hash> _cache;
272 mutable TfBigRWMutex _mutex;
273 public:
274 ColorSpaceHashCache() = default;
275 ~ColorSpaceHashCache() = default;
276
277 TfToken Find(const SdfPath& prim) override {
278 TfBigRWMutex::ScopedLock lock(_mutex, /*write=*/false);
279 auto it = _cache.find(prim);
280 if (it != _cache.end()) {
281 return it->second;
282 }
283 return TfToken();
284 }
285
286 void Insert(const SdfPath& prim, const TfToken& colorSpace) override {
287 TfBigRWMutex::ScopedLock lock(_mutex);
288 _cache[prim] = colorSpace;
289 }
290 };
291
310 USD_API
312 ColorSpaceCache* cache = nullptr);
313
319 USD_API
321 ColorSpaceCache* cache = nullptr);
322
341 USD_API
343 ColorSpaceCache* cache = nullptr);
344
350 USD_API
352 const TfToken& colorSpace,
353 ColorSpaceCache* cache = nullptr);
354
359 USD_API
361 ColorSpaceCache* cache = nullptr);
362
368 USD_API
370 const TfToken& colorSpace,
371 ColorSpaceCache* cache = nullptr);
372};
373
374PXR_NAMESPACE_CLOSE_SCOPE
375
376#endif
Basic type: ColorSpace.
Definition: colorSpace.h:115
Contains an asset path and optional evaluated and resolved paths.
Definition: assetPath.h:78
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
This class implements a readers-writer mutex and provides a scoped lock utility.
Definition: bigRWMutex.h:53
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
TfType represents a dynamic runtime type.
Definition: type.h:48
The base class for all API schemas.
Definition: apiSchemaBase.h:99
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:183
A minimalistic cache for color space lookups.
This is a simple example of a color space cache implementation.
UsdColorSpaceAPI is an API schema that introduces a colorSpace property for authoring scene referred ...
Definition: colorSpaceAPI.h:94
static USD_API const TfTokenVector & GetSchemaAttributeNames(bool includeInherited=true)
Return a vector of names of all pre-declared attributes for this schema class and all its ancestor cl...
virtual USD_API ~UsdColorSpaceAPI()
Destructor.
static const UsdSchemaKind schemaKind
Compile time constant representing what kind of schema this class is.
Definition: colorSpaceAPI.h:99
USD_API UsdSchemaKind _GetSchemaKind() const override
Returns the kind of schema this class belongs to.
USD_API UsdAttribute CreateColorSpaceNameAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetColorSpaceNameAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
static USD_API GfColorSpace ComputeColorSpace(const UsdAttribute &attribute, ColorSpaceCache *cache=nullptr)
Computes the color space for the given attribute on this prim, using the same algorithm as ComputeCol...
static USD_API TfToken ComputeColorSpaceName(UsdPrim prim, ColorSpaceCache *cache=nullptr)
Computes the color space name for the given prim.
UsdColorSpaceAPI(const UsdSchemaBase &schemaObj)
Construct a UsdColorSpaceAPI on the prim held by schemaObj .
static USD_API TfToken ComputeColorSpaceName(const UsdAttribute &attribute, ColorSpaceCache *cache=nullptr)
Computes the color space name for the given attribute.
static USD_API bool IsValidColorSpaceName(UsdPrim prim, const TfToken &colorSpace, ColorSpaceCache *cache=nullptr)
Returns true if the named color space is built in, defined on the supplied prim, or on one of the pri...
static USD_API UsdColorSpaceAPI Apply(const UsdPrim &prim)
Applies this single-apply API schema to the given prim.
static USD_API GfColorSpace ComputeColorSpace(UsdPrim prim, const TfToken &colorSpace, ColorSpaceCache *cache=nullptr)
Creates a color space object for the named color space if it built in, defined on the prim or on an a...
USD_API UsdAttribute GetColorSpaceNameAttr() const
The color space that applies to attributes with unauthored color spaces on this prim and its descende...
UsdColorSpaceAPI(const UsdPrim &prim=UsdPrim())
Construct a UsdColorSpaceAPI on UsdPrim prim .
static USD_API UsdColorSpaceAPI Get(const UsdStagePtr &stage, const SdfPath &path)
Return a UsdColorSpaceAPI holding the prim adhering to this schema at path on stage.
static USD_API GfColorSpace ComputeColorSpace(UsdPrim prim, ColorSpaceCache *cache=nullptr)
Computes the color space for this prim, using the same algorithm as ComputeColorSpaceName().
static USD_API bool CanApply(const UsdPrim &prim, std::string *whyNot=nullptr)
Returns true if this single-apply API schema can be applied to the given prim.
UsdPrim is the sole persistent scenegraph object on a UsdStage, and is the embodiment of a "Prim" as ...
Definition: prim.h:117
The base class for all schema types in Usd.
Definition: schemaBase.h:39
Singleton registry that provides access to schema type information and the prim definitions for regis...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
UsdSchemaKind
An enum representing which kind of schema a given schema class belongs to.
Definition: common.h:112
Scoped lock utility class.
Definition: bigRWMutex.h:69
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