This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
color.h
Go to the documentation of this file.
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_BASE_GF_COLOR_H
8#define PXR_BASE_GF_COLOR_H
9
12
13#include "pxr/pxr.h"
14#include "pxr/base/gf/colorSpace.h"
15#include "pxr/base/gf/vec2f.h"
16#include "pxr/base/gf/vec3f.h"
18#include "pxr/base/gf/api.h"
19
20#include <iosfwd>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
40
41class GfColor {
42public:
44 GF_API GfColor();
45
48 GF_API
49 explicit GfColor(const GfColorSpace& colorSpace);
50
55 GF_API
56 GfColor(const GfVec3f &rgb, const GfColorSpace& colorSpace);
57
61 GF_API
62 GfColor(const GfColor &color, const GfColorSpace& colorSpace);
63
70 GF_API
71 void SetFromPlanckianLocus(float kelvin, float luminance);
72
75 GfVec3f GetRGB() const { return _rgb; }
76
80
84 bool operator ==(const GfColor &rh) const {
85 return _rgb == rh._rgb && _colorSpace == rh._colorSpace;
86 }
87
91 bool operator !=(const GfColor &rh) const { return !(*this == rh); }
92
93protected:
96
97 // Get the CIEXY coordinate of the color in the chromaticity chart,
98 // For use in testing.
99 GF_API
100 GfVec2f _GetChromaticity() const;
101
102 // Set the color from a CIEXY coordinate in the chromaticity chart.
103 // For use in testing.
104 GF_API
105 void _SetFromChromaticity(const GfVec2f& xy);
106};
107
108
113inline bool
114GfIsClose(GfColor const &c1, GfColor const &c2, double tolerance)
115{
116 return GfIsClose(c1.GetRGB(), c2.GetRGB(), tolerance);
117}
118
128std::ostream& operator<<(std::ostream &, GfColor const &);
129
130PXR_NAMESPACE_CLOSE_SCOPE
131
132#endif // PXR_BASE_GF_COLOR_H
Represents a color in a specific color space.
Definition: color.h:41
GF_API GfColor(const GfColor &color, const GfColorSpace &colorSpace)
Construct a color by converting the source color into the specified color space.
GF_API void SetFromPlanckianLocus(float kelvin, float luminance)
Set the color from the Planckian locus (blackbody radiation) temperature in Kelvin,...
bool operator!=(const GfColor &rh) const
Inequality operator.
Definition: color.h:91
GfVec3f _rgb
The RGB tuple.
Definition: color.h:95
GfColorSpace GetColorSpace() const
Get the color space.
Definition: color.h:79
bool operator==(const GfColor &rh) const
Equality operator.
Definition: color.h:84
GfVec3f GetRGB() const
Get the RGB tuple.
Definition: color.h:75
GF_API GfColor()
The default constructor creates black, in the "lin_rec709" color space.
GF_API GfColor(const GfVec3f &rgb, const GfColorSpace &colorSpace)
Construct a color from an RGB tuple and color space.
GF_API GfColor(const GfColorSpace &colorSpace)
Construct a black color in the given color space.
GfColorSpace _colorSpace
The color space.
Definition: color.h:94
Basic type: ColorSpace.
Definition: colorSpace.h:95
Basic type for a vector of 2 float components.
Definition: vec2f.h:46
Basic type for a vector of 3 float components.
Definition: vec3f.h:46
bool GfIsClose(GfColor const &c1, GfColor const &c2, double tolerance)
Tests for equality of the RGB tuple in a color with a given tolerance, returning true if the length o...
Definition: color.h:114
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].