Beispiel #1
0
static void
test_schema_clone(void)
{
    int i;
    PCSCHEMA *myschema;
    PCSCHEMA *clone = pc_schema_clone(schema);
    hashtable *hash, *chash;
    char *xmlstr;
    CU_ASSERT_EQUAL(clone->pcid, schema->pcid);
    CU_ASSERT_EQUAL(clone->ndims, schema->ndims);
    CU_ASSERT_EQUAL(clone->size, schema->size);
    CU_ASSERT_EQUAL(clone->srid, schema->srid);
    CU_ASSERT_EQUAL(clone->x_position, schema->x_position);
    CU_ASSERT_EQUAL(clone->y_position, schema->y_position);
    CU_ASSERT_EQUAL(clone->compression, schema->compression);
    CU_ASSERT(clone->dims != schema->dims); /* deep clone */
    CU_ASSERT(clone->namehash != schema->namehash); /* deep clone */
    hash = schema->namehash;
    chash = clone->namehash;
    CU_ASSERT_EQUAL(chash->tablelength, hash->tablelength);
    CU_ASSERT_EQUAL(chash->entrycount, hash->entrycount);
    CU_ASSERT_EQUAL(chash->loadlimit, hash->loadlimit);
    CU_ASSERT_EQUAL(chash->primeindex, hash->primeindex);
    CU_ASSERT_EQUAL(chash->hashfn, hash->hashfn);
    CU_ASSERT_EQUAL(chash->eqfn, hash->eqfn);
    CU_ASSERT(chash->table != hash->table); /* deep clone */
    for (i=0; i<schema->ndims; ++i) {
      PCDIMENSION *dim = schema->dims[i];
      PCDIMENSION *cdim = clone->dims[i];
      CU_ASSERT(dim != cdim); /* deep clone */
      CU_ASSERT_STRING_EQUAL(cdim->name, dim->name);
      CU_ASSERT_STRING_EQUAL(cdim->description, dim->description);
      CU_ASSERT_EQUAL(cdim->position, dim->position);
      CU_ASSERT_EQUAL(cdim->size, dim->size);
      CU_ASSERT_EQUAL(cdim->byteoffset, dim->byteoffset);
      CU_ASSERT_EQUAL(cdim->interpretation, dim->interpretation);
      CU_ASSERT_EQUAL(cdim->scale, dim->scale);
      CU_ASSERT_EQUAL(cdim->offset, dim->offset);
      CU_ASSERT_EQUAL(cdim->active, dim->active);
      /* hash table is correctly setup */
      CU_ASSERT_EQUAL(cdim, hashtable_search(clone->namehash, dim->name) );
    }

    pc_schema_free(clone);

    /* See https://github.com/pgpointcloud/pointcloud/issues/66 */
	  xmlstr = "<pc:PointCloudSchema xmlns:pc='x'><pc:dimension><pc:position>1</pc:position></pc:dimension></pc:PointCloudSchema>";
    i = pc_schema_from_xml(xmlstr, &myschema);
	  CU_ASSERT_EQUAL(i, PC_SUCCESS);
    clone = pc_schema_clone(myschema);
    CU_ASSERT_EQUAL(clone->ndims, myschema->ndims);
    CU_ASSERT_EQUAL(clone->dims[0]->name, NULL);
    CU_ASSERT_EQUAL(clone->dims[0]->description, NULL);
    pc_schema_free(myschema);
    pc_schema_free(clone);
}
Beispiel #2
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);
}
Beispiel #3
0
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);
}