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" |
8c1bb1
|
12 |
ts_bool parseDump(char *dumpfname) { |
SP |
13 |
xmlDocPtr doc; |
|
14 |
xmlNodePtr cur; |
|
15 |
ts_vesicle *vesicle; |
|
16 |
|
|
17 |
doc = xmlParseFile(dumpfname); |
|
18 |
|
|
19 |
if (doc == NULL ) { |
|
20 |
fatal("Dump file could not be found or parsed. It is correct file?",1); |
|
21 |
} |
|
22 |
|
|
23 |
cur = xmlDocGetRootElement(doc); |
|
24 |
|
|
25 |
if (cur == NULL) { |
|
26 |
fatal("Dump file is empty.",1); |
|
27 |
} |
|
28 |
|
|
29 |
if (xmlStrcmp(cur->name, (const xmlChar *) "VTKFile")) { |
|
30 |
fatal("document of the wrong type, root node != story",1); |
|
31 |
} |
|
32 |
|
|
33 |
cur = cur->xmlChildrenNode; |
|
34 |
while (cur != NULL) { |
|
35 |
if ((!xmlStrcmp(cur->name, (const xmlChar *)"trisurf"))){ |
3c772b
|
36 |
vesicle=parseTrisurfTag(doc, cur); |
8c1bb1
|
37 |
} |
SP |
38 |
|
|
39 |
cur = cur->next; |
|
40 |
} |
|
41 |
|
|
42 |
xmlFreeDoc(doc); |
|
43 |
fprintf(stderr,"Restoration completed\n"); |
|
44 |
exit(0); |
3c772b
|
45 |
vesicle_free(vesicle); |
8c1bb1
|
46 |
return TS_SUCCESS; |
SP |
47 |
} |
|
48 |
|
|
49 |
ts_vesicle *parseTrisurfTag(xmlDocPtr doc, xmlNodePtr cur){ |
|
50 |
fprintf(stderr,"Parsing trisurf tag\n"); |
487968
|
51 |
xmlNodePtr child; |
SP |
52 |
|
|
53 |
#ifdef COMPRESS |
8c1bb1
|
54 |
/* base64decode */ |
SP |
55 |
size_t cLen; |
|
56 |
/*size_t tLen; |
|
57 |
const unsigned char test[]="Test"; |
|
58 |
char *cTest=base64_encode(test, 4,&tLen); |
|
59 |
unsigned char *cuTest=base64_decode((char *)cTest,tLen,&tLen); |
|
60 |
cuTest[tLen]=0; |
|
61 |
fprintf(stderr,"%s\n",cuTest); |
|
62 |
*/ |
|
63 |
xmlChar *b64=xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
64 |
unsigned char *compressed=base64_decode((char *)b64,strlen((char *)b64)-1,&cLen); |
|
65 |
/* uncompress */ |
|
66 |
unsigned char *subtree=(unsigned char *)malloc(512000*sizeof(unsigned char)); /* TODO: again, the uncompressed string must not exceed this */ |
|
67 |
z_stream infstream; |
|
68 |
infstream.zalloc = Z_NULL; |
|
69 |
infstream.zfree = Z_NULL; |
|
70 |
infstream.opaque = Z_NULL; |
|
71 |
infstream.avail_in = (ts_uint)cLen; // size of input |
|
72 |
infstream.next_in = compressed; // input char array |
|
73 |
infstream.avail_out = (ts_uint)512000; // size of output |
|
74 |
infstream.next_out = subtree; // output char array |
|
75 |
|
|
76 |
// the actual DE-compression work. |
|
77 |
inflateInit(&infstream); |
|
78 |
inflate(&infstream, Z_NO_FLUSH); |
|
79 |
inflateEnd(&infstream); |
|
80 |
fprintf(stderr,"%lu\n",cLen); |
|
81 |
subtree[infstream.total_out]='\0'; //zero terminate string |
|
82 |
fprintf(stderr,"%s\n",subtree); |
|
83 |
|
|
84 |
free(subtree); |
487968
|
85 |
#endif |
8c1bb1
|
86 |
/*parse xml subtree */ |
SP |
87 |
xmlChar *nvtx, *npoly, *nfono; |
|
88 |
nvtx = xmlGetProp(cur, (xmlChar *)"nvtx"); |
|
89 |
npoly=xmlGetProp(cur, (xmlChar *)"npoly"); |
|
90 |
nfono=xmlGetProp(cur, (xmlChar *)"nfono"); |
|
91 |
fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx)); |
|
92 |
ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),10,10,10,0.1); |
|
93 |
//vesicle->poly_list=init_poly_list(atoi((char *)npoly),atoi((char *)nmono), vesicle->vlist, vesicle); |
|
94 |
xmlFree(nvtx); |
|
95 |
xmlFree(npoly); |
|
96 |
xmlFree(nfono); |
487968
|
97 |
|
SP |
98 |
child = cur->xmlChildrenNode; |
|
99 |
while (child != NULL) { |
|
100 |
if ((!xmlStrcmp(child->name, (const xmlChar *)"vtxn"))){ |
|
101 |
parseTrisurfVtxn(vesicle->vlist, doc, child); |
|
102 |
} |
|
103 |
|
|
104 |
child = child->next; |
|
105 |
} |
|
106 |
|
|
107 |
|
|
108 |
|
8c1bb1
|
109 |
return vesicle; |
SP |
110 |
} |
487968
|
111 |
|
SP |
112 |
ts_bool *parseTrisurfVtxn(ts_vertex_list *vlist, xmlDocPtr doc, xmlNodePtr cur){ |
|
113 |
|
|
114 |
xmlChar *chari; |
|
115 |
xmlChar *neighs; |
|
116 |
char *n; |
|
117 |
char *token; |
|
118 |
ts_uint neighi; |
|
119 |
ts_uint i; |
|
120 |
chari = xmlGetProp(cur, (xmlChar *)"idx"); |
|
121 |
i=atoi((char *)chari); |
|
122 |
xmlFree(chari); |
|
123 |
ts_vertex *vtx=vlist->vtx[i]; |
|
124 |
neighs = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
|
125 |
//fprintf(stderr,"Found neigh for vtx %u that seems to have index %u with neighs=%s\n",i,vtx->idx,neighs); |
|
126 |
|
|
127 |
n=(char *)neighs; |
|
128 |
token=strtok(n," "); |
|
129 |
while(token!=NULL){ |
|
130 |
neighi=atoi(token); |
|
131 |
//fprintf(stderr,"%u", neighi); |
|
132 |
vtx_add_neighbour(vtx,vlist->vtx[neighi]); |
|
133 |
token=strtok(NULL," "); |
|
134 |
} |
|
135 |
xmlFree(neighs); |
|
136 |
return TS_SUCCESS; |
|
137 |
} |
|
138 |
|