Go to the documentation of this file.00001 #ifndef OPENTISSUE_DYNAMICS_MBD_MBD_JOINT_INTERFACE_H
00002 #define OPENTISSUE_DYNAMICS_MBD_MBD_JOINT_INTERFACE_H
00003
00004
00005
00006
00007
00008
00009
00010 #include <OpenTissue/configuration.h>
00011
00012 namespace OpenTissue
00013 {
00014 namespace mbd
00015 {
00023 template< typename mbd_types >
00024 class JointInterface
00025 : public mbd_types::identifier_type
00026 , public mbd_types::constraint_type
00027 {
00028 public:
00029
00030 typedef typename mbd_types::socket_type socket_type;
00031
00032 protected:
00033
00034 socket_type * m_socketA;
00035 socket_type * m_socketB;
00036
00037 public:
00038
00039 JointInterface()
00040 : m_socketA(0)
00041 , m_socketB(0)
00042 {}
00043
00044 virtual ~JointInterface() { clear(); }
00045
00046 public:
00047
00048 socket_type * get_socket_A() { return m_socketA; }
00049 socket_type * get_socket_B() { return m_socketB; }
00050 socket_type const * get_socket_A() const { return m_socketA; }
00051 socket_type const * get_socket_B() const { return m_socketB; }
00052
00053 void connect( socket_type const & socketA, socket_type const & socketB )
00054 {
00055 assert(!this->m_bodyA || !"JointInterface::connect(): body A was non-null");
00056 assert(!this->m_bodyB || !"JointInterface::connect(): body B was non-null");
00057 assert(socketA.get_body() || !"JointInterface::connect(): body from socket A was null");
00058 assert(socketB.get_body() || !"JointInterface::connect(): body from socket B was null");
00059 assert(socketA.get_body()!=socketB.get_body() || !"JointInterface::connect(): bodies from sockets were the same");
00060
00061 m_socketA = const_cast<socket_type*>(&socketA);
00062 m_socketB = const_cast<socket_type*>(&socketB);
00063
00064 this->m_bodyA = m_socketA->get_body();
00065 this->m_bodyB = m_socketB->get_body();
00066
00067 this->m_bodyA->m_joints.push_back(this);
00068 this->m_bodyB->m_joints.push_back(this);
00069
00070 calibration();
00071 }
00072
00073 void disconnect()
00074 {
00075 if(this->m_bodyA)
00076 this->m_bodyA->m_joints.remove(this);
00077 if(this->m_bodyB)
00078 this->m_bodyB->m_joints.remove(this);
00079 m_socketA = 0;
00080 m_socketB = 0;
00081 this->m_bodyA = 0;
00082 this->m_bodyB = 0;
00083 }
00084
00093 virtual void calibration()=0;
00094
00095 void clear()
00096 {
00097 disconnect();
00098 }
00099
00100 };
00101
00102 }
00103 }
00104
00105 #endif