Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <sstream>
//#include <strstream>
const int MAX = 1024 ;
int is_blank_line( char* line )
{
enum {LINE, BLANK};
int status = BLANK ;
char* p = NULL ;
if ( line[0] == '\0' ) {
status = BLANK ;
return status ;
} else if ( strlen( line ) == 0 ) {
status = BLANK ;
return status ;
}
for ( p = line; ( *p != '\0' || *p != '\n' ) ; p++ )
{
char c = *p ;
if ( !isspace( c ) ){
status = LINE ;
break ;
}
}
return status ;
}
int main( int argc, char* argv[])
{
char buf [MAX];
if( argc != 2 ) {
cerr << "USAGE: dawn_brep_converter old-format-file";
cerr << endl;
exit(1);
}
// input stream
ifstream input ( argv[1] ) ;
// states
int in_vertex = 0 ;
int in_facet = 0 ;
while( input.getline( buf, MAX ) )
{
if ( is_blank_line( buf ) ) {
cout << endl;
}
else if ( !strncmp( buf, "/Brep" , 5 ) )
{
cout << "/Polyhedron" << endl;
} else if ( !strncmp( buf, "/EndBrep" , 8 ) )
{
cout << "/EndPolyhedron" << endl;
} else if ( !strncmp( buf, "BeginVertex", 11 ) ||\
!strncmp( buf, "Vertex:" , 7 ) )
{
in_vertex = 1 ;
} else if ( !strncmp( buf, "EndVertex" , 9 ) ||\
!strncmp( buf, "end_Vertex", 10 ) )
{
in_vertex = 0 ;
} else if ( !strncmp( buf, "BeginFacet" , 10) ||\
!strncmp( buf, "Facet:" , 6) )
{
in_facet = 1 ;
} else if ( !strncmp( buf, "EndFacet" , 8) ||\
!strncmp( buf, "end_Facet" , 9) )
{
in_facet = 0 ;
} else if ( in_vertex ) {
int dummy;
double x, y, z ;
sscanf( buf, "%d %lg %lg %lg", &dummy, &x, &y, &z );
cout << "/Vertex" << " " ;
cout << x << " " ;
cout << y << " " ;
cout << z << endl;
} else if ( in_facet ) {
int flabel ;
char* p = buf ;
cout << "/Facet ";
// istrstream str_in ( buf ) ;
istringstream str_in ( buf ) ;
while ( str_in >> flabel ) {
cout << flabel << " " ;
}
cout << endl;
} else {
cout << buf << endl;
}
}
input.close();
}