Debian Codegraph @

vcg/wrap/io_trimesh/export_smf.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 History
25 $Log: export_smf.h,v $
26 Revision 1.4 2007/04/16 08:37:53 cignoni
27 Removed garbage chars at the beginning of the file
28
29 Revision 1.3 2006/11/21 19:23:50 e_cerisoli
30 Added comments for documentation
31
32 Revision 1.2 2006/11/16 11:24:44
33 ****************************************************************************/
34
35 #ifndef __VCGLIB_EXPORT_SMF
36 #define __VCGLIB_EXPORT_SMF
37
38 #include <stdio.h>
39
40 namespace vcg {
41 namespace tri {
42 namespace io {
43
44 template <class SaveMeshType>
45 /**
46 This class encapsulate a filter for save smf meshes.
47 */
48 class ExporterSMF
49 {
50 public:
51 typedef typename SaveMeshType::VertexPointer VertexPointer;
52 typedef typename SaveMeshType::ScalarType ScalarType;
53 typedef typename SaveMeshType::VertexType VertexType;
54 typedef typename SaveMeshType::FaceType FaceType;
55 typedef typename SaveMeshType::VertexIterator VertexIterator;
56 typedef typename SaveMeshType::FaceIterator FaceIterator;
57
58 ///Standard call for saving a mesh
59 static int Save(SaveMeshType &m, const char * filename, const int &mask, CallBackPos *cb=0)
60 {
61 VertexIterator vi;
62 FaceIterator fi;
63 FILE *fp;
64 fp = fopen(filename,"wb");
65 fprintf(fp,"#SMF \n" );
66
67 std::map<VertexPointer,int> index;
68 int ind;
69
70 for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
71 {
72 fprintf(fp,"v " );
73 fprintf(fp,"%f%s",(*vi).P()[0]," " );
74 fprintf(fp,"%f%s",(*vi).P()[1]," " );
75 fprintf(fp,"%f%s",(*vi).P()[2],"\n");
76
77 index[&*vi] = ind;
78 }
79 for (fi=m.face.begin(); fi!=m.face.end(); ++fi)
80 {
81 fprintf(fp,"%s","f ");
82 for (int j = 0; j < 3; j++)
83 fprintf(fp,"%i%s",index[(*fi).V(j)]," ");
84 fprintf(fp,"%s","\n");
85 }
86 fclose(fp);
87 return 0;
88 }
89
90 /// Standard call for knowing the meaning of an error code
91 static const char *ErrorMsg(int error)
92 {
93 static std::vector<std::string> smf_error_msg;
94 if(smf_error_msg.empty())
95 {
96 smf_error_msg.resize(2 );
97 smf_error_msg[0]="No errors";
98 smf_error_msg[1]="Can't open file";
99 }
100
101 if(error>1 || error<0) return "Unknown error";
102 else return smf_error_msg[error].c_str();
103 }
104 }; // end class
105 } // end Namespace tri
106 } // end Namespace io
107 } // end Namespace vcg
108
109 #endif
110