1 /*
2 ===============================================================================
3 
4   FILE:  lasreader.hpp
5 
6   CONTENTS:
7 
8     Interface to read LIDAR points from the LAS format versions 1.0 - 1.3 and
9     per on-the-fly conversion from simple ASCII files.
10 
11   PROGRAMMERS:
12 
13     martin.isenburg@rapidlasso.com  -  http://rapidlasso.com
14 
15   COPYRIGHT:
16 
17     (c) 2007-2017, martin isenburg, rapidlasso - fast tools to catch reality
18 
19     This is free software; you can redistribute and/or modify it under the
20     terms of the GNU Lesser General Licence as published by the Free Software
21     Foundation. See the LICENSE.txt file for more information.
22 
23     This software is distributed WITHOUT ANY WARRANTY and without even the
24     implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
25 
26   CHANGE HISTORY:
27 
28      7 September 2018 -- replaced calls to _strdup with calls to the LASCopyString macro
29      8 February 2018 -- new LASreaderStored via '-stored' option to allow piped operation
30     15 December 2017 -- optional '-files_are_flightline 101' start number like '-faf 101'
31     21 November 2017 -- allow adding up to 32 (from 10) additional extra bytes attributes
32      5 August 2017 -- unless '-buffered 25' just created buffers always '-remain_buffered'
33      5 August 2017 -- removed option '-unbuffered' because it makes too many assumptions
34      7 February 2014 -- added option '-apply_file_source_ID' when reading LAS/LAZ
35     22 August 2012 -- added the '-pipe_on' option for a multi-stage LAStools pipeline
36     11 August 2012 -- added on-the-fly buffered reading of LiDAR files (efficient with LAX)
37     5 September 2011 -- support for reading Terrasolid's BIN format
38     11 June 2011 -- billion point support: p_count & npoints are 64 bit counters
39     9 April 2011 -- added capability to read on-the-fly conversion from ASCII
40     24 January 2011 -- introduced LASreadOpener
41     21 January 2011 -- turned into abstract reader to support multiple files
42     3 December 2010 -- updated to (somewhat) support LAS format 1.3
43     7 September 2008 -- updated to support LAS format 1.2
44     18 February 2007 -- created after repairing 2 vacuum cleaners in the garden
45 
46 ===============================================================================
47 */
48 #ifndef LAS_READER_HPP
49 #define LAS_READER_HPP
50 
51 #include "lasdefinitions.hpp"
52 
53 class LASindex;
54 class LASfilter;
55 class LAStransform;
56 class ByteStreamIn;
57 
58 class LASLIB_DLL LASreader
59 {
60 public:
61   LASheader header;
62   LASpoint point;
63 
64   I64 npoints;
65   I64 p_count;
66 
67   virtual I32 get_format() const = 0;
has_layers() const68   virtual BOOL has_layers() const { return FALSE; };
69 
70   void set_index(LASindex* index);
get_index() const71   inline LASindex* get_index() const { return index; };
72   virtual void set_filter(LASfilter* filter);
get_filter() const73   inline LASfilter* get_filter() const { return filter; };
74   virtual void set_transform(LAStransform* transform);
get_transform() const75   inline LAStransform* get_transform() const { return transform; };
76 
get_inside() const77   inline U32 get_inside() const { return inside; };
78   virtual BOOL inside_none();
79   virtual BOOL inside_tile(const F32 ll_x, const F32 ll_y, const F32 size);
get_t_ll_x() const80   inline F32 get_t_ll_x() const { return t_ll_x; };
get_t_ll_y() const81   inline F32 get_t_ll_y() const { return t_ll_y; };
get_t_size() const82   inline F32 get_t_size() const { return t_size; };
83   virtual BOOL inside_circle(const F64 center_x, const F64 center_y, const F64 radius);
get_c_center_x() const84   inline F64 get_c_center_x() const { return c_center_x; };
get_c_center_y() const85   inline F64 get_c_center_y() const { return c_center_y; };
get_c_radius() const86   inline F64 get_c_radius() const { return c_radius; };
87   virtual BOOL inside_rectangle(const F64 min_x, const F64 min_y, const F64 max_x, const F64 max_y);
get_r_min_x() const88   inline F64 get_r_min_x() const { return r_min_x; };
get_r_min_y() const89   inline F64 get_r_min_y() const { return r_min_y; };
get_r_max_x() const90   inline F64 get_r_max_x() const { return r_max_x; };
get_r_max_y() const91   inline F64 get_r_max_y() const { return r_max_y; };
92 
93   virtual BOOL seek(const I64 p_index) = 0;
read_point()94   BOOL read_point() { return (this->*read_simple)(); };
95 
compute_coordinates()96   inline void compute_coordinates() { point.compute_coordinates(); };
97 
get_min_x() const98   inline F64 get_min_x() const { return header.min_x; };
get_min_y() const99   inline F64 get_min_y() const { return header.min_y; };
get_min_z() const100   inline F64 get_min_z() const { return header.min_z; };
101 
get_max_x() const102   inline F64 get_max_x() const { return header.max_x; };
get_max_y() const103   inline F64 get_max_y() const { return header.max_y; };
get_max_z() const104   inline F64 get_max_z() const { return header.max_z; };
105 
get_x() const106   inline F64 get_x() const { return get_x(point.get_X()); };
get_y() const107   inline F64 get_y() const { return get_y(point.get_Y()); };
get_z() const108   inline F64 get_z() const { return get_z(point.get_Z()); };
109 
get_x(const I32 x) const110   inline F64 get_x(const I32 x) const { return header.get_x(x); };
get_y(const I32 y) const111   inline F64 get_y(const I32 y) const { return header.get_y(y); };
get_z(const I32 z) const112   inline F64 get_z(const I32 z) const { return header.get_z(z); };
113 
get_X(const F64 x) const114   inline I32 get_X(const F64 x) const { return header.get_X(x); };
get_Y(const F64 y) const115   inline I32 get_Y(const F64 y) const { return header.get_Y(y); };
get_Z(const F64 z) const116   inline I32 get_Z(const F64 z) const { return header.get_Z(z); };
117 
118   virtual ByteStreamIn* get_stream() const = 0;
119   virtual void close(BOOL close_stream=TRUE) = 0;
120 
121   LASreader();
122   virtual ~LASreader();
123 
124 protected:
125   virtual BOOL read_point_default() = 0;
126 
127   LASindex* index;
128   LASfilter* filter;
129   LAStransform* transform;
130 
131   U32 inside;
132   F32 t_ll_x, t_ll_y, t_size, t_ur_x, t_ur_y;
133   F64 c_center_x, c_center_y, c_radius, c_radius_squared;
134   F64 r_min_x, r_min_y, r_max_x, r_max_y;
135   F64 orig_min_x, orig_min_y, orig_max_x, orig_max_y;
136 
137 private:
138   BOOL (LASreader::*read_simple)();
139   BOOL (LASreader::*read_complex)();
140 
141   BOOL read_point_none();
142   BOOL read_point_filtered();
143   BOOL read_point_transformed();
144   BOOL read_point_filtered_and_transformed();
145 
146   BOOL read_point_inside_tile();
147   BOOL read_point_inside_tile_indexed();
148   BOOL read_point_inside_circle();
149   BOOL read_point_inside_circle_indexed();
150   BOOL read_point_inside_rectangle();
151   BOOL read_point_inside_rectangle_indexed();
152 };
153 
154 #include "laswaveform13reader.hpp"
155 
156 class LASLIB_DLL LASreadOpener
157 {
158 public:
159   void set_io_ibuffer_size(I32 io_ibuffer_size);
get_io_ibuffer_size() const160   inline I32 get_io_ibuffer_size() const { return io_ibuffer_size; };
161   U32 get_file_name_number() const;
162   U32 get_file_name_current() const;
163   const CHAR* get_file_name() const;
164   const CHAR* get_file_name_only() const;
165   const CHAR* get_file_name(U32 number) const;
166   void set_file_name(const CHAR* file_name, BOOL unique=FALSE);
167   BOOL add_file_name(const CHAR* file_name, BOOL unique=FALSE);
168   BOOL add_list_of_files(const CHAR* list_of_files, BOOL unique=FALSE);
169   void delete_file_name(U32 file_name_id);
170   BOOL set_file_name_current(U32 file_name_id);
171   I32 get_file_format(U32 number) const;
172   void set_merged(const BOOL merged);
is_merged() const173   BOOL is_merged() const { return merged; };
174   void set_stored(const BOOL stored);
is_stored() const175   BOOL is_stored() const { return stored; };
176   void set_buffer_size(const F32 buffer_size);
177   F32 get_buffer_size() const;
178   void set_neighbor_file_name(const CHAR* neighbor_file_name, BOOL unique=FALSE);
179   BOOL add_neighbor_file_name(const CHAR* neighbor_file_name, BOOL unique=FALSE);
180   void set_auto_reoffset(const BOOL auto_reoffset);
is_auto_reoffset() const181   inline BOOL is_auto_reoffset() const { return auto_reoffset; };
182   void set_files_are_flightlines(const I32 files_are_flightlines);
are_files_flightlines() const183   inline I32 are_files_flightlines() const { return files_are_flightlines; };
184   void set_files_are_flightlines_index(const I32 files_are_flightlines_index);
get_files_flight_index() const185   inline I32 get_files_flight_index() const { return files_are_flightlines_index; };
186   void set_apply_file_source_ID(const BOOL apply_file_source_ID);
applying_file_source_ID() const187   inline BOOL applying_file_source_ID() const { return apply_file_source_ID; };
188   void set_scale_factor(const F64* scale_factor);
get_scale_factor() const189   inline const F64* get_scale_factor() const { return scale_factor; };
190   void set_offset(const F64* offset);
get_offset() const191   inline const F64* get_offset() const { return offset; };
192   void set_translate_intensity(F32 translate_intensity);
193   void set_scale_intensity(F32 scale_intensity);
194   void set_translate_scan_angle(F32 translate_scan_angle);
195   void set_scale_scan_angle(F32 scale_scan_angle);
196   void add_attribute(I32 data_type, const CHAR* name, const CHAR* description=0, F64 scale=1.0, F64 offset=0.0, F64 pre_scale=1.0, F64 pre_offset=0.0, F64 no_data=F64_MAX);
197   BOOL set_point_type(U8 point_type);
198   void set_parse_string(const CHAR* parse_string);
199   void set_skip_lines(I32 skip_lines);
200   void set_populate_header(BOOL populate_header);
201   void set_keep_lastiling(BOOL keep_lastiling);
202   void set_pipe_on(BOOL pipe_on);
203   const CHAR* get_parse_string() const;
204   void usage() const;
205   void set_decompress_selective(U32 decompress_selective);
206   void set_inside_tile(const F32 ll_x, const F32 ll_y, const F32 size);
207   void set_inside_circle(const F64 center_x, const F64 center_y, const F64 radius);
208   void set_inside_rectangle(const F64 min_x, const F64 min_y, const F64 max_x, const F64 max_y);
209   BOOL parse(int argc, char* argv[]);
210   BOOL is_piped() const;
211   BOOL is_buffered() const;
212   BOOL is_header_populated() const;
213   BOOL active() const;
214   BOOL is_inside() const;
215   I32 unparse(CHAR* string) const;
216   void set_filter(LASfilter* filter);
get_filter()217   LASfilter* get_filter() { return filter; };
218   void set_transform(LAStransform* transform);
get_transform()219   LAStransform* get_transform() { return transform; };
220   void reset();
get_temp_file_base() const221   const CHAR* get_temp_file_base() const { return temp_file_base; };
222   LASreader* open(const CHAR* other_file_name=0, BOOL reset_after_other=TRUE);
223   BOOL reopen(LASreader* lasreader, BOOL remain_buffered=TRUE);
224   LASwaveform13reader* open_waveform13(const LASheader* lasheader);
225   LASreadOpener();
226   ~LASreadOpener();
227 private:
228 #ifdef _WIN32
229   BOOL add_file_name_single(const CHAR* file_name, BOOL unique=FALSE);
230   BOOL add_neighbor_file_name_single(const CHAR* neighbor_file_name, BOOL unique=FALSE);
231 #endif
232   I32 io_ibuffer_size;
233   CHAR** file_names;
234   const CHAR* file_name;
235   BOOL merged;
236   BOOL stored;
237   U32 file_name_number;
238   U32 file_name_allocated;
239   U32 file_name_current;
240   F32 buffer_size;
241   CHAR* temp_file_base;
242   CHAR** neighbor_file_names;
243   U32 neighbor_file_name_number;
244   U32 neighbor_file_name_allocated;
245   BOOL comma_not_point;
246   F64* scale_factor;
247   F64* offset;
248   BOOL auto_reoffset;
249   I32 files_are_flightlines;
250   I32 files_are_flightlines_index;
251   BOOL apply_file_source_ID;
252   BOOL itxt;
253   BOOL ipts;
254   BOOL iptx;
255   F32 translate_intensity;
256   F32 scale_intensity;
257   F32 translate_scan_angle;
258   F32 scale_scan_angle;
259   I32 number_attributes;
260   I32 attribute_data_types[32];
261   CHAR* attribute_names[32];
262   CHAR* attribute_descriptions[32];
263   F64 attribute_scales[32];
264   F64 attribute_offsets[32];
265   F64 attribute_pre_scales[32];
266   F64 attribute_pre_offsets[32];
267   F64 attribute_no_datas[32];
268   U8 point_type;
269   CHAR* parse_string;
270   I32 skip_lines;
271   BOOL populate_header;
272   BOOL keep_lastiling;
273   BOOL pipe_on;
274   BOOL use_stdin;
275   BOOL unique;
276 
277   // optional extras
278   LASindex* index;
279   LASfilter* filter;
280   LAStransform* transform;
281 
282   // optional selective decompression (compressed new LAS 1.4 point types only)
283   U32 decompress_selective;
284 
285   // optional area-of-interest query (spatially indexed)
286   F32* inside_tile;
287   F64* inside_circle;
288   F64* inside_rectangle;
289 };
290 
291 #endif
292