trimesh_kdtree.cpp
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004-2012                                           \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
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 }


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:38:20