Debian Codegraph @

vcg/wrap/io_trimesh/export_dxf.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_dxf.h,v $
26 Revision 1.8 2006/11/21 19:23:50 e_cerisoli
27 Added comments for documentation
28
29 ****************************************************************************/
30
31 #ifndef __VCGLIB_EXPORT_DXF
32 #define __VCGLIB_EXPORT_DXF
33
34 namespace vcg {
35 namespace tri {
36 namespace io {
37
38 template <class SaveMeshType>
39 /**
40 This class encapsulate a filter for save dxf meshes.
41 */
42 class ExporterDXF
43 {
44 public:
45 ///Standard call for saving a mesh
46 static int Save(SaveMeshType &m, const char * filename)
47 {
48
49 FILE * o = fopen(filename,"w");
50 if(o==NULL) return 1;
51 fprintf(o,"0\n");
52 fprintf(o,"SECTION\n");
53 fprintf(o,"2\n");
54 fprintf(o,"ENTITIES\n");
55
56 typename SaveMeshType::FaceIterator fi;
57 for(fi=m.face.begin(); fi!=m.face.end(); ++fi)
58 {
59 if (!fi->IsD())
60 {
61 typename SaveMeshType::CoordType v0 = (*fi).V(0)->P();
62 typename SaveMeshType::CoordType v1 = (*fi).V(1)->P();
63 typename SaveMeshType::CoordType v2 = (*fi).V(2)->P();
64 fprintf(o,"0\n"); fprintf(o,"3DFACE\n"); fprintf(o,"8\n"); fprintf(o,"0\n");
65 fprintf(o,"10\n"); fprintf(o,"%f\n", v0[0]); //X
66 fprintf(o,"20\n"); fprintf(o,"%f\n", v0[1]); //Y
67 fprintf(o,"30\n"); fprintf(o,"%f\n", v0[2]); //Z
68
69 fprintf(o,"11\n"); fprintf(o,"%f\n", v1[0]); //X
70 fprintf(o,"21\n"); fprintf(o,"%f\n", v1[1]); //Y
71 fprintf(o,"31\n"); fprintf(o,"%f\n", v1[2]); //Z
72
73 fprintf(o,"12\n"); fprintf(o,"%f\n", v2[0]); //X
74 fprintf(o,"22\n"); fprintf(o,"%f\n", v2[1]); //Y
75 fprintf(o,"32\n"); fprintf(o,"%f\n", v2[2]); //Z
76
77 fprintf(o,"13\n"); fprintf(o,"%f\n", v2[0]); //X
78 fprintf(o,"23\n"); fprintf(o,"%f\n", v2[1]); //Y
79 fprintf(o,"33\n"); fprintf(o,"%f\n", v2[2]); //Z
80 }
81 }
82
83 fprintf(o,"0\n");
84 fprintf(o,"ENDSEC\n");
85 fprintf(o,"0\n");
86 fprintf(o,"EOF\n");
87 fclose(o);
88 return 0;
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> dxf_error_msg;
94 if(dxf_error_msg.empty())
95 {
96 dxf_error_msg.resize(2 );
97 dxf_error_msg[0]="No errors";
98 dxf_error_msg[1]="Can't open file";
99 }
100
101 if(error>1 || error<0) return "Unknown error";
102 else return dxf_error_msg[error].c_str();
103 }
104
105
106 }; // end class
107
108 } // end Namespace tri
109 } // end Namespace io
110 } // end Namespace vcg
111
112 #endif