IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
geometry_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/display/geometry_macros.h
3  * \brief macros for display classes
4  *
5  * Copyright 2007-2020 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPDISPLAY_GEOMETRY_MACROS_H
9 #define IMPDISPLAY_GEOMETRY_MACROS_H
10 #include "declare_Geometry.h"
11 #include <IMP/singleton_macros.h>
12 #include <IMP/pair_macros.h>
13 
14 //! Define information for an Geometry object
15 #define IMP_DISPLAY_GEOMETRY_DEF(Name, Type) \
16  Name::Name(std::string name) : display::Geometry(name) {} \
17  Name::Name(const Type &v) : display::Geometry(#Name), v_(v) {} \
18  Name::Name(const Type &v, const Color &c) \
19  : display::Geometry(c, #Name), v_(v) {} \
20  Name::Name(const Type &v, const std::string n) \
21  : display::Geometry(n), v_(v) {} \
22  Name::Name(const Type &v, const Color &c, std::string n) \
23  : display::Geometry(c, n), v_(v) {} \
24  display::Geometries Name::get_components() const { \
25  return display::Geometries(1, const_cast<Name *>(this)); \
26  } \
27  IMP_REQUIRE_SEMICOLON_NAMESPACE
28 
29 #if defined(IMP_DOXYGEN) || defined(SWIG)
30 //! Define a geometric object using an IMP::algebra one
31 #define IMP_DISPLAY_GEOMETRY_DECL(Name, Names, Type) \
32  /** Display a geometric object.*/ \
33  class IMPDISPLAYEXPORT Name : public display::Geometry { \
34  public: \
35  Name(const Type &v); \
36  Name(const Type &v, const display::Color &c); \
37  Name(const Type &v, const std::string n); \
38  Name(const Type &v, const display::Color &c, std::string n); \
39  virtual const Type &get_geometry() const { return v_; } \
40  void set_geometry(const Type &v) { v_ = v; } \
41  virtual IMP::display::Geometries get_components() const IMP_OVERRIDE; \
42  IMP_OBJECT_METHODS(Name); \
43  }; \
44  /** Create a Geometry with the passed primitive.*/ \
45  inline Name *create_geometry(const Type &t, std::string name = #Type + \
46  "%1" \
47  "%")
48 
49 #define IMP_DISPLAY_GEOMETRY_DECOMPOSABLE_DECL(Name, Names, Type) \
50  /** Display a compound geometric object.*/ \
51  class IMPDISPLAYEXPORT Name : public display::Geometry { \
52  public: \
53  Name(const Type &v); \
54  Name(const Type &v, const display::Color &c); \
55  Name(const Type &v, const std::string n); \
56  Name(const Type &v, const display::Color &c, std::string n); \
57  virtual const Type &get_geometry() const { return v_; } \
58  void set_geometry(const Type &v) { v_ = v; } \
59  virtual IMP::display::Geometries get_components() const IMP_OVERRIDE; \
60  IMP_OBJECT_METHODS(Name); \
61  }; \
62  /** Create a Geometry with the passed primitive.*/ \
63  inline Name *create_geometry(const Type &t, std::string name = #Type + \
64  "%1" \
65  "%")
66 
67 #else
68 
69 //! Define a geometric object using an IMP::algebra one
70 #define IMP_DISPLAY_GEOMETRY_DECL(Name, Names, Type) \
71  /** Display a geometric object.*/ \
72  class IMPDISPLAYEXPORT Name : public display::Geometry { \
73  Type v_; \
74  \
75  public: \
76  Name(std::string name); \
77  Name(const Type &v); \
78  Name(const Type &v, const display::Color &c); \
79  Name(const Type &v, const std::string n); \
80  Name(const Type &v, const display::Color &c, std::string n); \
81  virtual const Type &get_geometry() const { return v_; } \
82  void set_geometry(const Type &v) { v_ = v; } \
83  virtual IMP::display::Geometries get_components() const IMP_OVERRIDE; \
84  IMP_OBJECT_METHODS(Name); \
85  }; \
86  inline Name *create_geometry( \
87  const Type &t, std::string name = std::string(#Type) + "%1%") { \
88  return new Name(t, name); \
89  } \
90  IMP_OBJECTS(Name, Names)
91 
92 #define IMP_DISPLAY_GEOMETRY_DECOMPOSABLE_DECL(Name, Names, Type) \
93  /** Display a compound geometric object.*/ \
94  class IMPDISPLAYEXPORT Name : public display::Geometry { \
95  Type v_; \
96  \
97  public: \
98  Name(std::string name); \
99  Name(const Type &v); \
100  Name(const Type &v, const display::Color &c); \
101  Name(const Type &v, const std::string n); \
102  Name(const Type &v, const display::Color &c, std::string n); \
103  virtual const Type &get_geometry() const { return v_; } \
104  void set_geometry(const Type &v) { v_ = v; } \
105  virtual IMP::display::Geometries get_components() const IMP_OVERRIDE; \
106  IMP_OBJECT_METHODS(Name); \
107  }; \
108  inline Name *create_geometry( \
109  const Type &t, std::string name = std::string(#Type) + "%1%") { \
110  return new Name(t, name); \
111  } \
112  IMP_OBJECTS(Name, Names)
113 #endif
114 
115 #define IMP_DISPLAY_GEOMETRY_DECOMPOSABLE_DEF(Name, Type, decomp) \
116  Name::Name(std::string name) : display::Geometry(name) {} \
117  Name::Name(const Type &v) : display::Geometry(#Name), v_(v) {} \
118  Name::Name(const Type &v, const display::Color &c) \
119  : display::Geometry(c, #Name), v_(v) {} \
120  Name::Name(const Type &v, const std::string n) \
121  : display::Geometry(n), v_(v) {} \
122  Name::Name(const Type &v, const display::Color &c, std::string n) \
123  : display::Geometry(c, n), v_(v) {} \
124  display::Geometries Name::get_components() const { \
125  display::Geometries ret; \
126  decomp; \
127  return ret; \
128  } \
129  IMP_REQUIRE_SEMICOLON_NAMESPACE
130 
131 #define IMP_PARTICLE_GEOMETRY(Name, Decorator, action) \
132  /** Display a particle.*/ \
133  class Name##Geometry : public display::SingletonGeometry { \
134  public: \
135  Name##Geometry(Particle *p) : display::SingletonGeometry(p) {} \
136  Name##Geometry(Decorator d) : display::SingletonGeometry(d) {} \
137  IMP_IMPLEMENT_INLINE(display::Geometries get_components() const, { \
138  display::Geometries ret; \
139  Decorator d(get_particle()); \
140  action; \
141  return ret; \
142  }); \
143  IMP_OBJECT_METHODS(Name##Geometry); \
144  }; \
145  /** Display multiple particles.*/ \
146  class Name##sGeometry : public display::SingletonsGeometry { \
147  public: \
148  Name##sGeometry(SingletonContainer *sc) \
149  : display::SingletonsGeometry(sc) {} \
150  display::Geometries get_components() const { \
151  display::Geometries ret; \
152  IMP_FOREACH(ParticleIndex pi, get_container()->get_contents()) { \
153  Decorator d(get_container()->get_model(), pi); \
154  action; \
155  } \
156  return ret; \
157  } \
158  IMP_OBJECT_METHODS(Name##sGeometry); \
159  }
160 
161 #define IMP_PARTICLE_PAIR_GEOMETRY(Name, Decorator, action) \
162  /** Display a pair of particles.*/ \
163  class Name##Geometry : public display::PairGeometry { \
164  public: \
165  Name##Geometry(const ParticlePair &pp) \
166  : display::PairGeometry(pp) {} \
167  display::Geometries get_components() const { \
168  display::Geometries ret; \
169  Decorator d0(get_particle_pair()[0]); \
170  Decorator d1(get_particle_pair()[1]); \
171  action; \
172  return ret; \
173  } \
174  IMP_OBJECT_METHODS(Name##Geometry); \
175  }; \
176  /** Display multiple pairs of particles.*/ \
177  class Name##sGeometry : public display::PairsGeometry { \
178  public: \
179  Name##sGeometry(PairContainer *sc) : display::PairsGeometry(sc) {} \
180  display::Geometries get_components() const { \
181  display::Geometries ret; \
182  IMP_FOREACH(ParticleIndexPair pip, \
183  get_container()->get_contents()) { \
184  Decorator d0(get_container()->get_model(), pip[0]); \
185  Decorator d1(get_container()->get_model(), pip[1]); \
186  action; \
187  } \
188  return ret; \
189  } \
190  IMP_OBJECT_METHODS(Name##sGeometry); \
191  }
192 
193 #endif /* IMPDISPLAY_GEOMETRY_MACROS_H */
Macros for various classes.
Macros for various classes.
Implement geometry for the basic shapes from IMP.algebra.