| 511 | | /* // create a cheaper parse string that only looks for 'x' 'y' 'z' and 'r' |
| 512 | | */ |
| 513 | | parse_less = strdup(parse_string); |
| 514 | | for (i = 0; i < (int)strlen(parse_string); i++) |
| 515 | | { |
| 516 | | if (parse_less[i] != 'x' && parse_less[i] != 'y' && parse_less[i] != 'z' && parse_less[i] != 'r') |
| 517 | | { |
| 518 | | parse_less[i] = 's'; |
| 519 | | } |
| 520 | | } |
| 521 | | do |
| 522 | | { |
| 523 | | parse_less[i] = '\0'; |
| 524 | | i--; |
| 525 | | } while (parse_less[i] == 's'); |
| 526 | | /* |
| 527 | | // first pass to figure out the bounding box and number of returns |
| 528 | | */ |
| 529 | | |
| 530 | | fprintf(stderr, "first pass over file '%s' with parse '%s'\n", file_name_in, parse_less); |
| 531 | | |
| 532 | | /* // read the first line |
| 533 | | */ |
| 534 | | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| 535 | | { |
| 536 | | if (parse(parse_less, line, xyz, &point, &gps_time)) |
| 537 | | { |
| 538 | | /* // init the bounding box |
| 539 | | */ |
| 540 | | VecCopy3dv(xyz_min, xyz); |
| 541 | | VecCopy3dv(xyz_max, xyz); |
| 542 | | |
| 543 | | /* // mark that we found the first point |
| 544 | | */ |
| 545 | | number_of_point_records = 1; |
| 546 | | |
| 547 | | /* // create return histogram |
| 548 | | */ |
| 549 | | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| 550 | | /* // we can stop this loop |
| 551 | | */ |
| 552 | | break; |
| 553 | | } |
| 554 | | else |
| 555 | | { |
| 556 | | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", line, parse_less); |
| 557 | | } |
| 558 | | } |
| 559 | | |
| 560 | | /* // did we manage to parse a line |
| 561 | | */ |
| 562 | | if (number_of_point_records != 1) |
| 563 | | { |
| 564 | | fprintf(stderr, "ERROR: could not parse any lines with '%s'\n", parse_less); |
| 565 | | exit(1); |
| 566 | | } |
| 567 | | |
| 568 | | /* // loop over the remaining lines |
| 569 | | */ |
| 570 | | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| 571 | | { |
| 572 | | if (parse(parse_less, line, xyz, &point, &gps_time)) |
| 573 | | { |
| 574 | | /* // update bounding box |
| 575 | | */ |
| 576 | | VecUpdateMinMax3dv(xyz_min, xyz_max, xyz); |
| 577 | | |
| 578 | | /* // count points |
| 579 | | */ |
| 580 | | number_of_point_records++; |
| 581 | | |
| 582 | | /* // create return histogram |
| 583 | | */ |
| 584 | | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| 585 | | } |
| 586 | | else |
| 587 | | { |
| 588 | | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", line, parse_less); |
| 589 | | } |
| 590 | | } |
| 591 | | |
| 592 | | /* // output some stats |
| 593 | | */ |
| 594 | | if (verbose) |
| 595 | | { |
| 596 | | fprintf(stderr, "npoints %d min %g %g %g max %g %g %g\n", number_of_point_records, xyz_min[0], xyz_min[1], xyz_min[2], xyz_max[0], xyz_max[1], xyz_max[2]); |
| 597 | | fprintf(stderr, "return histogram %d %d %d %d %d %d %d %d\n", number_of_points_by_return[0], number_of_points_by_return[1], number_of_points_by_return[2], number_of_points_by_return[3], number_of_points_by_return[4], number_of_points_by_return[5], number_of_points_by_return[6], number_of_points_by_return[7]); |
| 598 | | } |
| 599 | | |
| 600 | | /* // close the input file |
| 601 | | */ |
| | 507 | /* create a cheaper parse string that only looks for 'x' 'y' 'z' and 'r' */ |
| | 508 | parse_less = strdup(parse_string); |
| | 509 | for (i = 0; i < (int)strlen(parse_string); i++) |
| | 510 | { |
| | 511 | if (parse_less[i] != 'x' && |
| | 512 | parse_less[i] != 'y' && |
| | 513 | parse_less[i] != 'z' && |
| | 514 | parse_less[i] != 'r') |
| | 515 | { |
| | 516 | parse_less[i] = 's'; |
| | 517 | } |
| | 518 | } |
| | 519 | |
| | 520 | do |
| | 521 | { |
| | 522 | parse_less[i] = '\0'; |
| | 523 | printf("nuking %d for %c\n", i, parse_less[i]); |
| | 524 | i--; |
| | 525 | } while (parse_less[i] == 's'); |
| | 526 | |
| | 527 | |
| | 528 | /* first pass to figure out the bounding box and number of returns */ |
| | 529 | if (verbose) { |
| | 530 | fprintf(stderr, |
| | 531 | "first pass over file '%s' with parse '%s'\n", |
| | 532 | file_name_in, |
| | 533 | parse_less); |
| | 534 | } |
| | 535 | |
| | 536 | /* read the first line */ |
| | 537 | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| | 538 | { |
| | 539 | if (parse(parse_less, line, xyz, &point, &gps_time)) |
| | 540 | { |
| | 541 | /* init the bounding box */ |
| | 542 | VecCopy3dv(xyz_min, xyz); |
| | 543 | VecCopy3dv(xyz_max, xyz); |
| | 544 | |
| | 545 | /* mark that we found the first point */ |
| | 546 | number_of_point_records = 1; |
| | 547 | |
| | 548 | /* create return histogram */ |
| | 549 | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| | 550 | |
| | 551 | /* we can stop this loop */ |
| | 552 | break; |
| | 553 | } |
| | 554 | else |
| | 555 | { |
| | 556 | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", |
| | 557 | line, |
| | 558 | parse_less); |
| | 559 | } |
| | 560 | } |
| | 561 | |
| | 562 | /* did we manage to parse a line? */ |
| | 563 | if (number_of_point_records != 1) |
| | 564 | { |
| | 565 | fprintf(stderr, "ERROR: could not parse any lines with '%s'\n", |
| | 566 | parse_less); |
| | 567 | exit(1); |
| | 568 | } |
| | 569 | |
| | 570 | /* loop over the remaining lines */ |
| | 571 | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| | 572 | { |
| | 573 | if (parse(parse_less, line, xyz, &point, &gps_time)) |
| | 574 | { |
| | 575 | /* update bounding box */ |
| | 576 | VecUpdateMinMax3dv(xyz_min, xyz_max, xyz); |
| | 577 | |
| | 578 | /* count points */ |
| | 579 | number_of_point_records++; |
| | 580 | |
| | 581 | /* create return histogram */ |
| | 582 | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| | 583 | } |
| | 584 | else |
| | 585 | { |
| | 586 | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", |
| | 587 | line, |
| | 588 | parse_less); |
| | 589 | } |
| | 590 | } |
| | 591 | |
| | 592 | /* output some stats */ |
| | 593 | if (verbose) |
| | 594 | { |
| | 595 | fprintf(stderr, |
| | 596 | "npoints %d min %g %g %g max %g %g %g\n", |
| | 597 | number_of_point_records, |
| | 598 | xyz_min[0], |
| | 599 | xyz_min[1], |
| | 600 | xyz_min[2], |
| | 601 | xyz_max[0], |
| | 602 | xyz_max[1], |
| | 603 | xyz_max[2] |
| | 604 | ); |
| | 605 | fprintf(stderr, |
| | 606 | "return histogram %d %d %d %d %d %d %d %d\n", |
| | 607 | number_of_points_by_return[0], |
| | 608 | number_of_points_by_return[1], |
| | 609 | number_of_points_by_return[2], |
| | 610 | number_of_points_by_return[3], |
| | 611 | number_of_points_by_return[4], |
| | 612 | number_of_points_by_return[5], |
| | 613 | number_of_points_by_return[6], |
| | 614 | number_of_points_by_return[7] |
| | 615 | ); |
| | 616 | } |
| | 617 | |
| | 618 | /* close the input file */ |
| 652 | | if (strstr(parse_string,"t")) |
| 653 | | { |
| 654 | | LASHeader_SetDataFormatId(header, 1); |
| 655 | | |
| 656 | | } |
| 657 | | else |
| 658 | | { |
| 659 | | LASHeader_SetDataFormatId(header, 0); |
| 660 | | } |
| 661 | | LASHeader_SetPointRecordsCount(header, number_of_point_records); |
| 662 | | LASHeader_SetScale(header, xyz_scale[0], xyz_scale[1], xyz_scale[2]); |
| 663 | | LASHeader_SetOffset(header, xyz_offset[0], xyz_offset[1], xyz_offset[2]); |
| 664 | | LASHeader_SetMin(header, xyz_min_dequant[0], xyz_min_dequant[1], xyz_min_dequant[2]); |
| 665 | | LASHeader_SetMax(header, xyz_max_dequant[0], xyz_max_dequant[1], xyz_max_dequant[2]); |
| 666 | | LASHeader_SetPointRecordsByReturnCount(header, 0, number_of_points_by_return[1]); |
| 667 | | LASHeader_SetPointRecordsByReturnCount(header, 1, number_of_points_by_return[2]); |
| 668 | | LASHeader_SetPointRecordsByReturnCount(header, 2, number_of_points_by_return[3]); |
| 669 | | LASHeader_SetPointRecordsByReturnCount(header, 3, number_of_points_by_return[4]); |
| 670 | | LASHeader_SetPointRecordsByReturnCount(header, 4, number_of_points_by_return[5]); |
| 671 | | |
| 672 | | |
| 673 | | |
| 674 | | /* // reopen input file for the second pass |
| 675 | | */ |
| 676 | | file_in = fopen(file_name_in, "r"); |
| 677 | | |
| 678 | | if (file_in == 0) |
| 679 | | { |
| 680 | | fprintf(stderr, "ERROR: could not open '%s' for second pass\n",file_name_in); |
| 681 | | exit(1); |
| 682 | | } |
| 683 | | |
| 684 | | /* // open the output pipe |
| 685 | | */ |
| 686 | | |
| | 672 | if (strstr(parse_string,"t")) |
| | 673 | { |
| | 674 | LASHeader_SetDataFormatId(header, 1); |
| | 675 | } |
| | 676 | else |
| | 677 | { |
| | 678 | LASHeader_SetDataFormatId(header, 0); |
| | 679 | } |
| | 680 | LASHeader_SetPointRecordsCount(header, number_of_point_records); |
| | 681 | LASHeader_SetScale(header, xyz_scale[0], xyz_scale[1], xyz_scale[2]); |
| | 682 | LASHeader_SetOffset(header, xyz_offset[0], xyz_offset[1], xyz_offset[2]); |
| | 683 | LASHeader_SetMin(header, xyz_min_dequant[0], xyz_min_dequant[1], xyz_min_dequant[2]); |
| | 684 | LASHeader_SetMax(header, xyz_max_dequant[0], xyz_max_dequant[1], xyz_max_dequant[2]); |
| | 685 | LASHeader_SetPointRecordsByReturnCount(header, 0, number_of_points_by_return[1]); |
| | 686 | LASHeader_SetPointRecordsByReturnCount(header, 1, number_of_points_by_return[2]); |
| | 687 | LASHeader_SetPointRecordsByReturnCount(header, 2, number_of_points_by_return[3]); |
| | 688 | LASHeader_SetPointRecordsByReturnCount(header, 3, number_of_points_by_return[4]); |
| | 689 | LASHeader_SetPointRecordsByReturnCount(header, 4, number_of_points_by_return[5]); |
| | 690 | |
| | 691 | |
| | 692 | |
| | 693 | /* reopen input file for the second pass */ |
| | 694 | file_in = fopen(file_name_in, "r"); |
| | 695 | |
| | 696 | if (file_in == 0) |
| | 697 | { |
| | 698 | fprintf(stderr, "ERROR: could not open '%s' for second pass\n",file_name_in); |
| | 699 | exit(1); |
| | 700 | } |
| | 701 | |
| | 702 | /* |
| | 703 | because the output goes to a file we can do everything in a |
| | 704 | single pass and compute the header information along the way |
| | 705 | */ |
| 688 | | /* |
| 689 | | if (laswriter->open(stdout, &header, olaz ? 1 : 0) == false) |
| 690 | | { |
| 691 | | fprintf(stderr, "ERROR: could not open laswriter\n"); |
| 692 | | exit(1); |
| 693 | | } |
| 694 | | |
| 695 | | fprintf(stderr, "second pass over file '%s' with parse '%s' writing to '%s'\n", file_name_in, parse_string, file_name_out ? file_name_out : "stdout"); |
| 696 | | |
| 697 | | // loop over points |
| 698 | | |
| 699 | | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| 700 | | { |
| 701 | | if (parse(parse_string, line, xyz, &point, &gps_time)) |
| 702 | | { |
| 703 | | point.x = (int)(0.5 + (xyz[0] - xyz_offset[0]) / xyz_scale[0]); |
| 704 | | point.y = (int)(0.5 + (xyz[1] - xyz_offset[1]) / xyz_scale[1]); |
| 705 | | point.z = (int)(0.5 + (xyz[2] - xyz_offset[2]) / xyz_scale[2]); |
| 706 | | laswriter->write_point(&point, gps_time); |
| 707 | | number_of_point_records--; |
| 708 | | } |
| 709 | | else |
| 710 | | { |
| 711 | | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", line, parse_string); |
| 712 | | } |
| 713 | | } |
| 714 | | |
| 715 | | if (number_of_point_records) |
| 716 | | { |
| 717 | | fprintf(stderr, "WARNING: second pass has different number of points (%d instead of %d)\n", header.number_of_point_records - number_of_point_records, header.number_of_point_records); |
| 718 | | } |
| 719 | | |
| 720 | | LASWriter_Destroy(writer); |
| 721 | | |
| 722 | | if (verbose) |
| 723 | | { |
| 724 | | fprintf(stderr, "done.\n"); |
| 725 | | } |
| 726 | | |
| 727 | | fclose(file_in); |
| 728 | | } |
| 729 | | else |
| 730 | | { |
| 731 | | */ |
| 732 | | /* |
| 733 | | // because the output goes to a file we can do everything in a single pass |
| 734 | | // and compute the header information along the way and then set it at the |
| 735 | | // end by fopen() the file with "rb+" |
| 736 | | |
| 737 | | // open input file |
| 738 | | */ |
| 739 | | |
| 740 | | if (file_name_in) |
| 741 | | { |
| 742 | | |
| 743 | | file_in = fopen(file_name_in, "r"); |
| 744 | | |
| 745 | | if (file_in == NULL) |
| 746 | | { |
| 747 | | LASError_Print("Could not open input file"); |
| 748 | | exit(1); |
| 749 | | } |
| 750 | | } |
| 751 | | |
| 752 | | /* // open output file |
| 753 | | */ |
| 754 | | printf("Creating file...\n"); |
| 755 | | writer = LASWriter_Create(file_name_out, header, LAS_MODE_WRITE); |
| 756 | | if (!writer) { |
| 757 | | fprintf(stderr, |
| 758 | | "Error! %d, %s, in method %s\n", |
| 759 | | LASError_GetLastErrorNum(), |
| 760 | | LASError_GetLastErrorMsg(), |
| 761 | | LASError_GetLastErrorMethod() |
| 762 | | ); |
| 763 | | exit(1); |
| 764 | | } |
| 765 | | |
| 766 | | |
| 767 | | fprintf(stderr, "scanning %s with parse '%s' writing to %s\n", file_name_in ? file_name_in : "stdin" , parse_string, file_name_out); |
| 768 | | |
| 769 | | /* // read the first line |
| 770 | | */ |
| 771 | | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| 772 | | { |
| 773 | | if (parse(parse_string, line, xyz, &point, &gps_time)) |
| 774 | | { |
| 775 | | /* // init the bounding box |
| 776 | | */ |
| 777 | | VecCopy3dv(xyz_min, xyz); |
| 778 | | VecCopy3dv(xyz_max, xyz); |
| 779 | | |
| 780 | | /* // we found the first point |
| 781 | | */ |
| 782 | | number_of_point_records = 1; |
| 783 | | |
| 784 | | /* // create return histogram |
| 785 | | */ |
| 786 | | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| 787 | | /* // compute the quantized x, y, and z values |
| 788 | | */ |
| 789 | | LASPoint_SetX(point, 0.5 + (xyz[0] - xyz_offset[0]) / xyz_scale[0]); |
| 790 | | LASPoint_SetY(point, 0.5 + (xyz[1] - xyz_offset[1]) / xyz_scale[1]); |
| 791 | | LASPoint_SetX(point, 0.5 + (xyz[2] - xyz_offset[2]) / xyz_scale[2]); |
| 792 | | |
| 793 | | /* // write the first point |
| 794 | | */ |
| 795 | | LASWriter_WritePoint(writer, point); |
| 796 | | |
| 797 | | /* // we can stop this loop |
| 798 | | */ |
| 799 | | break; |
| 800 | | } |
| 801 | | else |
| 802 | | { |
| 803 | | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", line, parse_string); |
| 804 | | } |
| 805 | | } |
| 806 | | |
| 807 | | /* // did we manage to parse a line |
| 808 | | */ |
| 809 | | if (number_of_point_records != 1) |
| 810 | | { |
| 811 | | fprintf(stderr, "ERROR: could not parse any lines with '%s'\n", parse_string); |
| 812 | | exit(1); |
| 813 | | } |
| 814 | | |
| 815 | | /* // loop over the remaining lines |
| 816 | | */ |
| 817 | | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| 818 | | { |
| 819 | | if (parse(parse_string, line, xyz, &point, &gps_time)) |
| 820 | | { |
| 821 | | |
| 822 | | /* // update bounding box |
| 823 | | */ |
| 824 | | VecUpdateMinMax3dv(xyz_min, xyz_max, xyz); |
| 825 | | |
| 826 | | /* // count points |
| 827 | | */ |
| 828 | | number_of_point_records++; |
| 829 | | |
| 830 | | /* // create return histogram |
| 831 | | */ |
| 832 | | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| 833 | | /* // compute the quantized x, y, and z values |
| 834 | | */ |
| 835 | | LASPoint_SetX(point, 0.5 + (xyz[0] - xyz_offset[0]) / xyz_scale[0]); |
| 836 | | LASPoint_SetY(point, 0.5 + (xyz[1] - xyz_offset[1]) / xyz_scale[1]); |
| 837 | | LASPoint_SetX(point, 0.5 + (xyz[2] - xyz_offset[2]) / xyz_scale[2]); |
| 838 | | |
| 839 | | /* // write the first point |
| 840 | | */ |
| 841 | | LASWriter_WritePoint(writer, point); |
| 842 | | } |
| 843 | | else |
| 844 | | { |
| 845 | | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", line, parse_string); |
| 846 | | } |
| 847 | | } |
| 848 | | |
| 849 | | /* // done writing the points |
| 850 | | */ |
| 851 | | |
| 852 | | /* if (file_in != stdin) fclose(file_in); |
| 853 | | */ |
| 854 | | |
| 855 | | LASWriter_Destroy(writer); |
| 856 | | |
| 857 | | /* // output some stats |
| 858 | | */ |
| 859 | | |
| 860 | | if (verbose) |
| 861 | | { |
| 862 | | fprintf(stderr, "npoints %d min %g %g %g max %g %g %g\n", number_of_point_records, xyz_min[0], xyz_min[1], xyz_min[2], xyz_max[0], xyz_max[1], xyz_max[2]); |
| 863 | | fprintf(stderr, "return histogram %d %d %d %d %d %d %d %d\n", number_of_points_by_return[0], number_of_points_by_return[1], number_of_points_by_return[2], number_of_points_by_return[3], number_of_points_by_return[4], number_of_points_by_return[5], number_of_points_by_return[6], number_of_points_by_return[7]); |
| 864 | | } |
| 865 | | |
| 866 | | /* // compute bounding box after quantization |
| 867 | | */ |
| 868 | | |
| 869 | | |
| 870 | | for (i = 0; i < 3; i++) |
| 871 | | { |
| 872 | | xyz_min_quant[i] = (int)(0.5 + (xyz_min[i] - xyz_offset[i]) / xyz_scale[i]); |
| 873 | | xyz_max_quant[i] = (int)(0.5 + (xyz_max[i] - xyz_offset[i]) / xyz_scale[i]); |
| 874 | | } |
| 875 | | |
| 876 | | |
| 877 | | |
| 878 | | for (i = 0; i < 3; i++) |
| 879 | | { |
| 880 | | xyz_min_dequant[i] = xyz_offset[i] + (xyz_min_quant[i] * xyz_scale[i]); |
| 881 | | xyz_max_dequant[i] = xyz_offset[i] + (xyz_max_quant[i] * xyz_scale[i]); |
| 882 | | } |
| 883 | | |
| 884 | | /* // make sure there is not sign flip |
| 885 | | */ |
| 886 | | |
| 887 | | #define log_xor !=0==! |
| 888 | | |
| 889 | | for (i = 0; i < 3; i++) |
| 890 | | { |
| 891 | | if ((xyz_min[i] > 0) log_xor (xyz_min_dequant[i] > 0)) |
| 892 | | { |
| 893 | | fprintf(stderr, "WARNING: quantization sign flip for %s min coord %g -> %g. use offset or scale up\n", (i ? (i == 1 ? "y" : "z") : "x"), xyz_min[i], xyz_min_dequant[i]); |
| 894 | | } |
| 895 | | if ((xyz_max[i] > 0) log_xor (xyz_max_dequant[i] > 0)) |
| 896 | | { |
| 897 | | fprintf(stderr, "WARNING: quantization sign flip for %s max coord %g -> %g. use offset or scale up\n", (i ? (i == 1 ? "y" : "z") : "x"), xyz_max[i], xyz_max_dequant[i]); |
| 898 | | } |
| 899 | | } |
| 900 | | |
| 901 | | #undef log_xor |
| 902 | | |
| 903 | | /* // re-open output file to rewrite the missing header information |
| 904 | | |
| 905 | | |
| 906 | | file_out = fopen(file_name_out, "rb+"); |
| | 707 | /* open output file */ |
| | 708 | printf("Creating file...\n"); |
| | 709 | writer = LASWriter_Create(file_name_out, header, LAS_MODE_WRITE); |
| | 710 | if (!writer) { |
| | 711 | LASError_Print("Could not open file for write mode "); |
| | 712 | exit(1); |
| | 713 | } |
| | 714 | |
| | 715 | if (verbose) { |
| | 716 | fprintf(stderr, |
| | 717 | "scanning %s with parse '%s' writing to %s\n", |
| | 718 | file_name_in , |
| | 719 | parse_string, |
| | 720 | file_name_out |
| | 721 | ); |
| | 722 | } |
| 908 | | if (file_out == 0) |
| 909 | | { |
| 910 | | fprintf(stderr, "ERROR: could not open re-output file '%s'\n",file_name_out); |
| 911 | | exit(1); |
| 912 | | } |
| 913 | | |
| 914 | | // rewrite the information |
| 915 | | |
| 916 | | |
| 917 | | |
| 918 | | fseek(file_out, 107, SEEK_SET); |
| 919 | | fwrite(&number_of_point_records, sizeof(unsigned int), 5, file_out); |
| 920 | | |
| 921 | | fseek(file_out, 111, SEEK_SET); |
| 922 | | fwrite(&(number_of_points_by_return[1]), sizeof(unsigned int), 5, file_out); |
| 923 | | |
| 924 | | fseek(file_out, 179, SEEK_SET); |
| 925 | | fwrite(&(xyz_max_dequant[0]), sizeof(double), 1, file_out); |
| 926 | | fwrite(&(xyz_min_dequant[0]), sizeof(double), 1, file_out); |
| 927 | | fwrite(&(xyz_max_dequant[1]), sizeof(double), 1, file_out); |
| 928 | | fwrite(&(xyz_min_dequant[1]), sizeof(double), 1, file_out); |
| 929 | | fwrite(&(xyz_max_dequant[2]), sizeof(double), 1, file_out); |
| 930 | | fwrite(&(xyz_min_dequant[2]), sizeof(double), 1, file_out); |
| 931 | | |
| 932 | | // close the rewritten file |
| 933 | | |
| 934 | | fclose(file_out); |
| 935 | | */ |
| 936 | | |
| | 724 | |
| | 725 | /* read the first line */ |
| | 726 | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| | 727 | { |
| | 728 | if (parse(parse_string, line, xyz, &point, &gps_time)) |
| | 729 | { |
| | 730 | /* init the bounding box */ |
| | 731 | VecCopy3dv(xyz_min, xyz); |
| | 732 | VecCopy3dv(xyz_max, xyz); |
| | 733 | |
| | 734 | /* mark that we found the first point */ |
| | 735 | number_of_point_records = 1; |
| | 736 | |
| | 737 | /* create return histogram */ |
| | 738 | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| | 739 | |
| | 740 | /* compute the quantized x, y, and z values */ |
| | 741 | LASPoint_SetX(point, 0.5 + (xyz[0] - xyz_offset[0]) / xyz_scale[0]); |
| | 742 | LASPoint_SetY(point, 0.5 + (xyz[1] - xyz_offset[1]) / xyz_scale[1]); |
| | 743 | LASPoint_SetX(point, 0.5 + (xyz[2] - xyz_offset[2]) / xyz_scale[2]); |
| | 744 | |
| | 745 | /* write the first point */ |
| | 746 | LASWriter_WritePoint(writer, point); |
| | 747 | printf("Writing point..."); |
| | 748 | |
| | 749 | /* we can stop this loop */ |
| | 750 | break; |
| | 751 | } |
| | 752 | else |
| | 753 | { |
| | 754 | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", |
| | 755 | line, |
| | 756 | parse_string); |
| | 757 | } |
| | 758 | } |
| | 759 | |
| | 760 | /* did we manage to parse a line? */ |
| | 761 | if (number_of_point_records != 1) |
| | 762 | { |
| | 763 | fprintf(stderr, "ERROR: could not parse any lines with '%s'\n", |
| | 764 | parse_less); |
| | 765 | exit(1); |
| | 766 | } |
| | 767 | |
| | 768 | /* loop over the remaining lines */ |
| | 769 | while (fgets(line, sizeof(char) * MAX_CHARACTERS_PER_LINE, file_in)) |
| | 770 | { |
| | 771 | if (parse(parse_string, line, xyz, &point, &gps_time)) |
| | 772 | { |
| | 773 | /* update bounding box */ |
| | 774 | VecUpdateMinMax3dv(xyz_min, xyz_max, xyz); |
| | 775 | |
| | 776 | /* count points */ |
| | 777 | number_of_point_records++; |
| | 778 | |
| | 779 | /* create return histogram */ |
| | 780 | number_of_points_by_return[LASPoint_GetReturnNumber(point)]++; |
| | 781 | |
| | 782 | /* compute the quantized x, y, and z values */ |
| | 783 | LASPoint_SetX(point, 0.5 + (xyz[0] - xyz_offset[0]) / xyz_scale[0]); |
| | 784 | LASPoint_SetY(point, 0.5 + (xyz[1] - xyz_offset[1]) / xyz_scale[1]); |
| | 785 | LASPoint_SetX(point, 0.5 + (xyz[2] - xyz_offset[2]) / xyz_scale[2]); |
| | 786 | |
| | 787 | /* write the first point */ |
| | 788 | LASWriter_WritePoint(writer, point); |
| | 789 | } |
| | 790 | else |
| | 791 | { |
| | 792 | fprintf(stderr, "WARNING: cannot parse '%s' with '%s'. skipping ...\n", |
| | 793 | line, |
| | 794 | parse_string); |
| | 795 | } |
| | 796 | } |
| | 797 | |
| | 798 | |
| | 799 | /* close up stuff */ |
| | 800 | fclose(file_in); |
| | 801 | LASWriter_Destroy(writer); |