Debian Codegraph @

vcg/wrap/io_tetramesh/export_ts.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
26 $Log: export_ts.h,v $
27 Revision 1.2 2005/12/06 10:42:59 ganovelli
28 minor bug
29
30 Revision 1.1 2004/10/11 17:41:41 ganovelli
31 added
32
33 Revision 1.1 2004/06/03 13:16:32 ganovelli
34 created
35
36 Revision 1.3 2004/05/10 13:14:28 ganovelli
37 converted to library style (namespaces etc..)
38
39
40 ****************************************************************************/
41 #ifndef __VCGLIB_EXPORTERSMF
42 #define __VCGLIB_EXPORTERSMF
43
44 #include <vcg/space/point3.h>
45
46 namespace vcg {
47 namespace tetra {
48 namespace io {
49
50 template <typename MESHTYPE>
51 struct ExporterTS{
52
53 typedef typename MESHTYPE::VertexPointer VertexPointer;
54 typedef typename MESHTYPE::VertexType VertexType;
55 typedef typename MESHTYPE::TetraType FaceType;
56 typedef typename MESHTYPE::VertexIterator VertexIterator;
57 typedef typename MESHTYPE::TetraIterator TetraIterator;
58 typedef typename MESHTYPE::ScalarType ScalarType;
59 typedef Point3<ScalarType> Point3x;
60
61 static FILE *& F(){static FILE * f; return f;}
62
63 inline static void WritePos(const Point3<ScalarType> &p){
64 fprintf(F(),"%g %g %g\n",p[0],p[1],p[2]);
65 }
66 inline static void WritePos(const Point4<ScalarType> &p){
67 fprintf(F(),"%g %g %g %g\n",p[0],p[1],p[2],p[3]);
68 }
69
70
71
72 static int Save( MESHTYPE & m, const char * filename )
73 {
74
75 F() = fopen(filename,"w");
76 if(F() == NULL )
77 {
78 printf( "The file could not be opened\n" );
79 return -1;
80 }
81 else
82 {
83 fprintf(F(), "%i\n", m.vn );
84 fprintf(F(), "%i\n", m.tn );
85 VertexIterator vi;
86 for (vi = m.vert.begin(); vi != m.vert.end();++vi)
87 //fprintf(F(), "%f %f %f \n", (*vi).P()[0],(*vi).P()[1],(*vi).P()[2] );
88 WritePos((*vi).P());
89
90 TetraIterator ti;
91 for( ti = m.tetra.begin(); ti != m.tetra.end(); ++ti)
92 fprintf(F(), "%d %d %d %d \n",
93 (*ti).V(0)-&*m.vert.begin(),
94 (*ti).V(1)-&*m.vert.begin(),
95 (*ti).V(2)-&*m.vert.begin(),
96 (*ti).V(3)-&*m.vert.begin());
97 }
98 return 0;
99 }
100 };// end class
101 };// end of io
102 };// end of tri
103 };// end of vcg
104
105 #endif
106