[GRASS-SVN] r44500 -
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 30 10:01:16 EST 2010
Author: mmetz
Date: 2010-11-30 07:01:16 -0800 (Tue, 30 Nov 2010)
New Revision: 44500
Removed:
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_elev.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files2.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_wind.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/conv.c
Modified:
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_method.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear_f.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic_f.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/defs.h
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/get_wind.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/global.h
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/local_proto.h
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c
grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/nearest.c
Log:
sync to i.rectify part 1
Deleted: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_elev.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_elev.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_elev.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,99 +0,0 @@
-/* #include "gis.h" */
-#include <stdlib.h>
-#include <string.h>
-#include <grass/vask.h>
-#include "global.h"
-
-#define ZERO_DATA 0
-
-int ask_elev_data(void)
-{
- char buf1[60];
- char buf2[60];
- char units[10];
- char *tl; /* Target Location */
- char *elev_data; /* Tempoary elevation data layer */
- short ok;
- int no_data_value = ZERO_DATA;
-
- tl = (char *)G_calloc(40, sizeof(char));
- elev_data = (char *)G_calloc(40, sizeof(char));
- tl = G_location();
-
- sprintf(elev_data, "ELEV_DATA");
- sprintf(units, "METERS");
- *buf1 = '\0';
-
- ok = 0;
-
- /** Ask user if modification of elevation data is needed **/
- ok = G_yes("\nModify the data used for elevation ? ", ok);
- if (!ok) {
- select_target_env();
- if ((mapset_elev = G_find_cell(elev_layer, "")) == NULL)
- exit(0);
- select_current_env();
- return (0);
- }
-
- ok = 0;
- while (!ok) {
- /* List options on the screen for the user to answer */
- ok = 1;
- V_clear();
- V_line(1, "Please check the G_mapcalc convention:");
- V_line(3,
- "ELEV_DATA = CELL FILE [MAPSET in LOCATION] [MATH EXPERSION][UNITS]");
-
- V_line(5, "ELEV_DATA : ");
- V_line(6, "CELL FILE : ");
- V_line(7, "MAPSET : ");
- V_line(8, "LOCATION : ");
- V_line(9, "MATH EXPRESSION : ");
- V_line(10, "UNITS : ");
- V_line(12, "NO DATA VALUES = :");
-
-
- /* V_ques ( variable, type, row, col, length) ; */
- V_ques(elev_data, 's', 5, 20, 40);
- V_const(elev_layer, 's', 6, 20, 40);
- V_const(mapset_elev, 's', 7, 20, 40);
- V_const(tl, 's', 8, 20, 40);
- V_ques(buf1, 's', 9, 20, 40);
- V_const(units, 's', 10, 20, 10);
- V_ques(&no_data_value, 'i', 12, 20, 10);
-
- V_intrpt_ok();
- if (!V_call())
- exit(1);
-
- ok = 1;
- sprintf(buf2, "Gmapcalc %s = 'if(%s, %s %s , %d)'", elev_data,
- elev_layer, elev_layer, buf1, no_data_value);
-
- fprintf(stderr,
- "\n\n The following G_mapcalc syntax will be used \n for the modified elevation data\n\n");
- fprintf(stderr, "%s = 'if(%s, %s %s , %d)'", elev_data, elev_layer,
- elev_layer, buf1, no_data_value);
- ok = G_yes("\nDo you accept this G_mapcalc convention \n", ok);
- if (ok) {
-
- /** Set LOCATION to target location **/
- G_setenv("LOCATION_NAME", tl);
-
- /** system GMAPCALC **/
- G_system(buf2);
- /* elev_data becomes the new elevation layer */
- strcpy(elev_layer, elev_data);
- /* need mapset if changed */
- if ((mapset_elev = G_find_cell(elev_layer, "")) == NULL)
- exit(0);
- select_current_env();
-
- /** reset LOCATION to current location **/
- G_setenv("LOCATION_NAME", G_location());
-
- }
- }
- return (0);
-}
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -9,15 +9,10 @@
int ask_files(char *groupname)
{
- char line[NFILES][75];
char result[NFILES][15];
- char *err[NFILES];
int repeat;
- int duplicate;
- int list;
- char *name, *mapset;
- int i, k, f1, f2, ln;
- int any;
+ int do_all;
+ int i, k, f1;
int *r;
char **nm;
@@ -25,140 +20,86 @@
nm = new_name;
repeat = 0;
- for (i = 0; i < NFILES; i++)
- err[i] = "";
- for (i = 0; i < group.group_ref.nfiles && i < NFILES; i++) {
- if (strlen(group.group_ref.file[i].name) < 15)
- sprintf(result[i], group.group_ref.file[i].name);
- else
- sprintf(result[i], "%14s", group.group_ref.file[i].name);
- }
- for (; i < NFILES; i++)
- result[i][0] = 0;
- f1 = 0;
- for (f2 = f1; f1 < group.group_ref.nfiles; f1 = f2) {
- any = 0;
- ln = 2;
- V_clear();
- V_line(0,
- _("Please select the file(s) you wish to rectify by naming an output file"));
+ /* name extension for rectified maps */
+ extension = (char *)G_malloc(GNAME_MAX * sizeof(char));
+ sprintf(extension, ".ortho");
+
+ repeat = 1;
+ while (repeat) {
repeat = 0;
- for (i = 0; f2 < group.group_ref.nfiles && i < NFILES; i++, f2++) {
- name = group.group_ref.file[f2].name;
- mapset = group.group_ref.file[f2].mapset;
- if (G_find_cell(name, mapset)) {
- sprintf(line[i], "%s in %s", name, mapset);
- dots(line[i], 36);
- V_line(ln, line[i]);
- V_ques(result[i], 's', ln, 37, 14);
- V_const(err[i], 's', ln, 53, 25);
- any = 1;
- ln++;
- }
- }
- if (!any)
- break;
- V_line(ln + 2,
- "(enter list by any name to get a list of existing raster maps)");
+ V_clear();
+ V_line(1, _("Enter an extension to be appended to rectified maps:"));
+ V_ques(extension, 's', 3, 0, 20);
V_intrpt_ok();
if (!V_call())
exit(0);
- /* check the files for illegal names and duplicate names */
-
- list = 0;
- duplicate = 0;
- for (i = 0; i < NFILES; i++) {
- err[i] = "";
- G_strip(result[i]);
- if (result[i][0]) {
- if (strcmp(result[i], "list") == 0) {
- list = 1;
- result[i][0] = 0;
- }
- else if (G_legal_filename(result[i]) < 0) {
- err[i] = "** illegal name **";
- repeat = 1;
- }
- else {
- for (k = 0; k < i; k++) {
- if (!result[k][0])
- continue;
- if (strcmp(result[k], result[i]) != 0)
- continue;
- err[i] = "** duplicate name **";
- duplicate = 1;
- break;
- }
- if (duplicate)
- continue;
- for (k = 0; k < group.group_ref.nfiles; k++) {
- if (ref_list[k] < 0)
- continue;
- if (strcmp(new_name[k], result[i]) != 0)
- continue;
- err[i] = "** duplicate name **";
- duplicate = 1;
- break;
- }
- }
+ /* test for legal file name */
+ sprintf(result[0], "%s%s", group.group_ref.file[0].name, extension);
+ if (G_legal_filename(result[0]) < 0) {
+ G_clear_screen();
+ fprintf(stderr, _("Extension <%s> is illegal"), extension);
+ repeat = G_yes(_("\nChoose another extension? "), 1);
+ if (!repeat) {
+ fprintf(stderr,_("Orthorectification cancelled."));
+ exit(0);
}
}
- if (duplicate)
- repeat = 1;
+ }
+
+ G_debug(1, "Extension: %s", extension);
- /* list the raster maps in the target location. must switch
- * environments to do this
- */
- if (list) {
- repeat = 1;
- select_target_env();
- G_set_list_hit_return(1);
- G_list_element("cell", "raster", G_mapset(), (int (*)())0);
- select_current_env();
- }
+ /* rectify all files ? */
+ do_all = 1;
+ G_clear_screen();
+ do_all = G_yes(_("\nRectify all files in the group? "), do_all);
- if (repeat) {
- f2 = f1;
- continue;
+ /* create list of files to be rectified */
+ f1 = 0;
+ for (i = 0; i < group.group_ref.nfiles && i < NFILES; i++) {
+ int ok = 1;
+ char buf[100];
+
+ if (!do_all) {
+ sprintf(buf, _("\nRectify image <%s>? "), group.group_ref.file[i].name);
+ ok = G_yes(buf, ok);
}
- /* check for existing raster maps
- * this check must occur in the target location, so we switch
- * environments to be in the target location
- */
- select_target_env();
- for (i = 0; i < NFILES; i++) {
- if (result[i][0] && G_find_cell(result[i], G_mapset())) {
- if (!repeat++) {
- repeat = 1;
- fprintf(stderr, "\n");
- fprintf(stderr,
- "** The following raster maps already exist in\n");
- fprintf(stderr, "** LOCATION %s, MAPSET %s:\n\n",
- G_location(), G_mapset());
- }
- fprintf(stderr, "%-18s%s", result[i],
- repeat % 4 ? " " : "\n");
- err[i] = "** file exists **";
- }
+ if (ok) {
+ sprintf(result[i], "%s%s", group.group_ref.file[i].name, extension);
+ *r++ = f1++;
+ *nm++ = G_store(result[i]);
}
- select_current_env();
- if (repeat) {
- repeat = !G_yes("\n\nOk to overwrite? ", 0);
- }
- if (repeat) {
- f2 = f1;
- continue;
- }
+ }
+ for (i = f1; i < NFILES; i++) {
+ result[i][0] = 0;
+ }
- for (i = 0; i < NFILES; i++) {
- if (result[i][0]) {
- *r++ = f1 + i;
- *nm++ = G_store(result[i]);
+ /* check if raster exists in target location/mapset */
+ select_target_env();
+ repeat = 0;
+ G_clear_screen();
+ for (i = 0; i < NFILES; i++) {
+ if (result[i][0] && G_find_cell(result[i], G_mapset())) {
+ if (!repeat++) {
+ repeat = 1;
+ fprintf(stderr, "\n");
+ fprintf(stderr,
+ "** The following raster maps already exist in\n");
+ fprintf(stderr, "** LOCATION %s, MAPSET %s:\n\n",
+ G_location(), G_mapset());
}
+ fprintf(stderr, "%-18s\n", result[i]);
}
}
+ select_current_env();
+ if (repeat) {
+ if (!G_yes("\n\nOk to overwrite? ", 0)) {
+ fprintf(stderr,_("Orthorectification cancelled."));
+ exit(0);
+ }
+ }
+
for (k = 0; k < group.group_ref.nfiles; k++)
if (ref_list[k] >= 0)
return 1;
@@ -166,22 +107,3 @@
G_sleep(3);
exit(0);
}
-
-int dots(char *buf, int n)
-{
- int k;
-
- for (k = 0; *buf; k++)
- buf++;
- if (k >= n)
- return 1;
- *buf++ = ' ';
- k++;
- while (k < n) {
- *buf++ = k % 2 ? '.' : ' ';
- k++;
- }
- *buf = 0;
-
- return 0;
-}
Deleted: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files2.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files2.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_files2.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,80 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include "global.h"
-#include <grass/vask.h>
-
-#define NFILES 15
-
-int ask_file_from_list(char *name, char *mapset)
-{
- char line[NFILES][75];
- char use[NFILES][3];
- int index[NFILES];
- int i, k, n, f1, f2, ln;
- int count;
- int same;
- struct Cell_head win1, win2;
-
- count = 0;
- same = 1;
- for (f1 = 0; f1 < group.group_ref.nfiles; f1++) {
- if (ref_list[f1] >= 0) {
- if (count++ == 0) {
- f2 = ref_list[f1];
- G_get_cellhd(group.group_ref.file[f2].name,
- group.group_ref.file[f2].mapset, &win1);
- }
- else if (same) {
- k = ref_list[f1];
- G_get_cellhd(group.group_ref.file[k].name,
- group.group_ref.file[k].mapset, &win2);
- if (win1.north != win2.north || win1.south != win2.south ||
- win1.east != win2.east || win1.west != win2.west ||
- win1.ns_res != win2.ns_res || win1.ew_res != win2.ew_res)
- same = 0;
- }
- }
- }
- if (count == 1 || same) {
- strcpy(name, group.group_ref.file[f2].name);
- strcpy(mapset, group.group_ref.file[f2].mapset);
- return 1;
- }
- while (1) {
- f1 = 0;
- for (f2 = f1; f1 < group.group_ref.nfiles; f1 = f2) {
- ln = 3;
- V_clear();
- V_line(0,
- "Please mark one file to use as a reference for the window");
- for (i = 0; i < NFILES; i++)
- use[i][0] = 0;
- for (i = 0; f2 < group.group_ref.nfiles && i < NFILES; i++, f2++) {
- if (ref_list[f2] < 0) {
- i--;
- continue;
- }
- n = index[i] = ref_list[f2];
- sprintf(line[i], " %s in %s", group.group_ref.file[n].name,
- group.group_ref.file[n].mapset);
- V_line(ln, line[i]);
- V_ques(use[i], 's', ln, 1, 1);
- ln++;
- }
- if (i == 0)
- break;
- V_intrpt_ok();
- if (!V_call())
- exit(0);
-
- for (i = 0; i < NFILES; i++) {
- if (use[i][0]) {
- n = index[i];
- strcpy(name, group.group_ref.file[n].name);
- strcpy(mapset, group.group_ref.file[n].mapset);
- return 0;
- }
- }
- }
- }
-}
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_method.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_method.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_method.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -13,6 +13,7 @@
while (1) {
char buf[100];
+ G_clear_screen();
fprintf(stderr, _("Please select one of the following interpolation methods\n"));
fprintf(stderr, _(" 1. nearest neighbor\n"));
fprintf(stderr, _(" 2. bilinear\n"));
Deleted: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_wind.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_wind.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/ask_wind.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,203 +0,0 @@
-#include <stdlib.h>
-#include <string.h>
-#include <grass/gis.h>
-#include <grass/vask.h>
-
-static int rnd(double *);
-static int visually_equal(double, double);
-
-int ask_window(struct Cell_head *window)
-{
- double south, west;
- char buff[64];
- short ok;
- struct Cell_head minimal;
-
- rnd(&window->north);
- rnd(&window->south);
- rnd(&window->west);
- rnd(&window->east);
- rnd(&window->ew_res);
- rnd(&window->ns_res);
- G_copy(&minimal, window, sizeof(minimal));
-
- window->rows = 0;
- window->cols = 0;
-
- ok = 0;
- while (!ok) {
- /* List window options on the screen for the user to answer */
-
- ok = 1;
- V_clear();
- V_line(0, "Please set the target window");
- V_line(2,
- " ============================= MINIMAL WINDOW ========");
- V_line(3,
- " | North: |");
- V_line(4,
- " | |");
- V_line(5,
- " | ======= GEOREF WINDOW ======= |");
- V_line(6,
- " | | NORTH EDGE: | |");
- V_line(7,
- " | | | |");
- V_line(8,
- " West |WEST EDGE | |EAST EDGE | East");
- V_line(9,
- " | | | |");
- V_line(10,
- " | | SOUTH EDGE: | |");
- V_line(11,
- " | ============================= |");
- V_line(12,
- " | |");
- V_line(13,
- " | South: |");
- V_line(14,
- " =====================================================");
-
- V_line(16,
- " Minimal GRID RESOLUTION Window ");
- V_line(17,
- " --- East-West --- ");
- V_line(18,
- " -- North-South -- ");
- V_line(20,
- "(Minimal window is just large enough to hold entire image)");
-
- /* V_ques ( variable, type, row, col, length) ; */
- V_ques(&window->north, 'd', 6, 36, 11);
- V_ques(&window->south, 'd', 10, 36, 11);
- V_ques(&window->west, 'd', 9, 12, 11);
- V_ques(&window->east, 'd', 9, 52, 11);
- V_ques(&window->ew_res, 'd', 17, 47, 7);
- V_ques(&window->ns_res, 'd', 18, 47, 7);
-
- V_const(&minimal.north, 'd', 3, 36, 11);
- V_const(&minimal.south, 'd', 13, 36, 11);
- V_const(&minimal.west, 'd', 9, 1, 11);
- V_const(&minimal.east, 'd', 9, 66, 11);
- V_const(&minimal.ew_res, 'd', 17, 19, 7);
- V_const(&minimal.ns_res, 'd', 18, 19, 7);
-
- V_intrpt_ok();
- if (!V_call())
- exit(1);
-
- rnd(&window->north);
- rnd(&window->south);
- rnd(&window->east);
- rnd(&window->west);
- rnd(&window->ew_res);
- rnd(&window->ns_res);
-
- if ((window->ns_res <= 0) || (window->ew_res <= 0)) {
- fprintf(stderr, "Illegal resolution value(s)\n");
- ok = 0;
- }
- if (window->north <= window->south) {
- fprintf(stderr, "North must be larger than south\n");
- ok = 0;
- }
- if (window->east <= window->west) {
- fprintf(stderr, "East must be larger than west\n");
- ok = 0;
- }
- if (!ok) {
- fprintf(stderr, "hit RETURN -->");
- G_gets(buff);
- continue;
- }
-
- /* if the north-south is not multiple of the resolution,
- * round the south downward
- */
- south = window->south;
- window->rows =
- (window->north - window->south +
- window->ns_res / 2) / window->ns_res;
- window->south = window->north - window->rows * window->ns_res;
-
- /* do the same for the west */
- west = window->west;
- window->cols =
- (window->east - window->west +
- window->ew_res / 2) / window->ew_res;
- window->west = window->east - window->cols * window->ew_res;
-
- fprintf(stderr, "\n\n");
-
- fprintf(stderr, " north: %12.2f\n", window->north);
- fprintf(stderr, " south: %12.2f", window->south);
-
- if (!visually_equal(window->south, south))
- fprintf(stderr, " (Changed to match resolution)");
- fprintf(stderr, "\n");
-
- fprintf(stderr, " east: %12.2f\n", window->east);
- fprintf(stderr, " west: %12.2f", window->west);
-
- if (!visually_equal(window->west, west))
- fprintf(stderr, " (Changed to match resolution)");
- fprintf(stderr, "\n");
-
- fprintf(stderr, "\n");
- fprintf(stderr, " e-w res: %12.2f\n", window->ew_res);
- fprintf(stderr, " n-s res: %12.2f\n", window->ns_res);
- fprintf(stderr, " total rows: %12d\n", window->rows);
- fprintf(stderr, " total cols: %12d\n", window->cols);
- fprintf(stderr, " total cells: %12d\n", window->rows * window->cols);
- fprintf(stderr, "\n");
-
- ok = 1;
- if (window->north > minimal.north) {
- fprintf(stderr,
- "warning - north falls outside the minimal window\n");
- ok = 0;
- }
- if (window->south < minimal.south) {
- fprintf(stderr,
- "warning - south falls outside the minimal window\n");
- ok = 0;
- }
- if (window->east > minimal.east) {
- fprintf(stderr,
- "warning - east falls outside the minimal window\n");
- ok = 0;
- }
- if (window->west < minimal.west) {
- fprintf(stderr,
- "warning - west falls outside the minimal window\n");
- ok = 0;
- }
-
- ok = G_yes("\nDo you accept this window? ", ok);
- }
-
- return 0;
-}
-
-static int visually_equal(double x, double y)
-{
- char xs[40], ys[40];
-
- if (x == y)
- return 1;
-
- sprintf(xs, "%.2f", x);
- sprintf(ys, "%.2f", y);
-
- return strcmp(xs, ys) == 0;
-}
-
-static int rnd(double *x)
-{
- char xs[40];
-
- sprintf(xs, "%.2f", *x);
- sscanf(xs, "%lf", x);
-
- return 0;
-}
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -14,12 +14,12 @@
#include <grass/gis.h>
#include "global.h"
-void p_bilinear(struct cache *ibuffer, /* input buffer */
- void *obufptr, /* ptr in output buffer */
- int cell_type, /* raster map type of obufptr */
- double *row_idx, /* row index */
- double *col_idx, /* column index */
- struct Cell_head *cellhd /* information of output map */
+void p_bilinear(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *row_idx, /* row index */
+ double *col_idx, /* column index */
+ struct Cell_head *cellhd /* information of output map */
)
{
int row; /* row indices for interp */
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear_f.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear_f.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/bilinear_f.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -12,12 +12,12 @@
#include <math.h>
#include "global.h"
-void p_bilinear_f(struct cache *ibuffer, /* input buffer */
- void *obufptr, /* ptr in output buffer */
- int cell_type, /* raster map type of obufptr */
- double *row_idx, /* row index */
- double *col_idx, /* column index */
- struct Cell_head *cellhd /* cell header of input layer */
+void p_bilinear_f(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *row_idx, /* row index */
+ double *col_idx, /* column index */
+ struct Cell_head *cellhd /* cell header of input layer */
)
{
/* start nearest neighbor to do some basic tests */
Deleted: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/conv.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/conv.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/conv.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,49 +0,0 @@
-#include "global.h"
-/* conversion routines to convert from view x,y to cell col,row
- * as well as cell col,row to cell east,north
- */
-int view_to_col(View * view, int x)
-{
- return x - view->cell.left;
-}
-
-int view_to_row(View * view, int y)
-{
- return y - view->cell.top;
-}
-
-int col_to_view(View * view, int col)
-{
- return view->cell.left + col;
-}
-
-int row_to_view(View * view, int row)
-{
- return view->cell.top + row;
-}
-
-/* in these next 2 routines, location determines if we are
- * converting from center of the cell (location == .5)
- * top or left edge (location == 0.0)
- * bottom or right edge (location == 1.0)
- */
-
-double row_to_northing(struct Cell_head *cellhd, int row, double location)
-{
- return cellhd->north - (row + location) * cellhd->ns_res;
-}
-
-double col_to_easting(struct Cell_head *cellhd, int col, double location)
-{
- return cellhd->west + (col + location) * cellhd->ew_res;
-}
-
-double northing_to_row(struct Cell_head *cellhd, double north)
-{
- return (cellhd->north - north) / cellhd->ns_res;
-}
-
-double easting_to_col(struct Cell_head *cellhd, double east)
-{
- return (east - cellhd->west) / cellhd->ew_res;
-}
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -16,12 +16,12 @@
#include <math.h>
#include "global.h"
-void p_cubic(struct cache *ibuffer, /* input buffer */
- void *obufptr, /* ptr in output buffer */
- int cell_type, /* raster map type of obufptr */
- double *row_idx, /* row index (decimal) */
- double *col_idx, /* column index (decimal) */
- struct Cell_head *cellhd /* information of output map */
+void p_cubic(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *row_idx, /* row index (decimal) */
+ double *col_idx, /* column index (decimal) */
+ struct Cell_head *cellhd /* information of output map */
)
{
int row; /* row indices for interp */
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic_f.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic_f.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/cubic_f.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -13,12 +13,12 @@
#include <math.h>
#include "global.h"
-void p_cubic_f(struct cache *ibuffer, /* input buffer */
- void *obufptr, /* ptr in output buffer */
- int cell_type, /* raster map type of obufptr */
- double *row_idx, /* row index */
- double *col_idx, /* column index */
- struct Cell_head *cellhd /* cell header of input layer */
+void p_cubic_f(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *row_idx, /* row index */
+ double *col_idx, /* column index */
+ struct Cell_head *cellhd /* cell header of input layer */
)
{
/* start nearest neighbor to do some basic tests */
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/defs.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/defs.h 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/defs.h 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,56 +1,28 @@
-#include <curses.h>
-#include <grass/rowio.h>
-#include "orthophoto.h"
+/* cache for raster data, code taken from r.proj */
-/* this is a curses structure */
-typedef struct
-{
- int top, left, bottom, right;
-} Window;
+#define L2BDIM 6
+#define BDIM (1<<(L2BDIM))
+#define L2BSIZE (2*(L2BDIM))
+#define BSIZE (1<<(L2BSIZE))
+#define HI(i) ((i)>>(L2BDIM))
+#define LO(i) ((i)&((BDIM)-1))
-/* this is a graphics structure */
-typedef struct
-{
- int top, bottom, left, right;
- int nrows, ncols;
- struct
- {
- int configured;
- struct Cell_head head;
- char name[30];
- char mapset[30];
- int top, bottom, left, right;
- double ew_res, ns_res; /* original map resolution */
- } cell;
-} View;
+typedef DCELL block[BDIM][BDIM]; /* FCELL sufficient ? */
-typedef struct
+struct cache
{
- int type; /* object type */
- int (*handler) (); /* routine to handle the event */
- char *label; /* label to display if MENU or OPTION */
- int binding; /* OPTION bindings */
- int *status; /* MENU,OPTION status */
- int top, bottom, left, right;
-} Objects;
+ int fd;
+ int stride;
+ int nblocks;
+ block **grid;
+ block *blocks;
+ int *refs;
+};
-typedef struct
-{
- double E12[3], N12[3], E21[3], N21[3];
-} Patch;
+typedef void (*func) (struct cache *, void *, int, double *, double *, struct Cell_head *);
+#define BKIDX(c,y,x) ((y) * (c)->stride + (x))
+#define BKPTR(c,y,x) ((c)->grid[BKIDX((c),(y),(x))])
+#define BLOCK(c,y,x) (BKPTR((c),(y),(x)) ? BKPTR((c),(y),(x)) : get_block((c),BKIDX((c),(y),(x))))
+#define CPTR(c,y,x) (&(*BLOCK((c),HI((y)),HI((x))))[LO((y))][LO((x))])
-#define MENU_OBJECT 1
-#define OPTION_OBJECT 2
-#define INFO_OBJECT 3
-#define OTHER_OBJECT 4
-
-
-#define MENU(label,handler,status) \
- {MENU_OBJECT,handler,label,0,status,0,0,0,0}
-#define OPTION(label,binding,status) \
- {OPTION_OBJECT,NULL,label,binding,status,0,0,0,0}
-#define INFO(label,status) \
- {INFO_OBJECT,NULL,label,0,status,0,0,0,0}
-#define OTHER(handler,status) \
- {OTHER_OBJECT,handler,NULL,0,status,0,0,0,0}
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/get_wind.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/get_wind.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/get_wind.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -3,10 +3,60 @@
#include <math.h>
#include "global.h"
+int get_ref_window(struct Cell_head *cellhd)
+{
+ int k, f1, f2;
+ int count;
+ struct Cell_head win;
+
+ /* from all the files in the group, get max extends and min resolutions */
+ count = 0;
+ for (f1 = 0; f1 < group.group_ref.nfiles; f1++) {
+ if (ref_list[f1] >= 0) {
+ if (count++ == 0) {
+ f2 = ref_list[f1];
+ G_get_cellhd(group.group_ref.file[f2].name,
+ group.group_ref.file[f2].mapset, cellhd);
+ }
+ else {
+ k = ref_list[f1];
+ G_get_cellhd(group.group_ref.file[k].name,
+ group.group_ref.file[k].mapset, &win);
+ /* extends */
+ if (cellhd->north < win.north)
+ cellhd->north = win.north;
+ if (cellhd->south > win.south)
+ cellhd->south = win.south;
+ if (cellhd->west > win.west)
+ cellhd->west = win.west;
+ if (cellhd->east < win.east)
+ cellhd->east = win.east;
+ /* resolution */
+ if (cellhd->ns_res > win.ns_res)
+ cellhd->ns_res = win.ns_res;
+ if (cellhd->ew_res > win.ew_res)
+ cellhd->ew_res = win.ew_res;
+ }
+ }
+ }
+
+ /* if the north-south is not multiple of the resolution,
+ * round the south downward
+ */
+ cellhd->rows = (cellhd->north - cellhd->south) /cellhd->ns_res + 0.5;
+ cellhd->south = cellhd->north - cellhd->rows * cellhd->ns_res;
+
+ /* do the same for the west */
+ cellhd->cols = (cellhd->east - cellhd->west) / cellhd->ew_res + 0.5;
+ cellhd->west = cellhd->east - cellhd->cols * cellhd->ew_res;
+
+ return 1;
+}
+
int get_target_window(void)
{
- char name[30], mapset[30];
struct Cell_head cellhd;
+ double res;
fprintf(stderr, "\n\n");
while (1) {
@@ -23,33 +73,48 @@
G_strip(buf);
if (strcmp(buf, "1") == 0) {
-
- /**ask_window (&target_window);**/
return 1;
}
if (strcmp(buf, "2") == 0)
break;
}
- ask_file_from_list(name, mapset);
+
+ /* ask for target resolution */
+ while (1) {
+ char buf[100];
- G_debug(1, "ask_file: %s in %s", name, mapset);
+ fprintf(stderr, "Desired target resolution\n");
+ fprintf(stderr,
+ " RETURN determine automatically\n");
+ fprintf(stderr, "> ");
+ if (!G_gets(buf))
+ continue;
- if (G_get_cellhd(name, mapset, &cellhd) < 0)
- exit(EXIT_FAILURE);
+ if (*buf == 0) { /* determine automatically */
+ res = -1;
+ break;
+ }
+ G_strip(buf);
+ if ((res = atof(buf)) <= 0) {
+ fprintf(stderr, "Resolution must be larger than zero!");
+ G_clear_screen();
+ }
+ else
+ break;
+ }
+
+ /* get reference window: max extend, min resolution */
+ get_ref_window(&cellhd);
+
G_debug(1, "current window: n s = %f %f,", cellhd.north,
cellhd.south);
G_debug(1, "current window: w e = %f %f,", cellhd.west,
cellhd.east);
- georef_window(&cellhd, &target_window);
- ask_window(&target_window);
-
-/**
- if(!G_yes("Would you like this window saved as the window in the target location?\n", -1))
- return 0;
-**/
+ georef_window(&cellhd, &target_window, res);
+
select_target_env();
if (G_put_window(&target_window) >= 0)
fprintf(stderr, "Window Saved!\n");
@@ -57,7 +122,7 @@
return 0;
}
-int georef_window(struct Cell_head *w1, struct Cell_head *w2)
+int georef_window(struct Cell_head *w1, struct Cell_head *w2, double res)
{
double n, e, z1, ad;
double n0, e0;
@@ -151,43 +216,48 @@
if (e < w2->west)
w2->west = e;
- /* this results in ugly res values, and ns_res != ew_res */
- /* and is no good for rotation */
- /*
- w2->ns_res = (w2->north - w2->south) / w1->rows;
- w2->ew_res = (w2->east - w2->west) / w1->cols;
- */
+ /* resolution */
+ if (res > 0)
+ w2->ew_res = w2->ns_res = res;
+ else {
+ /* this results in ugly res values, and ns_res != ew_res */
+ /* and is no good for rotation */
+ /*
+ w2->ns_res = (w2->north - w2->south) / w1->rows;
+ w2->ew_res = (w2->east - w2->west) / w1->cols;
+ */
- /* alternative: account for rotation and order > 1 */
+ /* alternative: account for rotation and order > 1 */
- /* N-S extends along western and eastern edge */
- w2->ns_res = (sqrt((nw.n - sw.n) * (nw.n - sw.n) +
- (nw.e - sw.e) * (nw.e - sw.e)) +
- sqrt((ne.n - se.n) * (ne.n - se.n) +
- (ne.e - se.e) * (ne.e - se.e))) / (2.0 * w1->rows);
+ /* N-S extends along western and eastern edge */
+ w2->ns_res = (sqrt((nw.n - sw.n) * (nw.n - sw.n) +
+ (nw.e - sw.e) * (nw.e - sw.e)) +
+ sqrt((ne.n - se.n) * (ne.n - se.n) +
+ (ne.e - se.e) * (ne.e - se.e))) / (2.0 * w1->rows);
- /* E-W extends along northern and southern edge */
- w2->ew_res = (sqrt((nw.n - ne.n) * (nw.n - ne.n) +
- (nw.e - ne.e) * (nw.e - ne.e)) +
- sqrt((sw.n - se.n) * (sw.n - se.n) +
- (sw.e - se.e) * (sw.e - se.e))) / (2.0 * w1->cols);
+ /* E-W extends along northern and southern edge */
+ w2->ew_res = (sqrt((nw.n - ne.n) * (nw.n - ne.n) +
+ (nw.e - ne.e) * (nw.e - ne.e)) +
+ sqrt((sw.n - se.n) * (sw.n - se.n) +
+ (sw.e - se.e) * (sw.e - se.e))) / (2.0 * w1->cols);
- /* make ew_res = ns_res */
- w2->ns_res = (w2->ns_res + w2->ew_res) / 2.0;
- w2->ew_res = w2->ns_res;
+ /* make ew_res = ns_res */
+ w2->ns_res = (w2->ns_res + w2->ew_res) / 2.0;
+ w2->ew_res = w2->ns_res;
- /* nice round values */
- if (w2->ns_res > 1) {
- if (w2->ns_res < 10) {
- /* round to first decimal */
- w2->ns_res = (int)(w2->ns_res * 10 + 0.5) / 10.0;
- w2->ew_res = w2->ns_res;
+ /* nice round values */
+ if (w2->ns_res > 1) {
+ if (w2->ns_res < 10) {
+ /* round to first decimal */
+ w2->ns_res = (int)(w2->ns_res * 10 + 0.5) / 10.0;
+ w2->ew_res = w2->ns_res;
+ }
+ else {
+ /* round to integer */
+ w2->ns_res = (int)(w2->ns_res + 0.5);
+ w2->ew_res = w2->ns_res;
+ }
}
- else {
- /* round to integer */
- w2->ns_res = (int)(w2->ns_res + 0.5);
- w2->ew_res = w2->ns_res;
- }
}
/* adjust extends */
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/global.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/global.h 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/global.h 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,13 +1,7 @@
-/* These next defines determine the size of the sub-window that will
- * be held in memory. Larger values will require
- * more memory (but less i/o) If you increase these values, keep in
- * mind that although you think the i/o will decrease, system paging
- * (which goes on behind the scenes) may actual increase the i/o.
- */
-
#include <grass/imagery.h>
#include <grass/ortholib.h>
#include <grass/glocale.h>
+#include "orthophoto.h"
#include "defs.h"
#ifndef GLOBAL
@@ -19,35 +13,17 @@
GLOBAL FILE *Bugsr;
#endif
-#define L2BDIM 6
-#define BDIM (1<<(L2BDIM))
-#define L2BSIZE (2*(L2BDIM))
-#define BSIZE (1<<(L2BSIZE))
-#define HI(i) ((i)>>(L2BDIM))
-#define LO(i) ((i)&((BDIM)-1))
+GLOBAL func interpolate; /* interpolation routine */
-typedef DCELL block[BDIM][BDIM];
-
-struct cache
-{
- int fd;
- int stride;
- int nblocks;
- block **grid;
- block *blocks;
- int *refs;
-};
-
-typedef void (*func) (struct cache *, void *, int, double *, double *, struct Cell_head *);
-
-GLOBAL func interpolate; /* interpolation routine */
-
GLOBAL int seg_mb_img, seg_mb_elev;
GLOBAL char *method;
GLOBAL int temp_fd;
GLOBAL CELL **cell_buf;
GLOBAL char *temp_name;
+GLOBAL char *extension;
+GLOBAL double target_res;
+
GLOBAL int *ref_list;
GLOBAL char **new_name;
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/local_proto.h
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/local_proto.h 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/local_proto.h 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,32 +1,12 @@
-/* ask_elev.c */
-int ask_elev_data(void);
-
/* ask_files.c */
int ask_files(char *);
-int dots(char *, int);
-/* ask_files2.c */
-int ask_file_from_list(char *, char *);
-
/* ask_method.c */
int ask_method(void);
-/* ask_wind.c */
-int ask_window(struct Cell_head *);
-
/* aver_z.c */
int get_aver_elev(struct Ortho_Control_Points *, double *);
-/* conv.c */
-int view_to_col(View *, int);
-int view_to_row(View *, int);
-int col_to_view(View *, int);
-int row_to_view(View *, int);
-double row_to_northing(struct Cell_head *, int, double);
-double col_to_easting(struct Cell_head *, int, double);
-double northing_to_row(struct Cell_head *, double);
-double easting_to_col(struct Cell_head *, double);
-
/* cp.c */
int get_conz_points(void);
int get_ref_points(void);
@@ -48,7 +28,7 @@
/* get_wind.c */
int get_target_window(void);
-int georef_window(struct Cell_head *, struct Cell_head *);
+int georef_window(struct Cell_head *, struct Cell_head *, double);
/* rectify.c */
int rectify(char *, char *, struct cache *, double, char *);
@@ -57,11 +37,6 @@
struct cache *readcell(int, int, int);
block *get_block(struct cache *, int);
-#define BKIDX(c,y,x) ((y) * (c)->stride + (x))
-#define BKPTR(c,y,x) ((c)->grid[BKIDX((c),(y),(x))])
-#define BLOCK(c,y,x) (BKPTR((c),(y),(x)) ? BKPTR((c),(y),(x)) : get_block((c),BKIDX((c),(y),(x))))
-#define CPTR(c,y,x) (&(*BLOCK((c),HI((y)),HI((x))))[LO((y))][LO((x))])
-
/* report.c */
int report(char *, char *, char *, long, long, int);
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/main.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -40,7 +40,6 @@
struct GModule *module;
struct Option *group_opt;
-
/* must run in a term window */
G_putenv("GRASS_UI_TERM", "1");
@@ -63,7 +62,7 @@
strcpy(name, group_opt->answer);
- camera = (char *)G_malloc(40 * sizeof(char));
+ camera = (char *)G_malloc(GNAME_MAX * sizeof(char));
elev_layer = (char *)G_malloc(GNAME_MAX * sizeof(char));
mapset_elev = (char *)G_malloc(GMAPSET_MAX * sizeof(char));
@@ -73,7 +72,8 @@
G_fatal_error(_("Group [%s] not found"), group.name);
/* get the group ref */
- I_get_group_ref(group.name, (struct Ref *)&group.group_ref);
+ if (!I_get_group_ref(group.name, (struct Ref *)&group.group_ref))
+ G_fatal_error(_("Could not read REF file for group [%s]"), group.name);
nfiles = group.group_ref.nfiles;
if (nfiles <= 0)
G_fatal_error(_("No files in this group!"));
@@ -133,7 +133,7 @@
/* ask for interpolation method and amount of memory to be used */
ask_method();
- /* go do it */
+ /* go do it */
exec_rectify();
exit(EXIT_SUCCESS);
Modified: grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/nearest.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/nearest.c 2010-11-30 10:03:47 UTC (rev 44499)
+++ grass/branches/develbranch_6/imagery/i.ortho.photo/photo.rectify/nearest.c 2010-11-30 15:01:16 UTC (rev 44500)
@@ -1,4 +1,3 @@
-
/*
* nearest.c - returns the nearest neighbor to a given
* x,y position
@@ -8,12 +7,12 @@
#include <grass/gis.h>
#include "global.h"
-void p_nearest(struct cache *ibuffer, /* input buffer */
- void *obufptr, /* ptr in output buffer */
- int cell_type, /* raster map type of obufptr */
- double *row_idx, /* row index in input matrix */
- double *col_idx, /* column index in input matrix */
- struct Cell_head *cellhd /* cell header of input layer */
+void p_nearest(struct cache *ibuffer, /* input buffer */
+ void *obufptr, /* ptr in output buffer */
+ int cell_type, /* raster map type of obufptr */
+ double *row_idx, /* row index in input matrix */
+ double *col_idx, /* column index in input matrix */
+ struct Cell_head *cellhd /* cell header of input layer */
)
{
int row, col; /* row/col of nearest neighbor */
More information about the grass-commit
mailing list