00001 #ifndef OPENTISSUE_KINEMATICS_ANIMATION_ANIMATION_NAIVE_BLEND_SCHEDULER_H 00002 #define OPENTISSUE_KINEMATICS_ANIMATION_ANIMATION_NAIVE_BLEND_SCHEDULER_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 <OpenTissue/kinematics/animation/animation_interface.h> 00013 00014 #include <boost/iterator/indirect_iterator.hpp> 00015 00016 #include <list> 00017 #include <algorithm> 00018 #include <cassert> 00019 00020 namespace OpenTissue 00021 { 00022 namespace animation 00023 { 00031 template<typename skeleton_type_> 00032 class NaiveBlendScheduler 00033 { 00034 protected: 00035 00036 typedef skeleton_type_ skeleton_type; 00037 typedef typename skeleton_type::bone_type bone_type; 00038 typedef typename skeleton_type::math_types math_types; 00039 typedef typename math_types::coordsys_type coordsys_type; 00040 typedef typename math_types::real_type real_type; 00041 typedef Interface<skeleton_type> animation_interface; 00042 00043 typedef std::list<animation_interface*> animation_ptr_container; 00044 typedef typename animation_ptr_container::iterator animation_ptr_iterator; 00045 typedef boost::indirect_iterator<animation_ptr_iterator,animation_interface> animation_iterator; 00046 00047 protected: 00048 00049 animation_ptr_container m_animations; 00050 00051 public: 00052 00053 NaiveBlendScheduler(){} 00054 00055 public: 00056 00057 void clear() { m_animations.clear(); } 00058 00059 void add(animation_interface * animation) 00060 { 00061 assert(animation || !"BlendScheduler::add(): Animation was null"); 00062 assert(find(m_animations.begin(),m_animations.end(),animation) == m_animations.end() || !"BlendScheduler::add(): Animation was already added."); 00063 00064 //--- TODO: 00065 //--- 00066 //--- Extend with parameters and do whatever is needed 00067 //--- to add the specified animation to the blend!!! 00068 00069 m_animations.push_back(animation); 00070 } 00071 00072 void remove(animation_interface * animation) 00073 { 00074 //--- TODO: 00075 //--- 00076 //--- Extend with parameters and do whatever is needed 00077 //--- to add the specified animation to the blend!!! 00078 00079 m_animations.remove(animation); 00080 } 00081 00087 real_type compute_duration() 00088 { 00089 //--- TODO: 00090 //--- 00091 //--- Modify code, so the correct duration is returned, depending 00092 //--- on the choice of blend scheduling algorithm! 00093 00094 real_type duration = 0; 00095 animation_iterator begin = m_animations.begin(); 00096 animation_iterator end = m_animations.end(); 00097 animation_iterator animation; 00098 for(animation=begin;animation!=end;++animation) 00099 { 00100 duration = std::max(duration,animation->compute_duration()); 00101 } 00102 return duration; 00103 } 00104 00112 void compute_pose(skeleton_type & skeleton, real_type const & global_time) 00113 { 00114 //--- TODO: 00115 //--- 00116 //--- Modify code, so the correct pose is returned, depending on the 00117 //--- choice of blend scheduling algorithm! 00118 00119 animation_iterator begin = m_animations.begin(); 00120 animation_iterator end = m_animations.end(); 00121 animation_iterator animation; 00122 00123 skeleton.clear_pose(); 00124 for(animation=begin;animation!=end;++animation) 00125 { 00126 real_type local_time = global_time; //--- TODO: add timewarping... 00127 //--- TODO: add alignment curve 00128 //--- TODO: set blend weights: animation->set_weight() 00129 animation->blend_pose(skeleton,local_time); 00130 } 00131 skeleton.compute_pose(); 00132 //--- TODO: possible constraint matching...? 00133 } 00134 00135 }; 00136 00137 } // namespace animation 00138 } // namespace OpenTissue 00139 00140 //OPENTISSUE_KINEMATICS_ANIMATION_ANIMATION_NAIVE_BLEND_SCHEDULER_H 00141 #endif