diff --git a/apps/sample/trimesh_pointmatching/trimesh_pointmatching.cpp b/apps/sample/trimesh_pointmatching/trimesh_pointmatching.cpp new file mode 100644 index 00000000..323d2435 --- /dev/null +++ b/apps/sample/trimesh_pointmatching/trimesh_pointmatching.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +* VCGLib o o * +* Visual and Computer Graphics Library o o * +* _ O _ * +* Copyright(C) 2004-2012 \/)\/ * +* Visual Computing Lab /\/| * +* ISTI - Italian National Research Council | * +* \ * +* All rights reserved. * +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; without even the implied warranty of * +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * +* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * +* for more details. * +* * +****************************************************************************/ +/*! \file trimesh_fitting.cpp +\ingroup code_sample + +\brief A small example about sampling and fitting + +Given a mesh (an icosahedron) for each face we get a few random samples over it, and then we recover: +- the plane fitting them (that coincide with the face plane and exactly approximate all the sample points) +- the plane fitting the perturbed version of this set +- the plane fitting the perturbed version of the set but using a weighted fitting scheme. +*/ + +#include +#include +#include +#include +#include +#include +#include + +using namespace vcg; +using namespace std; + +class MyEdge; +class MyFace; +class MyVertex; +struct MyUsedTypes : public vcg::UsedTypes< vcg::Use ::AsVertexType, + vcg::Use ::AsEdgeType, + vcg::Use ::AsFaceType>{}; + +class MyVertex : public vcg::Vertex{}; +class MyFace : public vcg::Face< MyUsedTypes, vcg::face::FFAdj, vcg::face::VertexRef, vcg::face::Normal3f, vcg::face::BitFlags > {}; +class MyEdge : public vcg::Edge{}; +class MyMesh : public vcg::tri::TriMesh< std::vector, std::vector , std::vector > {}; + +float EvalPlane(vcg::Plane3f &pl, vcg::Point3f &dir, std::vector posVec) +{ + float off=0; + for(size_t i=0;i::PerVertexNormalizedPerFaceNormalized(m); + vcg::tri::UpdateBounding::Box(m); + + // As a simple test we get a few random points on a mesh, + // we rot and trans them + // and we fit them + + std::vector ExactVec; + std::vector PerturbVec; + tri::MontecarloSampling(m,ExactVec,10); + PerturbVec=ExactVec; + + Matrix44f RotM; + Matrix44f TraM; + vcg::tri::SurfaceSampling::RandomPoint3fBall01(); + RotM.SetRotateDeg(rand()%360,vcg::tri::SurfaceSampling::RandomPoint3fBall01()); + TraM.SetTranslate(1,2,3); + Matrix44f RigidM = RotM*TraM; + + for(int i=0;i