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 */ }
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; }
int main(int argc, char *argv[]) { char name[GNAME_MAX], mapset[GMAPSET_MAX], xmapset[GMAPSET_MAX]; struct Cell_head cellhd; struct GModule *module; struct Option *grp; /* must run in a term window */ G_putenv("GRASS_UI_TERM", "1"); G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("imagery")); G_add_keyword(_("geometry")); module->description = _("Mark ground control points on image to be rectified."); grp = G_define_option(); grp->key = "group"; grp->type = TYPE_STRING; grp->required = YES; grp->gisprompt = "old,group,group"; grp->description = _("Name of imagery group to be registered"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); Rast_suppress_masking(); /* need to do this for target location */ interrupt_char = G_intr_char(); tempfile1 = G_tempfile(); tempfile2 = G_tempfile(); cell_list = G_tempfile(); vect_list = G_tempfile(); group_list = G_tempfile(); digit_points = G_tempfile(); digit_results = G_tempfile(); if (R_open_driver() != 0) G_fatal_error(_("No graphics device selected")); /* parse group name */ /* only enforce local-mapset-only due to I_get_group_ref() not liking "@mapset" */ if (G_name_is_fully_qualified(grp->answer, group.name, xmapset)) { if (0 != strcmp(G_mapset(), xmapset)) G_fatal_error(_("[%s] Only local groups may be used"), grp->answer); } else { strncpy(group.name, grp->answer, GNAME_MAX - 1); group.name[GNAME_MAX - 1] = '\0'; /* strncpy() doesn't null terminate on overflow */ } if (!I_get_group_ref(group.name, &group.ref)) G_fatal_error(_("Group [%s] contains no maps, run i.group"), group.name); if (group.ref.nfiles <= 0) G_fatal_error(_("Group [%s] contains no maps, run i.group"), group.name); /* write group files to group list file */ prepare_group_list(); /* get target info and environment */ get_target(); find_target_files(); /* read group control points, if any */ G_suppress_warnings(1); if (!I_get_control_points(group.name, &group.points)) group.points.count = 0; G_suppress_warnings(0); /* determine transformation equation */ Compute_equation(); signal(SIGINT, SIG_IGN); /* signal (SIGQUIT, SIG_IGN); */ Init_graphics(); display_title(VIEW_MAP1); select_target_env(); display_title(VIEW_MAP2); select_current_env(); Begin_curses(); G_set_error_routine(error); /* #ifdef SIGTSTP signal (SIGTSTP, SIG_IGN); #endif */ /* ask user for group file to be displayed */ do { if (!choose_groupfile(name, mapset)) quit(0); /* display this file in "map1" */ } while (!G_find_raster2(name, mapset)); Rast_get_cellhd(name, mapset, &cellhd); G_adjust_window_to_box(&cellhd, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows, VIEW_MAP1->ncols); Configure_view(VIEW_MAP1, name, mapset, cellhd.ns_res, cellhd.ew_res); drawcell(VIEW_MAP1); display_points(1); Curses_clear_window(PROMPT_WINDOW); /* determine initial input method. */ setup_digitizer(); if (use_digitizer) { from_digitizer = 1; from_keyboard = 0; from_flag = 1; } /* go do the work */ driver(); quit(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 */ }
int main(int argc, char *argv[]) { char mapset[GMAPSET_MAX]; char name[GNAME_MAX]; char *camera; struct GModule *module; struct Option *group_opt, *map_opt, *target_map_opt; struct Cell_head cellhd; int ok; int nfiles; /* must run in a term window */ G_putenv("GRASS_UI_TERM", "1"); G_gisinit(argv[0]); module = G_define_module(); module->keywords = _("imagery, orthorectify"); module->description = _("Creates control points on an image " "to be ortho-rectified."); group_opt = G_define_option(); group_opt->key = "group"; group_opt->type = TYPE_STRING; group_opt->required = YES; group_opt->multiple = NO; group_opt->description = _("Name of imagery group"); map_opt = G_define_standard_option(G_OPT_R_MAP); map_opt->required = NO; map_opt->description = _("Name of image to be rectified which will " "be initially drawn on screen"); target_map_opt = G_define_standard_option(G_OPT_R_MAP); target_map_opt->key = "target"; target_map_opt->required = NO; target_map_opt->description = _("Name of a map from target mapset which " "will be initially drawn on screen"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); G_suppress_masking(); /* need to do this for target location */ camera = (char *)G_malloc(40 * sizeof(char)); strcpy(name, group_opt->answer); interrupt_char = G_intr_char(); tempfile1 = G_tempfile(); tempfile2 = G_tempfile(); tempfile_dot = G_tempfile(); tempfile_dot2 = G_tempfile(); tempfile_win = G_tempfile(); tempfile_win2 = G_tempfile(); cell_list = G_tempfile(); vect_list = G_tempfile(); group_list = G_tempfile(); digit_points = G_tempfile(); if (R_open_driver() != 0) G_fatal_error(_("No graphics device selected")); /* get group ref */ strcpy(group.name, name); if (!I_find_group(group.name)) G_fatal_error(_("Group [%s] not found"), group.name); /* get the group ref */ I_get_group_ref(group.name, &group.group_ref); nfiles = group.group_ref.nfiles; /* write block files to block list file */ prepare_group_list(); /** look for camera info for this group**/ G_suppress_warnings(1); if (!I_get_group_camera(group.name, camera)) G_fatal_error(_("No camera reference file selected for group [%s]"), group.name); if (!I_get_cam_info(camera, &group.camera_ref)) G_fatal_error(_("Bad format in camera file for group [%s]"), group.name); G_suppress_warnings(0); /* get initial camera exposure station, if any */ if (!(ok = I_find_initial(group.name))) G_warning(_("No initial camera exposure station for group [%s]"), group.name); if (ok && (!I_get_init_info(group.name, &group.camera_exp)) ) G_warning(_("Bad format in initial camera exposure station for group [%s]"), group.name); /* get target info and environment */ G_suppress_warnings(1); get_target(); find_target_files(); G_suppress_warnings(0); /* read group reference points, if any */ G_suppress_warnings(1); if (!I_get_ref_points(group.name, &group.photo_points)) { G_suppress_warnings(0); if (group.photo_points.count == 0) G_fatal_error(_("No photo points for group [%s]"), group.name); else if (group.ref_equation_stat == 0) G_fatal_error(_("Poorly placed photo points for group [%s]"), group.name); } G_suppress_warnings(0); /* determine transformation equation */ Compute_ref_equation(); /* read group control points, format: image x,y,cfl; target E,N,Z */ G_suppress_warnings(1); if (!I_get_con_points(group.name, &group.control_points)) group.control_points.count = 0; G_suppress_warnings(0); /* compute image coordinates of photo control points */ /******** I_convert_con_points (group.name, &group.control_points, &group.control_points, group.E12, group.N12); ********/ /* determine transformation equation */ G_message(_("Computing equations ...")); if (group.control_points.count > 0) Compute_ortho_equation(); /* signal (SIGINT, SIG_IGN); */ /* signal (SIGQUIT, SIG_IGN); */ select_current_env(); Init_graphics(); display_title(VIEW_MAP1); select_target_env(); display_title(VIEW_MAP2); select_current_env(); Begin_curses(); G_set_error_routine(error); /* #ifdef SIGTSTP signal (SIGTSTP, SIG_IGN); #endif */ /* Set image to be rectified */ if (map_opt->answer) { char *ms; ms = G_find_cell(map_opt->answer, ""); if (ms == NULL) { G_fatal_error(_("Raster map <%s> not found"), map_opt->answer); } strcpy(name, map_opt->answer); strcpy(mapset, ms); if (G_get_cellhd(name, mapset, &cellhd) < 0) { G_fatal_error(_("Unable to read raster header of <%s>"), map_opt->answer); } } else { /* ask user for group file to be displayed */ do { if (!choose_groupfile(name, mapset)) quit(EXIT_SUCCESS); /* display this file in "map1" */ } while (G_get_cellhd(name, mapset, &cellhd) < 0); } G_adjust_window_to_box(&cellhd, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows, VIEW_MAP1->ncols); Configure_view(VIEW_MAP1, name, mapset, cellhd.ns_res, cellhd.ew_res); drawcell(VIEW_MAP1); /* Set target map if specified */ if (target_map_opt->answer) { char *ms; select_target_env(); ms = G_find_cell(target_map_opt->answer, ""); if (ms == NULL) { G_fatal_error(_("Raster map <%s> not found"), target_map_opt->answer); } strcpy(name, target_map_opt->answer); strcpy(mapset, ms); if (G_get_cellhd(name, mapset, &cellhd) < 0) { G_fatal_error(_("Unable to read raster header of <%s>"), target_map_opt->answer); } G_adjust_window_to_box(&cellhd, &VIEW_MAP2->cell.head, VIEW_MAP2->nrows, VIEW_MAP2->ncols); Configure_view(VIEW_MAP2, name, mapset, cellhd.ns_res, cellhd.ew_res); drawcell(VIEW_MAP2); from_flag = 1; from_keyboard = 0; from_screen = 1; } display_conz_points(1); Curses_clear_window(PROMPT_WINDOW); /* determine initial input method. */ setup_digitizer(); if (use_digitizer) { from_digitizer = 1; from_keyboard = 0; from_flag = 1; } /* go do the work */ driver(); quit(EXIT_SUCCESS); }