path.hpp
Go to the documentation of this file.
00001 
00060 template<typename NODE>
00061 void Path<NODE>::startFrame(const double time_in_sec)
00062 {
00063   act_ctxt_.clear();
00064 
00065   local_.link_.setTime(time_in_sec);
00066   last_time_ = time_in_sec;
00067 }
00068 
00069 template<typename NODE>
00070 void Path<NODE>::operator+=(typename OBJECT::Ptr obj)
00071 {
00072   act_ctxt_ += obj;
00073 
00074   //KEY key(obj);
00075   //std::map<KEY,typename NODE::Ptr>::iterator it = map_.find(key);
00076 }
00077 
00078 template<typename NODE>
00079 void Path<NODE>::finishFrame()
00080 {
00081 
00082   //registration
00083   //typename DOF6::TYPE success_rate, error_rate;
00084   //local_.node_->registration(act_ctxt_, local_.link_, success_rate, error_rate);
00085   {
00086     std::map<typename OBJECT::Ptr,bool> used;
00087     std::map<const NODE*,bool> visited_list;
00088     std::cout<<"LINK BEF123\n"<<local_.link_;
00089     local_.node_->compute(act_ctxt_, local_.link_, used, visited_list);
00090     std::cout<<"LINK AFT123\n"<<local_.link_;
00091   }
00092 
00093   if(needNewNode()) {
00094     const SWAY<NODE> * add = NULL;
00095     DOF6 l;
00096     //check if we can reuse existing node
00097     for(size_t i=0; i<local_.node_->getConnections().size(); i++)
00098     {
00099       //TODO: take nearest
00100 
00101       //get updated tf
00102       if(!getTF(l, &local_.node_->getConnections()[i], &local_))
00103         continue;
00104 
00105       std::cout<<"CHECKING LINK\n"<<l<<"\n";
00106 
00107       l = l+local_.link_;
00108 
00109       std::cout<<"CHECKING LINK\n"<<l<<"\n";
00110 
00111       if(
00112           //translation
00113           l.getTranslation().norm() + l.getTranslationVariance() < translation_res_
00114           &&
00115           //rotation
00116           l.getRotation().norm() + l.getRotationVariance() < rotation_res_
00117       )
00118       {
00119         add = &local_.node_->getConnections()[i];
00120         break;
00121       }
00122     }
00123 
00124     if(add)
00125     {
00126       // reuse node
00127       ROS_INFO("reuse node");
00128 
00129       //store node
00130       path_.push_back(local_);
00131 
00132       std::cout<<"REUSED LINK\n"<<l<<"\n";
00133 
00134       local_ = *add;
00135       local_.link_.deepCopy(l);
00136 //      *local_.link_.getSource1() = *path_.back().link_.getSource1() + *l.getSource1();
00137 //      local_.link_.setVariance(local_.link_.getSource1()->getTranslationVariance(),
00138 //                           local_.link_.getSource1()->getTranslation(),
00139 //                           local_.link_.getSource1()->getRotationVariance(),
00140 //                           (typename DOF6::TROTATION)( local_.link_.getSource1()->getRotation()) );
00141 
00142       //add path to new node (straight-forwared)
00143       local_.node_->addLink(path_.back());
00144     }
00145     else
00146     {
00147       // new node needed
00148 
00149       //store node
00150       path_.push_back(local_);
00151 
00152       //create new node
00153       newNode();
00154       local_.link_.setTime(last_time_);
00155 
00156       //add path to new node (straight-forwared)
00157       local_.node_->addLink(path_.back());
00158 
00159       //our new node gets some object (yummy)
00160       //local_.node_->addCtxt(act_ctxt_, local_.link_);
00161 
00162       ROS_INFO("new node %d", local_.id_);
00163     }
00164   }
00165   else
00166   {
00167     ROS_INFO("no new node");
00168 
00169     //local_.node_->addCtxt(act_ctxt_, local_.link_);
00170   }
00171 
00172 }
00173 
00174 template<typename NODE>
00175 bool Path<NODE>::getTF(DOF6 &tf, const SWAY<NODE> *start, const SWAY<NODE> *end)
00176 {
00177   if(start->id_<end->id_)
00178   {
00179     bool r = getTF(tf,end,start);
00180     tf.transpose();
00181     return r;
00182   }
00183 
00184   ROS_INFO("IDSSSS %d %d", start->id_, end->id_);
00185 
00186   if(start->id_!=end->id_)
00187   {
00188     for(size_t i=0; i<start->node_->getConnections().size(); i++)
00189     {
00190       if(start->node_->getConnections()[i].id_==end->id_)
00191       {
00192         tf.deepCopy(start->node_->getConnections()[i].link_);
00193         std::cout<<"SET LINK\n"<<tf<<"\n";
00194         return true;
00195       }
00196       else if(getTF(tf, &start->node_->getConnections()[i], end)) {    //TODO: takes only first
00197         tf = tf + start->node_->getConnections()[i].link_;
00198         std::cout<<"ADD LINK\n"<<start->node_->getConnections()[i].link_<<"\n";
00199         std::cout<<"NEW LINK\n"<<tf<<"\n";
00200         return true;
00201       }
00202     }
00203   }
00204 
00205   return false;
00206 }
00207 
00208 
00209 template<typename NODE>
00210 void Path<NODE>::test() {
00211   Eigen::Matrix4f M = Eigen::Matrix4f::Identity();
00212   Eigen::AngleAxisf aa(1,Eigen::Vector3f::Identity());
00213 
00214   M.topLeftCorner(3,3) = aa.toRotationMatrix();
00215   M.col(3).head<3>() = Eigen::Vector3f::Identity();
00216 
00217   local_.link_.setVariance(
00218       0,
00219       M.col(3).head<3>(),
00220       0,
00221       (typename DOF6::TROTATION)(M.topLeftCorner(3,3)));
00222 
00223   //store node
00224   path_.push_back(local_);
00225 
00226   //create new node
00227   newNode();
00228   local_.link_.setTime(last_time_);
00229 
00230   //add path to new node (straight-forwared)
00231   local_.node_->addLink(path_.back());
00232 
00233 
00234   M = M.inverse().eval();
00235   local_.link_.setVariance(
00236       0,
00237       M.col(3).head<3>(),
00238       0,
00239       (typename DOF6::TROTATION)(M.topLeftCorner(3,3)));
00240 
00241 
00242   const SWAY<NODE> * add = NULL;
00243   DOF6 l;
00244   //check if we can reuse existing node
00245   for(size_t i=0; i<local_.node_->getConnections().size(); i++)
00246   {
00247     //TODO: take nearest
00248 
00249     //get updated tf
00250     if(!getTF(l, &local_.node_->getConnections()[i], &local_))
00251       continue;
00252 
00253     std::cout<<"CHECKING LINK\n"<<l<<"\n";
00254 
00255     l = l+local_.link_;
00256 
00257     std::cout<<"CHECKING LINK\n"<<l<<"\n";
00258 
00259     if(
00260         //translation
00261         l.getTranslation().norm() + l.getTranslationVariance() < translation_res_
00262         &&
00263         //rotation
00264         l.getRotation().norm() + l.getRotationVariance() < rotation_res_
00265     )
00266     {
00267       add = &local_.node_->getConnections()[i];
00268       break;
00269     }
00270   }
00271 
00272   if(add)
00273   {
00274     // reuse node
00275     ROS_INFO("reuse node");
00276 
00277     //store node
00278     path_.push_back(local_);
00279 
00280     std::cout<<"REUSED LINK\n"<<l<<"\n";
00281 
00282     local_ = *add;
00283     local_.link_.deepCopy(l);
00284 //      *local_.link_.getSource1() = *path_.back().link_.getSource1() + *l.getSource1();
00285 //      local_.link_.setVariance(local_.link_.getSource1()->getTranslationVariance(),
00286 //                           local_.link_.getSource1()->getTranslation(),
00287 //                           local_.link_.getSource1()->getRotationVariance(),
00288 //                           (typename DOF6::TROTATION)( local_.link_.getSource1()->getRotation()) );
00289 
00290     //add path to new node (straight-forwared)
00291     local_.node_->addLink(path_.back());
00292   }
00293   else
00294   {
00295     // new node needed
00296 
00297     //store node
00298     path_.push_back(local_);
00299 
00300     //create new node
00301     newNode();
00302     local_.link_.setTime(last_time_);
00303 
00304     //add path to new node (straight-forwared)
00305     local_.node_->addLink(path_.back());
00306 
00307     //our new node gets some object (yummy)
00308     //local_.node_->addCtxt(act_ctxt_, local_.link_);
00309 
00310     ROS_INFO("new node %d", local_.id_);
00311   }
00312 }


cob_3d_mapping_slam
Author(s): Joshua Hampp
autogenerated on Wed Aug 26 2015 11:04:51