IMP  2.0.0
The Integrative Modeling Platform
Colored.h
Go to the documentation of this file.
1 /**
2  * \file IMP/display/Colored.h
3  * \brief A decorator for a particle with a color
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPDISPLAY_COLORED_H
9 #define IMPDISPLAY_COLORED_H
10 
11 #include <IMP/display/display_config.h>
12 
13 #include "Color.h"
14 #include <IMP/Decorator.h>
15 #include <IMP/decorator_macros.h>
16 
17 IMPDISPLAY_BEGIN_NAMESPACE
18 
19 //! A particle with a color.
20 /** Many of the geometry objects will use this color
21  if it is available.
22  */
23 class IMPDISPLAYEXPORT Colored: public Decorator
24 {
25 public:
26  static Colored setup_particle(Particle *p, Color c) {
27  p->add_attribute(get_color_keys()[0], c.get_red(), false);
28  p->add_attribute(get_color_keys()[1], c.get_green(), false);
29  p->add_attribute(get_color_keys()[2], c.get_blue(), false);
30  return Colored(p);
31  }
32 
33  void set_color(const Color &c) {
34  get_particle()->set_value(get_color_keys()[0], c.get_red());
35  get_particle()->set_value(get_color_keys()[1], c.get_green());
36  get_particle()->set_value(get_color_keys()[2], c.get_blue());
37  }
38 
39  Color get_color() const {
40  return Color(get_particle()->get_value(get_color_keys()[0]),
41  get_particle()->get_value(get_color_keys()[1]),
42  get_particle()->get_value(get_color_keys()[2]));
43  }
44 
45  static bool particle_is_instance(Particle *p) {
46  IMP_USAGE_CHECK((!p->has_attribute(get_color_keys()[0])
47  && !p->has_attribute(get_color_keys()[1])
48  && !p->has_attribute(get_color_keys()[2]))
49  || (p->has_attribute(get_color_keys()[0])
50  && p->has_attribute(get_color_keys()[1])
51  && p->has_attribute(get_color_keys()[2])),
52  "Only partially colored " << p->get_name());
53  return p->has_attribute(get_color_keys()[2]);
54  }
55 
56  static const FloatKeys& get_color_keys();
57 
59 };
60 
61 IMP_DECORATORS(Colored, Coloreds, Particles);
62 
63 
64 IMPDISPLAY_END_NAMESPACE
65 
66 #endif /* IMPDISPLAY_COLORED_H */