📄 las2las.cpp
字号:
/*
===============================================================================
FILE: las2las.cpp
CONTENTS:
This tool reads and writes LIDAR data in the LAS format and is typically
used to modify the contents of a LAS file. Examples are clipping the points
to those that lie within a certain region specified by a bounding box (-clip),
eliminating points that are the second return (-elim_return 2), that have a
scan angle above a certain threshold (-elim_scan_angle_above 5), or that are
below a certain intensity (-elim_intensity_below 15).
Another typical use may be to extract only first (-first_only) returns or
only last returns (-last_only). Extracting the first return is actually the
same as eliminating all others (e.g. -elim_return 2 -elim_return 3, ...).
PROGRAMMERS:
martin isenburg@cs.unc.edu
COPYRIGHT:
copyright (C) 2007 martin isenburg@cs.unc.edu
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
CHANGE HISTORY:
10 July 2007 -- created after talking with Linda about the H1B process
===============================================================================
*/
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "lasreader.h"
#include "laswriter.h"
#ifdef _WIN32
extern "C" FILE* fopenGzipped(const char* filename, const char* mode);
#endif
void usage()
{
fprintf(stderr,"usage:\n");
fprintf(stderr,"las2las -remove_extra_header in.las out.las\n");
fprintf(stderr,"las2las -i in.las -clip 63000000 483450000 63050000 483500000 -o out.las\n");
fprintf(stderr,"las2las -i in.las -eliminate_return 2 -o out.las\n");
fprintf(stderr,"las2las -i in.las -eliminate_scan_angle_above 15 -o out.las\n");
fprintf(stderr,"las2las -i in.las -eliminate_intensity_below 1000 -olas > out.las\n");
fprintf(stderr,"las2las -i in.las -first_only -clip 63000000 483450000 63050000 483500000 -o out.las\n");
fprintf(stderr,"las2las -i in.las -last_only -eliminate_intensity_below 2000 -olas > out.las\n");
fprintf(stderr,"las2las -i in.las -keep_class 2 -keep_class 3 -keep_class 4 -olas > out.las\n");
fprintf(stderr,"las2las -h\n");
exit(1);
}
void ptime(const char *const msg)
{
float t= ((float)clock())/CLOCKS_PER_SEC;
fprintf(stderr, "cumulative CPU time thru %s = %f\n", msg, t);
}
int main(int argc, char *argv[])
{
int i;
bool verbose = false;
char* file_name_in = 0;
char* file_name_out = 0;
bool olas = false;
bool olaz = false;
int* clip_xy_min = 0;
int* clip_xy_max = 0;
bool remove_extra_header = false;
int elim_return = 0;
int elim_scan_angle_above = 0;
int elim_intensity_below = 0;
int keep_classification[32] = {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1};
bool first_only = false;
bool last_only = false;
for (i = 1; i < argc; i++)
{
if (strcmp(argv[i],"-verbose") == 0)
{
verbose = true;
}
else if (strcmp(argv[i],"-h") == 0)
{
usage();
}
else if (strcmp(argv[i],"-i") == 0)
{
i++;
file_name_in = argv[i];
}
else if (strcmp(argv[i],"-o") == 0)
{
i++;
file_name_out = argv[i];
}
else if (strcmp(argv[i],"-olas") == 0)
{
olas = true;
}
else if (strcmp(argv[i],"-olaz") == 0)
{
olaz = true;
}
else if (strcmp(argv[i],"-clip") == 0 || strcmp(argv[i],"-clip_xy") == 0)
{
clip_xy_min = new int[2];
i++;
clip_xy_min[0] = atoi(argv[i]);
i++;
clip_xy_min[1] = atoi(argv[i]);
clip_xy_max = new int[2];
i++;
clip_xy_max[0] = atoi(argv[i]);
i++;
clip_xy_max[1] = atoi(argv[i]);
}
else if (strcmp(argv[i],"-eliminate_return") == 0 || strcmp(argv[i],"-elim_return") == 0 || strcmp(argv[i],"-elim_ret") == 0)
{
i++;
elim_return |= (1 << atoi(argv[i]));
}
else if (strcmp(argv[i],"-eliminate_scan_angle_above") == 0 || strcmp(argv[i],"-elim_scan_angle_above") == 0)
{
i++;
elim_scan_angle_above = atoi(argv[i]);
}
else if (strcmp(argv[i],"-eliminate_intensity_below") == 0 || strcmp(argv[i],"-elim_intensity_below") == 0)
{
i++;
elim_intensity_below = atoi(argv[i]);
}
else if (strcmp(argv[i],"-keep_classification") == 0 || strcmp(argv[i],"-keep_class") == 0)
{
i++;
int j = 0;
while (keep_classification[j] != -1) j++;
keep_classification[j] = atoi(argv[i]);
}
else if (strcmp(argv[i],"-first_only") == 0)
{
first_only = true;
}
else if (strcmp(argv[i],"-last_only") == 0)
{
last_only = true;
}
else if (strcmp(argv[i],"-remove_extra_header") == 0)
{
remove_extra_header = true;
}
else if (i == argc - 2 && file_name_in == 0 && file_name_out == 0)
{
file_name_in = argv[i];
}
else if (i == argc - 1 && file_name_in == 0 && file_name_out == 0)
{
file_name_in = argv[i];
}
else if (i == argc - 1 && file_name_in != 0 && file_name_out == 0)
{
file_name_out = argv[i];
}
}
// open input file
FILE* file_in;
if (file_name_in)
{
if (strstr(file_name_in, ".gz"))
{
#ifdef _WIN32
file_in = fopenGzipped(file_name_in, "rb");
#else
fprintf(stderr, "ERROR: no support for gzipped input\n");
exit(1);
#endif
}
else
{
file_in = fopen(file_name_in, "rb");
}
if (file_in == 0)
{
fprintf(stderr, "ERROR: could not open '%s'\n",file_name_in);
usage();
}
}
else
{
fprintf(stderr, "ERROR: no input specified\n");
usage();
}
LASreader* lasreader = new LASreader();
if (lasreader->open(file_in, true) == false)
{
fprintf(stderr, "ERROR: could not open lasreader\n");
exit(1);
}
// do the first pass
bool first_surviving_point = true;
unsigned int surviving_number_of_point_records = 0;
unsigned int surviving_number_of_points_by_return[] = {0,0,0,0,0,0,0,0};
LASpoint surviving_point_min;
LASpoint surviving_point_max;
double surviving_gps_time_min;
double surviving_gps_time_max;
int clipped = 0;
int eliminated_return = 0;
int eliminated_scan_angle = 0;
int eliminated_intensity = 0;
int eliminated_first_only = 0;
int eliminated_last_only = 0;
int eliminated_classification = 0;
if (verbose) ptime("start.");
fprintf(stderr, "first pass reading %d points ...\n", lasreader->npoints);
while (lasreader->read_point())
{
// put the points through all the tests
if (last_only && lasreader->point.return_number != lasreader->point.number_of_returns_of_given_pulse)
{
eliminated_last_only++;
continue;
}
if (first_only && lasreader->point.return_number != 1)
{
eliminated_first_only++;
continue;
}
if (clip_xy_min && (lasreader->point.x < clip_xy_min[0] || lasreader->point.y < clip_xy_min[1]))
{
clipped++;
continue;
}
if (clip_xy_max && (lasreader->point.x > clip_xy_max[0] || lasreader->point.y > clip_xy_max[1]))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -