trimesh_pointmatching.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00034 #include<vcg/complex/complex.h>
00035 #include<vcg/complex/algorithms/update/topology.h>
00036 #include<vcg/complex/algorithms/update/normal.h>
00037 #include<vcg/complex/algorithms/create/platonic.h>
00038 #include<vcg/complex/algorithms/point_sampling.h>
00039 #include<wrap/io_trimesh/import_off.h>
00040 #include<vcg/space/point_matching.h>
00041 
00042 using namespace vcg;
00043 using namespace std;
00044 
00045 class MyEdge;
00046 class MyFace;
00047 class MyVertex;
00048 struct MyUsedTypes : public vcg::UsedTypes<     vcg::Use<MyVertex>   ::AsVertexType,
00049                                         vcg::Use<MyEdge>     ::AsEdgeType,
00050                                         vcg::Use<MyFace>     ::AsFaceType>{};
00051 
00052 class MyVertex  : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags  >{};
00053 class MyFace    : public vcg::Face< MyUsedTypes, vcg::face::FFAdj,  vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
00054 class MyEdge    : public vcg::Edge<MyUsedTypes>{};
00055 class MyMesh    : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge>  > {};
00056 
00057 float EvalPlane(vcg::Plane3f &pl, std::vector<vcg::Point3f> posVec)
00058 {
00059   float off=0;
00060   for(size_t i=0;i<posVec.size();++i)
00061     off += fabs(vcg::SignedDistancePlanePoint(pl,posVec[i]));
00062 
00063   off/=float(posVec.size());
00064   return off;
00065 }
00066 
00067 
00068 int main( )
00069 {
00070   MyMesh m;
00071   vcg::tri::Icosahedron(m);
00072   vcg::tri::UpdateNormal<MyMesh>::PerVertexNormalizedPerFaceNormalized(m);
00073   vcg::tri::UpdateBounding<MyMesh>::Box(m);
00074 
00075   // As a simple test we get a few random points on a mesh,
00076   // we rot and trans them
00077   // and we fit them
00078 
00079   std::vector<vcg::Point3f> ExactVec;
00080   std::vector<vcg::Point3f> PerturbVec;
00081   tri::MontecarloSampling(m,ExactVec,10);
00082   PerturbVec=ExactVec;
00083 
00084   Matrix44f RotM;
00085   Matrix44f TraM;
00086   Point3f dir;
00087   vcg::math::MarsenneTwisterRNG rnd;
00088 
00089   vcg::math::GeneratePointInUnitBallUniform<float>(rnd);
00090   RotM.SetRotateDeg(rand()%360,dir);
00091   TraM.SetTranslate(1,2,3);
00092   Matrix44f RigidM = RotM*TraM;
00093 
00094   for(size_t i=0;i<ExactVec.size();++i)
00095     PerturbVec[i]=RigidM*ExactVec[i];
00096 
00097   Quaternionf q;
00098   Point3f tr;
00099   Matrix44f res;
00100   ComputeRigidMatchMatrix(PerturbVec,ExactVec,res);
00101 
00102   res.print();
00103   RigidM.print();
00104 
00105   return 0;
00106 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:21