Debian Codegraph @

src/vcglib/wrap/io_trimesh/import_smf.h

raw symbols SCIP
1 /****************************************************************************
2 * VCGLib o o *
3 * Visual and Computer Graphics Library o o *
4 * _ O _ *
5 * Copyright(C) 2004-2016 \/)\/ *
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: not supported by cvs2svn $
26 ****************************************************************************/
27
28 #ifndef __VCGLIB_IMPORTER_SMF
29 #define __VCGLIB_IMPORTER_SMF
30
31 #include <stdio.h>
32 #include <vcg/space/point3.h>
33
34 namespace vcg {
35 namespace tri {
36 namespace io {
37 template<class OpenMeshType>
38 /**
39 This class encapsulate a filter for opening smf meshes.
40 */
41 class ImporterSMF
42 {
43 public:
44 typedef typename OpenMeshType::VertexPointer VertexPointer;
45 typedef typename OpenMeshType::ScalarType ScalarType;
46 typedef typename OpenMeshType::VertexType VertexType;
47 typedef typename OpenMeshType::FaceType FaceType;
48 typedef typename OpenMeshType::VertexIterator VertexIterator;
49 typedef typename OpenMeshType::FaceIterator FaceIterator;
50
51 // if it is binary there are 80 char of comment, the number fn of faces and then exactly fn*4*3 bytes.
52 enum {SMF_LABEL_SIZE=80};
53
54 class SMFFacet
55 {
56 public:
57 vcg::Point3f n;
58 vcg::Point3f v[3];
59 };
60
61 enum SMFError {
62 E_NOERROR, // 0
63 // Errori di open
64 E_CANTOPEN, // 1
65 E_UNESPECTEDEOF // 2
66 };
67
68 /// Standard call for knowing the meaning of an error code
69 static const char *ErrorMsg(int error)
70 {
71 static const char * smf_error_msg[] =
72 {
73 "No errors",
74 "Can't open file",
75 "Premature End of file",
76 };
77 if(error>2 || error<0) return "Unknown error";
78 else return smf_error_msg[error];
79 };
80 ///Standard call for reading a mesh
81 static int Open(OpenMeshType &m, const char * filename )
82 {
83 VertexType v;
84 FaceType f;
85 FILE *fp;
86 float x,y,z;
87 bool one = true;
88 std::map<int,VertexPointer> mv;
89 fp = fopen(filename,"r");
90 if(!fp) return -1;
91 char buf[1024];
92 while( fgets(buf,1024,fp) )
93 {
94 char *vf, *comm_pt;
95 if((comm_pt = strstr(buf,"#")) != NULL)
96 *comm_pt = '\0';
97 if( (vf = strstr(buf,"v")) != NULL )
98 {
99 sscanf(vf+1,"%f %f %f", &x, &y, &z);
100 v.P()[0] = x;
101 v.P()[1] = y;
102 v.P()[2] = z;
103 m.vert.push_back(v);
104 }
105 else if( (vf = strstr(buf,"f")) != NULL)
106 {
107 if(one)
108 {
109 VertexIterator vi;
110 int ind;
111 for(ind=1,vi=m.vert.begin(); vi!=m.vert.end(); ++vi,++ind)
112 mv[ind]=&*vi;
113 one = false;
114 }
115 int v1,v2,v3;
116 sscanf(vf+1,"%d %d %d", &v1, &v2, &v3);
117 f.V(0) = mv[v1];
118 f.V(1) = mv[v2];
119 f.V(2) = mv[v3];
120 m.face.push_back(f);
121 }
122 }
123 m.vn = m.vert.size();
124 m.fn = m.face.size();
125 return 0;
126 }
127 };
128 }// end of io
129 }// end of tri
130 }// end of vcg
131
132 #endif
133