IMP logo
IMP Reference Guide  2.5.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-2015 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  static void do_setup_particle(Model *m, ParticleIndex pi,
25  Color c) {
26  m->add_attribute(get_color_keys()[0], pi, c.get_red(), false);
27  m->add_attribute(get_color_keys()[1], pi, c.get_green(), false);
28  m->add_attribute(get_color_keys()[2], pi, c.get_blue(), false);
29  }
30 
31  public:
32  void set_color(const Color &c) {
33  get_model()->set_attribute(get_color_keys()[0], get_particle_index(),
34  c.get_red());
35  get_model()->set_attribute(get_color_keys()[1], get_particle_index(),
36  c.get_green());
37  get_model()->set_attribute(get_color_keys()[2], get_particle_index(),
38  c.get_blue());
39  }
40 
41  Color get_color() const {
42  return Color(
43  get_model()->get_attribute(get_color_keys()[0], get_particle_index()),
44  get_model()->get_attribute(get_color_keys()[1], get_particle_index()),
45  get_model()->get_attribute(get_color_keys()[2], get_particle_index()));
46  }
47 
48  static bool get_is_setup(Model *m, ParticleIndex pi) {
49  IMP_USAGE_CHECK((!m->get_has_attribute(get_color_keys()[0], pi) &&
50  !m->get_has_attribute(get_color_keys()[1], pi) &&
51  !m->get_has_attribute(get_color_keys()[2], pi)) ||
52  (m->get_has_attribute(get_color_keys()[0], pi) &&
53  m->get_has_attribute(get_color_keys()[1], pi) &&
54  m->get_has_attribute(get_color_keys()[2], pi)),
55  "Only partially colored " << m->get_particle_name(pi));
56  return m->get_has_attribute(get_color_keys()[2], pi);
57  }
58 
59  static const FloatKeys &get_color_keys();
60 
63 };
64 
66 
67 IMPDISPLAY_END_NAMESPACE
68 
69 #endif /* IMPDISPLAY_COLORED_H */
The base class for decorators.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:186
Represent an RGB color.
Definition: Color.h:24
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:189
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
std::string get_particle_name(ParticleIndex pi)
Get the name of a particle.
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
Various general useful macros for IMP.
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
Represent a color.
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
A particle with a color.
Definition: Colored.h:23