From b10bfc04e215634451085ee7287f74abdba78d6f Mon Sep 17 00:00:00 2001 From: cignoni Date: Tue, 4 May 2010 15:17:52 +0000 Subject: [PATCH] Better comment and printing --- apps/sample/trimesh_ray/trimesh_ray.cpp | 40 +++++++++++++++---------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/apps/sample/trimesh_ray/trimesh_ray.cpp b/apps/sample/trimesh_ray/trimesh_ray.cpp index 8c2faf0e..ae8fb0b5 100644 --- a/apps/sample/trimesh_ray/trimesh_ray.cpp +++ b/apps/sample/trimesh_ray/trimesh_ray.cpp @@ -39,7 +39,9 @@ class MyFace : public Face , vector >{}; +// Uncomment only one of the two following lines to test different data structures typedef vcg::GridStaticPtr TriMeshGrid; +//typedef vcg::SpatialHashTable TriMeshGrid; int main(int argc,char ** argv) { @@ -56,29 +58,27 @@ int main(int argc,char ** argv) } MyMesh m; - + int t0=clock(); // open a mesh int err = tri::io::Importer::Open(m,argv[1]); - if(err) - { + if(err) { printf("Error in reading %s: '%s'\n",argv[1],tri::io::Importer::ErrorMsg(err)); exit(-1); } -// the other parameters + // the other parameters float widenessRad = math::ToRad(20.0); if(argc>2) { widenessRad = math::ToRad(atof(argv[2])); printf("Setting wideness to %f degree\n",atof(argv[2])); } - int n_samples=2; - if(argc>3) { - n_samples = atoi(argv[3]); - printf("Setting oversampling to %i \n",n_samples); - } + if(argc>3) n_samples = atoi(argv[3]); + int samplePerVert = (n_samples*2+ 1)*(n_samples*2+ 1); + printf("Using oversampling to %i (%i sample per vertex)\n",n_samples,samplePerVert); - // some cleaning to get rid of bad file formats like stl that duplicate vertexes.. + + // some cleaning to get rid of bad stuff int dup = tri::Clean::RemoveDuplicateVertex(m); int unref = tri::Clean::RemoveUnreferencedVertex(m); @@ -94,17 +94,18 @@ int main(int argc,char ** argv) // Create a static grid (for fast indexing) and fill it TriMeshGrid static_grid; static_grid.Set(m.face.begin(), m.face.end()); - std::vector intersected_cells; - typedef MyMesh::ScalarType ScalarType; + typedef MyMesh::ScalarType ScalarType; + int t1=clock(); float t; MyMesh::FaceType *rf; MyMesh::VertexIterator vi; float maxDist=m.bbox.Diag(); float offset= maxDist / 10000.0; - + int totRay=0; ScalarType deltaRad=widenessRad/(ScalarType)(n_samples*2); + if(n_samples==0) deltaRad=0; tri::UpdateQuality::VertexConstant(m,0); for(vi=m.vert.begin();vi!=m.vert.end();++vi) @@ -135,12 +136,19 @@ int main(int argc,char ** argv) cnt++; } } - if(cnt>0) + if(cnt>0){ (*vi).Q()/=cnt; + totRay+=cnt; + } } + int t2 = clock(); tri::UpdateColor::VertexQualityRamp(m); - tri::io::ExporterPLY::Save(m,"Pippo.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY); + tri::io::ExporterPLY::Save(m,"SDF.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY); - return 0; + printf("Initializated in %i msec\n",t1-t0); + printf("Completed in %i msec\n",t2-t1); + printf("Shoot %i rays and found %i intersections\n",m.vn*samplePerVert,totRay); + +return 0; }