00001 #ifndef OPENTISSUE_KINEMATICS_SKELETON_BONE_H 00002 #define OPENTISSUE_KINEMATICS_SKELETON_BONE_H 00003 // 00004 // OpenTissue Template Library 00005 // - A generic toolbox for physics-based modeling and simulation. 00006 // Copyright (C) 2008 Department of Computer Science, University of Copenhagen. 00007 // 00008 // OTTL is licensed under zlib: http://opensource.org/licenses/zlib-license.php 00009 // 00010 #include <OpenTissue/configuration.h> 00011 00012 #include <boost/iterator/indirect_iterator.hpp> 00013 00014 #include <list> 00015 #include <cassert> 00016 00017 namespace OpenTissue 00018 { 00019 namespace skeleton 00020 { 00021 00032 template<typename types> 00033 class Bone 00034 : public types::bone_traits 00035 { 00036 public: 00037 00038 friend class BoneAccess; 00039 00040 public: 00041 00042 typedef typename types::math_types math_types; 00043 typedef typename types::bone_traits bone_traits; 00044 typedef typename bone_traits::transform_type transform_type; 00045 00046 protected: 00047 00048 typedef typename math_types::value_traits value_traits; 00049 typedef typename types::math_types::coordsys_type coordsys_type; 00050 typedef typename types::math_types::real_type real_type; 00051 00052 public: 00053 00054 typedef typename types::bone_type bone_type; 00055 typedef typename types::skeleton_type skeleton_type; 00056 typedef std::list<bone_type*> bone_ptr_container; 00057 typedef typename bone_ptr_container::iterator bone_ptr_iterator; 00058 typedef boost::indirect_iterator<bone_ptr_iterator,bone_type> bone_iterator; 00059 00060 protected: 00061 00062 std::string m_name; 00063 size_t m_number; 00064 skeleton_type * m_skeleton; 00065 bone_type * m_parent; 00066 bone_ptr_container m_children; 00067 00068 transform_type m_bind_pose; 00069 transform_type m_bone_space; 00070 transform_type m_absolute; 00071 transform_type m_transform; 00072 transform_type m_relative; 00073 00074 real_type m_accumulated_weight; 00075 00076 public: 00077 00078 Bone() 00079 : m_name("bone") 00080 , m_number(0) 00081 , m_parent(0) 00082 , m_accumulated_weight( value_traits::zero() ) 00083 {} 00084 00085 public: 00086 00087 real_type const & accumulated_weight() const { return m_accumulated_weight; } 00088 real_type & accumulated_weight() { return m_accumulated_weight; } 00089 00090 transform_type const & relative() const { return m_relative; } 00091 transform_type & relative() { return m_relative; } 00092 00093 transform_type const & bind_pose() const { return m_bind_pose;} 00094 transform_type & bind_pose() { return m_bind_pose;} 00095 00096 transform_type const & bone_space() const { return m_bone_space;} 00097 transform_type & bone_space() { return m_bone_space;} 00098 00099 transform_type const & absolute() const { return m_absolute; } 00100 transform_type & absolute() { return m_absolute; } 00101 00102 transform_type const & bone_space_transform() const { return m_transform; } 00103 transform_type & bone_space_transform() { return m_transform; } 00104 00105 public: 00106 00113 bool is_root() const { return !m_parent; } 00114 00123 bool set_name(std::string const & name) 00124 { 00125 if(m_skeleton) 00126 return m_skeleton->rename_bone( this, name); 00127 return false; 00128 } 00129 00135 std::string const & get_name() const { return m_name; } 00136 00142 size_t const & get_number() const { return m_number; } 00143 00149 bone_type const * parent() const { return m_parent; } 00150 00156 skeleton_type const * skeleton() const { return m_skeleton; } 00157 00158 00164 bool is_leaf() const { return m_children.empty(); } 00165 }; 00166 00167 } // namespace skeleton 00168 } // namespace OpenTissue 00169 00170 //OPENTISSUE_KINEMATICS_SKELETON_BONE_H 00171 #endif