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 #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
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 }