Skip to content

Commit 224f74c

Browse files
author
Sandro Santilli
committed
Fix stat computed by PC_Filter for scaled/offsetted dimensions.
Closes #78 (for 1.0 branch) Includes testcase.
1 parent 8d61315 commit 224f74c

File tree

6 files changed

+45
-4
lines changed

6 files changed

+45
-4
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
- Bug fixes
55
- #79, Fix PC_Filter stats computation with dimensionally-compressed patches
6+
- #78, Fix PC_Filter stats computation with scaled dimensions
67
- #71, Fix crash in pc_schema_from_xml
78
- #66, Fix crash in pc_schema_clone (unexploitable via SQL)
89
- #37, Fix access to uninitialized variables

lib/pc_api_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ uint32_t pc_bytes_sigbits_count_32(const PCBYTES *pcb, uint32_t *nsigbits);
233233
/** Using an 64-bit word, what is the common word and number of bits in common? */
234234
uint64_t pc_bytes_sigbits_count_64(const PCBYTES *pcb, uint32_t *nsigbits);
235235

236+
/* NOTE: stats are gathered without applying scale and offset */
236237
PCBYTES pc_bytes_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLESTAT *stats);
237238

238239
PCBITMAP* pc_bytes_bitmap(const PCBYTES *pcb, PC_FILTERTYPE filter, double val1, double val2);

lib/pc_bytes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ pc_bytes_minmax(const PCBYTES *pcb, double *min, double *max, double *avg)
13051305
return PC_FAILURE;
13061306
}
13071307

1308+
/* NOTE: stats are gathered without applying scale and offset */
13081309
static PCBYTES
13091310
pc_bytes_uncompressed_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLESTAT *stats)
13101311
{
@@ -1342,6 +1343,7 @@ pc_bytes_uncompressed_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLEST
13421343
return fpcb;
13431344
}
13441345

1346+
/* NOTE: stats are gathered without applying scale and offset */
13451347
static PCBYTES
13461348
pc_bytes_run_length_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLESTAT *stats)
13471349
{
@@ -1405,6 +1407,7 @@ pc_bytes_run_length_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLESTAT
14051407
return fpcb;
14061408
}
14071409

1410+
/* NOTE: stats are gathered without applying scale and offset */
14081411
PCBYTES
14091412
pc_bytes_filter(const PCBYTES *pcb, const PCBITMAP *map, PCDOUBLESTAT *stats)
14101413
{

lib/pc_filter.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,20 @@ pc_patch_dimensional_filter(const PCPATCH_DIMENSIONAL *pdl, const PCBITMAP *map)
151151

152152
for ( i = 0; i < pdl->schema->ndims; i++ )
153153
{
154+
PCDIMENSION *dim;
154155
PCDOUBLESTAT stats;
155156
stats.min = FLT_MAX;
156157
stats.max = -1*FLT_MAX;
157158
stats.sum = 0;
158159
fpdl->bytes[i] = pc_bytes_filter(&(pdl->bytes[i]), map, &stats);
159160

161+
162+
/* Apply scale and offset */
163+
dim = pdl->schema->dims[i];
164+
stats.min = pc_value_scale_offset(stats.min, dim);
165+
stats.max = pc_value_scale_offset(stats.max, dim);
166+
stats.sum = pc_value_scale_offset(stats.sum, dim);
167+
160168
/* Save the X/Y stats for use in bounds later */
161169
if ( i == pdl->schema->x_position )
162170
{

pgsql/expected/pointcloud.out

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ SELECT PC_Version();
66
(1 row)
77

88
INSERT INTO pointcloud_formats (pcid, srid, schema)
9-
VALUES (1, 0,
9+
VALUES (1, 0, -- XYZI, scaled, uncompressed
1010
'<?xml version="1.0" encoding="UTF-8"?>
1111
<pc:PointCloudSchema xmlns:pc="http://pointcloud.org/schemas/PC/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
1212
<pc:dimension>
@@ -53,7 +53,7 @@ VALUES (1, 0,
5353
</pc:metadata>
5454
</pc:PointCloudSchema>'
5555
),
56-
(3, 0,
56+
(3, 0, -- XYZI, scaled, dimensionally compressed
5757
'<?xml version="1.0" encoding="UTF-8"?>
5858
<pc:PointCloudSchema xmlns:pc="http://pointcloud.org/schemas/PC/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5959
<pc:dimension>
@@ -338,4 +338,20 @@ FROM ( SELECT
338338
#79 | -1 | -1 | 0 | 0 | 1 | 1
339339
(1 row)
340340

341+
-- https://github.com/pgpointcloud/pointcloud/issues/78
342+
SELECT '#78' issue,
343+
PC_PatchMin(p,'x') x_min, PC_PatchMax(p,'x') x_max,
344+
PC_PatchMin(p,'y') y_min, PC_PatchMax(p,'y') y_max,
345+
PC_PatchMin(p,'z') z_min, PC_PatchMax(p,'z') z_max,
346+
PC_PatchMin(p,'intensity') i_min, PC_PatchMax(p,'intensity') i_max
347+
FROM ( SELECT
348+
PC_FilterEquals(
349+
PC_Patch( PC_MakePoint(3,ARRAY[-1,0,4862413,1]) ),
350+
'y',0) p
351+
) foo;
352+
issue | x_min | x_max | y_min | y_max | z_min | z_max | i_min | i_max
353+
-------+-------+-------+-------+-------+---------+---------+-------+-------
354+
#78 | -1 | -1 | 0 | 0 | 4862413 | 4862413 | 1 | 1
355+
(1 row)
356+
341357
TRUNCATE pointcloud_formats;

pgsql/sql/pointcloud.sql

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ CREATE EXTENSION pointcloud;
33
SELECT PC_Version();
44

55
INSERT INTO pointcloud_formats (pcid, srid, schema)
6-
VALUES (1, 0,
6+
VALUES (1, 0, -- XYZI, scaled, uncompressed
77
'<?xml version="1.0" encoding="UTF-8"?>
88
<pc:PointCloudSchema xmlns:pc="http://pointcloud.org/schemas/PC/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
99
<pc:dimension>
@@ -50,7 +50,7 @@ VALUES (1, 0,
5050
</pc:metadata>
5151
</pc:PointCloudSchema>'
5252
),
53-
(3, 0,
53+
(3, 0, -- XYZI, scaled, dimensionally compressed
5454
'<?xml version="1.0" encoding="UTF-8"?>
5555
<pc:PointCloudSchema xmlns:pc="http://pointcloud.org/schemas/PC/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5656
<pc:dimension>
@@ -213,4 +213,16 @@ FROM ( SELECT
213213
'y',0) p
214214
) foo;
215215

216+
-- https://github.com/pgpointcloud/pointcloud/issues/78
217+
SELECT '#78' issue,
218+
PC_PatchMin(p,'x') x_min, PC_PatchMax(p,'x') x_max,
219+
PC_PatchMin(p,'y') y_min, PC_PatchMax(p,'y') y_max,
220+
PC_PatchMin(p,'z') z_min, PC_PatchMax(p,'z') z_max,
221+
PC_PatchMin(p,'intensity') i_min, PC_PatchMax(p,'intensity') i_max
222+
FROM ( SELECT
223+
PC_FilterEquals(
224+
PC_Patch( PC_MakePoint(3,ARRAY[-1,0,4862413,1]) ),
225+
'y',0) p
226+
) foo;
227+
216228
TRUNCATE pointcloud_formats;

0 commit comments

Comments
 (0)