00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPDISPLAY_PARTICLE_GEOMETRY_H
00009 #define IMPDISPLAY_PARTICLE_GEOMETRY_H
00010
00011 #include "display_config.h"
00012 #include "display_macros.h"
00013 #include "Colored.h"
00014 #include <IMP/SingletonContainer.h>
00015 #include <IMP/PairContainer.h>
00016 #include <IMP/core/XYZR.h>
00017 #include <IMP/atom/bond_decorators.h>
00018 #include <IMP/display/geometry.h>
00019 #include <IMP/core/rigid_bodies.h>
00020 #include <IMP/SingletonScore.h>
00021
00022 IMPDISPLAY_BEGIN_NAMESPACE
00023
00024
00025
00026 class IMPDISPLAYEXPORT SingletonGeometry: public Geometry
00027 {
00028 IMP::Pointer<Particle> p_;
00029 public:
00030 SingletonGeometry(Particle *p);
00031
00032 bool get_has_color() const {
00033 return Colored::particle_is_instance(p_);
00034 }
00035
00036 Color get_color() const {
00037 return Colored(p_).get_color();
00038 }
00039
00040 Particle *get_particle() const {
00041 return p_;
00042 }
00043
00044 virtual ~SingletonGeometry(){}
00045 };
00046
00047
00048
00049
00050
00051 class IMPDISPLAYEXPORT SingletonsGeometry: public Geometry
00052 {
00053 IMP::internal::OwnerPointer<SingletonContainer> sc_;
00054 public:
00055 SingletonsGeometry(SingletonContainer *pc, Color c);
00056 SingletonsGeometry(SingletonContainer *pc);
00057
00058 SingletonContainer *get_container() const {
00059 return sc_;
00060 }
00061
00062 virtual ~SingletonsGeometry(){}
00063 };
00064
00065
00066
00067
00068 class IMPDISPLAYEXPORT PairGeometry: public Geometry
00069 {
00070 IMP::Pointer<Particle> p0_, p1_;
00071 public:
00072 PairGeometry(Particle *p0, Particle *p1);
00073
00074 bool get_has_color() const {
00075 return Colored::particle_is_instance(p0_)
00076 || Colored::particle_is_instance(p1_);
00077 }
00078
00079 Color get_color() const {
00080 if (Colored::particle_is_instance(p0_))
00081 return Colored(p0_).get_color();
00082 else return Colored(p1_).get_color();
00083 }
00084
00085 ParticlePair get_particle_pair() const {
00086 return ParticlePair(p0_, p1_);
00087 }
00088
00089 virtual ~PairGeometry(){}
00090 };
00091
00092
00093
00094
00095
00096 class IMPDISPLAYEXPORT PairsGeometry: public Geometry
00097 {
00098 IMP::internal::OwnerPointer<PairContainer> sc_;
00099 public:
00100 PairsGeometry(PairContainer *pc, Color c);
00101 PairsGeometry(PairContainer *pc);
00102
00103 PairContainer *get_container() const {
00104 return sc_;
00105 }
00106
00107 virtual ~PairsGeometry(){}
00108 };
00109
00110
00111
00112 IMP_PARTICLE_TRAITS_GEOMETRY(XYZR, core::XYZR,FloatKey, radius_key,
00113 {
00114 Geometry *g= new SphereGeometry(d.get_sphere());
00115 ret.push_back(g);
00116 });
00117
00118 IMP_PARTICLE_GEOMETRY(Bond, atom::Bond,{
00119 atom::Bonded ep0= d.get_bonded(0);
00120 core::XYZ epi0(ep0.get_particle());
00121 atom::Bonded ep1= d.get_bonded(1);
00122 core::XYZ epi1(ep1.get_particle());
00123 algebra::Segment3D s(epi0.get_coordinates(),
00124 epi1.get_coordinates());
00125 Geometry *g= new SegmentGeometry(s);
00126 ret.push_back(g);
00127 });
00128
00129
00130 IMP_PARTICLE_GEOMETRY(XYZDerivative, core::XYZ, {
00131 algebra::Segment3D s(d.get_coordinates(),
00132 d.get_coordinates()+d.get_derivatives());
00133 Geometry *g= new SegmentGeometry(s);
00134 ret.push_back(g);
00135 });
00136
00137 IMP_PARTICLE_GEOMETRY(RigidBodyDerivative, core::RigidBody, {
00138 Particles ms=d.get_members();
00139 algebra::Transformation3D otr= d.get_transformation();
00140 algebra::VectorD<4> rderiv= d.get_rotational_derivatives();
00141 algebra::VectorD<3> tderiv= d.get_derivatives();
00142 algebra::VectorD<4> rot = otr.get_rotation().get_quaternion();
00143 IMP_LOG(TERSE, "Old rotation was " << rot << std::endl);
00144 Float scale=.1;
00145 algebra::VectorD<4> dv=rderiv;
00146 if (dv.get_squared_magnitude() != 0) {
00147 dv= scale*dv.get_unit_vector();
00148 }
00149 rot+= dv;
00150 rot= rot.get_unit_vector();
00151 algebra::Rotation3D r(rot[0], rot[1], rot[2], rot[3]);
00152 IMP_LOG(TERSE, "Derivative was " << tderiv << std::endl);
00153 IMP_LOG(TERSE, "New rotation is " << rot << std::endl);
00154 FloatRange xr= d.get_particle()->get_model()
00155 ->get_range(core::XYZ::get_xyz_keys()[0]);
00156 Float wid= xr.second-xr.first;
00157 algebra::VectorD<3> stderiv= scale*tderiv*wid;
00158 algebra::Transformation3D ntr(algebra::Rotation3D(rot[0], rot[1],
00159 rot[2], rot[3]),
00160 stderiv+otr.get_translation());
00161 for (unsigned int i=0; i< ms.size(); ++i) {
00162 core::RigidMember dm(ms[i]);
00163 SegmentGeometry *tr
00164 = new SegmentGeometry(algebra::Segment3D(dm.get_coordinates(),
00165 dm.get_coordinates()+tderiv),
00166
00167 Color(1,0,0));
00168 ret.push_back(tr);
00169 algebra::VectorD<3> ic= r.get_rotated(dm.get_internal_coordinates())
00170 + d.get_coordinates();
00171 SegmentGeometry *rtr
00172 = new SegmentGeometry(algebra::Segment3D(dm.get_coordinates(),
00173 ic),
00174 Color(0,1,0));
00175 ret.push_back(rtr);
00176 SegmentGeometry *nrtr
00177 = new SegmentGeometry(algebra::Segment3D(dm.get_coordinates(),
00178 ntr.get_transformed(dm.get_internal_coordinates())),
00179 Color(0,0,1));
00180 ret.push_back(nrtr);
00181 }
00182 });
00183
00184 IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
00185 ret.push_back(
00186 new SegmentGeometry(algebra::Segment3D(d0.get_coordinates(),
00187 d1.get_coordinates())));
00188 });
00189
00190 IMPDISPLAY_END_NAMESPACE
00191
00192 #endif