1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
|
/***********************************************************************
* cu_pc_patch_lazperf.c
*
* Testing for the LazPerf API functions
*
* Copyright (c) 2016 Paul Blottiere, Oslandia
*
***********************************************************************/
#include "CUnit/Basic.h"
#include "cu_tester.h"
/* GLOBALS ************************************************************/
static PCSCHEMA *simpleschema = NULL;
static PCSCHEMA *multipledimschema = NULL;
static const char *simplexmlfile = "data/simple-schema.xml";
static const char *multipledimxmlfile =
"data/simple-schema-laz-multiple-dim.xml";
/* Setup/teardown for this suite */
static int init_suite(void)
{
char *xmlstr = file_to_str(simplexmlfile);
simpleschema = pc_schema_from_xml(xmlstr);
pcfree(xmlstr);
if (!simpleschema)
return 1;
xmlstr = file_to_str(multipledimxmlfile);
multipledimschema = pc_schema_from_xml(xmlstr);
pcfree(xmlstr);
if (!multipledimschema)
return 1;
return 0;
}
static int clean_suite(void)
{
pc_schema_free(simpleschema);
pc_schema_free(multipledimschema);
return 0;
}
#ifdef HAVE_LAZPERF
static void test_schema_compression_lazperf(void)
{
PCSCHEMA *myschema = NULL;
char *myxmlfile = "data/simple-schema-laz.xml";
char *xmlstr = file_to_str(myxmlfile);
myschema = pc_schema_from_xml(xmlstr);
CU_ASSERT_PTR_NOT_NULL(myschema);
int compression = myschema->compression;
CU_ASSERT_EQUAL(compression, PC_LAZPERF);
pc_schema_free(myschema);
pcfree(xmlstr);
}
static void test_patch_lazperf()
{
PCPOINT *pt;
int i;
int npts = 400;
PCPOINTLIST *pl;
PCPATCH_LAZPERF *pal;
PCPATCH_UNCOMPRESSED *paul, *pauref;
// build a list of points
pl = pc_pointlist_make(npts);
for (i = 0; i < npts; i++)
{
pt = pc_point_make(simpleschema);
pc_point_set_double_by_name(pt, "x", i * 2.0);
pc_point_set_double_by_name(pt, "y", i * 1.9);
pc_point_set_double_by_name(pt, "Z", i * 0.34);
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl, pt);
}
// compress the list in a lazperf patch
pal = pc_patch_lazperf_from_pointlist(pl);
// get an uncompressed patch from the lazperf patch
paul = pc_patch_uncompressed_from_lazperf(pal);
// get an uncompressed patch directly from the pointlist
pauref = pc_patch_uncompressed_from_pointlist(pl);
// test the number of points
CU_ASSERT_EQUAL(pal->npoints, pauref->npoints);
CU_ASSERT_EQUAL(paul->npoints, pauref->npoints);
// test bounds
CU_ASSERT_DOUBLE_EQUAL(pal->bounds.xmax, pauref->bounds.xmax, 0.0001);
CU_ASSERT_DOUBLE_EQUAL(paul->bounds.ymax, pauref->bounds.ymax, 0.000001);
// test type
CU_ASSERT_EQUAL(pal->type, PC_LAZPERF);
CU_ASSERT_EQUAL(paul->type, pauref->type);
// test readonly
CU_ASSERT_EQUAL(pauref->readonly, paul->readonly);
CU_ASSERT_EQUAL(pauref->readonly, pal->readonly);
// test datasize
CU_ASSERT_EQUAL(paul->datasize, pauref->datasize);
// free
pc_pointlist_free(pl);
pc_patch_free((PCPATCH *)pal);
pc_patch_free((PCPATCH *)paul);
pc_patch_free((PCPATCH *)pauref);
}
static void test_pointlist_lazperf()
{
PCPOINT *pt;
int i;
int npts = 400;
PCPOINTLIST *pl1, *pl2;
PCPATCH_LAZPERF *pch1;
PCPATCH_UNCOMPRESSED *pa1, *pa2;
char *wkt1, *wkt2;
// build a list of points
pl1 = pc_pointlist_make(npts);
for (i = 0; i < npts; i++)
{
pt = pc_point_make(simpleschema);
pc_point_set_double_by_name(pt, "x", i * 2.0);
pc_point_set_double_by_name(pt, "y", i * 1.9);
pc_point_set_double_by_name(pt, "Z", i * 0.34);
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl1, pt);
}
// compress the list in a lazperf patch
pch1 = pc_patch_lazperf_from_pointlist(pl1);
// decompress the lazperf patch in a pointlist
pl2 = pc_pointlist_from_lazperf(pch1);
// test that the string representation of pointlist is equal
pa1 = pc_patch_uncompressed_from_pointlist(pl1);
pa2 = pc_patch_uncompressed_from_lazperf(pch1);
wkt1 = pc_patch_uncompressed_to_string(pa1);
wkt2 = pc_patch_uncompressed_to_string(pa2);
CU_ASSERT_STRING_EQUAL(wkt1, wkt2);
pc_patch_free((PCPATCH *)pch1);
pc_patch_free((PCPATCH *)pa1);
pc_patch_free((PCPATCH *)pa2);
pc_pointlist_free(pl1);
pc_pointlist_free(pl2);
pcfree(wkt1);
pcfree(wkt2);
}
static void test_to_string_lazperf()
{
PCPOINT *pt;
int i;
int npts = 400;
PCPOINTLIST *pl;
PCPATCH_LAZPERF *pal;
PCPATCH_UNCOMPRESSED *pau;
char *str1, *str2;
// build a list of points
pl = pc_pointlist_make(npts);
for (i = 0; i < npts; i++)
{
pt = pc_point_make(simpleschema);
pc_point_set_double_by_name(pt, "x", i * 2.0);
pc_point_set_double_by_name(pt, "y", i * 1.9);
pc_point_set_double_by_name(pt, "Z", i * 0.34);
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl, pt);
}
// build patch
pau = pc_patch_uncompressed_from_pointlist(pl);
pal = pc_patch_lazperf_from_pointlist(pl);
// get string
str1 = pc_patch_uncompressed_to_string(pau);
str2 = pc_patch_lazperf_to_string(pal);
// compare
CU_ASSERT_STRING_EQUAL(str1, str2);
// free
pc_patch_free((PCPATCH *)pal);
pc_patch_free((PCPATCH *)pau);
pc_pointlist_free(pl);
pcfree(str1);
pcfree(str2);
}
static void test_wkb_lazperf()
{
PCPOINT *pt;
int i;
int npts = 400;
PCPOINTLIST *pl;
PCPATCH_LAZPERF *pal1, *pal2;
PCPATCH_UNCOMPRESSED *pau;
uint8_t *wkb1, *wkb2;
size_t wkbsize;
// build a list of points
pl = pc_pointlist_make(npts);
for (i = 0; i < npts; i++)
{
pt = pc_point_make(simpleschema);
pc_point_set_double_by_name(pt, "x", i * 2.0);
pc_point_set_double_by_name(pt, "y", i * 1.9);
pc_point_set_double_by_name(pt, "Z", i * 0.34);
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl, pt);
}
// build patch lazperf
pal1 = pc_patch_lazperf_from_pointlist(pl);
// get the corresponding wkb
wkb1 = pc_patch_lazperf_to_wkb(pal1, &wkbsize);
// rebuild a lazperf patch thanks to the wkb
pal2 =
(PCPATCH_LAZPERF *)pc_patch_lazperf_from_wkb(pal1->schema, wkb1, wkbsize);
// get the wkb reference
pau = pc_patch_uncompressed_from_pointlist(pl);
wkb2 = pc_patch_uncompressed_to_wkb(pau, &wkbsize);
// compare wkb
CU_ASSERT_STRING_EQUAL(wkb1, wkb2);
// free
pc_patch_free((PCPATCH *)pal1);
pc_patch_free((PCPATCH *)pal2);
pc_patch_free((PCPATCH *)pau);
pc_pointlist_free(pl);
pcfree(wkb1);
pcfree(wkb2);
}
static void test_patch_filter_lazperf_zero_point()
{
PCPOINT *pt;
int i;
int npts = 5;
PCPOINTLIST *pl;
PCPATCH_LAZPERF *pal;
PCPATCH *pa;
// build a list of points
pl = pc_pointlist_make(npts);
for (i = 0; i < npts; i++)
{
pt = pc_point_make(simpleschema);
pc_point_set_double_by_name(pt, "x", i * 2.0);
pc_point_set_double_by_name(pt, "y", i * 1.9);
pc_point_set_double_by_name(pt, "Z", i * 0.34);
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl, pt);
}
// build patch lazperf
pal = pc_patch_lazperf_from_pointlist(pl);
// filter with a resulting patch of 0 point(s)
pa = pc_patch_filter((PCPATCH *)pal, 0, PC_BETWEEN, 0.0, 0.0);
CU_ASSERT_EQUAL(pa->npoints, 0);
pc_patch_free((PCPATCH *)pal);
pc_patch_free((PCPATCH *)pa);
pc_pointlist_free(pl);
}
static void test_patch_compression_with_multiple_dimension()
{
PCPOINT *pt;
int i;
int npts = 5;
PCPOINTLIST *pl;
PCPATCH_LAZPERF *pal;
PCPATCH_UNCOMPRESSED *pau;
char *str1, *str2;
// build a list of points
pl = pc_pointlist_make(npts);
for (i = 0; i < npts; i++)
{
pt = pc_point_make(multipledimschema);
pc_point_set_double_by_name(pt, "x", i * 2);
pc_point_set_double_by_name(pt, "y", i * 1.9);
pc_point_set_double_by_name(pt, "z", i * 0.34);
pc_point_set_double_by_name(pt, "intensity", 10);
pc_pointlist_add_point(pl, pt);
}
// build patchs
pal = pc_patch_lazperf_from_pointlist(pl);
pau = pc_patch_uncompressed_from_pointlist(pl);
// compare str result
str1 = pc_patch_lazperf_to_string(pal);
str2 = pc_patch_uncompressed_to_string(pau);
CU_ASSERT_STRING_EQUAL(str1, str2);
pc_patch_free((PCPATCH *)pal);
pc_patch_free((PCPATCH *)pau);
pc_pointlist_free(pl);
pcfree(str1);
pcfree(str2);
}
#endif
/* REGISTER ***********************************************************/
CU_TestInfo lazperf_tests[] = {
#ifdef HAVE_LAZPERF
PC_TEST(test_schema_compression_lazperf),
PC_TEST(test_patch_lazperf),
PC_TEST(test_pointlist_lazperf),
PC_TEST(test_to_string_lazperf),
PC_TEST(test_wkb_lazperf),
PC_TEST(test_patch_filter_lazperf_zero_point),
PC_TEST(test_patch_compression_with_multiple_dimension),
#endif
CU_TEST_INFO_NULL};
CU_SuiteInfo lazperf_suite = {.pName = "lazperf",
.pInitFunc = init_suite,
.pCleanupFunc = clean_suite,
.pTests = lazperf_tests};
|