78 if (this->index)
delete this->
index;
298 return (!file_names && use_stdin);
303 return (populate_header || (file_name && (strstr(file_name,
".las") || strstr(file_name,
".laz") || strstr(file_name,
".LAS") || strstr(file_name,
".LAZ"))));
308 file_name_current = 0;
317 if (file_name_current == file_name_number)
return 0;
318 if ((file_name_number > 1) && merged)
331 for (file_name_current = 0; file_name_current < file_name_number; file_name_current++) lasreadermerged->
add_file_name(file_names[file_name_current]);
332 if (!lasreadermerged->
open())
334 fprintf(stderr,
"ERROR: cannot open lasreadermerged with %d file names\n", file_name_number);
335 delete lasreadermerged;
343 return lasreadermerged;
347 file_name = file_names[file_name_current];
349 if (strstr(file_name,
".las") || strstr(file_name,
".laz") || strstr(file_name,
".LAS") || strstr(file_name,
".LAZ"))
352 if (scale_factor == 0 && offset == 0)
354 else if (scale_factor != 0 && offset == 0)
356 else if (scale_factor == 0 && offset != 0)
359 lasreaderlas =
new LASreaderLASrescalereoffset(scale_factor[0], scale_factor[1], scale_factor[2], offset[0], offset[1], offset[2]);
360 if (!lasreaderlas->
open(file_name))
362 fprintf(stderr,
"ERROR: cannot open lasreaderlas with file name '%s'\n", file_name);
367 if (index->
read(file_name))
378 else if (strstr(file_name,
".bin") || strstr(file_name,
".BIN"))
381 if (scale_factor == 0 && offset == 0)
383 else if (scale_factor != 0 && offset == 0)
385 else if (scale_factor == 0 && offset != 0)
388 lasreaderbin =
new LASreaderBINrescalereoffset(scale_factor[0], scale_factor[1], scale_factor[2], offset[0], offset[1], offset[2]);
389 if (!lasreaderbin->
open(file_name))
391 fprintf(stderr,
"ERROR: cannot open lasreaderbin with file name '%s'\n", file_name);
396 if (index->
read(file_name))
407 else if (strstr(file_name,
".shp") || strstr(file_name,
".SHP"))
410 if (scale_factor == 0 && offset == 0)
412 else if (scale_factor != 0 && offset == 0)
414 else if (scale_factor == 0 && offset != 0)
417 lasreadershp =
new LASreaderSHPrescalereoffset(scale_factor[0], scale_factor[1], scale_factor[2], offset[0], offset[1], offset[2]);
418 if (!lasreadershp->
open(file_name))
420 fprintf(stderr,
"ERROR: cannot open lasreadershp with file name '%s'\n", file_name);
431 else if (strstr(file_name,
".qi") || strstr(file_name,
".QI"))
434 if (scale_factor == 0 && offset == 0)
436 else if (scale_factor != 0 && offset == 0)
438 else if (scale_factor == 0 && offset != 0)
442 if (!lasreaderqfit->
open(file_name))
444 fprintf(stderr,
"ERROR: cannot open lasreaderqfit with file name '%s'\n", file_name);
445 delete lasreaderqfit;
449 if (index->
read(file_name))
458 return lasreaderqfit;
469 if (number_extra_attributes)
471 for (
I32 i = 0; i < number_extra_attributes; i++)
473 lasreadertxt->
add_extra_attribute(extra_attribute_data_types[i], extra_attribute_names[i], extra_attribute_descriptions[i], extra_attribute_scales[i], extra_attribute_offsets[i]);
476 if (!lasreadertxt->
open(file_name, parse_string, skip_lines, populate_header))
478 fprintf(stderr,
"ERROR: cannot open lasreadertxt with file name '%s'\n", file_name);
493 use_stdin =
FALSE; populate_header =
TRUE;
495 if (scale_factor == 0 && offset == 0)
497 else if (scale_factor != 0 && offset == 0)
499 else if (scale_factor == 0 && offset != 0)
502 lasreaderlas =
new LASreaderLASrescalereoffset(scale_factor[0], scale_factor[1], scale_factor[2], offset[0], offset[1], offset[2]);
503 if (!lasreaderlas->
open(stdin))
505 fprintf(stderr,
"ERROR: cannot open lasreaderlas from stdin \n");
526 if ((file_name_number > 1) && merged)
529 if (!lasreadermerged->
reopen())
531 fprintf(stderr,
"ERROR: cannot reopen lasreadermerged\n");
542 if (!file_name)
return FALSE;
543 if (strstr(file_name,
".las") || strstr(file_name,
".laz") || strstr(file_name,
".LAS") || strstr(file_name,
".LAZ"))
546 if (!lasreaderlas->
open(file_name))
548 fprintf(stderr,
"ERROR: cannot reopen lasreaderlas with file name '%s'\n", file_name);
557 else if (strstr(file_name,
".bin") || strstr(file_name,
".BIN"))
560 if (!lasreaderbin->
open(file_name))
562 fprintf(stderr,
"ERROR: cannot reopen lasreaderbin with file name '%s'\n", file_name);
571 else if (strstr(file_name,
".shp") || strstr(file_name,
".SHP"))
574 if (!lasreadershp->
reopen(file_name))
576 fprintf(stderr,
"ERROR: cannot reopen lasreadershp with file name '%s'\n", file_name);
585 else if (strstr(file_name,
".qi") || strstr(file_name,
".QI"))
588 if (!lasreaderqfit->
reopen(file_name))
590 fprintf(stderr,
"ERROR: cannot reopen lasreaderqfit with file name '%s'\n", file_name);
602 if (!lasreadertxt->
reopen(file_name))
604 fprintf(stderr,
"ERROR: cannot reopen lasreadertxt with file name '%s'\n", file_name);
617 fprintf(stderr,
"ERROR: no lasreader input specified\n");
626 if (get_file_name() == 0)
return 0;
632 return waveform13reader;
639 return waveform13reader;
642 delete waveform13reader;
648 fprintf(stderr,
"Supported LAS Inputs\n");
649 fprintf(stderr,
" -i lidar.las\n");
650 fprintf(stderr,
" -i lidar.laz\n");
651 fprintf(stderr,
" -i lidar1.las lidar2.las lidar3.las -merged\n");
652 fprintf(stderr,
" -i *.las\n");
653 fprintf(stderr,
" -i flight0??.laz flight1??.laz -single\n");
654 fprintf(stderr,
" -i terrasolid.bin\n");
655 fprintf(stderr,
" -i esri.shp\n");
656 fprintf(stderr,
" -i nasa.qi\n");
657 fprintf(stderr,
" -i lidar.txt -iparse xyzti -iskip 2 (on-the-fly from ASCII)\n");
658 fprintf(stderr,
" -i lidar.txt -iparse xyzi -itranslate_intensity 1024\n");
659 fprintf(stderr,
" -lof file_list.txt\n");
660 fprintf(stderr,
" -stdin (pipe from stdin)\n");
661 fprintf(stderr,
" -rescale 0.1 0.1 0.1\n");
662 fprintf(stderr,
" -reoffset 600000 4000000 0\n");
668 for (i = 1; i <
argc; i++)
670 if (argv[i][0] ==
'\0')
674 else if (strcmp(argv[i],
"-h") == 0 || strcmp(argv[i],
"-help") == 0)
681 else if (strcmp(argv[i],
"-i") == 0)
685 fprintf(stderr,
"ERROR: '%s' needs at least 1 argument: file_name or wild_card\n", argv[i]);
693 add_file_name_windows(argv[i]);
695 add_file_name(argv[i]);
699 }
while (i < argc && *argv[i] !=
'-');
702 else if (strcmp(argv[i],
"-inside_tile") == 0)
706 fprintf(stderr,
"ERROR: '%s' needs 3 arguments: ll_x, ll_y, size\n", argv[i]);
713 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; i+=3;
715 else if (strcmp(argv[i],
"-inside_circle") == 0)
719 fprintf(stderr,
"ERROR: '%s' needs 3 arguments: center_x, center_y, radius\n", argv[i]);
726 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; i+=3;
728 else if (strcmp(argv[i],
"-inside") == 0 || strcmp(argv[i],
"-inside_rectangle") == 0)
732 fprintf(stderr,
"ERROR: '%s' needs 4 arguments: min_x, min_y, max_x, max_y\n", argv[i]);
740 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; *argv[i+4]=
'\0'; i+=4;
742 else if (strcmp(argv[i],
"-stdin") == 0)
747 else if (strcmp(argv[i],
"-lof") == 0)
751 fprintf(stderr,
"ERROR: '%s' needs 1 argument: list_of_files\n", argv[i]);
754 FILE*
file = fopen(argv[i+1],
"r");
757 fprintf(stderr,
"ERROR: cannot open '%s'\n", argv[i+1]);
761 while (fgets(line, 1024, file))
764 size_t len = strlen(line) - 1;
766 while (len > 0 && ((line[len] ==
'\n') || (line[len] ==
' ') || (line[len] ==
'\t') || (line[len] ==
'\012')))
773 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
775 else if (strcmp(argv[i],
"-rescale") == 0)
779 fprintf(stderr,
"ERROR: '%s' needs 3 arguments: rescale_x, rescale_y, rescale_z\n", argv[i]);
783 scale_factor[0] = atof(argv[i+1]);
784 scale_factor[1] = atof(argv[i+2]);
785 scale_factor[2] = atof(argv[i+3]);
786 set_scale_factor(scale_factor);
787 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; i+=3;
789 else if (strcmp(argv[i],
"-reoffset") == 0)
793 fprintf(stderr,
"ERROR: '%s' needs 3 arguments: reoffset_x, reoffset_y, reoffset_z\n", argv[i]);
797 offset[0] = atof(argv[i+1]);
798 offset[1] = atof(argv[i+2]);
799 offset[2] = atof(argv[i+3]);
801 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; i+=3;
803 else if (strcmp(argv[i],
"-files_are_flightlines") == 0)
805 use_alternate =
TRUE;
808 else if (strcmp(argv[i],
"-itranslate_intensity") == 0)
812 fprintf(stderr,
"ERROR: '%s' needs 1 argument: offset\n", argv[i]);
815 set_translate_intensity((
F32)atof(argv[i+1]));
816 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
818 else if (strcmp(argv[i],
"-iscale_intensity") == 0)
822 fprintf(stderr,
"ERROR: '%s' needs 1 argument: scale\n", argv[i]);
825 set_scale_intensity((
F32)atof(argv[i+1]));
826 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
828 else if (strcmp(argv[i],
"-itranslate_scan_angle") == 0)
832 fprintf(stderr,
"ERROR: '%s' needs 1 argument: offset\n", argv[i]);
835 set_translate_scan_angle((
F32)atof(argv[i+1]));
836 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
838 else if (strcmp(argv[i],
"-iscale_scan_angle") == 0)
842 fprintf(stderr,
"ERROR: '%s' needs 1 argument: scale\n", argv[i]);
845 set_scale_scan_angle((
F32)atof(argv[i+1]));
846 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
848 else if (strcmp(argv[i],
"-iadd_extra") == 0)
852 fprintf(stderr,
"ERROR: '%s' needs 3 arguments: data_type name description\n", argv[i]);
855 if (((i+4) < argc) && (argv[i+4][0] !=
'-'))
857 if (((i+5) < argc) && (argv[i+5][0] !=
'-'))
859 add_extra_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]), atof(argv[i+5]));
860 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; *argv[i+4]=
'\0'; *argv[i+5]=
'\0'; i+=5;
864 add_extra_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3], atof(argv[i+4]));
865 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; *argv[i+4]=
'\0'; i+=4;
870 add_extra_attribute(atoi(argv[i+1]), argv[i+2], argv[i+3]);
871 *argv[i]=
'\0'; *argv[i+1]=
'\0'; *argv[i+2]=
'\0'; *argv[i+3]=
'\0'; i+=3;
874 else if (strcmp(argv[i],
"-iparse") == 0)
878 fprintf(stderr,
"ERROR: '%s' needs 1 argument: string\n", argv[i]);
881 set_parse_string(argv[i+1]);
882 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
884 else if (strcmp(argv[i],
"-iskip") == 0)
888 fprintf(stderr,
"ERROR: '%s' needs 1 argument: number_of_lines\n", argv[i]);
891 set_skip_lines(atoi(argv[i+1]));
892 *argv[i]=
'\0'; *argv[i+1]=
'\0'; i+=1;
894 else if (strcmp(argv[i],
"-single") == 0)
899 else if (strcmp(argv[i],
"-merged") == 0)
904 else if (strcmp(argv[i],
"-populate") == 0)
906 set_populate_header(
TRUE);
909 else if (strcmp(argv[i],
"-do_not_populate") == 0)
911 set_populate_header(
FALSE);
949 if (file_name_number)
950 return file_names[0];
956 return file_names[number];
961 if (strstr(file_names[number],
".las") || strstr(file_names[number],
".LAS"))
965 else if (strstr(file_names[number],
".laz") || strstr(file_names[number],
".LAZ"))
969 else if (strstr(file_names[number],
".bin") || strstr(file_names[number],
".BIN"))
973 else if (strstr(file_names[number],
".shp") || strstr(file_names[number],
".SHP"))
977 else if (strstr(file_names[number],
".qi") || strstr(file_names[number],
".QI"))
989 this->merged = merged;
1000 add_file_name_windows(file_name, unique);
1002 add_file_name(file_name, unique);
1011 for (i = 0; i < file_name_number; i++)
1013 if (strcmp(file_names[i], file_name) == 0)
1019 if (file_name_number == file_name_allocated)
1023 file_name_allocated *= 2;
1024 file_names = (
char**)realloc(file_names,
sizeof(
char*)*file_name_allocated);
1028 file_name_allocated = 16;
1029 file_names = (
char**)malloc(
sizeof(
char*)*file_name_allocated);
1031 if (file_names == 0)
1033 fprintf(stderr,
"ERROR: alloc for file_names pointer array failed at %d\n", file_name_allocated);
1036 file_names[file_name_number] = strdup(file_name);
1043 if (file_name_id < file_name_number)
1046 free(file_names[file_name_id]);
1047 for (i = file_name_id+1; i < file_name_number; i++)
1049 file_names[i-1] = file_names[i];
1057 if (file_name_id < file_name_number)
1059 file_name_current = file_name_id;
1066 #include <windows.h> 1067 void LASreadOpener::add_file_name_windows(
const char* file_name,
BOOL unique)
1070 WIN32_FIND_DATA info;
1071 h = FindFirstFile(file_name, &info);
1072 if (h != INVALID_HANDLE_VALUE)
1075 size_t len = strlen(file_name);
1076 while (len && file_name[len] !=
'\\') len--;
1080 char full_file_name[512];
1081 strncpy(full_file_name, file_name, len);
1084 sprintf(&full_file_name[len],
"%s", info.cFileName);
1085 add_file_name(full_file_name, unique);
1086 }
while (FindNextFile(h, &info));
1092 add_file_name(info.cFileName, unique);
1093 }
while (FindNextFile(h, &info));
1102 return file_name_number;
1107 if (this->parse_string) free(this->parse_string);
1110 this->parse_string = strdup(parse_string);
1114 this->parse_string = 0;
1120 return parse_string;
1127 if (this->scale_factor == 0) this->scale_factor =
new F64[3];
1128 this->scale_factor[0] = scale_factor[0];
1129 this->scale_factor[1] = scale_factor[1];
1130 this->scale_factor[2] = scale_factor[2];
1132 else if (this->scale_factor)
1134 delete [] this->scale_factor;
1135 this->scale_factor = 0;
1143 if (this->offset == 0) this->offset =
new F64[3];
1144 this->offset[0] = offset[0];
1145 this->offset[1] = offset[1];
1146 this->offset[2] = offset[2];
1148 else if (this->offset)
1150 delete [] this->offset;
1157 this->translate_intensity = translate_intensity;
1162 this->scale_intensity = scale_intensity;
1167 this->translate_scan_angle = translate_scan_angle;
1172 this->scale_scan_angle = scale_scan_angle;
1177 extra_attribute_data_types[number_extra_attributes] = data_type;
1178 extra_attribute_names[number_extra_attributes] = (name ? strdup(name) : 0);
1179 extra_attribute_descriptions[number_extra_attributes] = (description ? strdup(description) : 0);
1180 extra_attribute_scales[number_extra_attributes] = scale;
1181 extra_attribute_offsets[number_extra_attributes] = offset;
1182 number_extra_attributes++;
1187 this->skip_lines = skip_lines;
1192 this->populate_header = populate_header;
1197 return ((file_name_current < file_name_number) || use_stdin);
1208 use_alternate =
FALSE;
1209 translate_intensity = 0.0f;
1210 scale_intensity = 1.0f;
1211 translate_scan_angle = 0.0f;
1212 scale_scan_angle = 1.0f;
1213 number_extra_attributes = 0;
1214 for (
I32 i = 0; i < 10; i++)
1216 extra_attribute_data_types[i] = 0;
1217 extra_attribute_names[i] = 0;
1218 extra_attribute_descriptions[i] = 0;
1219 extra_attribute_scales[i] = 1.0;
1220 extra_attribute_offsets[i] = 0.0;
1224 populate_header =
TRUE;
1225 file_name_number = 0;
1226 file_name_allocated = 0;
1227 file_name_current = 0;
1240 for (i = 0; i < file_name_number; i++) free(file_names[i]);
1243 if (parse_string) free(parse_string);
1244 if (scale_factor)
delete [] scale_factor;
1245 if (offset)
delete [] offset;
BOOL intersect_rectangle(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y)
void delete_file_name(U32 file_name_id)
BOOL open(const char *file_name)
BOOL read(const char *file_name)
BOOL filter(const LASpoint *point)
BOOL inside_tile(const F32 ll_x, const F32 ll_y, const F32 size)
virtual BOOL inside_circle(const F64 center_x, const F64 center_y, const F64 radius)
void set_scale_scan_angle(F32 scale_scan_angle)
void add_extra_attribute(I32 data_type, const char *name, const char *description=0, F64 scale=1.0, F64 offset=0.0)
BOOL read_point_inside_tile()
void set_parse_string(const char *parse_string)
void set_populate_header(BOOL populate_header)
void set_translate_intensity(F32 translate_intensity)
void set_skip_lines(I32 skip_lines)
BOOL(LASreader::* read_complex)()
LASwaveform13reader * open_waveform13(const LASheader *lasheader)
void set_filter(LASfilter *filter)
BOOL seek_next(LASreader *lasreader)
U32 get_file_name_number() const
BOOL read_point_inside_circle()
#define LAS_TOOLS_FORMAT_SHP
void set_scale_factor(const F64 *scale_factor)
void set_offset(const F64 *offset)
BOOL intersect_circle(const F64 center_x, const F64 center_y, const F64 radius)
virtual BOOL inside_tile(const F32 ll_x, const F32 ll_y, const F32 size)
void set_scale_intensity(F32 scale_intensity)
BOOL inside_rectangle(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y) const
BOOL has_populated_header() const
BOOL read_point_inside_tile_indexed()
void use_alternate_reader()
#define LAS_TOOLS_FORMAT_LAS
#define LAS_TOOLS_FORMAT_LAZ
BOOL add_file_name(const char *file_name, BOOL unique=FALSE)
void set_scale_scan_angle(F32 scale_scan_angle)
void set_translate_scan_angle(F32 translate_scan_angle)
void add_extra_attribute(I32 data_type, const char *name, const char *description=0, F64 scale=1.0, F64 offset=0.0)
void set_translate_intensity(F32 translate_intensity)
virtual BOOL read_point_default()=0
BOOL parse(int argc, char *argv[])
BOOL inside_circle(const F64 center_x, const F64 center_y, F64 squared_radius) const
void set_populate_header(BOOL populate_header)
void set_merged(const BOOL merged)
void set_scale_scan_angle(F32 scale_scan_angle)
void set_translate_scan_angle(F32 translate_scan_angle)
BOOL inside_circle(const F64 center_x, const F64 center_y, const F64 radius)
void set_file_name(const char *file_name, BOOL unique=FALSE)
void set_translate_intensity(F32 translate_intensity)
const char * get_parse_string() const
void set_translate_scan_angle(F32 translate_scan_angle)
BOOL intersect_tile(const F32 ll_x, const F32 ll_y, const F32 size)
virtual BOOL inside_rectangle(const F64 min_x, const F64 min_y, const F64 max_x, const F64 max_y)
BOOL set_file_name_current(U32 file_name_id)
void set_scale_factor(const F64 *scale_factor)
void set_offset(const F64 *offset)
I32 get_file_format(U32 number) const
BOOL reopen(const char *file_name)
#define LAS_TOOLS_FORMAT_BIN
void set_offset(const F64 *offset)
BOOL parse(int argc, char *argv[])
virtual BOOL open(const char *file_name)
void set_transform(LAStransform *transform)
void set_scale_intensity(F32 scale_intensity)
void set_parse_string(const char *parse_string)
virtual void set_filter(LASfilter *filter)
BOOL read_point_inside_rectangle()
BOOL inside_tile(const F32 ll_x, const F32 ll_y, const F32 ur_x, const F32 ur_y) const
#define LAS_TOOLS_FORMAT_TXT
BOOL inside_rectangle(const F64 min_x, const F64 min_y, const F64 max_x, const F64 max_y)
void set_index(LASindex *index)
BOOL reopen(const char *file_name)
BOOL open(const char *file_name, U32 io_buffer_size=65536)
BOOL read_point_filtered_and_transformed()
BOOL add_file_name(const char *file_name)
BOOL reopen(LASreader *lasreader)
BOOL read_point_filtered()
#define LAS_TOOLS_FORMAT_QFIT
const char * get_file_name() const
BOOL read_point_transformed()
LASindex * get_index() const
void set_scale_intensity(F32 scale_intensity)
void set_scale_factor(const F64 *scale_factor)
BOOL open(const char *file_name)
BOOL read_point_inside_rectangle_indexed()
virtual void set_transform(LAStransform *transform)
BOOL reopen(const char *file_name)
virtual BOOL open(const char *file_name, const char *parse_string=0, I32 skip_lines=0, BOOL populate_header=FALSE)
BOOL read_point_inside_circle_indexed()
void set_skip_lines(I32 skip_lines)
BOOL(LASreader::* read_simple)()