34 #include<vcg/complex/complex.h>
36 #include<wrap/io_trimesh/import.h>
37 #include<wrap/io_trimesh/export.h>
38 #include <vcg/space/index/kdtree/kdtree.h>
39 #include<vcg/complex/algorithms/update/normal.h>
40 #include<vcg/complex/algorithms/update/color.h>
48 struct MyUsedTypes :
public UsedTypes< Use<MyVertex> ::AsVertexType,
49 Use<MyEdge> ::AsEdgeType,
50 Use<MyFace> ::AsFaceType>{};
52 class MyVertex :
public Vertex<MyUsedTypes, vertex::Coord3f, vertex::Normal3f, vertex::Qualityf, vertex::Color4b, vertex::BitFlags >{};
53 class MyFace :
public Face< MyUsedTypes, face::VertexRef, face::BitFlags > {};
54 class MyEdge :
public Edge<MyUsedTypes>{};
55 class MyMesh :
public tri::TriMesh< vector<MyVertex>, vector<MyFace> , vector<MyEdge> > {};
57 int main(
int argc,
char **argv )
59 if(argc<2) argv[1]=(
char *)
"../../meshes/torus_irregular.ply";
62 if(tri::io::Importer<MyMesh>::Open(m,argv[1])!=0)
64 printf(
"Error reading file %s\n",argv[1]);
68 VertexConstDataWrapper<MyMesh> ww(m);
70 KdTree<float> tree(ww);
71 KdTree<float>::PriorityQueue queue;
73 for (
int j = 0; j < m.VN(); j++) {
74 tree.doQueryK(m.vert[j].cP(), 3, queue);
75 int neighbours = queue.getNofElements();
77 for (
int i = 0; i < neighbours; i++) {
78 int neightId = queue.getIndex(i);
79 avgDist += Distance(m.vert[j].cP(),m.vert[neightId].cP());
81 m.vert[j].Q() = avgDist/=neighbours;
84 tri::io::ExporterPLY<MyMesh>::Save(m,
"out.ply",tri::io::Mask::IOM_VERTCOLOR+tri::io::Mask::IOM_VERTQUALITY);