lasquadtree.hpp
Go to the documentation of this file.
1 /*
2 ===============================================================================
3 
4  FILE: lasquadtree.hpp
5 
6  CONTENTS:
7 
8  An efficient quadtree that can be used for spatial indexing, for tiling,
9  for sorting into space-filling curve order, and for injecting spatial
10  finalization tags to be used in memory-efficienct streaming algorithms.
11 
12  PROGRAMMERS:
13 
14  martin.isenburg@gmail.com
15 
16  COPYRIGHT:
17 
18  (c) 2009-11, Martin Isenburg, LASSO - tools to catch reality
19 
20  This is free software; you can redistribute and/or modify it under the
21  terms of the GNU Lesser General Licence as published by the Free Software
22  Foundation. See the COPYING file for more information.
23 
24  This software is distributed WITHOUT ANY WARRANTY and without even the
25  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 
27  CHANGE HISTORY:
28 
29  11 May 2011 -- moved into LASlib so that LASreader supports spatial indexing
30  19 January 2011 -- created after mara met with silke to talk about africa
31 
32 ===============================================================================
33 */
34 #ifndef LAS_QUADTREE_HPP
35 #define LAS_QUADTREE_HPP
36 
37 #include "lasspatial.hpp"
38 
39 class LASquadtree : public LASspatial
40 {
41 public:
42  LASquadtree();
43  ~LASquadtree();
44 
45  // read from file or write to file
46  BOOL read(ByteStreamIn* stream);
47  BOOL write(ByteStreamOut* stream) const;
48 
49  // create or finalize the cell (in the spatial hierarchy)
50  BOOL manage_cell(const U32 cell_index, const BOOL finalize=FALSE);
51 
52  // map points to cells
53  BOOL inside(const F64 x, const F64 y) const;
54  U32 get_cell_index(const F64 x, const F64 y) const;
55 
56  // map cells to coarser cells
57  BOOL coarsen(const I32 cell_index, I32* coarser_cell_index, U32* num_cell_indices, I32** cell_indices) const;
58 
59  // describe cells
60  void get_cell_bounding_box(const I32 cell_index, F32* min, F32* max) const;
61  void get_cell_bounding_box(const F64 x, const F64 y, F32* min, F32* max) const;
62 
63  // decribe spatial extend
64  F64 get_min_x() const { return min_x; };
65  F64 get_min_y() const { return min_y; };
66  F64 get_max_x() const { return max_x; };
67  F64 get_max_y() const { return max_y; };
68 
69  // query spatial intersections
70  U32 intersect_rectangle(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y);
71  U32 intersect_tile(const F32 ll_x, const F32 ll_y, const F32 size);
72  U32 intersect_circle(const F64 center_x, const F64 center_y, const F64 radius);
73 
74  // iterate over cells
78 
79  // for LASquadtree
80  BOOL setup(F64 bb_min_x, F64 bb_max_x, F64 bb_min_y, F64 bb_max_y, F32 cell_size = 1000.0f);
82 
83  // additional index queries
84  U32 get_level_index(const F64 x, const F64 y, U32 level) const;
85  U32 get_level_index(const F64 x, const F64 y) const;
86  U32 get_level_index(const F64 x, const F64 y, U32 level, F32* min, F32* max) const;
87  U32 get_level_index(const F64 x, const F64 y, F32* min, F32* max) const;
88  U32 get_cell_index(const F64 x, const F64 y, U32 level) const;
89 
90  // additional bounding box queries
91  void get_cell_bounding_box(const F64 x, const F64 y, U32 level, F32* min, F32* max) const;
92  void get_cell_bounding_box(U32 level_index, U32 level, F32* min, F32* max) const;
93  void get_cell_bounding_box(U32 level_index, F32* min, F32* max) const;
94 
95  // index conversions
96  U32 get_level(U32 cell_index) const;
97 
98  U32 get_level_index(U32 cell_index, U32 level) const;
99  U32 get_level_index(U32 cell_index) const;
100 
101  U32 get_cell_index(U32 level_index, U32 level) const;
102  U32 get_cell_index(U32 level_index) const;
103 
104  // convenience functions
105  U32 get_max_level_index(U32 level) const;
106  U32 get_max_level_index() const;
107 
108  U32 get_max_cell_index(U32 level) const;
109  U32 get_max_cell_index() const;
110 
111  U32* raster_occupancy(BOOL(*does_cell_exist)(I32), U32 level) const;
112  U32* raster_occupancy(BOOL(*does_cell_exist)(I32)) const;
113 
122 
123  // spatial queries
124  U32 intersect_rectangle(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, U32 level);
125  U32 intersect_tile(const F32 ll_x, const F32 ll_y, const F32 size, U32 level);
126  U32 intersect_circle(const F64 center_x, const F64 center_y, const F64 radius, U32 level);
127 
128 private:
135 
136  void intersect_rectangle_with_cells(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index);
137  void intersect_rectangle_with_cells_adaptive(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index);
138  void intersect_tile_with_cells(const F32 ll_x, const F32 ll_y, const F32 ur_x, const F32 ur_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index);
139  void intersect_tile_with_cells_adaptive(const F32 ll_x, const F32 ll_y, const F32 ur_x, const F32 ur_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index);
140  void intersect_circle_with_cells(const F64 center_x, const F64 center_y, const F64 radius, const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index);
141  void intersect_circle_with_cells_adaptive(const F64 center_x, const F64 center_y, const F64 radius, const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index);
142  BOOL intersect_circle_with_rectangle(const F64 center_x, const F64 center_y, const F64 radius, const F32 r_min_x, const F32 r_max_x, const F32 r_min_y, const F32 r_max_y);
143  void raster_occupancy(BOOL(*does_cell_exist)(I32), U32* data, U32 min_x, U32 min_y, U32 level_index, U32 level, U32 stop_level) const;
146 };
147 
148 #endif
LASquadtree::intersect_rectangle_with_cells
void intersect_rectangle_with_cells(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index)
Definition: lasquadtree.cpp:815
LASquadtree
Definition: lasquadtree.hpp:39
LASquadtree::manage_cell
BOOL manage_cell(const U32 cell_index, const BOOL finalize=FALSE)
Definition: lasquadtree.cpp:659
LASquadtree::next_cell_index
U32 next_cell_index
Definition: lasquadtree.hpp:145
LASquadtree::intersect_tile_with_cells_adaptive
void intersect_tile_with_cells_adaptive(const F32 ll_x, const F32 ll_y, const F32 ur_x, const F32 ur_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index)
Definition: lasquadtree.cpp:1067
LASquadtree::get_min_y
F64 get_min_y() const
Definition: lasquadtree.hpp:65
LASquadtree::adaptive_alloc
U32 adaptive_alloc
Definition: lasquadtree.hpp:133
LASquadtree::intersect_circle_with_cells
void intersect_circle_with_cells(const F64 center_x, const F64 center_y, const F64 radius, const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index)
Definition: lasquadtree.cpp:1153
LASquadtree::read
BOOL read(ByteStreamIn *stream)
Definition: lasquadtree.cpp:518
LASquadtree::max_y
F32 max_y
Definition: lasquadtree.hpp:119
LASquadtree::intersect_circle_with_cells_adaptive
void intersect_circle_with_cells_adaptive(const F64 center_x, const F64 center_y, const F64 radius, const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index)
Definition: lasquadtree.cpp:1239
LASquadtree::has_more_cells
BOOL has_more_cells()
Definition: lasquadtree.cpp:1407
F64
double F64
Definition: mydefs.hpp:52
LASquadtree::get_min_x
F64 get_min_x() const
Definition: lasquadtree.hpp:64
LASquadtree::get_level_index
U32 get_level_index(const F64 x, const F64 y, U32 level) const
Definition: lasquadtree.cpp:217
LASquadtree::get_all_cells
BOOL get_all_cells()
Definition: lasquadtree.cpp:1387
I32
int I32
Definition: mydefs.hpp:35
LASquadtree::setup
BOOL setup(F64 bb_min_x, F64 bb_max_x, F64 bb_min_y, F64 bb_max_y, F32 cell_size=1000.0f)
Definition: lasquadtree.cpp:1429
LASquadtree::intersect_tile
U32 intersect_tile(const F32 ll_x, const F32 ll_y, const F32 size)
Definition: lasquadtree.cpp:772
LASquadtree::write
BOOL write(ByteStreamOut *stream) const
Definition: lasquadtree.cpp:591
LASquadtree::intersect_rectangle
U32 intersect_rectangle(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y)
Definition: lasquadtree.cpp:736
LASquadtree::levels
U32 levels
Definition: lasquadtree.hpp:114
LASquadtree::get_max_y
F64 get_max_y() const
Definition: lasquadtree.hpp:67
LASquadtree::get_level
U32 get_level(U32 cell_index) const
Definition: lasquadtree.cpp:390
LASquadtree::cell_size
F32 cell_size
Definition: lasquadtree.hpp:115
LASquadtree::coarsen
BOOL coarsen(const I32 cell_index, I32 *coarser_cell_index, U32 *num_cell_indices, I32 **cell_indices) const
Definition: lasquadtree.cpp:349
LASspatial
Definition: lasspatial.hpp:42
LASquadtree::sub_level
U32 sub_level
Definition: lasquadtree.hpp:129
LASquadtree::cells_x
U32 cells_x
Definition: lasquadtree.hpp:120
LASquadtree::LASquadtree
LASquadtree()
Definition: lasquadtree.cpp:1499
LASquadtree::coarser_indices
U32 coarser_indices[4]
Definition: lasquadtree.hpp:132
LASquadtree::sub_level_index
U32 sub_level_index
Definition: lasquadtree.hpp:130
LASquadtree::subtiling_setup
BOOL subtiling_setup(F32 min_x, F32 max_x, F32 min_y, F32 max_y, U32 sub_level, U32 sub_level_index, U32 levels)
Definition: lasquadtree.cpp:1480
ByteStreamOut
Definition: bytestreamout.hpp:36
LASquadtree::intersect_circle
U32 intersect_circle(const F64 center_x, const F64 center_y, const F64 radius)
Definition: lasquadtree.cpp:810
LASquadtree::level_offset
U32 level_offset[24]
Definition: lasquadtree.hpp:131
LASquadtree::inside
BOOL inside(const F64 x, const F64 y) const
Definition: lasquadtree.cpp:696
ByteStreamIn
Definition: bytestreamin.hpp:36
LASquadtree::intersect_tile_with_cells
void intersect_tile_with_cells(const F32 ll_x, const F32 ll_y, const F32 ur_x, const F32 ur_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index)
Definition: lasquadtree.cpp:984
LASquadtree::get_max_cell_index
U32 get_max_cell_index() const
Definition: lasquadtree.cpp:435
LASquadtree::raster_occupancy
U32 * raster_occupancy(BOOL(*does_cell_exist)(I32), U32 level) const
Definition: lasquadtree.cpp:498
BOOL
int BOOL
Definition: mydefs.hpp:57
FALSE
#define FALSE
Definition: mydefs.hpp:133
F32
float F32
Definition: mydefs.hpp:51
LASquadtree::get_cell_index
U32 get_cell_index(const F64 x, const F64 y) const
Definition: lasquadtree.cpp:343
LASquadtree::get_cell_bounding_box
void get_cell_bounding_box(const I32 cell_index, F32 *min, F32 *max) const
Definition: lasquadtree.cpp:209
LASquadtree::get_max_x
F64 get_max_x() const
Definition: lasquadtree.hpp:66
LASquadtree::max_x
F32 max_x
Definition: lasquadtree.hpp:117
LASquadtree::get_intersected_cells
BOOL get_intersected_cells()
Definition: lasquadtree.cpp:1393
lasspatial.hpp
U32
unsigned int U32
Definition: mydefs.hpp:39
LASquadtree::get_max_level_index
U32 get_max_level_index() const
Definition: lasquadtree.cpp:423
LASquadtree::cells_y
U32 cells_y
Definition: lasquadtree.hpp:121
LASquadtree::intersect_circle_with_rectangle
BOOL intersect_circle_with_rectangle(const F64 center_x, const F64 center_y, const F64 radius, const F32 r_min_x, const F32 r_max_x, const F32 r_min_y, const F32 r_max_y)
Definition: lasquadtree.cpp:1328
LASquadtree::intersect_rectangle_with_cells_adaptive
void intersect_rectangle_with_cells_adaptive(const F64 r_min_x, const F64 r_min_y, const F64 r_max_x, const F64 r_max_y, const F32 cell_min_x, const F32 cell_max_x, const F32 cell_min_y, const F32 cell_max_y, U32 level, U32 level_index)
Definition: lasquadtree.cpp:898
LASquadtree::min_y
F32 min_y
Definition: lasquadtree.hpp:118
LASquadtree::adaptive
U32 * adaptive
Definition: lasquadtree.hpp:134
LASquadtree::current_cells
void * current_cells
Definition: lasquadtree.hpp:144
LASquadtree::min_x
F32 min_x
Definition: lasquadtree.hpp:116
LASquadtree::~LASquadtree
~LASquadtree()
Definition: lasquadtree.cpp:1521


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Wed Mar 2 2022 00:37:23