Debian Codegraph @

vcg/wrap/io_trimesh/export.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.h,v $
28 Revision 1.7 2008/04/15 10:38:12 cignoni
29 added suppor of color in OFF format.
30
31 Revision 1.6 2006/11/04 14:01:00 granzuglia
32 fixed bug: &(*filename.end()) ---> &(*filename.rbegin())
33
34 Revision 1.5 2006/07/09 05:32:15 cignoni
35 Uncommented obj export. Now obj saving is enabled by default
36
37 Revision 1.4 2006/03/29 08:14:20 corsini
38 Add LoadMask to OFF importer
39
40 Revision 1.3 2006/02/16 19:28:36 fmazzant
41 transfer of Export_3ds.h, Export_obj.h, Io_3ds_obj_material.h from Meshlab to vcg
42
43 Revision 1.2 2006/01/13 15:47:42 cignoni
44 Uniformed return type to the style of Open. Now every export function returns 0 in case of success.
45
46 Revision 1.1 2005/11/12 18:34:17 cignoni
47 Initial Commit
48
49
50 ****************************************************************************/
51
52 #ifndef __VCGLIB_TRIMESH_GENERIC_EXPORT
53 #define __VCGLIB_TRIMESH_GENERIC_EXPORT
54
55 #include <wrap/io_trimesh/export_ply.h>
56 #include <wrap/io_trimesh/export_stl.h>
57 #include <wrap/io_trimesh/export_off.h>
58 #include <wrap/io_trimesh/export_dxf.h>
59 #include <wrap/io_trimesh/export_obj.h>
60
61 #include <locale>
62
63 namespace vcg {
64 namespace tri {
65 namespace io {
66
67 /**
68 This class encapsulate a filter for automatically importing meshes by guessing
69 the right filter according to the extension
70 */
71
72 template <class OpenMeshType>
73 class Exporter
74 {
75 private:
76 enum KnownTypes { KT_UNKNOWN, KT_PLY, KT_STL, KT_DXF, KT_OFF, KT_OBJ};
77 static int &LastType()
78 {
79 static int lastType= KT_UNKNOWN;
80 return lastType;
81 }
82
83 public:
84 // simple aux function that returns true if a given file has a given extesnion
85 static bool FileExtension(std::string filename, std::string extension)
86 {
87 std::locale loc1 ;
88 std::use_facet<std::ctype<char> > ( loc1 ).tolower(&*filename.begin(),&(*filename.rbegin()));
89 std::use_facet<std::ctype<char> > ( loc1 ).tolower(&*extension.begin(),&(*extension.rbegin()));
90 std::string end=filename.substr(filename.length()-extension.length(),extension.length());
91 return end==extension;
92 }
93 // Open Mesh
94 static int Save(OpenMeshType &m, const char *filename, CallBackPos *cb=0)
95 {
96 return Save(m,filename,0,cb);
97 }
98
99 // Open Mesh
100 static int Save(OpenMeshType &m, const char *filename, const int mask, CallBackPos *cb=0)
101 {
102 int err;
103 if(FileExtension(filename,"ply"))
104 {
105 err = ExporterPLY<OpenMeshType>::Save(m,filename,mask);
106 LastType()=KT_PLY;
107 }
108 else if(FileExtension(filename,"stl"))
109 {
110 err = ExporterSTL<OpenMeshType>::Save(m,filename);
111 LastType()=KT_STL;
112 }
113 else if(FileExtension(filename,"off"))
114 {
115 err = ExporterOFF<OpenMeshType>::Save(m,filename,mask);
116 LastType()=KT_OFF;
117 }
118 else if(FileExtension(filename,"dxf"))
119 {
120 err = ExporterDXF<OpenMeshType>::Save(m,filename);
121 LastType()=KT_DXF;
122 }
123 else if(FileExtension(filename,"obj"))
124 {
125 err = ExporterOBJ<OpenMeshType>::Save(m,filename,mask,cb);
126 LastType()=KT_OBJ;
127 }
128 else {
129 err=1;
130 LastType()=KT_UNKNOWN;
131 }
132
133 return err;
134 }
135
136 static const char *ErrorMsg(int error)
137 {
138 switch(LastType())
139 {
140 case KT_PLY : return ExporterPLY<OpenMeshType>::ErrorMsg(error); break;
141 case KT_STL : return ExporterSTL<OpenMeshType>::ErrorMsg(error); break;
142 case KT_OFF : return ExporterOFF<OpenMeshType>::ErrorMsg(error); break;
143 case KT_DXF : return ExporterDXF<OpenMeshType>::ErrorMsg(error); break;
144 case KT_OBJ : return ExporterOBJ<OpenMeshType>::ErrorMsg(error); break;
145 }
146 return "Unknown type";
147 }
148
149 }; // end class
150 } // end Namespace tri
151 } // end Namespace io
152 } // end Namespace vcg
153
154 #endif