IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/21
The Integrative Modeling Platform
KinematicNode.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kinematics/KinematicNode.h
3  * \brief functionality for defining nodes on a kinematic chain
4  * \authors Dina Schneidman, Barak Raveh
5  *
6  * Copyright 2007-2022 IMP Inventors. All rights reserved.
7  */
8 
9 #ifndef IMPKINEMATICS_KINEMATIC_NODE_H
10 #define IMPKINEMATICS_KINEMATIC_NODE_H
11 
12 #include <IMP/kinematics/kinematics_config.h>
13 #include <IMP/core/rigid_bodies.h>
14 #include <IMP/kinematics/Joint.h>
15 
16 #include <IMP/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 //! A rigid body that is connected by a joint to other rigid bodies
26 class IMPKINEMATICSEXPORT KinematicNode : public IMP::core::RigidBody {
27  friend class KinematicForest;
28 
29  static void do_setup_particle(Model* m, ParticleIndex p,
30  KinematicForest* owner,
31  Joint* in_joint = nullptr,
32  Joints out_joints = Joints());
33 
34  public:
38  in_joint);
40  in_joint, Joints, out_joints);
41 
42  //! Return true if the particle is a kinematic node
43  inline static bool get_is_setup(Model* m, ParticleIndex pi);
44 
45  private:
46  //! returns the kinematic forest associated with this node
47  KinematicForest* get_owner();
48 
49  //! return nullptr if does not have incoming joint
50  inline Joint* get_in_joint();
51 
52  //! returns list of outcoming joints
53  inline JointsTemp get_out_joints();
54 
55  void set_out_joints(Joints in);
56 
57  void add_out_joint(Joint* j);
58 
59  void set_in_joint(Joint* j);
60 
61  static ObjectKey get_owner_key() {
62  static ObjectKey k("kinematics__kinematic_node_owner");
63  return k;
64  }
65 
66  static ObjectKey get_in_joint_key() {
67  static ObjectKey k("kinematics__kinematic_node_in_joint");
68  return k;
69  }
70 
71  static ObjectsKey get_out_joints_key() {
72  static ObjectsKey k("kinematics__kinematic_node_out_joint");
73  return k;
74  }
75 };
76 
77 /************** inlines ***********/
78 
79 bool KinematicNode::get_is_setup(Model* m, ParticleIndex pi) {
80  return m->get_has_attribute(get_owner_key(), pi);
81 }
82 
83 //! return nullptr if does not have incoming joint
84 Joint* KinematicNode::get_in_joint() {
85  if (!get_model()->get_has_attribute(get_in_joint_key(),
86  get_particle_index())) {
87  return nullptr;
88  }
89  Object* obj =
90  get_model()->get_attribute(get_in_joint_key(), get_particle_index());
91  return static_cast<Joint*>(obj);
92 }
93 
94 //! returns list of outcoming joints, or empty list if attribute
95 //! does not exist
96 JointsTemp KinematicNode::get_out_joints() {
97  JointsTemp joints;
98  if (!get_model()->get_has_attribute(get_out_joints_key(),
99  get_particle_index())) {
100  return joints;
101  }
102  Objects objs =
103  get_model()->get_attribute(get_out_joints_key(), get_particle_index());
104  for (unsigned int i = 0; i < objs.size(); i++) {
105  Object* o = objs[i];
106  Joint* j = static_cast<Joint*>(o);
107  joints.push_back(j);
108  }
109  return joints;
110 }
111 
112 // IMP_DECORATORS_DEF(KinematicNode, KinematicNodes);
113 IMP_DECORATORS(KinematicNode, KinematicNodes, IMP::core::RigidBody);
114 
115 IMPKINEMATICS_END_NAMESPACE
116 
117 #endif /* IMPKINEMATICS_KINEMATIC_NODE_H */
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
Exception definitions and assertions.
IMP::Vector< IMP::WeakPointer< Joint > > JointsTemp
Definition: Joint.h:125
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
functionality for defining a kinematic joint between rigid bodies as part of a kinematic tree ...
Common base class for heavy weight IMP objects.
Definition: Object.h:111
functionality for defining rigid bodies
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name)
IMP::Vector< IMP::Pointer< Joint > > Joints
Definition: Joint.h:125
IMP::Vector< IMP::Pointer< Object > > Objects
A list of objects.
Definition: types.h:59
A rigid body that is connected by a joint to other rigid bodies.
Definition: KinematicNode.h:26
Base class for joints between rigid bodies in a kinematic tree.
Definition: Joint.h:29
#define IMP_DECORATOR_METHODS(Name, Parent)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
A decorator for a rigid body.
Definition: rigid_bodies.h:82
#define IMP_DECORATOR_SETUP_3(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name,ThirdArgumentType, third_argument_name)
Define and manipulate a kinematic structure over a model.