scenepic 1.1.0
3D Visualization Made Easy
color.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#ifndef _SCENEPIC_COLOR_H_
5#define _SCENEPIC_COLOR_H_
6
7#include "matrix.h"
8
9#include <Eigen/Core>
10#include <cmath>
11#include <cstdint>
12#include <iostream>
13#include <string>
14
15namespace scenepic
16{
18 class Color : public Eigen::Vector3f
19 {
20 public:
22 Color(void) : Eigen::Vector3f() {}
23
25 Color(Eigen::Index rows, Eigen::Index cols) : Eigen::Vector3f(rows, cols) {}
26
27 typedef Eigen::Vector3f Base;
28
31 template<typename OtherDerived>
32 Color(const Eigen::MatrixBase<OtherDerived>& other) : Eigen::Vector3f(other)
33 {}
34
36 template<typename OtherDerived>
37 Color& operator=(const Eigen::MatrixBase<OtherDerived>& other)
38 {
39 this->Base::operator=(other);
40 return *this;
41 }
42
48 Color(const Scalar& red, const Scalar& green, const Scalar& blue);
49
56 static Color
57 from_bytes(std::uint8_t red, std::uint8_t green, std::uint8_t blue);
58
60 std::string to_html_hex() const;
61
63 Scalar r() const;
65 Scalar g() const;
67 Scalar b() const;
68
70 std::uint8_t R() const;
72 std::uint8_t G() const;
74 std::uint8_t B() const;
75
77 Scalar& r();
79 Scalar& g();
81 Scalar& b();
82
84 std::string to_string() const;
85
87 bool is_none() const;
88
90 static const Color None();
91 };
92
93 namespace Colors
94 {
95 const Color Black = Color::from_bytes(0, 0, 0);
96 const Color White = Color::from_bytes(255, 255, 255);
97 const Color Red = Color::from_bytes(255, 0, 0);
98 const Color Maroon = Color::from_bytes(128, 0, 0);
99 const Color Pink = Color::from_bytes(255, 200, 220);
100 const Color Brown = Color::from_bytes(170, 110, 40);
101 const Color Orange = Color::from_bytes(255, 150, 0);
102 const Color Coral = Color::from_bytes(255, 215, 180);
103 const Color Olive = Color::from_bytes(128, 128, 0);
104 const Color Yellow = Color::from_bytes(255, 235, 0);
105 const Color Beige = Color::from_bytes(255, 250, 200);
106 const Color Lime = Color::from_bytes(190, 255, 0);
107 const Color Green = Color::from_bytes(0, 190, 0);
108 const Color Mint = Color::from_bytes(170, 255, 195);
109 const Color Teal = Color::from_bytes(0, 128, 128);
110 const Color Cyan = Color::from_bytes(100, 255, 255);
111 const Color Navy = Color::from_bytes(0, 0, 128);
112 const Color Blue = Color::from_bytes(67, 133, 255);
113 const Color Purple = Color::from_bytes(130, 0, 150);
114 const Color Lavender = Color::from_bytes(230, 190, 255);
115 const Color Magenta = Color::from_bytes(255, 0, 255);
116 const Color Gray = Color::from_bytes(128, 128, 128);
117 } // namespace Colors
118} // namespace scenepic
119
120#endif
Class for representing color values.
Definition: color.h:19
Scalar r() const
The red value [0,1].
static Color from_bytes(std::uint8_t red, std::uint8_t green, std::uint8_t blue)
Construct a color object from byte values.
static const Color None()
Constant value indicating "no color".
Color(const Scalar &red, const Scalar &green, const Scalar &blue)
Constructor.
std::uint8_t G() const
The green value [0,255].
Color(Eigen::Index rows, Eigen::Index cols)
Needed for pybind.
Definition: color.h:25
Scalar & b()
Reference to the blue value [0,1].
Color(void)
Empty constructor.
Definition: color.h:22
Color & operator=(const Eigen::MatrixBase< OtherDerived > &other)
Constructor which allows Eigen assignments to Color.
Definition: color.h:37
Eigen::Vector3f Base
Definition: color.h:27
Scalar g() const
The green value [0,1].
std::uint8_t R() const
The red value [0,255].
bool is_none() const
Whether this is a "no color" instance.
Scalar & g()
Reference to the green value [0,1].
Scalar b() const
The blue value [0,1].
Color(const Eigen::MatrixBase< OtherDerived > &other)
Constructor which allows construction of Colors from Eigen expressions.
Definition: color.h:32
std::string to_string() const
Represent the color as a string.
std::string to_html_hex() const
Convert the color to an HTML hex color string.
std::uint8_t B() const
The blue value [0,255].
Scalar & r()
Reference to the red value [0,1].
const Color Green
Definition: color.h:107
const Color Olive
Definition: color.h:103
const Color Red
Definition: color.h:97
const Color Yellow
Definition: color.h:104
const Color Cyan
Definition: color.h:110
const Color Magenta
Definition: color.h:115
const Color Lime
Definition: color.h:106
const Color Maroon
Definition: color.h:98
const Color Mint
Definition: color.h:108
const Color Gray
Definition: color.h:116
const Color Purple
Definition: color.h:113
const Color White
Definition: color.h:96
const Color Navy
Definition: color.h:111
const Color Blue
Definition: color.h:112
const Color Black
Definition: color.h:95
const Color Orange
Definition: color.h:101
const Color Beige
Definition: color.h:105
const Color Lavender
Definition: color.h:114
const Color Coral
Definition: color.h:102
const Color Pink
Definition: color.h:99
const Color Brown
Definition: color.h:100
const Color Teal
Definition: color.h:109
Definition: audio_track.h:14