Пример #1
0
static int dotext(char *text, int top, int bottom, int left, int right,
		  int background)
{
    R_standard_color(background);
    R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
    R_standard_color(BLACK);
    /* center the text */
    left = (left + right - Text_width(text)) / 2;
    Text(text, top, bottom, left, right, 2);

    return 0;
}
Пример #2
0
static int show_point(int n, int true_color)
{
    if (!true_color)
	R_standard_color(ORANGE);
    else if (group.points.status[n])
	R_standard_color(GREEN);
    else
	R_standard_color(RED);

    display_one_point(VIEW_MAP1, group.points.e1[n], group.points.n1[n]);

    return 0;
}
Пример #3
0
static int dotext(char *text, int top, int bottom, int left, int right,
		  int centered, int color)
{
    R_standard_color(BACKGROUND);
    R_box_abs(left, top, right, bottom);
    R_standard_color(color);
    R_move_abs(left + 1 + edge, bottom - 1 - edge);
    if (centered)
	R_move_rel((right - left - strlen(text) * size) / 2, 0);
    R_set_window(top, bottom, left, right);	/* for text clipping */
    R_text(text);
    R_set_window(SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);

    return 0;
}
Пример #4
0
int do_color(char *buff)
{
    char in_color[64];
    int R, G, B, color = 0;

    if (1 != sscanf(buff, "%*s %s", in_color)) {
	G_warning(_("Unable to read color"));
	return (-1);
    }

    /* Parse and select color */
    color = G_str_to_color(in_color, &R, &G, &B);
    if (color == 0) {
	G_warning(_("[%s]: No such color"), in_color);
	/* store for backup */
	last_color.a = RGBA_COLOR_NONE;
	return (-1);
    }
    if (color == 1) {
	R_RGB_color(R, G, B);
	/* store for backup */
	set_last_color(R, G, B, RGBA_COLOR_OPAQUE);
    }
    if (color == 2) {		/* color == 'none' */
	R = D_translate_color(DEFAULT_BG_COLOR);
	R_standard_color(R);
	/* store for backup */
	set_last_color(0, 0, 0, RGBA_COLOR_NONE);
    }
    return (0);
}
Пример #5
0
int Erase_view(View * view)
{
    R_standard_color(WHITE);
    R_box_abs(view->left, view->top, view->right, view->bottom);

    return 0;
}
Пример #6
0
int Init_graphics(void)
{
    D_full_screen();


    SCREEN_TOP = R_screen_top();
    SCREEN_BOTTOM = R_screen_bot();
    SCREEN_LEFT = R_screen_left();
    SCREEN_RIGHT = R_screen_rite();

    R_standard_color(WHITE);

    VIEW_TITLE1 = makeview(97.5, 100.0, 0.0, 50.0);
    VIEW_TITLE2 = makeview(97.5, 100.0, 50.0, 100.0);
    VIEW_MAP1 = makeview(51.0, 97.5, 0.0, 50.0);
    VIEW_MAP2 = makeview(51.0, 97.5, 50.0, 100.0);
    VIEW_TITLE1_ZOOM = makeview(47.5, 51.0, 0.0, 50.0);
    VIEW_TITLE2_ZOOM = makeview(47.5, 51.0, 50.0, 100.0);
    VIEW_MAP1_ZOOM = makeview(2.5, 47.5, 0.0, 50.0);
    VIEW_MAP2_ZOOM = makeview(2.5, 47.5, 50.0, 100.0);
    VIEW_MENU = makeview(0.0, 2.5, 0.0, 100.0);

    G_init_colors(&VIEW_MAP1->cell.colors);
    G_init_colors(&VIEW_MAP2->cell.colors);

    return 0;
}
Пример #7
0
static int cancel_which(void)
{
    if (which == -2) {
	R_standard_color(BLACK);
	Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
    }
    else if (which >= 0) {
	R_standard_color(BLACK);
	Outline_box(list[which].box.top, list[which].box.bottom,
		    list[which].box.left, list[which].box.right);
    }
    which = -1;
    R_flush();

    return 0;
}
Пример #8
0
static int downarrow(struct box *box, int color)
{
    R_standard_color(color);
    Downarrow(box->top + edge, box->bottom - edge, box->left + edge,
	      box->right - edge);

    return 0;
}
Пример #9
0
static int draw_option_boxes(Objects * objects)
{
    Objects *x;

    R_standard_color(OUTLINE_COLOR);
    for (x = objects; x->type; x++) {
	if (x->type == OPTION_OBJECT && *x->status == 0)
	    Outline_box(x->top, x->bottom, x->left, x->right);
    }
    R_standard_color(GREEN);
    for (x = objects; x->type; x++) {
	if (x->type == OPTION_OBJECT && *x->status > 0)
	    Outline_box(x->top, x->bottom, x->left, x->right);
    }

    return 0;
}
Пример #10
0
static int pick(int x, int y, int button)
{
    int n;

    if (inbox(&more, x, y)) {
	cancel_which();
	if (page + 1 >= npages)
	    return 0;
	page++;
	return -1;
    }
    if (inbox(&less, x, y)) {
	cancel_which();
	if (page == 0)
	    return 0;
	page--;
	return -1;
    }
    if (inbox(&cancel, x, y)) {
	if (which == -2)
	    return -2;
	cancel_which();
	which = -2;
	R_standard_color(RED);
	Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);
	R_flush();
	return 0;
    }
    /* search name list. handle double click */
    for (n = 0; n < count; n++)
	if (inbox(&list[n].box, x, y)) {
	    if (n == which)	/* second click! */
		return 1;
	    cancel_which();
	    which = n;
	    R_standard_color(RED);
	    Outline_box(list[n].box.top, list[n].box.bottom,
			list[n].box.left, list[n].box.right);
	    R_flush();
	    return 0;		/* ignore first click */
	}

    cancel_which();
    return 0;
}
Пример #11
0
int display_title(View * view)
{
    View *title;
    char left[100], center[100];
    int size;

    *left = 0;
    *center = 0;

    if (view->cell.configured) {
	sprintf(center, "%s (mag %.1f)",
		view->cell.name, magnification(view));
    }

    if (view == VIEW_MAP1) {
	sprintf(left, "%s", G_location());
	title = VIEW_TITLE1;
    }
    else if (view == VIEW_MAP1_ZOOM) {
	title = VIEW_TITLE1_ZOOM;
    }

    if (view == VIEW_MAP2) {
	sprintf(left, "%s", G_location());
	title = VIEW_TITLE2;
    }
    else if (view == VIEW_MAP2_ZOOM) {
	title = VIEW_TITLE2_ZOOM;
    }

    Erase_view(title);
    R_standard_color(WHITE);
    size = title->nrows - 4;
    R_text_size(size, size);
    Text(left, title->top, title->bottom, title->left, title->right, 2);
    if (*center) {
	R_standard_color(YELLOW);
	Text(center, title->top, title->bottom,
	     (title->left + title->right - Text_width(center)) / 2,
	     title->right, 2);
    }

    return 0;
}
Пример #12
0
int display_points_in_view(View * view, int in_color,
			   double *east, double *north, int *status,
			   int count)
{
    if (!view->cell.configured)
	return 1;
    while (count-- > 0) {
	if (in_color && (*status > 0))
	    R_standard_color(GREEN);
	else if (in_color && (*status == 0))
	    R_standard_color(RED);
	else
	    R_standard_color(GREY);
	status++;
	display_one_point(view, *east++, *north++);
    }

    return 0;
}
Пример #13
0
static int cancel_which(void)
{
    if (which >= 0) {
	R_standard_color(BACKGROUND);
	Outline_box((report.top + which * height) + 1,
		    report.top + (which + 1) * height, report.left,
		    report.right - 1);
	show_point(first_point + which, 1);
    }
    which = -1;

    return 0;
}
Пример #14
0
static int dobox(struct box *box, char *text, int color, int top, int left,
		 int right, int centered)
{
    int bottom;

    bottom = top + height;
    /* fill inside of box with color */
    R_standard_color(color);
    R_box_abs(left + 1, top + 1, right - 1, bottom - 1);

    /* draw box outline and text in black */
    R_standard_color(BLACK);
    Outline_box(top, bottom, left, right);
    dotext(text, top, bottom, left, right, centered);
    R_flush();

    box->top = top;
    box->bottom = bottom;
    box->left = left;
    box->right = right;

    return 0;
}
Пример #15
0
int Menu_msg(char *msg)
{
    int size, edge;

    size = VIEW_MENU->nrows - 4;
    edge = 2;

    Erase_view(VIEW_MENU);

    if (*msg) {
	R_text_size(size, size);
	R_standard_color(BLACK);
	Text(msg, VIEW_MENU->top, VIEW_MENU->bottom,
	     VIEW_MENU->left, VIEW_MENU->right, edge);
    }
    R_flush();
    replot = 1;

    return 0;
}
Пример #16
0
int Init_graphics(void)
{
    D_full_screen();


    SCREEN_TOP = R_screen_top();
    SCREEN_BOTTOM = R_screen_bot();
    SCREEN_LEFT = R_screen_left();
    SCREEN_RIGHT = R_screen_rite();


    BLACK = D_translate_color("black");
    BLUE = D_translate_color("blue");
    BROWN = D_translate_color("brown");
    GREEN = D_translate_color("green");
    GREY = D_translate_color("grey");
    ORANGE = D_translate_color("orange");
    PURPLE = D_translate_color("purple");
    RED = D_translate_color("red");
    WHITE = D_translate_color("white");
    YELLOW = D_translate_color("yellow");

    R_standard_color(WHITE);

    VIEW_TITLE1 = makeview(97.5, 100.0, 0.0, 50.0);
    VIEW_TITLE2 = makeview(97.5, 100.0, 50.0, 100.0);
    VIEW_MAP1 = makeview(51.0, 97.5, 0.0, 50.0);
    VIEW_MAP2 = makeview(51.0, 97.5, 50.0, 100.0);
    VIEW_TITLE1_ZOOM = makeview(47.5, 51.0, 0.0, 50.0);
    VIEW_TITLE2_ZOOM = makeview(47.5, 51.0, 50.0, 100.0);
    VIEW_MAP1_ZOOM = makeview(2.5, 47.5, 0.0, 50.0);
    VIEW_MAP2_ZOOM = makeview(2.5, 47.5, 50.0, 100.0);
    VIEW_MENU = makeview(0.0, 2.5, 0.0, 100.0);

    Rast_init_colors(&VIEW_MAP1->cell.colors);
    Rast_init_colors(&VIEW_MAP2->cell.colors);

    return 0;
}
Пример #17
0
int Init_graphics(void)
{
    R_font("romans");
    R_text_size(3 * NORMAL_TEXT_SIZE / 4, NORMAL_TEXT_SIZE);

    D_full_screen();

    SCREEN_TOP = R_screen_top();
    SCREEN_BOTTOM = R_screen_bot();
    SCREEN_LEFT = R_screen_left();
    SCREEN_RIGHT = R_screen_rite();


    BLACK = D_translate_color("black");
    BLUE = D_translate_color("blue");
    BROWN = D_translate_color("brown");
    GREEN = D_translate_color("green");
    GREY = D_translate_color("grey");
    ORANGE = D_translate_color("orange");
    PURPLE = D_translate_color("purple");
    RED = D_translate_color("red");
    WHITE = D_translate_color("white");
    YELLOW = D_translate_color("yellow");

    R_standard_color(BLACK);

    VIEW_TITLE1 = makeview(97.5, 100.0, 50.0, 100.0);
    VIEW_MAP1 = makeview(51.0, 97.5, 50.0, 100.0);
    VIEW_TITLE1_ZOOM = makeview(48.5, 51.0, 50.0, 100.0);
    VIEW_MAP1_ZOOM = makeview(2.5, 48.5, 50.0, 100.0);
    VIEW_MASK1 = makeview(51.0, 97.5, 50.0, 100.0);	/*same as map1 */
    VIEW_MENU = makeview(0.0, 2.5, 0.0, 100.0);
    VIEW_HISTO = makeview(2.5, 100.0, 0.0, 50.0);

    return 0;
}
Пример #18
0
static void change_draw(void)
{

    int method;
    double dtmp;

    G_system("clear");
    fprintf(stderr, "\n\n    CHOOSE THE COLOR FOR DRAWING:\n\n");
    fprintf(stderr, "       Red             1\n");
    fprintf(stderr, "       Orange          2\n");
    fprintf(stderr, "       Yellow          3\n");
    fprintf(stderr, "       Green           4\n");
    fprintf(stderr, "       Blue            5\n");
    fprintf(stderr, "       Indigo          6\n");
    fprintf(stderr, "       White           7\n");
    fprintf(stderr, "       Black           8\n");
    fprintf(stderr, "       Brown           9\n");
    fprintf(stderr, "       Magenta        10\n");
    fprintf(stderr, "       Aqua           11\n");
    fprintf(stderr, "       Gray           12\n\n");

    do {
	fprintf(stderr, "\n                             Which Number?   ");
	numtrap(1, &dtmp);
	if ((method = fabs(dtmp)) > 12 || method < 1) {
	    fprintf(stderr, "\n    Choice must between 1-12; try again");
	}
    }
    while (method > 12 || method < 1);

    if (method == 1)
	R_standard_color(D_translate_color("red"));
    else if (method == 2)
	R_standard_color(D_translate_color("orange"));
    else if (method == 3)
	R_standard_color(D_translate_color("yellow"));
    else if (method == 4)
	R_standard_color(D_translate_color("green"));
    else if (method == 5)
	R_standard_color(D_translate_color("blue"));
    else if (method == 6)
	R_standard_color(D_translate_color("indigo"));
    else if (method == 7)
	R_standard_color(D_translate_color("white"));
    else if (method == 8)
	R_standard_color(D_translate_color("black"));
    else if (method == 9)
	R_standard_color(D_translate_color("brown"));
    else if (method == 10)
	R_standard_color(D_translate_color("magenta"));
    else if (method == 11)
	R_standard_color(D_translate_color("aqua"));
    else if (method == 12)
	R_standard_color(D_translate_color("gray"));

    return;

}
Пример #19
0
int ask_magnification(int *magnification)
{
    static int use = 1;
    int x, y;
    int height;
    int stat;
    int width;
    int top, bottom, left, right;

    static Objects objects[] = {
	OTHER(incr, &use),
	{0}
    };

    Menu_msg("");

    mag = *magnification;
    if (mag < 1)
	mag = 1;

    height = VIEW_MENU->nrows;
    R_text_size(height - 4, height - 4);


    Get_mouse_xy(&x, &y);
    top = y - height / 2;
    if (top < SCREEN_TOP)
	top = SCREEN_TOP;
    bottom = top + 4 * height;
    if (bottom >= VIEW_MENU->top) {
	top -= bottom - (VIEW_MENU->top - 1);
	bottom = VIEW_MENU->top - 1;
    }
    width = Text_width("MAGNIFICATION") + 4;
    left = x - width / 2;
    if (left < SCREEN_LEFT)
	left = SCREEN_LEFT;
    right = left + width;
    if (right > SCREEN_RIGHT) {
	left -= right - SCREEN_RIGHT;
	right = SCREEN_RIGHT;
    }

    R_panel_save(tempfile1, top, bottom, left, right);
    R_standard_color(WHITE);
    R_box_abs(left, top, right, bottom);
    R_standard_color(BLACK);
    Outline_box(top, bottom, left, right);

    plus.top = top + height;
    plus.bottom = plus.top + height;
    plus.left = left;
    plus.right = plus.left + Text_width("++") + 4;
    Outline_box(plus.top, plus.bottom, plus.left, plus.right);

    minus.top = top + height;
    minus.bottom = minus.top + height;
    minus.right = right;
    minus.left = minus.right - Text_width("--") - 4;
    Outline_box(minus.top, minus.bottom, minus.left, minus.right);

    value.top = top + height;
    value.bottom = value.top + height;
    value.left = plus.right;
    value.right = minus.left;
    Outline_box(value.top, value.bottom, value.left, value.right);

    accept.top = value.bottom;
    accept.bottom = accept.top + height;
    accept.left = left;
    accept.right = right;
    Outline_box(accept.top, accept.bottom, accept.left, accept.right);

    cancel.top = accept.bottom;
    cancel.bottom = cancel.top + height;
    cancel.left = left;
    cancel.right = right;
    Outline_box(cancel.top, cancel.bottom, cancel.left, cancel.right);

    dotext("MAGNIFICATION", top, top + height, left, right, WHITE);
    dotext("+", plus.top, plus.bottom, plus.left, plus.right, GREY);
    dotext("-", minus.top, minus.bottom, minus.left, minus.right, GREY);
    dotext("ACCEPT", accept.top, accept.bottom, accept.left, accept.right,
	   GREY);
    dotext("CANCEL", cancel.top, cancel.bottom, cancel.left, cancel.right,
	   GREY);
    draw_mag();

    stat = Input_pointer(objects);

    /* to respond to user */
    R_standard_color(WHITE);
    R_box_abs(left, top, right, bottom);
    R_flush();

    R_panel_restore(tempfile1);
    R_panel_delete(tempfile1);

    *magnification = mag;
    return stat > 0;
}
Пример #20
0
static void set_frame(double *msc, int *t, int *b, int *l, int *r)
{
    int t0, b0, l0, r0, btn;

    /* record the initial boundaries of the map */

    t0 = *t;
    b0 = *b;
    l0 = *l;
    r0 = *r;

    /* if the total area to be sampled will be the
       whole map */

    G_system("clear");

    if (G_yes
	("\n    Will the sampling frame (total area within which sampling\n      units are distributed) be the whole map?   ",
	 1)) {
	R_open_driver();
	R_standard_color(D_translate_color("grey"));
	draw_box(*l, *t, *r, *b, 1);
	R_close_driver();
	fprintf(stderr, "\n    Sampling frame set to whole map");
    }

    /* if the total area to be sampled is not the
       whole map, then have the user draw the
       area */

    else {
      back:
	G_system("clear");
	fprintf(stderr, " \n    OUTLINE SAMPLING FRAME:\n");
	R_open_driver();
	fprintf(stderr,
		"\n    Please move cursor to the UPPER-LEFT corner of\n");
	fprintf(stderr,
		"       the sampling frame and click any mouse button\n");
	R_get_location_with_line(0, 0, l, t, &btn);

	fprintf(stderr,
		"\n    Please move cursor to the LOWER-RIGHT corner of\n");
	fprintf(stderr,
		"       the sampling frame and click any mouse button again\n");
      back2:
	R_get_location_with_box(*l, *t, r, b, &btn);

	/* check that sampling frame is in map */

	if (*l < l0 || *r > r0 || *t < t0 || *b > b0) {
	    fprintf(stderr,
		    "\n    The cursor is outside of the map, try again\n");
	    goto back;
	}

	/* check that cursor is below & to right */

	if (*r <= *l || *b <= *t) {
	    fprintf(stderr,
		    "\n    Please put the lower right corner below and to the");
	    fprintf(stderr, "\n    right of the upper left corner\n");
	    goto back2;
	}

	R_standard_color(D_translate_color("grey"));
	*l = (int)((double)((int)(*l * msc[0] + 0.5)) / msc[0]);
	*r = (int)((double)((int)(*r * msc[0] + 0.5)) / msc[0]);
	*t = (int)((double)((int)(*t * msc[1] + 0.5)) / msc[1]);
	*b = (int)((double)((int)(*b * msc[1] + 0.5)) / msc[1]);
	draw_box(*l, *t, *r, *b, 1);
	R_close_driver();
	fprintf(stderr,
		"\n    Sampling frame is set to the area you just drew");
    }
    return;
}
Пример #21
0
static int zoom1(int x, int y)
{				/* called by Input_pointer */
    int top, bottom, left, right;
    int n, row, col;
    int nrows, ncols;
    struct Cell_head cellhd;
    int mag;
    double magnification();
    double north, south, east, west;

    if (In_view(pick_view = VIEW_MAP1, x, y)) {
	main_view = VIEW_MAP1;
	zoom_view = VIEW_MAP1_ZOOM;
	target_flag = 0;
    }
    else if (In_view(pick_view = VIEW_MAP2, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP2;
	zoom_view = VIEW_MAP2_ZOOM;
	target_flag = 1;
    }
    else if (In_view(pick_view = VIEW_MAP1_ZOOM, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP1;
	zoom_view = VIEW_MAP1_ZOOM;
	target_flag = 0;
    }
    else if (In_view(pick_view = VIEW_MAP2_ZOOM, x, y)) {
	if (!pick_view->cell.configured)
	    return 0;		/* ignore the mouse event */
	main_view = VIEW_MAP2;
	zoom_view = VIEW_MAP2_ZOOM;
	target_flag = 1;
    }
    else
	return 0;		/* ignore the mouse event */
    if (!pick_view->cell.configured)
	return 0;		/* just to be sure */
    /*
     * make sure point is within edges of image as well
     */
    if (x <= pick_view->cell.left)
	return 0;
    if (x >= pick_view->cell.right)
	return 0;
    if (y <= pick_view->cell.top)
	return 0;
    if (y >= pick_view->cell.bottom)
	return 0;


    /*
     * ok, erase menu messages
     */
    Menu_msg("");

    /* determine magnification of zoom */
    if (zoom_view->cell.configured) {
	if (zoom_view == pick_view)
	    mag = floor(magnification(zoom_view) + 1.0) + .1;
	else
	    mag = ceil(magnification(zoom_view)) + .1;
    }
    else {
	mag = floor(magnification(main_view) + 1.0) + .1;
    }
    if (!ask_magnification(&mag))
	return 1;
    /* 
     * Determine the the zoom window (ie, cellhd)
     */

    G_copy(&cellhd, &main_view->cell.head, sizeof(cellhd));
    cellhd.ns_res = main_view->cell.ns_res / mag;
    cellhd.ew_res = main_view->cell.ew_res / mag;
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;
    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;


    /* convert x,y to col,row */

    col = view_to_col(pick_view, x);
    east = col_to_easting(&pick_view->cell.head, col, 0.5);
    col = easting_to_col(&cellhd, east);

    row = view_to_row(pick_view, y);
    north = row_to_northing(&pick_view->cell.head, row, 0.5);
    row = northing_to_row(&cellhd, north);

    ncols = zoom_view->ncols;
    nrows = zoom_view->nrows;


    n = cellhd.cols - col;
    if (n > col)
	n = col;
    if (n + n + 1 >= ncols) {
	n = ncols / 2;
	if (n + n + 1 >= ncols)
	    n--;
    }
    left = col - n;
    right = col + n;

    n = cellhd.rows - row;
    if (n > row)
	n = row;
    if (n + n + 1 >= nrows) {
	n = nrows / 2;
	if (n + n + 1 >= nrows)
	    n--;
    }
    top = row - n;
    bottom = row + n;


    north = row_to_northing(&cellhd, top, 0.0);
    west = col_to_easting(&cellhd, left, 0.0);
    south = row_to_northing(&cellhd, bottom, 1.0);
    east = col_to_easting(&cellhd, right, 1.0);


    cellhd.north = north;
    cellhd.south = south;
    cellhd.east = east;
    cellhd.west = west;

    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;

    /*
     * Outline the zoom window on the main map
     * Turn previous one to grey.
     */
    if (zoom_view->cell.configured) {
	R_standard_color(GREY);
	Outline_cellhd(main_view, &zoom_view->cell.head);
    }
    R_standard_color(RED);
    Outline_cellhd(main_view, &cellhd);


    /*
     * zoom
     */
    if (target_flag)
	select_target_env();
    G_copy(&zoom_view->cell.head, &cellhd, sizeof(cellhd));
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
		   pick_view->cell.ns_res, pick_view->cell.ew_res);
    drawcell(zoom_view);
    select_current_env();
    display_points(1);

    return 1;			/* pop back */
}
Пример #22
0
/* FOR STRATIFIED RANDOM DISTRIBUTION, DRAW THE STRATA ON THE SCREEN */
static void draw_grid(int l, int t, int w_w, int w_l, int h_d, int v_d,
		      int starty, int startx, double colratio,
		      double rowratio)
{
    int j, k, l0, t0, itmp, dx, dy, initl, tmp;

    /* VARIABLES:
       k    = the remainder after dividing the screen width/height
       by the number of strata
       dx   = how many screen cols per stratum
       dy   = how many screen rows per stratum
       l0   = left side of screen + dx
       t0   = top of screen + dy
       w_w  = width of screen
       w_l  = height of screen
       h_d  = number of horizontal strata
       v_d  = number of vertical strata
     */

    R_open_driver();
    R_standard_color(D_translate_color("orange"));
    if (startx > 0) {
	dx = (int)((double)((int)(colratio *
				  ((int)
				   ((double)(w_w - startx) /
				    (double)(h_d)))) / colratio + 0.5));
	l0 = l + startx;
    }
    else {
	dx = (int)((double)((int)(colratio *
				  ((int)((double)(w_w) / (double)(h_d)))) /
			    colratio + 0.5));
	l0 = l;
    }
    if (starty > 0) {
	dy = (int)((double)((int)(rowratio *
				  ((int)
				   ((double)(w_l - starty) /
				    (double)(v_d)))) / rowratio + 0.5));

	t0 = t + starty;
    }
    else {
	dy = (int)((double)((int)(rowratio *
				  ((int)((double)(w_l) / (double)(v_d)))) /
			    rowratio + 0.5));
	t0 = t;
    }
    initl = l0;

    /* draw the vertical strata */

    for (j = 1; j <= h_d - 1; j++) {
	l0 += dx;
	R_move_abs(l0, t0);
	R_cont_rel(0, w_l - starty);
    }

    /* draw the horizontal strata */

    for (j = 1; j <= v_d - 1; j++) {
	t0 += dy;
	R_move_abs(initl, t0);
	R_cont_rel(w_w - startx, 0);
    }

    R_close_driver();
    return;
}
Пример #23
0
/* CALCULATE THE COORDINATES OF THE TOP LEFT CORNER OF THE SAMPLING UNITS */
static int calc_unit_loc(double radius, int top, int bot, int left, int right,
			 double ratio, int u_w, int u_l, int method,
			 double intv, int num, int h_d, int v_d, double *ux,
			 double *uy, int *sites, double startx, int starty,
			 int fmask, double nx, double x, double y)
{
    char *sites_mapset, sites_file_name[GNAME_MAX], *cmd;
    struct Map_info Map;
    struct Cell_head region;
    double D_u_to_a_col(), D_u_to_a_row();
    int i, j, k, cnt = 0, w_w = right - left, w_l = bot - top, exp1, exp2,
	dx = w_w, dy = w_l, l, t, left1 = left, top1 = top, n, tmp,
	ulrow, ulcol, *row_buf, lap = 0;
    static struct line_pnts *Points;
    struct line_cats *Cats;
    int ltype;

    /*   VARIABLES:
       UNITS FOR ALL DIMENSION VARIABLES IN THIS ROUTINE ARE IN PIXELS

       top  =       sampling frame top row in pixels
       bot  =       sampling frame bottom row in pixels
       left =       sampling frame left in pixels
       right        =       sampling frame right in pixels
       left1        =       col of left side of sampling frame or each stratum
       top1 =       row of top side of sampling frame or each stratum
       l    =       random # cols to be added to left1
       r    =       random # rows to be added to top1
       ratio        =
       u_w  =       sampling unit width in pixels
       u_l  =       sampling unit length in pixels
       method       =       method of sampling unit distribution (1-5)
       intv =       interval between sampling units when method=3
       num  =       number of sampling units
       h_d  =       number of horizontal strata
       v_d  =       number of vertical strata
       ux   =
       uy   =
       sites        =
       startx       =       col of UL corner starting pt for strata
       starty       =       row of UL corner starting pt for strata
       dx   =       number of cols per stratum
       dy   =       number of rows per stratum
       w_w  =       width of sampling frame in cols
       w_l  =       length of sampling frame in rows
     */


    /* if user hits Ctrl+C, abort this
       calculation */

    setjmp(jmp);
    if (tag) {
	tag = 0;
	return 0;
    }

    /* for syst. noncontig. distribution */

    if (method == 3) {
	u_w += intv;
	u_l += intv;
    }

    /* for stratified random distribution */

    if (method == 4) {
	dx = (int)((double)(w_w - startx) / (double)(h_d));
	dy = (int)((double)(w_l - starty) / (double)(v_d));
    }

    /* for syst. contig. and noncontig.
       distribution */

    else if (method == 2 || method == 3) {
	if (nx >= num)
	    dx = (w_w - startx) - (num - 1) * u_w;
	else {
	    dx = (w_w - startx) - (nx - 1) * u_w;
	    dy = (w_l - starty) - (num / nx - 1) * u_l;
	}
    }

    if (10 > (exp1 = (int)pow(10.0, ceil(log10((double)(dx - u_w + 10))))))
	exp1 = 10;
    if (10 > (exp2 = (int)pow(10.0, ceil(log10((double)(dy - u_l + 10))))))
	exp2 = 10;

    /* for random nonoverlapping and stratified
       random */

    if (method == 1 || method == 4) {

	fprintf(stderr,
		"\n   'Ctrl+C' and choose fewer units if the requested number");
	fprintf(stderr, " is not reached\n");


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

	    /* if Cntl+C */

	    if (signal(SIGINT, SIG_IGN) != SIG_IGN)
		signal(SIGINT, f);

	    /* for stratified random distribution */

	    if (method == 4) {
		j = 0;
		if (n = i % h_d)
		    left1 += dx;
		else {
		    left1 = left + startx;
		    if (i < h_d)
			top1 = top + starty;
		    else
			top1 += dy;
		}
		get_rd(exp1, exp2, dx, dy, u_w, u_l, &l, &t);

	    }

	    /* for random nonoverlapping distribution */

	    if (method == 1) {

		/* get random numbers */
	      back:
		get_rd(exp1, exp2, dx, dy, u_w, u_l, &l, &t);

		if (left1 + l + u_w > right || top1 + t + u_l > bot ||
		    left1 + l < left || top1 + t < top)
		    goto back;

		/* if there is a mask, check to see that
		   the unit will be within the mask area */

		if (fmask > 0) {
		    row_buf = Rast_allocate_c_buf();
		    Rast_get_c_row_nomask(fmask, row_buf, t + top1);
		    if (!
			(*(row_buf + l + left1) &&
			 *(row_buf + l + left1 + u_w - 1)))
			goto back;
		    Rast_zero_c_buf(row_buf);
		    Rast_get_c_row_nomask(fmask, row_buf, t + top1 + u_l - 1);
		    if (!
			(*(row_buf + l + left1) &&
			 *(row_buf + l + left1 + u_w - 1)))
			goto back;
		    G_free(row_buf);
		}

		/* check for sampling unit overlap */

		lap = 0;
		for (j = 0; j < cnt; j++) {
		    if (overlap
			(l + left1, t + top1, (int)ux[j], (int)uy[j], u_w,
			 u_l))
			lap = 1;
		}
		if (lap)
		    goto back;

		cnt++;
	    }
	    /* fill the array of upper left coordinates
	       for the sampling units */

	    *(ux + i) = l + left1;
	    *(uy + i) = t + top1;

	    /* draw the sampling units on the
	       screen */

	    R_open_driver();
	    R_standard_color(D_translate_color("red"));
	    if (radius)
		draw_circle((int)((double)(ux[i]) / x),
			    (int)((double)(uy[i]) / y),
			    (int)((double)(ux[i] + u_w) / x),
			    (int)((double)(uy[i] + u_l) / y), 3);
	    else
		draw_box((int)((double)(ux[i]) / x),
			 (int)((double)(uy[i]) / y),
			 (int)((double)(ux[i] + u_w) / x),
			 (int)((double)(uy[i] + u_l) / y), 1);
	    R_close_driver();
	    fprintf(stderr, "    Distributed unit %4d of %4d requested\r",
		    i + 1, num);

	}
    }

    /* for syst. contig. & syst. noncontig. */

    else if (method == 2 || method == 3) {
	for (i = 0; i < num; i++) {
	    *(ux + i) =
		left + startx + u_w * (i - nx * floor((double)i / nx));
	    *(uy + i) = top + starty + u_l * floor((double)i / nx);
	}
    }

    /* for centered over sites */

    else if (method == 5) {
	sites_mapset =
	    G_ask_vector_old("    Enter name of vector points map",
			     sites_file_name);
	if (sites_mapset == NULL) {
	    G_system("d.frame -e");
	    exit(0);
	}

	if (Vect_open_old(&Map, sites_file_name, sites_mapset) < 0)
	    G_fatal_error(_("Unable to open vector map <%s>"), sites_file_name);
	/*    fprintf(stderr, "\n    Can't open vector points file %s\n", sites_file_name); */

	*sites = 0;
	i = 0;
	n = 0;

	Points = Vect_new_line_struct();	/* init line_pnts struct */
	Cats = Vect_new_cats_struct();

	while (1) {
	    ltype = Vect_read_next_line(&Map, Points, Cats);
	    if (ltype == -1)
		G_fatal_error(_("Cannot read vector"));
	    if (ltype == -2)
		break;		/* EOF */
	    /* point features only. (GV_POINTS is pts AND centroids, GV_POINT is just pts) */
	    if (!(ltype & GV_POINT))
		continue;

	    ulcol = ((int)(D_u_to_a_col(Points->x[0]))) + 1 - u_w / 2;
	    ulrow = ((int)(D_u_to_a_row(Points->y[0]))) + 1 - u_l / 2;
	    if (ulcol <= left || ulrow <= top || ulcol + u_w - 1 > right ||
		ulrow + u_l - 1 > bot) {
		fprintf(stderr,
			"    No sampling unit over site %d at east=%8.1f north=%8.1f\n",
			n + 1, Points->x[0], Points->y[0]);
		fprintf(stderr,
			"       as it would extend outside the map\n");

	    }
	    else {
		*(ux + i) = ulcol - 1;
		*(uy + i) = ulrow - 1;
		i++;
	    }
	    n++;
	    if (n > 250)
		G_fatal_error
		    ("There are more than the maximum of 250 sites\n");
	}
	fprintf(stderr, "    Total sites with sampling units = %d\n", i);

	*sites = i;
	cmd = G_malloc(100);
	sprintf(cmd, "d.vect %s color=black", sites_file_name);
	G_system(cmd);
	G_free(cmd);

	Vect_close(&Map);
	G_free(Points);
	G_free(Cats);

    }

    return 1;

}
Пример #24
0
static void graph_unit(int t, int b, int l, int r, char *n1, char *n2,
		       char *n3, double *mx, int fmask)
{
    int x0 = 0, y0 = 0, xp, yp, ux[250], uy[250], u_w, u_l, btn = 0, k = 0,
	w_w = 0, w_l = 0, *row_buf, at, ab, al, ar, circle = 0,
	tmpw, tmpl, au_w, au_l, lap = 0, l0 = 0, r0 = 0, t0 = 0, b0 = 0;
    FILE *fp;
    double tmp, radius = 0.0;
    register int i, j;

    /*  VARIABLES:
       COORDINATES IN THIS ROUTINE ARE IN CELLS

       t    =       top row of sampling frame
       b    =       bottom row of sampling frame
       l    =       left col of sampling frame
       r    =       right col of sampling frame
       n1   =
       n2   =
       n3   =
       mx[0]        =       cols of region/width of screen
       mx[1]        =       rows of region/height of screen
       xp   =       mouse x location in screen coordinates (col)
       yp   =       mouse y location in screen coordinates (row)
       ar   =       mouse x location in map coordinates (col)
       al   =       mouse y location in map coordinates (row)

     */


    l0 = l;
    r0 = r;
    t0 = t;
    b0 = b;

    l = (int)((double)(l * mx[0]) + 0.5);
    r = (int)((double)(r * mx[0]) + 0.5);
    t = (int)((double)(t * mx[1]) + 0.5);
    b = (int)((double)(b * mx[1]) + 0.5);
    w_w = r - l;
    w_l = b - t;

    /* draw the sampling frame */

    R_open_driver();
    R_standard_color(D_translate_color("grey"));
    draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]),
	     (int)(b / mx[1]), 1);
    R_close_driver();

    fp = fopen0("r.le.para/units", "w");
    G_sleep_on_error(0);

    /* get the number of scales */

    do {
	fprintf(stderr,
		"\n    How many different SCALES do you want? (1-15)  ");

	numtrap(1, &tmp);
	if (tmp < 1 || tmp > 15)
	    fprintf(stderr,
		    "    Too many (>15) or too few scales, try again.\n");
    }
    while (tmp < 1 || tmp > 15);
    fprintf(fp, "%10d    # of scales\n", (int)(tmp));

    /* for each scale */

    for (i = 0; i < tmp; i++) {
	G_system("clear");

	radius = 0.0;
	circle = 0;

	/* if sampling using circles */

	fprintf(stderr, "\n    SCALE %d\n", i + 1);
	fprintf(stderr, "\n    Do you want to sample using rectangles");

	if (!G_yes("\n       (including squares) (y) or circles (n)?   ", 1)) {
	    circle = 1;
	    fprintf(stderr,
		    "\n    Draw a rectangular area to contain a standard circular");
	    fprintf(stderr,
		    "\n    sampling unit of scale %d.  First select upper left",
		    i + 1);
	    fprintf(stderr, "\n    corner, then lower right:\n");
	    fprintf(stderr, "       Left button:     Check unit size\n");
	    fprintf(stderr,
		    "       Middle button:   Upper left corner of area here\n");
	    fprintf(stderr,
		    "       Right button:    Lower right corner of area here\n");

	}

	else {
	    fprintf(stderr,
		    "\n    Draw a standard rectangular unit of scale %d.",
		    i + 1);
	    fprintf(stderr,
		    "\n    First select upper left corner, then lower right:\n");
	    fprintf(stderr, "       Left button:     Check unit size\n");
	    fprintf(stderr,
		    "       Middle button:   Upper left corner of unit here\n");
	    fprintf(stderr,
		    "       Right button:    Lower right corner of unit here\n");

	}

	R_open_driver();

	do {
	  back1:
	    R_get_location_with_box(x0, y0, &xp, &yp, &btn);

	    /* convert the upper left screen coordinate
	       (x0, y0) and the mouse position (xp, yp)
	       on the screen to the nearest row and
	       column; do the same for the sampling
	       unit width (u_w) and height (u_l);
	       then convert back */

	    ar = (int)((double)(xp) * mx[0] + 0.5);
	    xp = (int)((double)(ar) / mx[0] + 0.5);
	    al = (int)((double)(x0) * mx[0] + 0.5);
	    x0 = (int)((double)(al) / mx[0] + 0.5);
	    au_w = ar - al;
	    u_w = (int)((double)(au_w) / mx[0] + 0.5);
	    ab = (int)((double)(yp) * mx[1] + 0.5);
	    yp = (int)((double)(ab) / mx[1] + 0.5);
	    at = (int)((double)(y0) * mx[1] + 0.5);
	    y0 = (int)((double)(at) / mx[1] + 0.5);
	    au_l = ab - at;
	    u_l = (int)((double)(au_l) / mx[1] + 0.5);


	    /* left button, check the size of the rubber
	       box in array system */

	    if (btn == 1) {
		if (ar > r || ab > b || ar < l || ab < t) {
		    fprintf(stderr,
			    "\n    This point is not in the sampling frame; try again\n");

		    goto back1;
		}
		if (x0 < l || y0 < t) {
		    fprintf(stderr,
			    "\n    Use the middle button to first put the upper left");
		    fprintf(stderr,
			    "\n    corner inside the sampling frame\n");

		    goto back1;
		}
		if (ar <= al || ab <= at) {
		    fprintf(stderr,
			    "\n    Please put the lower right corner down and to");
		    fprintf(stderr,
			    "\n    the right of the upper left corner\n");

		    goto back1;
		}
		else {
		    fprintf(stderr,
			    "\n    Unit would be %d columns wide by %d rows long\n",
			    abs(au_w), abs(au_l));
		    fprintf(stderr,
			    "    Width/length would be %5.2f and size %d pixels\n",
			    (double)abs((au_w)) / (double)abs((au_l)),
			    abs(au_w) * abs(au_l));

		}
	    }

	    /* mid button, move the start point of the
	       rubber box */

	    else if (btn == 2) {
		if (ar > r || ab > b || ar < l || ab < t) {
		    fprintf(stderr,
			    "\n    Point is not in the sampling frame; try again\n");

		    goto back1;
		}
		else {
		    R_move_abs(xp, yp);
		    x0 = xp;
		    y0 = yp;
		}
	    }

	    /* right button, outline the unit */

	    else if (btn == 3) {

		if (circle) {
		    if (u_w > u_l) {
			al = al + ((ar - al) - (ab - at)) / 2;
			ar = al + (ab - at);
			x0 = (int)((double)(al) / mx[0] + 0.5);
			xp = (int)((double)(ar) / mx[0] + 0.5);
			au_w = ar - al;
			u_w = u_l = (int)((double)(au_w) / mx[0] + 0.5);
		    }
		    if (u_l > u_w) {
			at = at + ((ab - at) - (ar - al)) / 2;
			ab = at + (ar - al);
			y0 = (int)((double)(at) / mx[1] + 0.5);
			yp = (int)((double)(ab) / mx[1] + 0.5);
			au_l = ab - at;
			u_w = u_l = (int)((double)(au_l) / mx[1] + 0.5);
		    }
		}

		if (ar > r || ab > b || al < l || at < t) {
		    fprintf(stderr,
			    "\n    The unit extends outside the sampling frame or map;");
		    fprintf(stderr, "\n       try again\n");

		    goto back1;
		}

		if (au_w > w_w || au_l > w_l) {
		    fprintf(stderr,
			    "\n    The unit is too big for the sampling frame; ");
		    fprintf(stderr, "try again\n");

		    goto back1;
		}

		/* if there is a mask, check to see that
		   the unit will be within the mask area,
		   by checking to see whether the four
		   corners of the unit are in the mask */

		if (fmask > 0) {
		    row_buf = Rast_allocate_c_buf();
		    Rast_get_c_row_nomask(fmask, row_buf, at);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again\n");

			G_free(row_buf);
			goto back1;
		    }
		    Rast_zero_c_buf(row_buf);
		    Rast_get_c_row_nomask(fmask, row_buf, ab - 1);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again\n");

			G_free(row_buf);
			goto back1;
		    }
		    G_free(row_buf);
		}

		if (xp - x0 > 0 && yp - y0 > 0) {
		    R_standard_color(D_translate_color("red"));
		    if (circle)
			draw_circle(x0, y0, xp, yp, 3);
		    else
			draw_box(x0, y0, xp, yp, 1);
		    G_system("clear");
		    if (circle) {
			fprintf(stderr,
				"\n\n    The standard circular sampling unit has:\n");
			fprintf(stderr, "       radius = %f pixels\n",
				(double)(ar - al) / 2.0);

		    }
		    else {
			fprintf(stderr,
				"\n\n    The standard sampling unit has:\n");
			fprintf(stderr, "       columns=%d    rows=%d\n",
				abs(ar - al), abs(ab - at));
			fprintf(stderr, "       width/length ratio=%5.2f\n",
				(double)abs(ar - al) / (double)abs(ab - at));
			fprintf(stderr, "       size=%d pixels\n",
				abs(ar - al) * abs(ab - at));

		    }
		    k = 0;
		    ux[0] = al;
		    uy[0] = at;
		}
		else if (xp - x0 == 0 || yp - y0 == 0) {
		    fprintf(stderr,
			    "\n    Unit has 0 rows and/or 0 columns; try again\n");

		    goto back1;
		}
		else {
		    fprintf(stderr,
			    "\n    You did not put the lower right corner below");
		    fprintf(stderr,
			    "\n       and to the right of the upper left corner. Please try again");

		    goto back1;
		}
	    }
	}
	while (btn != 3);
	R_close_driver();

	/* use the size and shape of the
	   standard unit to outline more units
	   in that scale */

	fprintf(stderr, "\n    Outline more sampling units of scale %d?\n",
		i + 1);
	fprintf(stderr, "       Left button:     Exit\n");
	fprintf(stderr, "       Middle button:   Check unit position\n");
	fprintf(stderr,
		"       Right button:    Lower right corner of next unit here\n");

	R_open_driver();

	/* if not the left button (to exit) */

      back2:
	while (btn != 1) {
	    R_get_location_with_box(xp - u_w, yp - u_l, &xp, &yp, &btn);

	    /* convert the left (x0), right (y0),
	       top (y0), bottom (yp) coordinates in
	       screen pixels to the nearest row and
	       column; do the same for the sampling
	       unit width (u_w) and height (u_l);
	       then convert back */

	    ar = (int)((double)(xp) * mx[0] + 0.5);
	    ab = (int)((double)(yp) * mx[1] + 0.5);
	    xp = (int)((double)(ar) / mx[0] + 0.5);
	    yp = (int)((double)(ab) / mx[1] + 0.5);
	    al = (int)((double)(xp - u_w) * mx[0] + 0.5);
	    at = (int)((double)(yp - u_l) * mx[0] + 0.5);
	    x0 = (int)((double)(al) / mx[0] + 0.5);
	    y0 = (int)((double)(at) / mx[1] + 0.5);


	    /* if right button, outline the unit */

	    if (btn == 3) {

		if (ar > r || ab > b || al < l || at < t) {
		    fprintf(stderr,
			    "\n    The unit would be outside the map; try again");
		    goto back2;

		}

		/* if there is a mask, check to see that
		   the unit will be within the mask area */

		if (fmask > 0) {
		    row_buf = Rast_allocate_c_buf();
		    Rast_get_c_row_nomask(fmask, row_buf, at);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again");

			G_free(row_buf);
			goto back2;
		    }
		    Rast_zero_c_buf(row_buf);
		    Rast_get_c_row_nomask(fmask, row_buf, ab - 1);
		    if (!(*(row_buf + al) && *(row_buf + ar - 1))) {
			fprintf(stderr,
				"\n    The unit would be outside the mask; ");
			fprintf(stderr, "try again");
			G_free(row_buf);
			goto back2;
		    }
		    G_free(row_buf);
		}

		/* check for sampling unit overlap */

		lap = 0;
		for (j = 0; j < k + 1; j++) {
		    if (overlap(al, at, ux[j], uy[j], au_w, au_l)) {
			fprintf(stderr,
				"\n    The unit would overlap a previously drawn ");
			fprintf(stderr, "unit; try again");

			lap = 1;
		    }
		}
		if (lap)
		    goto back2;

		k++;
		fprintf(stderr, "\n    %d sampling units have been placed",
			(k + 1));

		ux[k] = al;
		uy[k] = at;
		R_standard_color(D_translate_color("red"));
		if (circle)
		    draw_circle(x0, y0, xp, yp, 3);
		else
		    draw_box(x0, y0, xp, yp, 1);
	    }
	}
	R_close_driver();

	/* save the sampling units in the
	   r.le.para/units file */

	if (circle)
	    radius = (double)(ar - al) / 2.0;
	else
	    radius = 0.0;
	fprintf(fp, "%10d    # of units of scale %d\n", k + 1, i + 1);
	fprintf(fp, "%10d%10d   u_w, u_l of units in scale %d\n",
		(int)(u_w * mx[0]), (int)(u_l * mx[1]), i + 1);
	fprintf(fp, "%10.1f             radius of circles in scale %d\n",
		radius, (i + 1));
	for (j = 0; j < k + 1; j++)
	    fprintf(fp, "%10d%10d   left, top of unit[%d]\n", ux[j], uy[j],
		    j + 1);

	if (i < tmp - 1 && G_yes("\n    Refresh the screen?   ", 1)) {
	    paint_map(n1, n2, n3);
	    R_open_driver();
	    R_standard_color(D_translate_color("red"));
	    R_close_driver();
	}
    }

    fclose(fp);
    return;
}
Пример #25
0
/* DEFINE SAMPLING UNITS MANUALLY */
static void man_unit(int t, int b, int l, int r, char *n1, char *n2, char *n3,
		     double *mx, int fmask)
{
    int i, j, dx, dy, w_w, w_l, u_w, u_l,
	method, l0, t0, randflag = 0, unit_num, num = 0, scales,
	h_d = 1, v_d = 1, itmp, thick, sites, *row_buf, fr, k,
	count = 0, maxsize = 0, nx = 0, ny = 0, numx = 0, numy = 0,
	al = 0, ar = 0, at = 0, ab = 0, au_w = 0, au_l = 0;
    double *ux, *uy;
    FILE *fp;
    double dtmp, ratio, size, intv = 0.0, start[2], cnt = 0, radius = 0.0;
    char *sites_mapset;
    struct Cell_head wind;

    /*  VARIABLES:
       COORDINATES IN THIS ROUTINE ARE IN CELLS

       t    =       top row of sampling frame
       b    =       bottom row of sampling frame
       l    =       left col of sampling frame
       r    =       right col of sampling frame
       n1   =
       n2   =
       n3   =
       start[0]=    row of UL corner of starting pt for strata
       start[1]=    col of UL corner of starting pt for strata
       mx[0]        =       cols of region/width of screen
       mx[1]        =       rows of region/height of screen

     */


    start[0] = 0.0;
    start[1] = 0.0;

    l = (int)((double)(l * mx[0]) + 0.5);
    r = (int)((double)(r * mx[0]) + 0.5);
    t = (int)((double)(t * mx[1]) + 0.5);
    b = (int)((double)(b * mx[1]) + 0.5);
    w_w = r - l;
    w_l = b - t;

    /* draw the sampling frame */

    R_open_driver();
    R_standard_color(D_translate_color("grey"));
    draw_box((int)(l / mx[0] + 0.5), (int)(t / mx[1] + 0.5),
	     (int)(r / mx[0] + 0.5), (int)(b / mx[1] + 0.5), 1);
    R_close_driver();

    /* open the units file for output */

    fp = fopen0("r.le.para/units", "w");
    G_sleep_on_error(0);

    /* get the number of scales */

    do {
	fprintf(stderr,
		"\n    How many different SCALES do you want (1-15)?   ");

	numtrap(1, &dtmp);
	if (dtmp > 15 || dtmp < 1) {
	    fprintf(stderr,
		    "\n    Too many (>15) or too few scales; try again");

	}
    }
    while (dtmp < 1 || dtmp > 15);

    fprintf(fp, "%10d    # of scales\n", (scales = (int)dtmp));


    /* for each scale */

    for (i = 0; i < scales; i++) {
	for (;;) {
	    G_system("clear");

	    radius = 0.0;

	    fprintf(stderr, "\n\n    TYPE IN PARAMETERS FOR SCALE %d:\n",
		    i + 1);


	    /* get the distribution method */

	    fprintf(stderr,
		    "\n    Choose method of sampling unit DISTRIBUTION  \n");
	    fprintf(stderr, "       Random nonoverlapping       1\n");
	    fprintf(stderr, "       Systematic contiguous       2\n");
	    fprintf(stderr, "       Systematic noncontiguous    3\n");
	    fprintf(stderr, "       Stratified random           4\n");
	    fprintf(stderr, "       Centered over sites         5\n");
	    fprintf(stderr, "       Exit to setup option menu   6\n\n");

	    do {
		fprintf(stderr, "                       Which Number?   ");

		numtrap(1, &dtmp);
		if ((method = fabs(dtmp)) > 6 || method < 1) {
		    fprintf(stderr,
			    "\n    Choice must between 1-5; try again");

		}
	    }
	    while (method > 6 || method < 1);

	    if (method == 6)
		return;

	    /* for stratified random distribution,
	       determine the number of strata */

	    if (method == 4) {
	      getstrata:
		fprintf(stderr,
			"\n    Number of strata along the x-axis? (1-60)  ");

		numtrap(1, &dtmp);
		h_d = fabs(dtmp);

		fprintf(stderr,
			"\n    Number of strata along the y-axis? (1-60)  ");

		numtrap(1, &dtmp);
		v_d = fabs(dtmp);

		if (h_d < 1 || v_d < 1 || h_d > 60 || v_d > 60) {
		    fprintf(stderr,
			    "\n    Number must be between 1-60; try again.");

		    goto getstrata;
		}
	    }

	    /* for methods with strata */

	    if (method == 2 || method == 3 || method == 4) {
	      strata:
		fprintf(stderr,
			"\n    Sampling frame row & col for upper left corner of");
		fprintf(stderr,
			" the strata?\n       Rows are numbered down and columns");
		fprintf(stderr,
			" are numbered to the right\n       Enter 1 1 to start in");
		fprintf(stderr, " upper left corner of sampling frame:  ");

		numtrap(2, start);
		start[0] = start[0] - 1.0;
		start[1] = start[1] - 1.0;
		if (start[0] > w_l || start[0] < 0 ||
		    start[1] > w_w || start[1] < 0) {
		    fprintf(stderr,
			    "\n    The starting row and col you entered are outside");
		    fprintf(stderr,
			    " the sampling frame\n       Try again\n");

		    goto strata;
		}
	    }


	    if (method == 4) {

		/* call draw_grid with the left, top, width,
		   length, the number of horizontal and
		   vertical strata, and the starting row
		   and col for the strata */

		draw_grid((int)(l / mx[0] + 0.5), (int)(t / mx[1] + 0.5),
			  (int)(w_w / mx[0] + 0.5), (int)(w_l / mx[1] + 0.5),
			  h_d, v_d, (int)(start[0] / mx[1] + 0.5),
			  (int)(start[1] / mx[0] + 0.5), mx[0], mx[1]);
		if (!G_yes("    Are these strata OK?   ", 1)) {
		    if (G_yes("\n\n    Refresh the screen?   ", 1)) {
			paint_map(n1, n2, n3);
			R_open_driver();
			R_standard_color(D_translate_color("grey"));
			draw_box((int)(l / mx[0] + 0.5),
				 (int)(t / mx[1] + 0.5),
				 (int)(r / mx[0] + 0.5),
				 (int)(b / mx[1] + 0.5), 1);
			R_close_driver();
		    }
		    goto getstrata;
		}
	    }

	    /* if sampling using circles */

	    fprintf(stderr, "\n    Do you want to sample using rectangles");

	    if (!G_yes
		("\n       (including squares) (y) or circles (n)?   ", 1)) {
	      getradius:
		fprintf(stderr,
			"\n    What radius do you want for the circles?  Radius");
		fprintf(stderr,
			"\n       is in pixels; add 0.5 pixels, for the center");
		fprintf(stderr,
			"\n       pixel, to the number of pixels outside the");
		fprintf(stderr,
			"\n       center pixel.  Type a real number with one");
		fprintf(stderr,
			"\n       decimal place ending in .5 (e.g., 4.5):        ");

		numtrap(1, &radius);
		if (radius > 100.0) {
		    fprintf(stderr,
			    "\n    Are you sure that you want such a large");

		    if (!G_yes("\n       radius (> 100 pixels)?   ", 1))
			goto getradius;
		}

		ratio = 1.0;
		u_w = (int)(2 * radius);
		u_l = (int)(2 * radius);

		if (fmask > 0) {
		    count = 0;
		    row_buf = Rast_allocate_buf(CELL_TYPE);
		    fr = Rast_open_old(n1, G_mapset());
		    for (j = t; j < b; j++) {
			Rast_zero_buf(row_buf, CELL_TYPE);
			Rast_get_row(fr, row_buf, j, CELL_TYPE);
			for (k = l; k < r; k++) {
			    if (*(row_buf + k))
				count++;
			}
		    }
		    G_free(row_buf);
		    Rast_close(fr);
		    cnt = (double)(count);
		    if (cnt)
			cnt = sqrt(cnt);
		    else
			cnt = 0;
		}
		else {
		    count = (w_l - (int)(start[0])) * (w_w - (int)(start[1]));
		}
	    }

	    /* if sampling using rectangles/squares */

	    else {

		/* get the width/length ratio */

	      getratio:
		fprintf(stderr,
			"\n    Sampling unit SHAPE (aspect ratio, #cols/#rows) "
			"expressed as real number"
			"\n    (e.g., 10 cols/5 rows = 2.0) for sampling units "
			"of scale %d? ", i + 1);

		numtrap(1, &ratio);
		if (ratio < 0)
		    ratio = -ratio;
		else if (ratio > 25.0)
		    if (!G_yes
			("\n    Are you sure you want such a large ratio?   ",
			 1))
			goto getratio;

		/* determine the recommended maximum size
		   for sampling units */

	      getsize:
		dtmp = (ratio > 1) ? 1 / ratio : ratio;
		dtmp /= (h_d > v_d) ? h_d * h_d : v_d * v_d;

	      tryagain:
		if (method == 1) {

		    if (fmask > 0) {
			count = 0;
			row_buf = Rast_allocate_buf(CELL_TYPE);
			fr = Rast_open_old(n1, G_mapset());
			for (j = t; j < b; j++) {
			    Rast_zero_buf(row_buf, CELL_TYPE);
			    Rast_get_row(fr, row_buf, j, CELL_TYPE);
			    for (k = l; k < r; k++) {
				if (*(row_buf + k))
				    count++;
			    }
			}
			G_free(row_buf);
			Rast_close(fr);
			cnt = (double)(count);
			if (cnt)
			    cnt = sqrt(cnt);
			else
			    cnt = 0;
			maxsize =
			    ((cnt * dtmp / 2) * (cnt * dtmp / 2) >
			     1.0 / dtmp) ? (cnt * dtmp / 2) * (cnt * dtmp /
							       2) : 1.0 /
			    dtmp;
			fprintf(stderr,
				"\n    Recommended maximum SIZE is %d in %d cell total",
				maxsize, count);
			fprintf(stderr, " area\n");

		    }

		    else {
			fprintf(stderr, "\n    Recommended maximum SIZE is");
			fprintf(stderr, " %d in %d pixel total area\n",
				(int)((w_l - (int)(start[0])) * (w_w -
								 (int)(start
								       [1])) *
				      dtmp / 2),
				(w_l - (int)(start[0])) * (w_w -
							   (int)(start[1])));

			count =
			    (w_l - (int)(start[0])) * (w_w - (int)(start[1]));
			maxsize =
			    (int)((w_l - (int)(start[0])) * (w_w -
							     (int)(start[1]))
				  * dtmp / 2);
		    }
		}

		else if (method == 2 || method == 3 || method == 5) {
		    fprintf(stderr,
			    "\n    Recommended maximum SIZE is %d in %d pixel total",
			    (int)((w_l - (int)(start[0])) * (w_w -
							     (int)(start[1]))
				  * dtmp / 2),
			    (w_l - (int)(start[0])) * (w_w -
						       (int)(start[1])));
		    fprintf(stderr, " area\n");

		}

		else if (method == 4) {
		    fprintf(stderr, "\n    Recommended maximum SIZE is");
		    fprintf(stderr, " %d in %d pixel individual",
			    (int)(w_w * w_l * dtmp / 2),
			    ((w_w - (int)(start[1])) / h_d) * ((w_l -
								(int)(start
								      [0])) /
							       v_d));
		    fprintf(stderr, " stratum area\n");

		}

		/* get the unit size, display the calculated
		   size, and ask if it is OK */

		fprintf(stderr,
			"    What size (in pixels) for each sampling unit of scale %d?  ",
			i + 1);

		numtrap(1, &size);
		thick = 1;
		if (size < 15 || ratio < 0.2 || ratio > 5)
		    thick = 0;
		u_w = sqrt(size * ratio);
		u_l = sqrt(size / ratio);
		fprintf(stderr,
			"\n    The nearest size is %d cells wide X %d cells high = %d",
			u_w, u_l, u_w * u_l);
		fprintf(stderr, " cells\n");

		if (!u_w || !u_l) {
		    fprintf(stderr,
			    "\n    0 cells wide or high is not acceptable; try again");

		    goto tryagain;
		}
		if (!G_yes("    Is this SIZE OK?   ", 1))
		    goto getsize;
	    }

	    /* for syst. noncontig. distribution, get
	       the interval between units */

	    if (method == 3) {
		fprintf(stderr,
			"\n    The interval, in pixels, between the units of scale");
		fprintf(stderr, " %d?  ", i + 1);

		numtrap(1, &intv);
	    }

	    /* if the unit dimension + the interval
	       is too large, print a warning and
	       try getting another size */

	    if (u_w + intv > w_w / h_d || u_l + intv > w_l / v_d) {
		fprintf(stderr,
			"\n    Unit size too large for sampling frame; try again\n");

		if (radius)
		    goto getradius;
		else
		    goto getsize;

	    }

	    /* for stratified random distribution,
	       the number of units is the same as
	       the number of strata */

	    if (method == 4)
		num = h_d * v_d;

	    /* for the other distributions, calculate the
	       maximum number of units, then get the
	       number of units */

	    else if (method == 1 || method == 2 || method == 3) {

		if (method == 1) {
		    if (!
			(unit_num =
			 calc_num(w_w, w_l, ratio, u_w, u_l, method, intv,
				  (int)(start[1]), (int)(start[0]), u_w * u_l,
				  count))) {
			fprintf(stderr,
				"\n    Something wrong with sampling unit size, try again\n");

			if (radius)
			    goto getradius;
			else
			    goto getsize;
		    }
		    fprintf(stderr,
			    "\n    Maximum NUMBER of units in scale %d is %d\n",
			    i + 1, unit_num);
		    fprintf(stderr,
			    "    Usually 1/2 of this number can be successfully");
		    fprintf(stderr,
			    " distributed\n    More than 1/2 can sometimes be");
		    fprintf(stderr, " distributed\n");

		}

		else if (method == 2 || method == 3) {
		    numx = floor((double)(w_w - start[1]) / (u_w + intv));
		    numy = floor((double)(w_l - start[0]) / (u_l + intv));
		    if (((w_w -
			  (int)(start[1])) % (numx * (u_w + (int)(intv)))) >=
			u_w)
			numx++;
		    if (((w_l -
			  (int)(start[0])) % (numy * (u_l + (int)(intv)))) >=
			u_l)
			numy++;
		    unit_num = numx * numy;
		    fprintf(stderr,
			    "\n    Maximum NUMBER of units in scale %d is %d as %d",
			    i + 1, unit_num, numy);
		    fprintf(stderr, " rows with %d units per row", numx);

		}

		do {
		    fprintf(stderr,
			    "\n    What NUMBER of sampling units do you want to try");
		    fprintf(stderr, " to use?  ");

		    numtrap(1, &dtmp);

		    if ((num = dtmp) > unit_num || num < 1) {
			fprintf(stderr,
				"\n    %d is greater than the maximum number of",
				num);
			fprintf(stderr, " sampling units; try again\n");

		    }

		    else if (method == 2 || method == 3) {
			fprintf(stderr,
				"\n    How many sampling units do you want per row?  ");

			numtrap(1, &dtmp);
			if ((nx = dtmp) > num) {
			    fprintf(stderr,
				    "\n    Number in each row > number requested; try");
			    fprintf(stderr, " again\n");

			}
			else {
			    if (nx > numx) {
				fprintf(stderr,
					"\n    Can't fit %d units in each row, try",
					nx);
				fprintf(stderr, " again\n");

			    }
			    else {
				if (num % nx)
				    ny = num / nx + 1;
				else
				    ny = num / nx;
				if (ny > numy) {
				    fprintf(stderr,
					    "\n    Can't fit the needed %d rows, try",
					    ny);
				    fprintf(stderr, " again\n");

				}
			    }
			}
		    }
		}
		while (num > unit_num || num < 1 || nx > num || nx > numx ||
		       ny > numy);
	    }

	    /* dynamically allocate storage for arrays to
	       store the upper left corner of sampling
	       units */

	    if (method != 5) {
		ux = G_calloc(num + 1, sizeof(double));
		uy = G_calloc(num + 1, sizeof(double));
	    }

	    else {
		ux = G_calloc(250, sizeof(double));
		uy = G_calloc(250, sizeof(double));
	    }

	    /* calculate the upper left corner of sampling
	       units and store them in arrays ux and uy */

	    if (!calc_unit_loc
		(radius, t, b, l, r, ratio, u_w, u_l, method, intv, num, h_d,
		 v_d, ux, uy, &sites, (int)(start[1]), (int)(start[0]), fmask,
		 nx, mx[0], mx[1]))
		goto last;

	    signal(SIGINT, SIG_DFL);
	    if (method == 5)
		num = sites;

	    /* draw the sampling units on the
	       screen */

	    if (method == 2 || method == 3 || method == 5) {
		R_open_driver();
		R_standard_color(D_translate_color("red"));
		for (j = 0; j < num; j++) {
		    if (radius) {
			draw_circle((int)((double)(ux[j]) / mx[0]),
				    (int)((double)(uy[j]) / mx[1]),
				    (int)((double)(ux[j] + u_w) / mx[0]),
				    (int)((double)(uy[j] + u_l) / mx[1]), 3);
		    }
		    else {
			draw_box((int)((double)(ux[j]) / mx[0]),
				 (int)((double)(uy[j]) / mx[1]),
				 (int)((double)(ux[j] + u_w) / mx[0]),
				 (int)((double)(uy[j] + u_l) / mx[1]), 1);
		    }
		}
		R_close_driver();
	    }

	    if (G_yes("\n    Is this set of sampling units OK?   ", 1))
		break;
	  last:
	    signal(SIGINT, SIG_DFL);
	    if (G_yes("\n    Refresh the screen?   ", 1)) {
		paint_map(n1, n2, n3);
		R_open_driver();
		R_standard_color(D_translate_color("grey"));
		draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]),
			 (int)(b / mx[1]), 1);
		R_close_driver();
	    }
	}

	/* save the sampling unit parameters
	   in r.le.para/units file */

	fprintf(fp, "%10d    # of units of scale %d.\n", num, (i + 1));
	fprintf(fp, "%10d%10d   u_w, u_l of units in scale %d\n", u_w, u_l,
		(i + 1));
	fprintf(fp, "%10.1f             radius of circles in scale %d\n",
		radius, (i + 1));

	for (j = 0; j < num; j++)
	    fprintf(fp, "%10d%10d   left, top of unit[%d]\n", (int)ux[j],
		    (int)uy[j], j + 1);

	if (i < scales - 1 && G_yes("\n\n    Refresh the screen?   ", 1)) {
	    paint_map(n1, n2, n3);
	    R_open_driver();
	    R_standard_color(D_translate_color("grey"));
	    draw_box((int)(l / mx[0]), (int)(t / mx[1]), (int)(r / mx[0]),
		     (int)(b / mx[1]), 1);
	    R_close_driver();
	}
    }

    /* free dynamically allocated memory */

    G_free(ux);
    G_free(uy);
    fclose(fp);
    return;
}
Пример #26
0
static int drawvect(int zoomit,	/* -1 = refresh, 0 = new image, 1 = zoom, 2 = warp */
		    View * zoom_view, double E[], double N[], int trans_order)
{				/* order of transformation if warping vectors */
    int stat = 0;
    int i;
    char name[GNAME_MAX], mapset[GMAPSET_MAX];
    struct Cell_head cellhd;
    struct line_pnts *Points;
    char msg[100], win_name[100];
    int t, b, l, r;
    int blank = 0;
    View *active_view;
    int left, top, nrows, ncols;
    static int vectclr[VFILES];


    /* if refresh screen or overlay & no displayed vector maps return */
    if ((zoomit == DO_REFRESH || zoomit == DO_WARP) && !numfiles) {
	if (zoomit == DO_REFRESH)
	    display_points(1);
	return 0;
    }

    /* numfiles stays at 0 until the end of the first vector map init */

    if (numfiles >= VFILES) {
	G_warning
	    ("Can't display another map; reached maximum number of files");
	return 0;
    }

    select_target_env();

    if (zoomit == DO_REFRESH || zoomit == DO_NEW) {	/* New Map File or Refresh Screen */

	if (zoomit == DO_NEW) {	/* zoomit==0, Draw New Map File */
	    if (!choose_vectfile(name, mapset))
		return 0;

	    strcpy(vect_file[numfiles], name);
	    strcpy(vect_mapset[numfiles], mapset);

	    get_vector_color();	/* ask line_color to draw map */

	    if (!numfiles) {	/* first map: SET VECTOR WINDOW BY WIND */
		G_get_window(&cellhd);
		G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd));
	    }
	    else		/* not the first map */
		G_copy(&cellhd, &VIEW_MAP2->cell.head,
		       sizeof(VIEW_MAP2->cell.head));

	    numfiles++;

	}
	else {			/* zoomit=-1 Refresh Screen */
	    G_copy(&cellhd, &VIEW_MAP2->cell.head,
		   sizeof(VIEW_MAP2->cell.head));

	    if (!cellmap_present)
		Erase_view(VIEW_MAP2_ZOOM);

	    VIEW_MAP2_ZOOM->cell.configured = 0;
	    blank = BLACK;
	}

	strcpy(win_name, "vect_map");
	if (!view2on) {
	    t = VIEW_MAP2->top;
	    b = VIEW_MAP2->bottom;
	    l = VIEW_MAP2->left;
	    r = VIEW_MAP2->right;
	    D_new_window(win_name, t, b, l, r);
	    if (!cellmap_present)
		blank = BLACK;
	    else
		blank = 0;	/* don't erase viewport */
	    view2on = 1;
	}

	active_view = VIEW_MAP2;
    }
    else {			/* zoomit>0   Zoom or Warp */

	G_copy(&cellhd, &zoom_view->cell.head, sizeof(zoom_view->cell.head));

	if (!(zoom_view == VIEW_MAP1)) {	/* target side */
	    VIEW_MAP2_ZOOM->cell.configured = 0;
	    strcpy(win_name, "zoom_map");
	    if (!view2zoomon) {
		t = VIEW_MAP2_ZOOM->top;
		b = VIEW_MAP2_ZOOM->bottom;
		l = VIEW_MAP2_ZOOM->left;
		r = VIEW_MAP2_ZOOM->right;
		D_new_window(win_name, t, b, l, r);
		view2zoomon = 1;

	    }
	    active_view = VIEW_MAP2_ZOOM;
	    blank = BLACK;
	}
	else {
	    strcpy(win_name, "warp_map");	/* defined in drawcell routine */
	    active_view = VIEW_MAP1;
	    blank = 0;		/* don't erase viewport */
	}
    }

    nrows = active_view->nrows;
    ncols = active_view->ncols;
    left = active_view->left;
    top = active_view->top;

    D_set_cur_wind(win_name);
    R_standard_color(YELLOW);
    Outline_box(top, top + nrows - 1, left, left + ncols - 1);
    Points = Vect_new_line_struct();

    if (zoomit != DO_WARP) {
	Curses_clear_window(INFO_WINDOW);
	Curses_write_window(INFO_WINDOW, 1, 13, "COORDINATES");
	Curses_write_window(INFO_WINDOW, 3, 2, "MAIN WINDOW");

	sprintf(msg, "N = %10.2f   E = %10.2f", VIEW_MAP2->cell.head.north,
		VIEW_MAP2->cell.head.east);
	Curses_write_window(INFO_WINDOW, 5, 4, msg);
	sprintf(msg, "S = %10.2f   W = %10.2f", VIEW_MAP2->cell.head.south,
		VIEW_MAP2->cell.head.west);
	Curses_write_window(INFO_WINDOW, 6, 4, msg);

	Curses_write_window(INFO_WINDOW, 9, 2, "ZOOM WINDOW");
	sprintf(msg, "N = %10.2f   E = %10.2f",
		VIEW_MAP2_ZOOM->cell.head.north,
		VIEW_MAP2_ZOOM->cell.head.east);
	Curses_write_window(INFO_WINDOW, 11, 4, msg);
	sprintf(msg, "S = %10.2f   W = %10.2f",
		VIEW_MAP2_ZOOM->cell.head.south,
		VIEW_MAP2_ZOOM->cell.head.west);
	Curses_write_window(INFO_WINDOW, 12, 4, msg);
    }

    if (zoomit) {		/* ie ! DO_NEW */

	dsp_setup(blank, &cellhd);

	for (i = 0; i < numfiles; i++) {
	    sprintf(msg, "Displaying %s", vect_file[i]);
	    Menu_msg(msg);
	    R_standard_color(vectclr[i]);
	    if (zoomit != DO_WARP)
		stat = plot(vect_file[i], vect_mapset[i], Points);
	    else
		stat = plot_warp(vect_file[i], vect_mapset[i],
				 Points, E, N, trans_order);
	}
    }
    else {			/* ie DO_NEW */

	if (numfiles == 1) {	/* let first file set window */
	    G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd));

	    cellhd.rows = VIEW_MAP2->nrows;
	    cellhd.cols = VIEW_MAP2->ncols;
	    cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
	    cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;
	    if (cellhd.ns_res > cellhd.ew_res)
		cellhd.ew_res = cellhd.ns_res;
	    else
		cellhd.ns_res = cellhd.ew_res;

	    VIEW_MAP2->cell.ns_res = cellhd.ns_res;
	    VIEW_MAP2->cell.ew_res = cellhd.ew_res;

	    G_copy(&VIEW_MAP2->cell.head, &cellhd, sizeof(cellhd));

	    G_adjust_window_to_box(&cellhd, &VIEW_MAP2->cell.head,
				   VIEW_MAP2->nrows, VIEW_MAP2->ncols);

	    if (!cellmap_present) {
		Configure_view(VIEW_MAP2, vect_file[numfiles - 1],
			       vect_mapset[numfiles - 1], cellhd.ns_res,
			       cellhd.ew_res);
	    }

	    Curses_write_window(INFO_WINDOW, 15, 2,
				"WHERE CURSOR-> Mid Button");
	}

	dsp_setup(blank, &cellhd);

	R_standard_color(YELLOW);
	Outline_box(top, top + nrows - 1, left, left + ncols - 1);

	sprintf(msg, "Displaying %s", vect_file[numfiles - 1]);
	Menu_msg(msg);

	R_standard_color(line_color);
	vectclr[numfiles - 1] = line_color;

	get_clr_name(vect_color[numfiles - 1], line_color);

	stat =
	    plot(vect_file[numfiles - 1], vect_mapset[numfiles - 1], Points);

    }

    display_points(1);

    R_standard_color(WHITE);
    Outline_box(top, top + nrows - 1, left, left + ncols - 1);

    Menu_msg("");

    Vect_destroy_line_struct(Points);

    /*    VIEW_MAP2->cell.configured = 1; XXX */

    select_current_env();
    if (from_screen < 0) {
	from_flag = 1;
	from_screen = 0;
	if (from_keyboard < 0) {
	    from_keyboard = 0;
	    from_screen = 1;
	}
    }

    if (numfiles) {
	Curses_clear_window(MENU_WINDOW);
	Curses_write_window(MENU_WINDOW, 1, 5, "COLOR  MAP FILE");
	for (i = 0; i < numfiles; i++) {
	    sprintf(msg, "%7s  %s", vect_color[i], vect_file[i]);
	    Curses_write_window(MENU_WINDOW, i + 3, 3, msg);
	}
    }

    return 0;
}
Пример #27
0
static int zoom2(int x, int y)
{
    int top, bottom, left, right;
    int row, col;
    struct Cell_head cellhd;

    x2 = x;
    y2 = y;
    /* 
     * user has completed the zoom window.
     * must be in same view as first corner
     */
    if (x1 == x2 || y1 == y2)
	return 0;		/* ignore event */
    if (!In_view(pick_view, x2, y2))
	return 0;
    /*
     * ok, erase menu messages
     */
    Menu_msg("");

    /*
     * assign window coordinates to top,bottom,left,right
     */
    if (x1 < x2) {
	left = x1;
	right = x2;
    }
    else {
	left = x2;
	right = x1;
    }
    if (y1 < y2) {
	top = y1;
	bottom = y2;
    }
    else {
	top = y2;
	bottom = y1;
    }

    /* 
     * Determine the the zoom window (ie, cellhd)
     * must copy the current view cellhd first, to preserve header info
     * (such as projection, zone, and other items.)
     * compute zoom window northings,eastings, rows, cols, and resolution
     */

    G_copy(&cellhd, &pick_view->cell.head, sizeof(cellhd));

    /* convert top to northing at top edge of cell
     * left to easting at left edge
     */
    col = view_to_col(pick_view, left);
    row = view_to_row(pick_view, top);
    cellhd.north = row_to_northing(&pick_view->cell.head, row, 0.0);
    cellhd.west = col_to_easting(&pick_view->cell.head, col, 0.0);

    /* convert bottom to northing at bottom edge of cell
     * right to easting at right edge
     */
    col = view_to_col(pick_view, right);
    row = view_to_row(pick_view, bottom);
    cellhd.south = row_to_northing(&pick_view->cell.head, row, 1.0);
    cellhd.east = col_to_easting(&pick_view->cell.head, col, 1.0);


    cellhd.rows = bottom - top + 1;
    cellhd.cols = right - left + 1;
    cellhd.ns_res = (cellhd.north - cellhd.south) / cellhd.rows;
    cellhd.ew_res = (cellhd.east - cellhd.west) / cellhd.cols;

    /*
     * Outline the zoom window on the main map
     * Turn previous one to grey.
     */
    if (zoom_view->cell.configured) {
	R_standard_color(GREY);
	Outline_cellhd(main_view, &zoom_view->cell.head);
    }
    R_standard_color(RED);
    Outline_cellhd(main_view, &cellhd);


    /*
     * zoom
     */
    if (target_flag)
	select_target_env();
    G_adjust_window_to_box(&cellhd, &zoom_view->cell.head, zoom_view->nrows,
			   zoom_view->ncols);
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
		   pick_view->cell.ns_res, pick_view->cell.ew_res);
    drawcell(zoom_view);
    select_current_env();
    display_ref_points(1);
    return 1;			/* pop back */
}
Пример #28
0
int ask_line_color(char *colors, int len1, char *xname, int position)
{
    static int use = 1;
    int pick();
    static Objects objects[] = {
	OTHER(pick, &use),
	{0}
    };

    char msg[100];
    int width;
    int len2 = 0, len;
    long offset;
    long *page_offset;
    int col, nlist;
    int line;
    int stat;
    char buf[100];
    int top, bottom, left, right, center;
    int topx, bottomx, leftx, rightx, widthx;
    char name[100], mapset[100], cur_mapset[100];
    int new_mapset;

    Menu_msg("");

    sprintf(msg, "Double click on color to assign to vector layer");

    /*
     * build a popup window at center of the screen.
     * 35% the height and wide enough to hold 2 columms of file names
     *
     * the window is for choosing file names and will be laid out in 2 columns
     *
     *             ------------------------------------------
     *             |     CANCEL           | (MORE) | (LESS) | 
     *             ------------------------------------------
     *             |             mapset                     |
     *             ------------------------------------------
     *             |      name1        |   name2            |
     *             ------------------------------------------
     *             |      name3        |   name4            |
     *             ------------------------------------------
     *             |      name5        |   name6            |
     *             |                   .                    |
     *             |                   .                    |
     *             |                   .                    |
     *             ------------------------------------------
     */

    /* height of 1 line, based on NLINES taking up 35% vertical space */
    height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;

    /* size of text, 80% of line height */
    text_size = .8 * height;
    size = text_size - 1;	/* fudge for computing pixels width of text */

    /* indent for the text */
    edge = .1 * height + 1;

    /* this is a fudge to determine the length of the largest text */
    len1 = 2 * len1;		/* name in 2 columns */
    len2 += strlen("mapset ");
    len = (len1 > len2 ? len1 : len2);

    /* width is for max chars plus sidecar for more/less */
    width = len * size + height;
    widthx = strlen(msg) * size;
    if (widthx < width)
	widthx = width;

    /* define the window */
    top = (SCREEN_TOP + SCREEN_BOTTOM - height * NLINES) / 2;
    bottom = top + height * NLINES;

    center = (SCREEN_LEFT + SCREEN_RIGHT) / 2;
    if (position > 0) {
	right = (center + SCREEN_RIGHT + width) / 2;
	if (right >= SCREEN_RIGHT)
	    right = SCREEN_RIGHT - 1;
	left = right - width;
    }
    else if (position < 0) {
	left = (center + SCREEN_LEFT - width) / 2;
	if (left <= SCREEN_LEFT)
	    left = SCREEN_LEFT + 1;
	right = left + width;
    }
    else {
	left = center + width / 2;
	right = left + width;
    }

    topx = top - 3 * height;
    bottomx = topx + 2 * height;
    leftx = (left + right - widthx) / 2;
    if (leftx < SCREEN_LEFT)
	leftx = SCREEN_LEFT;
    rightx = leftx + widthx;

    /* save what is under these areas, so they can be restored */
    R_panel_save(tempfile1, top, bottom, left, right);
    R_panel_save(tempfile2, topx, bottomx, leftx, rightx);

    /* fill it top with GREY, pick area with white */
    R_standard_color(WHITE);
    R_box_abs(left, top, right, bottom);
    R_standard_color(GREY);
    R_box_abs(leftx, topx, rightx, bottomx);

    R_standard_color(BLACK);
    Outline_box(top, bottom, left, right);
    right -= height;		/* reduce it to exclude sidecar */
    Outline_box(top, bottom, left, right);

    /* print messages above the files */
    dotext(msg, topx, topx + height, leftx, rightx, 1);
    dotext("Double click here to cancel", topx + height, bottomx, leftx,
	   rightx, 1);
    cancel.top = topx;
    cancel.bottom = bottomx;
    cancel.left = leftx;
    cancel.right = rightx;

    /* start the mouse in the cancel box */
    Set_mouse_xy((leftx + rightx) / 2, (topx + bottomx) / 2);

    dobox(&less, "", WHITE, top, right, right + height, 0);
    dobox(&more, "", WHITE, bottom - height, right, right + height, 0);

    /* as we read the file of names, keep track of pages so we can
     * page backward
     */
    page = 0;
    page_offset = (long *)G_calloc(npages = 1, sizeof(long));
    *page_offset = ftell(fd);

    nlist = sizeof(list) / sizeof(list[0]);
    for (stat = -1; stat < 0;) {
	line = 0;
	count = 0;
	*cur_mapset = 0;
	col = 0;
	while (1) {
	    /*
	       offset = ftell (fd);
	       if (fgets (buf, sizeof buf, fd) == NULL
	       || sscanf (buf, "%s %s", name, mapset) != 2)
	       break;
	       if(new_mapset = (strcmp (cur_mapset,mapset) != 0))
	       {
	       if(line) line++;
	       if (col) line++;
	       col = 0;
	       }
	       if (count >= nlist || line+new_mapset >= NLINES)
	       {
	       if (page+1 == npages)
	       {
	       npages++;
	       page_offset = (long *) G_realloc (page_offset, npages * sizeof (long));
	       page_offset[npages-1] = offset;
	       }
	       break;
	       }
	       if (new_mapset)
	       {
	       struct box dummy;
	       char label[100];

	       strcpy (cur_mapset, mapset);
	       sprintf (label, "Mapset %s", mapset);
	       dobox (&dummy, label, WHITE, top+line*height, left, right, 0);
	       line++;
	       }
	       if (col)
	       {
	       dobox (&list[count].box, name, GREY, top+line*height, left+width/2, right, 0);
	       line++;
	       col = 0;
	       }
	       else
	       {
	       dobox (&list[count].box, name, GREY, top+line*height, left, left+width/2, 0);
	       col = 1;
	       }
	       strcpy (list[count].name, name);
	       strcpy (list[count].mapset, mapset);
	       count++;
	       }
	       downarrow (&more, page+1 < npages ? BLACK : WHITE);
	       uparrow   (&less, page   > 0      ? BLACK : WHITE);
	       which = -1;
	       switch(Input_pointer(objects))
	       {
	       case -1: /* more or less */
	    break;
case -2:			/* cancel */
	    stat = 0;
	    continue;
default:			/* file picked */
	    strcpy(xname, list[which].name);
	    stat = 1;
	    continue;
	}
	fseek(fd, page_offset[page], 0);
	R_standard_color(WHITE);
	R_box_abs(left + 1, top + 1, right - 1, bottom - 1);
    }

    /* all done. restore what was under the window */
    right += height;		/* move it back over the sidecar */
    R_standard_color(WHITE);
    R_box_abs(left, top, right, bottom);
    R_panel_restore(tempfile1);
    R_panel_restore(tempfile2);
    R_panel_delete(tempfile1);
    R_panel_delete(tempfile2);
    R_flush();

    G_free(page_offset);
    return stat;
}
Пример #29
0
int analyze(void)
{
    static int use = 1;

    static Objects objects[] = {
	MENU("DONE", done, &use),
	MENU("PRINT", to_printer, &use),
	MENU("FILE", to_file, &use),
	MENU("OVERLAY", do_warp, &use),
	MENU(delete_msg, delete_mark, &use),
	INFO("Transform->", &use),
	MENU(order_msg, get_order, &use),
	INFO(pick_msg, &use),
	OTHER(pick, &use),
	{0}
    };

    int color;
    int tsize;
    int cury;
    int len;
    int line;
    int top, bottom, left, right, width, middle, nums;

    /* to give user a response of some sort */
    Menu_msg("Preparing analysis ...");

    /*
     * build a popup window at center of the screen.
     * 35% the height and wide enough to hold the report
     *
     */

    /* height of 1 line, based on NLINES taking up 35% vertical space */
    height = (.35 * (SCREEN_BOTTOM - SCREEN_TOP)) / NLINES + 1;

    /* size of text, 80% of line height */
    tsize = .8 * height;
    size = tsize - 2;		/* fudge for computing pixels width of text */

    /* indent for the text */
    edge = .1 * height + 1;

    /* determine the length, in chars, of printed line */
    FMT0(buf, 0);
    nums = strlen(buf) * size;
    FMT1(buf, 0.0, 0.0, 0.0);
    len = strlen(buf);
    middle = len * size;
    FMT2(buf, 0.0, 0.0, 0.0, 0.0);
    len += strlen(buf);

    /* width is for max chars plus sidecar for more/less */
    width = len * size + nums + 2 * height;
    if ((SCREEN_RIGHT - SCREEN_LEFT) < width)
	width = SCREEN_RIGHT - SCREEN_LEFT;


    /* define the window */
    bottom = VIEW_MENU->top - 1;
    top = bottom - height * NLINES;


    left = SCREEN_LEFT;
    right = left + width;
    middle += left + nums;
    nums += left;

    /* save what is under this area, so it can be restored */
    R_panel_save(tempfile1, top, bottom + 1, left, right + 1);


    /* fill it with white */
    R_standard_color(BACKGROUND);
    R_box_abs(left, top, right, bottom);

    right -= 2 * height;	/* reduce it to exclude sidecar */

    /* print messages in message area */
    R_text_size(tsize, tsize);


    /* setup the more/less boxes in the sidecar */
    R_standard_color(BLACK);
    less.top = top;
    less.bottom = top + 2 * height;
    less.left = right;
    less.right = right + 2 * height;
    Outline_box(less.top, less.bottom, less.left, less.right);

    more.top = bottom - 2 * height;
    more.bottom = bottom;
    more.left = right;
    more.right = right + 2 * height;
    Outline_box(more.top, more.bottom, more.left, more.right);

    /*
     * top two lines are for column labels
     * last two line is for overall rms error.
     */
    nlines = NLINES - 3;
    first_point = 0;

    /* allocate predicted values */
    xres = (double *)G_calloc(group.points.count, sizeof(double));
    yres = (double *)G_calloc(group.points.count, sizeof(double));
    gnd = (double *)G_calloc(group.points.count, sizeof(double));

    /* compute transformation for the first time */
    compute_transformation();

    /* put head on the report */
    cury = top;
    dotext(LHEAD1, cury, cury + height, left, middle, 0, BLACK);
    dotext(RHEAD1, cury, cury + height, middle, right - 1, 0, BLACK);
    cury += height;
    dotext(LHEAD2, cury, cury + height, left, middle, 0, BLACK);
    dotext(RHEAD2, cury, cury + height, middle, right - 1, 0, BLACK);
    cury += height;
    R_move_abs(left, cury - 1);
    R_cont_abs(right, cury - 1);

    /* isolate the sidecar */
    R_move_abs(right, top);
    R_cont_abs(right, bottom);

    /* define report box */
    report.top = cury;
    report.left = left;
    report.right = right;

    /* lets do it */

    pager = 1;
    while (1) {
	R_text_size(tsize, tsize);
	line = 0;
	curp = first_point;
	cury = top + 2 * height;
	while (1) {
	    if (line >= nlines || curp >= group.points.count)
		break;
	    line++;

	    if (!delete_mode)
		color = BLACK;
	    else
		color = BLUE;

	    if (group.equation_stat > 0 && group.points.status[curp] > 0) {
		/* color = BLACK; */
		FMT1(buf, xres[curp], yres[curp], gnd[curp]);
		if (curp == xmax || curp == ymax || curp == gmax)
		    color = RED;
		dotext(buf, cury, cury + height, nums, middle, 0, color);
	    }
	    else if (group.points.status[curp] > 0)
		dotext("?", cury, cury + height, nums, middle, 1, color);
	    else
		dotext("not used", cury, cury + height, nums, middle, 1,
		       color);

	    if (pager) {
		FMT0(buf, curp + 1);
		dotext(buf, cury, cury + height, left, nums, 0, color);
		FMT2(buf,
		     group.points.e1[curp],
		     group.points.n1[curp],
		     group.points.e2[curp], group.points.n2[curp]);
		dotext(buf, cury, cury + height, middle, right - 1, 0, color);
	    }
	    cury += height;
	    curp++;
	}
	report.bottom = cury;
	downarrow(&more, curp < group.points.count ? color : BACKGROUND);
	uparrow(&less, first_point > 0 ? color : BACKGROUND);
	R_standard_color(BACKGROUND);
	R_box_abs(left, cury, right - 1, bottom);
	if (group.equation_stat < 0) {

	    if (group.equation_stat == -1) {
		color = RED;
		strcpy(buf, "Poorly placed control points");
	    }
	    else {
		if (group.equation_stat == -2)
		    G_fatal_error("NOT ENOUGH MEMORY");
		else
		    G_fatal_error("PARAMETER ERROR");
	    }

	}
	else if (group.equation_stat == 0) {
	    color = RED;
	    strcpy(buf, "No active control points");
	}
	else {
	    color = BLACK;
	    sprintf(buf, "Overall rms error: %.2f", rms);
	}
	dotext(buf, bottom - height, bottom, left, right - 1, 0, color);
	R_standard_color(BLACK);
	R_move_abs(left, bottom - height);
	R_cont_abs(right - 1, bottom - height);

	pager = 0;
	which = -1;
	if (Input_pointer(objects) < 0)
	    break;
	display_points(1);
    }

    /* all done. restore what was under the window */
    right += 2 * height;	/* move it back over the sidecar */
    R_standard_color(BACKGROUND);
    R_box_abs(left, top, right, bottom);
    R_panel_restore(tempfile1);
    R_panel_delete(tempfile1);
    R_flush();

    G_free(xres);
    G_free(yres);
    G_free(gnd);
    I_put_control_points(group.name, &group.points);
    display_points(1);
    return 0;			/* return but don't QUIT */
}
Пример #30
0
static int pick(int x, int y)
{
    int n;
    int cur;

    cur = which;
    cancel_which();
    if (inbox(&more, x, y)) {
	if (curp >= group.points.count)
	    return 0;
	first_point = curp;
	pager = 1;
	return 1;
    }
    if (inbox(&less, x, y)) {
	if (first_point == 0)
	    return 0;
	first_point -= nlines;
	if (first_point < 0)
	    first_point = 0;
	pager = 1;
	return 1;
    }
    if (!inbox(&report, x, y)) {
	return 0;
    }

    n = (y - report.top) / height;
    if (n == cur) {		/* second click! */
	if (!delete_mode) {
	    group.points.status[first_point + n] =
		!group.points.status[first_point + n];
	    compute_transformation();
	    show_point(first_point + n, 1);
	    return 1;
	}
	else {
	    delete_control_point(first_point + n);
	    first_point = 0;
	    compute_transformation();
	    pager = 1;
	    return 1;
	}
    }

    /* first click */
    which = n;
    show_point(first_point + n, 0);
    if (!delete_mode)
	R_standard_color(RED);
    else
	R_standard_color(ORANGE);

    Outline_box((report.top + n * height) + 1, report.top + (n + 1) * height,
		report.left, report.right - 1);

    R_flush();

    return 0;			/* ignore first click */

}