/**************************************************************************** * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * * Copyright(C) 2004-2016 \/)\/ * * 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. * * * ****************************************************************************/ // stuff to define the mesh #include #include #include #include #include #include class BaseVertex; class BaseEdge; class BaseFace; struct BaseUsedTypes: public vcg::UsedTypes::AsVertexType,vcg::Use::AsEdgeType,vcg::Use::AsFaceType>{}; class BaseVertex : public vcg::Vertex< BaseUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags > {}; class BaseEdge : public vcg::Edge< BaseUsedTypes> {}; class BaseFace : public vcg::Face< BaseUsedTypes, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::BitFlags, vcg::face::Mark, vcg::face::EmptyEdgePlane > {}; class BaseMesh : public vcg::tri::TriMesh, std::vector > {}; class RTVertex; class RTEdge; class RTFace; struct RTUsedTypes: public vcg::UsedTypes::AsVertexType,vcg::Use::AsEdgeType,vcg::Use::AsFaceType>{}; class RTVertex : public vcg::Vertex< RTUsedTypes, vcg::vertex::Coord3f, vcg::vertex::Normal3f, vcg::vertex::BitFlags > {}; class RTEdge : public vcg::Edge< RTUsedTypes> {}; class RTFace : public vcg::Face< RTUsedTypes, vcg::face::Normal3f, vcg::face::VertexRef, vcg::face::EdgePlane, vcg::face::Mark, vcg::face::BitFlags > {}; class RTMesh : public vcg::tri::TriMesh, std::vector > {}; using namespace vcg; void Usage() { printf( "\nUsage: trimesh_closest mesh.ply samplenum sampledistance(as fraction of bboxdiag)"); exit(-1); } // Testing of closest point on a mesh functionalities // Two main options // - using or not precomputed edges and planes // - using the simple wrapper or the basic functions of the grid. // - using the fn as size of the grid or the edge lenght as cell side template bool UnitTest_Closest(const char *filename1, int sampleNum, float dispPerc, std::vector resultVec) { MeshType mr; typedef typename MeshType::ScalarType ScalarType; typedef typename MeshType::CoordType CoordType; typedef typename MeshType::FaceType FaceType; typedef GridStaticPtr TriMeshGrid; int startOpen=clock(); int err=vcg::tri::io::Importer::Open(mr,filename1); tri::UpdateBounding::Box(mr); // tri::UpdateNormals::PerFaceNormalized(mr); tri::UpdateNormal::PerFace(mr); float dispAbs = mr.bbox.Diag()*dispPerc; if(err) { std::cerr << "Unable to open mesh " << filename1 << " : " << vcg::tri::io::Importer::ErrorMsg(err) << std::endl; exit(-1); } int endOpen = clock(); printf("Loading %6.3f - ",float(endOpen-startOpen)/CLOCKS_PER_SEC); int startSampling = clock(); std::vector MontecarloSamples; // First step build the sampling typedef tri::TrivialSampler BaseSampler; BaseSampler mcSampler(MontecarloSamples); tri::SurfaceSampling::SamplingRandomGenerator().initialize(123); tri::SurfaceSampling::Montecarlo(mr, mcSampler, sampleNum); math::MarsenneTwisterRNG rnd; rnd.initialize(123); for(size_t i=0;i::ComputeEdgeLengthAverage(mr); TRGrid.SetWithRadius(mr.face.begin(),mr.face.end(),avgEdge*2); } if(useEdge) tri::UpdateComponentEP::Set(mr); int endGridInit = clock(); printf("Grid Init %6.3f - ",float(endGridInit-startGridInit)/CLOCKS_PER_SEC); const ScalarType maxDist=std::max(dispAbs*10.0f,mr.bbox.Diag()/1000.f); CoordType closest; ScalarType dist; int startGridQuery = clock(); double avgDist=0; resultVec.resize(MontecarloSamples.size()); if(useEdge && useWrap) for(size_t i=0;i MarkerFace; MarkerFace mf; mf.SetMesh(&mr); face::PointDistanceBaseFunctor PDistFunct; for(size_t i=0;i MarkerFace; MarkerFace mf; mf.SetMesh(&mr); face::PointDistanceBaseFunctor PDistFunct; for(size_t i=0;i resultVecRT11; std::vector resultVecRT01; std::vector resultVecRT00; std::vector resultVecRT10; std::vector resultVecBS01; std::vector resultVecBS00; UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT11); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT11); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT01); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT00); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT10); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT10); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT10); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecRT10); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecBS01); UnitTest_Closest (argv[1],sampleNum,dispPerc,resultVecBS01); UnitTest_Closest(argv[1],sampleNum,dispPerc,resultVecBS01); UnitTest_Closest(argv[1],sampleNum,dispPerc,resultVecBS01); for(size_t i=0;i