IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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>
16
17IMPDISPLAY_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 */
23class 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
61 IMP_DECORATOR_METHODS(Colored, Decorator);
62 IMP_DECORATOR_SETUP_1(Colored, Color, color);
63};
64
66
67IMPDISPLAY_END_NAMESPACE
68
69#endif /* IMPDISPLAY_COLORED_H */
Represent a color.
The base class for decorators.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition Decorator.h:211
Model * get_model() const
Returns the Model containing the particle.
Definition Decorator.h:214
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Represent an RGB color.
Definition Color.h:25
A particle with a color.
Definition Colored.h:23
Helper macros for implementing Decorators.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_METHODS(Name, Parent)
Index< ParticleIndexTag > ParticleIndex
Definition base_types.h:196
Vector< Pointer< Particle > > Particles
A list of reference-counted Particle objects.
Definition base_types.h:138
IMP::Vector< FloatKey > FloatKeys
Definition base_types.h:33