Still cleaning all the samples.

Now all the trimesh_samples should compile without any dependency
This commit is contained in:
Paolo Cignoni 2017-03-24 16:50:19 +01:00
parent 0965a29520
commit 8efebae360
4 changed files with 58 additions and 78 deletions

View File

@ -12,19 +12,22 @@ SUBDIRS = trimesh_allocate \
trimesh_cylinder_clipping \ trimesh_cylinder_clipping \
trimesh_disk_parametrization \ trimesh_disk_parametrization \
trimesh_edge \ trimesh_edge \
trimesh_field_smoothing\
trimesh_fitting \ trimesh_fitting \
trimesh_geodesic \ trimesh_geodesic \
trimesh_harmonic \ trimesh_harmonic \
trimesh_hole \ trimesh_hole \
trimesh_implicit_smooth \
trimesh_indexing \
trimesh_inertia \ trimesh_inertia \
trimesh_intersection \ trimesh_intersection \
trimesh_isosurface \ trimesh_isosurface \
trimesh_join \ trimesh_join \
trimesh_kdtree \ trimesh_kdtree \
trimesh_montecarlo_sampling \
trimesh_normal \ trimesh_normal \
trimesh_optional \ trimesh_optional \
trimesh_pointmatching \ trimesh_pointmatching \
trimesh_pointcloud_sampling \
trimesh_ray \ trimesh_ray \
trimesh_refine \ trimesh_refine \
trimesh_remeshing \ trimesh_remeshing \

View File

