9 #ifndef IMPKINEMATICS_KINEMATIC_FOREST_H
10 #define IMPKINEMATICS_KINEMATIC_FOREST_H
12 #include "kinematics_config.h"
19 #include <boost/unordered_set.hpp>
28 IMPKINEMATICS_BEGIN_NAMESPACE
80 void add_edge(
Joint* joint);
89 for (
int i = 0; i < (int)rbs.size() - 1; i++) {
90 add_edge(rbs[i], rbs[i + 1]);
101 void update_all_internal_coordinates() {
102 IMP_LOG(
VERBOSE,
"updating internal coords needed?" << std::endl);
103 if (is_internal_coords_updated_) {
106 IMP_LOG(
VERBOSE,
"updating!" << std::endl);
107 for (
unsigned int i = 0; i < joints_.size(); i++) {
108 joints_[i]->update_joint_from_cartesian_witnesses();
110 is_internal_coords_updated_ =
true;
113 void update_all_external_coordinates() {
114 if (is_external_coords_updated_) {
118 std::queue<KinematicNode> q;
119 boost::unordered_set<KinematicNode>::iterator it;
120 for (it = roots_.begin(); it != roots_.end(); it++) {
124 KinematicNode n = q.front();
127 for (
unsigned int i = 0; i < out_joints.size(); i++) {
128 Joint* joint_i = out_joints[i];
130 joint_i->update_child_node_reference_frame();
131 q.push(KinematicNode(joint_i->get_child_node()));
134 is_external_coords_updated_ =
true;
141 std::queue<KinematicNode> q;
142 boost::unordered_set<KinematicNode>::iterator it;
143 for (it = roots_.begin(); it != roots_.end(); it++) q.push(*it);
148 if (n.get_in_joint() !=
nullptr) ret.push_back(n.get_in_joint());
151 for (
unsigned int i = 0; i < out_joints.size(); i++) {
152 Joint* joint_i = out_joints[i];
165 is_external_coords_updated_ =
false;
174 is_internal_coords_updated_ =
false;
187 "A KinematicForest can only handle particles "
188 <<
" that were previously added to it");
190 mark_external_coordinates_changed();
197 "A KinematicForest can only handle particles "
198 <<
" that were previously added to it");
200 return rb.get_coordinates();
207 return KinematicNode::get_is_setup(p) &&
208 nodes_.find(KinematicNode(p)) != nodes_.end();
218 "A KinematicForest can only handle particles "
219 <<
" that were previously added to it");
220 const_cast<KinematicForest*
>(
this)->update_all_external_coordinates();
235 "A KinematicForest can only handle particles "
236 <<
" that were previously added to it");
238 mark_external_coordinates_changed();
249 friend std::ostream& operator<<(std::ostream& s,
const KinematicForest& kt);
255 bool is_internal_coords_updated_;
256 bool is_external_coords_updated_;
260 boost::unordered_set<KinematicNode> roots_;
263 boost::unordered_set<KinematicNode> nodes_;
270 IMPKINEMATICS_END_NAMESPACE
The base class for decorators.
void mark_external_coordinates_changed()
void mark_internal_coordinates_changed()
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Storage of a model, its restraints, constraints and particles.
Exception definitions and assertions.
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
IMP::Vector< IMP::WeakPointer< Joint > > JointsTemp
void reset_root(IMP::Particle *new_root)
rebuild tree (same topology but change directionality)
Class for storing model, its restraints, constraints, and particles.
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.
Common base class for heavy weight IMP objects.
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
Particle * get_particle() const
Returns the particle decorated by this decorator.
Joints get_ordered_joints() const
return joints sorted by BFS traversal
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
A rigid body that is connected by a joint to other rigid bodies.
Joint * add_edge(IMP::core::RigidBody parent, IMP::core::RigidBody child)
Exception definitions and assertions.
Base class for joints between rigid bodies in a kinematic tree.
A shared base class to help in debugging and things.
Class to handle individual particles of a Model object.
#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.
Define and manipulate a kinematic structure over a model.
IMP::algebra::ReferenceFrame3D get_reference_frame() const