Debian Codegraph @

vcg/wrap/io_trimesh/export_vmi.h

raw symbols SCIP
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004 \/)\/ *
6 * Visual Computing Lab /\/| *
7 * ISTI - Italian National Research Council | *
8 * \ *
9 * All rights reserved. *
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 * This program is distributed in the hope that it will be useful, *
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) *
20 * for more details. *
21 * *
22 ****************************************************************************/
23
24 /****************************************************************************
25 History
26
27 $Log: export_vmi.h,v $
28 Revision 1.2 2007/02/21 10:18:24 ganovelli
29 moved the vn and fn in the writig of the header
30
31 Revision 1.1 2007/02/14 01:20:37 ganovelli
32 working draft of VCG Mesh Image importer and exporter. Does not consider optional attributes. The mesh atributes are only vn and fn (no bbox, texture coordiantes)
33
34
35
36 ****************************************************************************/
37
38 #ifndef __VCGLIB_EXPORT_VMI
39 #define __VCGLIB_EXPORT_VMI
40
41 /*
42 VMI VCG Mesh Image.
43 The vmi image file consists of a header containing the description of the vertex and face type,
44 the length of vectors containing vertices of faces and the memory image of the object mesh as it is when
45 passed to the function Save(SaveMeshType m)
46 */
47
48 namespace vcg {
49 namespace tri {
50 namespace io {
51
52 template <class SaveMeshType>
53 class ExporterVMI
54 {
55 public:
56 typedef typename SaveMeshType::FaceIterator FaceIterator;
57 typedef typename SaveMeshType::VertexIterator VertexIterator;
58 typedef typename SaveMeshType::VertexType VertexType;
59
60 static void Save(const SaveMeshType &m,char * filename){
61 unsigned int i;
62 int vertSize,faceSize;
63 FILE * f = fopen(filename,"wb");
64 std::vector<string> nameF,nameV;
65 SaveMeshType::FaceType::Name(nameF);
66 SaveMeshType::VertexType::Name(nameV);
67 vertSize = m.vert.size();
68 faceSize = m.face.size();
69
70 /* write header */
71 fprintf(f,"FACE_TYPE %d\n",nameF.size());
72 for(i=0; i < nameF.size(); ++i) fprintf(f,"%s\n",nameF[i].c_str());
73 fprintf(f,"SIZE_VECTOR_FACES %d\n",faceSize);
74
75 fprintf(f,"VERTEX_TYPE %d\n",nameV.size());
76 for(i=0; i < nameV.size(); ++i) fprintf(f,"%s\n",nameV[i].c_str());
77 fprintf(f,"SIZE_VECTOR_VERTS %d\n",vertSize);
78 fprintf(f,"end_header\n");
79
80
81 unsigned int offsetV = (unsigned int) &m.vert[0];
82 /* write the address of the first vertex */
83 fwrite(&offsetV,sizeof(unsigned int),1,f);
84
85 int offsetF= ( int) &m.face[0];
86 /* write the address of the first face */
87 fwrite(&offsetF,sizeof( int),1,f);
88
89 /* save the object mesh */
90 fwrite(&m,sizeof(SaveMeshType),1,f);
91
92 int written;
93 /* save the vertices */
94 written = fwrite((void*)&m.vert[0],sizeof(SaveMeshType::VertexType),m.vert.size(),f);
95 assert(written==m.vert.size());
96
97 /* save the faces */
98 written = fwrite((void*)&m.face[0],sizeof(SaveMeshType::FaceType),m.face.size(),f);
99 assert(written==m.face.size());
100
101 // fflush(f);
102 fclose(f);
103 }
104
105 }; // end class
106
107 } // end Namespace tri
108 } // end Namespace io
109 } // end Namespace vcg
110
111 #endif