Ejemplo n.º 1
0
static void
test_patch_compress_from_ght_to_lazperf()
{
	PCPOINT *point;
	PCPOINTLIST *pointlist;
	PCPATCH_GHT *patch_ght;
	PCPATCH_LAZPERF *patch_lazperf;

	pointlist = pc_pointlist_make(1);
	point = pc_point_make(simplelazschema);
	pc_point_set_double_by_name(point, "x", 2.0);
	pc_point_set_double_by_name(point, "y", 1.9);
	pc_point_set_double_by_name(point, "Z", 0.34);
	pc_point_set_double_by_name(point, "intensity", 10);
	pc_pointlist_add_point(pointlist, point);

	patch_ght = pc_patch_ght_from_pointlist(pointlist);
	CU_ASSERT(patch_ght->type == PC_GHT);

	patch_lazperf = (PCPATCH_LAZPERF *)pc_patch_compress((PCPATCH *)patch_ght, NULL);
	CU_ASSERT(patch_lazperf != NULL);
	CU_ASSERT(patch_lazperf->type == PC_LAZPERF);

	pc_pointlist_free(pointlist);
	pc_patch_free((PCPATCH *)patch_ght);
	pc_patch_free((PCPATCH *)patch_lazperf);
}
Ejemplo n.º 2
0
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);
}
Ejemplo n.º 3
0
static void
test_patch_pointn_ght_compression()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000003 npoints
	// 0000000800000003000000050006 pt1 (XYZi)
	// 0000000200000003000000040008 pt2 (XYZi)
	// 0000000200000003000000040009 pt3 (XYZi)

	char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009";
	size_t hexsize = strlen(hexbuf);
	uint8_t *wkb = pc_bytes_from_hexbytes(hexbuf, hexsize);

	PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2);
	PCPOINTLIST *li = pc_pointlist_from_patch(pa);

#ifdef HAVE_LIBGHT
	PCPATCH_GHT* pag = pc_patch_ght_from_pointlist(li);
	PCPOINT *pt = pc_patch_pointn((PCPATCH*) pag, 2);
	CU_ASSERT(pt != NULL);
	CU_ASSERT_STRING_EQUAL(pc_point_to_string(pt), "{\"pcid\":0,\"pt\":[0.02,0.03,0.04,8]}");
	pc_patch_free( (PCPATCH*) pag );
	pc_point_free(pt);
#endif

	// free
	pcfree(wkb);
	pc_patch_free(pa);
	pc_pointlist_free(li);
}
Ejemplo n.º 4
0
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;



}
Ejemplo n.º 5
0
static void
test_patch_wkb()
{
    int i;
    int npts = 20;
    PCPOINTLIST *pl1;
    PCPATCH_UNCOMPRESSED *pu1, *pu2;
    PCPATCH *pa1, *pa2, *pa3, *pa4;
    PCDIMSTATS *pds = NULL;
    size_t z1, z2;
    uint8_t *wkb1, *wkb2;
    char *str;

    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.123);
        pc_point_set_double_by_name(pt, "y", i*2.9);
        pc_point_set_double_by_name(pt, "Z", i*0.3099);
        pc_point_set_double_by_name(pt, "intensity", 13);
        pc_pointlist_add_point(pl1, pt);
    }

    pa1 = (PCPATCH*)pc_patch_dimensional_from_pointlist(pl1);
    wkb1 = pc_patch_to_wkb(pa1, &z1);
    str = hexbytes_from_bytes(wkb1, z1);
    // printf("str\n%s\n",str);
    pa2 = pc_patch_from_wkb(simpleschema, wkb1, z1);

    // printf("pa2\n%s\n",pc_patch_to_string(pa2));

    pa3 = pc_patch_compress(pa2, NULL);

    // printf("pa3\n%s\n",pc_patch_to_string(pa3));

    wkb2 = pc_patch_to_wkb(pa3, &z2);
    pa4 = pc_patch_from_wkb(simpleschema, wkb2, z2);

    // printf("pa4\n%s\n",pc_patch_to_string(pa4));

    pu1 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa1);
    pu2 = (PCPATCH_UNCOMPRESSED*)pc_patch_uncompressed_from_dimensional((PCPATCH_DIMENSIONAL*)pa4);

    // printf("pu1\n%s\n", pc_patch_to_string((PCPATCH*)pu1));
    // printf("pu2\n%s\n", pc_patch_to_string((PCPATCH*)pu2));

    CU_ASSERT_EQUAL(pu1->datasize, pu2->datasize);
    CU_ASSERT_EQUAL(pu1->npoints, pu2->npoints);
    CU_ASSERT(memcmp(pu1->data, pu2->data, pu1->datasize) == 0);


    pc_pointlist_free(pl1);
    pc_patch_free(pa1);
    pc_patch_free(pa2);
    pcfree(wkb1);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
