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
25 boost::array<double, 3> c_;
26 int compare(
double a,
double b)
const {
35 for (
unsigned int i = 0; i < 3; ++i) {
36 int c =
compare(c_[i], o.c_[i]);
43 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(
Color);
49 Color(
double r,
double g,
double b);
55 std::copy(b, e, c_.begin());
62 double get_red()
const {
return c_[0]; }
64 double get_green()
const {
return c_[1]; }
65 double get_blue()
const {
return c_[2]; }
67 typedef const double *ComponentIterator;
68 ComponentIterator components_begin()
const {
return c_.begin(); }
69 ComponentIterator components_end()
const {
return c_.end(); }
70 const boost::array<double, 3> &get_rgb()
const {
return c_; }
74 void show(std::ostream &out, std::string delim)
const {
75 out << get_red() << delim << get_green() << delim << get_blue();
93 explicit SpacesIO(
const Color &v) : v_(v) {}
98 explicit CommasIO(
const Color &v) : v_(v) {}
100 inline std::ostream &operator<<(std::ostream &out,
const SpacesIO &s) {
104 inline std::ostream &operator<<(std::ostream &out,
const CommasIO &s) {
105 s.v_.show(out,
", ");
114 inline SpacesIO spaces_io(
const Color &v) {
return SpacesIO(v); }
121 inline CommasIO commas_io(
const Color &v) {
return CommasIO(v); }
126 inline Color
operator*(
double d, Color c) {
127 IMP_USAGE_CHECK(d <= 1 && d >= 0,
"Colors can only fade with multiplication");
128 return Color(c.get_red() * d, c.get_green() * d, c.get_blue() * d);
134 inline Color
operator*(Color c,
double d) {
return d * c; }
144 return Color((1 - f) * a.get_red() + f * b.get_red(),
145 (1 - f) * a.get_green() + f * b.get_green(),
146 (1 - f) * a.get_blue() + f * b.get_blue());
190 IMPDISPLAY_END_NAMESPACE
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Various general useful macros for IMP.
Color get_rgb_color(double f)
Return the color for f from the RGB color map.
#define IMP_COMPARISONS(Name)
Implement comparison in a class using a compare function.
double get_linear_color_map_value(double min, double max, double value)
Color get_interpolated_rgb(const Color &a, const Color &b, double f)
Return a color interpolated between a and b in RGB space.
Color get_hot_color(double f)
Return the color for f from the hot color map.
Base for a simple primitive-like type.
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
int compare(const VectorD< D > &a, const VectorD< D > &b)
lexicographic comparison of two vectors
Color get_display_color(unsigned int i)
Color get_gnuplot_color(double f)
Return colors using the gnuplot default color map.
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
Exception definitions and assertions.
Color get_gray_color(double f)
Return the a grayscale value for f.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Various general useful macros for IMP.
VectorD< D > operator*(double s, VectorD< D > o)
Color get_jet_color(double f)
Return the color for f from the jet color map.
Various general useful macros for IMP.