00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef PROJECTION_STATE_H
00017 #define PROJECTION_STATE_H
00018
00019 #include "angle_state.h"
00020 #include "options.h"
00021 #include "simulator.h"
00022
00040 template<class observation_type>
00041 class projection_state : public skeleton_state<observation_type>
00042 {
00043 public:
00044 projection_state (const options &opts, const calibration &_calib, const bool _for_show = true)
00045 : skeleton_state<observation_type> (opts, _calib, _for_show),
00046 pred_noise (opts.pred_noise ())
00047 {
00048 this->compute_pose ();
00049
00050
00051 std::list<vector3> chain_list;
00052 for (chain_iter iter = this->solver.chain_begin (); iter != this->solver.chain_end (); iter++)
00053 chain_list.push_back (iter->get_end_effector ()->absolute ().T ());
00054
00055
00056 int i = 0;
00057 for (bone_iter iter = this->bone_begin (); iter != this->bone_end (); iter++, i++)
00058 {
00059 if (iter->is_root ())
00060 continue;
00061
00062 const vector3 absolute = iter->absolute ().T ();
00063 const vector3 pabsolute = iter->parent ()->absolute ().T ();
00064
00065
00066 bool accept = true;
00067 for (std::list<vector3>::const_iterator ci = chain_list.begin ();
00068 ci != chain_list.end (); ci ++)
00069 {
00070 if (*ci == absolute)
00071 {
00072 accept = false;
00073 break;
00074 }
00075 }
00076
00077 if (accept)
00078 {
00079 chain_type chain;
00080 chain.init (this->skeleton.root (), &(*iter));
00081 this->solver.add_chain (chain);
00082 }
00083 }
00084 };
00085
00086 double predict (const observation_type &observation, const double variance_scale = 1.0)
00087 {
00088 gaussian1D gauss;
00089
00090
00091
00092
00093
00094
00095 this->compute_pose ();
00096 vector3 nu;
00097 int k = 0;
00098
00099 const double std [] = {0.019905, 0.003157, 0.008050, 0.180706, 0.101031, 0.137931,
00100 0.275119, 0.182599, 0.286416, 0.275119, 0.182599, 0.286416,
00101 0.390496, 0.301062, 0.483356, 0.508283, 0.808703, 0.806479,
00102 0.275119, 0.182599, 0.286416, 0.381652, 0.255074, 0.218130,
00103 0.498532, 0.249264, 0.615678, 0.938598, 0.593349, 1.098928,
00104 0.275119, 0.182599, 0.286416, 0.509799, 0.464794, 0.370578,
00105 0.988121, 0.796506, 0.450776, 1.155469, 1.320700, 0.709060};
00106
00107 for (chain_iter iter = this->solver.chain_begin (); iter != this->solver.chain_end (); iter++)
00108 {
00109 for (size_t n = 0; n < 3; n++)
00110 nu [n] = 0.5 * std [k++] * gauss.random () / variance_scale;
00111
00112 iter->p_global () = iter->get_end_effector ()->absolute ().T () + nu;
00113 }
00114
00115 this->solver.solve (&solver_type::default_SD_settings ());
00116 OpenTissue::kinematics::inverse::get_joint_parameters (*(this->solver.skeleton ()),
00117 this->theta);
00118
00119 return 0;
00120 };
00121
00122 projection_state& operator= (projection_state &new_state)
00123 {
00124 skeleton_state<observation_type>::operator= (new_state);
00125
00126 return *this;
00127 };
00128
00129 bool load (const std::string filename)
00130 {
00131 return skeleton_state<observation_type>::load (filename);
00132 };
00133
00134 bool load (std::ifstream &file)
00135 {
00136 return skeleton_state<observation_type>::load (file);
00137 };
00138
00139 private:
00140 const double pred_noise;
00141 };
00142
00143 #endif // PROJECTION_STATE_H