8 #ifndef IMPDISPLAY_COLOR_H
9 #define IMPDISPLAY_COLOR_H
11 #include <IMP/display/display_config.h>
17 #include <boost/array.hpp>
19 IMPDISPLAY_BEGIN_NAMESPACE
26 boost::array<double, 3> c_;
27 int compare(
double a,
double b)
const {
29 else if (a > b)
return 1;
32 int compare(
const Color &o)
const {
33 for (
unsigned int i=0; i< 3; ++i) {
34 int c= compare(c_[i], o.c_[i]);
45 Color(
double r,
double g,
double b);
51 std::copy(b,e, c_.begin());
58 double get_red()
const {
62 double get_green()
const {
65 double get_blue()
const {
69 typedef const double *ComponentIterator;
70 ComponentIterator components_begin()
const {
73 ComponentIterator components_end()
const {
79 void show(std::ostream &out, std::string delim)
const {
80 out << get_red() << delim << get_green() << delim << get_blue();
100 explicit SpacesIO(
const Color &v): v_(v){}
106 explicit CommasIO(
const Color &v): v_(v){}
108 inline std::ostream &operator<<(std::ostream &out,
const SpacesIO &s)
113 inline std::ostream &operator<<(std::ostream &out,
const CommasIO &s)
115 s.v_.show(out,
", ");
124 inline SpacesIO spaces_io(
const Color &v) {
136 inline CommasIO commas_io(
const Color &v) {
143 inline Color
operator*(
double d, Color c) {
144 IMP_USAGE_CHECK(d <=1 && d>=0,
"Colors can only fade with multiplication");
145 return Color(c.get_red()*d, c.get_green()*d, c.get_blue()*d);
151 inline Color
operator*(Color c,
double d) {
165 return Color((1-f)*a.get_red()+f*b.get_red(),
166 (1-f)*a.get_green()+f*b.get_green(),
167 (1-f)*a.get_blue()+f*b.get_blue());
213 IMPDISPLAY_END_NAMESPACE