Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef HULL_STATE_H
00017 #define HULL_STATE_H
00018
00019 #include <vector>
00020 #include "angle_state.h"
00021 #include "options.h"
00022 #include "simulator.h"
00023
00040 template<class observation_type>
00041 class hull_state : public skeleton_state<observation_type>
00042 {
00043 public:
00044 hull_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 radius.push_back (iter->get_width ());
00083 }
00084 }
00085 };
00086
00087 double predict (const observation_type &observation, const double variance_scale = 1.0)
00088 {
00089 gaussian1D gauss;
00090 const knn_cloud &nearest_cloud = observation.get_knn_cloud ();
00091 const project2d &proj2d = observation.get_project2d ();
00092
00093
00094
00095
00096
00097
00098 this->compute_pose ();
00099 vector3 nu, tmp;
00100 int k = 0;
00101
00102 const size_t max_rejects = 100;
00103 size_t chain_idx = 0;
00104 for (chain_iter iter = this->solver.chain_begin (); iter != this->solver.chain_end (); iter++, chain_idx++)
00105 {
00106 const double s = (k >= 7) ? 3.0 * pred_noise : pred_noise;
00107 k++;
00108 const double r = radius [chain_idx];
00109
00110 for (size_t trial = 0; trial < max_rejects; trial++)
00111 {
00112 for (size_t n = 0; n < 3; n++)
00113 tmp [n] = s * gauss.random ();
00114
00115 nu = iter->get_end_effector ()->absolute ().T () + tmp;
00116
00117 const CvPoint nu2d = this->calib.world_to_pixel (nu, PROJ2D_SCALE);
00118 if (proj2d.is_inside (nu2d) && nearest_cloud.nearest_distance (nu) < r)
00119 break;
00120 }
00121
00122 iter->p_global () = nu;
00123 }
00124
00125 this->solver.solve (&solver_type::default_SD_settings ());
00126 OpenTissue::kinematics::inverse::get_joint_parameters (*(this->solver.skeleton ()),
00127 this->theta);
00128
00129 return 0;
00130 };
00131
00132 hull_state& operator= (hull_state &new_state)
00133 {
00134 skeleton_state<observation_type>::operator= (new_state);
00135
00136 return *this;
00137 };
00138
00139 bool load (const std::string filename)
00140 {
00141 return skeleton_state<observation_type>::load (filename);
00142 };
00143
00144 bool load (std::ifstream &file)
00145 {
00146 return skeleton_state<observation_type>::load (file);
00147 };
00148
00149 private:
00150 const double pred_noise;
00151 std::vector<double> radius;
00152 };
00153
00154 #endif // HULL_STATE_H