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
00034 #include<vcg/complex/complex.h>
00035
00036 #include<wrap/io_trimesh/import.h>
00037 #include<wrap/io_trimesh/export.h>
00038 #include <vcg/space/index/kdtree/kdtree.h>
00039 #include<vcg/complex/algorithms/update/normal.h>
00040 #include<vcg/complex/algorithms/update/color.h>
00041
00042 using namespace vcg;
00043 using namespace std;
00044
00045 class MyEdge;
00046 class MyFace;
00047 class MyVertex;
00048 struct MyUsedTypes : public UsedTypes< Use<MyVertex> ::AsVertexType,
00049 Use<MyEdge> ::AsEdgeType,
00050 Use<MyFace> ::AsFaceType>{};
00051
00052 class MyVertex : public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Qualityf, vertex::Color4b, vertex::BitFlags >{};
00053 class MyFace : public Face< MyUsedTypes, face::VertexRef, face::BitFlags > {};
00054 class MyEdge : public Edge<MyUsedTypes>{};
00055 class MyMesh : public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
00056
00057 int main( int argc, char **argv )
00058 {
00059 if(argc<2) argv[1]="../../meshes/torus_irregular.ply";
00060
00061 MyMesh m;
00062 if(tri::io::Importer<MyMesh>::Open(m,argv[1])!=0)
00063 {
00064 printf("Error reading file %s\n",argv[1]);
00065 exit(0);
00066 }
00067
00068 VertexConstDataWrapper<MyMesh> ww(m);
00069
00070 KdTree<float> tree(ww);
00071 KdTree<float>::PriorityQueue queue;
00072
00073 for (int j = 0; j < m.VN(); j++) {
00074 tree.doQueryK(m.vert[j].cP(), 3, queue);
00075 int neighbours = queue.getNofElements();
00076 float avgDist=0;
00077 for (int i = 0; i < neighbours; i++) {
00078 int neightId = queue.getIndex(i);
00079 avgDist += Distance(m.vert[j].cP(),m.vert[neightId].cP());
00080 }
00081 m.vert[j].Q() = avgDist/=neighbours;
00082 }
00083 tri::UpdateColor<MyMesh>::PerVertexQualityRamp(m);
00084 tri::io::ExporterPLY<MyMesh>::Save(m,"out.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);
00085 return 0;
00086 }