commit | author | age
|
854cb6
|
1 |
#include<stdio.h> |
SP |
2 |
#include<general.h> |
|
3 |
#include<snapshot.h> |
22721d
|
4 |
#include<stdlib.h> |
SP |
5 |
#include<stdarg.h> |
|
6 |
#include <zlib.h> |
|
7 |
ts_uint ts_sprintf(ts_string *str, char *fmt, ...){ |
|
8 |
va_list ap; |
|
9 |
va_start(ap,fmt); |
|
10 |
ts_uint n=vsprintf(&(str->string[str->beg]),fmt,ap); |
|
11 |
va_end(ap); |
|
12 |
str->beg+=n; |
|
13 |
return n; |
|
14 |
} |
|
15 |
|
|
16 |
|
854cb6
|
17 |
ts_bool xml_trisurf_data(FILE *fh, ts_vesicle *vesicle){ |
22721d
|
18 |
|
SP |
19 |
ts_string *data=(ts_string *)malloc(sizeof(ts_sprintf)); |
|
20 |
data->string=(char *)malloc(512000*sizeof(char)); /*TODO: warning, can break if the string is to long */ |
|
21 |
data->beg=0; |
|
22 |
|
854cb6
|
23 |
xml_trisurf_header(fh, vesicle); |
22721d
|
24 |
xml_trisurf_tria(data,vesicle->tlist); |
SP |
25 |
xml_trisurf_tria_neigh(data,vesicle->tlist); |
|
26 |
xml_trisurf_vtx_neigh(data,vesicle->vlist); |
|
27 |
xml_trisurf_vtx_tristar(data,vesicle->vlist); |
|
28 |
#ifdef COMPRESSION |
|
29 |
z_stream defstream; |
|
30 |
defstream.zalloc = Z_NULL; |
|
31 |
defstream.zfree = Z_NULL; |
|
32 |
defstream.opaque = Z_NULL; |
|
33 |
defstream.avail_in = data->beg+1; |
|
34 |
defstream.next_in = (unsigned char *)data->string; |
|
35 |
char *compr=(char *)malloc((data->beg+1)*sizeof(char *)); |
|
36 |
defstream.avail_out = data->beg+1; |
|
37 |
defstream.next_out = (unsigned char *)compr; |
|
38 |
deflateInit(&defstream, Z_BEST_COMPRESSION); |
|
39 |
deflate(&defstream, Z_FINISH); |
|
40 |
deflateEnd(&defstream); |
|
41 |
fwrite(compr, sizeof(unsigned char), defstream.total_out, fh); |
|
42 |
// fprintf(fh,"%s",compr); |
|
43 |
//printf("Uncompressed size is: %lu\n", defstream.total_out); |
|
44 |
free(compr); |
|
45 |
#else |
|
46 |
fprintf(fh,"%s", data->string); |
|
47 |
#endif |
|
48 |
free(data->string); |
|
49 |
free(data); |
854cb6
|
50 |
xml_trisurf_footer(fh); |
SP |
51 |
return TS_SUCCESS; |
|
52 |
} |
|
53 |
|
|
54 |
ts_bool xml_trisurf_header(FILE *fh, ts_vesicle *vesicle){ |
|
55 |
fprintf(fh, "<trisurf nvtx=\"%u\" npoly=\"%u\" nfono=\"%u\">\n", vesicle->vlist->n, vesicle->poly_list->n, vesicle->poly_list->poly[0]->vlist->n); |
|
56 |
return TS_SUCCESS; |
|
57 |
} |
|
58 |
|
|
59 |
ts_bool xml_trisurf_footer(FILE *fh){ |
|
60 |
fprintf(fh, "</trisurf>\n"); |
|
61 |
return TS_SUCCESS; |
|
62 |
} |
|
63 |
|
22721d
|
64 |
ts_bool xml_trisurf_tria(ts_string *data, ts_triangle_list *tlist){ |
854cb6
|
65 |
ts_uint i; |
22721d
|
66 |
ts_sprintf(data,"<tria>\n"); |
854cb6
|
67 |
for(i=0; i<tlist->n;i++){ |
22721d
|
68 |
ts_sprintf(data,"%u %u %u\n",tlist->tria[i]->vertex[0]->idx, tlist->tria[i]->vertex[1]->idx, tlist->tria[i]->vertex[2]->idx); |
854cb6
|
69 |
} |
22721d
|
70 |
ts_sprintf(data,"</tria>\n"); |
854cb6
|
71 |
return TS_SUCCESS; |
SP |
72 |
} |
|
73 |
|
22721d
|
74 |
ts_bool xml_trisurf_tria_neigh(ts_string *data, ts_triangle_list *tlist){ |
854cb6
|
75 |
ts_uint i; |
22721d
|
76 |
ts_sprintf(data,"<trianeigh>\n"); |
854cb6
|
77 |
for(i=0; i<tlist->n;i++){ |
22721d
|
78 |
ts_sprintf(data,"%u %u %u\n",tlist->tria[i]->neigh[0]->idx, tlist->tria[i]->neigh[1]->idx, tlist->tria[i]->neigh[2]->idx); |
854cb6
|
79 |
} |
22721d
|
80 |
ts_sprintf(data,"</trianeigh>\n"); |
854cb6
|
81 |
return TS_SUCCESS; |
SP |
82 |
} |
|
83 |
|
22721d
|
84 |
ts_bool xml_trisurf_vtx_neigh(ts_string *data, ts_vertex_list *vlist){ |
854cb6
|
85 |
ts_uint i,j; |
SP |
86 |
for(i=0;i<vlist->n;i++){ |
22721d
|
87 |
ts_sprintf(data,"<vtxn idx=\"%u\">",vlist->vtx[i]->idx); |
854cb6
|
88 |
for(j=0;j<vlist->vtx[i]->neigh_no;j++){ |
22721d
|
89 |
ts_sprintf(data,"%u ",vlist->vtx[i]->neigh[j]->idx); |
854cb6
|
90 |
} |
22721d
|
91 |
ts_sprintf(data, "</vtxn>\n"); |
854cb6
|
92 |
} |
SP |
93 |
return TS_SUCCESS; |
|
94 |
} |
|
95 |
|
22721d
|
96 |
ts_bool xml_trisurf_vtx_tristar(ts_string *data, ts_vertex_list *vlist){ |
854cb6
|
97 |
ts_uint i,j; |
SP |
98 |
for(i=0;i<vlist->n;i++){ |
22721d
|
99 |
ts_sprintf(data,"<tristar idx=\"%u\">",vlist->vtx[i]->idx); |
854cb6
|
100 |
for(j=0;j<vlist->vtx[i]->tristar_no;j++){ |
22721d
|
101 |
ts_sprintf(data,"%u ",vlist->vtx[i]->tristar[j]->idx); |
854cb6
|
102 |
} |
22721d
|
103 |
ts_sprintf(data, "</tristar>\n"); |
854cb6
|
104 |
} |
SP |
105 |
return TS_SUCCESS; |
|
106 |
} |
|
107 |
|