Exemplo n.º 1
0
/* Destroys Delaunay triangulation.
 *
 * @param d Structure to be destroyed
 */
void delaunay_destroy(delaunay* d)
{
    if (d == NULL)
        return;

    if (d->point_triangles != NULL) {
        int i;

        for (i = 0; i < d->npoints; ++i)
            if (d->point_triangles[i] != NULL)
                free(d->point_triangles[i]);
        free(d->point_triangles);
    }
    if (d->nedges > 0)
        free(d->edges);
    if (d->n_point_triangles != NULL)
        free(d->n_point_triangles);
    if (d->flags != NULL)
        free(d->flags);
    if (d->circles != NULL)
        free(d->circles);
    if (d->neighbours != NULL)
        free(d->neighbours);
    if (d->triangles != NULL)
        free(d->triangles);
    if (d->t_in != NULL)
        istack_destroy(d->t_in);
    if (d->t_out != NULL)
        istack_destroy(d->t_out);
    free(d);
}
Exemplo n.º 2
0
static void nnpi_getneighbours(nnpi* nn, point* p, int nt, int* tids, int* n, int** nids)
{
    delaunay* d = nn->d;
    istack* neighbours = istack_create();
    indexedpoint* v = NULL;
    int i;

    for (i = 0; i < nt; ++i) {
        triangle* t = &d->triangles[tids[i]];

        istack_push(neighbours, t->vids[0]);
        istack_push(neighbours, t->vids[1]);
        istack_push(neighbours, t->vids[2]);
    }
    qsort(neighbours->v, neighbours->n, sizeof(int), compare_int);

    v = malloc(sizeof(indexedpoint) * neighbours->n);

    v[0].p = &d->points[neighbours->v[0]];
    v[0].i = neighbours->v[0];
    *n = 1;
    for (i = 1; i < neighbours->n; ++i) {
        if (neighbours->v[i] == neighbours->v[i - 1])
            continue;
        v[*n].p = &d->points[neighbours->v[i]];
        v[*n].i = neighbours->v[i];
        (*n)++;
    }

    /*
     * I assume that if there is exactly one tricircle the point belongs to,
     * then number of natural neighbours *n = 3, and they are already sorted
     * in the right way in triangulation process.
     */
    if (*n > 3) {
        v[0].p0 = NULL;
        v[0].p1 = NULL;
        for (i = 1; i < *n; ++i) {
            v[i].p0 = p;
            v[i].p1 = v[0].p;
        }

        qsort(&v[1], *n - 1, sizeof(indexedpoint), compare_indexedpoints);
    }

    (*nids) = malloc(*n * sizeof(int));

    for (i = 0; i < *n; ++i)
        (*nids)[i] = v[i].i;

    istack_destroy(neighbours);
    free(v);
}
Exemplo n.º 3
0
unsigned int flush_paramstack (unsigned int numParams) {
	int offset;
	inode * current;
	node * refsymb;
	current = paramstack->current;
	// run through params stack and push args in reverse order
	//while (current != NULL) {
	for (unsigned int i = 0; i < numParams; i++) {
		switch (current->memt) {
			case IMMEDIATE:
				switch (current->t) {
					case INT:
						fprintf (fp, "\tpushl\t$%d\n", current->val);
						break;
					case STRING:
						fprintf (fp, "\tpushl\t$.LC%d\n", current->val);
						break;
				}
				break;
			case REFERENCE:
				// check for global or local ref
				refsymb = lookup (sts, current->id);
				if (refsymb->offset == 0) {
					fprintf (fp, "\tpushl\t%s\n", current->id);
				} else {
					fprintf (fp, "\tpushl\t%d(%%ebp)\n", refsymb->offset);
				}
				break;
			case RESULT:
				// calculate offset from current stack position
				// only push if offset is greater than zero, otherwise param is already in position
				offset = param_spoffset - current->offset;
				if (offset > 0)
					fprintf (fp, "\tpushl\t%d(%%esp)\n", offset);
				break;
		}
		// increment esp counter
		param_spoffset += 4;
		// move to next param
		current = current->prev;
	}
	// mark the new current inode
	paramstack->current = current;
	// reinitialize stack and reset esp counter
	if (current == NULL)
		istack_destroy (paramstack);
	param_spoffset = 0;
	return (4 * numParams);
}
Exemplo n.º 4
0
void destroy_symboltable () {
	generate_globals();
	generate_strings();
	// free stack
	stack_destroy (sts);
	free (sts);
	// free params type check list
	istack_destroy(paramstack);
	free(paramstack);
	// free return call check list
	list_destroy(returncheck);
	free(returncheck);
	// free operator stack
	istack_destroy (inststack);
	free (inststack);
	// free global stack
	istack_destroy (globstack);
	free (globstack);
	// free string stack
	istack_destroy (strstack);
	free (strstack);
	// close output file
	fclose(fp);
}
Exemplo n.º 5
0
int main(int argc, char *argv[])
{
    istack st;
    int i;
    int val;

    istack_init(&st);
    for (i = 0; i < 32; i++) {
        istack_push(&st, i);
        istack_top(&st, &val);
        printf("%d ", val);
    }
    istack_destroy(&st);
    printf("\n");
    return 0;
}
Exemplo n.º 6
0
void flush_istack (unsigned int convertint) {
	// For arithmetic operations we must use the stack like
	//   a queue. Therefore we start from the bottom and
	//   work upwards (see istack.h)
	node * refsymb;
	inode * current;
	current = inststack->base;
	// generate instruction
	while (current != NULL) {
		switch (current->memt) {
			case IMMEDIATE:
				switch (current->t) {
					case INT:
						fprintf (fp, "\tpushl\t$%d\n", current->val);
						if (convertint)
							generate_num2str();
						break;
					case STRING:
						fprintf (fp, "\tpushl\t$.LC%d\n", current->val);
						break;
				}
				break;
			case REFERENCE:
				// check for global or local ref
				refsymb = lookup (sts, current->id);
				if (refsymb->offset == 0) {
					fprintf (fp, "\tpushl\t%s\n", current->id);
				} else {
					fprintf (fp, "\tpushl\t%d(%%ebp)\n", refsymb->offset);
				}
				// check for integer conversion in the case of string cat
				if ( convertint && (refsymb->t == INT) )
					generate_num2str();
				break;
		}
		current = current->up;
	}
	istack_destroy(inststack);
}
Exemplo n.º 7
0
void dump_operands () {
	// empty inststack
	istack_destroy (inststack);
}