commit | author | age
|
8c1bb1
|
1 |
#include <stdio.h> |
SP |
2 |
#include <string.h> |
|
3 |
#include <stdlib.h> |
|
4 |
#include <libxml/xmlmemory.h> |
|
5 |
#include <libxml/parser.h> |
|
6 |
#include <general.h> |
|
7 |
#include <restore.h> |
|
8 |
#include <snapshot.h> |
|
9 |
#include <zlib.h> |
|
10 |
#include "vesicle.h" |
487968
|
11 |
#include "vertex.h" |
a011d2
|
12 |
#include "triangle.h" |
SP |
13 |
|
8c1bb1
|
14 |
ts_bool parseDump(char *dumpfname) { |
SP |
15 |
xmlDocPtr doc; |
|
16 |
xmlNodePtr cur; |
|
17 |
ts_vesicle *vesicle; |
|
18 |
|
|
19 |
doc = xmlParseFile(dumpfname); |
|
20 |
|
|
21 |
if (doc == NULL ) { |
|
22 |
fatal("Dump file could not be found or parsed. It is correct file?",1); |
|
23 |
} |
|
24 |
|
|
25 |
cur = xmlDocGetRootElement(doc); |
|
26 |
|
|
27 |
if (cur == NULL) { |
|
28 |
fatal("Dump file is empty.",1); |
|
29 |
} |
|
30 |
|
|
31 |
if (xmlStrcmp(cur->name, (const xmlChar *) "VTKFile")) { |
|
32 |
fatal("document of the wrong type, root node != story",1); |
|
33 |
} |
|
34 |
|
|
35 |
cur = cur->xmlChildrenNode; |
|
36 |
while (cur != NULL) { |
|
37 |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"trisurf"))){ |
3c772b
|
38 |
vesicle=parseTrisurfTag(doc, cur); |
8c1bb1
|
39 |
} |
SP |
40 |
|
|
41 |
cur = cur->next; |
|
42 |
} |
|
43 |
|
|
44 |
xmlFreeDoc(doc); |
|
45 |
fprintf(stderr,"Restoration completed\n"); |
|
46 |
exit(0); |
3c772b
|
47 |
vesicle_free(vesicle); |
8c1bb1
|
48 |
return TS_SUCCESS; |
SP |
49 |
} |
|
50 |
|
|
51 |
ts_vesicle *parseTrisurfTag(xmlDocPtr doc, xmlNodePtr cur){ |
|
52 |
fprintf(stderr,"Parsing trisurf tag\n"); |
487968
|
53 |
xmlNodePtr child; |
SP |
54 |
|
|
55 |
#ifdef COMPRESS |
8c1bb1
|
56 |
/* base64decode */ |
SP |
57 |
size_t cLen; |
|
58 |
/*size_t tLen; |
|
59 |
const unsigned char test[]="Test"; |
|
60 |
char *cTest=base64_encode(test, 4,&tLen); |
|
61 |
unsigned char *cuTest=base64_decode((char *)cTest,tLen,&tLen); |
|
62 |
cuTest[tLen]=0; |
|
63 |
fprintf(stderr,"%s\n",cuTest); |
|
64 |
*/ |
|
65 |
xmlChar *b64=xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
66 |
unsigned char *compressed=base64_decode((char *)b64,strlen((char *)b64)-1,&cLen); |
|
67 |
/* uncompress */ |
|
68 |
unsigned char *subtree=(unsigned char *)malloc(512000*sizeof(unsigned char)); /* TODO: again, the uncompressed string must not exceed this */ |
|
69 |
z_stream infstream; |
|
70 |
infstream.zalloc = Z_NULL; |
|
71 |
infstream.zfree = Z_NULL; |
|
72 |
infstream.opaque = Z_NULL; |
|
73 |
infstream.avail_in = (ts_uint)cLen; // size of input |
|
74 |
infstream.next_in = compressed; // input char array |
|
75 |
infstream.avail_out = (ts_uint)512000; // size of output |
|
76 |
infstream.next_out = subtree; // output char array |
|
77 |
|
|
78 |
// the actual DE-compression work. |
|
79 |
inflateInit(&infstream); |
|
80 |
inflate(&infstream, Z_NO_FLUSH); |
|
81 |
inflateEnd(&infstream); |
|
82 |
fprintf(stderr,"%lu\n",cLen); |
|
83 |
subtree[infstream.total_out]='\0'; //zero terminate string |
|
84 |
fprintf(stderr,"%s\n",subtree); |
|
85 |
|
|
86 |
free(subtree); |
487968
|
87 |
#endif |
8c1bb1
|
88 |
/*parse xml subtree */ |
SP |
89 |
xmlChar *nvtx, *npoly, *nfono; |
|
90 |
nvtx = xmlGetProp(cur, (xmlChar *)"nvtx"); |
|
91 |
npoly=xmlGetProp(cur, (xmlChar *)"npoly"); |
|
92 |
nfono=xmlGetProp(cur, (xmlChar *)"nfono"); |
|
93 |
fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx)); |
|
94 |
ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),10,10,10,0.1); |
|
95 |
//vesicle->poly_list=init_poly_list(atoi((char *)npoly),atoi((char *)nmono), vesicle->vlist, vesicle); |
|
96 |
xmlFree(nvtx); |
|
97 |
xmlFree(npoly); |
|
98 |
xmlFree(nfono); |
487968
|
99 |
|
SP |
100 |
child = cur->xmlChildrenNode; |
|
101 |
while (child != NULL) { |
|
102 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"vtxn"))){ |
|
103 |
parseTrisurfVtxn(vesicle->vlist, doc, child); |
|
104 |
} |
a011d2
|
105 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"tria"))){ |
SP |
106 |
parseTrisurfTria(vesicle, doc, child); |
|
107 |
} |
|
108 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"tristar"))){ |
|
109 |
parseTrisurfTristar(vesicle, doc, child); |
|
110 |
} |
|
111 |
|
487968
|
112 |
child = child->next; |
SP |
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
|
8c1bb1
|
117 |
return vesicle; |
SP |
118 |
} |
487968
|
119 |
|
a011d2
|
120 |
|
SP |
121 |
|
|
122 |
/* Low level tags parsers */ |
|
123 |
|
|
124 |
ts_bool parseTrisurfVtxn(ts_vertex_list *vlist, xmlDocPtr doc, xmlNodePtr cur){ |
487968
|
125 |
|
SP |
126 |
xmlChar *chari; |
|
127 |
xmlChar *neighs; |
|
128 |
char *n; |
|
129 |
char *token; |
|
130 |
ts_uint neighi; |
|
131 |
ts_uint i; |
|
132 |
chari = xmlGetProp(cur, (xmlChar *)"idx"); |
|
133 |
i=atoi((char *)chari); |
|
134 |
xmlFree(chari); |
|
135 |
ts_vertex *vtx=vlist->vtx[i]; |
|
136 |
neighs = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
137 |
//fprintf(stderr,"Found neigh for vtx %u that seems to have index %u with neighs=%s\n",i,vtx->idx,neighs); |
|
138 |
|
|
139 |
n=(char *)neighs; |
|
140 |
token=strtok(n," "); |
|
141 |
while(token!=NULL){ |
|
142 |
neighi=atoi(token); |
|
143 |
//fprintf(stderr,"%u", neighi); |
|
144 |
vtx_add_neighbour(vtx,vlist->vtx[neighi]); |
|
145 |
token=strtok(NULL," "); |
|
146 |
} |
|
147 |
xmlFree(neighs); |
|
148 |
return TS_SUCCESS; |
|
149 |
} |
|
150 |
|
a011d2
|
151 |
ts_bool parseTrisurfTria(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
SP |
152 |
xmlChar *triangles; |
|
153 |
char *tria; |
|
154 |
char *vtx[3]; |
|
155 |
|
|
156 |
ts_uint i; |
|
157 |
triangles = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
158 |
tria=(char *)triangles; |
|
159 |
for(i=0;i<3;i++) vtx[i]=strtok(tria," "); |
|
160 |
while(vtx[2]!=NULL){ |
|
161 |
triangle_add(vesicle->tlist, vesicle->vlist->vtx[atoi(vtx[0])],vesicle->vlist->vtx[atoi(vtx[1])],vesicle->vlist->vtx[atoi(vtx[2])]); |
|
162 |
for(i=0;i<3;i++) vtx[i]=strtok(NULL," "); |
|
163 |
} |
|
164 |
|
|
165 |
xmlFree(triangles); |
|
166 |
return TS_SUCCESS; |
|
167 |
} |
|
168 |
|
|
169 |
|
|
170 |
ts_bool parseTrisurfTristar(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
|
171 |
|
|
172 |
xmlChar *chari; |
|
173 |
xmlChar *tristar; |
|
174 |
char *t; |
|
175 |
char *token; |
|
176 |
ts_uint neighi; |
|
177 |
ts_uint i; |
|
178 |
chari = xmlGetProp(cur, (xmlChar *)"idx"); |
|
179 |
i=atoi((char *)chari); |
|
180 |
xmlFree(chari); |
|
181 |
ts_vertex *vtx=vesicle->vlist->vtx[i]; |
|
182 |
tristar = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
183 |
// fprintf(stderr,"Found tristar for vtx %u that seems to have index %u with tristar=%s\n",i,vtx->idx,tristar); |
|
184 |
|
|
185 |
t=(char *)tristar; |
|
186 |
token=strtok(t," "); |
|
187 |
while(token!=NULL){ |
|
188 |
neighi=atoi(token); |
|
189 |
//fprintf(stderr,"%u", neighi); |
|
190 |
vertex_add_tristar(vtx,vesicle->tlist->tria[neighi]); |
|
191 |
token=strtok(NULL," "); |
|
192 |
} |
|
193 |
xmlFree(tristar); |
|
194 |
return TS_SUCCESS; |
|
195 |
} |
|
196 |
|