IMP  2.1.1
The Integrative Modeling Platform
KinematicNode.h
Go to the documentation of this file.
1 /**
2  * \file KinematicNode.h
3  * \brief functionality for defining nodes on a kinematic chain
4  * \authors Dina Schneidman, Barak Raveh
5  *
6  * Copyright 2007-2012 IMP Inventors. All rights reserved.
7  */
8 
9 #ifndef IMPKINEMATICS_KINEMATIC_NODE_H
10 #define IMPKINEMATICS_KINEMATIC_NODE_H
11 
12 #include "kinematics_config.h"
13 #include <IMP/core/rigid_bodies.h>
14 #include <IMP/kinematics/Joint.h>
15 
16 #include <IMP/base/exception.h>
17 
18 IMPKINEMATICS_BEGIN_NAMESPACE
19 
20 class KinematicForest;
21 
22 // TODO: check for cycles
23 // TODO: privatize most methods INCLUDING constructor
24 
25 /**
26  A KinematicNode is a rigid body that is connected by a joint to other
27  rigid bodies
28 */
29 class IMPKINEMATICSEXPORT KinematicNode : public IMP::core::RigidBody{
30  friend class KinematicForest;
31 
32  static void do_setup_particle( kernel::Model *m,
34  KinematicForest* owner,
35  Joint* in_joint = nullptr,
36  Joints out_joints = Joints() );
37  public:
41  Joint*, in_joint);
43  Joint*, in_joint, Joints, out_joints);
44 
45  /**
46  @brief Return true if the particle is a kinematic nodea (has the
47  appropriate properties).
48  */
49  inline static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi);
50 
51  private:
52 
53  //! returns the kinematic forest associated with this node
54  KinematicForest* get_owner();
55 
56  //! return nullptr if does not have incoming joint
57  inline Joint* get_in_joint();
58 
59  //! returns list of outcoming joints
60  inline JointsTemp get_out_joints();
61 
62  void set_out_joints(Joints in);
63 
64  void add_out_joint(Joint* j);
65 
66  void set_in_joint(Joint* j);
67 
68  static ObjectKey get_owner_key()
69  {
70  static ObjectKey k("kinematics__kinematic_node_owner");
71  return k;
72  }
73 
74  static ObjectKey get_in_joint_key()
75  {
76  static ObjectKey k("kinematics__kinematic_node_in_joint");
77  return k;
78  }
79 
80  static ObjectsKey get_out_joints_key()
81  {
82  static ObjectsKey k("kinematics__kinematic_node_out_joint");
83  return k;
84  }
85 
86 };
87 
88 /************** inlines ***********/
89 
90 bool
91 KinematicNode::get_is_setup(kernel::Model *m,
93 {
94  return
95  m->get_has_attribute( get_owner_key(), pi);
96 }
97 
98 
99 //! return nullptr if does not have incoming joint
100 Joint*
101 KinematicNode::get_in_joint() {
102  if( !get_model()->get_has_attribute
103  ( get_in_joint_key(), get_particle_index() ) )
104  {
105  return nullptr;
106  }
107  base::Object* obj = get_model()->get_attribute
108  ( get_in_joint_key(), get_particle_index() );
109  return static_cast<Joint*>(obj);
110 }
111 
112 //! returns list of outcoming joints, or empty list if attribute
113 //! does not exist
115 KinematicNode::get_out_joints() {
116  JointsTemp joints;
117  if(! get_model()->get_has_attribute
118  ( get_out_joints_key(), get_particle_index() ) ) {
119  return joints;
120  }
121  base::Objects objs = get_model()->get_attribute
122  ( get_out_joints_key(), get_particle_index() );
123  for(unsigned int i = 0; i < objs.size(); i++){
124  base::Object * o = objs[i];
125  Joint* j = static_cast<Joint*>(o);
126  joints.push_back(j);
127  }
128  return joints;
129 }
130 
131 
132 //IMP_DECORATORS_DEF(KinematicNode, KinematicNodes);
133 IMP_DECORATORS(KinematicNode, KinematicNodes, IMP::core::RigidBody);
134 
135 IMPKINEMATICS_END_NAMESPACE
136 
137 #endif /* IMPKINEMATICS_KINEMATIC_NODE_H */
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name)
A base class for Keys.
Definition: kernel/Key.h:46
IMP::base::Vector< IMP::base::Pointer< Object > > Objects
A list of objects.
Definition: base/types.h:61
IMP::base::Vector< IMP::base::WeakPointer< Joint > > JointsTemp
Definition: Joint.h:145
#define IMP_DECORATOR_METHODS(Name, Parent)
functionality for defining a kinematic joint between rigid bodies as part of a kinematic tree ...
functionality for defining rigid bodies
Key< 7, true > ObjectsKey
The type used to identify a particle attribute in the Particles.
IMP::base::Vector< IMP::base::Pointer< Joint > > Joints
Definition: Joint.h:145
Common base class for heavy weight IMP objects.
Exception definitions and assertions.
#define IMP_DECORATOR_SETUP_3(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name,ThirdArgumentType, third_argument_name)
A decorator for a rigid body.
Definition: rigid_bodies.h:75
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Class for storing model, its restraints, constraints, and particles.