IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
Surface.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/Surface.h \brief Simple surface decorator.
3  *
4  * Copyright 2007-2017 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPCORE_SURFACE_H
9 #define IMPCORE_SURFACE_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/core/XYZ.h>
13 #include <IMP/core/XYZR.h>
15 #include <IMP/algebra/Plane3D.h>
17 #include <IMP/algebra/Segment3D.h>
18 #include <IMP/algebra/Cylinder3D.h>
19 #include <IMP/Constraint.h>
20 #include <IMP/decorator_macros.h>
21 #include <IMP/Decorator.h>
22 #include <IMP/Particle.h>
23 #include <IMP/Object.h>
24 #include <IMP/Model.h>
25 #include <IMP/Pointer.h>
26 
27 
28 IMPCORE_BEGIN_NAMESPACE
29 
30 //! A decorator for a particle that represents a surface, its coordinates, and orientation.
31 /** \ingroup decorators
32 */
33 class IMPCOREEXPORT Surface : public XYZ {
34  public:
35  static void do_setup_particle(Model *m, ParticleIndex pi,
36  const algebra::Vector3D &center = algebra::Vector3D(0, 0, 0),
37  const algebra::Vector3D &normal = algebra::Vector3D(0, 0, 1));
38 
39  static void do_setup_particle(Model *m, ParticleIndex pi,
40  const algebra::ReferenceFrame3D &rf);
41 
44  //! Set up the surface to align with the reference frame.
48  IMP_DECORATOR_GET_SET(normal_x, get_normal_key(0), Float, Float);
49  IMP_DECORATOR_GET_SET(normal_y, get_normal_key(1), Float, Float);
50  IMP_DECORATOR_GET_SET(normal_z, get_normal_key(2), Float, Float);
51 
52  //! Check if particle is setup as a surface.
53  static bool get_is_setup(Model *m, ParticleIndex pi);
54 
55  static FloatKey get_normal_key(unsigned int i);
56 
57  //! Get the vector of derivatives added to the surface normal.
59  return get_particle()->get_derivative(get_normal_key(i));
60  }
61 
62  //! Get the vector of derivatives added to the surface normal.
63  algebra::Vector3D get_normal_derivatives() const;
64 
65  //! Add v to the derivative of the ith coordinate of the normal.
67  get_particle()->add_to_derivative(get_normal_key(i), v, d);
68  }
69 
70  //! Add v to the derivatives of the x,y,z coordinates of the normal.
71  void add_to_normal_derivatives(const algebra::Vector3D &v,
73 
74  //! Get whether surface normal is optimized.
75  bool get_normal_is_optimized() const;
76 
77  //! Set whether surface normal is optimized.
78  void set_normal_is_optimized(bool tf) const;
79 
80  //! Get unit vector normal to surface.
81  algebra::Vector3D get_normal() const;
82 
83  //! Set surface normal.
84  void set_normal(const algebra::Vector3D &normal);
85 
86  //! Flip surface so normal is reversed.
87  void reflect() { set_normal(-get_normal()); }
88 
89  //! Get height of point above surface.
90  /** \note If point is below surface, value is negative. */
91  double get_height(const algebra::Vector3D &v) const;
92 
93  //! Get depth of point below surface.
94  /** \note If point is above surface, value is negative. */
95  double get_depth(const algebra::Vector3D &v) const;
96 
97  //! Get distance from point to surface.
98  double get_distance_to(const algebra::Vector3D &v) const;
99 
100  //! Get distance from point to center of surface.
101  double get_distance_to_center(const algebra::Vector3D &v) const;
102 
103  //! Set coordinates and normal from a reference frame.
107  set_coordinates(c);
108  set_normal(n);
109  }
110 
111  //! Get surface orientation as a reference frame.
112  algebra::ReferenceFrame3D get_reference_frame() const;
113 
114  //! Get a plane that lies along the surface.
116  return algebra::Plane3D(get_coordinates(), get_normal());
117  }
118 };
119 
120 IMP_DECORATORS(Surface, Surfaces, XYZs);
121 
122 //! Get height of sphere above surface.
123 /** \note If sphere crosses or is below surface, height is
124  negative the distance from the surface to the furthest point
125  of the sphere.
126 */
127 inline double get_height(const Surface &s, const XYZR &d) {
128  return s.get_height(d.get_coordinates()) - d.get_radius();
129 }
130 
131 //! Get height of point above surface.
132 inline double get_height(const Surface &s, const XYZ &d) {
133  return s.get_height(d.get_coordinates());
134 }
135 
136 //! Get depth of sphere below surface.
137 /** \note If sphere crosses or is above surface, depth is
138  negative the distance from the surface to the furthest point
139  of the sphere.
140 */
141 inline double get_depth(const Surface &s, const XYZR &d) {
142  return s.get_depth(d.get_coordinates()) - d.get_radius();
143 }
144 
145 //! Get depth of point below surface.
146 inline double get_depth(const Surface &s, const XYZ &d) {
147  return s.get_depth(d.get_coordinates());
148 }
149 
150 //! Get distance from sphere to surface.
151 inline double get_distance(const Surface &s, const XYZR &d) {
152  return s.get_distance_to(d.get_coordinates()) - d.get_radius();
153 }
154 
155 //! Get distance from point to surface.
156 inline double get_distance(const Surface &s, const XYZ &d) {
157  return s.get_distance_to(d.get_coordinates());
158 }
159 
160 /** \class SurfaceGeometry
161  \brief Display a Surface particle as a cylindrical disk.
162 
163  \class SurfacesGeometry
164  \brief Display an IMP::SingletonContainer of Surface particles
165  as cylindrical disks.
166 */
167 class IMPCOREEXPORT SurfaceGeometry : public display::Geometry {
168  Surface s_;
171 
172  //! Get disk aligned with surface plane for geometry.
173  algebra::Cylinder3D get_cylinder(double radius=10.0,
174  double thick=0.1) const;
175 
176  //! Get line segment along surface normal for geometry.
177  algebra::Segment3D get_segment(double length=5.0) const;
178 
179  public:
180  SurfaceGeometry(std::string n="SurfaceGeometry");
181  SurfaceGeometry(Surface s, const std::string n="SurfaceGeometry");
182  SurfaceGeometry(Surface s, const display::Color &c, std::string n="SurfaceGeometry");
183  virtual const Surface get_geometry() const { return s_; }
184  void set_geometry(Surface s);
187 };
188 //! Create a geometry from a Surface
190  const Surface s, std::string name = std::string("SurfaceGeometry%1%")) {
191  IMP_NEW(SurfaceGeometry, g, (s, name));
192  return g.release();
193 }
195 
196 //! Constrain a SurfaceGeometry to a Surface.
197 /** \note Use IMP.core.get_constrained_surface_geometry to create.
198 */
199 class IMPCOREEXPORT SurfaceGeometryConstraint : public IMP::Constraint {
200  ParticleIndex pi_;
202 
203  public:
205  : IMP::Constraint(s.get_model(), "SurfaceGeometryConstraint%1%")
206  , pi_(s.get_particle_index()), g_(g) {}
207 
208  Surface get_surface() const { return Surface(get_model(), pi_); }
209 
210  SurfaceGeometry* get_geometry() const { return g_; }
211 
212  virtual void do_update_attributes() IMP_OVERRIDE {};
213  virtual void do_update_derivatives(DerivativeAccumulator *) IMP_OVERRIDE {};
214  virtual void do_before_evaluate() IMP_OVERRIDE { g_->set_geometry(get_surface());}
215  virtual void do_after_evaluate(DerivativeAccumulator *) IMP_OVERRIDE {
216  g_->set_geometry(get_surface());
217  };
218 
219 
221  ParticlesTemp ps = ParticlesTemp(1, get_surface().get_particle());
222  return ps;
223  }
224 
226  ParticlesTemp ps = ParticlesTemp(1, get_surface().get_particle());
227  return ps;
228  }
229 
231 };
232 
233 //! Get surface geometry constrained to the surface.
235  const Surface s, std::string name="SurfaceGeometry%1%") {
236  IMP_NEW(SurfaceGeometry, g, (s, name));
238  s.get_model()->add_score_state(c.release());
239  return g.release();
240 }
242 
243 //! Constrain the center of a Surface for visualization.
244 /** The Surface center can wander laterally. This constraint ensures
245  the center is placed in the Surface such that it is along the
246  normal from a point.
247 */
248 class IMPCOREEXPORT LateralSurfaceConstraint : public IMP::Constraint {
249  ParticleIndex spi_;
250  ParticleIndex dpi_;
251 
252  public:
254  : IMP::Constraint(s.get_model(), "LateralSurfaceConstraint%1%")
255  , spi_(s.get_particle_index()), dpi_(d.get_particle_index()) {}
256 
257  virtual void do_update_attributes() IMP_OVERRIDE {}
258  virtual void do_update_derivatives(DerivativeAccumulator *) IMP_OVERRIDE {}
259  virtual void do_before_evaluate() IMP_OVERRIDE {
260  algebra::Vector3D d = XYZ(get_model(), dpi_).get_coordinates();
261  Surface s = Surface(get_model(), spi_);
263  }
264  virtual void do_after_evaluate(DerivativeAccumulator *) IMP_OVERRIDE {}
265 
267  ParticlesTemp ps;
268  ps.push_back(get_model()->get_particle(dpi_));
269  ps.push_back(get_model()->get_particle(spi_));
270  return ps;
271  }
272 
274  ParticlesTemp ps = ParticlesTemp(1, get_model()->get_particle(spi_));
275  return ps;
276  }
277 
279 };
280 
281 IMPCORE_END_NAMESPACE
282 
283 #endif /* IMPCORE_SURFACE_H */
The base class for decorators.
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
double get_height(const Surface &s, const XYZR &d)
Get height of sphere above surface.
Definition: Surface.h:127
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:188
double get_height(const algebra::Vector3D &v) const
Get height of point above surface.
Represent an RGB color.
Definition: Color.h:24
double get_depth(const Surface &s, const XYZ &d)
Get depth of point below surface.
Definition: Surface.h:146
Float get_normal_derivative(int i) const
Get the vector of derivatives added to the surface normal.
Definition: Surface.h:58
Represent a cylinder in 3D.
The base class for geometry.
virtual ModelObjectsTemp do_get_outputs() const
Definition: Surface.h:225
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Constrain a SurfaceGeometry to a Surface.
Definition: Surface.h:199
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:191
Storage of a model, its restraints, constraints and particles.
algebra::Plane3D get_plane() const
Get a plane that lies along the surface.
Definition: Surface.h:115
Display a Surface particle as a cylindrical disk.
Definition: Surface.h:167
Represent a cylinder in 3D.
Definition: Cylinder3D.h:26
Constrain the center of a Surface for visualization.
Definition: Surface.h:248
void add_to_normal_derivative(int i, Float v, DerivativeAccumulator &d)
Add v to the derivative of the ith coordinate of the normal.
Definition: Surface.h:66
double get_depth(const algebra::Vector3D &v) const
Get depth of point below surface.
Simple XYZ decorator.
A reference frame in 3D.
Simple implementation of segments in 3D.
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Definition: object_macros.h:64
Implement a constraint on the Model.
Definition: Constraint.h:49
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Implement geometry for the basic shapes from IMP.algebra.
virtual ModelObjectsTemp do_get_outputs() const
Definition: Surface.h:273
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:62
void set_reference_frame(const algebra::ReferenceFrame3D &rf)
Set coordinates and normal from a reference frame.
Definition: Surface.h:104
double get_height(const Surface &s, const XYZ &d)
Get height of point above surface.
Definition: Surface.h:132
SurfaceGeometry * create_geometry(const Surface s, std::string name=std::string("SurfaceGeometry%1%"))
Create a geometry from a Surface.
Definition: Surface.h:189
Various general useful macros for IMP.
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name)
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
#define IMP_DECORATOR_SETUP_0(Name)
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:109
A base class for constraints.
A decorator for a particle that represents a surface, its coordinates, and orientation.
Definition: Surface.h:33
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:171
virtual ModelObjectsTemp do_get_inputs() const
Definition: Surface.h:266
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
double get_distance_to(const algebra::Vector3D &v) const
Get distance from point to surface.
Simple implementation of segments in 3D.
Definition: Segment3D.h:24
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
Definition: object_macros.h:44
A nullptr-initialized pointer to an IMP Object.
SurfaceGeometry * get_constrained_surface_geometry(const Surface s, std::string name="SurfaceGeometry%1%")
Get surface geometry constrained to the surface.
Definition: Surface.h:234
Simple 3D plane class.
virtual Geometries get_components() const
Return a set of geometry composing this one.
A shared base class to help in debugging and things.
virtual ModelObjectsTemp do_get_inputs() const
Definition: Surface.h:220
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
void reflect()
Flip surface so normal is reversed.
Definition: Surface.h:87
double get_depth(const Surface &s, const XYZR &d)
Get depth of sphere below surface.
Definition: Surface.h:141
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Vector3D get_projected(const Vector3D &p) const
Project the point onto the plane.
Definition: Plane3D.h:37
double get_distance(const Surface &s, const XYZ &d)
Get distance from point to surface.
Definition: Surface.h:156
A reference frame in 3D.
Vector3D get_global_coordinates(const Vector3D &v) const
Represent a plane in 3D.
Definition: Plane3D.h:20
Decorator for a sphere-like particle.
DensityMap * get_segment(DensityMap *map_to_segment, int nx_start, int nx_end, int ny_start, int ny_end, int nz_start, int nz_end)
Get a segment of the map according to xyz indexes.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27