static void test_patch_range_compression_none_with_bad_arguments(int first, int count) { int i; int npts = 20; PCPOINTLIST *pl; PCPATCH *pa; PCPATCH *par; pl = pc_pointlist_make(npts); for ( i = 0; i < npts; i++ ) { PCPOINT *pt = pc_point_make(simpleschema); pc_point_set_double_by_name(pt, "X", i); pc_point_set_double_by_name(pt, "Y", i); pc_point_set_double_by_name(pt, "Z", i * 0.1); pc_point_set_double_by_name(pt, "Intensity", 100 - i); pc_pointlist_add_point(pl, pt); } pa = (PCPATCH*)pc_patch_uncompressed_from_pointlist(pl); par = pc_patch_range(pa, first, count); CU_ASSERT(par == NULL); pc_patch_free(pa); pc_pointlist_free(pl); }
static void test_patch_range_compression_none() { int i; int npts = 20; PCPOINTLIST *pl; PCPATCH *pa; PCPATCH *par; char *str; pl = pc_pointlist_make(npts); for ( i = 0; i < npts; i++ ) { PCPOINT *pt = pc_point_make(simpleschema); pc_point_set_double_by_name(pt, "X", i); pc_point_set_double_by_name(pt, "Y", i); pc_point_set_double_by_name(pt, "Z", i * 0.1); pc_point_set_double_by_name(pt, "Intensity", 100 - i); pc_pointlist_add_point(pl, pt); } pa = (PCPATCH*)pc_patch_uncompressed_from_pointlist(pl); par = pc_patch_range(pa, 16, 4); str = pc_patch_to_string(par); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[15,15,1.5,85],[16,16,1.6,84],[17,17,1.7,83],[18,18,1.8,82]]}"); pcfree(str); pc_patch_free(par); pc_patch_free(pa); pc_pointlist_free(pl); }
static void test_patch_range_compression_none_with_full_range() { int i; int npts = 4; PCPOINTLIST *pl; PCPATCH *pa; PCPATCH *par; char *str; pl = pc_pointlist_make(npts); for ( i = 0; i < npts; i++ ) { PCPOINT *pt = pc_point_make(simpleschema); pc_point_set_double_by_name(pt, "X", i); pc_point_set_double_by_name(pt, "Y", i); pc_point_set_double_by_name(pt, "Z", i * 0.1); pc_point_set_double_by_name(pt, "Intensity", 100 - i); pc_pointlist_add_point(pl, pt); } pa = (PCPATCH*)pc_patch_uncompressed_from_pointlist(pl); par = pc_patch_range(pa, 1, npts); CU_ASSERT(pa == par); str = pc_patch_to_string(par); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[0,0,0,100],[1,1,0.1,99],[2,2,0.2,98],[3,3,0.3,97]]}"); pcfree(str); pc_patch_free(pa); pc_pointlist_free(pl); }
static void test_patch_union() { int i; int npts = 20; PCPOINTLIST *pl1; PCPATCH *pu; PCPATCH **palist; pl1 = pc_pointlist_make(npts); for ( i = 0; i < npts; i++ ) { PCPOINT *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); } palist = pcalloc(2*sizeof(PCPATCH*)); palist[0] = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1); palist[1] = (PCPATCH*)pc_patch_uncompressed_from_pointlist(pl1); pu = pc_patch_from_patchlist(palist, 2); CU_ASSERT_EQUAL(pu->npoints, 2*npts); pc_pointlist_free(pl1); pc_patch_free(pu); pc_patch_free(palist[0]); pc_patch_free(palist[1]); pcfree(palist); }
/* * Write an uncompressed patch out to hex */ static void test_patch_hex_out() { // 00 endian // 00000000 pcid // 00000000 compression // 00000002 npoints // 0000000200000003000000050006 pt1 (XYZi) // 0000000200000003000000050008 pt2 (XYZi) static char *wkt_result = "{\"pcid\":0,\"pts\":[[0.02,0.03,0.05,6],[0.02,0.03,0.05,8]]}"; static char *hexresult_xdr = "0000000000000000000000000200000002000000030000000500060000000200000003000000050008"; static char *hexresult_ndr = "0100000000000000000200000002000000030000000500000006000200000003000000050000000800"; double d0[4] = { 0.02, 0.03, 0.05, 6 }; double d1[4] = { 0.02, 0.03, 0.05, 8 }; PCPOINT *pt0 = pc_point_from_double_array(simpleschema, d0, 4); PCPOINT *pt1 = pc_point_from_double_array(simpleschema, d1, 4); PCPATCH_UNCOMPRESSED *pa; uint8_t *wkb; size_t wkbsize; char *hexwkb; char *wkt; PCPOINTLIST *pl = pc_pointlist_make(2); pc_pointlist_add_point(pl, pt0); pc_pointlist_add_point(pl, pt1); pa = pc_patch_uncompressed_from_pointlist(pl); wkb = pc_patch_uncompressed_to_wkb(pa, &wkbsize); // printf("wkbsize %zu\n", wkbsize); hexwkb = hexbytes_from_bytes(wkb, wkbsize); // printf("hexwkb %s\n", hexwkb); // printf("hexresult_ndr %s\n", hexresult_ndr); // printf("machine_endian %d\n", machine_endian()); if ( machine_endian() == PC_NDR ) { CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_ndr); } else { CU_ASSERT_STRING_EQUAL(hexwkb, hexresult_xdr); } wkt = pc_patch_uncompressed_to_string(pa); // printf("wkt %s\n", wkt); CU_ASSERT_STRING_EQUAL(wkt, wkt_result); pc_patch_free((PCPATCH*)pa); pc_pointlist_free(pl); pcfree(hexwkb); pcfree(wkb); pcfree(wkt); }
static void test_patch_filter() { int i; int npts = 20; PCPOINTLIST *pl1, *pl2; PCPATCH *pa1, *pa2, *pa3, *pa4; char *str1, *str2; pl1 = pc_pointlist_make(npts); pl2 = pc_pointlist_make(npts); for ( i = 0; i < npts; i++ ) { PCPOINT *pt1 = pc_point_make(simpleschema); PCPOINT *pt2 = pc_point_make(simpleschema); pc_point_set_double_by_name(pt1, "x", i); pc_point_set_double_by_name(pt1, "y", i); pc_point_set_double_by_name(pt1, "Z", i*0.1); pc_point_set_double_by_name(pt1, "intensity", 100-i); pc_pointlist_add_point(pl1, pt1); pc_point_set_double_by_name(pt2, "x", i); pc_point_set_double_by_name(pt2, "y", i); pc_point_set_double_by_name(pt2, "Z", i*0.1); pc_point_set_double_by_name(pt2, "intensity", 100-i); pc_pointlist_add_point(pl2, pt2); } // PCPATCH* pc_patch_filter(const PCPATCH *pa, uint32_t dimnum, PC_FILTERTYPE filter, double val1, double val2); pa1 = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1); // printf("pa1\n%s\n", pc_patch_to_string(pa1)); pa2 = pc_patch_filter(pa1, 0, PC_GT, 17, 20); str1 = pc_patch_to_string(pa2); // printf("pa2\n%s\n", str1); CU_ASSERT_STRING_EQUAL(str1, "{\"pcid\":0,\"pts\":[[18,18,1.8,82],[19,19,1.9,81]]}"); pa3 = (PCPATCH*)pc_patch_uncompressed_from_pointlist(pl2); // printf("\npa3\n%s\n", pc_patch_to_string(pa3)); pa4 = pc_patch_filter(pa3, 0, PC_GT, 17, 20); str2 = pc_patch_to_string(pa4); // printf("\npa4\n%s\n", str2); CU_ASSERT_STRING_EQUAL(str2, "{\"pcid\":0,\"pts\":[[18,18,1.8,82],[19,19,1.9,81]]}"); pcfree(str1); pcfree(str2); pc_pointlist_free(pl1); pc_pointlist_free(pl2); pc_patch_free(pa1); pc_patch_free(pa3); pc_patch_free(pa4); pc_patch_free(pa2); return; }
PCPATCH_DIMENSIONAL * pc_patch_dimensional_from_pointlist(const PCPOINTLIST *pdl) { PCPATCH_UNCOMPRESSED *patch = pc_patch_uncompressed_from_pointlist(pdl); PCPATCH_DIMENSIONAL *dimpatch = pc_patch_dimensional_from_uncompressed(patch); pc_patch_uncompressed_free(patch); return dimpatch; }
PCPATCH_GHT * pc_patch_ght_from_pointlist(const PCPOINTLIST *pdl) { PCPATCH_UNCOMPRESSED *patch = pc_patch_uncompressed_from_pointlist(pdl); PCPATCH_GHT *ghtpatch = pc_patch_ght_from_uncompressed(patch); pc_patch_uncompressed_free(patch); return ghtpatch; }
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_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_set_schema_compression_none() { // init data PCPATCH_UNCOMPRESSED *pau; PCPATCH *pat0, *pat1; PCPOINTLIST *pl; PCPOINT *pt; char *str; int i; int npts = 4; // build a patch pl = pc_pointlist_make(npts); for ( i = npts; i >= 0; i-- ) { pt = pc_point_make(simpleschema); pc_point_set_double_by_name(pt, "X", i * 0.1); pc_point_set_double_by_name(pt, "Y", i * 0.2); pc_point_set_double_by_name(pt, "Z", i * 0.3); pc_point_set_double_by_name(pt, "Intensity", 10); pc_pointlist_add_point(pl, pt); } pau = pc_patch_uncompressed_from_pointlist(pl); // assign a valid schema to the patch pat0 = pc_patch_set_schema((PCPATCH*) pau, simpleschema_nointensity, 0.0); CU_ASSERT(pat0 != NULL); str = pc_patch_to_string(pat0); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[0.4,0.8,1.2],[0.3,0.6,0.9],[0.2,0.4,0.6],[0.1,0.2,0.3],[0,0,0]]}"); pcfree(str); // assign a schema with unknown dimension to the patch pat1 = pc_patch_set_schema(pat0, simpleschema, 0.0); CU_ASSERT(pat1 != NULL); str = pc_patch_to_string(pat1); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[0.4,0.8,1.2,0],[0.3,0.6,0.9,0],[0.2,0.4,0.6,0],[0.1,0.2,0.3,0],[0,0,0,0]]}"); pcfree(str); pc_patch_free(pat0); pc_patch_free(pat1); pc_patch_free((PCPATCH*) pau); pc_pointlist_free(pl); }
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_patch_set_schema_compression_none_offset() { // init data PCPATCH_UNCOMPRESSED *pau; PCPATCH *pat; PCPOINTLIST *pl; PCPOINT *pt; PCSCHEMA *new_schema; char *str; int i; int npts = 4; // build a patch pl = pc_pointlist_make(npts); for ( i = npts; i >= 0; i-- ) { pt = pc_point_make(simpleschema_nointensity); pc_point_set_double_by_name(pt, "X", i * 0.1); pc_point_set_double_by_name(pt, "Y", i * 0.2); pc_point_set_double_by_name(pt, "Z", i * 0.3); pc_pointlist_add_point(pl, pt); } pau = pc_patch_uncompressed_from_pointlist(pl); new_schema = pc_schema_clone(simpleschema); new_schema->dims[3]->offset = 10; // assign a valid schema to the patch pat = pc_patch_set_schema((PCPATCH *) pau, new_schema, 0.0); CU_ASSERT(pat != NULL); str = pc_patch_to_string(pat); CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[0.4,0.8,1.2,10],[0.3,0.6,0.9,10],[0.2,0.4,0.6,10],[0.1,0.2,0.3,10],[0,0,0,10]]}"); pcfree(str); pc_patch_free(pat); pc_schema_free(new_schema); pc_patch_free((PCPATCH*) pau); pc_pointlist_free(pl); }
static void test_patch_transform_compression_none() { // init data PCPATCH_UNCOMPRESSED *pau; PCSCHEMA *nschema; PCPOINTLIST *pl; PCPATCH *pa; PCPOINT *pt; char *str; int i; int npts = 5; uint8_t *wkb; size_t wkbsize; // build a patch pl = pc_pointlist_make(npts); for ( i = (npts - 1); i >= 0; i-- ) { pt = pc_point_make(simpleschema); pc_point_set_double_by_name(pt, "X", i * 0.1); pc_point_set_double_by_name(pt, "Y", i * 0.2); pc_point_set_double_by_name(pt, "Z", i * 0.3); pc_point_set_double_by_name(pt, "Intensity", 10); pc_pointlist_add_point(pl, pt); } pau = pc_patch_uncompressed_from_pointlist(pl); // create a new schema, and use 0.02 scale values for x, y and z nschema = pc_schema_clone(simpleschema); nschema->xdim->scale = 0.02; nschema->ydim->scale = 0.02; nschema->zdim->scale = 0.02; // transform the patch pa = pc_patch_transform((PCPATCH*) pau, nschema, 0.0); CU_ASSERT(pa != NULL); // check point 1 // expected: x=hex(20)=0x14, y=hex(40)=0x28, z=hex(60)=0x3C, I=hex(10)=0x0A pt = pc_patch_pointn(pa, 1); wkb = pc_point_to_wkb(pt, &wkbsize); str = hexbytes_from_bytes(wkb, wkbsize); CU_ASSERT_STRING_EQUAL(str, "010000000014000000280000003C0000000A00"); pcfree(str); pcfree(wkb); pc_point_free(pt); // check point 2 // expected: x=hex(15)=0x0F, y=hex(30)=0x1E, z=hex(45)=0x2D, I=hex(10)=0x0A pt = pc_patch_pointn(pa, 2); wkb = pc_point_to_wkb(pt, &wkbsize); str = hexbytes_from_bytes(wkb, wkbsize); CU_ASSERT_STRING_EQUAL(str, "01000000000F0000001E0000002D0000000A00"); pcfree(str); pcfree(wkb); pc_point_free(pt); // check point 3 // expected: x=hex(10)=0x0A, y=hex(20)=0x14, z=hex(30)=0x1E, I=hex(10)=0x0A pt = pc_patch_pointn(pa, 3); wkb = pc_point_to_wkb(pt, &wkbsize); str = hexbytes_from_bytes(wkb, wkbsize); CU_ASSERT_STRING_EQUAL(str, "01000000000A000000140000001E0000000A00"); pcfree(str); pcfree(wkb); pc_point_free(pt); // check point 4 // expected: x=hex(5)=0x05, y=hex(10)=0x0A, z=hex(15)=0x0F, I=hex(10)=0x0A pt = pc_patch_pointn(pa, 4); wkb = pc_point_to_wkb(pt, &wkbsize); str = hexbytes_from_bytes(wkb, wkbsize); CU_ASSERT_STRING_EQUAL(str, "0100000000050000000A0000000F0000000A00"); pcfree(str); pcfree(wkb); pc_point_free(pt); // check point 5 // expected: x=hex(0)=0x00, y=hex(0)=0x00, z=hex(0)=0x00, I=hex(10)=0x0A pt = pc_patch_pointn(pa, 5); wkb = pc_point_to_wkb(pt, &wkbsize); str = hexbytes_from_bytes(wkb, wkbsize); CU_ASSERT_STRING_EQUAL(str, "01000000000000000000000000000000000A00"); pcfree(str); pcfree(wkb); pc_point_free(pt); pc_patch_free(pa); pc_schema_free(nschema); pc_patch_free((PCPATCH*) pau); pc_pointlist_free(pl); }