示例#1
0
int dig_Rd_P_area(struct Plus_head *Plus, int n, struct gvfile * fp)
{
    int cnt;
    struct P_area *ptr;

    G_debug(4, "dig_Rd_P_area(): n = %d", n);

    if (0 >= dig__fread_port_P(&cnt, 1, fp))
	return (-1);

    if (cnt == 0) {		/* dead */
	Plus->Area[n] = NULL;
	return 0;
    }

    ptr = dig_alloc_area();

    /* boundaries */
    ptr->n_lines = cnt;

    if (dig_area_alloc_line(ptr, ptr->n_lines) == -1)
	return -1;

    if (ptr->n_lines)
	if (0 >= dig__fread_port_P(ptr->lines, ptr->n_lines, fp))
	    return -1;

    /* isles */
    if (0 >= dig__fread_port_P(&(ptr->n_isles), 1, fp))
	return -1;

    if (dig_area_alloc_isle(ptr, ptr->n_isles) == -1)
	return -1;

    if (ptr->n_isles)
	if (0 >= dig__fread_port_P(ptr->isles, ptr->n_isles, fp))
	    return -1;

    /* centroid */
    if (0 >= dig__fread_port_P(&(ptr->centroid), 1, fp))
	return -1;

    Plus->Area[n] = ptr;

    return (0);
}
示例#2
0
/*!
 * \brief Allocate space for new area and create boundary info from array.
 *
 * Then for each line in area, update line (right,left) info.
 *
 * Neither islands nor centroids area filled.
 *
 * \param[in] plus pointer to Plus_head structure
 * \param[in] n_lines number of lines
 * \param[in] lines array of lines, negative for reverse direction
 *
 * \return number of new area
 * \return -1 on error
 */
int dig_add_area(struct Plus_head *plus, int n_lines, plus_t * lines,
		 struct bound_box *box)
{
    register int i;
    register int area, line;
    struct P_area *Area;
    struct P_line *Line;
    struct P_topo_b *topo;

    G_debug(3, "dig_add_area():");
    /* First look if we have space in array of pointers to areas
     *  and reallocate if necessary */
    if (plus->n_areas >= plus->alloc_areas) {	/* array is full */
	if (dig_alloc_areas(plus, 1000) == -1)
	    return -1;
    }

    /* allocate area structure */
    area = plus->n_areas + 1;
    G_debug(3, "    new area = %d", area);
    Area = dig_alloc_area();
    if (Area == NULL)
	return -1;

    if (dig_area_alloc_line(Area, n_lines) == -1)
	return -1;

    for (i = 0; i < n_lines; i++) {
	line = lines[i];
	Area->lines[i] = line;
	Line = plus->Line[abs(line)];
	topo = (struct P_topo_b *)Line->topo;
	if (plus->do_uplist)
	    dig_line_add_updated(plus, abs(line));
	if (line < 0) {		/* revers direction -> area on left */
	    if (topo->left != 0) {
		G_warning(_("Line %d already has area/isle %d to left"), line,
			  topo->left);
		return -1;
	    }

	    G_debug(3, "  Line %d left set to %d.", line, area);
	    topo->left = area;
	}
	else {
	    if (topo->right != 0) {
		G_warning(_("Line %d already has area/isle %d to right"),
			  line, topo->right);
		return -1;
	    }

	    G_debug(3, "  Line %d right set to %d.", line, area);
	    topo->right = area;
	}
    }
    Area->n_lines = n_lines;
    Area->centroid = 0;

    plus->Area[area] = Area;

    dig_spidx_add_area(plus, area, box);

    plus->n_areas++;

    return (area);
}