FAST  3.2.0
Framework for Heterogeneous Medical Image Computing and Visualization
Color.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 #include <cctype> // std::tolower
5 
6 namespace fast {
7 
8 class FAST_EXPORT Color {
9  private:
10  Vector3f mColorVector;
11  public:
12  Color() : mColorVector(Vector3f(0, 0, 0)) {};
13 
14  Color(float red, float green, float blue) : mColorVector(Vector3f(red, green, blue)) {};
15 
16  static Color fromString(std::string str) {
17  std::transform(str.begin(), str.end(), str.begin(),
18  [](unsigned char c) { return std::tolower(c); });
19  std::map<std::string, Color> mapping = {
20  {"black", Color::Black()},
21  {"white", Color::White()},
22  {"red", Color::Red()},
23  {"blue", Color::Blue()},
24  {"green", Color::Green()},
25  {"yellow", Color::Yellow()},
26  {"cyan", Color::Cyan()},
27  {"magenta", Color::Magenta()},
28  {"brown", Color::Brown()},
29  };
30 
31  if(mapping.count(str) == 0)
32  throw Exception("Could not find color " + str);
33 
34  return mapping[str];
35  }
36 
37  Vector3f asVector() const {
38  return mColorVector;
39  }
40  float getRedValue() const {
41  return mColorVector.x();
42  }
43  float getGreenValue() const {
44  return mColorVector.y();
45  }
46  float getBlueValue() const {
47  return mColorVector.z();
48  }
49  static Color Red() {
50  return Color(1,0,0);
51  }
52  static Color Green() {
53  return Color(0,1,0);
54  }
55  static Color Blue() {
56  return Color(0,0,1);
57  }
58  static Color White() {
59  return Color(1,1,1);
60  }
61  static Color Black() {
62  return Color(0,0,0);
63  }
64  static Color Yellow() {
65  return Color(1, 1, 0);
66  }
67  static Color Magenta() {
68  return Color(1, 0, 1);
69  }
70  static Color Cyan() {
71  return Color(0, 1, 1);
72  }
73  static Color Brown() {
74  return Color(1, 0.6, 0.2);
75  }
76 
77 };
78 
79 
80 }
81 
fast::Color::getRedValue
float getRedValue() const
Definition: Color.hpp:40
fast::Color::Black
static Color Black()
Definition: Color.hpp:61
fast::Color::Blue
static Color Blue()
Definition: Color.hpp:55
fast::Exception
Definition: Exception.hpp:15
fast::Color::Green
static Color Green()
Definition: Color.hpp:52
fast::Color::getBlueValue
float getBlueValue() const
Definition: Color.hpp:46
fast
Definition: AffineTransformation.hpp:7
fast::Color::Yellow
static Color Yellow()
Definition: Color.hpp:64
fast::Color::Cyan
static Color Cyan()
Definition: Color.hpp:70
fast::Color::Color
Color()
Definition: Color.hpp:12
fast::Color::Red
static Color Red()
Definition: Color.hpp:49
fast::Color::getGreenValue
float getGreenValue() const
Definition: Color.hpp:43
fast::Color::White
static Color White()
Definition: Color.hpp:58
fast::Color::Brown
static Color Brown()
Definition: Color.hpp:73
fast::Color::fromString
static Color fromString(std::string str)
Definition: Color.hpp:16
fast::Color::Magenta
static Color Magenta()
Definition: Color.hpp:67
DataTypes.hpp
fast::Color::Color
Color(float red, float green, float blue)
Definition: Color.hpp:14
fast::Color
Definition: Color.hpp:8
fast::Color::asVector
Vector3f asVector() const
Definition: Color.hpp:37