1 /*
2 ===============================================================================
3 
4   FILE:  lasindex.hpp
5 
6   CONTENTS:
7 
8     This class can create a spatial indexing, store a spatial indexing, write
9     a spatial indexing to file, read a spatial indexing from file, and - most
10     importantly - it can be used together with a lasreader for efficient access
11     to a particular spatial region of a LAS file or a LAZ file.
12 
13   PROGRAMMERS:
14 
15     martin.isenburg@rapidlasso.com  -  http://rapidlasso.com
16 
17   COPYRIGHT:
18 
19     (c) 2007-2017, martin isenburg, rapidlasso - fast tools to catch reality
20 
21     This is free software; you can redistribute and/or modify it under the
22     terms of the GNU Lesser General Licence as published by the Free Software
23     Foundation. See the LICENSE.txt file for more information.
24 
25     This software is distributed WITHOUT ANY WARRANTY and without even the
26     implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 
28   CHANGE HISTORY:
29 
30      7 September 2018 -- replaced calls to _strdup with calls to the LASCopyString macro
31      7 January 2017 -- add read(FILE* file) for Trimble LASzip DLL improvement
32      2 April 2015 -- add seek_next(LASreadPoint* reader, I64 &p_count) for DLL
33      2 April 2015 -- delete read_next(LASreader* lasreader) that was not used
34     31 March 2015 -- remove unused LASquadtree inheritance of abstract LASspatial
35     29 April 2011 -- created after cable outage during the royal wedding (-:
36 
37 ===============================================================================
38 */
39 #ifndef LAS_INDEX_HPP
40 #define LAS_INDEX_HPP
41 
42 #include <stdio.h>
43 
44 #include "mydefs.hpp"
45 
46 class LASquadtree;
47 class LASinterval;
48 #ifdef LASZIPDLL_EXPORTS
49 class LASreadPoint;
50 #else
51 class LASreader;
52 #endif
53 class ByteStreamIn;
54 class ByteStreamOut;
55 
56 class LASLIB_DLL LASindex
57 {
58 public:
59   LASindex();
60   ~LASindex();
61 
62   // create spatial index
63   void prepare(LASquadtree* spatial, I32 threshold=1000);
64   BOOL add(const F64 x, const F64 y, const U32 index);
65   void complete(U32 minimum_points=100000, I32 maximum_intervals=-1, const BOOL verbose=TRUE);
66 
67   // read from file or write to file
68   BOOL read(FILE* file);
69   BOOL write(FILE* file) const;
70   BOOL read(const char* file_name);
71   BOOL append(const char* file_name) const;
72   BOOL write(const char* file_name) const;
73   BOOL read(ByteStreamIn* stream);
74   BOOL write(ByteStreamOut* stream) const;
75 
76   // intersect
77   BOOL intersect_rectangle(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y);
78   BOOL intersect_tile(const F32 ll_x, const F32 ll_y, const F32 size);
79   BOOL intersect_circle(const F64 center_x, const F64 center_y, const F64 radius);
80 
81   // access the intersected intervals
82   BOOL get_intervals();
83   BOOL has_intervals();
84 
85   U32 start;
86   U32 end;
87   U32 full;
88   U32 total;
89   U32 cells;
90 
91   // seek to next interval
92 #ifdef LASZIPDLL_EXPORTS
93   BOOL seek_next(LASreadPoint* reader, I64 &p_count);
94 #else
95   BOOL seek_next(LASreader* lasreader);
96 #endif
97 
98   // for debugging
99   void print(BOOL verbose);
100 
101   // for visualization
102   LASquadtree* get_spatial() const;
103   LASinterval* get_interval() const;
104 
105 private:
106   BOOL merge_intervals();
107 
108   LASquadtree* spatial;
109   LASinterval* interval;
110   BOOL have_interval;
111 };
112 
113 #endif
114