12 #ifndef IMPKINEMATICS_KINEMATIC_FOREST_H
13 #define IMPKINEMATICS_KINEMATIC_FOREST_H
15 #include "kinematics_config.h"
22 #include <boost/unordered_set.hpp>
31 IMPKINEMATICS_BEGIN_NAMESPACE
84 void add_edge(
Joint* joint);
93 for (
int i = 0; i < (int)rbs.size() - 1; i++) {
94 add_edge(rbs[i], rbs[i + 1]);
105 void update_all_internal_coordinates() {
106 IMP_LOG(
VERBOSE,
"updating internal coords needed?" << std::endl);
107 if (is_internal_coords_updated_) {
110 IMP_LOG(
VERBOSE,
"updating!" << std::endl);
111 for (
unsigned int i = 0; i < joints_.size(); i++) {
112 joints_[i]->update_joint_from_cartesian_witnesses();
114 is_internal_coords_updated_ =
true;
117 void update_all_external_coordinates() {
118 if (is_external_coords_updated_) {
122 std::queue<KinematicNode> q;
123 boost::unordered_set<KinematicNode>::iterator it;
124 for (it = roots_.begin(); it != roots_.end(); it++) {
128 KinematicNode n = q.front();
131 for (
unsigned int i = 0; i < out_joints.size(); i++) {
132 Joint* joint_i = out_joints[i];
134 joint_i->update_child_node_reference_frame();
135 q.push(KinematicNode(joint_i->get_child_node()));
138 is_external_coords_updated_ =
true;
142 Joints get_ordered_joints()
const {
145 std::queue<KinematicNode> q;
146 boost::unordered_set<KinematicNode>::iterator it;
147 for (it = roots_.begin(); it != roots_.end(); it++) q.push(*it);
150 KinematicNode n = q.front();
152 if (n.get_in_joint() !=
nullptr) ret.push_back(n.get_in_joint());
155 for (
unsigned int i = 0; i < out_joints.size(); i++) {
156 Joint* joint_i = out_joints[i];
157 q.push(KinematicNode(joint_i->get_child_node()));
169 is_external_coords_updated_ =
false;
178 is_internal_coords_updated_ =
false;
191 "A KinematicForest can only handle particles "
192 <<
" that were previously added to it");
194 mark_external_coordinates_changed();
201 "A KinematicForest can only handle particles "
202 <<
" that were previously added to it");
204 return rb.get_coordinates();
211 return KinematicNode::get_is_setup(p) &&
212 nodes_.find(KinematicNode(p)) != nodes_.end();
222 "A KinematicForest can only handle particles "
223 <<
" that were previously added to it");
224 const_cast<KinematicForest*
>(
this)->update_all_external_coordinates();
239 "A KinematicForest can only handle particles "
240 <<
" that were previously added to it");
242 mark_external_coordinates_changed();
253 friend std::ostream& operator<<(std::ostream& s,
const KinematicForest& kt);
259 bool is_internal_coords_updated_;
260 bool is_external_coords_updated_;
264 boost::unordered_set<KinematicNode> roots_;
267 boost::unordered_set<KinematicNode> nodes_;
274 IMPKINEMATICS_END_NAMESPACE
Import IMP/kernel/Decorator.h in the namespace.
void mark_external_coordinates_changed()
IMP::base::Vector< IMP::base::WeakPointer< Joint > > JointsTemp
Particle * get_particle() const
Returns the particle decorated by this decorator.
void mark_internal_coordinates_changed()
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Exception definitions and assertions.
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Decorator for helping deal with a hierarchy of molecules.
void set_reference_frame_safe(IMP::core::RigidBody rb, IMP::algebra::ReferenceFrame3D r)
void add_rigid_bodies_in_chain(IMP::core::RigidBodies rbs)
functionality for defining a kinematic joint between rigid bodies as part of a kinematic tree ...
The standard decorator for manipulating molecular structures.
void set_reference_frame(const IMP::algebra::ReferenceFrame3D &tr)
Set the current reference frame.
Various general useful macros for IMP.
#define IMP_UNUSED(variable)
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
void set_coordinates_safe(IMP::core::RigidBody rb, IMP::algebra::Vector3D c)
functionality for defining nodes on a kinematic chain
Class to handle individual model particles.
IMP::base::Vector< IMP::base::Pointer< Joint > > Joints
Storage of a model, its restraints, constraints and particles.
Common base class for heavy weight IMP objects.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Joint * add_edge(IMP::core::RigidBody parent, IMP::core::RigidBody child)
Exception definitions and assertions.
A shared base class to help in debugging and things.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
#define IMP_NOT_IMPLEMENTED
Use this to mark that the method is not implemented yet.
A decorator for a rigid body.
Class for storing model, its restraints, constraints, and particles.
IMP::algebra::ReferenceFrame3D get_reference_frame() const
Get the reference frame for the local coordinates.