Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef BGSUB_STATE_H
00017 #define BGSUB_STATE_H
00018
00019 #include "skeleton_state.h"
00020 #include "options.h"
00021 #include "simulator.h"
00022
00039 template<class observation_type>
00040 class bgsub_state : public skeleton_state<observation_type>
00041 {
00042 public:
00043 bgsub_state (const options &opts, const calibration &_calib, const bool _for_show = true)
00044 : skeleton_state<observation_type> (opts, _calib, _for_show),
00045 pred_noise (opts.pred_noise ())
00046 {
00047 this->compute_pose ();
00048
00049
00050 std::list<vector3> chain_list;
00051 for (chain_iter iter = this->solver.chain_begin (); iter != this->solver.chain_end (); iter++)
00052 chain_list.push_back (iter->get_end_effector ()->absolute ().T ());
00053
00054
00055 int i = 0;
00056 for (bone_iter iter = this->bone_begin (); iter != this->bone_end (); iter++, i++)
00057 {
00058 if (iter->is_root ())
00059 continue;
00060
00061 const vector3 absolute = iter->absolute ().T ();
00062 const vector3 pabsolute = iter->parent ()->absolute ().T ();
00063
00064
00065 bool accept = true;
00066 for (std::list<vector3>::const_iterator ci = chain_list.begin ();
00067 ci != chain_list.end (); ci ++)
00068 {
00069 if (*ci == absolute)
00070 {
00071 accept = false;
00072 break;
00073 }
00074 }
00075
00076 if (accept)
00077 {
00078 chain_type chain;
00079 chain.init (this->skeleton.root (), &(*iter));
00080 this->solver.add_chain (chain);
00081 }
00082 }
00083 };
00084
00085 double predict (const observation_type &observation, const double variance_scale = 1.0)
00086 {
00087 const size_t max_rejects = 10;
00088
00089 this->compute_pose ();
00090
00091 gaussian1D gauss;
00092 const project2d &proj2d = observation.get_project2d ();
00093 const vector3 origin = this->calib.camera_centre ();
00094
00095 int k = 0;
00096 for (chain_iter iter = this->solver.chain_begin (); iter != this->solver.chain_end (); iter++)
00097 {
00098 vector3 nu, nu_valid;
00099 CvPoint nu2d;
00100
00101
00102 const double s = (k >= 7) ? 3.0 * pred_noise : pred_noise;
00103 k++;
00104
00105
00106 bool inside = false;
00107 for (size_t trial = 0; trial < max_rejects; trial++)
00108 {
00109
00110 for (size_t n = 0; n < 3; n++)
00111 nu [n] = s * gauss.random ();
00112 nu = iter->get_end_effector ()->absolute ().T () + nu;
00113
00114
00115 nu2d = this->calib.world_to_pixel (nu, PROJ2D_SCALE);
00116 if (proj2d.is_inside (nu2d))
00117 {
00118 nu_valid = nu;
00119 inside = true;
00120 break;
00121 }
00122 }
00123
00124
00125 if (!inside)
00126 {
00127 const CvPoint goal2d = proj2d.project (nu2d);
00128 const vector3 goal_line = this->calib.pixel_to_world (goal2d, PROJ2D_SCALE);
00129 nu_valid = project_point_on_line (nu, origin, goal_line);
00130 }
00131
00132
00133 iter->p_global () = nu_valid;
00134 }
00135
00136 this->solver.solve (&solver_type::default_SD_settings ());
00137 OpenTissue::kinematics::inverse::get_joint_parameters (*(this->solver.skeleton ()),
00138 this->theta);
00139
00140 return 0;
00141 };
00142
00143 bgsub_state& operator= (bgsub_state &new_state)
00144 {
00145 skeleton_state<observation_type>::operator= (new_state);
00146
00147 return *this;
00148 };
00149
00150 bool load (const std::string filename)
00151 {
00152 return skeleton_state<observation_type>::load (filename);
00153 };
00154
00155 bool load (std::ifstream &file)
00156 {
00157 return skeleton_state<observation_type>::load (file);
00158 };
00159 private:
00160 const double pred_noise;
00161 };
00162
00163 #endif // BGSUB_STATE_H