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; |
8fa1c0
|
16 |
xmlNodePtr cur, cur1,cur2; |
SP |
17 |
ts_vesicle *vesicle=NULL; |
8c1bb1
|
18 |
|
SP |
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 |
} |
8fa1c0
|
40 |
// START Point Position data & Bonds |
SP |
41 |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"UnstructuredGrid"))){ |
|
42 |
cur1 = cur->xmlChildrenNode; |
|
43 |
while(cur1!=NULL){ |
|
44 |
if ((!xmlStrcmp(cur1->name, (const xmlChar *)"Piece"))){ |
|
45 |
cur2=cur1->xmlChildrenNode; |
|
46 |
while(cur2!=NULL){ |
|
47 |
if ((!xmlStrcmp(cur2->name, (const xmlChar *)"Points"))){ |
|
48 |
fprintf(stderr,"Found point data\n"); |
|
49 |
if(vesicle!=NULL) |
|
50 |
parseXMLVertexPosition(vesicle, doc, cur); |
|
51 |
} |
|
52 |
if ((!xmlStrcmp(cur2->name, (const xmlChar *)"Cells"))){ |
|
53 |
fprintf(stderr,"Found cell(Bonds) data\n"); |
|
54 |
} |
|
55 |
cur2=cur2->next; |
|
56 |
} |
|
57 |
} |
|
58 |
cur1 = cur1->next; |
|
59 |
} |
|
60 |
} |
|
61 |
// END Point Position data & Bonds |
8c1bb1
|
62 |
cur = cur->next; |
SP |
63 |
} |
|
64 |
|
|
65 |
xmlFreeDoc(doc); |
|
66 |
fprintf(stderr,"Restoration completed\n"); |
|
67 |
exit(0); |
3c772b
|
68 |
vesicle_free(vesicle); |
8c1bb1
|
69 |
return TS_SUCCESS; |
SP |
70 |
} |
|
71 |
|
8fa1c0
|
72 |
|
SP |
73 |
|
|
74 |
/* this is a parser of additional data in xml */ |
8c1bb1
|
75 |
ts_vesicle *parseTrisurfTag(xmlDocPtr doc, xmlNodePtr cur){ |
SP |
76 |
fprintf(stderr,"Parsing trisurf tag\n"); |
487968
|
77 |
xmlNodePtr child; |
SP |
78 |
|
|
79 |
#ifdef COMPRESS |
8c1bb1
|
80 |
/* base64decode */ |
SP |
81 |
size_t cLen; |
|
82 |
/*size_t tLen; |
|
83 |
const unsigned char test[]="Test"; |
|
84 |
char *cTest=base64_encode(test, 4,&tLen); |
|
85 |
unsigned char *cuTest=base64_decode((char *)cTest,tLen,&tLen); |
|
86 |
cuTest[tLen]=0; |
|
87 |
fprintf(stderr,"%s\n",cuTest); |
|
88 |
*/ |
|
89 |
xmlChar *b64=xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
90 |
unsigned char *compressed=base64_decode((char *)b64,strlen((char *)b64)-1,&cLen); |
|
91 |
/* uncompress */ |
|
92 |
unsigned char *subtree=(unsigned char *)malloc(512000*sizeof(unsigned char)); /* TODO: again, the uncompressed string must not exceed this */ |
|
93 |
z_stream infstream; |
|
94 |
infstream.zalloc = Z_NULL; |
|
95 |
infstream.zfree = Z_NULL; |
|
96 |
infstream.opaque = Z_NULL; |
|
97 |
infstream.avail_in = (ts_uint)cLen; // size of input |
|
98 |
infstream.next_in = compressed; // input char array |
|
99 |
infstream.avail_out = (ts_uint)512000; // size of output |
|
100 |
infstream.next_out = subtree; // output char array |
|
101 |
|
|
102 |
// the actual DE-compression work. |
|
103 |
inflateInit(&infstream); |
|
104 |
inflate(&infstream, Z_NO_FLUSH); |
|
105 |
inflateEnd(&infstream); |
|
106 |
fprintf(stderr,"%lu\n",cLen); |
|
107 |
subtree[infstream.total_out]='\0'; //zero terminate string |
|
108 |
fprintf(stderr,"%s\n",subtree); |
|
109 |
|
|
110 |
free(subtree); |
487968
|
111 |
#endif |
8c1bb1
|
112 |
/*parse xml subtree */ |
SP |
113 |
xmlChar *nvtx, *npoly, *nfono; |
|
114 |
nvtx = xmlGetProp(cur, (xmlChar *)"nvtx"); |
|
115 |
npoly=xmlGetProp(cur, (xmlChar *)"npoly"); |
|
116 |
nfono=xmlGetProp(cur, (xmlChar *)"nfono"); |
|
117 |
fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx)); |
|
118 |
ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),10,10,10,0.1); |
|
119 |
//vesicle->poly_list=init_poly_list(atoi((char *)npoly),atoi((char *)nmono), vesicle->vlist, vesicle); |
|
120 |
xmlFree(nvtx); |
|
121 |
xmlFree(npoly); |
|
122 |
xmlFree(nfono); |
487968
|
123 |
|
SP |
124 |
child = cur->xmlChildrenNode; |
|
125 |
while (child != NULL) { |
|
126 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"vtxn"))){ |
|
127 |
parseTrisurfVtxn(vesicle->vlist, doc, child); |
|
128 |
} |
a011d2
|
129 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"tria"))){ |
SP |
130 |
parseTrisurfTria(vesicle, doc, child); |
|
131 |
} |
|
132 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"tristar"))){ |
|
133 |
parseTrisurfTristar(vesicle, doc, child); |
|
134 |
} |
|
135 |
|
487968
|
136 |
child = child->next; |
SP |
137 |
} |
|
138 |
|
|
139 |
|
|
140 |
|
8c1bb1
|
141 |
return vesicle; |
SP |
142 |
} |
487968
|
143 |
|
a011d2
|
144 |
|
SP |
145 |
|
|
146 |
/* Low level tags parsers */ |
|
147 |
|
|
148 |
ts_bool parseTrisurfVtxn(ts_vertex_list *vlist, xmlDocPtr doc, xmlNodePtr cur){ |
487968
|
149 |
|
SP |
150 |
xmlChar *chari; |
|
151 |
xmlChar *neighs; |
|
152 |
char *n; |
|
153 |
char *token; |
|
154 |
ts_uint neighi; |
|
155 |
ts_uint i; |
|
156 |
chari = xmlGetProp(cur, (xmlChar *)"idx"); |
|
157 |
i=atoi((char *)chari); |
|
158 |
xmlFree(chari); |
|
159 |
ts_vertex *vtx=vlist->vtx[i]; |
|
160 |
neighs = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
161 |
//fprintf(stderr,"Found neigh for vtx %u that seems to have index %u with neighs=%s\n",i,vtx->idx,neighs); |
|
162 |
|
|
163 |
n=(char *)neighs; |
|
164 |
token=strtok(n," "); |
|
165 |
while(token!=NULL){ |
|
166 |
neighi=atoi(token); |
|
167 |
//fprintf(stderr,"%u", neighi); |
|
168 |
vtx_add_neighbour(vtx,vlist->vtx[neighi]); |
|
169 |
token=strtok(NULL," "); |
|
170 |
} |
|
171 |
xmlFree(neighs); |
|
172 |
return TS_SUCCESS; |
|
173 |
} |
|
174 |
|
a011d2
|
175 |
ts_bool parseTrisurfTria(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
SP |
176 |
xmlChar *triangles; |
|
177 |
char *tria; |
|
178 |
char *vtx[3]; |
|
179 |
|
|
180 |
ts_uint i; |
|
181 |
triangles = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
182 |
tria=(char *)triangles; |
|
183 |
for(i=0;i<3;i++) vtx[i]=strtok(tria," "); |
|
184 |
while(vtx[2]!=NULL){ |
|
185 |
triangle_add(vesicle->tlist, vesicle->vlist->vtx[atoi(vtx[0])],vesicle->vlist->vtx[atoi(vtx[1])],vesicle->vlist->vtx[atoi(vtx[2])]); |
|
186 |
for(i=0;i<3;i++) vtx[i]=strtok(NULL," "); |
|
187 |
} |
|
188 |
|
|
189 |
xmlFree(triangles); |
|
190 |
return TS_SUCCESS; |
|
191 |
} |
|
192 |
|
|
193 |
|
|
194 |
ts_bool parseTrisurfTristar(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
|
195 |
|
|
196 |
xmlChar *chari; |
|
197 |
xmlChar *tristar; |
|
198 |
char *t; |
|
199 |
char *token; |
|
200 |
ts_uint neighi; |
|
201 |
ts_uint i; |
|
202 |
chari = xmlGetProp(cur, (xmlChar *)"idx"); |
|
203 |
i=atoi((char *)chari); |
|
204 |
xmlFree(chari); |
|
205 |
ts_vertex *vtx=vesicle->vlist->vtx[i]; |
|
206 |
tristar = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
207 |
// fprintf(stderr,"Found tristar for vtx %u that seems to have index %u with tristar=%s\n",i,vtx->idx,tristar); |
|
208 |
|
|
209 |
t=(char *)tristar; |
|
210 |
token=strtok(t," "); |
|
211 |
while(token!=NULL){ |
|
212 |
neighi=atoi(token); |
|
213 |
//fprintf(stderr,"%u", neighi); |
|
214 |
vertex_add_tristar(vtx,vesicle->tlist->tria[neighi]); |
|
215 |
token=strtok(NULL," "); |
|
216 |
} |
|
217 |
xmlFree(tristar); |
|
218 |
return TS_SUCCESS; |
|
219 |
} |
|
220 |
|
8fa1c0
|
221 |
|
SP |
222 |
/* this is a parser of vertex positions and bonds from main xml data */ |
|
223 |
ts_bool parseXMLVertexPosition(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur){ |
|
224 |
xmlNodePtr child = cur->xmlChildrenNode; |
|
225 |
xmlChar *points; |
|
226 |
char *pts; |
|
227 |
int i, idx; |
|
228 |
char *token[3]; |
|
229 |
while (child != NULL) { |
|
230 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"DataArray"))){ |
|
231 |
points = xmlNodeListGetString(doc, child->xmlChildrenNode, 1); |
|
232 |
pts=(char *)points; |
|
233 |
for(i=0;i<3;i++) token[i]=strtok(pts," "); |
|
234 |
idx=0; |
|
235 |
while(token[0]!=NULL){ |
|
236 |
vesicle->vlist->vtx[idx]->x=atof(token[0]); |
|
237 |
vesicle->vlist->vtx[idx]->y=atof(token[1]); |
|
238 |
vesicle->vlist->vtx[idx]->z=atof(token[2]); |
|
239 |
for(i=0;i<3;i++) token[i]=strtok(NULL," "); |
|
240 |
idx++; |
|
241 |
} |
|
242 |
xmlFree(points); |
|
243 |
} |
|
244 |
child=child->next; |
|
245 |
} |
|
246 |
return TS_SUCCESS; |
|
247 |
} |
|
248 |
|
|
249 |
|