/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLGeom/src/ICLGeom/ICP.cpp ** ** Module : ICLGeom ** ** Authors: Christian Groszewski, Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include using namespace icl::utils; using namespace icl::math; namespace icl{ namespace geom{ ICP::Result::Result():rotation(3,3),translation(1,3),error(0.1){} ICP::ICP(std::vector > &model) { kdt.buildTree(model); } ICP::ICP(std::vector* > &model) { kdt.buildTree(model); } ICP::ICP(){} ICP::~ICP(){} const ICP::Result &ICP::apply(const std::vector* > &pointlist){ FixedMatrix mat; DynMatrix mat3(4,4); DynMatrix XsD(pointlist.size(),3),YsD(pointlist.size(),3); DynMatrix *mm2 = 0; DynMatrix *mm = 0; double eye[] = {1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; DynMatrix mat2(4,4,eye); DynMatrix temp(4,4); double cerror = 0.0; std::vector* > np; std::vector* > lpointlist; for(unsigned int i=0;i(pointlist.at(0)->cols(),pointlist.at(0)->rows(),pointlist.at(i)->data(),true)); } do{ np.clear(); m_result.error=cerror; for(unsigned int i=0;i *p = kdt.nearestNeighbour(lpointlist.at(i)); np.push_back(p); } for(unsigned int i=0;ibegin(),(np[i])->begin()+3, YsD.col_begin(i)); std::copy((lpointlist[i])->begin(),(lpointlist[i])->begin()+3, XsD.col_begin(i)); } mat = PoseEstimator::map(XsD,YsD); for(unsigned int i=0;i<16;++i){ mat3[i] = mat[i]; } for(unsigned int i=0;i<3;++i){ m_result.translation[i] = mat3.at(3,i); for(unsigned int j=0;j<3;++j){ m_result.rotation.at(i,j) = mat3.at(i,j); } } //SHOW(rotation); //SHOW(translation); //SHOW(*(np[0])); //SHOW(*(lpointlist[0])); for(unsigned int i=0;i(1,3); m_result.rotation.mult(*mm2,*mm); (*mm) = (*mm)+m_result.translation; lpointlist[i] = mm; delete mm2; } //SHOW(*(lpointlist[0])); mat3.mult(mat2,temp); mat2 = temp; cerror = error(lpointlist,np); std::cout << cerror << " " << m_result.error << std::endl; /*if(std::abs(cerror-m_error)<0.01) break;*/ }while(cerror != m_result.error); for(unsigned int i=0;i<3;++i){ m_result.translation[i] = mat2.at(3,i); for(unsigned int j=0;j<3;++j){ m_result.rotation.at(i,j) = mat2.at(i,j); } } for(unsigned int i=0;i *ICP::compute(const std::vector* > &data,const std::vector* > &model){ DynMatrix mean_data(1,3); DynMatrix mean_model(1,3); for(unsigned int i=0;i* > &dat, const std::vector* > &mod){ double error = 0.0; double sumsq = 0.0; DynMatrix d(1,3); if(dat.size() == mod.size() && dat.size()>0 && mod.size()>0){ for(unsigned int j=0;j