size_t pc_patch_dimensional_serialized_size(const PCPATCH_DIMENSIONAL *patch) { PCPATCH_DIMENSIONAL *p = (PCPATCH_DIMENSIONAL*)patch; int i; size_t size = 0; for ( i = 0; i < p->schema->ndims; i++ ) { size += pc_bytes_serialized_size(&(p->bytes[i])); } return size; }
static PCPATCH * pc_patch_dimensional_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEMA *schema) { // typedef struct // { // uint32_t size; // uint32_t pcid; // uint32_t compression; // uint32_t npoints; // double xmin, xmax, ymin, ymax; // data: // pcpoint[3] pcstats(min, max, avg) // pcbytes[ndims]; // } // SERIALIZED_PATCH; PCPATCH_DIMENSIONAL *patch; int i; const uint8_t *buf; int ndims = schema->ndims; int npoints = serpatch->npoints; size_t stats_size = pc_stats_size(schema); // 3 pcpoints worth of stats /* Reference the external data */ patch = pcalloc(sizeof(PCPATCH_DIMENSIONAL)); /* Set up basic info */ patch->type = serpatch->compression; patch->schema = schema; patch->readonly = true; patch->npoints = npoints; patch->bounds = serpatch->bounds; /* Point into the stats area */ patch->stats = pc_patch_stats_deserialize(schema, serpatch->data); /* Set up dimensions */ patch->bytes = pcalloc(ndims * sizeof(PCBYTES)); buf = serpatch->data + stats_size; for ( i = 0; i < ndims; i++ ) { PCBYTES *pcb = &(patch->bytes[i]); PCDIMENSION *dim = schema->dims[i]; pc_bytes_deserialize(buf, dim, pcb, true /*readonly*/, false /*flipendian*/); pcb->npoints = npoints; buf += pc_bytes_serialized_size(pcb); } return (PCPATCH*)patch; }
PCPATCH * pc_patch_dimensional_from_wkb(const PCSCHEMA *schema, const uint8_t *wkb, size_t wkbsize) { /* byte: endianness (1 = NDR, 0 = XDR) uint32: pcid (key to POINTCLOUD_SCHEMAS) uint32: compression (0 = no compression, 1 = dimensional, 2 = GHT) uint32: npoints dimensions[]: dims (interpret relative to pcid and compressions) */ static size_t hdrsz = 1+4+4+4; /* endian + pcid + compression + npoints */ PCPATCH_DIMENSIONAL *patch; uint8_t swap_endian = (wkb[0] != machine_endian()); uint32_t npoints, ndims; const uint8_t *buf; int i; if ( wkb_get_compression(wkb) != PC_DIMENSIONAL ) { pcerror("%s: call with wkb that is not dimensionally compressed", __func__); return NULL; } npoints = wkb_get_npoints(wkb); ndims = schema->ndims; patch = pcalloc(sizeof(PCPATCH_DIMENSIONAL)); patch->type = PC_DIMENSIONAL; patch->readonly = PC_FALSE; patch->schema = schema; patch->npoints = npoints; patch->bytes = pcalloc(ndims*sizeof(PCBYTES)); buf = wkb+hdrsz; for ( i = 0; i < ndims; i++ ) { PCBYTES *pcb = &(patch->bytes[i]); PCDIMENSION *dim = schema->dims[i]; pc_bytes_deserialize(buf, dim, pcb, PC_FALSE /*readonly*/, swap_endian); pcb->npoints = npoints; buf += pc_bytes_serialized_size(pcb); } return (PCPATCH*)patch; }
static PCPATCH * pc_patch_dimensional_deserialize(const SERIALIZED_PATCH *serpatch, const PCSCHEMA *schema) { PCPATCH_DIMENSIONAL *patch; int i; const uint8_t *buf; int ndims = schema->ndims; int npoints = serpatch->npoints; /* Reference the external data */ patch = pcalloc(sizeof(PCPATCH_DIMENSIONAL)); /* Set up basic info */ patch->type = PC_DIMENSIONAL; patch->schema = schema; patch->readonly = true; patch->npoints = npoints; patch->xmin = serpatch->xmin; patch->ymin = serpatch->ymin; patch->xmax = serpatch->xmax; patch->ymax = serpatch->ymax; /* Set up dimensions */ patch->bytes = pcalloc(ndims * sizeof(PCBYTES)); buf = serpatch->data; for ( i = 0; i < ndims; i++ ) { PCBYTES *pcb = &(patch->bytes[i]); PCDIMENSION *dim = schema->dims[i]; pc_bytes_deserialize(buf, dim, pcb, true /*readonly*/, false /*flipendian*/); pcb->npoints = npoints; buf += pc_bytes_serialized_size(pcb); } return (PCPATCH*)patch; }