Beispiel #1
0
static PCBITMAP *
pc_patch_uncompressed_bitmap(const PCPATCH_UNCOMPRESSED *pa, uint32_t dimnum, PC_FILTERTYPE filter, double val1, double val2)
{
	PCPOINT pt;
	uint32_t i = 0;
	uint8_t *buf = pa->data;
	double d;
	size_t sz = pa->schema->size;
	PCBITMAP *map = pc_bitmap_new(pa->npoints);

	pt.readonly = PC_TRUE;
	pt.schema = pa->schema;

	while ( i < pa->npoints )
	{
		pt.data = buf;
		pc_point_get_double(&pt, pa->schema->dims[dimnum], &d);
		/* Apply the filter to the bitmap */
		pc_bitmap_filter(map, filter, i, d, val1, val2);
		/* Advance data pointer and counter */
		buf += sz;
		i++;
	}

	return map;
}
Beispiel #2
0
int
pc_point_get_double_by_name(const PCPOINT *pt, const char *name, double *val)
{
	PCDIMENSION *dim;
	dim = pc_schema_get_dimension_by_name(pt->schema, name);
	return pc_point_get_double(pt, dim, val);
}
Beispiel #3
0
int
pc_point_get_double_by_index(const PCPOINT *pt, uint32_t idx, double *val)
{
	PCDIMENSION *dim;
	dim = pc_schema_get_dimension(pt->schema, idx);
	return pc_point_get_double(pt, dim, val);
}
Beispiel #4
0
int
pc_point_get_double_by_name(const PCPOINT *pt, const char *name, double *d)
{
	PCDIMENSION *dim;
	dim = pc_schema_get_dimension_by_name(pt->schema, name);
	if ( ! dim ) return PC_FAILURE;
	return pc_point_get_double(pt, dim, d);
}
Beispiel #5
0
int
pc_point_get_double_by_index(const PCPOINT *pt, uint32_t idx, double *d)
{
	PCDIMENSION *dim;
	dim = pc_schema_get_dimension(pt->schema, idx);
	if ( ! dim ) return PC_FAILURE;
	return pc_point_get_double(pt, dim, d);
}
Beispiel #6
0
int
pc_patch_uncompressed_compute_stats(PCPATCH_UNCOMPRESSED *pa)
{
    int i, j;
    const PCSCHEMA *schema = pa->schema;
    double val;
    PCDOUBLESTATS *dstats = pc_dstats_new(pa->schema->ndims);

    if ( pa->stats )
        pc_stats_free(pa->stats);

    /* Point on stack for fast access to values in patch */
    PCPOINT pt;
    pt.readonly = PC_TRUE;
    pt.schema = schema;
    pt.data = pa->data;

    /* We know npoints right away */
    dstats->npoints = pa->npoints;

    for ( i = 0; i < pa->npoints; i++ )
    {
        for ( j = 0; j < schema->ndims; j++ )
        {
            pc_point_get_double(&pt, schema->dims[j], &val);
            /* Check minimum */
            if ( val < dstats->dims[j].min )
                dstats->dims[j].min = val;
            /* Check maximum */
            if ( val > dstats->dims[j].max )
                dstats->dims[j].max = val;
            /* Add to sum */
            dstats->dims[j].sum += val;
        }
        /* Advance to next point */
        pt.data += schema->size;
    }

    pa->stats = pc_stats_new_from_dstats(pa->schema, dstats);
    pc_dstats_free(dstats);
    return PC_SUCCESS;
}
PCPATCH_GHT *
pc_patch_ght_from_uncompressed(const PCPATCH_UNCOMPRESSED *pa)
{
#ifndef HAVE_LIBGHT
	pcerror("%s: libght support is not enabled", __func__);
	return NULL;
#else

	int i, j;
	int pointcount = 0;
	GhtSchemaPtr schema;
	GhtTreePtr tree;
	GhtCoordinate coord;
	GhtNodePtr node;
	PCPOINT pt;
	PCDIMENSION *xdim, *ydim;
	PCPATCH_GHT *paght = NULL;
	size_t pt_size = pa->schema->size;

	/* Cannot handle empty patches */
	if ( ! pa || ! pa->npoints ) return NULL;

	pt.schema = pa->schema;
	pt.readonly = PC_TRUE;

	xdim = pa->schema->dims[pa->schema->x_position];
	ydim = pa->schema->dims[pa->schema->y_position];

	schema = ght_schema_from_pc_schema(pa->schema);
	if ( ght_tree_new(schema, &tree) != GHT_OK ) {
		pcerror("ght_tree_new failed");
		return NULL;
	}

	/* Build up the tree from the points. */
	for ( i = 0; i < pa->npoints; i++ )
	{
		pt.data = pa->data + pt_size * i;
		pc_point_get_double(&pt, xdim, &(coord.x));
		pc_point_get_double(&pt, ydim, &(coord.y));

		/* Build a node from the x/y information */
		/* TODO, make resolution configurable from the schema */
		if ( ght_node_new_from_coordinate(&coord, GHT_MAX_HASH_LENGTH, &node) == GHT_OK )
		{
			unsigned int num_dims;
			ght_schema_get_num_dimensions(schema, &num_dims);
			/* Add attributes to the node */
			for ( j = 0; j < num_dims; j++ )
			{
				PCDIMENSION *dim;
				GhtDimensionPtr ghtdim;
				GhtAttributePtr attr;
				double val;

				/* Don't add X or Y as attributes, they are already embodied in the hash */
				if ( j == pa->schema->x_position || j == pa->schema->y_position )
					continue;

				dim = pc_schema_get_dimension(pa->schema, j);
				pc_point_get_double(&pt, dim, &val);

				ght_schema_get_dimension_by_index(schema, j, &ghtdim);
				ght_attribute_new_from_double(ghtdim, val, &attr);
				ght_node_add_attribute(node, attr);
			}

			/* Add the node to the tree */
			/* TODO, make duplicate handling configurable from the schema */
			if ( ght_tree_insert_node(tree, node) == GHT_OK )
			{
				pointcount++;
			}
			else
			{
				// ght_tree_free(tree);
				pcerror("ght_tree_insert_node failed");
				return NULL;
			}
		}
		else
		{
			ght_tree_free(tree);
			pcerror("ght_node_new_from_coordinate failed");
			return NULL;
		}
	}

	/* Compact the tree */
	if ( ght_tree_compact_attributes(tree) == GHT_OK )
	{
		GhtWriterPtr writer;
		paght = pcalloc(sizeof(PCPATCH_GHT));
		paght->type = PC_GHT;
		paght->readonly = PC_FALSE;
		paght->schema = pa->schema;
		paght->npoints = pointcount;
		paght->bounds = pa->bounds;
		paght->stats = pc_stats_clone(pa->stats);

		/* Convert the tree to a memory buffer */
		ght_writer_new_mem(&writer);
		ght_tree_write(tree, writer);
		ght_writer_get_size(writer, &(paght->ghtsize));
		paght->ght = pcalloc(paght->ghtsize);
		ght_writer_get_bytes(writer, paght->ght);
		ght_writer_free(writer);
	}

	// Let the hierarchical memory manager clean up the tree
	// ght_tree_free(tree);
	return paght;
#endif
}
Beispiel #8
0
int
pc_point_get_m(const PCPOINT *pt, double *val)
{
	return pc_point_get_double(pt, pt->schema->mdim, val);
}