• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

/home/hauberg/Dokumenter/Capture/humim-tracker-0.1/src/projection_state.h

Go to the documentation of this file.
00001 // Copyright (C) 2011 Soren Hauberg
00002 //
00003 // This program is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU General Public License
00005 // as published by the Free Software Foundation; either version 3
00006 // of the License, or (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful, but
00009 // WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, see <http://www.gnu.org/licenses/>.
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       // Store default chains temporarely
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       // Add everything as end-effectors
00056       int i = 0;
00057       for (bone_iter iter = this->bone_begin (); iter != this->bone_end (); iter++, i++)
00058         {
00059           if (iter->is_root ()) // || i == 3 || i == 4 || i == 5 ||  i == 7 || i == 11)
00060             continue;
00061         
00062           const vector3 absolute = iter->absolute ().T ();
00063           const vector3 pabsolute = iter->parent ()->absolute ().T ();
00064 
00065           // Make sure the bone isn't already an end-effector
00066           bool accept = true; //(absolute != pabsolute);
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       // Predict root
00091       //this->root (0) += 0.05 * gauss.random ();
00092       //this->root (1) += 0.0001 * gauss.random ();
00093       //this->root (2) += 0.05 * gauss.random ();
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; // - this->root;
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

Generated on Thu Dec 1 2011 12:54:02 for HUMIM Tracker by  doxygen 1.7.1