IMP  2.0.1
The Integrative Modeling Platform
rigid_body_geometries.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/rigid_body_geometries.h
3  * \brief functionality for defining rigid bodies
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_RIGID_BODY_GEOMETRIES_H
9 #define IMPCORE_RIGID_BODY_GEOMETRIES_H
10 
11 #include <IMP/core/core_config.h>
12 #include "rigid_bodies.h"
13 #include "internal/rigid_body_tree.h"
15 
16 IMPCORE_BEGIN_NAMESPACE
17 
18 
19 /** Show the collision detection hierarchy for a rigid body.*/
20 class IMPCOREEXPORT RigidBodyHierarchyGeometry:
22  Pointer<internal::RigidBodyHierarchy> h_;
23  unsigned int node_, layer_;
24  RigidBodyHierarchyGeometry(internal::RigidBodyHierarchy *h,
25  unsigned int node,
26  unsigned int layer);
27 public:
29  const ParticlesTemp &constituents);
32 };
33 
34 IMP_PARTICLE_GEOMETRY(RigidBodyDerivative, core::RigidBody, {
35  Particles ms=get_as<Particles>(d.get_members());
37  = d.get_reference_frame().get_transformation_to();
38  algebra::VectorD<4> rderiv= d.get_rotational_derivatives();
39  algebra::Vector3D tderiv= d.get_derivatives();
40  algebra::VectorD<4> rot = otr.get_rotation().get_quaternion();
41  IMP_LOG_TERSE( "Old rotation was " << rot << std::endl);
42  Float scale=.1;
43  algebra::VectorD<4> dv=rderiv;
44  if (dv.get_squared_magnitude() > 0.00001) {
45  dv= scale*dv.get_unit_vector();
46  }
47  rot+= dv;
48  rot= rot.get_unit_vector();
49  algebra::Rotation3D r(rot[0], rot[1], rot[2], rot[3]);
50  IMP_LOG_TERSE( "Derivative was " << tderiv << std::endl);
51  IMP_LOG_TERSE( "New rotation is " << rot << std::endl);
52  FloatRange xr= d.get_particle()->get_model()
53  ->get_range(core::XYZ::get_xyz_keys()[0]);
54  Float wid= xr.second-xr.first;
55  algebra::Vector3D stderiv= scale*tderiv*wid;
57  rot[2], rot[3]),
58  stderiv+otr.get_translation());
59  for (unsigned int i=0; i< ms.size(); ++i) {
60  core::RigidMember dm(ms[i]);
62  = new display::SegmentGeometry(algebra::Segment3D(dm.get_coordinates(),
63  dm.get_coordinates()+tderiv),
64  /*xyzcolor_*/
65  display::Color(1,0,0));
66  ret.push_back(tr);
67  algebra::Vector3D ic= r.get_rotated(dm.get_internal_coordinates())
68  + d.get_coordinates();
70  = new display::SegmentGeometry(algebra::Segment3D(dm.get_coordinates(),
71  ic),
72  display::Color(0,1,0));
73  ret.push_back(rtr);
75  = new display::SegmentGeometry(algebra::Segment3D(dm.get_coordinates(),
76  ntr.get_transformed(dm.get_internal_coordinates())),
77  display::Color(0,0,1));
78  ret.push_back(nrtr);
79  }
80  });
81 
82 IMP_PARTICLE_GEOMETRY(RigidBodyFrame, core::RigidBody, {
83  ret.push_back(new display::ReferenceFrameGeometry(d.get_reference_frame()));
84  });
85 
86 /** Display the torque on a rigid body as a line segment.*/
87 class IMPCOREEXPORT RigidBodyTorque: public display::SegmentGeometry {
89  mutable algebra::Segment3D cache_;
90  static algebra::Segment3D extract_geometry(Particle *p);
91 public:
93  const algebra::Segment3D &get_geometry() const;
94 };
95 
96 
97 IMPCORE_END_NAMESPACE
98 
99 #endif /* IMPCORE_RIGID_BODY_GEOMETRIES_H */