Skip to content

Commit 3c55459

Browse files
author
Martin Isenburg
committed
added useless LASkdtreePoint after four weeks of memoy pain in Samara
1 parent cbfa7e2 commit 3c55459

2 files changed

Lines changed: 90 additions & 3 deletions

File tree

LASlib/inc/laskdtree.hpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
66
CONTENTS:
77
8-
Tree structure for fast overlap checks of rectangles with list of rectangles
8+
Tree structure for fast overlap checks of points or rectangles with list
9+
of rectangles
910
1011
PROGRAMMERS:
1112
1213
martin.isenburg@rapidlasso.com - http://rapidlasso.com
1314
1415
COPYRIGHT:
1516
16-
(c) 2007-2019, martin isenburg, rapidlasso - fast tools to catch reality
17+
(c) 2007-2021, martin isenburg, rapidlasso - fast tools to catch reality
1718
1819
This is free software; you can redistribute and/or modify it under the
1920
terms of the GNU Lesser General Licence as published by the Free Software
@@ -24,6 +25,7 @@
2425
2526
CHANGE HISTORY:
2627
28+
26 June 2021 -- new LASkdtreePoint after four weeks of memoy pain in Samara
2729
26 October 2019 -- created at LoCoworking after three days of rain in Samara
2830
2931
===============================================================================
@@ -56,6 +58,17 @@ class LASkdtreeRectangle
5658
LASkdtreeRectangle(F64 min_x, F64 min_y, F64 max_x, F64 max_y, U32 index);
5759
};
5860

61+
class LASkdtreePoint
62+
{
63+
public:
64+
F64 pos[2];
65+
66+
BOOL overlap(const LASkdtreeRectangle &rectangle) const;
67+
68+
LASkdtreePoint();
69+
LASkdtreePoint(F64 x, F64 y);
70+
};
71+
5972
typedef list<LASkdtreeRectangle> my_rectangle_list;
6073

6174
class LASkdtreeRectanglesNode
@@ -77,7 +90,8 @@ class LASkdtreeRectangles
7790
void add(F64 min_x, F64 min_y, F64 max_x, F64 max_y);
7891
BOOL build();
7992
BOOL was_built() const;
80-
BOOL overlap(F64 min_x, F64 min_y, F64 max_x, F64 max_y);
93+
BOOL overlap(F64 min_x, F64 min_y, F64 max_x, F64 max_y); // rectangle
94+
BOOL overlap(F64 x, F64 y); // point
8195
void print_overlap();
8296
BOOL has_overlaps();
8397
BOOL get_overlap(U32& index);
@@ -93,6 +107,7 @@ class LASkdtreeRectangles
93107

94108
void build_recursive(LASkdtreeRectanglesNode* node, I32 plane, LASkdtreeRectangle bb, my_rectangle_list* insertion_list, I32 unchanged);
95109
void overlap_rectangles(LASkdtreeRectanglesNode* node, I32 plane, LASkdtreeRectangle rectangle, my_index_set* overlap_set);
110+
void overlap_rectangles(LASkdtreeRectanglesNode* node, I32 plane, LASkdtreePoint point, my_index_set* overlap_set);
96111
};
97112

98113
#endif

LASlib/src/laskdtree.cpp

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,27 @@ LASkdtreeRectangle::LASkdtreeRectangle()
6969
idx = 0;
7070
}
7171

72+
BOOL LASkdtreePoint::overlap(const LASkdtreeRectangle &rectangle) const
73+
{
74+
if (pos[0] < rectangle.min[0]) return FALSE;
75+
if (pos[1] < rectangle.min[1]) return FALSE;
76+
if (rectangle.max[0] < pos[0]) return FALSE;
77+
if (rectangle.max[1] < pos[1]) return FALSE;
78+
return TRUE;
79+
}
80+
81+
LASkdtreePoint::LASkdtreePoint(F64 x, F64 y)
82+
{
83+
pos[0] = x;
84+
pos[1] = y;
85+
}
86+
87+
LASkdtreePoint::LASkdtreePoint()
88+
{
89+
pos[0] = 0;
90+
pos[1] = 0;
91+
}
92+
7293
LASkdtreeRectanglesNode::LASkdtreeRectanglesNode()
7394
{
7495
left = 0;
@@ -164,6 +185,18 @@ BOOL LASkdtreeRectangles::overlap(F64 min_x, F64 min_y, F64 max_x, F64 max_y)
164185
return TRUE;
165186
}
166187

188+
BOOL LASkdtreeRectangles::overlap(F64 x, F64 y)
189+
{
190+
if (overlap_set == 0)
191+
{
192+
return FALSE;
193+
}
194+
overlap_set->clear();
195+
LASkdtreePoint point(x, y);
196+
overlap_rectangles(root, 0, point, overlap_set);
197+
return TRUE;
198+
}
199+
167200
BOOL LASkdtreeRectangles::has_overlaps()
168201
{
169202
if (overlap_set && overlap_set->size())
@@ -324,6 +357,45 @@ void LASkdtreeRectangles::overlap_rectangles(LASkdtreeRectanglesNode* node, I32
324357
}
325358
}
326359

360+
void LASkdtreeRectangles::overlap_rectangles(LASkdtreeRectanglesNode* node, I32 plane, LASkdtreePoint point, my_index_set* overlap_set)
361+
{
362+
if (node->list)
363+
{
364+
my_rectangle_list::iterator list_element = node->list->begin();
365+
while (TRUE)
366+
{
367+
if (list_element == node->list->end())
368+
{
369+
break;
370+
}
371+
372+
LASkdtreeRectangle overlap_candidate = (*list_element);
373+
374+
if (point.overlap(overlap_candidate))
375+
{
376+
overlap_set->insert(overlap_candidate.idx);
377+
}
378+
list_element++;
379+
}
380+
}
381+
else
382+
{
383+
// maybe recurse left
384+
385+
if (point.pos[plane] < node->split)
386+
{
387+
overlap_rectangles(node->left, (plane + 1) % 2, point, overlap_set);
388+
}
389+
390+
// maybe recurse right
391+
392+
if (node->split <= point.pos[plane])
393+
{
394+
overlap_rectangles(node->right, (plane + 1) % 2, point, overlap_set);
395+
}
396+
}
397+
}
398+
327399
void LASkdtreeRectangles::print_overlap()
328400
{
329401
fprintf(stderr, "overlap elements: %u\n", (U32)overlap_set->size());

0 commit comments

Comments
 (0)