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
00024 #include <stdio.h>
00025 #include <vcg/complex/complex.h>
00026 #include <vcg/complex/algorithms/create/zonohedron.h>
00027 #include <vcg/complex/algorithms/polygon_support.h>
00028 #include <wrap/io_trimesh/export_off.h>
00029
00030
00031
00032 class MyVertex;
00033 class MyEdge;
00034 class MyFace;
00035
00036 struct MyUsedTypes: public vcg::UsedTypes<vcg::Use<MyVertex>::AsVertexType,vcg::Use<MyEdge>::AsEdgeType,vcg::Use<MyFace>::AsFaceType>{};
00037
00038 class MyVertex : public vcg::Vertex< MyUsedTypes,vcg::vertex::Coord3f,vcg::vertex::BitFlags >{};
00039
00040 class MyEdge : public vcg::Edge< MyUsedTypes > {};
00041
00042 class MyFace : public vcg::Face< MyUsedTypes,
00043 vcg::face::FFAdj,
00044 vcg::face::VertexRef,
00045 vcg::face::Normal3f,
00046 vcg::face::BitFlags > {};
00047
00048
00049 class MyMesh : public vcg::tri::TriMesh<std::vector<MyVertex>, std::vector<MyFace> > {};
00050
00051
00052
00053
00054 void example1(){
00055
00056 vcg::tri::Zonohedron<float> z;
00057 z.addVector( 0,0,1 );
00058 z.addVector( 0,1,0 );
00059 z.addVector( 1,0,0 );
00060
00061 MyMesh m;
00062 z.createMesh(m);
00063
00064 vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
00065
00066 int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL;
00067 vcg::tri::io::ExporterOFF<MyMesh>::Save(m,"cube.off",savemask);
00068 }
00069
00070
00071
00072 void example2(){
00073
00074 FILE* f = fopen("input.txt","rt");
00075 if (!f) return;
00076
00077 while (1) {
00078
00079
00080 char meshFilename[1024], fullMeshFilename[1024];
00081 if (fscanf(f,"%s",meshFilename)!=1) break;
00082 sprintf(fullMeshFilename,"%s.off",meshFilename);
00083
00084
00085 vcg::tri::Zonohedron<float> z;
00086 while (1) {
00087 float a,b,c;
00088 if (fscanf(f,"%f %f %f",&a, &b, &c)!=3) break;
00089 z.addVector(a,b,c);
00090 }
00091
00092 printf("Building %s from %d vectors...\n",fullMeshFilename, z.vectors().size() );
00093
00094 MyMesh m;
00095 z.createMesh(m);
00096
00097 vcg::tri::UpdateTopology<MyMesh>::FaceFace(m);
00098
00099
00100
00101 vcg::tri::PolygonSupport<MyMesh,int>::MergeFlatFaces(m);
00102
00103 int savemask = vcg::tri::io::Mask::IOM_BITPOLYGONAL;
00104 vcg::tri::io::ExporterOFF<MyMesh>::Save(m,fullMeshFilename,savemask);
00105 }
00106
00107 }
00108
00109 int main(int argc, char *argv[]){
00110 example1();
00111 example2();
00112 return 0;
00113 }