static void
test_sort_patch_is_sorted_compression_dimensional(enum DIMCOMPRESSIONS dimcomp)
{
	// init data
	PCPATCH_DIMENSIONAL *padim1, *padim2, *padimsort;
	PCPOINT *pt;
	PCPOINTLIST *pl;
	int i;
	int ndims = 1;
	int npts = PCDIMSTATS_MIN_SAMPLE+1; // force to keep custom compression
	const char *X[] = {"X"};

	// build a dimensional patch
	pl = pc_pointlist_make(npts);

	for ( i = npts; i >= 0; i-- )
	{
		pt = pc_point_make(schema);
		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);
		pc_point_set_double_by_name(pt, "intensity", 10);
		pc_pointlist_add_point(pl, pt);
	}

	padim1 = pc_patch_dimensional_from_pointlist(pl);

	// set dimensional compression for each dimension
	PCDIMSTATS *stats = pc_dimstats_make(schema);
	pc_dimstats_update(stats, padim1);
	for ( i = 0; i<padim1->schema->ndims; i++ )
		stats->stats[i].recommended_compression = dimcomp;

	// compress patch
	padim2 = pc_patch_dimensional_compress(padim1, stats);

	// test that patch is not sorted
	CU_ASSERT_EQUAL(pc_patch_is_sorted((PCPATCH*) padim2, X, ndims, PC_FALSE), PC_FALSE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted((PCPATCH*) padim2, X, ndims, PC_TRUE), PC_FALSE);

	// sort
	padimsort = (PCPATCH_DIMENSIONAL*) pc_patch_sort((PCPATCH*) padim2, X, 1);

	// test that resulting data is sorted
	CU_ASSERT_EQUAL(pc_patch_is_sorted((PCPATCH*) padimsort, X, ndims, PC_TRUE), PC_TRUE);

	// free
	pc_dimstats_free(stats);
	pc_patch_free((PCPATCH *)padim1);
	pc_patch_free((PCPATCH *)padim2);
	pc_patch_free((PCPATCH *)padimsort);
	pc_pointlist_free(pl);
}
Ejemplo n.º 8
0
static void
test_patch_set_schema_dimensional_compression(enum DIMCOMPRESSIONS dimcomp)
{
	// init data
	PCPATCH_DIMENSIONAL *padim1, *padim2;
	PCPATCH *pat;
	PCPOINT *pt;
	PCPOINTLIST *pl;
	char *str;
	int i;
	int npts = PCDIMSTATS_MIN_SAMPLE+1; // force to keep custom compression

	// 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);
	}

	padim1 = pc_patch_dimensional_from_pointlist(pl);

	// set dimensional compression for each dimension
	PCDIMSTATS *stats = pc_dimstats_make(simpleschema);
	pc_dimstats_update(stats, padim1);
	for ( i = 0; i<padim1->schema->ndims; i++ )
		stats->stats[i].recommended_compression = dimcomp;

	// compress patch
	padim2 = pc_patch_dimensional_compress(padim1, stats);

	// assign a valid schema to the patch
	pat = pc_patch_set_schema((PCPATCH*) padim2, simpleschema_nointensity, 0.0);
	CU_ASSERT(pat != NULL);
	pt = pc_patch_pointn(pat, 1);
	str = pc_point_to_string(pt);
	CU_ASSERT_STRING_EQUAL(str,"{\"pcid\":0,\"pt\":[1000.1,2000.2,3000.3]}");
	pcfree(str);
	pc_point_free(pt);
	pc_patch_free(pat);

	pc_pointlist_free(pl);
	pc_dimstats_free(stats);
	pc_patch_free((PCPATCH *)padim1);
	pc_patch_free((PCPATCH *)padim2);
}
Ejemplo n.º 9
0
static void
test_patch_range_compression_dimensional(enum DIMCOMPRESSIONS dimcomp)
{
	int i;
	PCPOINTLIST *pl;
	PCPATCH *pa;
	PCPATCH *par;
	PCPATCH_DIMENSIONAL *pad;
	PCPOINT *pt;
	char *str;
	int npts = PCDIMSTATS_MIN_SAMPLE+1; // force to keep custom compression

	// build a dimensional 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);
		pc_point_set_double_by_name(pt, "Y", i);
		pc_point_set_double_by_name(pt, "Z", i);
		pc_point_set_double_by_name(pt, "Intensity", 10);
		pc_pointlist_add_point(pl, pt);
	}

	pad = pc_patch_dimensional_from_pointlist(pl);

	// set dimensional compression for each dimension
	PCDIMSTATS *stats = pc_dimstats_make(simpleschema);
	pc_dimstats_update(stats, pad);
	for ( i = 0; i<pad->schema->ndims; i++ )
		stats->stats[i].recommended_compression = dimcomp;

	// compress patch
	pa = (PCPATCH*) pc_patch_dimensional_compress(pad, stats);

	par = pc_patch_range(pa, 16, 4);
	str = pc_patch_to_string(par);

	CU_ASSERT_STRING_EQUAL(str,
		"{\"pcid\":0,\"pts\":[[9986,9986,9986,10],[9985,9985,9985,10],[9984,9984,9984,10],[9983,9983,9983,10]]}");

	pcfree(str);
	pc_patch_free(par);
	pc_patch_free((PCPATCH *)pad);
	pc_dimstats_free(stats);
	pc_patch_free(pa);
	pc_pointlist_free(pl);
}
Ejemplo n.º 10
0
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);
}
Ejemplo n.º 11
0
static void
test_patch_pointn_last_first()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000003 npoints
	// 0000000800000003000000050006 pt1 (XYZi)
	// 0000000200000003000000040008 pt2 (XYZi)
	// 0000000200000003000000040009 pt3 (XYZi)

	char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009";
	size_t hexsize = strlen(hexbuf);
	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	char *str;

	PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2);

	PCPOINT *pt = pc_patch_pointn(pa, -1);
	str = pc_point_to_string(pt);
	CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pt\":[0.02,0.03,0.04,9]}");
	pc_point_free(pt);
	free(str);

	pt = pc_patch_pointn(pa, -3);
	str = pc_point_to_string(pt);
	CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pt\":[0.08,0.03,0.05,6]}");
	pc_point_free(pt);
	free(str);

	pc_patch_free(pa);
	pcfree(wkb);
}
Ejemplo n.º 12
0
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);
}
Ejemplo n.º 13
0
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);
}
Ejemplo n.º 14
0
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);
}
Ejemplo n.º 15
0
static void
test_sort_simple()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000002 npoints
	// 0000000800000003000000050006 pt1 (XYZi)
	// 0000000200000001000000040008 pt2 (XYZi)

	// init data
	PCPOINTLIST *lisort;
	PCPATCH *pasort;
	double d1;
	double d2;
	char *hexbuf = "0000000000000000000000000200000008000000030000000500060000000200000001000000040008";
	size_t hexsize = strlen(hexbuf);

	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2);
	PCPOINTLIST *li = pc_pointlist_from_patch(pa);
	const char *X[] = {"X"};

	// check that initial data are not sorted
	pc_point_get_double_by_name(pc_pointlist_get_point(li, 0), "X", &d1);
	pc_point_get_double_by_name(pc_pointlist_get_point(li, 1), "X", &d2);

	CU_ASSERT_DOUBLE_EQUAL(d1, 0.08, precision);
	CU_ASSERT_DOUBLE_EQUAL(d2, 0.02, precision);

	// sort on X attribute and check if data are well sorted
	pasort = pc_patch_sort(pa, X, 1);
	lisort = pc_pointlist_from_patch(pasort);

	pc_point_get_double_by_name(pc_pointlist_get_point(lisort, 0), "X", &d1);
	pc_point_get_double_by_name(pc_pointlist_get_point(lisort, 1), "X", &d2);

	CU_ASSERT_DOUBLE_EQUAL(d1, 0.02, precision);
	CU_ASSERT_DOUBLE_EQUAL(d2, 0.08, precision);

	// free
	pc_pointlist_free(li);
	pc_pointlist_free(lisort);
	pc_patch_free(pa);
	pc_patch_free(pasort);
	pcfree(wkb);
}
Ejemplo n.º 16
0
static void
test_patch_set_schema_compression_ght()
{
	// init data
	PCPATCH_GHT *pag;
	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);
	}

	pag = pc_patch_ght_from_pointlist(pl);

	// assign a valid schema to the patch
	pat0 = pc_patch_set_schema((PCPATCH*) pag, 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*) pag);
	pc_pointlist_free(pl);
}
Ejemplo n.º 17
0
/*
* 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);
}
Ejemplo n.º 18
0
char *
pc_patch_dimensional_to_string(const PCPATCH_DIMENSIONAL *pa)
{
	PCPATCH_UNCOMPRESSED *patch = pc_patch_uncompressed_from_dimensional(pa);
	char *str = pc_patch_uncompressed_to_string(patch);
	pc_patch_free((PCPATCH*)patch);
	return str;
}
Ejemplo n.º 19
0
static void
test_sort_consistency()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000002 npoints
	// 0000000800000003000000050006 pt1 (XYZi)
	// 0000000200000001000000040008 pt2 (XYZi)

	// init data
	PCPATCH *pasort;
	char *pastr, *pasortstr;
	uint8_t *wkbsort;
	char *hexbuf = "0000000000000000000000000200000008000000030000000500060000000200000001000000040008";
	size_t hexsize = strlen(hexbuf);
	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2);
	PCPOINTLIST *li = pc_pointlist_from_patch(pa);
	const char *X[] = {"X"};

	// sort on X attribute
	pasort = pc_patch_sort(pa, X, 1);

	//chek consistency
	wkbsort = pc_patch_to_wkb(pasort, &hexsize);
	CU_ASSERT_EQUAL(wkb_get_pcid(wkb), wkb_get_pcid(wkbsort));
	CU_ASSERT_EQUAL(wkb_get_npoints(wkb), wkb_get_npoints(wkbsort));
	CU_ASSERT_EQUAL(wkb_get_compression(wkb), wkb_get_compression(wkbsort));

	pastr = pc_patch_to_string(pa);
	CU_ASSERT_STRING_EQUAL(pastr, "{\"pcid\":0,\"pts\":[[0.08,0.03,0.05,6],[0.02,0.01,0.04,8]]}");

	pasortstr = pc_patch_to_string(pasort);
	CU_ASSERT_STRING_EQUAL(pasortstr, "{\"pcid\":0,\"pts\":[[0.02,0.01,0.04,8],[0.08,0.03,0.05,6]]}");

	// free
	pcfree(wkb);
	pcfree(wkbsort);
	pcfree(pastr);
	pcfree(pasortstr);
	pc_patch_free(pasort);
	pc_patch_free(pa);
	pc_pointlist_free(li);
}
Ejemplo n.º 20
0
Datum pcpatch_uncompress(PG_FUNCTION_ARGS)
{
	SERIALIZED_PATCH *serpa = PG_GETARG_SERPATCH_P(0);
    PCSCHEMA *schema = pc_schema_from_pcid(serpa->pcid, fcinfo);
    PCPATCH *patch = pc_patch_deserialize(serpa, schema);
    SERIALIZED_PATCH *serpa_out = pc_patch_serialize_uncompressed(patch);
    pc_patch_free(patch);
    PG_RETURN_POINTER(serpa_out);
}
Ejemplo n.º 21
0
PCPOINT *
pc_patch_ght_pointn(const PCPATCH_GHT *patch, int n)
{
	PCPATCH_UNCOMPRESSED *pu;
	pu = pc_patch_uncompressed_from_ght(patch);
	PCPOINT *pt = pc_patch_uncompressed_pointn(pu,n);
	pc_patch_free((PCPATCH *)pu);
	return pt;
}
Ejemplo n.º 22
0
PCPATCH_DIMENSIONAL *
pc_patch_dimensional_from_pointlist(const PCPOINTLIST *pdl)
{
	PCPATCH_UNCOMPRESSED *patch = pc_patch_uncompressed_from_pointlist(pdl);
	if ( ! patch ) return NULL;
	PCPATCH_DIMENSIONAL *dimpatch = pc_patch_dimensional_from_uncompressed(patch);
	pc_patch_free((PCPATCH*)patch);
	return dimpatch;
}
Ejemplo n.º 23
0
static void
test_sort_patch_ndims()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000002 npoints
	// 0000000800000001000000050006 pt1 (XYZi)
	// 0000000200000003000000040008 pt2 (XYZi)
	// 0000000200000002000000040008 pt2 (XYZi)

	// init data
	PCPATCH *pasort1, *pasort2;
	char *hexbuf = "00000000000000000000000003000000080000000400000005000600000002000000030000000400080000000200000002000000040009";
	size_t hexsize = strlen(hexbuf);
	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2);
	const char *X[] = {"X"};
	const char *Y[] = {"Y"};
	const char *X_Y[] = {"X", "Y"};

	// test that initial data is not sorted
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, X, 1, PC_FALSE), PC_FALSE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, Y, 1, PC_FALSE), PC_FALSE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pa, X_Y, 2, PC_FALSE), PC_FALSE);

	// sort on X attribute and test
	pasort1 = pc_patch_sort(pa, X, 1);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort1, X, 1, PC_TRUE), PC_TRUE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort1, Y, 1, PC_TRUE), PC_FALSE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort1, X_Y, 2, PC_TRUE), PC_FALSE);

	// sort on X and Y and tst
	pasort2 = pc_patch_sort(pa, X_Y, 2);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort2, X, 1, PC_TRUE), PC_TRUE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort2, Y, 1, PC_TRUE), PC_TRUE);
	CU_ASSERT_EQUAL(pc_patch_is_sorted(pasort2, X_Y, 2, PC_TRUE), PC_TRUE);

	// free
	pcfree(wkb);
	pc_patch_free(pasort1);
	pc_patch_free(pasort2);
	pc_patch_free(pa);
}
Ejemplo n.º 24
0
PCPOINTLIST *
pc_pointlist_from_ght(const PCPATCH_GHT *pag)
{
	PCPATCH_UNCOMPRESSED *pu;
	pu = pc_patch_uncompressed_from_ght(pag);
	PCPOINTLIST *pl = pc_pointlist_from_uncompressed(pu);
	pl->mem = pc_patch_uncompressed_readonly(pu);
	pc_patch_free((PCPATCH *)pu);
	return pl;
}
Ejemplo n.º 25
0
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);
}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 27
0
/**
* Pivot a pointlist into a dimlist and back.
* Test for data loss or alteration.
*/
static void
test_patch_dimensional()
{
	PCPOINT *pt;
	int i;
	int npts = 10;
	PCPOINTLIST *pl1, *pl2;
	PCPATCH_DIMENSIONAL *pdl;
	PCDIMSTATS *pds;

	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);
	}

	pdl = pc_patch_dimensional_from_pointlist(pl1);
	pl2 = pc_pointlist_from_dimensional(pdl);

	for ( i = 0; i < npts; i++ )
	{
		pt = pc_pointlist_get_point(pl2, i);
		double v1, v2, v3, v4;
		pc_point_get_double_by_name(pt, "x", &v1);
		pc_point_get_double_by_name(pt, "y", &v2);
		pc_point_get_double_by_name(pt, "Z", &v3);
		pc_point_get_double_by_name(pt, "intensity", &v4);
		// printf("%g\n", v4);
		CU_ASSERT_DOUBLE_EQUAL(v1, i*2.0, 0.001);
		CU_ASSERT_DOUBLE_EQUAL(v2, i*1.9, 0.001);
		CU_ASSERT_DOUBLE_EQUAL(v3, i*0.34, 0.001);
		CU_ASSERT_DOUBLE_EQUAL(v4, 10, 0.001);
	}

	pds = pc_dimstats_make(simpleschema);
	pc_dimstats_update(pds, pdl);
	pc_dimstats_update(pds, pdl);


	pc_patch_free((PCPATCH*)pdl);
	pc_pointlist_free(pl1);
	pc_pointlist_free(pl2);
	pc_dimstats_free(pds);
}
Ejemplo n.º 28
0
Datum pcpatch_out(PG_FUNCTION_ARGS)
{
	PCPATCH *patch = NULL;
	SERIALIZED_PATCH *serpatch = NULL;
	char *hexwkb = NULL;
	PCSCHEMA *schema = NULL;

	serpatch = PG_GETARG_SERPATCH_P(0);
	schema = pc_schema_from_pcid(serpatch->pcid, fcinfo);
	patch = pc_patch_deserialize(serpatch, schema);
	hexwkb = pc_patch_to_hexwkb(patch);
	pc_patch_free(patch);
	PG_RETURN_CSTRING(hexwkb);
}
Ejemplo n.º 29
0
/**
* Convert struct to byte array.
* Userdata is currently only PCDIMSTATS, hopefully updated across
* a number of iterations and saved.
*/
SERIALIZED_PATCH *
pc_patch_serialize(const PCPATCH *patch_in, void *userdata)
{
	PCPATCH *patch = (PCPATCH*)patch_in;
	SERIALIZED_PATCH *serpatch = NULL;
	/*
	* Ensure the patch has stats calculated before going on
	*/
	if ( ! patch->stats )
	{
		pcerror("%s: patch is missing stats", __func__);
		return NULL;
	}
	/*
	* Convert the patch to the final target compression,
	* which is the one in the schema.
	*/
	if ( patch->type != patch->schema->compression )
	{
		patch = pc_patch_compress(patch_in, userdata);
	}

	switch( patch->type )
	{
	case PC_NONE:
	{
		serpatch = pc_patch_uncompressed_serialize(patch);
		break;
	}
	case PC_DIMENSIONAL:
	{
		serpatch = pc_patch_dimensional_serialize(patch);
		break;
	}
	case PC_GHT:
	{
		serpatch = pc_patch_ght_serialize(patch);
		break;
	}
	default:
	{
		pcerror("%s: unsupported compression type %d", __func__, patch->type);
	}
	}

	if ( patch != patch_in )
		pc_patch_free(patch);

	return serpatch;
}
Ejemplo n.º 30
0
static void
test_sort_stable()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000002 npoints
	// 0000000800000003000000050006 pt1 (XYZi)
	// 0000000200000003000000040008 pt2 (XYZi)
	// 0000000200000003000000040009 pt3 (XYZi)

	// init data
	PCPATCH *pasort;
	char *hexbuf = "00000000000000000000000003000000080000000300000005000600000002000000030000000400080000000200000003000000040009";
	size_t hexsize = strlen(hexbuf);
	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	PCPATCH *pa = pc_patch_from_wkb(schema, wkb, hexsize/2);
	PCPOINTLIST *li = pc_pointlist_from_patch(pa);
	const char *dims[] = {"Y"};

	// sort on Y attribute
	pasort = pc_patch_sort(pa, dims, 1);

	// check that sort is stable
	char *pastr = pc_patch_to_string(pa);
	char *pasortstr = pc_patch_to_string(pasort);
	CU_ASSERT_STRING_EQUAL(pastr, pasortstr);

	// free
	free(pastr);
	free(pasortstr);
	pcfree(wkb);
	pc_patch_free(pa);
	pc_patch_free(pasort);
	pc_pointlist_free(li);
}