int parse(int argc, char *argv[], struct parms *parms) { struct Option *group, *subgroup, *sigfile, *output; struct Option *blocksize; struct Flag *ml; group = G_define_standard_option(G_OPT_I_GROUP); subgroup = G_define_standard_option(G_OPT_I_SUBGROUP); sigfile = G_define_option(); sigfile->key = "signaturefile"; sigfile->label = _("Name of file containing signatures"); sigfile->description = _("Generated by i.gensigset"); sigfile->key_desc = "name"; sigfile->required = YES; sigfile->type = TYPE_STRING; output = G_define_standard_option(G_OPT_R_OUTPUT); blocksize = G_define_option(); blocksize->key = "blocksize"; blocksize->description = _("Size of submatrix to process at one time"); blocksize->required = NO; blocksize->type = TYPE_INTEGER; blocksize->answer = "128"; ml = G_define_flag(); ml->key = 'm'; ml->description = _("Use maximum likelihood estimation (instead of smap)"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); parms->ml = ml->answer; parms->output_map = output->answer; parms->group = group->answer; parms->subgroup = subgroup->answer; parms->sigfile = sigfile->answer; /* check all the inputs */ if (!I_find_group(parms->group)) G_fatal_error(_("Group <%s> not found"), parms->group); if (!I_find_subgroup(parms->group, parms->subgroup)) G_fatal_error(_("Subgroup <%s> not found"), parms->subgroup); if (sscanf(blocksize->answer, "%d", &parms->blocksize) != 1 || parms->blocksize <= 8) parms->blocksize = 8; return 0; }
int parse(int argc, char *argv[], struct parms *parms) { struct Option *group, *subgroup, *sigfile, *trainingmap, *maxsig; trainingmap = G_define_standard_option(G_OPT_R_MAP); trainingmap->key = "trainingmap"; trainingmap->description = _("Ground truth training map"); group = G_define_standard_option(G_OPT_I_GROUP); subgroup = G_define_standard_option(G_OPT_I_SUBGROUP); sigfile = G_define_option(); sigfile->key = "signaturefile"; sigfile->description = _("Name for output file containing result signatures"); sigfile->required = YES; sigfile->type = TYPE_STRING; maxsig = G_define_option(); maxsig->key = "maxsig"; maxsig->description = _("Maximum number of sub-signatures in any class"); maxsig->required = NO; maxsig->type = TYPE_INTEGER; maxsig->answer = "10"; if (G_parser(argc, argv)) exit(EXIT_FAILURE); parms->training_map = trainingmap->answer; parms->group = group->answer; parms->subgroup = subgroup->answer; parms->sigfile = sigfile->answer; /* check all the inputs */ if (G_find_raster(parms->training_map, "") == NULL) { G_fatal_error(_("Raster map <%s> not found"), parms->training_map); } if (!I_find_group(parms->group)) { G_fatal_error(_("Group <%s> not found"), parms->group); } if (!I_find_subgroup(parms->group, parms->subgroup)) { G_fatal_error(_("Subgroup <%s> not found"), parms->subgroup); } if (sscanf(maxsig->answer, "%d", &parms->maxsubclasses) != 1 || parms->maxsubclasses <= 0) { G_fatal_error(_("Illegal number of sub-signatures (%s)"), maxsig->answer); } return 0; }
int main(int argc, char *argv[]) { const char *input, *source, *output; char *title; struct Cell_head cellhd; GDALDatasetH hDS; GDALRasterBandH hBand; struct GModule *module; struct { struct Option *input, *source, *output, *band, *title; } parm; struct { struct Flag *o, *f, *e, *r, *h, *v; } flag; int min_band, max_band, band; struct band_info info; int flip; struct Ref reference; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("raster")); G_add_keyword(_("import")); G_add_keyword(_("input")); G_add_keyword(_("external")); module->description = _("Links GDAL supported raster data as a pseudo GRASS raster map."); parm.input = G_define_standard_option(G_OPT_F_INPUT); parm.input->description = _("Name of raster file to be linked"); parm.input->required = NO; parm.input->guisection = _("Input"); parm.source = G_define_option(); parm.source->key = "source"; parm.source->description = _("Name of non-file GDAL data source"); parm.source->required = NO; parm.source->type = TYPE_STRING; parm.source->key_desc = "name"; parm.source->guisection = _("Input"); parm.output = G_define_standard_option(G_OPT_R_OUTPUT); parm.band = G_define_option(); parm.band->key = "band"; parm.band->type = TYPE_INTEGER; parm.band->required = NO; parm.band->description = _("Band to select (default: all)"); parm.band->guisection = _("Input"); parm.title = G_define_option(); parm.title->key = "title"; parm.title->key_desc = "phrase"; parm.title->type = TYPE_STRING; parm.title->required = NO; parm.title->description = _("Title for resultant raster map"); parm.title->guisection = _("Metadata"); flag.f = G_define_flag(); flag.f->key = 'f'; flag.f->description = _("List supported formats and exit"); flag.f->guisection = _("Print"); flag.f->suppress_required = YES; flag.o = G_define_flag(); flag.o->key = 'o'; flag.o->description = _("Override projection (use location's projection)"); flag.e = G_define_flag(); flag.e->key = 'e'; flag.e->description = _("Extend location extents based on new dataset"); flag.r = G_define_flag(); flag.r->key = 'r'; flag.r->description = _("Require exact range"); flag.h = G_define_flag(); flag.h->key = 'h'; flag.h->description = _("Flip horizontally"); flag.v = G_define_flag(); flag.v->key = 'v'; flag.v->description = _("Flip vertically"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); GDALAllRegister(); if (flag.f->answer) { list_formats(); exit(EXIT_SUCCESS); } input = parm.input->answer; source = parm.source->answer; output = parm.output->answer; flip = 0; if (flag.h->answer) flip |= FLIP_H; if (flag.v->answer) flip |= FLIP_V; if (parm.title->answer) { title = G_store(parm.title->answer); G_strip(title); } else title = NULL; if (!input && !source) G_fatal_error(_("One of options <%s> or <%s> must be given"), parm.input->key, parm.source->key); if (input && source) G_fatal_error(_("Option <%s> and <%s> are mutually exclusive"), parm.input->key, parm.source->key); if (input && !G_is_absolute_path(input)) { char path[GPATH_MAX]; getcwd(path, sizeof(path)); strcat(path, "/"); strcat(path, input); input = G_store(path); } if (!input) input = source; hDS = GDALOpen(input, GA_ReadOnly); if (hDS == NULL) return 1; setup_window(&cellhd, hDS, &flip); check_projection(&cellhd, hDS, flag.o->answer); Rast_set_window(&cellhd); if (parm.band->answer) min_band = max_band = atoi(parm.band->answer); else min_band = 1, max_band = GDALGetRasterCount(hDS); G_verbose_message(_("Proceeding with import...")); if (max_band > min_band) { if (I_find_group(output) == 1) G_warning(_("Imagery group <%s> already exists and will be overwritten."), output); I_init_group_ref(&reference); } for (band = min_band; band <= max_band; band++) { char *output2, *title2 = NULL; G_message(_("Reading band %d of %d..."), band, GDALGetRasterCount( hDS )); hBand = GDALGetRasterBand(hDS, band); if (!hBand) G_fatal_error(_("Selected band (%d) does not exist"), band); if (max_band > min_band) { G_asprintf(&output2, "%s.%d", output, band); if (title) G_asprintf(&title2, "%s (band %d)", title, band); G_debug(1, "Adding raster map <%s> to group <%s>", output2, output); I_add_file_to_group_ref(output2, G_mapset(), &reference); } else { output2 = G_store(output); if (title) title2 = G_store(title); } query_band(hBand, output2, flag.r->answer, &cellhd, &info); create_map(input, band, output2, &cellhd, &info, title, flip); G_free(output2); G_free(title2); } if (flag.e->answer) update_default_window(&cellhd); /* Create the imagery group if multiple bands are imported */ if (max_band > min_band) { I_put_group_ref(output, &reference); I_put_group(output); G_message(_("Imagery group <%s> created"), output); } exit(EXIT_SUCCESS); }
int open_files(void) { char *name, *mapset; FILE *fd; int n; I_init_group_ref(&Ref); if (!I_find_group(group)) G_fatal_error(_("Group <%s> not found"), group); if (!I_find_subgroup(group, subgroup)) G_fatal_error(_("Subgroup <%s> in group <%s> not found"), subgroup, group); I_get_subgroup_ref(group, subgroup, &Ref); if (Ref.nfiles <= 1) { if (Ref.nfiles <= 0) G_fatal_error(_("Subgroup <%s> of group <%s> doesn't have any raster maps. " "The subgroup must have at least 2 raster maps.")); else G_fatal_error(_("Subgroup <%s> of group <%s> only has 1 raster map. " "The subgroup must have at least 2 raster maps.")); } cell = (DCELL **) G_malloc(Ref.nfiles * sizeof(DCELL *)); cellfd = (int *)G_malloc(Ref.nfiles * sizeof(int)); P = (double *)G_malloc(Ref.nfiles * sizeof(double)); for (n = 0; n < Ref.nfiles; n++) { cell[n] = Rast_allocate_d_buf(); name = Ref.file[n].name; mapset = Ref.file[n].mapset; cellfd[n] = Rast_open_old(name, mapset); } I_init_signatures(&S, Ref.nfiles); fd = I_fopen_signature_file_old(group, subgroup, sigfile); if (fd == NULL) G_fatal_error(_("Unable to open signature file <%s>"), sigfile); n = I_read_signatures(fd, &S); fclose(fd); if (n < 0) G_fatal_error(_("Unable to read signature file <%s>"), sigfile); if (S.nsigs > 255) G_fatal_error(_("<%s> has too many signatures (limit is 255)"), sigfile); B = (double *)G_malloc(S.nsigs * sizeof(double)); invert_signatures(); class_fd = Rast_open_c_new(class_name); class_cell = Rast_allocate_c_buf(); reject_cell = NULL; if (reject_name) { reject_fd = Rast_open_c_new(reject_name); reject_cell = Rast_allocate_c_buf(); } return 0; }
int main(int argc, char *argv[]) { struct GModule *module; struct Option *group_opt, *xc_opt, *yc_opt, *zc_opt, *xcsd_opt, *ycsd_opt, *zcsd_opt, *omega_opt, *phi_opt, *kappa_opt, *omegasd_opt, *phisd_opt, *kappasd_opt; struct Flag *use_flag, *print_flag; struct Ortho_Image_Group group; struct Ortho_Camera_Exp_Init *init_info; double deg2rad, rad2deg; G_gisinit(argv[0]); module = G_define_module(); G_add_keyword(_("imagery")); G_add_keyword(_("orthorectify")); module->description = _("Interactively creates or modifies entries in a camera " "initial exposure station file for imagery group referenced " "by a sub-block."); group_opt = G_define_standard_option(G_OPT_I_GROUP); group_opt->required = YES; group_opt->description = _("Name of imagery group for ortho-rectification"); xc_opt = G_define_option(); xc_opt->key = "xc"; xc_opt->type = TYPE_DOUBLE; xc_opt->description = _("Initial Camera Exposure X-coordinate"); yc_opt = G_define_option(); yc_opt->key = "yc"; yc_opt->type = TYPE_DOUBLE; yc_opt->description = _("Initial Camera Exposure Y-coordinate"); zc_opt = G_define_option(); zc_opt->key = "zc"; zc_opt->type = TYPE_DOUBLE; zc_opt->description = _("Initial Camera Exposure Z-coordinate"); xcsd_opt = G_define_option(); xcsd_opt->key = "xc_sd"; xcsd_opt->type = TYPE_DOUBLE; xcsd_opt->description = _("X-coordinate standard deviation"); ycsd_opt = G_define_option(); ycsd_opt->key = "yc_sd"; ycsd_opt->type = TYPE_DOUBLE; ycsd_opt->description = _("Y-coordinate standard deviation"); zcsd_opt = G_define_option(); zcsd_opt->key = "zc_sd"; zcsd_opt->type = TYPE_DOUBLE; zcsd_opt->description = _("Z-coordinate standard deviation"); omega_opt = G_define_option(); omega_opt->key = "omega"; omega_opt->type = TYPE_DOUBLE; omega_opt->description = _("Initial Camera Omega (roll) degrees"); phi_opt = G_define_option(); phi_opt->key = "omega"; phi_opt->type = TYPE_DOUBLE; phi_opt->description = _("Initial Camera Phi (pitch) degrees"); kappa_opt = G_define_option(); kappa_opt->key = "omega"; kappa_opt->type = TYPE_DOUBLE; kappa_opt->description = _("Initial Camera Kappa (yaw) degrees"); omegasd_opt = G_define_option(); omegasd_opt->key = "omega"; omegasd_opt->type = TYPE_DOUBLE; omegasd_opt->description = _("Omega (roll) standard deviation"); phisd_opt = G_define_option(); phisd_opt->key = "omega"; phisd_opt->type = TYPE_DOUBLE; phisd_opt->description = _("Phi (pitch) standard deviation"); kappasd_opt = G_define_option(); kappasd_opt->key = "omega"; kappasd_opt->type = TYPE_DOUBLE; kappasd_opt->description = _("Kappa (yaw) standard deviation"); use_flag = G_define_flag(); use_flag->key = 'r'; use_flag->description = _("Use initial values at run time"); print_flag = G_define_flag(); print_flag->key = 'p'; print_flag->description = _("Print initial values"); if (G_parser(argc, argv)) exit(EXIT_FAILURE); deg2rad = M_PI / 180.; rad2deg = 180. / M_PI; /* get group ref */ strcpy(group.name, group_opt->answer); if (!I_find_group(group.name)) { G_fatal_error(_("Group [%s] not found"), group.name); } G_debug(1, "Found group %s", group.name); /* get initial camera exposure info */ if (I_find_initial(group.name)) { I_get_init_info(group.name, &group.camera_exp); } else { /* create new initial camera exposure info */ /* all values must be given */ if (!xc_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), xc_opt->key); } if (!yc_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), yc_opt->key); } if (!zc_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), zc_opt->key); } if (!xcsd_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), xcsd_opt->key); } if (!ycsd_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), ycsd_opt->key); } if (!zcsd_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), zcsd_opt->key); } if (!omega_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), omega_opt->key); } if (!phi_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), phi_opt->key); } if (!kappa_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), kappa_opt->key); } if (!omegasd_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), omegasd_opt->key); } if (!phisd_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), phisd_opt->key); } if (!kappasd_opt->answer) { G_fatal_error(_("Option '%s' is required for new exposure info"), kappasd_opt->key); } } /* modify info */ init_info = &group.camera_exp; if (xc_opt->answer) { init_info->XC_init = atof(xc_opt->answer); } if (yc_opt->answer) { init_info->YC_init = atof(yc_opt->answer); } if (zc_opt->answer) { init_info->ZC_init = atof(zc_opt->answer); } if (xcsd_opt->answer) { init_info->XC_var = atof(xcsd_opt->answer); } if (ycsd_opt->answer) { init_info->YC_var = atof(ycsd_opt->answer); } if (zcsd_opt->answer) { init_info->ZC_var = atof(zcsd_opt->answer); } if (omega_opt->answer) { init_info->omega_init = atof(omega_opt->answer) * deg2rad; } if (phi_opt->answer) { init_info->phi_init = atof(phi_opt->answer) * deg2rad; } if (kappa_opt->answer) { init_info->kappa_init = atof(kappa_opt->answer) * deg2rad; } if (omegasd_opt->answer) { init_info->omega_var = atof(omegasd_opt->answer) * deg2rad; } if (phisd_opt->answer) { init_info->phi_var = atof(phisd_opt->answer) * deg2rad; } if (kappasd_opt->answer) { init_info->kappa_var = atof(kappasd_opt->answer) * deg2rad; } init_info->status = use_flag->answer != 0; if (print_flag->answer) { /* do not translate, scripts might want to parse the output */ fprintf(stdout, "xc=%.17g\n", init_info->XC_init); fprintf(stdout, "yc=%.17g\n", init_info->YC_init); fprintf(stdout, "zc=%.17g\n", init_info->ZC_init); fprintf(stdout, "xc_sd=%.17g\n", init_info->XC_var); fprintf(stdout, "yc_sd=%.17g\n", init_info->YC_var); fprintf(stdout, "zc_sd=%.17g\n", init_info->ZC_var); fprintf(stdout, "omega=%.17g\n", init_info->omega_init * rad2deg); fprintf(stdout, "phi=%.17g\n", init_info->phi_init * rad2deg); fprintf(stdout, "kappa=%.17g\n", init_info->kappa_init * rad2deg); fprintf(stdout, "omega_sd=%.17g\n", init_info->omega_var * rad2deg); fprintf(stdout, "phi_sd=%.17g\n", init_info->phi_var * rad2deg); fprintf(stdout, "kappa_sd=%.17g\n", init_info->kappa_var * rad2deg); fprintf(stdout, "use=%d", init_info->status); } /* save info */ I_put_init_info(group.name, &group.camera_exp); exit(EXIT_SUCCESS); }
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); }