| 575 | } |
| 576 | |
| 577 | int ply_write_header(p_ply ply) { |
| 578 | long i, j; |
| 579 | assert(ply && ply->fp && ply->io_mode == PLY_WRITE); |
| 580 | assert(ply->element || ply->nelements == 0); |
| 581 | assert(!ply->element || ply->nelements > 0); |
| 582 | if (fprintf(ply->fp, "ply\nformat %s 1.0\n", |
| 583 | ply_storage_mode_list[ply->storage_mode]) <= 0) goto error; |
| 584 | for (i = 0; i < ply->ncomments; i++) |
| 585 | if (fprintf(ply->fp, "comment %s\n", ply->comment + LINESIZE*i) <= 0) |
| 586 | goto error; |
| 587 | for (i = 0; i < ply->nobj_infos; i++) |
| 588 | if (fprintf(ply->fp, "obj_info %s\n", ply->obj_info + LINESIZE*i) <= 0) |
| 589 | goto error; |
| 590 | for (i = 0; i < ply->nelements; i++) { |
| 591 | p_ply_element element = &ply->element[i]; |
| 592 | assert(element->property || element->nproperties == 0); |
| 593 | assert(!element->property || element->nproperties > 0); |
| 594 | if (fprintf(ply->fp, "element %s %ld\n", element->name, |
| 595 | element->ninstances) <= 0) goto error; |
| 596 | for (j = 0; j < element->nproperties; j++) { |
| 597 | p_ply_property property = &element->property[j]; |
| 598 | if (property->type == PLY_LIST) { |
| 599 | if (fprintf(ply->fp, "property list %s %s %s\n", |
| 600 | ply_type_list[property->length_type], |
| 601 | ply_type_list[property->value_type], |
| 602 | property->name) <= 0) goto error; |
| 603 | } else { |
| 604 | if (fprintf(ply->fp, "property %s %s\n", |
| 605 | ply_type_list[property->type], |
| 606 | property->name) <= 0) goto error; |
| 607 | } |
| 608 | } |
| 609 | } |
| 610 | return fprintf(ply->fp, "end_header\n") > 0; |
| 611 | error: |
| 612 | ply_ferror(ply, "Error writing to file"); |
| 613 | return 0; |
| 614 | } |
| 615 | |
| 616 | int ply_write(p_ply ply, double value) { |
| 617 | p_ply_element element = NULL; |
no test coverage detected