| commit | author | age | ||
| 7f6076 | 1 | /* vim: set ts=4 sts=4 sw=4 noet : */ |
| 8c1bb1 | 2 | #include <stdio.h> |
| SP | 3 | #include <string.h> |
| 4 | #include <stdlib.h> | |
| 5 | #include <libxml/xmlmemory.h> | |
| 6 | #include <libxml/parser.h> | |
| 7 | #include <general.h> | |
| 8 | #include <restore.h> | |
| 9 | #include <snapshot.h> | |
| 1eb75b | 10 | #include <b64zlib_compression.h> |
| 8c1bb1 | 11 | #include "vesicle.h" |
| 487968 | 12 | #include "vertex.h" |
| a011d2 | 13 | #include "triangle.h" |
| a3dbf0 | 14 | #include "bond.h" |
| SP | 15 | #include "energy.h" |
| bb4033 | 16 | #include "poly.h" |
| a3dbf0 | 17 | #include "initial_distribution.h" |
| 698ae1 | 18 | #include "io.h" |
| 002513 | 19 | #include <math.h> |
| a011d2 | 20 | |
| ab798b | 21 | ts_vesicle *parseDump(char *dumpfname) { |
| 8c1bb1 | 22 | xmlDocPtr doc; |
| 8fa1c0 | 23 | xmlNodePtr cur, cur1,cur2; |
| SP | 24 | ts_vesicle *vesicle=NULL; |
| 8c1bb1 | 25 | doc = xmlParseFile(dumpfname); |
| 002513 | 26 | int i; |
| 8c1bb1 | 27 | if (doc == NULL ) { |
| SP | 28 | fatal("Dump file could not be found or parsed. It is correct file?",1); |
| 29 | } | |
| 30 | ||
| 31 | cur = xmlDocGetRootElement(doc); | |
| 32 | ||
| 33 | if (cur == NULL) { | |
| 34 | fatal("Dump file is empty.",1); | |
| 35 | } | |
| 36 | ||
| 37 | if (xmlStrcmp(cur->name, (const xmlChar *) "VTKFile")) { | |
| 38 | fatal("document of the wrong type, root node != story",1); | |
| 39 | } | |
| 40 | ||
| 41 | cur = cur->xmlChildrenNode; | |
| 42 | while (cur != NULL) { | |
| 698ae1 | 43 | |
| SP | 44 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"tape"))){ |
| 45 | setGlobalTapeTXTfromTapeTag(doc, cur); | |
| 46 | } | |
| 47 | ||
| 8c1bb1 | 48 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"trisurf"))){ |
| 3c772b | 49 | vesicle=parseTrisurfTag(doc, cur); |
| 8c1bb1 | 50 | } |
| 8fa1c0 | 51 | // START Point Position data & Bonds |
| SP | 52 | if ((!xmlStrcmp(cur->name, (const xmlChar *)"UnstructuredGrid"))){ |
| 53 | cur1 = cur->xmlChildrenNode; | |
| 54 | while(cur1!=NULL){ | |
| 55 | if ((!xmlStrcmp(cur1->name, (const xmlChar *)"Piece"))){ | |
| 56 | cur2=cur1->xmlChildrenNode; | |
| 57 | while(cur2!=NULL){ | |
| def8b5 | 58 | if ((!xmlStrcmp(cur2->name, (const xmlChar *)"PointData"))){ |
| SP | 59 | if(vesicle!=NULL) |
| 60 | parseXMLPointData(vesicle,doc,cur2); | |
| 61 | } | |
| 8fa1c0 | 62 | if ((!xmlStrcmp(cur2->name, (const xmlChar *)"Points"))){ |
| 720bd4 | 63 | //fprintf(stderr,"Found point data\n"); |
| 8fa1c0 | 64 | if(vesicle!=NULL) |
| f62178 | 65 | //fprintf(stderr,"Fils: %ld, Nfono: %ld\n", vesicle->tape->nfil, vesicle->tape->nfono); |
| 28efdb | 66 | parseXMLVertexPosition(vesicle, doc, cur2); |
| 8fa1c0 | 67 | } |
| SP | 68 | if ((!xmlStrcmp(cur2->name, (const xmlChar *)"Cells"))){ |
| 720bd4 | 69 | //fprintf(stderr,"Found cell(Bonds) data\n"); |
| a3dbf0 | 70 | if(vesicle!=NULL) |
| 28efdb | 71 | parseXMLBonds(vesicle, doc, cur2); |
| 8fa1c0 | 72 | } |
| SP | 73 | cur2=cur2->next; |
| 74 | } | |
| 75 | } | |
| 76 | cur1 = cur1->next; | |
| 77 | } | |
| 78 | } | |
| 79 | // END Point Position data & Bonds | |
| 8c1bb1 | 80 | cur = cur->next; |
| SP | 81 | } |
| 82 | xmlFreeDoc(doc); | |
| bb4033 | 83 | |
| 86b69b | 84 | // vesicle->poly_list=init_poly_list(0, 0, vesicle->vlist, vesicle); |
| d43116 | 85 | set_vesicle_values_from_tape(vesicle); |
| a3dbf0 | 86 | init_normal_vectors(vesicle->tlist); |
| SP | 87 | mean_curvature_and_energy(vesicle); |
| 89434d | 88 | sweep_attraction_bond_energy(vesicle); |
| 002513 | 89 | if(vesicle->tape->stretchswitch==1){ |
| 699ac4 | 90 | vesicle->tlist->a0=sqrt(3)/4.0*pow((vesicle->tape->dmax+1.0)/2.0,2); |
| 002513 | 91 | for(i=0;i<vesicle->tlist->n;i++){ |
| SP | 92 | stretchenergy(vesicle, vesicle->tlist->tria[i]); |
| 93 | } | |
| 94 | } | |
| ab798b | 95 | /* TODO: filaments */ |
| a3dbf0 | 96 | |
| f4d6ca | 97 | // ts_fprintf(stdout,"Restoration completed\n"); |
| ab798b | 98 | // write_vertex_xml_file(vesicle,999); |
| SP | 99 | // vesicle_free(vesicle); |
| 100 | // exit(0); | |
| 101 | return vesicle; | |
| 8c1bb1 | 102 | } |
| SP | 103 | |
| 698ae1 | 104 | ts_bool setGlobalTapeTXTfromTapeTag(xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 105 | xmlChar *tape = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
| 106 | strcpy(tapetxt,(char *)tape); | |
| 107 | xmlFree(tape); | |
| 108 | return TS_SUCCESS; | |
| 109 | } | |
| 8fa1c0 | 110 | |
| SP | 111 | |
| 112 | /* this is a parser of additional data in xml */ | |
| 8c1bb1 | 113 | ts_vesicle *parseTrisurfTag(xmlDocPtr doc, xmlNodePtr cur){ |
| 720bd4 | 114 | //fprintf(stderr,"Parsing trisurf tag\n"); |
| 487968 | 115 | xmlNodePtr child; |
| SP | 116 | |
| 117 | #ifdef COMPRESS | |
| 8c1bb1 | 118 | /* base64decode */ |
| SP | 119 | size_t cLen; |
| 120 | /*size_t tLen; | |
| 121 | const unsigned char test[]="Test"; | |
| 122 | char *cTest=base64_encode(test, 4,&tLen); | |
| 123 | unsigned char *cuTest=base64_decode((char *)cTest,tLen,&tLen); | |
| 124 | cuTest[tLen]=0; | |
| 125 | fprintf(stderr,"%s\n",cuTest); | |
| 126 | */ | |
| 127 | xmlChar *b64=xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); | |
| 128 | unsigned char *compressed=base64_decode((char *)b64,strlen((char *)b64)-1,&cLen); | |
| 129 | /* uncompress */ | |
| 130 | unsigned char *subtree=(unsigned char *)malloc(512000*sizeof(unsigned char)); /* TODO: again, the uncompressed string must not exceed this */ | |
| 131 | z_stream infstream; | |
| 132 | infstream.zalloc = Z_NULL; | |
| 133 | infstream.zfree = Z_NULL; | |
| 134 | infstream.opaque = Z_NULL; | |
| 135 | infstream.avail_in = (ts_uint)cLen; // size of input | |
| 136 | infstream.next_in = compressed; // input char array | |
| 137 | infstream.avail_out = (ts_uint)512000; // size of output | |
| 138 | infstream.next_out = subtree; // output char array | |
| 139 | ||
| 140 | // the actual DE-compression work. | |
| 141 | inflateInit(&infstream); | |
| 142 | inflate(&infstream, Z_NO_FLUSH); | |
| 143 | inflateEnd(&infstream); | |
| 720bd4 | 144 | //fprintf(stderr,"%lu\n",cLen); |
| 8c1bb1 | 145 | subtree[infstream.total_out]='\0'; //zero terminate string |
| 720bd4 | 146 | //fprintf(stderr,"%s\n",subtree); |
| 8c1bb1 | 147 | |
| SP | 148 | free(subtree); |
| 487968 | 149 | #endif |
| 8c1bb1 | 150 | /*parse xml subtree */ |
| 86b69b | 151 | xmlChar *nvtx, *npoly, *nmono; |
| 8c1bb1 | 152 | nvtx = xmlGetProp(cur, (xmlChar *)"nvtx"); |
| SP | 153 | npoly=xmlGetProp(cur, (xmlChar *)"npoly"); |
| 86b69b | 154 | nmono=xmlGetProp(cur, (xmlChar *)"nmono"); |
| 698ae1 | 155 | ts_tape *tape=parsetapebuffer(tapetxt); |
| SP | 156 | //fprintf(stderr,"nvtx=%u\n",atoi((char *)nvtx)); |
| 157 | //TODO: check if nvtx is in agreement with nshell from tape | |
| 158 | ts_vesicle *vesicle=init_vesicle(atoi((char *)nvtx),tape->ncxmax,tape->ncymax,tape->nczmax,tape->stepsize); | |
| d43116 | 159 | // vesicle->poly_list=init_poly_list(atoi((char *)npoly),atoi((char *)nmono), vesicle->vlist, vesicle); |
| SP | 160 | vesicle->poly_list=init_empty_poly_list(atoi((char *)npoly),atoi((char *)nmono)); |
| 8c1bb1 | 161 | xmlFree(nvtx); |
| SP | 162 | xmlFree(npoly); |
| 86b69b | 163 | xmlFree(nmono); |
| 487968 | 164 | |
| SP | 165 | child = cur->xmlChildrenNode; |
| 166 | while (child != NULL) { | |
| 167 | if ((!xmlStrcmp(child->name, (const xmlChar *)"vtxn"))){ | |
| 168 | parseTrisurfVtxn(vesicle->vlist, doc, child); | |
| 169 | } | |
| a011d2 | 170 | if ((!xmlStrcmp(child->name, (const xmlChar *)"tria"))){ |
| SP | 171 | parseTrisurfTria(vesicle, doc, child); |
| 172 | } | |
| e9ac7b | 173 | if ((!xmlStrcmp(child->name, (const xmlChar *)"trianeigh"))){ |
| SP | 174 | parseTrisurfTriaNeigh(vesicle, doc, child); |
| 175 | } | |
| a011d2 | 176 | if ((!xmlStrcmp(child->name, (const xmlChar *)"tristar"))){ |
| SP | 177 | parseTrisurfTristar(vesicle, doc, child); |
| 178 | } | |
| 4891eb | 179 | if ((!xmlStrcmp(child->name, (const xmlChar *)"nucleus"))){ |
| SP | 180 | parseTrisurfNucleus(vesicle, doc, child); |
| 181 | } | |
| 49981c | 182 | if ((!xmlStrcmp(child->name, (const xmlChar *)"constant_volume"))){ |
| SP | 183 | parseTrisurfConstantVolume(doc, child); |
| 184 | } | |
| 185 | if ((!xmlStrcmp(child->name, (const xmlChar *)"constant_area"))){ | |
| 186 | parseTrisurfConstantArea(doc, child); | |
| 187 | } | |
| 188 | ||
| a011d2 | 189 | |
| 487968 | 190 | child = child->next; |
| SP | 191 | } |
| 192 | ||
| 698ae1 | 193 | vesicle->tape=tape; |
| d43116 | 194 | // set_vesicle_values_from_tape(vesicle); |
| 8c1bb1 | 195 | return vesicle; |
| SP | 196 | } |
| 487968 | 197 | |
| a011d2 | 198 | |
| SP | 199 | |
| 200 | /* Low level tags parsers */ | |
| 49981c | 201 | ts_bool parseTrisurfConstantVolume(xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 202 | xmlChar *cvol = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
| 203 | char *n=(char *)cvol; | |
| 204 | V0=atof(n); | |
| 205 | xmlFree(cvol); | |
| 206 | return TS_SUCCESS; | |
| 207 | } | |
| 208 | ts_bool parseTrisurfConstantArea(xmlDocPtr doc, xmlNodePtr cur){ | |
| 209 | xmlChar *carea = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); | |
| 210 | char *n=(char *)carea; | |
| 211 | A0=atof(n); | |
| 212 | xmlFree(carea); | |
| 213 | return TS_SUCCESS; | |
| 214 | } | |
| 215 | ||
| 4891eb | 216 | ts_bool parseTrisurfNucleus(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 217 | xmlChar *coords = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
| 218 | char *n=(char *)coords; | |
| 219 | char *token=strtok(n," "); | |
| 220 | ts_uint i; | |
| 221 | for(i=0;i<3;i++){ | |
| 222 | vesicle->nucleus_center[i]=atof(token); | |
| 223 | token=strtok(NULL," "); | |
| 224 | } | |
| 225 | xmlFree(coords); | |
| 226 | return TS_SUCCESS; | |
| 227 | } | |
| a011d2 | 228 | |
| SP | 229 | ts_bool parseTrisurfVtxn(ts_vertex_list *vlist, xmlDocPtr doc, xmlNodePtr cur){ |
| 487968 | 230 | |
| SP | 231 | xmlChar *chari; |
| 232 | xmlChar *neighs; | |
| 233 | char *n; | |
| 234 | char *token; | |
| 235 | ts_uint neighi; | |
| 236 | ts_uint i; | |
| 237 | chari = xmlGetProp(cur, (xmlChar *)"idx"); | |
| 238 | i=atoi((char *)chari); | |
| 239 | xmlFree(chari); | |
| 240 | ts_vertex *vtx=vlist->vtx[i]; | |
| 241 | neighs = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); | |
| 242 | //fprintf(stderr,"Found neigh for vtx %u that seems to have index %u with neighs=%s\n",i,vtx->idx,neighs); | |
| 243 | ||
| 244 | n=(char *)neighs; | |
| 245 | token=strtok(n," "); | |
| 246 | while(token!=NULL){ | |
| 247 | neighi=atoi(token); | |
| 248 | //fprintf(stderr,"%u", neighi); | |
| 249 | vtx_add_neighbour(vtx,vlist->vtx[neighi]); | |
| 250 | token=strtok(NULL," "); | |
| 251 | } | |
| 252 | xmlFree(neighs); | |
| 253 | return TS_SUCCESS; | |
| 254 | } | |
| 255 | ||
| a011d2 | 256 | ts_bool parseTrisurfTria(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 257 | xmlChar *triangles; |
| 258 | char *tria; | |
| 259 | char *vtx[3]; | |
| 260 | ||
| e87e4e | 261 | ts_uint i,j; |
| a011d2 | 262 | triangles = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); |
| SP | 263 | tria=(char *)triangles; |
| e87e4e | 264 | vtx[0]=strtok(tria," "); |
| SP | 265 | for(i=1;i<3;i++) vtx[i]=strtok(NULL," "); |
| 266 | j=0; | |
| a011d2 | 267 | while(vtx[2]!=NULL){ |
| SP | 268 | triangle_add(vesicle->tlist, vesicle->vlist->vtx[atoi(vtx[0])],vesicle->vlist->vtx[atoi(vtx[1])],vesicle->vlist->vtx[atoi(vtx[2])]); |
| 269 | for(i=0;i<3;i++) vtx[i]=strtok(NULL," "); | |
| e87e4e | 270 | j++; |
| a011d2 | 271 | } |
| 720bd4 | 272 | //fprintf(stderr,"Parsing triangles %s j=%d\n",triangles,j); |
| a011d2 | 273 | |
| SP | 274 | xmlFree(triangles); |
| 275 | return TS_SUCCESS; | |
| 276 | } | |
| 277 | ||
| 278 | ||
| e9ac7b | 279 | ts_bool parseTrisurfTriaNeigh(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 280 | xmlChar *triangles; |
| 281 | char *tria; | |
| 282 | char *ntria[3]; | |
| 283 | ts_uint i,j; | |
| 284 | triangles = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); | |
| 285 | tria=(char *)triangles; | |
| e87e4e | 286 | ntria[0]=strtok(tria," "); |
| SP | 287 | for(i=1;i<3;i++) ntria[i]=strtok(NULL," "); |
| e9ac7b | 288 | j=0; |
| SP | 289 | while(ntria[2]!=NULL){ |
| 290 | triangle_add_neighbour(vesicle->tlist->tria[j],vesicle->tlist->tria[atoi(ntria[0])]); | |
| 291 | triangle_add_neighbour(vesicle->tlist->tria[j],vesicle->tlist->tria[atoi(ntria[1])]); | |
| 292 | triangle_add_neighbour(vesicle->tlist->tria[j],vesicle->tlist->tria[atoi(ntria[2])]); | |
| 293 | j++; | |
| 294 | for(i=0;i<3;i++) ntria[i]=strtok(NULL," "); | |
| 295 | } | |
| 720bd4 | 296 | //fprintf(stderr,"Parsing triangle neighbors j=%d\n",j); |
| e9ac7b | 297 | |
| SP | 298 | xmlFree(triangles); |
| 299 | return TS_SUCCESS; | |
| 300 | } | |
| 301 | ||
| 302 | ||
| a011d2 | 303 | ts_bool parseTrisurfTristar(ts_vesicle *vesicle, xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 304 | |
| 305 | xmlChar *chari; | |
| 306 | xmlChar *tristar; | |
| 307 | char *t; | |
| 308 | char *token; | |
| 309 | ts_uint neighi; | |
| 310 | ts_uint i; | |
| 311 | chari = xmlGetProp(cur, (xmlChar *)"idx"); | |
| 312 | i=atoi((char *)chari); | |
| 313 | xmlFree(chari); | |
| 314 | ts_vertex *vtx=vesicle->vlist->vtx[i]; | |
| 315 | tristar = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); | |
| 316 | // fprintf(stderr,"Found tristar for vtx %u that seems to have index %u with tristar=%s\n",i,vtx->idx,tristar); | |
| 317 | ||
| 318 | t=(char *)tristar; | |
| 319 | token=strtok(t," "); | |
| 320 | while(token!=NULL){ | |
| 321 | neighi=atoi(token); | |
| 322 | //fprintf(stderr,"%u", neighi); | |
| 323 | vertex_add_tristar(vtx,vesicle->tlist->tria[neighi]); | |
| 324 | token=strtok(NULL," "); | |
| 325 | } | |
| 326 | xmlFree(tristar); | |
| 327 | return TS_SUCCESS; | |
| 328 | } | |
| 329 | ||
| def8b5 | 330 | /* this parses the data for vertices (like spontaneous curvature, etc.) */ |
| SP | 331 | ts_bool parseXMLPointData(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur){ |
| 332 | xmlNodePtr child = cur->xmlChildrenNode; | |
| 333 | xmlChar *property_name; | |
| 334 | xmlChar *values; | |
| 1eb75b | 335 | // char *vals; |
| SP | 336 | // char *token; |
| def8b5 | 337 | int idx, polyidx, monoidx, filidx, fonoidx; |
| SP | 338 | while (child != NULL) { |
| 339 | if ((!xmlStrcmp(child->name, (const xmlChar *)"DataArray"))){ | |
| 340 | property_name=xmlGetProp(child, (xmlChar *)"Name"); | |
| 341 | // fprintf(stderr,"Name: %s\n", property_name); | |
| 342 | if(!xmlStrcmp(property_name,(const xmlChar *)"spontaneous_curvature")){ | |
| 343 | values=xmlNodeListGetString(doc,child->xmlChildrenNode,1); | |
| 1eb75b | 344 | // vals=(char *)values; |
| SP | 345 | unsigned long data_len=0; |
| 346 | ts_double *curv_values=(double *)ts_decompress((unsigned char *)values,strlen((char *)values), &data_len); | |
| 201659 | 347 | data_len=data_len/sizeof(ts_double); |
| 1eb75b | 348 | // token=strtok(vals," "); |
| SP | 349 | for(idx=0;idx<data_len;idx++){ |
| 350 | // while(token!=NULL){ | |
| def8b5 | 351 | if(idx<vesicle->vlist->n){ |
| 1eb75b | 352 | vesicle->vlist->vtx[idx]->c=curv_values[idx]; //atof(token); |
| def8b5 | 353 | } else if(vesicle->tape->nmono && vesicle->tape->npoly && idx<vesicle->vlist->n+vesicle->tape->nmono*vesicle->tape->npoly) { |
| SP | 354 | polyidx=(idx-vesicle->vlist->n)/vesicle->tape->nmono; |
| 355 | monoidx=(idx-vesicle->vlist->n)%vesicle->tape->nmono; | |
| 1eb75b | 356 | vesicle->poly_list->poly[polyidx]->vlist->vtx[monoidx]->c=curv_values[idx];//atof(token); |
| def8b5 | 357 | } else { |
| SP | 358 | filidx=(idx-vesicle->vlist->n-vesicle->tape->nmono*vesicle->tape->npoly)/vesicle->tape->nfono; |
| 359 | fonoidx=(idx-vesicle->vlist->n-vesicle->tape->nmono*vesicle->tape->npoly)%vesicle->tape->nfono; | |
| 360 | //fprintf(stderr,"filidx=%d, fonoidx=%d, coord=%s,%s,%s\n",filidx,fonoidx,token[0],token[1],token[2]); | |
| 1eb75b | 361 | vesicle->filament_list->poly[filidx]->vlist->vtx[fonoidx]->c=curv_values[idx];//atof(token); |
| def8b5 | 362 | } |
| 1eb75b | 363 | //idx++; |
| SP | 364 | //token=strtok(NULL," "); |
| def8b5 | 365 | } |
| 201659 | 366 | |
| def8b5 | 367 | xmlFree(values); |
| 201659 | 368 | free(curv_values); |
| def8b5 | 369 | } |
| SP | 370 | xmlFree(property_name); |
| 371 | } | |
| 372 | ||
| 373 | child=child->next; | |
| 374 | } | |
| 375 | return TS_SUCCESS; | |
| 376 | } | |
| 8fa1c0 | 377 | /* this is a parser of vertex positions and bonds from main xml data */ |
| SP | 378 | ts_bool parseXMLVertexPosition(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur){ |
| 379 | xmlNodePtr child = cur->xmlChildrenNode; | |
| 380 | xmlChar *points; | |
| 1eb75b | 381 | // char *pts; |
| 201659 | 382 | int i,idx, polyidx, monoidx, filidx, fonoidx; |
| 1eb75b | 383 | // char *token[3]; |
| 8fa1c0 | 384 | while (child != NULL) { |
| SP | 385 | if ((!xmlStrcmp(child->name, (const xmlChar *)"DataArray"))){ |
| 386 | points = xmlNodeListGetString(doc, child->xmlChildrenNode, 1); | |
| 1eb75b | 387 | unsigned long data_len=0; |
| SP | 388 | ts_double *coords=(double *)ts_decompress((unsigned char *)points,strlen((char *)points), &data_len); |
| 201659 | 389 | data_len=data_len/sizeof(ts_double); |
| 1eb75b | 390 | //pts=(char *)points; |
| SP | 391 | //token[0]=strtok(pts," "); |
| 392 | //token[1]=strtok(NULL," "); | |
| 393 | //token[2]=strtok(NULL,"\n"); | |
| 201659 | 394 | for(i=0,idx=0;i<data_len;i+=3,idx++){ |
| 1eb75b | 395 | // while(token[0]!=NULL){ |
| 86b69b | 396 | if(idx<vesicle->vlist->n){ |
| 579fbd | 397 | vesicle->vlist->vtx[idx]->x=coords[i];//atof(token[0]); |
| SP | 398 | vesicle->vlist->vtx[idx]->y=coords[i+1];//atof(token[1]); |
| 399 | vesicle->vlist->vtx[idx]->z=coords[i+2];//atof(token[2]); | |
| 301c87 | 400 | } else if(vesicle->tape->nmono && vesicle->tape->npoly && idx<vesicle->vlist->n+vesicle->tape->nmono*vesicle->tape->npoly) { |
| 86b69b | 401 | polyidx=(idx-vesicle->vlist->n)/vesicle->tape->nmono; |
| SP | 402 | monoidx=(idx-vesicle->vlist->n)%vesicle->tape->nmono; |
| 579fbd | 403 | vesicle->poly_list->poly[polyidx]->vlist->vtx[monoidx]->x=coords[i];//atof(token[0]); |
| SP | 404 | vesicle->poly_list->poly[polyidx]->vlist->vtx[monoidx]->y=coords[i+1];//atof(token[1]); |
| 405 | vesicle->poly_list->poly[polyidx]->vlist->vtx[monoidx]->z=coords[i+2];//atof(token[2]); | |
| 301c87 | 406 | } else { |
| SP | 407 | filidx=(idx-vesicle->vlist->n-vesicle->tape->nmono*vesicle->tape->npoly)/vesicle->tape->nfono; |
| 408 | fonoidx=(idx-vesicle->vlist->n-vesicle->tape->nmono*vesicle->tape->npoly)%vesicle->tape->nfono; | |
| f62178 | 409 | //fprintf(stderr,"filidx=%d, fonoidx=%d, coord=%s,%s,%s\n",filidx,fonoidx,token[0],token[1],token[2]); |
| 579fbd | 410 | vesicle->filament_list->poly[filidx]->vlist->vtx[fonoidx]->x=coords[i];//atof(token[0]); |
| SP | 411 | vesicle->filament_list->poly[filidx]->vlist->vtx[fonoidx]->y=coords[i+1];//atof(token[1]); |
| 412 | vesicle->filament_list->poly[filidx]->vlist->vtx[fonoidx]->z=coords[i+2];//atof(token[2]); | |
| 86b69b | 413 | } |
| 1eb75b | 414 | //for(i=0;i<2;i++) token[i]=strtok(NULL," "); |
| SP | 415 | //token[2]=strtok(NULL,"\n"); |
| 416 | //idx++; | |
| 8fa1c0 | 417 | } |
| SP | 418 | xmlFree(points); |
| 4f5ffc | 419 | free(coords); |
| 8fa1c0 | 420 | } |
| SP | 421 | child=child->next; |
| 422 | } | |
| f62178 | 423 | //fprintf(stderr,"Came here\n"); |
| 720bd4 | 424 | //fprintf(stderr,"Vertices position j=%d\n",idx); |
| 28efdb | 425 | |
| 8fa1c0 | 426 | return TS_SUCCESS; |
| SP | 427 | } |
| a3dbf0 | 428 | ts_bool parseXMLBonds(ts_vesicle *vesicle,xmlDocPtr doc, xmlNodePtr cur){ |
| SP | 429 | xmlNodePtr child = cur->xmlChildrenNode; |
| bb4033 | 430 | xmlChar *bonds, *conname; |
| 1eb75b | 431 | // char *b; |
| 579fbd | 432 | int idx, polyidx; |
| 1eb75b | 433 | // char *token[2]; |
| SP | 434 | // int temp_cnt=0; |
| a3dbf0 | 435 | while (child != NULL) { |
| bb4033 | 436 | conname=xmlGetProp(child, (xmlChar *)"Name"); |
| SP | 437 | if ((!xmlStrcmp(child->name, (const xmlChar *)"DataArray")) && !xmlStrcmp(conname, (const xmlChar *)"connectivity") ){ |
| a3dbf0 | 438 | bonds = xmlNodeListGetString(doc, child->xmlChildrenNode, 1); |
| 1eb75b | 439 | unsigned long data_len=0; |
| SP | 440 | unsigned long *conn=(unsigned long *)ts_decompress((unsigned char *)bonds,strlen((char *)bonds), &data_len); |
| 201659 | 441 | data_len=data_len/sizeof(unsigned long); |
| 1eb75b | 442 | //token[0]=strtok(b," "); |
| SP | 443 | //token[1]=strtok(NULL,"\n"); |
| 579fbd | 444 | for(idx=0;idx<data_len;idx+=2){ |
| 1eb75b | 445 | // while(token[0]!=NULL){ |
| 86b69b | 446 | if(idx<3*(vesicle->vlist->n-2)){ |
| 1eb75b | 447 | bond_add(vesicle->blist, vesicle->vlist->vtx[conn[idx]], vesicle->vlist->vtx[conn[idx+1]]); |
| 3cd5f4 | 448 | //fprintf(stderr,"Bonds in vesicle count idx=%d\n",idx); |
| 86b69b | 449 | } |
| SP | 450 | else { |
| 451 | //find grafted vtx | |
| 301c87 | 452 | if(vesicle->tape->npoly && vesicle->tape->nmono && (vesicle->tape->nmono-1)==(idx-3*(vesicle->vlist->n-2))%(vesicle->tape->nmono) |
| 3cd5f4 | 453 | && idx<(3*vesicle->vlist->n-2+vesicle->tape->nmono*vesicle->tape->npoly)){ |
| 1eb75b | 454 | // temp_cnt++; |
| 3cd5f4 | 455 | //fprintf(stderr,"%d: Bonds in poly count idx=%d, t1=%s t2=%s\n",temp_cnt,idx, token[0], token[1]); |
| SP | 456 | |
| 86b69b | 457 | polyidx=(idx-3*(vesicle->vlist->n-2))/(vesicle->tape->nmono); |
| 720bd4 | 458 | //fprintf(stderr,"poly=%d, vertex=%d\n",polyidx,atoi(token[0])); |
| 1eb75b | 459 | vesicle->poly_list->poly[polyidx]->grafted_vtx=vesicle->vlist->vtx[conn[idx]]; |
| SP | 460 | vesicle->vlist->vtx[conn[idx]]->grafted_poly=vesicle->poly_list->poly[polyidx]; |
| 86b69b | 461 | } |
| SP | 462 | } |
| a3dbf0 | 463 | } |
| SP | 464 | xmlFree(bonds); |
| 4f5ffc | 465 | free(conn); |
| a3dbf0 | 466 | } |
| bb4033 | 467 | xmlFree(conname); |
| a3dbf0 | 468 | child=child->next; |
| SP | 469 | } |
| 720bd4 | 470 | //fprintf(stderr,"Bond data j=%d\n",idx); |
| a3dbf0 | 471 | return TS_SUCCESS; |
| SP | 472 | } |
| 473 | ||
| 8fa1c0 | 474 | |
| SP | 475 | |