trimesh_harmonic.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-2009                                           \/)\/    *
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 ****************************************************************************/
00023 #include<vcg/complex/complex.h>
00024 #include<wrap/io_trimesh/import_ply.h>
00025 #include<wrap/io_trimesh/export_ply.h>
00026 #include<vcg/complex/algorithms/update/color.h>
00027 #include<vcg/complex/algorithms/update/quality.h>
00028 #include<vcg/complex/algorithms/harmonic.h>
00029 
00030 
00031 using namespace vcg;
00032 using namespace std;
00033 
00034 class MyFace;
00035 class MyVertex;
00036 struct MyUsedTypes : public UsedTypes<  Use<MyVertex>   ::AsVertexType,
00037                                         Use<MyFace>     ::AsFaceType>{};
00038 
00039 class MyVertex  : public Vertex<MyUsedTypes,  vertex::Coord3f, vertex::Normal3f, vertex::VFAdj, vertex::Qualityf, vertex::Color4b, vertex::BitFlags  >{};
00040 class MyFace    : public Face< MyUsedTypes,   face::VertexRef, face::Normal3f, face::Mark, face::BitFlags, face::VFAdj, face::FFAdj > {};
00041 class MyMesh    : public tri::TriMesh< vector<MyVertex>, vector<MyFace>   > {};
00042 
00043 
00044 
00045 
00046 int main( int argc, char **argv )
00047 {
00048   MyMesh m;
00049   if(argc < 2 )
00050   {
00051     printf("Usage: trimesh_harmonic mesh.ply\n");
00052     return -1;
00053   }
00054 
00055   int ret= tri::io::ImporterPLY<MyMesh>::Open(m,argv[1]);
00056   if(ret!=0)
00057   {
00058     printf("Unable to open %s for '%s'\n",argv[1],tri::io::ImporterPLY<MyMesh>::ErrorMsg(ret));
00059     return -1;
00060   }
00061 
00062   tri::UpdateTopology<MyMesh>::FaceFace(m);
00063 
00064 
00065   srand(time(0));
00066   int ind0=rand()%m.vn;
00067   int ind1=rand()%m.vn;
00068   printf("Computing harmonic field from vertex %i to vertex %i\n",ind0,ind1);
00069 
00070   // Get the two vertices with value set
00071   tri::Harmonic<MyMesh, double>::ConstraintVec constraints;
00072   constraints.push_back(tri::Harmonic<MyMesh, double>::Constraint(&(m.vert[ind0]), 1.0f));
00073   constraints.push_back(tri::Harmonic<MyMesh, double>::Constraint(&(m.vert[ind1]), 2.0f));
00074 
00075   MyMesh::PerVertexAttributeHandle<double> handle = tri::Allocator<MyMesh>::GetPerVertexAttribute<double>(m, "harmonic");
00076   bool ok = tri::Harmonic<MyMesh, double>::ComputeScalarField(m, constraints, handle);
00077   assert(ok);
00078 
00079   tri::UpdateQuality<MyMesh>::VertexFromAttributeHandle(m,handle);
00080   tri::UpdateColor<MyMesh>::PerVertexQualityRamp(m,1,2);
00081   tri::io::ExporterPLY<MyMesh>::Save(m,"harmonic.ply",tri::io::Mask::IOM_VERTCOLOR | tri::io::Mask::IOM_VERTQUALITY);
00082 
00083   return 0;
00084 }


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