Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include<vcg/complex/complex.h>
00024
00025 #include<wrap/io_trimesh/import_ply.h>
00026 #include<wrap/io_trimesh/export_ply.h>
00027
00028 #include<vcg/complex/algorithms/point_sampling.h>
00029 #include<vcg/complex/algorithms/geodesic.h>
00030 #include<vcg/complex/algorithms/update/color.h>
00031
00032 using namespace vcg;
00033 using namespace std;
00034
00035 class MyEdge;
00036 class MyFace;
00037 class MyVertex;
00038 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00039 Use<MyEdge> ::AsEdgeType,
00040 Use<MyFace> ::AsFaceType>{};
00041
00042 class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Mark, vertex::VFAdj, vertex::Color4b, vertex::Qualityf, vertex::BitFlags >{};
00043 class MyFace : public Face< MyUsedTypes, face::VFAdj, face::VertexRef, face::Normal3f, face::BitFlags > {};
00044 class MyEdge : public Edge<MyUsedTypes>{};
00045 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
00046
00047 int main( int argc, char **argv )
00048 {
00049 if(argc<2)
00050 {
00051 printf("Usage trimesh_geodesic <meshfilename.obj>\n");
00052
00053 }
00054
00055 MyMesh m;
00056
00057
00058 if(tri::io::ImporterPLY<MyMesh>::Open(m,"../../meshes/disk_irregular_650k.ply")!=0)
00059 {
00060 printf("Error reading file %s\n",argv[1]);
00061 exit(0);
00062 }
00063
00064 Point3f c=m.bbox.Center();
00065 MyVertex*closest=&*m.vert.begin();
00066 float minDist = Distance(closest->P(),c);
00067 for(MyMesh::VertexIterator vi=m.vert.begin();vi!=m.vert.end(); ++vi)
00068 {
00069 if(Distance(vi->P(),c)<minDist)
00070 {
00071 minDist = Distance(vi->P(),c);
00072 closest = &*vi;
00073 }
00074 }
00075 vector<MyVertex*> seedVec;
00076 seedVec.push_back(closest);
00077 tri::EuclideanDistance<MyMesh> ed;
00078 tri::Clean<MyMesh>::RemoveUnreferencedVertex(m);
00079 tri::Allocator<MyMesh>::CompactEveryVector(m);
00080 tri::UpdateTopology<MyMesh>::VertexFace(m);
00081 tri::Geodesic<MyMesh>::Compute(m,seedVec,ed);
00082 pair<float,float> minmax = tri::Stat<MyMesh>::ComputePerVertexQualityMinMax(m);
00083 tri::UpdateColor<MyMesh>::PerVertexQualityRamp(m);
00084 printf("min %f max %f\n",minmax.first,minmax.second);
00085 tri::io::ExporterPLY<MyMesh>::Save(m,"base.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
00086 int t0=clock();
00087 tri::Geodesic<MyMesh>::PerVertexDijsktraCompute(m,seedVec,ed);
00088 int t1=clock();
00089 printf("Geodesic dijkstra %6.3f\n",float(t1-t0)/CLOCKS_PER_SEC);
00090 tri::UpdateColor<MyMesh>::PerVertexQualityRamp(m);
00091 tri::io::ExporterPLY<MyMesh>::Save(m,"base_d.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
00092
00093 return 0;
00094 }