Esempio n. 1
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;



}
Esempio n. 2
0
static void
test_patch_range_compression_lazperf()
{
	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_lazperf_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);
}
Esempio n. 3
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);
}
Esempio n. 4
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);
}
Esempio n. 5
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);
}
Esempio n. 6
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);
}
Esempio n. 7
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);
}
Esempio n. 8
0
Datum pcpatch_as_text(PG_FUNCTION_ARGS)
{
	SERIALIZED_PATCH *serpatch = PG_GETARG_SERPATCH_P(0);
	text *txt;
	char *str;
	PCSCHEMA *schema = pc_schema_from_pcid(serpatch->pcid, fcinfo);
	PCPATCH *patch = pc_patch_deserialize(serpatch, schema);
	if ( ! patch )
		PG_RETURN_NULL();

	str = pc_patch_to_string(patch);
	pc_patch_free(patch);
	txt = cstring_to_text(str);
	pfree(str);
	PG_RETURN_TEXT_P(txt);
}
Esempio n. 9
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);
}
Esempio n. 10
0
static void
test_patch_hex_in()
{
	// 00 endian (big)
	// 00000000 pcid
	// 00000000 compression
	// 00000002 npoints
	// 0000000200000003000000050006 pt1 (XYZi)
	// 0000000200000003000000050008 pt2 (XYZi)
	char *hexbuf = "0000000000000000000000000200000002000000030000000500060000000200000003000000050008";

	double d;
	char *str;
	size_t hexsize = strlen(hexbuf);
	uint8_t *wkb = bytes_from_hexbytes(hexbuf, hexsize);
	PCPATCH *pa = pc_patch_from_wkb(simpleschema, wkb, hexsize/2);
	PCPOINTLIST *pl = pc_pointlist_from_patch(pa);

	pc_point_get_double_by_name(pc_pointlist_get_point(pl, 0), "X", &d);
	CU_ASSERT_DOUBLE_EQUAL(d, 0.02, 0.000001);
	pc_point_get_double_by_name(pc_pointlist_get_point(pl, 1), "Intensity", &d);
	CU_ASSERT_DOUBLE_EQUAL(d, 8, 0.000001);

	pc_point_get_double_by_name(&(pa->stats->min), "Intensity", &d);
	CU_ASSERT_DOUBLE_EQUAL(d, 6, 0.000001);
	pc_point_get_double_by_name(&(pa->stats->max), "Intensity", &d);
	CU_ASSERT_DOUBLE_EQUAL(d, 8, 0.000001);
	pc_point_get_double_by_name(&(pa->stats->avg), "Intensity", &d);
	CU_ASSERT_DOUBLE_EQUAL(d, 7, 0.000001);

	str = pc_patch_to_string(pa);
	CU_ASSERT_STRING_EQUAL(str, "{\"pcid\":0,\"pts\":[[0.02,0.03,0.05,6],[0.02,0.03,0.05,8]]}");
	// printf("\n%s\n",str);
	pcfree(str);

	pc_pointlist_free(pl);
	pc_patch_free(pa);
	pcfree(wkb);
}
Esempio n. 11
0
/**
* Test the function which clone a patch keeping only a part of dimensions, numerous print to see what happens
*/
static void
test_patch_subset()
{
    int i;
    int npts = 20;
    PCPOINTLIST *pl1,*pl2 ;
    PCPATCH_UNCOMPRESSED *pu1, *pu2;
    PCPATCH *pa1, *pa2, *pa3, *pa4;
    PCDIMSTATS *pds = NULL;
    size_t z1, z2;
    uint8_t *wkb1, *wkb2;
    char *str1;

	//getting a test patch
	
    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*2.8);
        pc_point_set_double_by_name(pt1, "y", i*1.3);
        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));
 
    
    //testing the function :
   // printf("testing the dimension-reduction function\n");
    //printf("\n\n	position of x : %i \n\n",pc_schema_get_dimension_position_by_name(pa1->schema, "x"));
    uint32_t new_dim_number = 2; 
	char *dim_to_keep[] = {  "y", "x" }; 
	uint32_t dim_position[2];
	int i2 ;
	
	//test of pc_schema_get_dimension_position_by_name
	/*
		for(i2=0;i2<new_dim_number;i2++)
		{
			dim_position[i2] = pc_schema_get_dimension_position_by_name(pa1->schema, dim_to_keep[i2]);
			printf("\n dimension %s has position %d",dim_to_keep[i2],dim_position[i2] );
		}
	printf("\n");
	* */
	 //printf("\n the original schema to json : %s",pc_schema_to_json(pa1->schema));
	 //test of pc_bounds_to_string(PCBOUNDS *b) 
	 
	 //testing the function pc_patch_dimensional_bytes_array_to_string
	 //printf(" the original PCBYTES array :%s",pc_patch_dimensional_bytes_array_to_string((PCPATCH_DIMENSIONAL*)pa1));
    
    //testing dimstat function :
		//creating dimstats
		//pds = pc_dimstats_make(simpleschema);
		//pc_dimstats_update(pds, (PCPATCH_DIMENSIONAL*)pa1);
		//testing function : 
		//PCDIMSTATS * o_dimstats = pc_dimstats_clone_subset(pds,dim_position, new_dim_number);
	
	//testing reduce_dimension function
    //printf("\n \n beginning test of patch_reduce_dimension \n ");
    pa3 = pc_patch_reduce_dimension(pa1, dim_to_keep, new_dim_number);
    
    //printf("\n the schema to json : %s",pc_schema_to_json(pa3->schema));
   // printf("\n the stats to json : %s",pc_stats_to_json(pa3->stats));
   // printf("\n \n \n the patch to json : %s" , pc_patch_to_string(pa3));
    
	//printf(" the  pa3 PCBYTES array :%s",pc_patch_dimensional_bytes_array_to_string((PCPATCH_DIMENSIONAL*)pa3)); 
   
    //test of the serialize / deserialize function to emulate the pc_acess top function
    
    //test on the result pathc :
		 //test of pc_bounds_to_string(PCBOUNDS *b)
			//printf("the bounds of pa3 : %s \n",  pc_bounds_to_string( &(pa3->bounds) ) );
		 
	//the test on result patch : should return a new patch with only Y and X dimension
	
	// printf("%s",pc_patch_to_string( pa3));
	
	 CU_ASSERT_STRING_EQUAL(pc_patch_to_string( pa3), "{\"pcid\":0,\"pts\":[[0,0],[1.3,2.8],[2.6,5.6],[3.9,8.4],[5.2,11.2],[6.5,14],[7.8,16.8],[9.1,19.6],[10.4,22.4],[11.7,25.2],[13,28],[14.3,30.8],[15.6,33.6],[16.9,36.4],[18.2,39.2],[19.5,42],[20.8,44.8],[22.1,47.6],[23.4,50.4],[24.7,53.2]]}");
 
    return;
		//test on schema :
		
		
		
	printf("%s",pc_schema_to_json(pa3->schema ));
     printf("pa1\n%s\n", pc_patch_to_string(pa3));
    
    //cleaning
    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;

}