8 #ifndef IMPDISPLAY_COLOR_H
9 #define IMPDISPLAY_COLOR_H
11 #include <IMP/display/display_config.h>
18 #include <cereal/access.hpp>
20 IMPDISPLAY_BEGIN_NAMESPACE
26 std::array<double, 3> c_;
28 friend class cereal::access;
30 template<
class Archive>
void serialize(Archive &ar) {
31 ar(c_[0], c_[1], c_[2]);
34 int compare(
double a,
double b)
const {
43 for (
unsigned int i = 0; i < 3; ++i) {
44 int c =
compare(c_[i], o.c_[i]);
51 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(
Color);
57 Color(
double r,
double g,
double b);
63 std::copy(b, e, c_.begin());
70 double get_red()
const {
return c_[0]; }
72 double get_green()
const {
return c_[1]; }
73 double get_blue()
const {
return c_[2]; }
75 typedef std::array<double, 3>::const_iterator ComponentIterator;
76 ComponentIterator components_begin()
const {
return c_.begin(); }
77 ComponentIterator components_end()
const {
return c_.end(); }
78 const std::array<double, 3> &get_rgb()
const {
return c_; }
82 void show(std::ostream &out, std::string delim)
const {
83 out << get_red() << delim << get_green() << delim << get_blue();
101 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) {
112 inline std::ostream &operator<<(std::ostream &out,
const CommasIO &s) {
113 s.v_.show(out,
", ");
122 inline SpacesIO spaces_io(
const Color &v) {
return SpacesIO(v); }
129 inline CommasIO commas_io(
const Color &v) {
return CommasIO(v); }
134 inline Color
operator*(
double d, Color c) {
135 IMP_USAGE_CHECK(d <= 1 && d >= 0,
"Colors can only fade with multiplication");
136 return Color(c.get_red() * d, c.get_green() * d, c.get_blue() * d);
142 inline Color
operator*(Color c,
double d) {
return d * c; }
152 return Color((1 - f) * a.get_red() + f * b.get_red(),
153 (1 - f) * a.get_green() + f * b.get_green(),
154 (1 - f) * a.get_blue() + f * b.get_blue());
198 IMPDISPLAY_END_NAMESPACE
#define IMP_SHOWABLE_INLINE(Name, how_to_show)
Declare the methods needed by an object that can be printed.
Helper macros for implementing comparisons of IMP objects.
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.
A more IMP-like version of the std::vector.
Base class 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.
Helper macros for throwing and handling exceptions.
Base class for a simple primitive-like type.
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.
Macros to help in implementing Value objects.
VectorD< D > operator*(double s, VectorD< D > o)
Color get_jet_color(double f)
Return the color for f from the jet color map.
Macros to help with objects that can be printed to a stream.