static void test_point_access() { PCPOINT *pt; int rv; double a1, a2, a3, a4, b1, b2, b3, b4; int idx = 0; pt = pc_point_make(schema); CU_ASSERT( pt != NULL ); /* One at a time */ idx = 0; a1 = 1.5; rv = pc_point_set_double_by_index(pt, idx, a1); rv = pc_point_get_double_by_index(pt, idx, &b1); // printf("d1=%g, d2=%g\n", a1, b1); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); idx = 2; a2 = 1501500.12; rv = pc_point_set_double_by_index(pt, idx, a2); rv = pc_point_get_double_by_index(pt, idx, &b2); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); a3 = 91; rv = pc_point_set_double_by_name(pt, "NumberOfReturns", a3); rv = pc_point_get_double_by_name(pt, "NumberOfReturns", &b3); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); pc_point_free(pt); /* All at once */ pt = pc_point_make(schema); a1 = 1.5; a2 = 1501500.12; a3 = 91; a4 = 200; rv = pc_point_set_double_by_index(pt, 0, a1); rv = pc_point_set_double_by_index(pt, 2, a2); rv = pc_point_set_double_by_name(pt, "NumberOfReturns", a3); rv = pc_point_set_double_by_name(pt, "UserData", a4); rv = pc_point_get_double_by_index(pt, 0, &b1); rv = pc_point_get_double_by_index(pt, 2, &b2); rv = pc_point_get_double_by_name(pt, "NumberOfReturns", &b3); rv = pc_point_get_double_by_name(pt, "UserData", &b4); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001); pc_point_free(pt); }
char * pc_point_to_string(const PCPOINT *pt) { /* { "pcid":1, "values":[<dim1>, <dim2>, <dim3>, <dim4>] }*/ stringbuffer_t *sb = stringbuffer_create(); char *str; int i; stringbuffer_aprintf(sb, "{\"pcid\":%d,\"pt\":[", pt->schema->pcid); for ( i = 0; i < pt->schema->ndims; i++ ) { double d; if ( ! pc_point_get_double_by_index(pt, i, &d) ) { pcerror("pc_point_to_string: unable to read double at position %d", i); } if ( i ) { stringbuffer_append(sb, ","); } stringbuffer_aprintf(sb, "%g", d); } stringbuffer_append(sb, "]}"); str = stringbuffer_getstringcopy(sb); stringbuffer_destroy(sb); return str; }
double pc_point_get_y(const PCPOINT *pt) { double d; pc_point_get_double_by_index(pt, pt->schema->y_position, &d); return d; }
/** * @brief this function convert a PCPOINT to an array of double containing * all the dimension values of this point * * @param a pointer to the point to convert to double * * @return a pointer to an array of double containing all the dimensions * of the point expressed as double precision * */ double * pc_point_to_double_array(const PCPOINT *p) { int i; double *a = (double *) pcalloc( p->schema->ndims * sizeof(double) ); for(i=0; i<p->schema->ndims; ++i) { pc_point_get_double_by_index(p, i, &(a[i])); } return a; }
/* TODO: expose to API ? Would require also exposing stringbuffer * See https://github.com/pgpointcloud/pointcloud/issues/74 */ static int pc_patch_uncompressed_to_stringbuffer(const PCPATCH_UNCOMPRESSED *patch, stringbuffer_t *sb) { PCPOINTLIST *pl; int i, j; /* { "pcid":1, "points":[[<dim1>, <dim2>, <dim3>, <dim4>],[<dim1>, <dim2>, <dim3>, <dim4>]] }*/ /* TODO: reserve space in buffer ? */ pl = pc_pointlist_from_uncompressed(patch); stringbuffer_aprintf(sb, "{\"pcid\":%d,\"pts\":[", patch->schema->pcid); for ( i = 0; i < pl->npoints; i++ ) { PCPOINT *pt = pc_pointlist_get_point(pl, i); if ( i ) stringbuffer_append(sb, ",["); else stringbuffer_append(sb, "["); for ( j = 0; j < pt->schema->ndims; j++ ) { double d; if ( ! pc_point_get_double_by_index(pt, j, &d)) { pcerror("%s: unable to read double at index %d", __func__, j); return PC_FAILURE; } if ( j ) stringbuffer_aprintf(sb, ",%g", d); else stringbuffer_aprintf(sb, "%g", d); } stringbuffer_append(sb, "]"); } stringbuffer_append(sb, "]}"); /* All done, copy and clean up */ pc_pointlist_free(pl); return PC_SUCCESS; }
static void test_point_access() { PCPOINT *pt; int rv; double a1, a2, a3, a4, b1, b2, b3, b4; int idx = 0; double *allvals; pt = pc_point_make(schema); CU_ASSERT( pt != NULL ); /* One at a time */ idx = 0; a1 = 1.5; rv = pc_point_set_double_by_index(pt, idx, a1); rv = pc_point_get_double_by_index(pt, idx, &b1); // printf("d1=%g, d2=%g\n", a1, b1); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); idx = 2; a2 = 1501500.12; rv = pc_point_set_double_by_index(pt, idx, a2); rv = pc_point_get_double_by_index(pt, idx, &b2); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); a3 = 91; rv = pc_point_set_double_by_name(pt, "Intensity", a3); rv = pc_point_get_double_by_name(pt, "Intensity", &b3); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); pc_point_free(pt); /* All at once */ pt = pc_point_make(schema); a1 = 1.5; a2 = 1501500.12; a3 = 91; a4 = 200; rv = pc_point_set_double_by_index(pt, 0, a1); rv = pc_point_set_double_by_index(pt, 1, a2); rv = pc_point_set_double_by_name(pt, "Intensity", a3); rv = pc_point_set_double_by_name(pt, "Z", a4); rv = pc_point_get_double_by_index(pt, 0, &b1); rv = pc_point_get_double_by_index(pt, 1, &b2); rv = pc_point_get_double_by_name(pt, "Intensity", &b3); rv = pc_point_get_double_by_name(pt, "Z", &b4); CU_ASSERT_DOUBLE_EQUAL(a1, b1, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a2, b2, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a3, b3, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(a4, b4, 0.0000001); /* as a double array */ rv = pc_point_set_double_by_index(pt, 0, a1); rv = pc_point_set_double_by_index(pt, 1, a2); rv = pc_point_set_double_by_index(pt, 2, a3); rv = pc_point_set_double_by_index(pt, 3, a4); allvals = pc_point_to_double_array(pt); CU_ASSERT_DOUBLE_EQUAL(allvals[0], a1, 0.0000001); CU_ASSERT_DOUBLE_EQUAL(allvals[1], a2, 0.0000001); //printf("allvals[2]:%g\n", allvals[2]); CU_ASSERT_DOUBLE_EQUAL(allvals[2], a3, 0.0000001); //printf("allvals[3]:%g\n", allvals[3]); CU_ASSERT_DOUBLE_EQUAL(allvals[3], a4, 0.0000001); pcfree(allvals); pc_point_free(pt); }