Skip to content

Commit 2d0e783

Browse files
author
Éric Lemoine
committed
Add zmin and zmax to PCBOUNDS
This is required if we want to take z into account when checking that bounds intersect.
1 parent 7803609 commit 2d0e783

7 files changed

Lines changed: 63 additions & 12 deletions

File tree

lib/pc_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ typedef struct
150150
double xmax;
151151
double ymin;
152152
double ymax;
153+
double zmin;
154+
double zmax;
153155
} PCBOUNDS;
154156

155157
/* Used for generic patch statistics */

lib/pc_patch_dimensional.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pc_patch_dimensional_free(PCPATCH_DIMENSIONAL *pdl)
179179
int
180180
pc_patch_dimensional_compute_extent(PCPATCH_DIMENSIONAL *pdl)
181181
{
182-
double xmin, xmax, ymin, ymax, xavg, yavg;
182+
double xmin, xmax, ymin, ymax, zmin, zmax, xavg, yavg, zavg;
183183
int rv;
184184
PCBYTES *pcb;
185185

@@ -204,6 +204,18 @@ pc_patch_dimensional_compute_extent(PCPATCH_DIMENSIONAL *pdl)
204204
pdl->bounds.ymin = ymin;
205205
pdl->bounds.ymax = ymax;
206206

207+
if ( pdl->schema->z_position > -1 )
208+
{
209+
/* Get z extremes */
210+
pcb = &(pdl->bytes[pdl->schema->z_position]);
211+
rv = pc_bytes_minmax(pcb, &zmin, &zmax, &zavg);
212+
if ( PC_FAILURE == rv ) return PC_FAILURE;
213+
ymin = pc_value_scale_offset(zmin, pdl->schema->dims[pdl->schema->z_position]);
214+
ymax = pc_value_scale_offset(zmax, pdl->schema->dims[pdl->schema->z_position]);
215+
pdl->bounds.zmin = zmin;
216+
pdl->bounds.zmax = zmax;
217+
}
218+
207219
return PC_SUCCESS;
208220
}
209221

lib/pc_patch_ght.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ pc_patch_ght_compute_extent(PCPATCH_GHT *patch)
402402
patch->bounds.ymin = area.y.min;
403403
patch->bounds.ymax = area.y.max;
404404

405+
// GHT does not have z.min and z.max, so a 2d bounds
406+
// is used although the patch may be 3d
407+
405408
// ght_tree_free(tree);
406409

407410
return PC_SUCCESS;

lib/pc_patch_uncompressed.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,20 +191,29 @@ pc_patch_uncompressed_compute_extent(PCPATCH_UNCOMPRESSED *patch)
191191
int i;
192192
PCPOINT *pt = pc_point_from_data(patch->schema, patch->data);
193193
PCBOUNDS b;
194-
double x, y;
194+
double x, y, z;
195195

196196
/* Calculate bounds */
197197
pc_bounds_init(&b);
198198
for ( i = 0; i < patch->npoints; i++ )
199199
{
200200
/* Just push the data buffer forward by one point at a time */
201201
pt->data = patch->data + i * patch->schema->size;
202+
202203
x = pc_point_get_x(pt);
203-
y = pc_point_get_y(pt);
204204
if ( b.xmin > x ) b.xmin = x;
205-
if ( b.ymin > y ) b.ymin = y;
206205
if ( b.xmax < x ) b.xmax = x;
206+
207+
y = pc_point_get_y(pt);
208+
if ( b.ymin > y ) b.ymin = y;
207209
if ( b.ymax < y ) b.ymax = y;
210+
211+
if ( pt->schema->z_position > -1 )
212+
{
213+
z = pc_point_get_z(pt);
214+
if ( b.zmin > z ) b.zmin = z;
215+
if ( b.zmax < z ) b.zmax = z;
216+
}
208217
}
209218

210219
patch->bounds = b;

lib/pc_util.c

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,21 +238,41 @@ uncompressed_bytes_flip_endian(const uint8_t *bytebuf, const PCSCHEMA *schema, u
238238
int
239239
pc_bounds_intersects(const PCBOUNDS *b1, const PCBOUNDS *b2)
240240
{
241-
if ( b1->xmin > b2->xmax ||
242-
b1->xmax < b2->xmin ||
243-
b1->ymin > b2->ymax ||
244-
b1->ymax < b2->ymin )
241+
if ( b1->xmin > b2->xmax ||
242+
b1->xmax < b2->xmin ||
243+
b1->ymin > b2->ymax ||
244+
b1->ymax < b2->ymin )
245245
{
246246
return PC_FALSE;
247247
}
248+
249+
if ( b1->zmin == DBL_MAX && b2->zmin == DBL_MAX )
250+
{
251+
// b1 and b2 are both 2d, so we are done
252+
return PC_TRUE;
253+
}
254+
255+
if ( b1->zmin == DBL_MAX ||
256+
b2->zmin == DBL_MAX )
257+
{
258+
// b1 is 2d and b2 is 3d, or vice-versa
259+
return PC_FALSE;
260+
}
261+
262+
if ( b1->zmin > b2->zmax ||
263+
b1->zmax < b2->zmin )
264+
{
265+
return PC_FALSE;
266+
}
267+
248268
return PC_TRUE;
249269
}
250270

251271
void
252272
pc_bounds_init(PCBOUNDS *b)
253273
{
254-
b->xmin = b->ymin = DBL_MAX;
255-
b->xmax = b->ymax = -1*DBL_MAX;
274+
b->xmin = b->ymin = b->zmin = DBL_MAX;
275+
b->xmax = b->ymax = b->zmax = -1*DBL_MAX;
256276
}
257277

258278
void pc_bounds_merge(PCBOUNDS *b1, const PCBOUNDS *b2)
@@ -261,5 +281,10 @@ void pc_bounds_merge(PCBOUNDS *b1, const PCBOUNDS *b2)
261281
if ( b2->ymin < b1->ymin ) b1->ymin = b2->ymin;
262282
if ( b2->xmax > b1->xmax ) b1->xmax = b2->xmax;
263283
if ( b2->ymax > b1->ymax ) b1->ymax = b2->ymax;
284+
if ( b1->zmin != DBL_MAX && b2->zmin != DBL_MAX )
285+
{
286+
if ( b2->zmin < b1->zmin ) b1->zmin = b2->zmin;
287+
if ( b2->zmax > b1->zmax ) b1->zmax = b2->zmax;
288+
}
264289
}
265290

pgsql/expected/pointcloud-laz.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ SELECT Sum(PC_NumPoints(pa)) FROM pa_test_laz;
9696
SELECT Sum(PC_MemSize(pa)) FROM pa_test_laz;
9797
sum
9898
-----
99-
487
99+
503
100100
(1 row)
101101

102102
SELECT Sum(PC_PatchMax(pa,'x')) FROM pa_test_laz;

pgsql/expected/pointcloud.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ SELECT Sum(PC_NumPoints(pa)) FROM pa_test_dim;
343343
SELECT Sum(PC_MemSize(pa)) FROM pa_test_dim;
344344
sum
345345
-----
346-
684
346+
700
347347
(1 row)
348348

349349
SELECT Sum(PC_PatchMax(pa,'x')) FROM pa_test_dim;

0 commit comments

Comments
 (0)