Esempio n. 1
0
struct point *make_point( double orientation, double inclination,
			  int y, int x, int row_viewpt, int col_viewpt, 
			  SEGMENT *seg_out_p, CELL cell_no)
{
    struct point *NEW_PT;
    CELL data_read, data_to_write;
    char *value_read, *value_to_write;
    
    NEW_PT = (struct point *) G_malloc(sizeof(struct point));
    NEW_PT_ORIENTATION = orientation;
    NEW_PT_INCLINATION = inclination;
    NEW_PT_Y           = y;
    NEW_PT_X           = x;
    NEXT_NEW_PT        = NULL_HERE;
    
    value_read = (char*) &data_read;
    value_to_write = (char*) &data_to_write;
    data_to_write = 0;
    segment_get (seg_out_p, value_read,
		 row_viewpt - y, x + col_viewpt);
    if (data_read != cell_no)
	segment_put (seg_out_p, value_to_write,
		     row_viewpt - y, x + col_viewpt);
    return(NEW_PT);
}
Esempio n. 2
0
int
mark_visible_points(struct point *head, SEGMENT * seg_out_p, int row_viewpt,
		    int col_viewpt, double color_factor, double COLOR_SHIFT)
{
    struct point *PT_TO_MARK;
    FCELL data;

    PT_TO_MARK = head;

    while (PT_TO_MARK != NULL) {	/*        loop till end of list   */
	segment_get(seg_out_p, &data,
		    row_viewpt - PT_TO_MARK_Y, PT_TO_MARK_X + col_viewpt);

	if (data != (FCELL) 1) {	/* point has not been deleted previously        */
	    /* old value    
	       data = (FCELL ) (PT_TO_MARK_INCL* 57.3 * color_factor 
	       + COLOR_SHIFT);
	       end of old data      */
	    data = (FCELL) (PT_TO_MARK_INCL * 57.325 + 90.0);
	    segment_put(seg_out_p, &data,
			row_viewpt - PT_TO_MARK_Y, PT_TO_MARK_X + col_viewpt);
	}

	PT_TO_MARK = NEXT_PT_TO_MARK;	/* next visible point   */
    }
    return 0;
}
Esempio n. 3
0
int cseg_put(CSEG * cseg, CELL * value, int row, int col)
{
    if (segment_put(&(cseg->seg), value, row, col) < 0) {
	G_warning("cseg_put(): could not write segment file");
	return -1;
    }
    return 0;
}
Esempio n. 4
0
int dseg_put(DSEG * dseg, int row, int col, DCELL value)
{
    if (segment_put(&(dseg->seg), &value, row, col) < 0) {
	G_warning("dseg_put(): could not write segment file");
	return -1;
    }
    return 0;
}
Esempio n. 5
0
extern void segment_PutGet_test(umMem_T memory)
{
        uint32_t array[10];
                       
        for (int i = 0; i < 10; i++) {
                array[i] = (uint32_t) (i * 10);
        }
        
        /* Map segment 8, and store array elements in segment 8 */
        segment_map(memory, 8, 10);
        for(int i = 0; i < 10; i++) {
                segment_put(memory, 8, i, array[i]);
        }
        for(int i = 0; i < 10; i++) {
                if (segment_get(memory, 8, i) != array[i]) {
                        fprintf(stderr, "Offset %d has incorrect value\n", i);
                }
        }
        
        fprintf(stderr, "segment_PutGet is fine with valid inputs\n");
}
Esempio n. 6
0
static int queue_pixel_core ( move *movements, queue **redo_segments,
                              cell_map *dist, cell_map *elev,
                              cell_map *dir, cell_map *up, cell_map *dw,
                              seg_map *segment_info, int seg, int *count,
                              int **neighbours )
{
    FCELL dist_cell = 0, dist_cell_neig = 0, up_cell = 0, dw_cell = 0;
    FCELL elev_cell = 0, elev_cell_neig = 0;
    //CELL dir_cell = 0;

    elem *el = pop( redo_segments[seg] ), *prev;
    //int *neighbours[NMV] = {{0, 0},{0, 0},};

    G_debug ( 4, "Segment number: %d\n", seg );

    // check if there is pixel to do in the row
    while (el != NULL)
    {
        int row = el->point.row;
        int col = el->point.col;
        segment_get( &dist->seg, &dist_cell, row, col );

        if ( dist_cell >= 0 )
        {
            // get cell neighbours
            get_neighbours ( row, col, movements, neighbours,
                             segment_info->nrows, segment_info->ncols );

            for ( int n = 0; n < ( int ) sizeof ( movements ) ; n++ )
            {
                // TODO: after check if there are performce consegunece to declaire here or not
                int nx = neighbours[n][0];
                int ny = neighbours[n][1];

                //Check if neighbours are inside the region AND the domain
                if ( nx != NULL_NEIG){
                    // get distance value
                    segment_get( &dist->seg, &dist_cell_neig, nx, ny );
                    //Check if distance is in the domain
                    if (dist_cell_neig>0 )
                    {
                        float new_dist = dist_cell + movements[n].dist;
                        if ( dist_cell_neig > new_dist )
                        {
                            // assign the smaller one
                            segment_put ( &dist->seg, &new_dist, nx, ny );
                            segment_put ( &dir->seg, &movements[n].dir, nx, ny );
                            //check if drop is positive or negative
                            segment_get( &elev->seg, &elev_cell, row, col );
                            segment_get( &elev->seg, &elev_cell_neig, nx, ny );
                            float drop = elev_cell_neig - elev_cell;

                            if ( drop >= 0 )
                            {
                                segment_get( &up->seg, &up_cell, row, col );
                                up_cell += drop;
                                segment_put ( &up->seg, &up_cell, nx, ny );
                                //up_cache[nx][ny] = up_cache[1][col] + drop;
                                segment_get( &dw->seg, &dw_cell, row, col );
                                segment_put ( &dw->seg, &dw_cell, nx, ny );
                                //dw_cache[nx][ny] = dw_cache[1][col];
                            }
                            else
                            {
                                segment_get( &up->seg, &up_cell, row, col );
                                segment_put ( &up->seg, &up_cell, nx, ny );
                                //up_cache[nx][ny] = up_cache[1][col];
                                segment_get( &dw->seg, &dw_cell, row, col );
                                dw_cell += drop;
                                segment_put ( &dw->seg, &dw_cell, nx, ny );
                                //dw_cache[nx][ny] = dw_cache[1][col] + drop;
                            }
                            int seg_numb = get_segment_number(nx, ny, segment_info);
                            array_append(seg_numb, nx, ny, redo_segments);
                            *count += 1;
                        }
                    }
                }
            }
        }
        prev = el;
        free(prev);
        el = pop( redo_segments[seg] );
    }
    return 0;
}
Esempio n. 7
0
int P_Sparse_Raster_Points(SEGMENT *out_seg, struct Cell_head *Elaboration,
		struct Cell_head *Original, struct bound_box General, struct bound_box Overlap,
		struct Point *obs, double *param, double pe, double pn,
		double overlap, int nsplx, int nsply, int num_points,
		int bilin, double mean)
{
    int i, row, col;
    double X, Y, interpolation, csi, eta, weight, dval;
    int points_in_box = 0;

    /* Reading points inside output region and inside general box */
    /* all points available here are inside the output box,
     * selected by P_Read_Raster_Region_Nulls(), no check needed */

    for (i = 0; i < num_points; i++) {

	X = obs[i].coordX;
	Y = obs[i].coordY;

	/* X,Y are cell center cordinates, MUST be inside General box */
	row = (int) (floor(Rast_northing_to_row(Y, Original)) + 0.1);
	col = (int) (floor((X - Original->west) / Original->ew_res) + 0.1);

	if (row < 0 || row >= Original->rows) {
	    G_fatal_error("row index out of range");
	    continue;
	}

	if (col < 0 || col >= Original->cols) {
	    G_fatal_error("col index out of range");
	    continue;
	}
	points_in_box++;

	G_debug(3, "P_Sparse_Raster_Points: interpolate point %d...", i);
	if (bilin)
	    interpolation =
		dataInterpolateBilin(X, Y, pe, pn, nsplx,
				     nsply, Elaboration->west,
				     Elaboration->south, param);
	else
	    interpolation =
		dataInterpolateBicubic(X, Y, pe, pn, nsplx,
				       nsply, Elaboration->west,
				       Elaboration->south, param);

	interpolation += mean;

	if (Vect_point_in_box(X, Y, interpolation, &Overlap)) {	/* (5) */
	    dval = interpolation;
	}
	else {
	    segment_get(out_seg, &dval, row, col);
	    if ((X > Overlap.E) && (X < General.E)) {
		if ((Y > Overlap.N) && (Y < General.N)) {	/* (3) */
		    csi = (General.E - X) / overlap;
		    eta = (General.N - Y) / overlap;
		    weight = csi * eta;
		    interpolation *= weight;
		    dval += interpolation;
		}
		else if ((Y < Overlap.S) && (Y > General.S)) {	/* (1) */
		    csi = (General.E - X) / overlap;
		    eta = (Y - General.S) / overlap;
		    weight = csi * eta;
		    interpolation *= weight;
		    dval = interpolation;
		}
		else if ((Y >= Overlap.S) && (Y <= Overlap.N)) {	/* (1) */
		    weight = (General.E - X ) / overlap;
		    interpolation *= weight;
		    dval = interpolation;
		}
	    }
	    else if ((X < Overlap.W) && (X > General.W)) {
		if ((Y > Overlap.N) && (Y < General.N)) {	/* (4) */
		    csi = (X - General.W) / overlap;
		    eta = (General.N - Y) / overlap;
		    weight = eta * csi;
		    interpolation *= weight;
		    dval += interpolation;
		}
		else if ((Y < Overlap.S) && (Y > General.S)) {	/* (2) */
		    csi = (X - General.W) / overlap;
		    eta = (Y - General.S) / overlap;
		    weight = csi * eta;
		    interpolation *= weight;
		    dval += interpolation;
		}
		else if ((Y >= Overlap.S) && (Y <= Overlap.N)) {	/* (2) */
		    weight = (X - General.W) / overlap;
		    interpolation *= weight;
		    dval += interpolation;
		}
	    }
	    else if ((X >= Overlap.W) && (X <= Overlap.E)) {
		if ((Y > Overlap.N) && (Y < General.N)) {	/* (3) */
		    weight = (General.N - Y) / overlap;
		    interpolation *= weight;
		    dval += interpolation;
		}
		else if ((Y < Overlap.S) && (Y > General.S)) {	/* (1) */
		    weight = (Y - General.S) / overlap;
		    interpolation *= weight;
		    dval = interpolation;
		}
	    }
	} /* end not in overlap */
	segment_put(out_seg, &dval, row, col);
    }  /* for num_points */

    return 1;
}