From eb8baaeee07c178d01f55b0214e30595d4a93c03 Mon Sep 17 00:00:00 2001 From: cignoni Date: Thu, 4 Oct 2012 16:26:52 +0000 Subject: [PATCH] Cleaning up the old metro app --- apps/metro/metro.cpp | 66 +++++++++++++++++++++---------- apps/metro/sampling.h | 91 ++++--------------------------------------- 2 files changed, 52 insertions(+), 105 deletions(-) diff --git a/apps/metro/metro.cpp b/apps/metro/metro.cpp index a72e7540..91cc95ba 100644 --- a/apps/metro/metro.cpp +++ b/apps/metro/metro.cpp @@ -98,18 +98,42 @@ GPL added // standard libraries #include -#include -using namespace std; -// project definitions. -#include "defs.h" -#include "sampling.h" -#include "mesh_type.h" -#include -#include + + #include -#include +#include +#include #include #include +#include +#include +#include "sampling.h" + +using namespace std; +// project definitions. +// error messages + +#define MSG_ERR_MESH_LOAD "error loading the input meshes.\n" +#define MSG_ERR_INVALID_OPTION "unable to parse option '%s'\n" +#define MSG_ERR_FILE_OPEN "unable to open the output file.'n" +#define MSG_ERR_UNKNOWN_FORMAT "unknown file format '%s'.\n" + +// global constants +#define NO_SAMPLES_PER_FACE 10 +#define N_SAMPLES_EDGE_TO_FACE_RATIO 0.1 +#define BBOX_FACTOR 0.1 +#define INFLATE_PERCENTAGE 0.02 +#define MIN_SIZE 125 /* 125 = 5^3 */ +#define N_HIST_BINS 256 +#define PRINT_EVERY_N_ELEMENTS 1000 + + +class CFace; +class CVertex; +struct UsedTypes:public vcg::UsedTypes< vcg::Use::AsFaceType, vcg::Use::AsVertexType>{}; +class CVertex : public vcg::Vertex {}; +class CFace : public vcg::Face< UsedTypes,vcg::face::VertexRef, vcg::face::Normal3d, vcg::face::EdgePlane,vcg::face::Color4b,vcg::face::Mark,vcg::face::BitFlags> {}; +class CMesh : public vcg::tri::TriMesh< std::vector, std::vector > {}; // ----------------------------------------------------------------------------------------------- @@ -257,8 +281,8 @@ int main(int argc, char**argv) } // compute face information - tri::UpdateEdges::Set(S1); - tri::UpdateEdges::Set(S2); + tri::UpdateComponentEP::Set(S1); + tri::UpdateComponentEP::Set(S2); // set bounding boxes for S1 and S2 tri::UpdateBounding::Box(S1); @@ -300,16 +324,16 @@ int main(int argc, char**argv) ForwardSampling.SetSamplesPerAreaUnit(n_samples_per_area_unit); n_samples_target = ForwardSampling.GetNSamplesTarget(); } - printf("target # samples : %u\ntarget # samples/area : %f\n", n_samples_target, n_samples_per_area_unit); + printf("target # samples : %lu\ntarget # samples/area : %f\n", n_samples_target, n_samples_per_area_unit); ForwardSampling.Hausdorff(); dist1_max = ForwardSampling.GetDistMax(); printf("\ndistances:\n max : %f (%f wrt bounding box diagonal)\n", (float)dist1_max, (float)dist1_max/bbox.Diag()); printf(" mean : %f\n", ForwardSampling.GetDistMean()); printf(" RMS : %f\n", ForwardSampling.GetDistRMS()); - printf("# vertex samples %9d\n", ForwardSampling.GetNVertexSamples()); - printf("# edge samples %9d\n", ForwardSampling.GetNEdgeSamples()); - printf("# area samples %9d\n", ForwardSampling.GetNAreaSamples()); - printf("# total samples %9d\n", ForwardSampling.GetNSamples()); + printf("# vertex samples %9lu\n", ForwardSampling.GetNVertexSamples()); + printf("# edge samples %9lu\n", ForwardSampling.GetNEdgeSamples()); + printf("# area samples %9lu\n", ForwardSampling.GetNAreaSamples()); + printf("# total samples %9lu\n", ForwardSampling.GetNSamples()); printf("# samples per area unit: %f\n\n", ForwardSampling.GetNSamplesPerAreaUnit()); // Backward distance. @@ -325,16 +349,16 @@ int main(int argc, char**argv) BackwardSampling.SetSamplesPerAreaUnit(n_samples_per_area_unit); n_samples_target = BackwardSampling.GetNSamplesTarget(); } - printf("target # samples : %u\ntarget # samples/area : %f\n", n_samples_target, n_samples_per_area_unit); + printf("target # samples : %lu\ntarget # samples/area : %f\n", n_samples_target, n_samples_per_area_unit); BackwardSampling.Hausdorff(); dist2_max = BackwardSampling.GetDistMax(); printf("\ndistances:\n max : %f (%f wrt bounding box diagonal)\n", (float)dist2_max, (float)dist2_max/bbox.Diag()); printf(" mean : %f\n", BackwardSampling.GetDistMean()); printf(" RMS : %f\n", BackwardSampling.GetDistRMS()); - printf("# vertex samples %9d\n", BackwardSampling.GetNVertexSamples()); - printf("# edge samples %9d\n", BackwardSampling.GetNEdgeSamples()); - printf("# area samples %9d\n", BackwardSampling.GetNAreaSamples()); - printf("# total samples %9d\n", BackwardSampling.GetNSamples()); + printf("# vertex samples %9lu\n", BackwardSampling.GetNVertexSamples()); + printf("# edge samples %9lu\n", BackwardSampling.GetNEdgeSamples()); + printf("# area samples %9lu\n", BackwardSampling.GetNAreaSamples()); + printf("# total samples %9lu\n", BackwardSampling.GetNSamples()); printf("# samples per area unit: %f\n\n", BackwardSampling.GetNSamplesPerAreaUnit()); // compute time info. diff --git a/apps/metro/sampling.h b/apps/metro/sampling.h index 587cf99c..97dacf6d 100644 --- a/apps/metro/sampling.h +++ b/apps/metro/sampling.h @@ -2,7 +2,7 @@ * VCGLib o o * * Visual and Computer Graphics Library o o * * _ O _ * -* Copyright(C) 2004 \/)\/ * +* Copyright(C) 2004-2012 \/)\/ * * Visual Computing Lab /\/| * * ISTI - Italian National Research Council | * * \ * @@ -20,87 +20,11 @@ * for more details. * * * ****************************************************************************/ -/**************************************************************************** - History -$Log: not supported by cvs2svn $ -Revision 1.24 2007/05/04 16:50:23 ganovelli -added plus types version (#ifdef _PLUS_TYPES_ to use it ). - -Revision 1.23 2006/10/25 12:40:19 fiorin -Added possibility to use Octree as search structure: - -Revision 1.22 2006/04/20 08:30:24 cignoni -small GCC compiling issues - -Revision 1.21 2006/01/22 10:05:43 cignoni -Corrected use of Area with the unambiguous DoubleArea - -Revision 1.20 2005/11/12 06:44:29 cignoni -Changed GetClosest -> GetClosestFace - -Revision 1.19 2005/10/02 23:11:50 cignoni -Changed the core for distance computation. -Current version uses the lib flexible search structures. -Now the comparison can be done exploiting a static uniform grid, -a hashed grid or a hierarchy of AA box. - -Revision 1.18 2005/09/16 11:55:18 cignoni -Partial adding of AABB trees, still not working... - -Revision 1.17 2005/08/26 10:42:47 cignoni -Added scalar type specification in the typedef of MetroMeshGrid - -Revision 1.16 2005/04/04 10:47:26 cignoni -Release 4.05 -Added saving of Error Histogram - -Revision 1.15 2005/01/26 22:45:34 cignoni -Release 4.04 -final updates for gcc compiling issues - -Revision 1.14 2005/01/24 15:37:14 cignoni -updated from MinDistPoint to Closest (and removed some warnings) - -Revision 1.13 2004/09/20 16:17:46 ponchio -Floating except fixed (happened on meshes with less than 100 faces :P) - -Revision 1.12 2004/09/09 22:59:15 cignoni -Removed many small warnings - -Revision 1.11 2004/08/25 15:28:15 ponchio -Comma at end of enum. - -Revision 1.10 2004/08/25 15:15:22 ganovelli -minor changes to comply gcc compiler (typename's and stuff) - -Revision 1.9 2004/07/18 10:13:34 cignoni -NewUserBit -> NewBitFlag - -Revision 1.8 2004/06/24 09:08:31 cignoni -Official Release of Metro 4.00 - -Revision 1.7 2004/05/14 13:49:07 ganovelli -created - -Revision 1.6 2004/05/14 00:38:01 ganovelli -a bit of cleaning: -SamplingFlags struct added -optional treatment for unreferred vertices. -Note: unref vertices are tested against unref vertices without -using the grid...it is n^2 with n number of unreferred vertices. To make it -with the grid in the proper way : -derive face and vertex from a simplexClass, -instantiate GridStaticPtr on the simplexClass template. - - - -****************************************************************************/ #ifndef __VCGLIB__SAMPLING #define __VCGLIB__SAMPLING #include -//#include "min_dist_point.h" #include #include #include @@ -308,13 +232,13 @@ float Sampling::AddSample(const Point3x &p ) // compute distance between p_i and the mesh S2 if(Flags & SamplingFlags::USE_AABB_TREE) - f=tri::GetClosestFace(S2, tS2, p, dist_upper_bound, dist, normf, bestq, ip); + f=tri::GetClosestFaceEP(S2, tS2, p, dist_upper_bound, dist, normf, bestq, ip); if(Flags & SamplingFlags::USE_HASH_GRID) - f=tri::GetClosestFace(S2, hS2, p, dist_upper_bound, dist, normf, bestq, ip); + f=tri::GetClosestFaceEP(S2, hS2, p, dist_upper_bound, dist, normf, bestq, ip); if(Flags & SamplingFlags::USE_STATIC_GRID) - f=tri::GetClosestFace(S2, gS2, p, dist_upper_bound, dist, normf, bestq, ip); - if (Flags & SamplingFlags::USE_OCTREE) - f=tri::GetClosestFace(S2, oS2, p, dist_upper_bound, dist, normf, bestq, ip); + f=tri::GetClosestFaceEP(S2, gS2, p, dist_upper_bound, dist, normf, bestq, ip); + if (Flags & SamplingFlags::USE_OCTREE) + f=tri::GetClosestFaceEP(S2, oS2, p, dist_upper_bound, dist, normf, bestq, ip); // update distance measures if(dist == dist_upper_bound) @@ -423,7 +347,7 @@ void Sampling::EdgeSampling() // print progress information if(!(++cnt % print_every_n_elements)) - printf("Sampling edge %d%%\r", (100 * cnt/Edges.size())); + printf("Sampling edge %lu%%\r", (100 * cnt/Edges.size())); } printf(" \r"); } @@ -465,7 +389,6 @@ template void Sampling::MontecarloFaceSampling() { // Montecarlo sampling. - int cnt = 0; double n_samples_decimal = 0.0; FaceIterator fi;