VCG Library
trimesh_pointmatching.cpp
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
34 #include<vcg/complex/complex.h>
35 #include<vcg/complex/algorithms/create/platonic.h>
36 #include<vcg/complex/algorithms/point_sampling.h>
37 #include<wrap/io_trimesh/import_off.h>
38 #include<vcg/space/point_matching.h>
39 
40 using namespace vcg;
41 using namespace std;
42 
43 class MyEdge;
44 class MyFace;
45 class MyVertex;
46 struct MyUsedTypes : public vcg::UsedTypes< vcg::Use<MyVertex> ::AsVertexType,
47  vcg::Use<MyEdge> ::AsEdgeType,
48  vcg::Use<MyFace> ::AsFaceType>{};
49 
50 class MyVertex : public vcg::Vertex<MyUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags >{};
51 class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {};
52 class MyEdge : public vcg::Edge<MyUsedTypes>{};
53 class MyMesh : public vcg::tri::TriMesh< std::vector<MyVertex>, std::vector<MyFace> , std::vector<MyEdge> > {};
54 
55 float EvalPlane(vcg::Plane3f &pl, std::vector<vcg::Point3f> posVec)
56 {
57  float off=0;
58  for(size_t i=0;i<posVec.size();++i)
59  off += fabs(vcg::SignedDistancePlanePoint(pl,posVec[i]));
60 
61  off/=float(posVec.size());
62  return off;
63 }
64 
65 
66 int main( )
67 {
68  MyMesh m;
69  vcg::tri::Icosahedron(m);
72 
73  // As a simple test we get a few random points on a mesh,
74  // we rot and trans them
75  // and we fit them
76 
77  std::vector<vcg::Point3f> ExactVec;
78  std::vector<vcg::Point3f> PerturbVec;
79  tri::MontecarloSampling(m,ExactVec,10);
80  PerturbVec=ExactVec;
81 
82  Matrix44f RotM;
83  Matrix44f TraM;
84  Point3f dir;
85  vcg::math::MarsenneTwisterRNG rnd;
86 
87  vcg::math::GeneratePointInUnitBallUniform<float>(rnd);
88  RotM.SetRotateDeg(rand()%360,dir);
89  TraM.SetTranslate(1,2,3);
90  Matrix44f RigidM = RotM*TraM;
91 
92  for(size_t i=0;i<ExactVec.size();++i)
93  PerturbVec[i]=RigidM*ExactVec[i];
94 
95  Quaternionf q;
96  Point3f tr;
97  Matrix44f res;
98  ComputeRigidMatchMatrix(PerturbVec,ExactVec,res);
99 
100  res.print();
101  RigidM.print();
102 
103  return 0;
104 }