@ -1,5 +1,4 @@
#include <iostream> #include <iostream>
#include <QTime>
#ifdef _OPENMP #ifdef _OPENMP
#include <omp.h> #include <omp.h>
#endif #endif
@ -21,7 +20,7 @@
int num_test = 1000; int num_test = 1000;
int kNearest = 256; int kNearest = 256;
float queryDist = 0.0037; float queryDist = 0.0037;
float ratio = 1000.0f; float bboxratio = 1000.0f;
class CVertex; class CVertex;
@ -34,6 +33,10 @@ class CFace : public vcg::Face < CUsedTypes, vcg::face::VertexRef>{};
class CMesh : public vcg::tri::TriMesh < std::vector< CVertex >, std::vector< CFace > > {}; class CMesh : public vcg::tri::TriMesh < std::vector< CVertex >, std::vector< CFace > > {};
int elapsed(int t)
{
return ((clock()-t)*1000.0)/CLOCKS_PER_SEC;
}
template <typename T> template <typename T>
struct PointCloud struct PointCloud
@ -72,21 +75,19 @@ void testKDTree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
{ {
std::cout << "==================================================="<< std::endl; std::cout << "==================================================="<< std::endl;
std::cout << "KDTree" << std::endl; std::cout << "KDTree" << std::endl;
QTime time; int t0=clock();
time.start();
// Construction of the kdTree // Construction of the kdTree
vcg::ConstDataWrapper<CMesh::VertexType::CoordType> wrapperVcg(&mesh.vert[0].P(), mesh.vert.size(), size_t(mesh.vert[1].P().V()) - size_t(mesh.vert[0].P().V())); vcg::ConstDataWrapper<CMesh::VertexType::CoordType> wrapperVcg(&mesh.vert[0].P(), mesh.vert.size(), size_t(mesh.vert[1].P().V()) - size_t(mesh.vert[0].P().V()));
vcg::KdTree<CMesh::ScalarType> kdTreeVcg(wrapperVcg); vcg::KdTree<CMesh::ScalarType> kdTreeVcg(wrapperVcg);
std::cout << "Build: " << time.elapsed() << " ms" << std::endl; std::cout << "Build: " << elapsed(t0) << " ms" << std::endl;
int nn=1; int nn=1;
// Computation of the point radius // Computation of the point radius
float mAveragePointSpacing = 0; float mAveragePointSpacing = 0;
time.restart(); t0=clock();
#pragma omp parallel for reduction(+: mAveragePointSpacing) schedule(dynamic, 10) #pragma omp parallel for reduction(+: mAveragePointSpacing) schedule(dynamic, 10)
for (int i = 0; i < mesh.vert.size(); i++) for (int i = 0; i < mesh.vert.size(); i++)
{ {
#ifdef #ifdef _OPENMP #ifdef _OPENMP
nn =omp_get_num_threads(); nn =omp_get_num_threads();
#endif #endif
vcg::KdTree<CMesh::ScalarType>::PriorityQueue queue; vcg::KdTree<CMesh::ScalarType>::PriorityQueue queue;
@ -98,7 +99,7 @@ void testKDTree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
std::cout << "Num trhread " << nn << std::endl; std::cout << "Num trhread " << nn << std::endl;
mAveragePointSpacing /= mesh.vert.size(); mAveragePointSpacing /= mesh.vert.size();
std::cout << "Average point radius (OpenMP with" << nn << " threads) " << mAveragePointSpacing << std::endl; std::cout << "Average point radius (OpenMP with" << nn << " threads) " << mAveragePointSpacing << std::endl;
std::cout << "Time (OpenMP): " << time.elapsed() << " ms" << std::endl; std::cout << "Time (OpenMP): " << elapsed(t0) << " ms" << std::endl;
queryDist = mAveragePointSpacing * 150; queryDist = mAveragePointSpacing * 150;
@ -107,11 +108,11 @@ void testKDTree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
float avgTime = 0.0f; float avgTime = 0.0f;
for (int ii = 0; ii < num_test; ii++) for (int ii = 0; ii < num_test; ii++)
{ {
time.restart(); int t0=clock();
std::vector<unsigned int> indeces; std::vector<unsigned int> indeces;
std::vector<float> dists; std::vector<float> dists;
kdTreeVcg.doQueryDist(mesh.vert[test_indeces[ii]].cP(), queryDist, indeces, dists); kdTreeVcg.doQueryDist(mesh.vert[test_indeces[ii]].cP(), queryDist, indeces, dists);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl; std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl;
@ -120,10 +121,10 @@ void testKDTree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); int t0=clock();
vcg::KdTree<CMesh::ScalarType>::PriorityQueue queue; vcg::KdTree<CMesh::ScalarType>::PriorityQueue queue;
kdTreeVcg.doQueryK(mesh.vert[test_indeces[ii]].cP(), kNearest, queue); kdTreeVcg.doQueryK(mesh.vert[test_indeces[ii]].cP(), kNearest, queue);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl; std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl;
@ -132,11 +133,11 @@ void testKDTree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); int t0=clock();
unsigned int index; unsigned int index;
float minDist; float minDist;
kdTreeVcg.doQueryClosest(randomSamples[ii], index, minDist); kdTreeVcg.doQueryClosest(randomSamples[ii], index, minDist);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl; std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl;
} }
@ -163,11 +164,10 @@ void testNanoFLANN(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::ve
> my_kd_tree_t; > my_kd_tree_t;
// Construction of the nanoFLANN KDtree // Construction of the nanoFLANN KDtree
QTime time; int t0=clock();
time.start();
my_kd_tree_t index(3, cloud, nanoflann::KDTreeSingleIndexAdaptorParams(16) ); my_kd_tree_t index(3, cloud, nanoflann::KDTreeSingleIndexAdaptorParams(16) );
index.buildIndex(); index.buildIndex();
std::cout << "Build nanoFlann: " << time.elapsed() << " ms" << std::endl; std::cout << "Build nanoFlann: " << elapsed(t0) << " ms" << std::endl;
// Test with the radius search // Test with the radius search
std::cout << "Radius search (" << num_test << " tests)"<< std::endl; std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
@ -176,9 +176,9 @@ void testNanoFLANN(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::ve
nanoflann::SearchParams params; nanoflann::SearchParams params;
for (int ii = 0; ii < num_test; ii++) for (int ii = 0; ii < num_test; ii++)
{ {
time.restart(); t0=clock();
const size_t nMatches = index.radiusSearch(mesh.vert[test_indeces[ii]].P().V(), queryDist, ret_matches, params); const size_t nMatches = index.radiusSearch(mesh.vert[test_indeces[ii]].P().V(), queryDist, ret_matches, params);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl; std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl;
@ -189,9 +189,9 @@ void testNanoFLANN(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::ve
std::vector<float> out_dist_sqr(kNearest); std::vector<float> out_dist_sqr(kNearest);
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
index.knnSearch(mesh.vert[test_indeces[ii]].P().V(), kNearest, &ret_index[0], &out_dist_sqr[0]); index.knnSearch(mesh.vert[test_indeces[ii]].P().V(), kNearest, &ret_index[0], &out_dist_sqr[0]);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl; std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl;
@ -202,9 +202,9 @@ void testNanoFLANN(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::ve
std::vector<float> out_dist_sqr_clos(1); std::vector<float> out_dist_sqr_clos(1);
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
index.knnSearch(randomSamples[ii].V(), 1, &ret_index_clos[0], &out_dist_sqr_clos[0]); index.knnSearch(randomSamples[ii].V(), 1, &ret_index_clos[0], &out_dist_sqr_clos[0]);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl; std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl;
} }
@ -214,26 +214,25 @@ void testUniformGrid(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::
{ {
std::cout << "==================================================="<< std::endl; std::cout << "==================================================="<< std::endl;
std::cout << "Uniform Grid" << std::endl; std::cout << "Uniform Grid" << std::endl;
QTime time; int t0=clock();
time.start();
// Construction of the uniform grid // Construction of the uniform grid
typedef vcg::GridStaticPtr<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid; typedef vcg::GridStaticPtr<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid;
MeshGrid uniformGrid; MeshGrid uniformGrid;
uniformGrid.Set(mesh.vert.begin(), mesh.vert.end()); uniformGrid.Set(mesh.vert.begin(), mesh.vert.end());
std::cout << "Build: " << time.elapsed() << " ms" << std::endl; std::cout << "Build: " << elapsed(t0) << " ms" << std::endl;
// Test with the radius search // Test with the radius search
std::cout << "Radius search (" << num_test << " tests)"<< std::endl; std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
float avgTime = 0.0f; float avgTime = 0.0f;
for (int ii = 0; ii < num_test; ii++) for (int ii = 0; ii < num_test; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points); vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl; std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl;
@ -242,12 +241,12 @@ void testUniformGrid(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points); vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl; std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl;
@ -256,10 +255,10 @@ void testUniformGrid(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
float minDist; float minDist;
vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist); vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl; std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl;
} }
@ -270,26 +269,25 @@ void testSpatialHashing(CMesh& mesh, std::vector<unsigned int>& test_indeces, st
{ {
std::cout << "==================================================="<< std::endl; std::cout << "==================================================="<< std::endl;
std::cout << "Spatial Hashing" << std::endl; std::cout << "Spatial Hashing" << std::endl;
QTime time; int t0=clock();
time.start();
// Construction of the uniform grid // Construction of the uniform grid
typedef vcg::SpatialHashTable<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid; typedef vcg::SpatialHashTable<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid;
MeshGrid uniformGrid; MeshGrid uniformGrid;
uniformGrid.Set(mesh.vert.begin(), mesh.vert.end()); uniformGrid.Set(mesh.vert.begin(), mesh.vert.end());
std::cout << "Build: " << time.elapsed() << " ms" << std::endl; std::cout << "Build: " << elapsed(t0) << " ms" << std::endl;
// Test with the radius search // Test with the radius search
std::cout << "Radius search (" << num_test << " tests)"<< std::endl; std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
float avgTime = 0.0f; float avgTime = 0.0f;
for (int ii = 0; ii < num_test; ii++) for (int ii = 0; ii < num_test; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points); vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl; std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl;
@ -298,12 +296,12 @@ void testSpatialHashing(CMesh& mesh, std::vector<unsigned int>& test_indeces, st
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points); vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl; std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl;
@ -312,10 +310,10 @@ void testSpatialHashing(CMesh& mesh, std::vector<unsigned int>& test_indeces, st
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
float minDist; float minDist;
vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist); vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl; std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl;
} }
@ -326,26 +324,25 @@ void testPerfectSpatialHashing(CMesh& mesh, std::vector<unsigned int>& test_inde
{ {
std::cout << "==================================================="<< std::endl; std::cout << "==================================================="<< std::endl;
std::cout << "Perfect Spatial Hashing" << std::endl; std::cout << "Perfect Spatial Hashing" << std::endl;
QTime time; int t0=clock();
time.start();
// Construction of the uniform grid // Construction of the uniform grid
typedef vcg::SpatialHashTable<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid; typedef vcg::SpatialHashTable<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid;
MeshGrid uniformGrid; MeshGrid uniformGrid;
uniformGrid.Set(mesh.vert.begin(), mesh.vert.end()); uniformGrid.Set(mesh.vert.begin(), mesh.vert.end());
std::cout << "Build: " << time.elapsed() << " ms" << std::endl; std::cout << "Build: " << elapsed(t0) << " ms" << std::endl;
// Test with the radius search // Test with the radius search
std::cout << "Radius search (" << num_test << " tests)"<< std::endl; std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
float avgTime = 0.0f; float avgTime = 0.0f;
for (int ii = 0; ii < num_test; ii++) for (int ii = 0; ii < num_test; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points); vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl << std::endl; std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl << std::endl;
} }
@ -355,26 +352,25 @@ void testOctree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
{ {
std::cout << "==================================================="<< std::endl; std::cout << "==================================================="<< std::endl;
std::cout << "Octree" << std::endl; std::cout << "Octree" << std::endl;
QTime time; int t0=clock();
time.start();
// Construction of the uniform grid // Construction of the uniform grid
typedef vcg::Octree<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid; typedef vcg::Octree<CMesh::VertexType, CMesh::VertexType::ScalarType> MeshGrid;
MeshGrid uniformGrid; MeshGrid uniformGrid;
uniformGrid.Set(mesh.vert.begin(), mesh.vert.end()); uniformGrid.Set(mesh.vert.begin(), mesh.vert.end());
std::cout << "Build: " << time.elapsed() << " ms" << std::endl; std::cout << "Build: " << elapsed(t0) << " ms" << std::endl;
// Test with the radius search // Test with the radius search
std::cout << "Radius search (" << num_test << " tests)"<< std::endl; std::cout << "Radius search (" << num_test << " tests)"<< std::endl;
float avgTime = 0.0f; float avgTime = 0.0f;
for (int ii = 0; ii < num_test; ii++) for (int ii = 0; ii < num_test; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points); vcg::tri::GetInSphereVertex(mesh, uniformGrid, mesh.vert[test_indeces[ii]].cP(), queryDist, vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl; std::cout << "Time (radius = " << queryDist << "): " << avgTime << " ms (mean " << avgTime / num_test << "ms)" << std::endl;
@ -383,12 +379,12 @@ void testOctree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
std::vector<CMesh::VertexPointer> vertexPtr; std::vector<CMesh::VertexPointer> vertexPtr;
std::vector<CMesh::VertexType::CoordType> points; std::vector<CMesh::VertexType::CoordType> points;
std::vector<float> dists; std::vector<float> dists;
vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points); vcg::tri::GetKClosestVertex(mesh, uniformGrid, kNearest, mesh.vert[test_indeces[ii]].cP(), mesh.bbox.Diag(), vertexPtr, dists, points);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl; std::cout << "Time (k = " << kNearest << "): " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl;
@ -397,10 +393,10 @@ void testOctree(CMesh& mesh, std::vector<unsigned int>& test_indeces, std::vecto
avgTime = 0.0f; avgTime = 0.0f;
for (int ii = 0; ii < num_test * 10; ii++) for (int ii = 0; ii < num_test * 10; ii++)
{ {
time.restart(); t0=clock();
float minDist; float minDist;
vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist); vcg::tri::GetClosestVertex(mesh, uniformGrid, randomSamples[ii], mesh.bbox.Diag(), minDist);
avgTime += time.elapsed(); avgTime += elapsed(t0);
} }
std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl; std::cout << "Time : " << avgTime << " ms (mean " << avgTime / (num_test * 10) << "ms)" << std::endl << std::endl;
} }
@ -424,7 +420,7 @@ int main( int argc, char * argv[] )
randGen.initialize(0); randGen.initialize(0);
std::vector<vcg::Point3f> randomSamples; std::vector<vcg::Point3f> randomSamples;
for (int i = 0; i < num_test * 10; i++) for (int i = 0; i < num_test * 10; i++)
randomSamples.push_back(vcg::math::GeneratePointOnUnitSphereUniform<float>(randGen) * randGen.generate01() * mesh.bbox.Diag() / ratio); randomSamples.push_back(vcg::math::GeneratePointOnUnitSphereUniform<float>(randGen) * randGen.generate01() * mesh.bbox.Diag() / bboxratio);
std::vector<unsigned int> test_indeces; std::vector<unsigned int> test_indeces;
for (int i = 0; i < num_test * 10; i++) for (int i = 0; i < num_test * 10; i++)

View File

@ -1,22 +1,4 @@
include(../common.pri) include(../common.pri)
TARGET = kdTree_test TARGET = kdTree_test
HEADERS = nanoflann.hpp
SOURCES = trimesh_indexing.cpp \ SOURCES = trimesh_indexing.cpp \
../../../wrap/ply/plylib.cpp ../../../wrap/ply/plylib.cpp
win32-msvc2010:QMAKE_CXXFLAGS += /openmp
win32-msvc2012:QMAKE_CXXFLAGS += /openmp
win32-g++:QMAKE_CXXFLAGS += -fopenmp
win32-g++:QMAKE_LIB += -lgomp
mac-g++:QMAKE_CXXFLAGS += -fopenmp
mac-g++:QMAKE_LIB += -lgomp
win32{
DEFINES += NOMINMAX
}

View File

@ -70,11 +70,10 @@ int main( int argc, char **argv )
float radius = m.bbox.Diag() * perc; float radius = m.bbox.Diag() * perc;
printf("Subsampling a PointCloud of %i vert with %f radius\n",m.VN(),radius); printf("Subsampling a PointCloud of %i vert with %f radius\n",m.VN(),radius);
tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam pp; tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam pp;
tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskParam::Stat pds; pp.pds=&pds;
pp.bestSampleChoiceFlag=false; pp.bestSampleChoiceFlag=false;
tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskPruning(mps, m, radius, pp); tri::SurfaceSampling<MyMesh,tri::MeshSampler<MyMesh> >::PoissonDiskPruning(mps, m, radius, pp);
tri::io::ExporterPLY<MyMesh>::Save(subM,"PoissonMesh.ply"); tri::io::ExporterPLY<MyMesh>::Save(subM,"PoissonMesh.ply");
printf("Sampled %i vertices in %5.2f\n",subM.VN(), float(pds.pruneTime+pds.gridTime)/float(CLOCKS_PER_SEC)); printf("Sampled %i vertices in %5.2f\n",subM.VN(), float(pp.pds.pruneTime+pp.pds.gridTime)/float(CLOCKS_PER_SEC));
int t0=clock(); int t0=clock();
tri::Clustering<MyMesh, vcg::tri::AverageColorCell<MyMesh> > ClusteringGrid; tri::Clustering<MyMesh, vcg::tri::AverageColorCell<MyMesh> > ClusteringGrid;