[GRASS-SVN] r47351 - grass-addons/grass7/imagery/i.points.auto
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 2 08:25:32 EDT 2011
Author: mmetz
Date: 2011-08-02 05:25:32 -0700 (Tue, 02 Aug 2011)
New Revision: 47351
Added:
grass-addons/grass7/imagery/i.points.auto/creat_rand.c
grass-addons/grass7/imagery/i.points.auto/crs.c
grass-addons/grass7/imagery/i.points.auto/crs.h
grass-addons/grass7/imagery/i.points.auto/i.points.auto.html
grass-addons/grass7/imagery/i.points.auto/overlap.c
Removed:
grass-addons/grass7/imagery/i.points.auto/analyze.c
grass-addons/grass7/imagery/i.points.auto/ask.c
grass-addons/grass7/imagery/i.points.auto/ask_mag.c
grass-addons/grass7/imagery/i.points.auto/call.c
grass-addons/grass7/imagery/i.points.auto/cell.c
grass-addons/grass7/imagery/i.points.auto/colors.c
grass-addons/grass7/imagery/i.points.auto/conv.c
grass-addons/grass7/imagery/i.points.auto/curses.c
grass-addons/grass7/imagery/i.points.auto/debug.c
grass-addons/grass7/imagery/i.points.auto/description.html
grass-addons/grass7/imagery/i.points.auto/digit.c
grass-addons/grass7/imagery/i.points.auto/dot.c
grass-addons/grass7/imagery/i.points.auto/drawcell.c
grass-addons/grass7/imagery/i.points.auto/driver.c
grass-addons/grass7/imagery/i.points.auto/find.c
grass-addons/grass7/imagery/i.points.auto/find_points_semi.c
grass-addons/grass7/imagery/i.points.auto/georef.c
grass-addons/grass7/imagery/i.points.auto/graphics.c
grass-addons/grass7/imagery/i.points.auto/input.c
grass-addons/grass7/imagery/i.points.auto/line.c
grass-addons/grass7/imagery/i.points.auto/mark.c
grass-addons/grass7/imagery/i.points.auto/mouse.c
grass-addons/grass7/imagery/i.points.auto/overlap_area.c
grass-addons/grass7/imagery/i.points.auto/points.c
grass-addons/grass7/imagery/i.points.auto/title.c
grass-addons/grass7/imagery/i.points.auto/view.c
grass-addons/grass7/imagery/i.points.auto/where.c
grass-addons/grass7/imagery/i.points.auto/zoom.c
grass-addons/grass7/imagery/i.points.auto/zoom_box.c
grass-addons/grass7/imagery/i.points.auto/zoom_pnt.c
Modified:
grass-addons/grass7/imagery/i.points.auto/Makefile
grass-addons/grass7/imagery/i.points.auto/cellhd.c
grass-addons/grass7/imagery/i.points.auto/defs.h
grass-addons/grass7/imagery/i.points.auto/equ.c
grass-addons/grass7/imagery/i.points.auto/find_points.c
grass-addons/grass7/imagery/i.points.auto/globals.h
grass-addons/grass7/imagery/i.points.auto/group.c
grass-addons/grass7/imagery/i.points.auto/local_proto.h
grass-addons/grass7/imagery/i.points.auto/main.c
grass-addons/grass7/imagery/i.points.auto/target.c
Log:
new i.points.auto for trunk
Modified: grass-addons/grass7/imagery/i.points.auto/Makefile
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/Makefile 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/Makefile 2011-08-02 12:25:32 UTC (rev 47351)
@@ -2,8 +2,8 @@
PGM = i.points.auto
-LIBES = $(IMAGERYLIB) $(GMATHLIB) $(D_LIB) $(DISPLAYLIB) $(RASTERLIB) $(GISLIB) $(VASKLIB) $(CURSES) $(FFTWLIB)
-DEPENDENCIES= $(IMAGERYDEP) $(GMATHDEP) $(D_DEP) $(DISPLAYDEP) $(RASTERDEP) $(GISDEP) $(VASKDEP)
+LIBES = $(IMAGERYLIB) $(GMATHLIB) $(RASTERLIB) $(GISLIB) $(FFTWLIB)
+DEPENDENCIES= $(IMAGERYDEP) $(GMATHDEP) $(RASTERDEP) $(GISDEP)
include $(MODULE_TOPDIR)/include/Make/Module.make
Deleted: grass-addons/grass7/imagery/i.points.auto/analyze.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/analyze.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/analyze.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,936 +0,0 @@
-#include <string.h>
-#include <unistd.h>
-#include <math.h>
-#include <stdlib.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-#define NLINES 18
-struct box
-{
- int top, bottom, left,right;
-};
-
-static int uparrow ( struct box *,int);
-static int downarrow ( struct box *,int) ;
-static int pick(int,int);
-static int done(void);
-static int cancel_which(void);
-static int inbox (struct box *,int,int);
-static int dotext (char *,int,int,int,int,int,int);
-static int compute_transformation(void);
-static int to_file(void);
-static int askfile(void);
-static int to_printer(void);
-static int do_report ( FILE *);
-static int printcentered(FILE *,char *,int);
-static int show_point(int,int);
-static int offsetx, offsety;
-static int n_old;
-static int which;
-static struct box more, less, report,box_lines, box_points;
-static int height, size, edge, nlines;
-static int curp, first_point;
-static double rms,l_rms;
-static double *xres, *yres, *gnd, *tres, *ures, *lgnd;
-static int pager;
-static int xmax, ymax, gmax;
-static int tmax, umax, lgmax;
-static char buf[300];
-int new_control_line (Lines *ln,double t1,double u1,double t2,double u2,int status);
-Lines lines; /* contiene t ed u delle rette inserite */
-int use_points=1;
-int top, bottom, left, right, width, middle, nums;
-int count =0, first_line=0;
-#define FMT0(buf,n) \
- sprintf (buf, "%3d ", n)
-#define FMT1(buf,xres,yres,gnd) \
- sprintf (buf, "%5.1f %5.1f %6.1f ", xres,yres,gnd)
-#define LHEAD1 " error "
-#define LHEAD2 " # col row target"
-#define LLINEHEAD2 " # dt du target"
-
-#define FMT2(buf,e1,n1,e2,n2) \
- sprintf (buf, "%9.1f %9.1f %9.1f %9.1f ", e1,n1,e2,n2)
-#define RHEAD1 " image target"
-#define RHEAD2 " east north east north"
-#define RLINEHEAD2 " t1 u1 t2 u2 "
-
-#define BACKGROUND WHITE
-
-int
-analyze (void)
-{
-
- double t_temp1,u_temp1, t_temp2, u_temp2;
-
- static int use = 1;
-
- static Objects objects[]=
- {
- MENU(" DONE ", done, &use),
- MENU(" PRINT ", to_printer, &use),
- MENU(" FILE ", to_file, &use),
- INFO(" Double click on point to be included/excluded ", &use),
- OTHER(pick,&use),
- {0}
- };
-
- int color;
- int tsize;
- int cury;
- int len;
- int line;
- int i;
-/* to give user a response of some sort */
- if (group.points.count ==0)
- return 0;
-
-
- 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;
- use_points=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 */
- R_standard_color (WHITE);
- 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;
-
- bottom = height*NLINES;
- top = 0;
-
-
- 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, left, right);
-
-
-/* fill it with white */
- R_standard_color (WHITE);
- 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 (BLUE);
- 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 - 4;
- 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));
-
-
- i=0;
- while(group.points.status[i]!=1 && i < group.points.count)
- i++;
- if(i >=group.points.count && group.points.status[i]!=1)
- i=0;
-offsetx = group.points.e2[i] - group.points.e1[i];
-offsety = group.points.n2[i] - group.points.n1[i];
-
-
-lines.count=0;
- for (i=0; i < group.points.count; i++)
- {
- if (group.points.status[i] == 2 || group.points.status[i] == -2)
- {
- points_to_line (group.points.e1[i], group.points.n1[i],group.points.e1[i+1], group.points.n1[i+1],&t_temp1,&u_temp1);
- points_to_line (group.points.e2[i]- offsetx, group.points.n2[i]-offsety,group.points.e2[i+1]-offsetx, group.points.n2[i+1]-offsety,&t_temp2,&u_temp2);
-
- sprintf (buf, "t2[0] e u2[0].... %f %f \n",10000*t_temp2,10000*u_temp2 );
- Curses_write_window (INFO_WINDOW, 3+ i, 2, buf);
-
-
- new_control_line ( &lines,10000*t_temp1,10000*u_temp1,10000*t_temp2,10000*u_temp2,group.points.status[i]);
- }
- }
-
- tres = (double *) G_calloc (lines.count, sizeof (double));
- ures = (double *) G_calloc (lines.count, sizeof (double));
- lgnd = (double *) G_calloc (lines.count, sizeof (double));
-
- /* compute transformation for the first time */
- compute_transformation();
-
-
- /* put head on the report */
-
- box_points.top=top;
- box_points.bottom=top+height-1;
- box_points.left= left;
- box_points.right=(right-left)/2;
- dotext (" ANALYZE -> POINTS",top, top+height, left, (right-left)/2, 0, RED);
- Outline_box (box_points.top, box_points.bottom, box_points.left, box_points.right);
-
- box_lines.top=top;
- box_lines.bottom=top+height-1;
- box_lines.left= ((right- left)/2)+1;
- box_lines.right=right;
- dotext (" ANALYZE -> LINES",top, top+height, ((right-left)/2)+1, right, 0, BLACK);
- Outline_box (box_lines.top, box_lines.bottom, box_lines.left, box_lines.right);
-
- cury=top;
- cury = top+height;
- 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_standard_color (BLACK);
- R_move_abs (right, top);
- R_cont_abs (right, bottom);
-
-/* define report box */
- report.top = cury;
- report.left = left;
- report.right = right;
- count = 0;
- first_line = 0;
-
-/* lets do it */
- pager = 1;
- while(1)
- {
- R_text_size (tsize, tsize);
- line = 0;
- curp = first_point;
- cury = top + 3*height;
- count=0;
- while(1)
- {
- if (line >= nlines || curp >= group.points.count)
- break;
- if(group.equation_stat > 0 && group.points.status[curp]==1)
- {
- if(use_points)
- {
- color = BLUE;
- 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);
- line++;
- cury += height;
- }
- }
- else if(group.points.status[curp] ==2)
- {
- /* if(group.points.status[curp+1]!=3)
- break;*/
- if(!use_points)
- {
- color = BLUE;
- if (count+first_line == tmax || count+first_line == umax || count+first_line == lgmax)
- color = RED;
- sprintf (buf, "%5.1f %5.1f %5.1f ", tres[count+ first_line],ures[count+first_line],lgnd[count+first_line]);
- dotext (buf, cury, cury+height, nums, middle, 0, color);
- line++;
- cury += height;
- }
-
- curp++;
- }
- else if (group.points.status[curp] > 0)
- {
- FMT0 (buf, curp+1-count);
- dotext (buf, cury, cury+height, left, nums, 0, BLACK);
- 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, BLACK);
- dotext ("?", cury, cury+height, nums, middle, 1, BLACK);
- line++;
- cury += height;
- }
-
- else if (group.points.status[curp] == -2 )
- {
- if(group.points.status[curp+1]!=-3)
- break;
- if (!use_points)
- {
- dotext ("not used", cury, cury+height, nums, middle, 1, BLUE);
- line++;
- cury += height;
- }
- curp++;
- }
- else if (use_points)
- {
- dotext ("not used", cury, cury+height, nums, middle, 1, BLACK);
- line++;
- cury += height;
- }
- if (pager)
- {
- if(use_points &&( group.points.status[curp]==1 || group.points.status[curp]==0))
- {
-
- FMT0 (buf, curp+1-2*(first_line+count));
- dotext (buf, cury-height, cury, left, nums, 0, BLACK);
- FMT2(buf,
- group.points.e1[curp],
- group.points.n1[curp],
- group.points.e2[curp],
- group.points.n2[curp]);
- dotext (buf, cury-height, cury, middle, right-1, 0, BLACK);
- }
- if(!use_points &&( group.points.status[curp]>1 || group.points.status[curp]<-1))
- {
- FMT0 (buf, first_line + count);
- dotext (buf, cury-height, cury, left, nums, 0, BLACK);
- sprintf (buf, "%9.1f %9.1f %9.1f %9.1f ",
- lines.t1[first_line+count],
- lines.u1[first_line+count],
- lines.t2[first_line+count],
- lines.u2[first_line+count]);
- dotext (buf, cury-height, cury, middle, right-1, 0, BLACK);
-
- }
- }
- if( group.points.status[curp]>1 || group.points.status[curp]<-1)
- count++;
- curp++;
- }
- report.bottom = cury;
- if(use_points)
- {
- downarrow (&more, ((group.points.count-curp)-2*(lines.count-(count+first_line)))>0 ? BLACK : BACKGROUND);
- uparrow (&less, first_point > 0 ? BLACK : BACKGROUND);
- }
- if(!use_points)
- {
- downarrow (&more, (lines.count-(count+first_line))>0 ? BLACK : BACKGROUND);
- uparrow (&less, first_point > 0 ? BLACK : BACKGROUND);
- }
-
- R_standard_color (BACKGROUND);
- R_box_abs (left, cury, right-1, bottom);
- if(use_points) {
- if (group.equation_stat < 0)
- {
- color = RED;
- strcpy (buf, "Poorly placed control points");
- }
- else if (group.equation_stat == 0)
- {
- color = RED;
- strcpy (buf, "No active control points");
- }
- else
- {
- color = BLACK;
- sprintf (buf, "Overall rms error: %.2f", rms);
- }
- }
- else
- {
- if (lines.line_stat < 0)
- {
- color = RED;
- strcpy (buf, "Poorly placed control points");
- }
- else if (lines.line_stat == 0)
- {
- color = RED;
- strcpy (buf, "No active control points");
- }
- else
- {
- color = BLACK;
- sprintf (buf, "Overall rms error: %.2f", l_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;
-
-
-
- }
-
- /* 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();
-
- free (xres); free (yres); free (gnd);
- I_put_control_points (group.name, &group.points);
- display_points(1);
- return 0; /* return but don't QUIT */
-}
-
-
-static int uparrow (struct box *box, int color)
-{
- R_standard_color (BLACK);
- Uparrow (box->top+edge, box->bottom-edge, box->left+edge, box->right-edge);
-
- return 0;
-}
-
-static int downarrow(struct box *box, int color)
-{
- R_standard_color (BLACK);
- Downarrow (box->top+edge, box->bottom-edge, box->left+edge, box->right-edge);
-
- return 0;
-}
-
-static int pick(int x,int y)
-{
- int n;
- int cur;
- int i;
-
- cur = which;
- cancel_which();
- if (inbox(&more,x,y))
- {
- if (use_points && ((group.points.count-curp)-2*(lines.count-(count+first_line)))<=0)
- return 0;
- if(!use_points && (lines.count-(count+first_line))<=0)
- return 0;
- first_point = curp;
- first_line +=count;
- pager = 1;
- return 1;
- }
- if (inbox(&box_points,x,y))
- {
- R_text_size (.8*height, .8*height);
- use_points=1;
- dotext (" ANALYZE -> POINTS",top, top+height, left, (right-left)/2, 0, RED);
- dotext (" ANALYZE -> LINES",top, top+height,((right-left)/2)+1, right, 0, BLACK);
- Outline_box (box_points.top, box_points.bottom, box_points.left, box_points.right);
- Outline_box (box_lines.top, box_lines.bottom, box_lines.left, box_lines.right);
- dotext (LHEAD2, top+2*height, top+3*height, left, middle, 0, BLACK);
- dotext (RHEAD2, top+2*height, top+3*height, middle, right-1, 0, BLACK);
- first_point = 0;
- first_line = 0;
- pager = 1;
- return 1;
- }
- if (inbox(&box_lines,x,y))
- {
- R_text_size (.8*height, .8*height);
- use_points=0;
- dotext (" ANALYZE -> LINES",top, top+height, ((right-left)/2)+1, right, 0, RED);
- dotext (" ANALYZE -> POINTS",top, top+height, left, (right-left)/2, 0, BLACK);
- Outline_box (box_points.top, box_points.bottom, box_points.left, box_points.right);
- Outline_box (box_lines.top, box_lines.bottom, box_lines.left, box_lines.right);
- dotext (LLINEHEAD2, top+2*height, top+3*height, left, middle, 0, BLACK);
- dotext (RLINEHEAD2, top+2*height, top+3*height, middle, right-1, 0, BLACK);
- first_point = 0;
- first_line = 0;
- pager = 1;
- return 1;
- }
- if (inbox(&less,x,y))
- {
- if (first_point == 0)
- return 0;
- first_point = 0;
- first_line = 0;
- pager = 1;
- return 1;
- }
- if (!inbox (&report,x,y))
- {
- return 0;
- }
-
- n_old = n = (y - report.top)/height;
- i=0;
- if(use_points){
- for (i; i<=n; i++)
- if (group.points.status[first_point + i]==2||group.points.status[first_point + i]==-2) n+=2;
- }
- else { while (n>=0) {
- if (group.points.status[first_point + i]==2||group.points.status[first_point + i]==-2) {
- n--;
- i++;
- }
- i++;
- }
- n=i-2;
- }
- if (n == cur) /* second click! */
- {
- if (group.points.status[first_point +n]==2||group.points.status[first_point +n]==-2) {
- group.points.status[first_point+n] = -group.points.status[first_point+n];
- group.points.status[first_point+(n+1)] = -group.points.status[first_point+(n+1)];
- lines.status[first_line + n_old] = - lines.status[first_line + n_old];
- }
-
- else
- group.points.status[first_point+n] = !group.points.status[first_point+n];
- compute_transformation();
- show_point (first_point+n, 1);
-
-
- return 1;
- }
- which = n;
- show_point (first_point+n, 0);
- R_standard_color (RED);
- Outline_box (report.top + n*height, report.top +(n+1)*height,
- report.left, report.right-1);
- return 0; /* ignore first click */
-
-}
-
-static int done (void)
-{
- cancel_which();
- return -1;
-}
-
-static int cancel_which (void)
-{
- if (which >= 0)
- {
- R_standard_color (BACKGROUND);
- Outline_box (report.top + which*height, report.top +(which+1)*height,
- report.left, report.right-1);
- show_point (first_point+which, 1);
- }
- which = -1;
-
- return 0;
-}
-
-static int inbox (struct box *box,int x,int y)
-{
- return (x>box->left && x <box->right && y>box->top && y<box->bottom);
-}
-
-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;
-}
-
-static int compute_transformation (void)
-{
- int n, count;
- double d,d1,d2,sum;
- double e1, e2, n1, n2;
- double t1, t2, u1, u2;
- double xval, yval, gval;
- double tval, uval, lgval;
-
- xmax = ymax = gmax = 0;
- xval = yval = gval = 0.0;
-
- Compute_equation(); /*trova gli A,B,C che legano punti dell'image a punti del ltarget */
- lines.line_stat = compute_georef_equations_lp(&lines);
-
- if (group.equation_stat <= 0 && lines.line_stat<=0) return 1;
-
-/* compute the row,col error plus ground error
- * keep track of largest and second largest error
- */
- sum = 0.0;
- rms = 0.0;
- count = 0;
- for (n = 0; n < group.points.count && group.equation_stat>0; n++)
- {
- if (group.points.status[n] !=1) continue;
- count++;
- georef (group.points.e2[n], group.points.n2[n], &e1, &n1, group.E21, group.N21);
- georef (group.points.e1[n], group.points.n1[n], &e2, &n2, group.E12, group.N12);
-
- if((d = xres[n] = e1-group.points.e1[n]) < 0)
- d = -d;
- if (d > xval)
- {
- xmax = n;
- xval = d;
- }
-
- if ((d = yres[n] = n1-group.points.n1[n]) < 0)
- d = -d;
- if (d > yval)
- {
- ymax = n;
- yval = d;
- }
-
-/* compute ground error (ie along diagonal) */
- d1 = e2 - group.points.e2[n];
- d2 = n2 - group.points.n2[n];
- d = d1*d1 + d2*d2;
- sum += d; /* add it to rms sum, before taking sqrt */
- d = sqrt(d);
- gnd[n] = d;
- if (d > gval) /* is this one the max? */
- {
- gmax = n;
- gval = d;
- }
-
- }
-/* compute overall rms error */
- if (count)
- rms = sqrt (sum/count);
-
- count =0;
- tmax = umax = lgmax = 0;
- tval = uval = lgval = 0.0;
- sum = 0.0;
- l_rms = 0.0;
- for (n = 0; n < lines.count && lines.line_stat>0 ; n++)
- {
- if (lines.status[n] !=2) continue;
- count++;
- georef (lines.t2[n], lines.u2[n], &t1, &u1, lines.E21, lines.N21);
- georef (lines.t1[n], lines.u1[n], &t2, &u2, lines.E12, lines.N12);
- if((d = tres[n] = t1- lines.t1[n]) < 0)
- d = -d;
- if (d > tval)
- {
- tmax = n;
- tval = d;
- }
-
- if ((d = ures[n] = u1- lines.u1[n]) < 0)
- d = -d;
- if (d > uval)
- {
- umax = n;
- uval = d;
- }
-
-/* compute ground error (ie along diagonal) */
- d1 = t2 - lines.t2[n];
- d2 = u2 - lines.u2[n];
- d = d1*d1 + d2*d2;
- sum += d; /* add it to rms sum, before taking sqrt */
- d = sqrt(d);
- lgnd[n] = d;
- if (d > lgval) /* is this one the max? */
- {
- lgmax = n;
- lgval = d;
- }
-
- }
- if (count)
- l_rms = sqrt (sum/count);
-
-
-
- return 0;
-}
-
-static int to_file (void)
-{
- FILE *fd;
- char msg[1024];
-
- cancel_which();
- if (Input_other (askfile, "Keyboard") < 0)
- {
- return 0;
- }
-
- fd = fopen (buf, "w");
- if (fd == NULL)
- {
- sprintf (msg, "** Unable to create file %s\n", buf);
- Beep();
- Curses_write_window (PROMPT_WINDOW, 2, 1, msg);
- }
- else
- {
- do_report (fd);
- fclose (fd);
- sprintf (msg, "Report saved in file %s\n", buf);
- Curses_write_window (PROMPT_WINDOW, 2, 1, msg);
- }
- return 0;
-}
-
-static int askfile (void)
-{
- char file[100];
-
- while (1)
- {
- Curses_prompt_gets ("Enter file to hold report: ", file);
- G_strip (file);
- if (*file == 0) return -1;
- if (G_index (file, '/'))
- strcpy (buf, file);
- else
- sprintf (buf, "%s/%s", G_home(), file);
- if (access (buf, 0) != 0)
- return 1;
- sprintf (buf, "** %s already exists. choose another file", file);
- Beep();
- Curses_write_window (PROMPT_WINDOW, 2, 1, buf);
- }
-
- return 0;
-}
-
-static int to_printer (void)
-{
- FILE *fd;
- cancel_which();
- Menu_msg ("sending report to printer ...");
-
- fd = popen ("lpr", "w");
- do_report (fd);
- pclose (fd);
- return 0;
-}
-
-static int do_report ( FILE *fd)
-{
- char buf[100];
- int n;
- int width;
-
- fprintf (fd, "LOCATION: %-20s GROUP: %-20s MAPSET: %s\n\n",
- G_location(), group.name, G_mapset());
- fprintf (fd, "%15sAnalysis of control point registration\n\n", "");
- fprintf (fd, "%s %s\n", LHEAD1, RHEAD1);
- fprintf (fd, "%s %s\n", LHEAD2, RHEAD2);
-
- FMT1 (buf,0.0,0.0,0.0);
- width = strlen (buf);
-
- for (n = 0; n < group.points.count; n++)
- {
- FMT0(buf,n+1);
- fprintf (fd, "%s", buf);
- if(group.equation_stat > 0 && group.points.status[n] > 0)
- {
- FMT1(buf, xres[n], yres[n], gnd[n]);
- fprintf (fd, "%s", buf);
- }
- else if (group.points.status[n] > 0)
- printcentered (fd, "?", width);
- else
- printcentered (fd, "not used", width);
- FMT2(buf,
- group.points.e1[n],
- group.points.n1[n],
- group.points.e2[n],
- group.points.n2[n]);
- fprintf (fd, " %s\n", buf);
- }
- fprintf (fd, "\n");
- if (group.equation_stat < 0)
- fprintf (fd, "Poorly place control points\n");
- else if (group.equation_stat == 0)
- fprintf (fd, "No active control points\n");
- else
- fprintf (fd, "Overall rms error: %.2f\n", rms);
-
- return 0;
-}
-
-static int printcentered (FILE *fd, char *buf,int width)
-{
- int len;
- int n;
- int i;
-
- len = strlen (buf);
- n = (width -len)/2;
-
- for (i = 0; i < n; i++)
- fprintf (fd, " ");
- fprintf (fd, "%s", buf);
- i += len;
- while (i++ < width)
- fprintf (fd, " ");
-
- return 0;
-}
-
-static int show_point(int n,int true_color)
-{
- int x_temp[2], y_temp[2];
- int row,col;
-
- if (!true_color)
- R_standard_color (ORANGE);
- else if(group.points.status[n]>0)
- R_standard_color (GREEN);
- else
- R_standard_color (RED);
-
-
- /* Display red_points in VIEW_MAP1_ZOOM */
-
- if (group.points.status[n]==0 || group.points.status[n] == 1 )
- display_one_point (VIEW_MAP1_ZOOM, group.points.e1[n], group.points.n1[n]);
- else
- {
- display_one_point (VIEW_MAP1_ZOOM, group.points.e1[n], group.points.n1[n]);
- display_one_point (VIEW_MAP1_ZOOM, group.points.e1[n+1], group.points.n1[n+1]);
- row = northing_to_row (&VIEW_MAP1_ZOOM->cell.head, group.points.n1[n]) + .5;
- col = easting_to_col (&VIEW_MAP1_ZOOM->cell.head, group.points.e1[n]) + .5;
- y_temp[0] = row_to_view (VIEW_MAP1_ZOOM, row);
- x_temp[0] = col_to_view (VIEW_MAP1_ZOOM, col);
-
- row = northing_to_row (&VIEW_MAP1_ZOOM->cell.head, group.points.n1[n+1]) + .5;
- col = easting_to_col (&VIEW_MAP1_ZOOM->cell.head,group.points.e1[n+1]) + .5;
- y_temp[1] = row_to_view (VIEW_MAP1_ZOOM, row);
- x_temp[1] = col_to_view (VIEW_MAP1_ZOOM, col);
-
- R_polyline_abs (x_temp,y_temp,2);
- R_flush();
-
- }
-
-
- /* Display red_points in VIEW_MAP2_ZOOM */
- if (group.points.status[n]==0 || group.points.status[n] == 1 )
- display_one_point (VIEW_MAP2_ZOOM, group.points.e2[n], group.points.n2[n]);
- else
- {
- display_one_point (VIEW_MAP2_ZOOM, group.points.e2[n], group.points.n2[n]);
- display_one_point (VIEW_MAP2_ZOOM, group.points.e2[n+1], group.points.n2[n+1]);
- row = northing_to_row (&VIEW_MAP2_ZOOM->cell.head, group.points.n2[n]) + .5;
- col = easting_to_col (&VIEW_MAP2_ZOOM->cell.head, group.points.e2[n]) + .5;
- y_temp[0] = row_to_view (VIEW_MAP2_ZOOM, row);
- x_temp[0] = col_to_view (VIEW_MAP2_ZOOM, col);
-
- row = northing_to_row (&VIEW_MAP2_ZOOM->cell.head, group.points.n2[n+1]) + .5;
- col = easting_to_col (&VIEW_MAP2_ZOOM->cell.head,group.points.e2[n+1]) + .5;
- y_temp[1] = row_to_view (VIEW_MAP2_ZOOM, row);
- x_temp[1] = col_to_view (VIEW_MAP2_ZOOM, col);
-
- R_polyline_abs (x_temp,y_temp,2);
- R_flush();
-
- }
-
-
-
- return 0;
-}
-
-
-int points_to_line (double e1, double n1, double e2, double n2, double *t, double *u)
-{
- double a,b,c;
- a=-(n2 - n1);
- b= (e2 - e1);
- c= (n2*e1 - n1*e2);
- *t= a/c;
- *u=b/c;
- }
-
-int new_control_line ( Lines *ln,
- double t1,double u1,double t2,double u2,int status)
-{
- int i;
- unsigned int size;
-
- i = (ln->count)++ ;
- size = ln->count * sizeof(double) ;
- ln->t1 = (double *) G_realloc (ln->t1, size);
- ln->t2 = (double *) G_realloc (ln->t2, size);
- ln->u1 = (double *) G_realloc (ln->u1, size);
- ln->u2 = (double *) G_realloc (ln->u2, size);
- size = ln->count * sizeof(int) ;
- ln->status = (int *) G_realloc (ln->status, size);
-
- ln->t1[i] = t1;
- ln->t2[i] = t2;
- ln->u1[i] = u1;
- ln->u2[i] = u2;
- ln->status[i] = status;
-
- return 0;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/ask.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/ask.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/ask.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,676 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-#define NLINES 18
-
-struct box
-{
- int top, bottom, left,right;
-};
-
-static int pick(int,int,int);
-static int downarrow(struct box *,int);
-static int uparrow(struct box *,int);
-static int dobox(struct box *,char *,int,int,int,int,int);
-static int dotext(char *,int ,int ,int ,int ,int );
-static int inbox(struct box *,int ,int );
-static int cancel_which();
-
-static int text_size;
-static int which;
-static struct box cancel, more, less;
-static int height, size, edge, count;
-static int page,npages;
-static struct
-{
- char name[GNAME_MAX], mapset[GMAPSET_MAX];
- struct box box;
-} list[NLINES*2];
-
-int
-ask_gis_files (char *type, char *file, char *xname, char *xmapset, int position)
-{
- static int use = 1;
- int pick();
- static Objects objects[]=
- {
- OTHER(pick,&use),
- {0}
- };
-
- char msg[100];
- FILE *fd;
- int width;
- int len1, len2, 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[GNAME_MAX], mapset[GMAPSET_MAX], cur_mapset[GMAPSET_MAX];
- int new_mapset;
- char debugmsg[200];
-
- Menu_msg("");
- debug("ask_gis_files todo\n");
-
- fd = fopen (file, "r");
- if (fd == NULL)
- G_fatal_error ("ask_gis_files: can't read tempfile");
- if (fread (&len1, sizeof(len1), 1, fd) != 1
- || fread (&len2, sizeof(len2), 1, fd) != 1
- || len1 <= 0 || len2 <= 0)
- {
- fclose (fd);
- return 0;
- }
-
- sprintf (msg, "Double click on %s file to be plotted", type);
-
-/*
- * 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 (BLACK); /* GREY */
- R_box_abs (leftx, topx, rightx, bottomx);
-
- R_standard_color (BLUE); /* 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 */
- R_standard_color (ORANGE);/*WHITE*/ /* ADDED */
- 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, "", BLUE, top, right, right+height,0);
- dobox (&more, "", BLUE, 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;
- sprintf(debugmsg, "fgets name: %s\n", name);
- debug(debugmsg);
- 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[GMAPSET_MAX+7];
-
- strcpy (cur_mapset, mapset);
- sprintf (label, "Mapset %s", mapset);
- dobox (&dummy, label, GREY, top+line*height, left, right, 0);
- line++;
- }
- if (col)
- {
- dobox (&list[count].box, name, WHITE, top+line*height, left+width/2, right, 0);
- line++;
- col = 0;
- }
- else
- {
- dobox (&list[count].box, name, WHITE, 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);
- strcpy (xmapset, list[which].mapset);
- 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;
-}
-
-
-
-
-
-
-
-
-
-
-int
-ask_original_map(char *type, char *file, char *xname, char *xmapset, int position)
-{
- static int use = 1;
- int pick();
- static Objects objects[]=
- {
- OTHER(pick,&use),
- {0}
- };
-
- char msg[100];
- FILE *fd;
- int width;
- int len1, len2, 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[GNAME_MAX], mapset[GMAPSET_MAX], cur_mapset[GMAPSET_MAX];
- int new_mapset;
-
- Menu_msg("");
-
- fd = fopen (file, "r");
- if (fd == NULL)
- G_fatal_error ("ask_gis_files: can't read tempfile");
- if (fread (&len1, sizeof(len1), 1, fd) != 1
- || fread (&len2, sizeof(len2), 1, fd) != 1
- || len1 <= 0 || len2 <= 0)
- {
- fclose (fd);
- return 0;
- }
-
- sprintf (msg, "Double click on the final %s map ", type);
-
-/*
- * 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 (BLACK);
- R_box_abs (leftx, topx, rightx, bottomx);
-
- R_standard_color (BLUE); /*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 */
- R_standard_color (ORANGE); /*BLACK */
- 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, "", BLUE, top, right, right+height,0);
- dobox (&more, "", BLUE, 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[GMAPSET_MAX+7];
-
- strcpy (cur_mapset, mapset);
- sprintf (label, "Mapset %s", mapset);
- dobox (&dummy, label, GREY, top+line*height, left, right, 0);
- line++;
- }
- if (col)
- {
- dobox (&list[count].box, name, WHITE, top+line*height, left+width/2, right, 0);
- line++;
- col = 0;
- }
- else
- {
- dobox (&list[count].box, name, WHITE, 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);
- strcpy (xmapset, list[which].mapset);
- 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;
-}
-
-
-
-
-
-
-
-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 (BLUE); /*BLACK*/
- Outline_box (top, bottom, left, right);
- R_standard_color (BLACK); /* ADDED. It determines the colour of text in the table */
- dotext (text, top, bottom, left, right, centered);
-
- box->top = top;
- box->bottom = bottom;
- box->left = left;
- box->right = right;
-
- return 0;
-}
-
-static int uparrow(struct box *box,int color)
-{
- R_standard_color (color);
- Uparrow (box->top+edge, box->bottom-edge, box->left+edge, box->right-edge);
-
- return 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;
-}
-
-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);
- 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);
- return 0; /* ignore first click */
- }
-
- cancel_which();
- return 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;
-
- return 0;
-}
-
-static int inbox(struct box *box,int x,int y)
-{
- return (x>box->left && x <box->right && y>box->top && y<box->bottom);
-}
-
-static int dotext(char *text,int top,int bottom,int left,int right,int centered)
-{
- R_text_size (text_size, text_size);
- 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;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/ask_mag.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/ask_mag.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/ask_mag.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,168 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-struct box
-{
- int top, bottom, left, right;
-};
-
-static struct box plus, minus, value;
-static struct box cancel, accept;
-static int mag;
-static int inbox(struct box *,int,int);
-static int dotext(char *,int,int,int,int,int);
-static int incr(int,int);
-
-int
-ask_magnification (int *magnification)
-{
- static int use = 1;
- int incr();
- 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 (BLUE); /*WHITE*/
- R_box_abs (left, top, right, bottom);
- R_standard_color (RED); /*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 (BLUE); /*WHITE*/
- R_box_abs (left, top, right, bottom);
- R_flush();
-
- R_panel_restore (tempfile1);
- R_panel_delete (tempfile1);
-
- *magnification = mag;
- return stat > 0;
-}
-
-int
-draw_mag (void)
-{
- char buf[10];
-
- sprintf (buf, "%d", mag);
- dotext (buf, value.top, value.bottom, value.left, value.right, WHITE);
-
- return 0;
-}
-
-static int incr(int x,int y)
-{
- if (inbox (&accept,x,y))
- return 1;
- if (inbox (&cancel,x,y))
- return -1;
- if (inbox (&plus,x,y))
- {
- mag++;
- draw_mag();
- }
- else if (inbox (&minus,x,y) && mag > 1)
- {
- mag--;
- draw_mag();
- }
- return 0;
-}
-
-static int dotext(char *text,int top,int bottom,int left,int right,int background)
-{
- R_standard_color (BLUE); /*background*/
- R_box_abs (left+1, top+1, right-1, bottom-1);
- R_standard_color (WHITE); /*BLACK*/
- /* center the text */
- left = (left + right - Text_width (text))/2;
- Text (text, top, bottom, left, right, 2);
- R_flush();
-
- return 0;
-}
-
-static int inbox(struct box *box,int x,int y)
-{
- return (x>box->left && x <box->right && y>box->top && y<box->bottom);
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/call.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/call.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/call.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,58 +0,0 @@
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-/*
- * call a subroutine, but as a child process
- * allowing interrupts for the child
- */
-#include <signal.h>
-
-int call (int (*function)(),char *msg)
-{
- int pid;
- int w, status;
- char i_msg[80];
-
-/*
- * build interrupt msg
- */
- sprintf (i_msg, "Hit %s %s\n", G_unctrl(interrupt_char), msg);
-/*
- * make sure all graphics have gotten to the monitor
- */
- R_stabilize();
-
-/* fork to create child */
- pid = fork();
- if (pid < 0)
- {
- End_curses();
- perror ("Can't fork");
- exit (1);
- }
-
-/* parent just waits for child */
- Curses_allow_interrupts(1);
- if (pid)
- {
- Curses_write_window (PROMPT_WINDOW, 1, 1, i_msg);
- while ( (w = wait (&status)) != pid && w != -1)
- ;
- Curses_allow_interrupts(0);
- Curses_write_window (PROMPT_WINDOW, 1, 1, "\n");
- }
-
-/* child turns on interrupts and calls the function */
- else
- {
- signal (SIGINT, SIG_DFL);
- (*function)();
- exit(0);
- }
- return 0;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/cell.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/cell.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/cell.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,100 +0,0 @@
-#include <unistd.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int use = 1;
-static int choose_cellfile(char *,char *);
-static int plot(int,int);
-static int cancel(void);
-
-int
-plotcell (int x, int y)
-{
- int cancel();
- int plot();
- static Objects objects[] =
- {
- MENU("CANCEL", cancel, &use),
- INFO("Indicate which side should be plotted", &use),
- OTHER(plot, &use),
- {0}
- };
-/*
- * if the target cell file list is ready, ask the user which side
- * should be plotted, otherwise can only plot group files
- */
- if (access (cell_list,0) == 0)
- Input_pointer (objects);
- else
- plot (VIEW_MAP1->left+1,0);
- return 0;
-}
-
-static int
-cancel (void)
-{
- return 1;
-}
-
-
-static int plot(int x,int y)
-{
- char name[100], mapset[100];
- struct Cell_head cellhd;
-
- if (x > VIEW_MAP1->left && x < VIEW_MAP1->right)
- {
- if (!choose_groupfile(name,mapset))
- return 1;
- if(G_get_cellhd(name, mapset, &cellhd) < 0)
- return 1;
-
- Erase_view (VIEW_MAP1_ZOOM);
- VIEW_MAP1_ZOOM->cell.configured = 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);
- }
- else if (x > VIEW_MAP2->left && x < VIEW_MAP2->right)
- {
- if (!ask_gis_files("raster",group_list,name, mapset,1))
- return 1;
- select_target_env();
-
- if(G_get_cellhd(name, mapset, &cellhd) < 0)
- {
- select_current_env();
- return 1;
- }
-
- Erase_view (VIEW_MAP2_ZOOM);
- VIEW_MAP2_ZOOM->cell.configured = 0;
-
- 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);
- select_target_env();
- drawcell(VIEW_MAP2);
- select_current_env();
- if (from_screen < 0)
- {
- from_flag = 1;
- from_screen = 0;
- if (from_keyboard < 0)
- {
- from_keyboard = 0;
- from_screen = 1;
- }
- }
- }
- else
- return 0; /* ignore mouse click */
-
- display_points(1);
- return 1;
-}
-
-static int choose_cellfile(char *name,char *mapset)
-{
- return ask_gis_files ("raster", cell_list, name, mapset, 1);
-}
Modified: grass-addons/grass7/imagery/i.points.auto/cellhd.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/cellhd.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/cellhd.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,25 +1,63 @@
#include "globals.h"
#include "local_proto.h"
-int
-Outline_cellhd (View *view, struct Cell_head *cellhd)
+int set_target_window(void)
{
- int row,col;
- int top, bottom, left, right;
+ double e, n;
- row = northing_to_row (&view->cell.head, cellhd->north) + .5;
- top = row_to_view (view, row);
+ G_debug(1, "set_target_window()");
- col = easting_to_col (&view->cell.head, cellhd->west) + .5;
- left = col_to_view (view, col);
+ /* NW corner */
+ CRS_georef(curr_window.west, curr_window.north, &e, &n,
+ group.E12, group.N12, transform_order);
- row = northing_to_row (&view->cell.head, cellhd->south) + .5;
- bottom = row_to_view (view, row);
+ tgt_window.north = tgt_window.south = n;
+ tgt_window.east = tgt_window.west = e;
+
+ /* NE corner */
+ CRS_georef(curr_window.east, curr_window.north, &e, &n,
+ group.E12, group.N12, transform_order);
- col = easting_to_col (&view->cell.head, cellhd->east) + .5;
- right = col_to_view (view, col);
+ if (tgt_window.north < n)
+ tgt_window.north = n;
+ if (tgt_window.south > n)
+ tgt_window.south = n;
+ if (tgt_window.east < e)
+ tgt_window.east = e;
+ if (tgt_window.west > e)
+ tgt_window.west = e;
- Outline_box (top, bottom, left, right);
+ /* SE corner */
+ CRS_georef(curr_window.east, curr_window.south, &e, &n,
+ group.E12, group.N12, transform_order);
- return 0;
+ if (tgt_window.north < n)
+ tgt_window.north = n;
+ if (tgt_window.south > n)
+ tgt_window.south = n;
+ if (tgt_window.east < e)
+ tgt_window.east = e;
+ if (tgt_window.west > e)
+ tgt_window.west = e;
+
+ /* SW corner */
+ CRS_georef(curr_window.west, curr_window.south, &e, &n,
+ group.E12, group.N12, transform_order);
+
+ if (tgt_window.north < n)
+ tgt_window.north = n;
+ if (tgt_window.south > n)
+ tgt_window.south = n;
+ if (tgt_window.east < e)
+ tgt_window.east = e;
+ if (tgt_window.west > e)
+ tgt_window.west = e;
+
+ tgt_window.ew_res = (tgt_window.east - tgt_window.west) / curr_window.cols;
+ tgt_window.ns_res = (tgt_window.north - tgt_window.south) / curr_window.rows;
+ tgt_window.cols = curr_window.cols;
+ tgt_window.rows = curr_window.rows;
+ G_adjust_Cell_head(&tgt_window, 0, 0);
+
+ return 1;
}
Deleted: grass-addons/grass7/imagery/i.points.auto/colors.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/colors.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/colors.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,7 +0,0 @@
-#include <grass/gis.h>
-#include <grass/display.h>
-int
-set_colors (struct Colors *colors)
-{
- return 0;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/conv.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/conv.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/conv.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,59 +0,0 @@
-#include "globals.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;
-}
-
Added: grass-addons/grass7/imagery/i.points.auto/creat_rand.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/creat_rand.c (rev 0)
+++ grass-addons/grass7/imagery/i.points.auto/creat_rand.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -0,0 +1,43 @@
+#include <time.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <grass/config.h>
+
+
+#ifndef USE_RAND
+
+#ifndef HAVE_DRAND48
+#define lrand48() (((long) rand() ^ ((long) rand() << 16)) & 0x7FFFFFFF)
+#define srand48(sv) (srand((unsigned)(sv)))
+#endif
+
+
+long make_rand(void)
+{
+ return lrand48();
+}
+
+void init_rand(void)
+{
+ srand48((long)time((time_t *) 0));
+}
+
+#else
+
+static long labs(int n)
+{
+ return n < 0 ? (-n) : n;
+}
+
+long make_rand(void)
+{
+ return (labs(rand() + (rand() << 16)));
+}
+
+void init_rand(void)
+{
+ srand(getpid());
+}
+
+#endif
Added: grass-addons/grass7/imagery/i.points.auto/crs.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/crs.c (rev 0)
+++ grass-addons/grass7/imagery/i.points.auto/crs.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -0,0 +1,453 @@
+
+/***************************************************************************/
+
+/***************************************************************************/
+/*
+ CRS.C - Center for Remote Sensing rectification routines
+
+ Written By: Brian J. Buckley
+
+ At: The Center for Remote Sensing
+ Michigan State University
+ 302 Berkey Hall
+ East Lansing, MI 48824
+ (517)353-7195
+
+ Written: 12/19/91
+
+ Last Update: 12/26/91 Brian J. Buckley
+ Last Update: 1/24/92 Brian J. Buckley
+ Added printout of trnfile. Triggered by BDEBUG.
+ Last Update: 1/27/92 Brian J. Buckley
+ Fixed bug so that only the active control points were used.
+ */
+
+/***************************************************************************/
+
+/***************************************************************************/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+#include <limits.h>
+
+#include <grass/gis.h>
+#include <grass/imagery.h>
+
+#include "crs.h"
+
+/* STRUCTURE FOR USE INTERNALLY WITH THESE FUNCTIONS. THESE FUNCTIONS EXPECT
+ SQUARE MATRICES SO ONLY ONE VARIABLE IS GIVEN (N) FOR THE MATRIX SIZE */
+
+struct MATRIX
+{
+ int n; /* SIZE OF THIS MATRIX (N x N) */
+ double *v;
+};
+
+/* CALCULATE OFFSET INTO ARRAY BASED ON R/C */
+
+#define M(row,col) m->v[(((row)-1)*(m->n))+(col)-1]
+
+/***************************************************************************/
+/*
+ */
+/***************************************************************************/
+
+#define MSUCCESS 1 /* SUCCESS */
+#define MNPTERR 0 /* NOT ENOUGH POINTS */
+#define MUNSOLVABLE -1 /* NOT SOLVABLE */
+#define MMEMERR -2 /* NOT ENOUGH MEMORY */
+#define MPARMERR -3 /* PARAMETER ERROR */
+#define MINTERR -4 /* INTERNAL ERROR */
+
+/***************************************************************************/
+/*
+ FUNCTION PROTOTYPES FOR STATIC (INTERNAL) FUNCTIONS
+ */
+/***************************************************************************/
+
+static int calccoef(struct Control_Points *, double *, double *, int);
+static int calcls(struct Control_Points *, struct MATRIX *, double *,
+ double *, double *, double *);
+static int exactdet(struct Control_Points *, struct MATRIX *, double *,
+ double *, double *, double *);
+static int solvemat(struct MATRIX *, double *, double *, double *, double *);
+static double term(int, double, double);
+
+/***************************************************************************/
+/*
+ TRANSFORM A SINGLE COORDINATE PAIR.
+ */
+/***************************************************************************/
+
+int CRS_georef(double e1, /* EASTING TO BE TRANSFORMED */
+ double n1, /* NORTHING TO BE TRANSFORMED */
+ double *e, /* TRANSFORMED EASTING */
+ double *n, /* TRANSFORMED NORTHING */
+ double E[], /* EASTING COEFFICIENTS */
+ double N[], /* NORTHING COEFFICIENTS */
+ int order /* ORDER OF TRANSFORMATION TO BE PERFORMED, MUST MATCH THE
+ ORDER USED TO CALCULATE THE COEFFICIENTS */
+ )
+{
+ double e3, e2n, en2, n3, e2, en, n2;
+
+ switch (order) {
+ case 1:
+
+ *e = E[0] + E[1] * e1 + E[2] * n1;
+ *n = N[0] + N[1] * e1 + N[2] * n1;
+ break;
+
+ case 2:
+
+ e2 = e1 * e1;
+ n2 = n1 * n1;
+ en = e1 * n1;
+
+ *e = E[0] + E[1] * e1 + E[2] * n1 + E[3] * e2 + E[4] * en + E[5] * n2;
+ *n = N[0] + N[1] * e1 + N[2] * n1 + N[3] * e2 + N[4] * en + N[5] * n2;
+ break;
+
+ case 3:
+
+ e2 = e1 * e1;
+ en = e1 * n1;
+ n2 = n1 * n1;
+ e3 = e1 * e2;
+ e2n = e2 * n1;
+ en2 = e1 * n2;
+ n3 = n1 * n2;
+
+ *e = E[0] +
+ E[1] * e1 + E[2] * n1 +
+ E[3] * e2 + E[4] * en + E[5] * n2 +
+ E[6] * e3 + E[7] * e2n + E[8] * en2 + E[9] * n3;
+ *n = N[0] +
+ N[1] * e1 + N[2] * n1 +
+ N[3] * e2 + N[4] * en + N[5] * n2 +
+ N[6] * e3 + N[7] * e2n + N[8] * en2 + N[9] * n3;
+ break;
+
+ default:
+ return MPARMERR;
+ }
+
+ return MSUCCESS;
+}
+
+/***************************************************************************/
+/*
+ COMPUTE THE GEOREFFERENCING COEFFICIENTS BASED ON A SET OF CONTROL POINTS
+ */
+/***************************************************************************/
+
+int CRS_compute_georef_equations(struct Control_Points *cp, double E12[],
+ double N12[], double E21[], double N21[],
+ int order)
+{
+ double *tempptr;
+ int status;
+
+ if (order < 1 || order > MAXORDER)
+ return MPARMERR;
+
+ /* CALCULATE THE FORWARD TRANSFORMATION COEFFICIENTS */
+
+ status = calccoef(cp, E12, N12, order);
+
+ if (status != MSUCCESS)
+ return status;
+
+ /* SWITCH THE 1 AND 2 EASTING AND NORTHING ARRAYS */
+
+ tempptr = cp->e1;
+ cp->e1 = cp->e2;
+ cp->e2 = tempptr;
+ tempptr = cp->n1;
+ cp->n1 = cp->n2;
+ cp->n2 = tempptr;
+
+ /* CALCULATE THE BACKWARD TRANSFORMATION COEFFICIENTS */
+
+ status = calccoef(cp, E21, N21, order);
+
+ /* SWITCH THE 1 AND 2 EASTING AND NORTHING ARRAYS BACK */
+
+ tempptr = cp->e1;
+ cp->e1 = cp->e2;
+ cp->e2 = tempptr;
+ tempptr = cp->n1;
+ cp->n1 = cp->n2;
+ cp->n2 = tempptr;
+
+ return status;
+}
+
+/***************************************************************************/
+/*
+ COMPUTE THE GEOREFFERENCING COEFFICIENTS BASED ON A SET OF CONTROL POINTS
+ */
+/***************************************************************************/
+
+static int calccoef(struct Control_Points *cp, double E[], double N[],
+ int order)
+{
+ struct MATRIX m;
+ double *a;
+ double *b;
+ int numactive; /* NUMBER OF ACTIVE CONTROL POINTS */
+ int status, i;
+
+ /* CALCULATE THE NUMBER OF VALID CONTROL POINTS */
+
+ for (i = numactive = 0; i < cp->count; i++) {
+ if (cp->status[i] > 0)
+ numactive++;
+ }
+
+ /* CALCULATE THE MINIMUM NUMBER OF CONTROL POINTS NEEDED TO DETERMINE
+ A TRANSFORMATION OF THIS ORDER */
+
+ m.n = ((order + 1) * (order + 2)) / 2;
+
+ if (numactive < m.n)
+ return MNPTERR;
+
+ /* INITIALIZE MATRIX */
+
+ m.v = G_calloc(m.n * m.n, sizeof(double));
+ a = G_calloc(m.n, sizeof(double));
+ b = G_calloc(m.n, sizeof(double));
+
+ if (numactive == m.n)
+ status = exactdet(cp, &m, a, b, E, N);
+ else
+ status = calcls(cp, &m, a, b, E, N);
+
+ G_free(m.v);
+ G_free(a);
+ G_free(b);
+
+ return status;
+}
+
+/***************************************************************************/
+/*
+ CALCULATE THE TRANSFORMATION COEFFICIENTS WITH EXACTLY THE MINIMUM
+ NUMBER OF CONTROL POINTS REQUIRED FOR THIS TRANSFORMATION.
+ */
+/***************************************************************************/
+
+static int exactdet(struct Control_Points *cp, struct MATRIX *m, double a[], double b[], double E[], /* EASTING COEFFICIENTS */
+ double N[] /* NORTHING COEFFICIENTS */
+ )
+{
+ int pntnow, currow, j;
+
+ currow = 1;
+ for (pntnow = 0; pntnow < cp->count; pntnow++) {
+ if (cp->status[pntnow] > 0) {
+ /* POPULATE MATRIX M */
+
+ for (j = 1; j <= m->n; j++)
+ M(currow, j) = term(j, cp->e1[pntnow], cp->n1[pntnow]);
+
+ /* POPULATE MATRIX A AND B */
+
+ a[currow - 1] = cp->e2[pntnow];
+ b[currow - 1] = cp->n2[pntnow];
+
+ currow++;
+ }
+ }
+
+ if (currow - 1 != m->n)
+ return MINTERR;
+
+ return solvemat(m, a, b, E, N);
+}
+
+/***************************************************************************/
+/*
+ CALCULATE THE TRANSFORMATION COEFFICIENTS WITH MORE THAN THE MINIMUM
+ NUMBER OF CONTROL POINTS REQUIRED FOR THIS TRANSFORMATION. THIS
+ ROUTINE USES THE LEAST SQUARES METHOD TO COMPUTE THE COEFFICIENTS.
+ */
+/***************************************************************************/
+
+static int calcls(struct Control_Points *cp, struct MATRIX *m, double a[], double b[], double E[], /* EASTING COEFFICIENTS */
+ double N[] /* NORTHING COEFFICIENTS */
+ )
+{
+ int i, j, n, numactive = 0;
+
+ /* INITIALIZE THE UPPER HALF OF THE MATRIX AND THE TWO COLUMN VECTORS */
+
+ for (i = 1; i <= m->n; i++) {
+ for (j = i; j <= m->n; j++)
+ M(i, j) = 0.0;
+ a[i - 1] = b[i - 1] = 0.0;
+ }
+
+ /* SUM THE UPPER HALF OF THE MATRIX AND THE COLUMN VECTORS ACCORDING TO
+ THE LEAST SQUARES METHOD OF SOLVING OVER DETERMINED SYSTEMS */
+
+ for (n = 0; n < cp->count; n++) {
+ if (cp->status[n] > 0) {
+ numactive++;
+ for (i = 1; i <= m->n; i++) {
+ for (j = i; j <= m->n; j++)
+ M(i, j) +=
+ term(i, cp->e1[n], cp->n1[n]) * term(j, cp->e1[n],
+ cp->n1[n]);
+
+ a[i - 1] += cp->e2[n] * term(i, cp->e1[n], cp->n1[n]);
+ b[i - 1] += cp->n2[n] * term(i, cp->e1[n], cp->n1[n]);
+ }
+ }
+ }
+
+ if (numactive <= m->n)
+ return MINTERR;
+
+ /* TRANSPOSE VALUES IN UPPER HALF OF M TO OTHER HALF */
+
+ for (i = 2; i <= m->n; i++)
+ for (j = 1; j < i; j++)
+ M(i, j) = M(j, i);
+
+ return solvemat(m, a, b, E, N);
+}
+
+/***************************************************************************/
+/*
+ CALCULATE THE X/Y TERM BASED ON THE TERM NUMBER
+
+ ORDER\TERM 1 2 3 4 5 6 7 8 9 10
+ 1 e0n0 e1n0 e0n1
+ 2 e0n0 e1n0 e0n1 e2n0 e1n1 e0n2
+ 3 e0n0 e1n0 e0n1 e2n0 e1n1 e0n2 e3n0 e2n1 e1n2 e0n3
+ */
+/***************************************************************************/
+
+static double term(int term, double e, double n)
+{
+ switch (term) {
+ case 1:
+ return 1.0;
+ case 2:
+ return e;
+ case 3:
+ return n;
+ case 4:
+ return e * e;
+ case 5:
+ return e * n;
+ case 6:
+ return n * n;
+ case 7:
+ return e * e * e;
+ case 8:
+ return e * e * n;
+ case 9:
+ return e * n * n;
+ case 10:
+ return n * n * n;
+ }
+
+ return 0.0;
+}
+
+/***************************************************************************/
+/*
+ SOLVE FOR THE 'E' AND 'N' COEFFICIENTS BY USING A SOMEWHAT MODIFIED
+ GAUSSIAN ELIMINATION METHOD.
+
+ | M11 M12 ... M1n | | E0 | | a0 |
+ | M21 M22 ... M2n | | E1 | = | a1 |
+ | . . . . | | . | | . |
+ | Mn1 Mn2 ... Mnn | | En-1 | | an-1 |
+
+ and
+
+ | M11 M12 ... M1n | | N0 | | b0 |
+ | M21 M22 ... M2n | | N1 | = | b1 |
+ | . . . . | | . | | . |
+ | Mn1 Mn2 ... Mnn | | Nn-1 | | bn-1 |
+ */
+/***************************************************************************/
+
+static int solvemat(struct MATRIX *m, double a[], double b[], double E[],
+ double N[])
+{
+ int i, j, i2, j2, imark;
+ double factor, temp;
+ double pivot; /* ACTUAL VALUE OF THE LARGEST PIVOT CANDIDATE */
+
+ for (i = 1; i <= m->n; i++) {
+ j = i;
+
+ /* find row with largest magnitude value for pivot value */
+
+ pivot = M(i, j);
+ imark = i;
+ for (i2 = i + 1; i2 <= m->n; i2++) {
+ temp = fabs(M(i2, j));
+ if (temp > fabs(pivot)) {
+ pivot = M(i2, j);
+ imark = i2;
+ }
+ }
+
+ /* if the pivot is very small then the points are nearly co-linear */
+ /* co-linear points result in an undefined matrix, and nearly */
+ /* co-linear points results in a solution with rounding error */
+
+ if (pivot == 0.0)
+ return MUNSOLVABLE;
+
+ /* if row with highest pivot is not the current row, switch them */
+
+ if (imark != i) {
+ for (j2 = 1; j2 <= m->n; j2++) {
+ temp = M(imark, j2);
+ M(imark, j2) = M(i, j2);
+ M(i, j2) = temp;
+ }
+
+ temp = a[imark - 1];
+ a[imark - 1] = a[i - 1];
+ a[i - 1] = temp;
+
+ temp = b[imark - 1];
+ b[imark - 1] = b[i - 1];
+ b[i - 1] = temp;
+ }
+
+ /* compute zeros above and below the pivot, and compute
+ values for the rest of the row as well */
+
+ for (i2 = 1; i2 <= m->n; i2++) {
+ if (i2 != i) {
+ factor = M(i2, j) / pivot;
+ for (j2 = j; j2 <= m->n; j2++)
+ M(i2, j2) -= factor * M(i, j2);
+ a[i2 - 1] -= factor * a[i - 1];
+ b[i2 - 1] -= factor * b[i - 1];
+ }
+ }
+ }
+
+ /* SINCE ALL OTHER VALUES IN THE MATRIX ARE ZERO NOW, CALCULATE THE
+ COEFFICIENTS BY DIVIDING THE COLUMN VECTORS BY THE DIAGONAL VALUES. */
+
+ for (i = 1; i <= m->n; i++) {
+ E[i - 1] = a[i - 1] / M(i, i);
+ N[i - 1] = b[i - 1] / M(i, i);
+ }
+
+ return MSUCCESS;
+}
Added: grass-addons/grass7/imagery/i.points.auto/crs.h
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/crs.h (rev 0)
+++ grass-addons/grass7/imagery/i.points.auto/crs.h 2011-08-02 12:25:32 UTC (rev 47351)
@@ -0,0 +1,30 @@
+
+/***************************************************************************/
+
+/***************************************************************************/
+/*
+ CRS.H - Center for Remote Sensing rectification routines
+
+ Written By: Brian J. Buckley
+
+ At: The Center for Remote Sensing
+ Michigan State University
+ 302 Berkey Hall
+ East Lansing, MI 48824
+ (517)353-7195
+
+ Written: 12/19/91
+
+ Last Update: 12/26/91 Brian J. Buckley
+ */
+
+/***************************************************************************/
+
+/***************************************************************************/
+
+#define MAXORDER 3
+
+int CRS_compute_georef_equations(struct Control_Points *, double *,
+ double *, double *, double *, int);
+int CRS_georef(double, double, double *, double *, double *, double *,
+ int);
Deleted: grass-addons/grass7/imagery/i.points.auto/curses.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/curses.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/curses.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,282 +0,0 @@
-#include <stdlib.h>
-#include <unistd.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int inited = 0;
-
-static WINDOW *save;
-WINDOW *newwin();
-
-static Window *make_window (int top, int bottom, int left, int right)
-{
- Window *window;
-
- if (top < 0 || bottom >= LINES || left < 0 || right >= COLS
- || bottom-top <= 1 || right-left <= 1)
- {
- End_curses();
- fprintf (stderr, "make_window(%d,%d,%d,%d): illegal screen values\n",
- top, bottom, left, right);
- sleep(3);
- exit(1);
- }
- window = (Window *) G_malloc (sizeof(Window));
- window->top = top;
- window->bottom = bottom;
- window->left = left;
- window->right = right;
- Curses_clear_window (window);
- return window;
-}
-
-int Begin_curses (void)
-{
-/* should only be called once at program outset */
-
- initscr () ; /* initialize curses standard screens */
- raw() ; /* set tty modes via curses calls */
- noecho() ;
- nonl() ;
-
- inited = 1;
-
-/* make a window to save stdscr */
- save = newwin(LINES,COLS,0,0);
-
-/* make_window (nrows, ncols, start_row, start_col) */
- INFO_WINDOW = make_window (0, LINES-4, COLS/2, COLS-1);
- MENU_WINDOW = make_window (0, LINES-4, 0, COLS/2);
- PROMPT_WINDOW = make_window (LINES-4, LINES-1, 0, COLS-1);
- refresh();
-
-
- return 0;
-}
-
-int End_curses (void)
-{
-/* should only be called upon program exit */
-
- clear() ; /* clear the screen */
- refresh() ;
- endwin() ; /* let curses reset the tty now */
-
- return 0;
-}
-
-int Suspend_curses (void)
-{
- overwrite (stdscr, save);
- clear();
- refresh();
- endwin();
-
- return 0;
-}
-
-int Resume_curses (void)
-{
- clear();
- refresh();
- overwrite (save, stdscr);
- refresh();
-
- return 0;
-}
-
-int Curses_allow_interrupts (int ok)
-{
- refresh();
- if (ok)
- noraw();
- else
- raw();
-
- return 0;
-}
-
-int Curses_clear_window (Window *window)
-{
- int y,x;
-
-if (!inited) return 1;
- for (y = window->top+1; y < window->bottom; y++)
- {
- move (y, x=window->left+1);
- while (x++ < window->right)
- addch (' ');
- }
- Curses_outline_window (window);
- refresh();
-
- return 0;
-}
-
-int Curses_outline_window (Window *window)
-{
- int x, y;
-
- move (window->top, x=window->left+1);
- while (x++ < window->right)
- addch ('-');
- move (window->bottom, x=window->left+1);
- while (x++ < window->right)
- addch ('-');
- for (y=window->top+1; y < window->bottom; y++)
- {
- move (y, window->left);
- addch ('|');
- move (y, window->right);
- addch ('|');
- }
- move (window->top, window->left);
- addch ('+');
- move (window->top, window->right);
- addch ('+');
- move (window->bottom, window->left);
- addch ('+');
- if (window->bottom < LINES-1 || window->right < COLS-1)
- {
- move (window->bottom, window->right);
- addch ('+');
- }
-
- return 0;
-}
-
-int Curses_write_window (Window *window, int line, int col, char *message)
-{
- int y,x,i;
-
-if (!inited)
-{
- fprintf (stderr, "%s\n", message);
- return 1;
-}
- if (line <= 0 || line >= window->bottom-window->top)
- return 1;
- if (col <= 0 || col >= window->right-window->left)
- return 1;
- move(y=window->top+line, x=window->left+col);
- while (*message != 0 && *message != '\n' && x < window->right)
- {
- addch (*message);
- message++;
- x++;
- }
- if (*message == '\n')
- for (i = x; i < window->right; i++)
- addch (' ');
- move (y, x);
- refresh();
-
- return 0;
-}
-
-
-int
-Curses_replot_screen (void)
-{
- int x,y;
- getyx (stdscr, y, x);
- wrefresh(curscr) ;
- move (y, x);
- refresh();
-
- return 0;
-}
-
-int Curses_prompt_gets (char *prompt, char *answer)
-{
- char c ;
- int n;
- int y,x;
-
- *answer = 0;
- n = 0;
-
- Curses_write_window (PROMPT_WINDOW, 1, 1, "\n");
- Curses_write_window (PROMPT_WINDOW, 1, 1, prompt);
-
- for(;;)
- {
- refresh ();
- c = Curses_getch(0) ;
- if (c == '\n' || c == '\r')
- break;
-
- getyx (stdscr, y, x);
- if (c > 037 && c < 0177)
- {
- if (x < PROMPT_WINDOW->right)
- {
- *answer++ = c ;
- *answer = 0 ;
- addch(c) ;
- n++;
- }
- continue;
- }
- if (c == '\b')
- {
- if (n > 0)
- {
- answer--;
- *answer = 0;
- move (y, x-1);
- addch (' ');
- move (y, x-1);
- n--;
- }
- continue;
- }
- Beep();
- }
-
- return 0;
-}
-
-int
-Beep (void)
-{
- putchar ('\7');
- fflush (stdout);
-
- return 0;
-}
-
-int
-Curses_getch (int with_echo)
-{
- char achar;
- int c;
- int kill;
-
-if (!inited) return 0;
- kill = 0;
- while(1)
- {
- c = getch() & 0177;
- if (c == interrupt_char)
- {
- if (kill++ >= 3)
- {
- End_curses();
- exit(0);
- }
- continue;
- }
- kill = 0;
- if (c != 18)
- break;
- Curses_replot_screen();
- }
- if (with_echo)
- {
- achar = c;
- addch(achar);
- refresh();
- }
- return c;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/debug.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/debug.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/debug.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,13 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-int
-debug (char *msg)
-{
- R_stabilize();
- Curses_write_window (PROMPT_WINDOW, 1, 1, msg);
- /* Curses_getch(0);*/
-
- return 0;
-}
Modified: grass-addons/grass7/imagery/i.points.auto/defs.h
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/defs.h 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/defs.h 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,72 +1,26 @@
#include <grass/imagery.h>
-#include <curses.h>
-/* this is a curses structure */
-typedef struct
-{
- int top, left, bottom, right;
-} Window;
+#define SRC_ENV 0
+#define TGT_ENV 1
-/* this is a graphics structure */
typedef struct
{
- int top, bottom ,left, right;
- int nrows, ncols;
- struct
- {
- int configured;
- struct Cell_head head;
- struct Colors colors;
- char name[100];
- char mapset[100];
- int top, bottom ,left, right;
- double ew_res, ns_res; /* original map resolution */
- } cell;
-} View;
-
-
-typedef struct
-{
- char name[100];
+ char *name;
+ char *img, *tgt_img;
struct Ref ref;
struct Control_Points points;
- double E12[3], N12[3], E21[3], N21[3];
+ double E12[10], N12[10], E21[10], N21[10];
int equation_stat;
} Group;
typedef struct
{
- 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;
-
-#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}
-
-typedef struct
-{
double *t1;
double *u1;
double *t2;
double *u2;
int *status;
- double E12[3], N12[3], E21[3], N21[3];
+ double E12[10], N12[10], E21[10], N21[10];
int count;
int line_stat;
} Lines;
Deleted: grass-addons/grass7/imagery/i.points.auto/description.html
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/description.html 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/description.html 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,55 +0,0 @@
-<H2>DESCRIPTION</H2>
-
-This module allows a search of GCP's on two raster-maps with differents levels
-of automation.
-
-The manual search is the default search, so it's possible to
-determine the GCP's manually with the mouse.
-
-<b>Semiautomated-search</b>
-You have to determine with the mouse some corrispondent areas
-(with a discrete precision) in the two maps and the module searches the GCP's in these areas.
-
-<b>Automated-search</b>
-At the start of module you have to load the maps that the algorithm uses to the search,
-so it's recommended to use the maps filtered with the filters DIVERSITY or STDDEV
-(of GRASS) with a window of 3x3 or 5x5 pixels. However, the algorithm sometimes work
-well with the original maps too.
-
-You click the button Automated-Search and then you have to load the maps that you want to
-visualize at the end of the search (with the GCP's), usually they are the original maps.
-
-If the maps have strong geometric distortion and strong geometric differencies, maybe
-the results of the search (with the default options) are not good, so you can click the
-button LESS-GCP's and then repeat the operation.
-
-The Overlap-Points (O.P.) era two corresponding points (one for every maps) that is
-used from the algorithm to determine the overlapping-area in the two maps.
-The Master-map is considered the map on the left, and the Slave-map is the map on the right.
-
-Center, top, bottom, left, right are the position of the Master Overlap-Point (on the
-left map) that will be searched on the Slave map (right map). Center is the point at the
-center of the map. Top, bottom, left, right are the position of the O.P. respect to
-the center of the map. If you choose one of these possibilities, then you have to
-choose the shift from the center, measured in percentage of the dimensions of the map; there
-are two possibilities: 5% and 10%.
-This type of search is the most automated (fully-automated ).
-
-If you choose -MARK SLAVE O.P.-, then the module visualizes a blue point at the center
-of the master map, and you have to mark the corrispondent point on the slave map.
-You can use this function if the maps are overlapped for more of 50% and if the
-algorithm doesn't have success in the fully-automated search.
-
-If the maps have a overlapping area less of 50%, you can use the function -MARK M and S O.P.-.
-You have to mark a point in the master map and the corresponding point on the slave map.
-
-At the end of search it's possible to exclude automatically the points not really
-corresponding. This function use the rms with a threshold. The default-value for
-the threshold is 2.5, but (before to active the Auto-Exclusion) you can change it,
-chossing one of different proposed values; you can choose an arbitrary value with
-click on -OTHER-, so you go on the shell and digit the value from keyboard and confirm
-with ENTER.
-
-<H2>AUTHOR</H2>
-
-<p><i>Last changed: $Date: 2006/06/22 07:46:46 $</i></p>
Deleted: grass-addons/grass7/imagery/i.points.auto/digit.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/digit.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/digit.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,129 +0,0 @@
-#include <stdlib.h>
-#include <unistd.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int setup(void);
-static int oops(void);
-static int yes(void);
-static int no(void);
-
-int
-setup_digitizer (void)
-{
- static int use = 1;
- int setup(), no(), yes();
- static Objects objects[]=
- {
- INFO("Do you wish to use the digitizer? ", &use),
- MENU("YES", yes, &use),
- MENU("NO", no, &use),
- {0}
- };
- char command[1024];
-
- use_digitizer = 0;
-/*
- * test to see if we have a digitizer (geo.quest)
- * make sure this program has execute permission first.
- * then run the program and check its exit status
- * 0 means can use digitizer, other means can't
- */
- sprintf (command, "%s/etc/geo.quest", G_gisbase());
- if (access (command, 1) != 0)
- return 0;
- if (system(command))
- return 0;
-
-
-/*
- * ask the user if he/she wishes to use it
- */
- Start_mouse_in_menu();
- Input_pointer (objects);
- if (use_digitizer)
- Input_other (setup, "Keyboard");
-
- return 0;
-}
-
-static int
-setup (void)
-{
- char command[1024];
-/*
- * setup the digitizer. system() call must exit with 0 to indicate
- * everything went fine
- */
- sprintf (command, "%s/etc/geo.reg %s %d",
- G_gisbase(), digit_points, getpid());
- Suspend_curses();
- if (system (command))
- {
- use_digitizer = 0;
- sleep(3);
- }
- Resume_curses();
-
- return 0;
-}
-
-int
-digitizer_point (double *east, double *north)
-{
- char command[1024];
- FILE *fd;
- int stat;
-
-/* make sure digitzer is to be used */
- if (!use_digitizer)
- return 0;
-
- sprintf (command, "%s/etc/geo.point %s %s",
- G_gisbase(), digit_points, digit_results);
-
- Suspend_curses();
- if(system (command))
- {
- sleep(3);
- Resume_curses();
- oops();
- return 0;
- }
- Resume_curses();
- fd = fopen (digit_results, "r");
- if (fd == NULL)
- {
- oops();
- return 0;
- }
- stat = (fscanf (fd, "%lf %lf", east, north) == 2);
- fclose (fd);
-
- if (stat == 0)
- oops();
- return stat;
-}
-
-static int
-oops (void)
-{
- Curses_clear_window (MENU_WINDOW);
- Curses_write_window (MENU_WINDOW, 3,2,"Can't get data from digitizer");
-
- return 0;
-}
-
-static int
-no (void)
-{
- use_digitizer = 0;
- return 1;
-}
-
-static int
-yes (void)
-{
- use_digitizer = 1;
- return 1;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/dot.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/dot.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/dot.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,55 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-
-int
-dot (int x, int y)
-{
- int vx[5], vy[5];
-
- vx[0] = x; vy[0] = y - dotsize;
- vx[1] = x - dotsize; vy[1] = y;
- vx[2] = x; vy[2] = y + dotsize;
- vx[3] = x + dotsize; vy[3] = y;
- vx[4] = x; vy[4] = y - dotsize;
-
- R_polygon_abs (vx, vy, 5);
-/*
- int i;
-
- for (i = 0; i < dotsize; i++)
- {
- R_move_abs (x-i, y+i-dotsize);
- R_cont_rel (i+i,0);
- R_move_abs (x-i, y+dotsize-i);
- R_cont_rel (i+i,0);
- }
- R_move_abs (x-dotsize, y);
- R_cont_rel (dotsize+dotsize, 0);
-*/
-
- return 0;
-}
-
-int
-save_under_dot (int x, int y)
-{
- R_panel_save (tempfile1, y-dotsize, y+dotsize, x-dotsize, x+dotsize);
-
- return 0;
-}
-
-int
-restore_under_dot (void)
-{
- R_panel_restore (tempfile1);
-
- return 0;
-}
-
-int
-release_under_dot (void)
-{
- R_panel_delete (tempfile1);
-
- return 0;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/drawcell.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/drawcell.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/drawcell.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,77 +0,0 @@
-#include <stdlib.h>
-#include <grass/gis.h>
-#include "globals.h"
-#include <grass/display.h>
-#include <grass/raster.h>
-#include "local_proto.h"
-
-int drawcell(View *view)
-{
- int fd;
- int left, top;
- int ncols, nrows;
- int row;
- DCELL *dcell;
- struct Colors *colors;
- int read_colors;
- char msg[GNAME_MAX];
-
-
- if (!view->cell.configured) return 0;
- if (view == VIEW_MAP1 || view == VIEW_MAP1_ZOOM)
- {
- colors = &VIEW_MAP1->cell.colors;
- read_colors = view == VIEW_MAP1;
- }
- else
- {
- colors = &VIEW_MAP2->cell.colors;
- read_colors = view == VIEW_MAP2;
- }
- if (read_colors)
- {
- G_free_colors (colors);
- if(G_read_colors (view->cell.name, view->cell.mapset, colors) < 0)
- return 0;
- }
-
- display_title (view);
-
- set_colors (colors);
-
- G_set_window (&view->cell.head);
- nrows = G_window_rows();
- ncols = G_window_cols();
-
- left = view->cell.left;
- top = view->cell.top;
-
- R_standard_color (BLUE);
- Outline_box (top, top+nrows-1, left, left+ncols-1);
-
- if (getenv("NO_DRAW"))
- return 1;
-
- fd = G_open_cell_old (view->cell.name, view->cell.mapset);
- if (fd < 0)
- return 0;
- dcell = G_allocate_d_raster_buf();
-
- sprintf (msg, "Plotting %s ...", view->cell.name);
- Menu_msg(msg);
-
- D_cell_draw_setup(top, top + nrows, left, left + ncols);
- for (row = 0; row < nrows; row++)
- {
- if(G_get_d_raster_row_nomask(fd, dcell, row) < 0)
- break;
- D_draw_d_raster (row, dcell, colors);
- }
- D_cell_draw_end();
- G_close_cell (fd);
- G_free (dcell);
- if(colors != &VIEW_MAP1->cell.colors)
- set_colors(&VIEW_MAP1->cell.colors);
-
- return row==nrows;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/driver.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/driver.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/driver.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,63 +0,0 @@
-#include "globals.h"
-#include "local_proto.h"
-
-static int use = 1;
-static int stop(void);
-static int dont_stop(void);
-static int really_quit(void);
-
-int driver (void)
-{
- static Objects objects[] =
- {
- MENU(" QUIT ",really_quit,&use),
- MENU(" ZOOM ",zoom,&use),
- MENU(" PLOT RASTER ",plotcell,&use),
- MENU(" LINE ",line,&use),
- MENU(" ANALYZE ",analyze,&use),
- MENU(" SEMIAUTOMATED SEARCH ",Extract_matrix_semi,&use),
- MENU(" AUTOMATED SEARCH ",automated_search,&use),
- OTHER(mark, &use),
- {0}
- };
-
- Input_pointer (objects);
- Menu_msg ("");
-
- return 0;
-}
-
-
-
-
-
-
-static int
-really_quit (void)
-{
- static Objects objects[] =
- {
- INFO("really quit? ",&use),
- MENU(" NO ",dont_stop,&use),
- MENU(" YES ",stop,&use),
- {0}
- };
- if (Input_pointer (objects) < 0)
- return -1;
- return 0; /* don't quit */
-}
-
-
-static int
-dont_stop (void)
-{
- return 1;
-}
-
-static int
-stop (void)
-{
- return -1;
-}
-
-
Modified: grass-addons/grass7/imagery/i.points.auto/equ.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/equ.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/equ.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,11 +1,12 @@
#include "globals.h"
#include "local_proto.h"
-int
-Compute_equation (void)
+int Compute_equation(void)
{
- group.equation_stat = compute_georef_equations(&group.points,
- group.E12, group.N12, group.E21, group.N21);
+ group.equation_stat = CRS_compute_georef_equations(&group.points,
+ group.E12, group.N12,
+ group.E21, group.N21,
+ transform_order);
return 0;
}
Deleted: grass-addons/grass7/imagery/i.points.auto/find.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/find.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/find.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,21 +0,0 @@
-#include <stdlib.h>
-#include "globals.h"
-#include "local_proto.h"
-
-/*
- * run etc/i.find command find all cell, vect files
- * in the target location.
- */
-int find_target_files (void)
-{
- char command[1024];
-
- select_target_env();
- sprintf (command, "%s/etc/i.find %s %s cell %s dig %s",
- G_gisbase(), G_location(), G_mapset(), cell_list, vect_list);
- select_current_env();
-
- system(command);
-
- return 0;
-}
Modified: grass-addons/grass7/imagery/i.points.auto/find_points.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/find_points.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/find_points.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,2212 +1,681 @@
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
+#include <math.h>
#include <string.h>
#include <signal.h>
-#include <math.h>
#include <grass/config.h>
-#ifdef HAVE_FFTW_H
-#include <fftw.h>
+#ifdef HAVE_FFTW3_H
+#include <fftw3.h>
#endif
#ifdef HAVE_DFFTW_H
#include <dfftw.h>
#endif
+#include <grass/gis.h>
#include <grass/raster.h>
#include <grass/imagery.h>
#include <grass/gmath.h>
+#include <grass/glocale.h>
#include "globals.h"
#include "local_proto.h"
-#ifdef NULL_VALUE
-#undef NULL_VALUE
-#endif
-#define NULL_VALUE -1
-
-
-double *fft_first[2];
-double *fft_second[2];
-double *fft_prod_con[2];
-
-int n=1; /*If (n==1) then the algorithm is searching the Overlapping-Area, if (n==2), it is searching the GCP's*/
-int pos_point;
-int dist;
-int ncols1, ncols2, nrows1, nrows2;
-int nrows1_img, ncols1_img, nrows2_img, ncols2_img;
-int r1, c1; /* Central (or around the central) point of the first img */
-int r2, c2; /* Corresponding point in the second img */
-int r2c, c2c; /* Central point of the first img */
-
-char *group_name;
-char *group_MAPSET;
-char *group_LOCATION_NAME;
-char *group_GISDBASE;
-int q;
-FILE *fp;
-FILE *fp_old;
-/*int i;*/
-char file_name[500];
-
-char name1[100];
-char name2[100];
-char mapset[100];
-
-int dist_r, dist_c;
-
-int z;
-
-
-int n_points=0; /* When "LESS_GCP's" is activated, then (n_points==0) */
-int man_op=0; /* Variable for the option "Manual_OP". It's 1 if the option is activated */
-double e_man2, n_man2; /* Coordinates for the manual_OP */
-int man_m_s_op=0;
-double e_man1, n_man1;
-
-View *m1, *m2;
-
-
-
-
-int min(int a, int b)
+static void diagonal(double *dg, double *d2, double dx, double dy)
{
-
- if(a <= b)
- {
- return a;
- }
- else
- {
- return b;
- }
+ *d2 = dx * dx + dy * dy;
+ *dg = sqrt(*d2);
}
-static int main_menu();
-static int cancel();
-static int shift1();
-static int shift2();
-
-static int less_GCPs();
-static int manual_op();
-static int manual_op1();
-static int mark_op(int x,int y,int button);
-static int mark_point_op (View *view,int x, int y);
-
-static int central();
-static int top();
-static int bottom();
-static int left();
-static int right();
-
-static int manual_m_s_op();
-static int manual_m_s_op1();
-static int mark_m_s_op(int x,int y,int button);
-static int mark_point_m_s_op (View *view,int x, int y);
-
-/* variables for function "TRY_AGAIN" */
-char name1_initial[100];
-char name2_initial[100];
-char mapset_initial[100];
-static int try_again();
-static int store_points();
-
-
-
-
-/* Variables and functions for the Auto-Exclusion */
-static int curp, first_point;
-static double *xres, *yres, *gnd, *tres, *ures, *lgnd;
-static int offsetx, offsety;
-static int xmax, ymax, gmax;
-static int tmax, umax, lgmax;
-static double rms,l_rms;
-static double th=2.5; /*Default threshold of the rms for the Auto-Exclusion.*/
-char file_name1[500];
-static int auto_exclusion();
-static int change_rms_th();
-static int compute_transformation(void);
-static int th_1();
-static int th_2();
-static int th_3();
-static int th_4();
-static int th_5();
-static int other_th();
-static int pre_analyze();
-
-
-
-
-
-
-
-
-
-int automated_search()
+void Extract_matrix_auto(void)
{
+ char *first_map_R_mapset;
+ char *first_map_R_name;
+ int first_map_R_fd;
+ RASTER_MAP_TYPE first_map_R_type;
+ char *second_map_R_mapset;
+ char *second_map_R_name;
+ int second_map_R_fd;
+ RASTER_MAP_TYPE second_map_R_type;
+ struct Cell_head cellhd_zoom1;
+ struct Cell_head cellhd_zoom2;
+ int ncols1, ncols2, nrows1, nrows2;
+ double fft_thresh;
+ int fft_windows, fft_size;
+ int i;
+ int check_reading;
+ char *group_name;
+ char *group_MAPSET;
+ char *group_LOCATION_NAME;
+ char *group_GISDBASE;
+ DCELL *rowbuf1_R;
+ DCELL tf1_R;
+ DCELL *rowbuf2_R;
+ DCELL tf2_R;
+ DCELL *mat1, *mat2;
+ int r, c;
+ int q;
+ char file_name[GPATH_MAX];
+ FILE *fp;
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
- static int use = 1;
+ G_debug(1, "Extract_matrix_auto()");
- ask_original_map ("raster", group_list, name1,mapset, -1);
- ask_original_map ("raster", group_list, name2,mapset, 1);
+ select_env(SRC_ENV);
-
+ /* Load environmental vars */
+ group_LOCATION_NAME = G_store(G_getenv("LOCATION_NAME"));
+ group_GISDBASE = G_store(G_getenv("GISDBASE"));
+ group_MAPSET = G_store(G_getenv("MAPSET"));
- static Objects objects1[]=
- {
- MENU(" MAIN MENU ",cancel,&use),
- INFO(" O.P. -> ",&use),
- MENU(" Central ",central,&use),
- MENU(" Top ",top,&use),
- MENU(" Bottom ",bottom,&use),
- MENU(" Left ",left,&use),
- MENU(" Right ",right,&use),
- INFO(" ",&use),
- MENU(" LESS GCPs ",less_GCPs,&use),
- MENU(" Mark Slave-O.P. ",manual_op,&use),
- MENU(" Mark M&S-O.P. ",manual_m_s_op,&use),
- {0}
- };
-
-
- Input_pointer (objects1);
-
- m=0;
-
- return 0;
-
-}
-
-
-
-
-
-
-void Extract_matrix()
-{
- struct GModule *module;
- struct Control_Points *cp1;
- char buf[256];
- char *s;
- int rows, cols;
-
- char *first_map_R_mapset;
- char *first_map_R_name;
- int first_map_R_fd;
- char *second_map_R_mapset;
- char *second_map_R_name;
- int second_map_R_fd;
-
- int K;
-
- int correlation_window_dim;
- int search_window_dim;
- int search_window_dim1;
- int search_window_dim2;
-
-
- int squared_search_window_dim;
- int search_jump;
-
- int left1, top1, left2, top2;
- int repeat;
-
- int n_1, e_1, n_2, e_2, s_1, s_2, w_1, w_2;
- int r1_1, r1_2, r2_1, r2_2;
- int c1_1, c1_2, c2_1, c2_2;
-
- int i;
-
- int h1_r;
- int h1_c;
- int h2_r;
- int h2_c;
-
-
- DCELL *rowbuf1_R;
- DCELL *tf1_R;
- DCELL *rowbuf2_R;
- DCELL *tf2_R;
- double **search_window;
- double **mat1,**mat2;
- int r,c;
- int search_border;
- int p1;
- int dim_win_c, dim_win_r;
- char first_sites[500];
- char second_sites[500];
- char file_name_old[500];
- FILE *first_fp;
- FILE *second_fp;
-
- int xp1, yp1, xs1, ys1;
- int xp2, yp2, xs2, ys2;
- int nimg;
-
- static int use = 1;
-
-
-
-
- if(n==1)
- {
- m1=VIEW_MAP1;
- m2=VIEW_MAP2;
+ if (G_name_is_fully_qualified(group.name, xname, xmapset)) {
+ group_name = xname;
}
-
- else
- {
-
- if( (r2 >= r1) && (c2 >= c1 ) )
- {
- xp1 = (c1 - (min(c1,c2)))+1;
- xp2 = (c2 - (c1-xp1));
- xs2 = (c2 + min((ncols1-c1),(ncols2-c2)))-1;
- xs1 = (c1 + (xs2 - c2));
- yp1 = (r1 - (min(r1,r2)))+1;
- yp2 = (r2 - (r1 - yp1));
- ys2 = (r2 + min((nrows1-r1),(nrows2-r2)))-1;
- ys1 = (r1 + (ys2 - r2));
- }
- else if( (r2 <= r1) && (c2 <= c1) )
- {
- xp2 = (c2 - (min(c2,c1)))+1;
- xp1 = (c1 - (c2 - xp2));
- xs1 = (c1 + min((ncols1-c1),(ncols2-c2)))-1;
- xs2 = (c2 + (xs1 - c1));
- yp2 = (r2 - min(r2,r1))+1;
- yp1 = (r1 - (r2 - yp2));
- ys1 = (r1 + min((nrows1-r1),(nrows2-r2)))-1;
- ys2 = (r2 + (ys1 - r1));
- }
- else if( (r2 >= r1) && (c2 <= c1) )
- {
- xp2 = (c2 - min(c2,c1))+1;
- xp1 = (c1 - (c2 - xp2));
- xs1 = (c1 + min((ncols1-c1),(ncols2-c2)))-1;
- xs2 = (c2 + (xs1 - c1));
- yp1 = (r1 - min(r1,r2))+1;
- yp2 = (r2 - (r1 - yp1));
- ys2 = (r2 + min((nrows1-r1),(nrows2-r2)))-1;
- ys1 = (r1 + (ys2 - r2));
- }
- else if( (r2 <= r1) && (c2 >= c1) )
- {
- xp1 = (c1 - min(c1,c2))+1;
- xp2 = (c2 - (c1 - xp1));
- xs2 = (c2 + min((ncols2-c2),(ncols1-c1)))-1;
- xs1 = (c1 + (xs2 - c2));
- yp2 = (r2 - min(r1,r2))+1;
- yp1 = (r1 - (r2 - yp2));
- ys1 = (r1 + min((nrows1-r1),(nrows2-r2)))-1;
- ys2 = (r2 + (ys1 - r1));
- }
-
-
- /* overlap_area(): function that extracts a window from the angle-points
- * top_left (xp1, yp1) and down_right (xs1, ys1)
- */
- nimg = 1;
- overlap_area(xp1, yp1, xs1, ys1, nimg, ncols1, nrows1);
-
-
- nimg = 2;
- overlap_area(xp2, yp2, xs2, ys2, nimg, ncols2, nrows2);
-
-
- m1=VIEW_MAP1_ZOOM;
- m2=VIEW_MAP2_ZOOM;
-
- }
-
-
-
- first_map_R_name=m1->cell.name;
- second_map_R_name=m2->cell.name;
-
-
-
-
-
- /* rows & cols of the view in m1 */
- n_1=m1->cell.head.north;
- e_1=m1->cell.head.east;
- s_1=m1->cell.head.south;
- w_1=m1->cell.head.west;
- left1 = m1->cell.left;
- top1 = m1->cell.top;
-
- r1_1=s_1/m1->cell.ns_res;
- r1_2=n_1/m1->cell.ns_res;
- c1_1=w_1/m1->cell.ew_res;
- c1_2=e_1/m1->cell.ew_res;
-
- nrows1=r1_2-r1_1;
- ncols1=c1_2-c1_1;
-
-
- /* rows & cols of the view in m2 */
- n_2=m2->cell.head.north;
- e_2=m2->cell.head.east;
- s_2=m2->cell.head.south;
- w_2=m2->cell.head.west;
- left2 = m2->cell.left;
- top2 = m2->cell.top;
-
- r2_1=s_2/m2->cell.ns_res;
- r2_2=n_2/m2->cell.ns_res;
- c2_1=w_2/m2->cell.ew_res;
- c2_2=e_2/m2->cell.ew_res;
-
- nrows2=r2_2-r2_1;
- ncols2=c2_2-c2_1;
-
-
- if(n==1)
- {
- nrows1_img = nrows1;
- ncols1_img = ncols1;
- nrows2_img = nrows2;
- ncols2_img = ncols2;
+ else {
+ group_name = group.name;
}
-
-
- /* Initialize the GIS calls */
- module = G_define_module();
- module->description = "Fine registration of two stereo images";
-
- /* Load environmental vars*/
- group_LOCATION_NAME=buf;
- group_LOCATION_NAME=G_getenv("LOCATION_NAME");
- group_GISDBASE=buf;
- group_GISDBASE=G_getenv("GISDBASE");
- group_MAPSET=buf;
- group_MAPSET=G_getenv("MAPSET");
-
-
- if(n==1)
- {
- strcpy (name1_initial,first_map_R_name);
- strcpy (name2_initial,second_map_R_name);
- strcpy (mapset_initial,group_MAPSET);
-
- }
+ first_map_R_name = group.img;
+ first_map_R_mapset = (char *)G_find_raster2(first_map_R_name, "");
+ /* get source cell head */
+ G_debug(1, "get source image cellhd");
+ Rast_get_cellhd(first_map_R_name, first_map_R_mapset, &cellhd1);
+ Rast_get_cellhd(first_map_R_name, first_map_R_mapset, &cellhd_zoom1);
- /* Correlation parameters */
- if(n==1)
- {
+ /* Find second map */
+ select_env(TGT_ENV);
- if(ncols1 <= nrows1)
- {
- search_window_dim1 = ncols1;
- }
- else
- {
- search_window_dim1 = nrows1;
- }
+ second_map_R_name = group.tgt_img;
+ second_map_R_mapset = (char *)G_find_raster2(second_map_R_name, "");
- if(ncols2 <= nrows2)
- {
- search_window_dim2 = ncols2;
- }
- else
- {
- search_window_dim2 = nrows2;
- }
+ /* get target cell head */
+ G_debug(1, "get target image cellhd");
+ Rast_get_cellhd(second_map_R_name, second_map_R_mapset, &cellhd2);
+ Rast_get_cellhd(second_map_R_name, second_map_R_mapset, &cellhd_zoom2);
+ G_debug(1, "north: map1 %f, map2 %f", curr_window.north, tgt_window.north);
+ G_debug(1, "south: map1 %f, map2 %f", curr_window.south, tgt_window.south);
+ G_debug(1, "east: map1 %f, map2 %f", curr_window.east, tgt_window.east);
+ G_debug(1, "west: map1 %f, map2 %f", curr_window.west, tgt_window.west);
+ G_debug(1, "rows: map1 %d, map2 %d", curr_window.rows, tgt_window.rows);
+ G_debug(1, "cols: map1 %d, map2 %d", curr_window.cols, tgt_window.cols);
- if(search_window_dim1 <= search_window_dim2)
- {
- search_window_dim = search_window_dim1;
- }
- else
- {
- search_window_dim = search_window_dim2;
- }
- }
+ select_env(SRC_ENV);
+
+ /* Open first map: load for current region */
+ G_debug(1, "load source image");
+ Rast_set_input_window(&curr_window);
-
- else if(n==2)
- {
- correlation_window_dim=((ncols1/10+nrows1/10)/4);
-
-
-
- if(n_points==1)
- {
-
- K=((ncols1/4+nrows1/4)/3);
- search_window_dim = (correlation_window_dim + K);
- n_points = 0;
-
- }
- else
- {
-
- K=((ncols1/4+nrows1/4)/8);
- search_window_dim = G_math_max_pow2(correlation_window_dim + K);
-
- }
-
-
-
- search_jump=search_window_dim / 2;
+ if ((first_map_R_fd =
+ Rast_open_old(first_map_R_name, first_map_R_mapset)) < 0) {
+ G_fatal_error(_("Error opening first raster map <%s>"), first_map_R_name);
}
-
+ if ((first_map_R_type =
+ Rast_map_type(first_map_R_name, first_map_R_mapset)) < 0)
+ G_fatal_error(_("Error getting first raster map type"));
+ nrows1 = curr_window.rows;
+ ncols1 = curr_window.cols;
+ /* Memory allocation for map_1: */
+ mat1 = (DCELL *) G_calloc((nrows1 * ncols1), sizeof(DCELL));
- group_name=group.name;
- squared_search_window_dim=search_window_dim*search_window_dim;
-
-
- if(n==1)
- {
- Menu_msg ("Loading first image...");
- }
+ rowbuf1_R = Rast_allocate_d_input_buf();
- else
- {
- Menu_msg ("Loading first overlapping_image...");
- }
+ /* Load first map */
- /* Open first real map*/
-
- if((first_map_R_mapset = G_find_cell2(first_map_R_name, "")) == NULL)
- {
- sprintf(buf,"Raster map [%s] not available",first_map_R_name);
- G_fatal_error(buf);
- }
-
-
- if((first_map_R_fd = G_open_cell_old(first_map_R_name,
- first_map_R_mapset)) < 0)
- {
- sprintf(buf,"Error opening raster map [%s]", first_map_R_name);
- G_fatal_error(buf);
- }
+ check_reading = 0;
- /* Set region to first map definition region < m1 > */
- G_get_cellhd (first_map_R_name, first_map_R_mapset, &cellhd1);
- G_set_window(&cellhd1);
- h1_r=cellhd1.rows;
- h1_c=cellhd1.cols;
-
+ for (r = 0; r < nrows1; r++) {
+ Rast_get_row(first_map_R_fd, rowbuf1_R, r, DCELL_TYPE);
-
- /* Memory allocation for the first overlapping_map */
-
- mat1 = (DCELL **) G_calloc(nrows1,sizeof(DCELL *));
- for(r=0;r<nrows1;r++)
- mat1[r] = (DCELL *) G_calloc(ncols1,sizeof(DCELL));
-
+ for (c = 0; c < ncols1; c++) {
+ tf1_R = rowbuf1_R[c];
+ if (!Rast_is_d_null_value(&tf1_R))
+ mat1[(ncols1 * (r)) + c] = tf1_R;
+ else
+ mat1[(ncols1 * (r)) + c] = 0.0;
- /* Load first map*/
-
- rowbuf1_R = (DCELL *)G_calloc(h1_r * h1_c,sizeof(DCELL));
- tf1_R=rowbuf1_R;
-
- for(r=h1_r-r1_2;r<h1_r-r1_1;r++)
- {
- G_get_d_raster_row(first_map_R_fd, tf1_R, r);
- if (G_is_d_null_value (tf1_R))
- *tf1_R = NULL_VALUE;
- c=0;
- while(c<c1_1)
- {
- tf1_R++;
- c++;
- }
- for(c = c1_1; c < c1_2; c++)
- {
- mat1[-h1_r+r1_2+r][c-c1_1] = *tf1_R;
- tf1_R++;
+ if (mat1[(ncols1 * (r)) + c])
+ check_reading = 1;
}
}
- G_close_cell(first_map_R_fd);
-
-
- /* Open second map*/
- if((second_map_R_mapset = G_find_cell2(second_map_R_name, "")) == NULL)
- {
- sprintf(buf,"Raster map [%s] not available",second_map_R_name);
- G_fatal_error(buf);
- }
-
- if((second_map_R_fd = G_open_cell_old(second_map_R_name,
- second_map_R_mapset)) < 0)
- {
- sprintf(buf,"Error opening raster map [%s]", second_map_R_name);
- G_fatal_error(buf);
- }
-
- /* Set region to second map definition region */
- G_get_cellhd (second_map_R_name, second_map_R_mapset, &cellhd2);
- G_set_window(&cellhd2);
- h2_r=cellhd2.rows;
- h2_c=cellhd2.cols;
-
-
- /* Memory allocation for the second overlapping_map */
- mat2 = (DCELL **) G_calloc(nrows2,sizeof(DCELL *));
- for(r=0;r<nrows2;r++)
- mat2[r] = (DCELL *) G_calloc(ncols2,sizeof(DCELL));
+ Rast_close(first_map_R_fd);
+ G_free(rowbuf1_R);
- /* Load second real map */
- if(n==1)
- {
- Menu_msg ("Loading second image...");
- }
+ if (!check_reading)
+ G_fatal_error(_("Nothing read from map1 %d"), check_reading);
- else
- {
- Menu_msg ("Loading second overlapping_image...");
- }
-
- rowbuf2_R=(DCELL *)G_calloc(h2_r * h2_c,sizeof(DCELL));
- tf2_R=rowbuf2_R;
- for(r=h2_r-r2_2;r<h2_r-r2_1;r++)
-
- {
- G_get_d_raster_row(second_map_R_fd, tf2_R, r);
- c=0;
- while(c<c2_1)
- {
- tf2_R++;
- c++;
- }
- for(c = c2_1; c < c2_2; c++)
- {
- if (G_is_d_null_value (tf2_R))
- *tf2_R = NULL_VALUE;
- mat2[-h2_r+r2_2+r][c-c2_1] = *tf2_R;
- tf2_R++;
- }
- }
-
- G_close_cell(second_map_R_fd);
-
+ /* Load second map */
- if( (n==1) && (man_op==0) )
- {
- Menu_msg ("Searching in the second image the corresponding point of the central point of the first one...");
- }
- else if(n==2)
- {
- Menu_msg ("Searching points...");
- }
-
- /* Memory allocation */
- search_window = (DCELL **) G_calloc(search_window_dim,
- sizeof(DCELL *));
- for(r=0;r<search_window_dim;r++)
- search_window[r] = (DCELL *) G_calloc(search_window_dim,
- sizeof(DCELL));
-
- fft_first[0] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_first[1] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_second[0] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_second[1] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_prod_con[0] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_prod_con[1] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
-
+ select_env(TGT_ENV);
+ Rast_set_input_window(&tgt_window);
- /* Inizialize control points */
- if(n==1)
- {
- sPoints.count=1;
- sPoints.e1=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.n1=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.e2=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.n2=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.status=(int *) G_calloc(sPoints.count,sizeof(int));
- }
+ /* Open second map */
+ G_debug(1, "load target image");
+ G_debug(1, "location: %s", G_location());
+ G_debug(1, "projection: %s", G__projection_name(G_projection()));
+ G_debug(1, "tgt_window projection: %s", G__projection_name(tgt_window.proj));
+ G_debug(1, "cellhd2 projection: %s", G__projection_name(cellhd2.proj));
- /* Sites file */
- sprintf(first_sites,"%s/%s/%s/site_lists/%s_%s",G__getenv("GISDBASE"),
- G__getenv("LOCATION_NAME"),G__getenv("MAPSET"),
- group_name,first_map_R_name);
- sprintf(second_sites,"%s/%s/%s/site_lists/%s_%s",G__getenv("GISDBASE"),
- G__getenv("LOCATION_NAME"),G__getenv("MAPSET"),
- group_name,second_map_R_name);
-
-
- /* Set cellhd1 to overlapping_map_1 */
- cellhd1.rows=nrows1;
- cellhd1.cols=ncols1;
- cellhd1.north=r1_2*m1->cell.ns_res;
- cellhd1.south=r1_1*m1->cell.ns_res;
- cellhd1.east=c1_2*m1->cell.ew_res;
- cellhd1.west=c1_1*m1->cell.ew_res;
-
- /* Set cellhd2 to overlapping_map_2 */
- cellhd2.rows=nrows2;
- cellhd2.cols=ncols2;
- cellhd2.north=r2_2*m2->cell.ns_res;
- cellhd2.south=r1_1*m2->cell.ns_res;
- cellhd2.east=c2_2*m2->cell.ew_res;
- cellhd2.west=c2_1*m2->cell.ew_res;
-
- /* Set windows to cellhd1 */
- G_set_window(&cellhd1);
-
-
-
- /******************************************/
- /* function --> Search_correlation_points */
- /******************************************/
- Search_correlation_points(mat1, mat2,
- search_window_dim,
- squared_search_window_dim,
- search_jump,group_name, nrows1, ncols1,
- search_window, r1_2, c1_1, r2_2, c2_1,
- h1_r, h2_r, h1_c, h2_c, nrows2, ncols2, n );
-
-
-
-
- sprintf(file_name,"%s/%s/%s/group/%s/TARGET",group_GISDBASE,
- group_LOCATION_NAME, group_MAPSET,group_name);
- fp = fopen(file_name,"w");
- fprintf(fp,"%s\n%s\n",group_LOCATION_NAME,group_MAPSET);
- fclose(fp);
-
-
- if(n==2)
- {
-
- G_get_cellhd (name1, mapset, &cellhd1);
- G_adjust_window_to_box (&cellhd1, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows, VIEW_MAP1->ncols);
- Configure_view (VIEW_MAP1, name1, mapset, cellhd1.ns_res, cellhd1.ew_res);
- drawcell(VIEW_MAP1);
- display_points(1);
- R_flush();
- Curses_clear_window (PROMPT_WINDOW);
-
-
- G_get_cellhd (name2, mapset, &cellhd2);
- G_adjust_window_to_box (&cellhd2, &VIEW_MAP2->cell.head, VIEW_MAP2->nrows, VIEW_MAP2->ncols);
- Configure_view (VIEW_MAP2, name2, mapset, cellhd2.ns_res, cellhd2.ew_res);
- drawcell(VIEW_MAP2);
- display_points(1);
- R_flush();
- Curses_clear_window (PROMPT_WINDOW);
-
- nimg = 1;
- overlap_area(xp1, yp1, xs1, ys1, nimg, ncols1_img, nrows1_img);
-
- nimg = 2;
- overlap_area(xp2, yp2, xs2, ys2, nimg, ncols2_img, nrows2_img);
-
-
+ if ((second_map_R_fd =
+ Rast_open_old(second_map_R_name, second_map_R_mapset)) < 0) {
+ G_fatal_error(_("Error opening second raster map <%s>"),
+ second_map_R_name);
}
+ G_debug(1, "target image map type");
+ if ((second_map_R_type =
+ Rast_map_type(second_map_R_name, second_map_R_mapset)) < 0)
+ G_fatal_error(_("Error getting second raster map type"));
+ nrows2 = tgt_window.rows;
+ ncols2 = tgt_window.cols;
-
- select_current_env ();
+ /* Memory allocation for zoom_map_2 */
+ mat2 = (DCELL *) G_calloc((nrows2 * ncols2), sizeof(DCELL));
-
- display_points_in_view_diff_color (VIEW_MAP1, 1,
- sPoints.e1, sPoints.n1,
- sPoints.status, sPoints.count);
-
-
- display_points_in_view_diff_color (VIEW_MAP2, 1,
- sPoints.e2, sPoints.n2,
- sPoints.status, sPoints.count);
+ rowbuf2_R = Rast_allocate_d_input_buf();
-
-
-
- display_points_in_view_diff_color (VIEW_MAP1_ZOOM, 1,
- sPoints.e1, sPoints.n1,
- sPoints.status, sPoints.count);
-
-
-
- display_points_in_view_diff_color (VIEW_MAP2_ZOOM, 1,
- sPoints.e2, sPoints.n2,
- sPoints.status, sPoints.count);
-
- R_flush();
+ check_reading = 0;
+ G_debug(1, "read target image");
+ for (r = 0; r < nrows2; r++) {
+ Rast_get_row(second_map_R_fd, rowbuf2_R, r, DCELL_TYPE);
+ for (c = 0; c < ncols2; c++) {
+ tf2_R = rowbuf2_R[c];
+ if (!Rast_is_d_null_value(&tf2_R))
+ mat2[(ncols2 * (r)) + c] = tf2_R;
+ else
+ mat2[(ncols2 * (r)) + c] = 0.0;
-
- if(n==2)
- {
-
- static Objects objects[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" STORE POINTS IN FILE ",store_points,&use),
- MENU(" TRY AGAIN ",try_again,&use),
- INFO(" ",&use),
- MENU(" rms-th ",change_rms_th,&use),
- MENU(" Auto-Exclusion GCPs ",auto_exclusion,&use),
- {0}
- };
-
- Input_pointer (objects);
-
-
- return 0;
+ if (mat1[(ncols2 * (r)) + c])
+ check_reading = 1;
+ }
}
+ Rast_close(second_map_R_fd);
+ G_free(rowbuf2_R);
+ if (!check_reading)
+ G_fatal_error(_("Nothing read from map1 %d"), check_reading);
+ select_env(SRC_ENV);
+ Rast_set_input_window(&curr_window);
+ /* Initialize control points */
+ sPoints.count = 1;
+ sPoints.e1 = (double *)G_malloc(sPoints.count * sizeof(double));
+ sPoints.n1 = (double *)G_malloc(sPoints.count * sizeof(double));
+ sPoints.e2 = (double *)G_malloc(sPoints.count * sizeof(double));
+ sPoints.n2 = (double *)G_malloc(sPoints.count * sizeof(double));
+ sPoints.status = (int *)G_malloc(sPoints.count * sizeof(int));
- /* Free memory */
+ /* define fft parameters */
+ fft_size = detail;
+ fft_windows = n_new_points;
+ fft_thresh = 0.4;
- free( rowbuf1_R);
- free( rowbuf2_R);
+ /******************************************/
+ /* function --> Search_correlation_points */
+ /******************************************/
+ Search_correlation_points_auto(mat1, mat2, fft_size, fft_windows, fft_thresh);
-
- for(r=0;r<nrows1;r++)
- free( mat1[r]);
- free(mat1);
-
- for(r=0;r<nrows2;r++)
- free( mat2[r]);
- free(mat2);
-
- for(r=0;r<search_window_dim;r++)
- free(search_window[r]);
- free(search_window);
-
- for(r=0;r<2;r++)
- {
- free(fft_first[r]);
- free(fft_second[r]);
- free(fft_prod_con[r]);
- }
-
-
- if(n==2)
- {
- sPoints.e1[0];
- sPoints.n1[0];
- sPoints.e2[0];
- sPoints.n2[0];
- sPoints.status[0];
-
- free(sPoints.e1);
- free(sPoints.n1);
- free(sPoints.n2);
- free(sPoints.e2);
- free(sPoints.status);
- }
-
-
-
-
- if(n==1)
- {
- n=2;
- Extract_matrix();
- }
- else
- {
- man_op = 0;
- man_m_s_op = 0;
-
- return 0;
- }
-
-}
-
-
-
-
-
-
-void Search_correlation_points(DCELL **mat1_R, DCELL **mat2_R,
- int search_window_dim,
- int squared_search_window_dim,
- int search_jump, char *group_name,
- int dim_win_r, int dim_win_c,
- DCELL **search_window, int r1_2,int c1_1,
- int r2_2,int c2_1, int h1_r, int h2_r,
- int h1_c, int h2_c, int nrows2, int ncols2, int n )
-{
- int r,c;
- int i, j, search_border;
- char *group_MAPSET;
- char *group_LOCATION_NAME;
- char *group_GISDBASE;
- char first_sites[500];
- char second_sites[500];
- char file_name[500];
- FILE *fp;
- FILE *first_fp;
- FILE *second_fp;
- double cc;
- double north1,east1,north2,east2;
- int tmp_r,tmp_c;
- double mean;
- int index;
-
-
-
-
- if( (n==1) && (man_m_s_op==0) )
- {
+ /* Build or update group/POINTS file */
+ sPoints.count -= 1;
+ if (sPoints.count > 0) {
+ int n_points_filtered = sPoints.count;
- r1 = (dim_win_r/2);
- c1 = (dim_win_c/2);
-
-
- if(man_op==0)
- {
-
- switch (pos_point)
- {
- case 0: dist = 0;
- dist_r = 0;
- dist_c = 0;
- break;
- case 1: r1 = ((dim_win_r/2)-dist);
- break;
- case 2: r1 = ((dim_win_r/2)+dist);
- break;
- case 3: c1 = ((dim_win_c/2)-dist);
- break;
- case 4: c1 = ((dim_win_c/2)+dist);
- break;
- }
-
-
-
- r2c = (nrows2 / 2);
- c2c = (ncols2 / 2);
-
-
- if(pos_point!=0)
- {
- search_window_dim = (search_window_dim - (2*dist));
- squared_search_window_dim = (search_window_dim * search_window_dim);
- search_jump = (search_window_dim / 2);
- }
-
-
-
- search_border = search_window_dim / 2;
-
-
-
- /* Reinizialize fft vectors */
-
- for(i=0;i<squared_search_window_dim;i++)
- {
- fft_first[0][i]=0.0;
- fft_first[1][i]=0.0;
- fft_second[0][i]=0.0;
- fft_second[1][i]=0.0;
- fft_prod_con[0][i]=0.0;
- fft_prod_con[1][i]=0.0;
- }
-
-
- /* Coordinates of the "initial" point */
-
- east1 = G_col_to_easting((double) c1, &cellhd1);
- north1 = G_row_to_northing((double) r1, &cellhd1);
-
-
-
+ sprintf(file_name, "%s/%s/%s/group/%s/POINTS", group_GISDBASE,
+ group_LOCATION_NAME, group_MAPSET, group_name);
+ if (access(file_name, F_OK)) {
+ q = 0;
+ }
+ else {
+ q = 1;
+ }
-
-
- /* Real window in the first image */
-
- Extract_portion_of_double_matrix(r1,c1,search_border,search_border,
- mat1_R,search_window);
-
+ G_debug(1, "Write new control points");
+ fp = fopen(file_name, "a");
+ if (q == 0) {
+ fprintf(fp, "# %7s %15s %15s %15s %9s status\n", "",
+ "image", "", "target", "");
+ fprintf(fp, "# %15s %15s %15s %15s (1=ok)\n",
+ "east", "north", "east", "north");
+ fprintf(fp, "#\n");
+ }
+ /* filter with RMS threshold */
+ for (i = 0; i < sPoints.count; i++) {
+ double e, n;
+ double rx, ry, rd, rd2;
- mean = 0.0;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- mean += search_window[i][j];
- }
- }
- mean /= squared_search_window_dim;
-
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- fft_first[0][i*search_window_dim+j]=search_window[i][j]-mean;
- }
- }
+ /* calculate backward RMS error */
+ CRS_georef(sPoints.e2[i], sPoints.n2[i], &e, &n, group.E21, group.N21, transform_order);
+ rx = fabs(e - sPoints.e1[i]);
+ ry = fabs(n - sPoints.n1[i]);
+ diagonal(&rd, &rd2, rx, ry);
-
-
- Extract_portion_of_double_matrix(r2c,c2c,search_border,search_border,
- mat2_R,search_window);
-
-
- mean = 0.0;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- mean += search_window[i][j];
- }
+ if (rd > rms_threshold) {
+ sPoints.status[i] = -1;
+ n_points_filtered--;
}
- mean /= squared_search_window_dim;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- fft_second[0][i*search_window_dim+j]=search_window[i][j]-mean;
- }
- }
+ }
-
-
-
- /* fft of the 2 (complex) windows */
- fft(-1,fft_first,squared_search_window_dim,search_window_dim,
- search_window_dim);
- fft(-1,fft_second,squared_search_window_dim,search_window_dim,
- search_window_dim);
-
-
-
-
- /* product of the first fft for the coniugate of the second one */
- for(i=0;i<squared_search_window_dim;i+=1)
- {
- fft_prod_con[0][i] = (fft_first[0][i] * fft_second[0][i]) +
- (fft_first[1][i] * fft_second[1][i]);
- fft_prod_con[1][i] = (fft_first[1][i] * fft_second[0][i]) -
- (fft_first[0][i] * fft_second[1][i]);
+ for (i = 0; i < sPoints.count; i++) {
+ if (sPoints.status[i] != -1) {
+ fprintf(fp, " %15f %15f %15f %15f %4d\n",
+ sPoints.e1[i], sPoints.n1[i], sPoints.e2[i],
+ sPoints.n2[i], sPoints.status[i]);
}
-
-
-
-
- /* fft^{-1} of the product <==> cross-correlation at differnet lag
- between the two orig. (complex) windows */
- fft(1,fft_prod_con,squared_search_window_dim,search_window_dim,
- search_window_dim);
-
-
-
-
- /* Search the lag coresponding to the maximum correlation */
- cc = 0.0;
-
- for(i=0;i<squared_search_window_dim;i++)
- {
- if(fft_prod_con[0][i] > cc)
- {
- cc = fft_prod_con[0][i];
- tmp_r=i/search_window_dim;
- tmp_c=i%search_window_dim;
-
- }
- }
-
-
-
-
- /* Get coordinates of "ending" point */
- if((tmp_r <= search_window_dim/2) && (tmp_c <= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c1 - tmp_c,&cellhd2) + dist_c;
- north2 = G_row_to_northing((double) r1 - tmp_r,&cellhd2) + dist_r;
-
- }
- if((tmp_r <= search_window_dim/2) && (tmp_c >= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c1 - (tmp_c-search_window_dim-1),&cellhd2) + dist_c;
- north2 = G_row_to_northing((double) r1 - tmp_r,&cellhd2) + dist_r;
-
- }
- if((tmp_r >= search_window_dim/2) && (tmp_c <= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c1 - tmp_c,&cellhd2) + dist_c;
- north2 = G_row_to_northing((double) r1 - (tmp_r-search_window_dim-1),&cellhd2) + dist_r;
-
- }
- if((tmp_r >= search_window_dim/2) && (tmp_c >= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c1 - (tmp_c-search_window_dim-1),&cellhd2) + dist_c;
- north2 = G_row_to_northing((double) r1 - (tmp_r-search_window_dim-1),&cellhd2) + dist_r;
-
- }
-
-
-
- r2 = G_northing_to_row(north2,&cellhd2);
- c2 = G_easting_to_col(east2,&cellhd2);
-
- sPoints.e1[sPoints.count-1] = east1;
- sPoints.n1[sPoints.count-1] = north1;
- sPoints.e2[sPoints.count-1] = east2;
- sPoints.n2[sPoints.count-1] = north2;
}
-
+ fclose(fp);
+ /* Load new control points */
+ G_debug(1, "Load new control points");
- else if(man_op==1)
- {
-
- east1 = G_col_to_easting((double) c1, &cellhd1);
- north1 = G_row_to_northing((double) r1, &cellhd1);
-
-
- sPoints.e1[sPoints.count-1] = east1;
- sPoints.n1[sPoints.count-1] = north1;
-
-
-
- R_standard_color (BLUE);
- display_one_point(VIEW_MAP1,east1,north1);
-
-
- manual_op1();
-
-
- east2 = e_man2;
- north2 = n_man2;
-
-
- r2 = G_northing_to_row(north2,&cellhd2);
- c2 = G_easting_to_col(east2,&cellhd2);
-
-
- sPoints.e2[sPoints.count-1] = east2;
- sPoints.n2[sPoints.count-1] = north2;
-
- display_points_in_view_diff_color (VIEW_MAP2, 1,
- sPoints.e2, sPoints.n2,
- sPoints.status, sPoints.count);
-
-
-
- R_flush();
-
-
- }
-
-
-
-
- /* Fill the POINTS file*/
- sPoints.status[sPoints.count-1] = 1;
- sPoints.count += 1;
- sPoints.e1=(double *)G_realloc(sPoints.e1,sPoints.count*sizeof(double));
- sPoints.n1=(double *)G_realloc(sPoints.n1,sPoints.count*sizeof(double));
- sPoints.e2=(double *)G_realloc(sPoints.e2,sPoints.count*sizeof(double));
- sPoints.n2=(double *)G_realloc(sPoints.n2,sPoints.count*sizeof(double));
- sPoints.status=(int *)G_realloc(sPoints.status,sPoints.count*sizeof(int));
-
-
- }
-
-
- else if( (n==1) && (man_m_s_op==1) )
- {
- manual_m_s_op1();
-
- east1 = e_man1;
- north1 = n_man1;
-
- r1 = G_northing_to_row(north1,&cellhd1);
- c1 = G_easting_to_col(east1,&cellhd1);
-
-
- sPoints.e1[sPoints.count-1] = east1;
- sPoints.n1[sPoints.count-1] = north1;
-
-
- R_standard_color (BLUE);
- display_one_point(VIEW_MAP1,east1,north1);
-
-
-
- manual_op1();
-
-
- east2 = e_man2;
- north2 = n_man2;
-
-
- r2 = G_northing_to_row(north2,&cellhd2);
- c2 = G_easting_to_col(east2,&cellhd2);
-
-
- sPoints.e2[sPoints.count-1] = east2;
- sPoints.n2[sPoints.count-1] = north2;
-
-
- display_points_in_view_diff_color (VIEW_MAP2, 1,
- sPoints.e2, sPoints.n2,
- sPoints.status, sPoints.count);
-
-
-
- R_flush();
-
-
- /* Fill the POINTS file*/
- sPoints.status[sPoints.count-1] = 1;
- sPoints.count += 1;
- sPoints.e1=(double *)G_realloc(sPoints.e1,sPoints.count*sizeof(double));
- sPoints.n1=(double *)G_realloc(sPoints.n1,sPoints.count*sizeof(double));
- sPoints.e2=(double *)G_realloc(sPoints.e2,sPoints.count*sizeof(double));
- sPoints.n2=(double *)G_realloc(sPoints.n2,sPoints.count*sizeof(double));
- sPoints.status=(int *)G_realloc(sPoints.status,sPoints.count*sizeof(int));
-
-
-
- }
-
-
-
-
- else
- {
-
-
- /*Begin computation*/
- search_border = search_window_dim / 2;
-
- for(r = search_border; r < dim_win_r - search_border; r += search_jump)
- {
- for(c = search_border; c < dim_win_c - search_border; c += search_jump)
- {
-
- /* Reinizialize fft vectors */
-
- for(i=0;i<squared_search_window_dim;i++)
- {
- fft_first[0][i]=0.0;
- fft_first[1][i]=0.0;
- fft_second[0][i]=0.0;
- fft_second[1][i]=0.0;
- fft_prod_con[0][i]=0.0;
- fft_prod_con[1][i]=0.0;
- }
-
-
- /* Coordinates of the "initial" point */
-
- east1 = G_col_to_easting((double) c, &cellhd1);
- north1 = G_row_to_northing((double) r, &cellhd1);
-
- /* Real window in the first image */
-
- Extract_portion_of_double_matrix(r,c,search_border,search_border,
- mat1_R,search_window);
-
- mean = 0.0;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- mean += search_window[i][j];
- }
- }
- mean /= squared_search_window_dim;
-
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- fft_first[0][i*search_window_dim+j]=search_window[i][j]-mean;
- }
- }
-
-
- /* Real window in the second image */
-
- if((r-search_border+2*search_border>=nrows2)||(c-search_border+2*search_border>=ncols2))
- {
- if (sPoints.count<=1)
- {
- Menu_msg("DEFINE A NEW REGION.");
- sleep(3);
- pause;
- }
- return 0;
- }
-
- Extract_portion_of_double_matrix(r,c,search_border,search_border,
- mat2_R,search_window);
- mean = 0.0;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- mean += search_window[i][j];
- }
- }
- mean /= squared_search_window_dim;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- fft_second[0][i*search_window_dim+j]=search_window[i][j]-mean;
- }
- }
-
-
-
-
- /* fft of the 2 (complex) windows */
- fft(-1,fft_first,squared_search_window_dim,search_window_dim,
- search_window_dim);
- fft(-1,fft_second,squared_search_window_dim,search_window_dim,
- search_window_dim);
-
-
-
-
-
- /* product of the first fft for the coniugate of the second one */
- for(i=0;i<squared_search_window_dim;i+=1)
- {
- fft_prod_con[0][i] = (fft_first[0][i] * fft_second[0][i]) +
- (fft_first[1][i] * fft_second[1][i]);
- fft_prod_con[1][i] = (fft_first[1][i] * fft_second[0][i]) -
- (fft_first[0][i] * fft_second[1][i]);
- }
-
-
-
-
-
- /* fft^{-1} of the product <==> cross-correlation at differnet lag
- between the two orig. (complex) windows */
- fft(1,fft_prod_con,squared_search_window_dim,search_window_dim,
- search_window_dim);
-
-
-
-
-
- /* Search the lag coresponding to the maximum correlation */
- cc = 0.0;
-
- for(i=0;i<squared_search_window_dim;i++)
- {
- if(fft_prod_con[0][i] > cc)
- {
- cc = fft_prod_con[0][i];
- tmp_r=i/search_window_dim;
- tmp_c=i%search_window_dim;
-
- }
- }
-
- /* Get coordinates of "ending" point */
- if((tmp_r <= search_window_dim/2) && (tmp_c <= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - tmp_c,&cellhd2);
- north2 = G_row_to_northing((double) r - tmp_r,&cellhd2);
-
- }
- if((tmp_r <= search_window_dim/2) && (tmp_c >= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - (tmp_c-search_window_dim-1),&cellhd2);
- north2 = G_row_to_northing((double) r - tmp_r,&cellhd2);
-
- }
- if((tmp_r >= search_window_dim/2) && (tmp_c <= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - tmp_c,&cellhd2);
- north2 = G_row_to_northing((double) r - (tmp_r-search_window_dim-1),&cellhd2);
-
- }
- if((tmp_r >= search_window_dim/2) && (tmp_c >= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - (tmp_c-search_window_dim-1),&cellhd2);
- north2 = G_row_to_northing((double) r - (tmp_r-search_window_dim-1),&cellhd2);
-
- }
-
-
-
- /* Fill the POINTS file*/
- sPoints.e1[sPoints.count-1] = east1;
- sPoints.n1[sPoints.count-1] = north1;
- sPoints.e2[sPoints.count-1] = east2;
- sPoints.n2[sPoints.count-1] = north2;
-
- sPoints.status[sPoints.count-1] = 1;
- sPoints.count += 1;
- sPoints.e1=(double *)G_realloc(sPoints.e1,sPoints.count*sizeof(double));
- sPoints.n1=(double *)G_realloc(sPoints.n1,sPoints.count*sizeof(double));
- sPoints.e2=(double *)G_realloc(sPoints.e2,sPoints.count*sizeof(double));
- sPoints.n2=(double *)G_realloc(sPoints.n2,sPoints.count*sizeof(double));
- sPoints.status=(int *)G_realloc(sPoints.status,sPoints.count*sizeof(int));
+ for (i = 0; i < sPoints.count; i++) {
+ if (sPoints.status[i] != -1) {
+ I_new_control_point(&group.points, sPoints.e1[i],
+ sPoints.n1[i], sPoints.e2[i],
+ sPoints.n2[i], sPoints.status[i]);
}
- G_percent (r,dim_win_r, 1);
}
+ if (sPoints.count < n_new_points)
+ G_message(_("%d of %d points had a poor FFT correlation"),
+ n_new_points - sPoints.count, n_new_points);
+ if (n_points_filtered == 0)
+ G_message(_("%d points found but no point was below RMS threshold %.4G"),
+ sPoints.count, rms_threshold);
+ else if (rms_threshold > 0 && n_points_filtered < sPoints.count)
+ G_message(_("%d points found, %d point%s below RMS threshold %.4G"),
+ sPoints.count, n_points_filtered,
+ n_points_filtered > 1 ? _("s were") : (" was"),
+ rms_threshold);
+ else
+ G_message(_("%d points found"), sPoints.count);
-
-
+ select_current_env();
}
-}
+ G_debug(1, "Free memory");
+ /* Free memory */
-void Extract_portion_of_double_matrix(int r,int c,int br,int bc,DCELL **mat,DCELL **wind)
- /*
- extract a squared portion of a matrix mat
- given a the indeces of the center [r,c]
- and the semilength of the borders [br,bc]
- Output to array wind
- */
-{
- int i,j;
- for(i=0;(i <2*br);i++)
- for(j = 0;(j <2*bc);j++)
- {
- wind[i][j] = mat[r - br + i][c - bc +j];
- }
-}
+ G_free(mat1);
+ G_free(mat2);
+ G_debug(1, "Free points");
+ G_free(sPoints.e1);
+ G_free(sPoints.n1);
+ G_free(sPoints.n2);
+ G_free(sPoints.e2);
+ G_free(sPoints.status);
-
-
-
-
-
-static int less_GCPs()
-{
-
- n_points = 1;
-
- return 0;
+ G_message(_("Done searching"));
+ return;
}
-
-
-
-static int manual_op()
+void Search_correlation_points_auto(DCELL *mat1_R, DCELL *mat2_R,
+ int search_window_dim, int n_windows,
+ double thresh)
{
- man_op = 1;
+ int search_border;
+ struct Control_Points fftPoints;
+ double *fft_first_s[2];
+ double *fft_second_s[2];
+ double *fft_prod_con_s[2];
+ int fft_rows, fft_cols;
+ long fft_size;
+ int fft_r, fft_c, i, j;
+ int squared_search_window_dim;
+ long l_i;
+ int r_start, c_start, r_start1, c_start1, r_end, c_end;
+ double *cc;
+ int fft_nr = 0;
+ double north1, east1, north2, east2;
+ int shift_r, shift_c;
+ double mean_1, mean_2;
+ double fft_prod_real, fft_prod_img;
+ double v_product;
+ int check_reading;
+ int dump_unity_pulse = 1;
+ long nc, nt;
- n=1;
+ G_debug(1, "Search_correlation_points_auto()");
+ G_debug(1, "search_window_dim %d", search_window_dim);
- Extract_matrix();
+ /* Correlation parameters */
+ squared_search_window_dim = search_window_dim * search_window_dim;
+ search_border = search_window_dim / 2;
- return 0;
-}
+ fft_rows = search_window_dim;
+ fft_cols = search_window_dim;
+ fft_size = fft_rows * fft_cols;
+ /* Memory allocation */
+ G_debug(1, "Memory allocation");
+ fft_first_s[0] = (double *)G_malloc(fft_size * sizeof(double));
+ fft_first_s[1] = (double *)G_malloc(fft_size * sizeof(double));
+ fft_second_s[0] = (double *)G_malloc(fft_size * sizeof(double));
+ fft_second_s[1] = (double *)G_malloc(fft_size * sizeof(double));
+ fft_prod_con_s[0] = (double *)G_malloc(fft_size * sizeof(double));
+ fft_prod_con_s[1] = (double *)G_malloc(fft_size * sizeof(double));
+ cc = (double *)G_malloc(n_windows * sizeof(double));
+ fftPoints.n1 = (double *)G_malloc(n_windows * sizeof(double));
+ fftPoints.e1 = (double *)G_malloc(n_windows * sizeof(double));
+ fftPoints.n2 = (double *)G_malloc(n_windows * sizeof(double));
+ fftPoints.e2 = (double *)G_malloc(n_windows * sizeof(double));
+ fftPoints.count = 0;
+ /* Begin computation */
+ G_debug(1, "begin computation");
-static int manual_op1()
-{
+ r_end = curr_window.rows - search_border;
+ c_end = curr_window.cols - search_border;
- static int use = 1;
+ /* go through maps */
+ init_rand();
+ nc = curr_window.rows * curr_window.cols;
+ nt = n_windows;
+ G_debug(1, "start loops");
+ for (fft_r = search_border; fft_r < r_end; fft_r++) {
+ r_start = fft_r - search_border;
- static Objects objects[] =
- {
- INFO(" Mark on the second img the Overlap-Point ",&use),
- OTHER(mark_op, &use),
- {0}
- };
-
- Input_pointer (objects);
- Menu_msg ("");
-
-
-
- return 0;
+ G_percent(r_start, r_end - search_border, 2);
+ for (fft_c = search_border; fft_c < c_end; fft_c++) {
+ c_start = fft_c - search_border;
-}
+ nc--;
+ /* Coordinates of center point point for reference matrix 2 */
+ G_debug(2, "get map2 center point");
+ north2 = tgt_window.north - (fft_r + 0.5) * tgt_window.ns_res;
+ east2 = tgt_window.west + (fft_c + 0.5) * tgt_window.ew_res;
+ /* estimate center point in map 1 */
+ CRS_georef(east2, north2, &east1, &north1,
+ group.E21, group.N21, transform_order);
-static int mark_op(int x,int y,int button)
-{
+ /* northing to row */
+ r_start1 = (curr_window.north - north1) / curr_window.ns_res;
+ c_start1 = (east1 - curr_window.west) / curr_window.ew_res;
- static int use = 1;
-
- if (button != 1)
- return where (x,y);
-
- if (VIEW_MAP2->cell.configured && In_view (VIEW_MAP2, x, y))
- mark_point_op(VIEW_MAP2, x, y);
-
- else
- return 0;
-
- return -1 ; /* return but don't quit */
-}
+ r_start1 -= search_border;
+ if (r_start1 < 0 || r_start1 + search_window_dim > curr_window.rows)
+ continue;
+ c_start1 -= search_border;
+ if (c_start1 < 0 || c_start1 + search_window_dim > curr_window.cols)
+ continue;
+ if (make_rand() % nc >= nt)
+ continue;
+ /* only decrement if point with ok FFT correlation found, see below */
+ /* nt--; */
+ /* Initialize fft vectors */
-static int mark_point_op (View *view,int x, int y)
-{
+ G_debug(2, "initialize fft vectors");
+ for (l_i = 0; l_i < fft_size; l_i++) {
+ fft_first_s[0][l_i] = 0.0;
+ fft_first_s[1][l_i] = 0.0;
+ fft_second_s[0][l_i] = 0.0;
+ fft_second_s[1][l_i] = 0.0;
+ fft_prod_con_s[0][l_i] = 0.0;
+ fft_prod_con_s[1][l_i] = 0.0;
+ }
- /* convert x,y to east,north at center of cell */
- c2= view_to_col (view, x);
- e_man2 = col_to_easting (&view->cell.head, c2, 0.5);
- r2= view_to_row (view, y);
- n_man2 = row_to_northing (&view->cell.head, r2, 0.5);
+ /* Get means for search window extends of map1 and map2 */
+ mean_1 = 0.0;
+ mean_2 = 0.0;
+ for (i = 0; i < search_window_dim; i++) {
+ for (j = 0; j < search_window_dim; j++) {
+ mean_1 +=
+ mat1_R[(r_start1 + i) * curr_window.cols + c_start1 + j];
- return 0 ;
+ mean_2 +=
+ mat2_R[(r_start + i) * tgt_window.cols + c_start + j];
+ }
+ }
+ mean_1 = (mean_1 / squared_search_window_dim);
+ mean_2 = (mean_2 / squared_search_window_dim);
-}
+ /* copy search window extends of map1 and map2 to fft arrays */
+ check_reading = 0;
+ for (i = 0; i < search_window_dim; i++) {
-static int manual_m_s_op()
-{
- man_m_s_op = 1;
+ for (j = 0; j < search_window_dim; j++) {
- n=1;
+ fft_first_s[0][i * search_window_dim + j] =
+ (mat1_R
+ [(r_start1 + i) * curr_window.cols + c_start1 + j] - mean_1);
- Extract_matrix();
+ fft_second_s[0][i * search_window_dim + j] =
+ (mat2_R
+ [(r_start + i) * tgt_window.cols + c_start + j] - mean_2);
+ if (fft_first_s[0][i * search_window_dim + j])
+ check_reading = 1;
+ }
+ }
- return 0;
-}
+ if (check_reading == 0) {
+ G_warning(_("First matrix not copied"));
+ continue;
+ }
+ /* real to complex fft of the 2 real windows */
+ fft(-1, fft_first_s, fft_size, fft_cols, fft_rows);
+ fft(-1, fft_second_s, fft_size, fft_cols, fft_rows);
-static int manual_m_s_op1()
-{
- static int use = 1;
+ /* overlay the two signals: multiplication
+ product of the first fft with the conjugate of the second one
+ division by magnitude |F(map1) * F(map2)*|
+ */
- static Objects objects[] =
- {
- INFO(" Mark on the first img the Overlap-Point ",&use),
- OTHER(mark_m_s_op, &use),
- {0}
- };
-
- Input_pointer (objects);
- Menu_msg ("");
-
+ G_debug(2, "compute power spectrum");
+ check_reading = 0;
+ v_product = 0.0;
+ for (l_i = 0; l_i < fft_size; l_i++) {
- return 0;
-}
+ fft_prod_real =
+ (fft_first_s[0][l_i] * fft_second_s[0][l_i]) +
+ (fft_first_s[1][l_i] * fft_second_s[1][l_i]);
+ fft_prod_img =
+ (fft_first_s[1][l_i] * fft_second_s[0][l_i]) -
+ (fft_first_s[0][l_i] * fft_second_s[1][l_i]);
-static int mark_m_s_op(int x,int y,int button)
-{
+ v_product += sqrt(fft_prod_real * fft_prod_real + fft_prod_img * fft_prod_img);
+ }
+ v_product /= search_window_dim; /* fft_size; */
- static int use = 1;
-
- if (button != 1)
- return where (x,y);
-
- if (VIEW_MAP1->cell.configured && In_view (VIEW_MAP1, x, y))
- mark_point_m_s_op(VIEW_MAP1, x, y);
-
- else
- return 0;
-
- return -1 ; /* return but don't quit */
-}
+ for (l_i = 0; l_i < fft_size; l_i++) {
+ fft_prod_real =
+ (fft_first_s[0][l_i] * fft_second_s[0][l_i]) +
+ (fft_first_s[1][l_i] * fft_second_s[1][l_i]);
+ fft_prod_img =
+ (fft_first_s[1][l_i] * fft_second_s[0][l_i]) -
+ (fft_first_s[0][l_i] * fft_second_s[1][l_i]);
+ fft_prod_con_s[0][l_i] = (fft_prod_real / v_product);
+ fft_prod_con_s[1][l_i] = (fft_prod_img / v_product);
+ if (fft_prod_real != 0.0 && fft_prod_img != 0.0) {
+ check_reading = 1;
+ }
+ }
-static int mark_point_m_s_op (View *view,int x, int y)
-{
+ if (check_reading == 0) {
+ G_debug(2, "FFT product error");
+ continue;
+ }
- /* convert x,y to east,north at center of cell */
- c1= view_to_col (view, x);
- e_man1 = col_to_easting (&view->cell.head, c1, 0.5);
- r1= view_to_row (view, y);
- n_man1 = row_to_northing (&view->cell.head, r1, 0.5);
+ /* reverse fft to create a compound signal */
+ /* fft^{-1} of the product <==> cross-correlation at different lag
+ between the two orig. (complex) windows */
+ fft(1, fft_prod_con_s, fft_size, fft_cols, fft_rows);
+ /* Search the lag corresponding to the maximum correlation */
+ /* actually the unity pulse */
+ cc[fftPoints.count] = 0.0;
+ shift_r = shift_c = 0;
+ G_debug(2, "find unity pulse");
- return 0 ;
+ for (i = 0; i < search_window_dim; i++) {
+ for (j = 0; j < search_window_dim; j++)
+ if (fft_prod_con_s[0][(i * fft_cols) + j] >
+ cc[fftPoints.count]) {
+ cc[fftPoints.count] =
+ fft_prod_con_s[0][(i * fft_cols) + j];
+ shift_r = i;
+ shift_c = j;
+ }
+ }
+ /* cc was somewhere larger than thresh */
+ if (cc[fftPoints.count] > thresh) {
+ G_debug(2, "correlation: %4e", cc[fftPoints.count]);
-}
+ /* Get row and col of "ending" point in map 2 */
+ /* not yet understood layout of inverse fft
+ * if tmp_r < search_border, tmp_r = tmp_r + search_border
+ * if tmp_r >= search_border, tmp_r = tmp_r - search_border
+ * if tmp_c < search_border, tmp_c = tmp_c + search_border
+ * if tmp_c >= search_border, tmp_c = tmp_c - search_border
+ *
+ * now get shift: tmp_r = tmp_r - search_border
+ *
+ * now add shift to r
+ */
+ /* indices are zero-based: the nth row is row n-1 */
+ if (shift_r < search_border)
+ shift_r = shift_r + search_border;
+ else
+ shift_r = shift_r - search_border;
+ shift_r = shift_r - search_border;
+ if (shift_c < search_border)
+ shift_c = shift_c + search_border;
+ else
+ shift_c = shift_c - search_border;
+ shift_c = shift_c - search_border;
-static int central()
-{
- n=1;
- pos_point = 0;
- man_op=0;
+ G_debug(2, "row shift %d, col shift %d", shift_r, shift_c);
- Extract_matrix();
+ /* Get coordinates of "ending" point in source map 1 */
+ r_start1 += search_border;
+ north1 =
+ curr_window.north - (r_start1 + shift_r + 0.5) * curr_window.ns_res;
+ c_start1 += search_border;
+ east1 =
+ curr_window.west + (c_start1 + shift_c + 0.5) * curr_window.ew_res;
- return 0;
+ /* Fill the fftPoints array */
+ fftPoints.e1[fftPoints.count] = east1;
+ fftPoints.n1[fftPoints.count] = north1;
+ fftPoints.e2[fftPoints.count] = east2;
+ fftPoints.n2[fftPoints.count] = north2;
+ fftPoints.count++;
-}
+ /* dump unity pulse */
+ if (dump_unity_pulse) {
+ int rd, cd, fd;
+ DCELL *dump, dnullval;
+ char dumpfile[GNAME_MAX];
+ sprintf(dumpfile, "unity_pulse_%d", fftPoints.count);
+ fd = Rast_open_new(dumpfile, DCELL_TYPE);
-static int shift1()
-{
- double nn_1,ee_1,ss_1,ww_1,rr1_1,rr1_2,cc1_1,cc1_2,nnrows1,nncols1;
- int shift1;
+ dump = Rast_allocate_d_input_buf();
+ Rast_set_d_null_value(&dnullval, 1);
- nn_1=VIEW_MAP1->cell.head.north;
- ee_1=VIEW_MAP1->cell.head.east;
- ss_1=VIEW_MAP1->cell.head.south;
- ww_1=VIEW_MAP1->cell.head.west;
-
- rr1_1=ss_1/VIEW_MAP1->cell.ns_res;
- rr1_2=nn_1/VIEW_MAP1->cell.ns_res;
- cc1_1=ww_1/VIEW_MAP1->cell.ew_res;
- cc1_2=ee_1/VIEW_MAP1->cell.ew_res;
-
- nnrows1=rr1_2-rr1_1;
- nncols1=cc1_2-cc1_1;
+ r_start1 -= search_border;
+ c_start1 -= search_border;
+ for (rd = 0; rd < curr_window.rows; rd++) {
+ for (cd = 0; cd < curr_window.cols; cd++) {
-
- shift1 = (((nnrows1 + nncols1)/2)/100)*5;
-
- switch (pos_point)
- {
-
- case 1: dist = shift1;
- dist_r = -shift1;
- dist_c = 0;
- break;
- case 2: dist = shift1;
- dist_r = shift1;
- dist_c = 0;
- break;
- case 3: dist = shift1;
- dist_c = shift1;
- dist_r = 0;
- break;
- case 4: dist = shift1;
- dist_c = -shift1;
- dist_r = 0;
- break;
- }
-
-
-
- Extract_matrix();
-
- return 0;
-}
-
-
-
-
-static int shift2()
-{
-
- double nn_1,ee_1,ss_1,ww_1,rr1_1,rr1_2,cc1_1,cc1_2,nnrows1,nncols1;
- int shift2;
-
- nn_1=VIEW_MAP1->cell.head.north;
- ee_1=VIEW_MAP1->cell.head.east;
- ss_1=VIEW_MAP1->cell.head.south;
- ww_1=VIEW_MAP1->cell.head.west;
-
- rr1_1=ss_1/VIEW_MAP1->cell.ns_res;
- rr1_2=nn_1/VIEW_MAP1->cell.ns_res;
- cc1_1=ww_1/VIEW_MAP1->cell.ew_res;
- cc1_2=ee_1/VIEW_MAP1->cell.ew_res;
-
- nnrows1=rr1_2-rr1_1;
- nncols1=cc1_2-cc1_1;
-
-
-
- shift2 = (((nnrows1 + nncols1)/2)/100)*10;
-
-
-
- switch (pos_point)
- {
-
- case 1: dist = shift2;
- dist_r = -shift2;
- dist_c = 0;
- break;
- case 2: dist = shift2;
- dist_r = shift2;
- dist_c = 0;
- break;
- case 3: dist = shift2;
- dist_c = shift2;
- dist_r = 0;
- break;
- case 4: dist = shift2;
- dist_c = -shift2;
- dist_r = 0;
- break;
- }
-
-
-
- Extract_matrix();
-
- return 0;
-}
-
-
-
-
-
-static int top()
-{
- static int use = 1;
-
- n=1;
- pos_point = 1;
- man_op=0;
-
- static Objects objects2[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" <-- ",cancel,&use),
- INFO(" Shift O.P. (% of map) -> ",&use),
- MENU(" 5% ",shift1,&use),
- MENU(" 10% ",shift2,&use),
- {0}
- };
-
- Input_pointer (objects2);
-
-
- return 0;
-
-}
-
-
-
-
-
-static int bottom()
-{
- static int use = 1;
-
- n=1;
- pos_point = 2;
- man_op=0;
-
- static Objects objects3[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" <-- ",cancel,&use),
- INFO(" Shift O.P. (% of map) -> ",&use),
- MENU(" 5% ",shift1,&use),
- MENU(" 10% ",shift2,&use),
- {0}
- };
-
- Input_pointer (objects3);
-
-
- return 0;
-
-}
-
-
-
-static int left()
-{
- static int use = 1;
-
- n=1;
- pos_point = 3;
- man_op=0;
-
- static Objects objects4[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" <-- ",cancel,&use),
- INFO(" Shift O.P. (% of map) -> ",&use),
- MENU(" 5% ",shift1,&use),
- MENU(" 10% ",shift2,&use),
- {0}
- };
-
- Input_pointer (objects4);
-
-
- return 0;
-
-}
-
-
-
-static int right()
-{
- static int use = 1;
-
- n=1;
- pos_point = 4;
- man_op=0;
-
- static Objects objects5[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" <-- ",cancel,&use),
- INFO(" Shift O.P. (% of map) -> ",&use),
- MENU(" 5% ",shift1,&use),
- MENU(" 10% ",shift2,&use),
- {0}
- };
-
- Input_pointer (objects5);
-
-
- return 0;
-
-}
-
-
-
-
-
-
-static int try_again()
-{
-
- static int use = 1;
-
- G_get_cellhd (name1_initial, mapset_initial, &cellhd1);
- G_adjust_window_to_box (&cellhd1, &VIEW_MAP1->cell.head, VIEW_MAP1->nrows, VIEW_MAP1->ncols);
- Configure_view (VIEW_MAP1, name1_initial, mapset_initial, cellhd1.ns_res, cellhd1.ew_res);
- drawcell(VIEW_MAP1);
- display_points(1);
- R_flush();
- Curses_clear_window (PROMPT_WINDOW);
-
- Erase_view (VIEW_MAP1_ZOOM);
-
-
- G_get_cellhd (name2_initial, mapset_initial, &cellhd2);
- G_adjust_window_to_box (&cellhd2, &VIEW_MAP2->cell.head, VIEW_MAP2->nrows, VIEW_MAP2->ncols);
- Configure_view (VIEW_MAP2, name2_initial, mapset_initial, cellhd2.ns_res, cellhd2.ew_res);
- drawcell(VIEW_MAP2);
- display_points(1);
- R_flush();
- Curses_clear_window (PROMPT_WINDOW);
-
- Erase_view (VIEW_MAP2_ZOOM);
-
-
- static Objects objects3[]=
- {
-
-
- MENU(" MAIN MENU ",cancel,&use),
- INFO(" O.P. -> ",&use),
- MENU(" Central ",central,&use),
- MENU(" Top ",top,&use),
- MENU(" Bottom ",bottom,&use),
- MENU(" Left ",left,&use),
- MENU(" Right ",right,&use),
- INFO(" ",&use),
- MENU(" LESS GCPs ",less_GCPs,&use),
- MENU(" Mark Slave-O.P. ",manual_op,&use),
- MENU(" Mark M&S-O.P. ",manual_m_s_op,&use),
- {0}
- };
-
-
- Input_pointer (objects3);
-
- return 0;
-}
-
-
-
-
-
-
-
-
-
-static int store_points()
-{
-
- int i;
-
-
- sPoints.count -= 1;
- if(sPoints.count > 0)
- {
-
- sprintf(file_name,"%s/%s/%s/group/%s/POINTS",group_GISDBASE,
- group_LOCATION_NAME,group_MAPSET,group_name);
-
- fp = fopen(file_name,"w");
- fprintf (fp,"# %7s %15s %15s %15s %9s status\n","",
- "provaimage","","target","");
- fprintf (fp,"# %15s %15s %15s %15s (1=ok)\n",
- "east","north","east","north");
- fprintf (fp,"#\n");
-
- for (i = 1; i < sPoints.count; i++) /* i=1 because the sPoints[0] is the O.P. */
- if ( sPoints.status[i] != -1)
- fprintf (fp, " %15f %15f %15f %15f %4d\n",
- sPoints.e1[i], sPoints.n1[i], sPoints.e2[i], sPoints.n2[i], sPoints.status[i]);
-
-
- fclose (fp);
- }
-
-
-
- /* Load new control points */
-
- for (i = 1; i < sPoints.count; i++)
- if ( sPoints.status[i] != -1)
- I_new_control_point (&group.points,sPoints.e1[i], sPoints.n1[i],
- sPoints.e2[i], sPoints.n2[i], sPoints.status[i] );
-
-
-
- m=1; /* To directly return to the main menu */
-
-
- return 0;
-
-}
-
-
-
-
-
-static int main_menu()
-{
- m=1;
-
- return 0;
-}
-
-
-static int
-cancel (void)
-{
- return -1;
-}
-
-
-
-
-
-
-static int change_rms_th()
-{
- static int use = 1;
-
- static Objects objects[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" <-- ",cancel,&use),
- INFO(" ",&use),
- MENU(" 1 ",th_1,&use),
- MENU(" 2 ",th_2,&use),
- MENU(" 3 ",th_3,&use),
- MENU(" 4 ",th_4,&use),
- MENU(" 5 ",th_5,&use),
- MENU(" OTHER ",other_th,&use),
- /*
- OPTION(" 1 ", 2, &after_OPTION_out),
- OPTION(" 2 ", 2, &temp_th_2),
- OPTION(" 3 ", 2, &temp_th_3),
- OPTION(" 4 ", 2, &temp_th_4),
- OPTION(" 5 ", 2, &temp_th_5),*/
- {0}
- };
-
-
-
- Input_pointer (objects);
-
-
- return 0;
-}
-
-
-
-static int after_th()
-{
- static int use = 1;
-
-
- static Objects objects3[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" STORE POINTS IN FILE ",store_points,&use),
- MENU(" TRY AGAIN ",try_again,&use),
- INFO(" ",&use),
- MENU(" rms-th ",change_rms_th,&use),
- MENU(" Auto-Exclusion GCPs ",auto_exclusion,&use),
- {0}
- };
-
-
- Input_pointer (objects3);
-
-
-
- return 0;
-}
-
-
-
-
-
-
-static int th_1()
-{
- th=1;
-
- after_th();
-
- return 0;
-}
-
-
-static int th_2()
-{
- th=2;
-
- after_th();
-
- return 0;
-}
-
-
-static int th_3()
-{
- th=3;
-
- after_th();
-
- return 0;
-}
-
-
-static int th_4()
-{
- th=4;
-
- after_th();
-
- return 0;
-}
-
-static int th_5()
-{
- th=5;
-
- after_th();
-
- return 0;
-}
-
-
-
-static int other_th()
-{
- char buf[100];
- double tmp_th;
-
- G_clear_screen();
-
- while(1)
- {
- Curses_prompt_gets ("Insert the rms-threshold desired: ", buf);
- sscanf (buf, "%lf", &tmp_th);
- if(tmp_th!=0) break;
-
- }
-
- th = tmp_th;
-
- after_th();
-
- return 0;
-}
-
-
-
-
-
-int auto_exclusion(void)
-{
- int k;
- int i;
- static int use = 1;
-
- sPoints.count = sPoints.count -1;
-
- /* Load new control points */
-
- for (i = 1; i < sPoints.count; i++)
- if ( sPoints.status[i] != -1)
- I_new_control_point (&group.points,sPoints.e1[i], sPoints.n1[i],
- sPoints.e2[i], sPoints.n2[i], sPoints.status[i] );
-
-
-
-
- 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();
-
-
- while(rms>=th)
- {
- for(k=0; k < group.points.count; k++)
- {
-
- if(group.equation_stat > 0 && group.points.status[k]==1)
- {
-
- if (k == xmax || k == ymax || k == gmax)
- {
- group.points.status[k] = 0;
+ if (rd < r_start1 || rd >= r_start1 + search_window_dim)
+ dump[cd] = dnullval;
+ else if (cd < c_start1 || cd >= c_start1 + search_window_dim)
+ dump[cd] = dnullval;
+ else
+ dump[cd] = fft_prod_con_s[0][((rd - r_start1) * fft_cols) + (cd - c_start1)];
+ }
+ Rast_put_d_row(fd, dump);
+ }
+ Rast_close(fd);
+ G_free(dump);
}
+ /* point with sufficiently good FFT correlation: decrease nt */
+ nt--;
}
- compute_transformation();
-
+ else {
+ G_debug(2, "correlation: %4e", cc[fftPoints.count]);
+ }
+ fft_nr++;
}
}
- display_points(1);
+ G_percent(1, 1, 2); /* finish it */
-
-
- static Objects objects[]=
- {
- MENU(" MAIN MENU ",main_menu,&use),
- MENU(" ANALYZE & STORE ",pre_analyze,&use),
- {0}
- };
-
- Input_pointer (objects);
+ if (fftPoints.count > 0) {
- free (xres); free (yres); free (gnd);
+ for (i = 0; i < fftPoints.count; i++) {
+ /* Fill the sPoints array */
+ sPoints.e1[sPoints.count - 1] = fftPoints.e1[i];
+ sPoints.n1[sPoints.count - 1] = fftPoints.n1[i];
+ sPoints.e2[sPoints.count - 1] = fftPoints.e2[i];
+ sPoints.n2[sPoints.count - 1] = fftPoints.n2[i];
- return 0;
-}
-
-
-
-static int pre_analyze()
-{
-
- analyze();
-
- m=1;
-
- return 0;
-}
-
-
-
-
-
-
-static int compute_transformation (void)
-{
- int n, count;
- double d,d1,d2,sum;
- double e1, e2, n1, n2;
- double t1, t2, u1, u2;
- double xval, yval, gval;
- double tval, uval, lgval;
-
- xmax = ymax = gmax = 0;
- xval = yval = gval = 0.0;
-
- Compute_equation();
-
- /* compute the row,col error plus ground error
- * keep track of largest and second largest error
- */
- sum = 0.0;
- rms = 0.0;
- count = 0;
- for (n = 0; n < group.points.count && group.equation_stat>0; n++)
- {
- if (group.points.status[n] !=1) continue;
- count++;
- georef (group.points.e2[n], group.points.n2[n], &e1, &n1, group.E21, group.N21);
- georef (group.points.e1[n], group.points.n1[n], &e2, &n2, group.E12, group.N12);
-
- if((d = xres[n] = e1-group.points.e1[n]) < 0)
- d = -d;
- if (d > xval)
- {
- xmax = n;
- xval = d;
+ sPoints.status[sPoints.count - 1] = 1;
+ sPoints.count += 1;
+ sPoints.e1 =
+ (double *)G_realloc(sPoints.e1, sPoints.count * sizeof(double));
+ sPoints.n1 =
+ (double *)G_realloc(sPoints.n1, sPoints.count * sizeof(double));
+ sPoints.e2 =
+ (double *)G_realloc(sPoints.e2, sPoints.count * sizeof(double));
+ sPoints.n2 =
+ (double *)G_realloc(sPoints.n2, sPoints.count * sizeof(double));
+ sPoints.status =
+ (int *)G_realloc(sPoints.status, sPoints.count * sizeof(int));
}
-
- if ((d = yres[n] = n1-group.points.n1[n]) < 0)
- d = -d;
- if (d > yval)
- {
- ymax = n;
- yval = d;
- }
-
- /* compute ground error (ie along diagonal) */
- d1 = e2 - group.points.e2[n];
- d2 = n2 - group.points.n2[n];
- d = d1*d1 + d2*d2;
- sum += d; /* add it to rms sum, before taking sqrt */
- d = sqrt(d);
- gnd[n] = d;
- if (d > gval) /* is this one the max? */
- {
- gmax = n;
- gval = d;
- }
-
}
- /* compute overall rms error */
- if (count)
- rms = sqrt (sum/count);
-
- return 0;
-}
+ /* free memory */
+ G_free(fft_first_s[0]);
+ G_free(fft_first_s[1]);
+ G_free(fft_second_s[0]);
+ G_free(fft_second_s[1]);
+ G_free(fft_prod_con_s[0]);
+ G_free(fft_prod_con_s[1]);
+ G_free(fftPoints.n1);
+ G_free(fftPoints.e1);
+ G_free(fftPoints.n2);
+ G_free(fftPoints.e2);
-
-
-
-
+ return;
+}
Deleted: grass-addons/grass7/imagery/i.points.auto/find_points_semi.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/find_points_semi.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/find_points_semi.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,778 +0,0 @@
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-
-#include <grass/config.h>
-#ifdef HAVE_FFTW_H
-#include <fftw.h>
-#endif
-#ifdef HAVE_DFFTW_H
-#include <dfftw.h>
-#endif
-
-#include <grass/raster.h>
-#include <grass/imagery.h>
-#include <grass/gmath.h>
-#include "globals.h"
-#include "local_proto.h"
-
-#ifdef NULL_VALUE
-#undef NULL_VALUE
-#endif
-#define NULL_VALUE -1
-
-
-#ifdef DEBUG
-#undef DEBUG
-#endif
-
-double *fft_first_s[2];
-double *fft_second_s[2];
-double *fft_prod_con_s[2];
-
-View *ms1, *ms2;
-
-void Extract_matrix_semi()
-{
- struct GModule *module;
- struct Control_Points *cp1;
- char buf[256];
- char *s;
- int rows, cols;
- char *first_map_R_mapset;
- char *first_map_R_name;
- int first_map_R_fd;
- char *second_map_R_mapset;
- char *second_map_R_name;
- int second_map_R_fd;
-
- int K;
-
- int correlation_window_dim;
- int search_window_dim;
-
- int squared_search_window_dim;
- int search_jump;
-
- int ncols1, ncols2, nrows1, nrows2;
- int left1, top1, left2, top2;
- int repeat;
-
- int n_1, e_1, n_2, e_2, s_1, s_2, w_1, w_2;
- int r1_1, r1_2, r2_1, r2_2;
- int c1_1, c1_2, c2_1, c2_2;
-
- int i;
-
- int h1_r;
- int h1_c;
- int h2_r;
- int h2_c;
-
-
- char *group_name;
- char *group_MAPSET;
- char *group_LOCATION_NAME;
- char *group_GISDBASE;
- DCELL *rowbuf1_R;
- DCELL *tf1_R;
- DCELL *rowbuf2_R;
- DCELL *tf2_R;
- double **search_window;
- double **mat1,**mat2;
- int r,c;
- int search_border;
- int q;
- int p1;
- int dim_win_c, dim_win_r;
- char first_sites[500];
- char second_sites[500];
- char file_name[500];
- char file_name_old[500];
- FILE *first_fp;
- FILE *second_fp;
- FILE *fp;
- FILE *fp_old;
-
-
-
- /* Read VIEW_MAP1_ZOOM & VIEW_MAP2_ZOOM informations */
-
-
- ms1=VIEW_MAP1_ZOOM;
- ms2=VIEW_MAP2_ZOOM;
-
- first_map_R_name=ms1->cell.name;
- second_map_R_name=ms2->cell.name;
-
- /* rows & cols of VIEW_MAP1_ZOOM */
- n_1=ms1->cell.head.north;
- e_1=ms1->cell.head.east;
- s_1=ms1->cell.head.south;
- w_1=ms1->cell.head.west;
- left1 = ms1->cell.left;
- top1 = ms1->cell.top;
-
- r1_1=s_1/ms1->cell.ns_res;
- r1_2=n_1/ms1->cell.ns_res;
- c1_1=w_1/ms1->cell.ew_res;
- c1_2=e_1/ms1->cell.ew_res;
-
- nrows1=r1_2-r1_1;
- ncols1=c1_2-c1_1;
-
-
- /* rows & cols of VIEW_MAP2_ZOOM */
- n_2=ms2->cell.head.north;
- e_2=ms2->cell.head.east;
- s_2=ms2->cell.head.south;
- w_2=ms2->cell.head.west;
- left2 = ms2->cell.left;
- top2 = ms2->cell.top;
-
- r2_1=s_2/ms2->cell.ns_res;
- r2_2=n_2/ms2->cell.ns_res;
- c2_1=w_2/ms2->cell.ew_res;
- c2_2=e_2/ms2->cell.ew_res;
-
- nrows2=r2_2-r2_1;
- ncols2=c2_2-c2_1;
-
-
-
- /* Initialize the GIS calls */
- module = G_define_module();
- module->description = "Fine registration of two stereo images";
-
- /* Load environmental vars*/
- group_LOCATION_NAME=buf;
- group_LOCATION_NAME=G_getenv("LOCATION_NAME");
- group_GISDBASE=buf;
- group_GISDBASE=G_getenv("GISDBASE");
- group_MAPSET=buf;
- group_MAPSET=G_getenv("MAPSET");
-
-
- /* Correlation parameters */
- correlation_window_dim=((ncols1/10+nrows1/10)/2);
- K=((ncols1/4+nrows1/4)/2);
-
- search_window_dim = G_math_max_pow2(correlation_window_dim + K);
- group_name=group.name;
- squared_search_window_dim=search_window_dim*search_window_dim;
- search_jump=search_window_dim / 2;
-
-
-
- Menu_msg ("Loading first zoom_image...");
-
- /* Open first real map*/
- if((first_map_R_mapset = G_find_cell2(first_map_R_name, "")) == NULL)
- {
- sprintf(buf,"Raster map [%s] not available",first_map_R_name);
- G_fatal_error(buf);
- }
-
-
- if((first_map_R_fd = G_open_cell_old(first_map_R_name,
- first_map_R_mapset)) < 0)
- {
- sprintf(buf,"Error opening raster map [%s]", first_map_R_name);
- G_fatal_error(buf);
- }
-
- /* Set region to first map definition region < ms1 > */
- G_get_cellhd (first_map_R_name, first_map_R_mapset, &cellhd1);
- G_set_window(&cellhd1);
- h1_r=cellhd1.rows;
- h1_c=cellhd1.cols;
-
-
-
- /* Memory allocation for zoom_map_1 */
-
- mat1 = (DCELL **) G_calloc(nrows1,sizeof(DCELL *));
- for(r=0;r<nrows1;r++)
- mat1[r] = (DCELL *) G_calloc(ncols1,sizeof(DCELL));
-
-
- /* Load first map*/
-
- rowbuf1_R = (DCELL *)G_calloc(h1_r * h1_c,sizeof(DCELL));
- tf1_R=rowbuf1_R;
-
- for(r=h1_r-r1_2;r<h1_r-r1_1;r++)
- {
- G_get_d_raster_row(first_map_R_fd, tf1_R, r);
- if (G_is_d_null_value (tf1_R))
- *tf1_R = NULL_VALUE;
- c=0;
- while(c<c1_1)
- {
- tf1_R++;
- c++;
- }
- for(c = c1_1; c < c1_2; c++)
- {
- mat1[-h1_r+r1_2+r][c-c1_1] = *tf1_R;
- tf1_R++;
- }
- }
- G_close_cell(first_map_R_fd);
-
-
- /* Open second map*/
- if((second_map_R_mapset = G_find_cell2(second_map_R_name, "")) == NULL)
- {
- sprintf(buf,"Raster map [%s] not available",second_map_R_name);
- G_fatal_error(buf);
- }
-
- if((second_map_R_fd = G_open_cell_old(second_map_R_name,
- second_map_R_mapset)) < 0)
- {
- sprintf(buf,"Error opening raster map [%s]", second_map_R_name);
- G_fatal_error(buf);
- }
-
- /* Set region to second map definition region */
- G_get_cellhd (second_map_R_name, second_map_R_mapset, &cellhd2);
- G_set_window(&cellhd2);
- h2_r=cellhd2.rows;
- h2_c=cellhd2.cols;
-
-
- /* Memory allocation for zoom_map_2 */
- mat2 = (DCELL **) G_calloc(nrows2,sizeof(DCELL *));
- for(r=0;r<nrows2;r++)
- mat2[r] = (DCELL *) G_calloc(ncols2,sizeof(DCELL));
-
- /* Load second real map */
- Menu_msg ("Loading second zoom_image...");
-
- rowbuf2_R=(DCELL *)G_calloc(h2_r * h2_c,sizeof(DCELL));
- tf2_R=rowbuf2_R;
- for(r=h2_r-r2_2;r<h2_r-r2_1;r++)
-
- {
- G_get_d_raster_row(second_map_R_fd, tf2_R, r);
- c=0;
- while(c<c2_1)
- {
- tf2_R++;
- c++;
- }
- for(c = c2_1; c < c2_2; c++)
- {
- if (G_is_d_null_value (tf2_R))
- *tf2_R = NULL_VALUE;
- mat2[-h2_r+r2_2+r][c-c2_1] = *tf2_R;
- tf2_R++;
- }
- }
-
- G_close_cell(second_map_R_fd);
-
-
- Menu_msg ("Searching points...");
-
- /* Memory allocation */
- search_window = (DCELL **) G_calloc(search_window_dim,
- sizeof(DCELL *));
- for(r=0;r<search_window_dim;r++)
- search_window[r] = (DCELL *) G_calloc(search_window_dim,
- sizeof(DCELL));
-
- fft_first_s[0] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_first_s[1] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_second_s[0] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_second_s[1] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_prod_con_s[0] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
- fft_prod_con_s[1] = (double *)G_calloc(squared_search_window_dim, sizeof(double));
-
-
- /* Inizialize control points */
- sPoints.count=1;
- sPoints.e1=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.n1=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.e2=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.n2=(double *) G_calloc(sPoints.count,sizeof(double));
- sPoints.status=(int *) G_calloc(sPoints.count,sizeof(int));
-
- /* Sites file */
- sprintf(first_sites,"%s/%s/%s/site_lists/%s_%s",G__getenv("GISDBASE"),
- G__getenv("LOCATION_NAME"),G__getenv("MAPSET"),
- group_name,first_map_R_name);
- sprintf(second_sites,"%s/%s/%s/site_lists/%s_%s",G__getenv("GISDBASE"),
- G__getenv("LOCATION_NAME"),G__getenv("MAPSET"),
- group_name,second_map_R_name);
-
-
- /* Set cellhd1 to zoom_map_1 */
- cellhd1.rows=nrows1;
- cellhd1.cols=ncols1;
- cellhd1.north=r1_2*ms1->cell.ns_res;
- cellhd1.south=r1_1*ms1->cell.ns_res;
- cellhd1.east=c1_2*ms1->cell.ew_res;
- cellhd1.west=c1_1*ms1->cell.ew_res;
-
- /* Set cellhd2 to zoom_map_2 */
- cellhd2.rows=nrows2;
- cellhd2.cols=ncols2;
- cellhd2.north=r2_2*ms2->cell.ns_res;
- cellhd2.south=r1_1*ms2->cell.ns_res;
- cellhd2.east=c2_2*ms2->cell.ew_res;
- cellhd2.west=c2_1*ms2->cell.ew_res;
-
- /* Set windows to cellhd1 */
- G_set_window(&cellhd1);
-
-
-
- /******************************************/
- /* function --> Search_correlation_points */
- /******************************************/
- Search_correlation_points_semi(mat1, mat2,
- search_window_dim,
- squared_search_window_dim,
- search_jump,group_name, nrows1, ncols1,
- search_window, r1_2, c1_1, r2_2, c2_1,
- h1_r, h2_r, h1_c, h2_c, nrows2, ncols2 );
-
-
-
-
- /* Build group/POINTS file */
- sPoints.count -= 1;
- if(sPoints.count > 0)
- {
- sprintf(file_name,"%s/%s/%s/group/%s/POINTS",group_GISDBASE,
- group_LOCATION_NAME,group_MAPSET,group_name);
- fp_old = fopen(file_name,"r");
- if( fp_old==NULL)
- {
- q=0;
- }
- else
- {
- q=1;
- fclose(fp_old);
- }
-
- if (q==0)
- {
- fp = fopen(file_name,"a");
- fprintf (fp,"# %7s %15s %15s %15s %9s status\n","",
- "image","","target","");
- fprintf (fp,"# %15s %15s %15s %15s (1=ok)\n",
- "east","north","east","north");
- fprintf (fp,"#\n");
-
- for (i = 0; i < sPoints.count; i++)
- if ( sPoints.status[i] != -1)
- fprintf (fp, " %15f %15f %15f %15f %4d\n",
- sPoints.e1[i], sPoints.n1[i], sPoints.e2[i], sPoints.n2[i], sPoints.status[i]);
-
- }
- if(q==1)
- {
- fp = fopen(file_name,"a");
- for (i = 0; i < sPoints.count; i++)
- if ( sPoints.status[i] != -1)
- fprintf (fp, " %15f %15f %15f %15f %4d\n", sPoints.e1[i], sPoints.n1[i], sPoints.e2[i], sPoints.n2[i], sPoints.status[i]);
- }
- fclose (fp);
- }
-
- /* Load new control points */
-
- for (i = 0; i < sPoints.count; i++)
- if ( sPoints.status[i] != -1)
- I_new_control_point (&group.points,sPoints.e1[i], sPoints.n1[i],
- sPoints.e2[i], sPoints.n2[i], sPoints.status[i] );
-
- /* Build group/REF file */
- /*
- sprintf(file_name,"%s/%s/%s/group/%s/REF",group_GISDBASE,
- group_LOCATION_NAME, group_MAPSET,group_name);
- fp = fopen(file_name,"w");
- fprintf(fp,"%s %s\n",first_map_R_name,first_map_R_mapset);
-
- fclose(fp);
- */
-
- /* Build group/TARGET file */
- sprintf(file_name,"%s/%s/%s/group/%s/TARGET",group_GISDBASE,
- group_LOCATION_NAME, group_MAPSET,group_name);
- fp = fopen(file_name,"w");
- fprintf(fp,"%s\n%s\n",group_LOCATION_NAME,group_MAPSET);
- fclose(fp);
-
- /* Display new points */
- select_current_env ();
- display_points_in_view (VIEW_MAP1, 1,
- group.points.e1, group.points.n1,
- group.points.status, group.points.count);
-
- display_points_in_view (VIEW_MAP1_ZOOM, 1,
- group.points.e1, group.points.n1,
- group.points.status, group.points.count);
-
- display_points_in_view (VIEW_MAP2, 1,
- group.points.e2, group.points.n2,
- group.points.status, group.points.count);
-
- display_points_in_view (VIEW_MAP2_ZOOM, 1,
- group.points.e2, group.points.n2,
- group.points.status, group.points.count);
- R_flush();
-
- /* Free memory */
-
- free( rowbuf1_R);
- free( rowbuf2_R);
-
-
- for(r=0;r<nrows1;r++)
- free( mat1[r]);
- free(mat1);
-
- for(r=0;r<nrows2;r++)
- free( mat2[r]);
- free(mat2);
-
- for(r=0;r<search_window_dim;r++)
- free(search_window[r]);
- free(search_window);
-
- for(r=0;r<2;r++)
- {
- free(fft_first_s[r]);
- free(fft_second_s[r]);
- free(fft_prod_con_s[r]);
- }
-
- sPoints.e1[0];
- sPoints.n1[0];
- sPoints.e2[0];
- sPoints.n2[0];
- sPoints.status[0];
-
- free(sPoints.e1);
- free(sPoints.n1);
- free(sPoints.n2);
- free(sPoints.e2);
- free(sPoints.status);
-
-
-
- return 0;
-}
-
-
-void Search_correlation_points_semi(DCELL **mat1_R, DCELL **mat2_R,
- int search_window_dim,
- int squared_search_window_dim,
- int search_jump, char *group_name,
- int dim_win_r, int dim_win_c,
- DCELL **search_window, int r1_2,int c1_1,
- int r2_2,int c2_1, int h1_r, int h2_r,
- int h1_c, int h2_c, int nrows2, int ncols2 )
-{
- int r,c,i, j,search_border;
- char *group_MAPSET;
- char *group_LOCATION_NAME;
- char *group_GISDBASE;
- char first_sites[500];
- char second_sites[500];
- char file_name[500];
- FILE *fp;
- FILE *first_fp;
- FILE *second_fp;
- double cc;
- double north1,east1,north2,east2;
- int tmp_r,tmp_c;
- double mean;
- int index;
-
-
-
-
-
- /*Begin computation*/
- search_border = search_window_dim / 2;
-
-
- for(r = search_border; r < dim_win_r - search_border; r += search_jump)
- {
- for(c = search_border; c < dim_win_c - search_border; c += search_jump)
- {
- /* Reinizialize fft vectors */
-
- for(i=0;i<squared_search_window_dim;i++)
- {
- fft_first_s[0][i]=0.0;
- fft_first_s[1][i]=0.0;
- fft_second_s[0][i]=0.0;
- fft_second_s[1][i]=0.0;
- fft_prod_con_s[0][i]=0.0;
- fft_prod_con_s[1][i]=0.0;
- }
-
-
- /* Coordinates of the "initial" point */
-
- east1 = G_col_to_easting((double) c, &cellhd1);
- north1 = G_row_to_northing((double) r, &cellhd1);
-
- /* Real window in the first image */
-
- Extract_portion_of_double_matrix_semi(r,c,search_border,search_border,
- mat1_R,search_window);
-
- mean = 0.0;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- mean += search_window[i][j];
- }
- }
- mean /= squared_search_window_dim;
-
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- fft_first_s[0][i*search_window_dim+j]=search_window[i][j]-mean;
- }
- }
-
-
- /* Real window in the second image */
-
- if((r-search_border+2*search_border>=nrows2)||(c-search_border+2*search_border>=ncols2))
- {
- if (sPoints.count<=1)
- {
- Menu_msg("DEFINE A NEW REGION.");
- sleep(3);
- pause;
- }
- return 0;
- }
-
- Extract_portion_of_double_matrix_semi(r,c,search_border,search_border,
- mat2_R,search_window);
- mean = 0.0;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- mean += search_window[i][j];
- }
- }
- mean /= squared_search_window_dim;
- for(i=0;i<search_window_dim;i++)
- {
- for(j=0;j<search_window_dim;j++)
- {
- fft_second_s[0][i*search_window_dim+j]=search_window[i][j]-mean;
- }
- }
-
-#ifdef DEBUG
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_first_s[0][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_first_s[1][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_second_s[0][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_second_s[1][i]);
- }
- fprintf(stderr,"\n\n");
-#endif
- /* fft of the 2 (complex) windows */
- fft(-1,fft_first_s,squared_search_window_dim,search_window_dim,
- search_window_dim);
- fft(-1,fft_second_s,squared_search_window_dim,search_window_dim,
- search_window_dim);
-
-
-#ifdef DEBUG
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_first_s[0][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_first_s[1][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_second_s[0][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_second_s[1][i]);
- }
- fprintf(stderr,"\n\n");
-#endif
-
- /* product of the first fft for the coniugate of the second one */
- for(i=0;i<squared_search_window_dim;i+=1)
- {
- fft_prod_con_s[0][i] = (fft_first_s[0][i] * fft_second_s[0][i]) +
- (fft_first_s[1][i] * fft_second_s[1][i]);
- fft_prod_con_s[1][i] = (fft_first_s[1][i] * fft_second_s[0][i]) -
- (fft_first_s[0][i] * fft_second_s[1][i]);
- }
-
-
-#ifdef DEBUG
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_prod_con_s[0][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_prod_con_s[1][i]);
- }
- fprintf(stderr,"\n\n");
-#endif
-
- /* fft^{-1} of the product <==> cross-correlation at differnet lag
- between the two orig. (complex) windows */
- fft(1,fft_prod_con_s,squared_search_window_dim,search_window_dim,
- search_window_dim);
-
-#ifdef DEBUG
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_prod_con_s[0][i]);
- }
- fprintf(stderr,"\n\n");
- for(i=0;i<squared_search_window_dim;i++)
- {
- fprintf(stderr,"%f\t",fft_prod_con_s[1][i]);
- }
- fprintf(stderr,"\n\n");
-#endif
-
- /* Search the lag coresponding to the maximum correlation */
- cc = 0.0;
-
- for(i=0;i<squared_search_window_dim;i++)
- {
- if(fft_prod_con_s[0][i] > cc)
- {
- cc = fft_prod_con_s[0][i];
- tmp_r=i/search_window_dim;
- tmp_c=i%search_window_dim;
-
- }
- }
-
- /* Get coordinates of "ending" point */
- if((tmp_r <= search_window_dim/2) && (tmp_c <= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - tmp_c,&cellhd2);
- north2 = G_row_to_northing((double) r - tmp_r,&cellhd2);
-
- }
- if((tmp_r <= search_window_dim/2) && (tmp_c >= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - (tmp_c-search_window_dim-1),&cellhd2);
- north2 = G_row_to_northing((double) r - tmp_r,&cellhd2);
-
- }
- if((tmp_r >= search_window_dim/2) && (tmp_c <= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - tmp_c,&cellhd2);
- north2 = G_row_to_northing((double) r - (tmp_r-search_window_dim-1),&cellhd2);
-
- }
- if((tmp_r >= search_window_dim/2) && (tmp_c >= search_window_dim/2))
- {
-
- east2 = G_col_to_easting((double) c - (tmp_c-search_window_dim-1),&cellhd2);
- north2 = G_row_to_northing((double) r - (tmp_r-search_window_dim-1),&cellhd2);
-
- }
-
-
- /* Fill the POINTS file*/
- sPoints.e1[sPoints.count-1] = east1;
- sPoints.n1[sPoints.count-1] = north1;
- sPoints.e2[sPoints.count-1] = east2;
- sPoints.n2[sPoints.count-1] = north2;
-
- sPoints.status[sPoints.count-1] = 1;
- sPoints.count += 1;
- sPoints.e1=(double *)G_realloc(sPoints.e1,sPoints.count*sizeof(double));
- sPoints.n1=(double *)G_realloc(sPoints.n1,sPoints.count*sizeof(double));
- sPoints.e2=(double *)G_realloc(sPoints.e2,sPoints.count*sizeof(double));
- sPoints.n2=(double *)G_realloc(sPoints.n2,sPoints.count*sizeof(double));
- sPoints.status=(int *)G_realloc(sPoints.status,sPoints.count*sizeof(int));
- }
- G_percent (r,dim_win_r, 1);
- }
- }
-
-
-void Extract_portion_of_double_matrix_semi(int r,int c,int br,int bc,DCELL **mat,DCELL **wind)
- /*
- extract a squared portion of a matrix mat
- given a the indeces of the center [r,c]
- and the semilength of the borders [br,bc]
- Output to array wind
- */
-{
- int i,j;
- for(i=0;(i <2*br);i++)
- for(j = 0;(j <2*bc);j++)
- {
- wind[i][j] = mat[r - br + i][c - bc +j];
- }
-}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Deleted: grass-addons/grass7/imagery/i.points.auto/georef.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/georef.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/georef.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,326 +0,0 @@
-#include <signal.h>
-#include "globals.h"
-
-static int floating_exception;
-static void catch(int);
-static double determinant(double,double,
- double,double,double,double,double,double,double);
-
-void (*sigfpe)();
-
-/* find coefficients A,B,C for e2 = A + B*e1 + C*n1
- * also compute the reverse equations
- *
- * return 0 if no points
- * -1 if not solvable
- * 1 if ok
- *
- * method is least squares.
- * the least squares problem reduces to solving the following
- * system of equations for A,B,C
- *
- * s0*A + s1*B + s2*C = x0
- * s1*A + s3*B + s4*C = x1
- * s2*A + s4*B + s5*C = x2
- *
- * use Cramer's rule
- *
- * | x0 s1 s2 | | s0 x0 s2 | | s0 s1 x0 |
- * | x1 s3 s4 | | s1 x1 s4 | | s1 s3 x1 |
- * | x2 s4 s5 | | s2 x2 s5 | | s2 s4 x2 |
- * A = ------------ B = ------------ C = ------------
- * | s0 s1 s2 | | s0 s1 s2 | | s0 s1 s2 |
- * | s1 s3 s4 | | s1 s3 s4 | | s1 s3 s4 |
- * | s2 s4 s5 | | s2 s4 s5 | | s2 s4 s5 |
- *
- */
-
-int compute_georef_equations(
- struct Control_Points *cp,
- double E12[3], double N12[3], double E21[3], double N21[3])
-{
- double s0,s1,s2,s3,s4,s5;
- double x0,x1,x2;
- double det;
- int i;
-
-
- s0 = s1 = s2 = s3 = s4 = s5 = 0.0;
- for (i = 0; i < cp->count; i++)
- {
- if (cp->status[i] != 1)
- continue;
- s0 += 1.0;
- s1 += cp->e1[i];
- s2 += cp->n1[i];
- s3 += cp->e1[i] * cp->e1[i];
- s4 += cp->e1[i] * cp->n1[i];
- s5 += cp->n1[i] * cp->n1[i];
- }
- if (s0 < 0.5) return 0;
-
- floating_exception = 0;
- sigfpe = signal (SIGFPE, catch);
-
-/* eastings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < cp->count; i++)
- {
- if (cp->status[i] != 1)
- continue;
- x0 += cp->e2[i];
- x1 += cp->e1[i] * cp->e2[i];
- x2 += cp->n1[i] * cp->e2[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- E12[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- E12[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- E12[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
-/* northings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < cp->count; i++)
- {
- if (cp->status[i] != 1)
- continue;
- x0 += cp->n2[i];
- x1 += cp->e1[i] * cp->n2[i];
- x2 += cp->n1[i] * cp->n2[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- N12[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- N12[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- N12[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
-/* the inverse equations */
-
- s0 = s1 = s2 = s3 = s4 = s5 = 0.0;
- for (i = 0; i < cp->count; i++)
- {
- if (cp->status[i] != 1)
- continue;
- s0 += 1.0;
- s1 += cp->e2[i];
- s2 += cp->n2[i];
- s3 += cp->e2[i] * cp->e2[i];
- s4 += cp->e2[i] * cp->n2[i];
- s5 += cp->n2[i] * cp->n2[i];
- }
-
-/* eastings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < cp->count; i++)
- {
- if (cp->status[i] != 1)
- continue;
- x0 += cp->e1[i];
- x1 += cp->e2[i] * cp->e1[i];
- x2 += cp->n2[i] * cp->e1[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- E21[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- E21[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- E21[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
-/* northings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < cp->count; i++)
- {
- if (cp->status[i] != 1)
- continue;
- x0 += cp->n1[i];
- x1 += cp->e2[i] * cp->n1[i];
- x2 += cp->n2[i] * cp->n1[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- N21[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- N21[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- N21[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
- signal (SIGFPE, sigfpe);
- return floating_exception ? -1 : 1;
-}
-
-
-int compute_georef_equations_lp (Lines *ln)
-{
- double s0,s1,s2,s3,s4,s5;
- double x0,x1,x2;
- double det;
- int i;
-
-
- s0 = s1 = s2 = s3 = s4 = s5 = 0.0;
- for (i = 0; i < ln->count; i++)
- {
- if (ln->status[i] != 2)
- continue;
- s0 += 1.0;
- s1 += ln->t1[i];
- s2 += ln->u1[i];
- s3 += ln->t1[i] * ln->t1[i];
- s4 += ln->t1[i] * ln->u1[i];
- s5 += ln->u1[i] * ln->u1[i];
- }
- if (s0 < 0.5) return 0;
-
- floating_exception = 0;
- sigfpe = signal (SIGFPE, catch);
-
-/* eastings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < ln->count; i++)
- {
- if (ln->status[i] != 2)
- continue;
- x0 += ln->t2[i];
- x1 += ln->t1[i] * ln->t2[i];
- x2 += ln->u1[i] * ln->t2[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- ln->E12[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- ln->E12[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- ln->E12[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
-/* northings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < ln->count; i++)
- {
- if (ln->status[i] != 2)
- continue;
- x0 += ln->u2[i];
- x1 += ln->t1[i] * ln->u2[i];
- x2 += ln->u1[i] * ln->u2[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- ln->N12[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- ln->N12[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- ln->N12[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
-/* the inverse equations */
-
- s0 = s1 = s2 = s3 = s4 = s5 = 0.0;
- for (i = 0; i < ln->count; i++)
- {
- if (ln->status[i] != 2)
- continue;
- s0 += 1.0;
- s1 += ln->t2[i];
- s2 += ln->u2[i];
- s3 += ln->t2[i] * ln->t2[i];
- s4 += ln->t2[i] * ln->u2[i];
- s5 += ln->u2[i] * ln->u2[i];
- }
-
-/* eastings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < ln->count; i++)
- {
- if (ln->status[i] != 2)
- continue;
- x0 += ln->t1[i];
- x1 += ln->t2[i] * ln->t1[i];
- x2 += ln->u2[i] * ln->t1[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- ln->E21[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- ln->E21[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- ln->E21[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
-/* northings */
- x0 = x1 = x2 = 0.0;
- for (i = 0; i < ln->count; i++)
- {
- if (ln->status[i] != 2)
- continue;
- x0 += ln->u1[i];
- x1 += ln->t2[i] * ln->u1[i];
- x2 += ln->u2[i] * ln->u1[i];
- }
-
- det = determinant (s0,s1,s2,s1,s3,s4,s2,s4,s5);
- if (det == 0.0)
- {
- signal (SIGFPE, sigfpe);
- return -1;
- }
- ln->N21[0] = determinant (x0,s1,s2,x1,s3,s4,x2,s4,s5)/det;
- ln->N21[1] = determinant (s0,x0,s2,s1,x1,s4,s2,x2,s5)/det;
- ln->N21[2] = determinant (s0,s1,x0,s1,s3,x1,s2,s4,x2)/det;
-
- signal (SIGFPE, sigfpe);
- return floating_exception ? -1 : 1;
-}
-
-
-
-static double determinant (
- double a, double b, double c, double d, double e,
- double f, double g, double h, double i)
-{
-/* compute determinant of 3x3 matrix
- * | a b c |
- * | d e f |
- * | g h i |
- */
- return a * (e*i - f*h) - b * (d*i - f*g) + c * (d*h - e*g) ;
-}
-
-static void catch(int n)
-{
- floating_exception = 1;
- signal (n, catch);
-}
-
-int georef (
- double e1,double n1,
- double *e2,double *n2,
- double E[3],double N[3])
-{
- *e2 = E[0] + E[1] * e1 + E[2] * n1;
- *n2 = N[0] + N[1] * e1 + N[2] * n1;
-
- return 0;
-}
Modified: grass-addons/grass7/imagery/i.points.auto/globals.h
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/globals.h 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/globals.h 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,85 +1,34 @@
#include "defs.h"
+#include "crs.h"
#ifndef GLOBAL
# define GLOBAL extern
-# define INIT(x)
-#else
-# define INIT(x) = x
#endif
GLOBAL struct Control_Points sPoints;
GLOBAL struct Cell_head cellhd1;
GLOBAL struct Cell_head cellhd2;
+GLOBAL struct Cell_head curr_window;
+GLOBAL struct Cell_head tgt_window;
+GLOBAL double rms_threshold;
-
-/* Variable for the botton "Main-Menu". */
-GLOBAL int m;
-
-GLOBAL int G_get_color();
-
-GLOBAL int SCREEN_TOP;
-GLOBAL int SCREEN_BOTTOM;
-GLOBAL int SCREEN_LEFT;
-GLOBAL int SCREEN_RIGHT;
-
GLOBAL int correlation_window_dim;
GLOBAL int K;
+GLOBAL int transform_order;
+GLOBAL int n_new_points;
+GLOBAL int detail;
-GLOBAL Window *INFO_WINDOW;
-GLOBAL Window *MENU_WINDOW;
-GLOBAL Window *PROMPT_WINDOW;
-GLOBAL View *VIEW_MAP1;
-GLOBAL View *VIEW_TITLE1;
-GLOBAL View *VIEW_MAP1_ZOOM;
-GLOBAL View *VIEW_TITLE1_ZOOM;
-
-GLOBAL View *VIEW_MAP2;
-GLOBAL View *VIEW_TITLE2;
-GLOBAL View *VIEW_MAP2_ZOOM;
-GLOBAL View *VIEW_TITLE2_ZOOM;
-
-GLOBAL View *VIEW_MENU;
-
GLOBAL Group group;
GLOBAL char interrupt_char;
GLOBAL char *tempfile1;
GLOBAL char *tempfile2;
GLOBAL char *tempfile3;
-GLOBAL char *digit_points; /* digitizer control points */
-GLOBAL char *digit_results; /* digitizer results */
-GLOBAL int use_digitizer INIT(0); /* is there a digitizer out there? */
-/* group file list, target cell,vector files */
-GLOBAL char *group_list INIT(NULL);
-GLOBAL char *cell_list INIT(NULL);
-GLOBAL char *vect_list INIT(NULL);
-
-GLOBAL int from_keyboard INIT(-1); /* input method */
-GLOBAL int from_digitizer INIT(-1);
-GLOBAL int from_screen INIT(-1);
-GLOBAL int from_flag INIT(0);
-
-GLOBAL int dotsize INIT(4);
-
-GLOBAL int THE_COLORS[10];
-#define BLACK THE_COLORS[0]
-#define BLUE THE_COLORS[1]
-#define BROWN THE_COLORS[2]
-#define GREEN THE_COLORS[3]
-#define GREY THE_COLORS[4]
-#define ORANGE THE_COLORS[5]
-#define PURPLE THE_COLORS[6]
-#define RED THE_COLORS[7]
-#define WHITE THE_COLORS[8]
-#define YELLOW THE_COLORS[9]
-
double row_to_northing();
double col_to_easting();
double northing_to_row();
double easting_to_col();
-#undef INIT
-
Deleted: grass-addons/grass7/imagery/i.points.auto/graphics.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/graphics.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/graphics.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,149 +0,0 @@
-#include "globals.h"
-#include "local_proto.h"
-#include <grass/display.h>
-#include <grass/raster.h>
-
-static View *
-makeview (double bottom, double top, double left, double right)
-{
- View *view;
-
- view = (View *) G_malloc (sizeof (View));
-
- top = 100-top;
- bottom = 100-bottom;
-
- view->top = SCREEN_TOP + (SCREEN_BOTTOM - SCREEN_TOP) * top / 100.0 ;
- view->bottom = SCREEN_TOP + (SCREEN_BOTTOM - SCREEN_TOP) * bottom / 100.0 ;
- view->left = SCREEN_LEFT + (SCREEN_RIGHT - SCREEN_LEFT) * left / 100.0 ;
- view->right = SCREEN_LEFT + (SCREEN_RIGHT - SCREEN_LEFT) * right / 100.0 ;
-
- if (view->top < SCREEN_TOP)
- view->top = SCREEN_TOP;
- if (view->bottom > SCREEN_BOTTOM)
- view->bottom = SCREEN_BOTTOM;
- if (view->left < SCREEN_LEFT)
- view->left = SCREEN_LEFT;
- if (view->right > SCREEN_RIGHT)
- view->right = SCREEN_RIGHT;
-
- Outline_box (view->top, view->bottom, view->left, view->right);
-
- view->top++;
- view->bottom--;
- view->left++;
- view->right--;
-
- view->nrows = view->bottom - view->top + 1;
- view->ncols = view->right - view->left + 1;
- view->cell.configured = 0;
-
- return view;
-}
-
-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);
-
- G_init_colors (&VIEW_MAP1->cell.colors);
- G_init_colors (&VIEW_MAP2->cell.colors);
-
- Erase_view (VIEW_MAP1);
- Erase_view (VIEW_MAP1_ZOOM);
- Erase_view (VIEW_MAP2);
- Erase_view (VIEW_MAP2_ZOOM);
-
- return 0;
-}
-
-int
-Outline_box (int top, int bottom, int left, int right)
-{
- R_move_abs (left, top);
- R_cont_abs (left, bottom);
- R_cont_abs (right, bottom);
- R_cont_abs (right, top);
- R_cont_abs (left, top);
-
- return 0;
-}
-
-
-int
-Text_width (char *text)
-{
- int top, bottom, left, right;
-
- R_get_text_box (text, &top, &bottom, &left, &right);
-
- if (right > left)
- return right-left+1;
- else
- return left-right+1;
-}
-
-int
-Text (char *text, int top, int bottom, int left, int right, int edge)
-{
- R_set_window (top, bottom, left, right);
- R_move_abs (left+edge, bottom-edge);
- R_text (text);
- R_set_window (SCREEN_TOP, SCREEN_BOTTOM, SCREEN_LEFT, SCREEN_RIGHT);
-
- return 0;
-}
-
-int
-Uparrow (int top, int bottom, int left, int right)
-{
- R_move_abs ((left+right)/2, bottom);
- R_cont_abs ((left+right)/2, top);
- R_cont_rel ((left-right)/2, (bottom-top)/2);
- R_move_abs ((left+right)/2, top);
- R_cont_rel ((right-left)/2, (bottom-top)/2);
-
- return 0;
-}
-
-int
-Downarrow (int top, int bottom, int left, int right)
-{
- R_move_abs ((left+right)/2, top);
- R_cont_abs ((left+right)/2, bottom);
- R_cont_rel ((left-right)/2, (top-bottom)/2);
- R_move_abs ((left+right)/2, bottom);
- R_cont_rel ((right-left)/2, (top-bottom)/2);
-
- return 0;
-}
Modified: grass-addons/grass7/imagery/i.points.auto/group.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/group.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/group.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,70 +1,58 @@
+#include <unistd.h>
#include <string.h>
-#include <stdlib.h>
-#include <grass/gis.h>
#include "globals.h"
-#include "local_proto.h"
+#include <grass/glocale.h>
-static int cmp(const void *, const void *);
+/* get group */
-int prepare_group_list (void)
+int get_group(void)
{
- FILE *fd;
- int *idx;
- int n;
- int len,len1,len2;
+ int i, check_ok;
+ char xname[GNAME_MAX], xmapset[GMAPSET_MAX];
+ char *sname, *smapset;
-/* open file to store group file names */
- fd = fopen (group_list, "w");
- if (fd == NULL)
- G_fatal_error ("Can't open any tempfiles");
+ G_debug(1, "get_group()");
-/*
- * build sorted index into group files
- * so that all cell files for a mapset to appear together
- */
- idx = (int *) G_calloc (group.ref.nfiles, sizeof (int));
- for (n = 0; n < group.ref.nfiles; n++)
- idx[n] = n;
- qsort (idx, group.ref.nfiles, sizeof(int), cmp);
+ /* check if group exists */
+ if (!I_find_group(group.name))
+ G_fatal_error(_("Imagery group <%s> does not exist"), group.name);
-/* determine length of longest mapset name, and longest cell file name */
- len1 = len2 = 0;
- for (n = 0; n < group.ref.nfiles; n++)
- {
- len = strlen (group.ref.file[n].name);
- if (len > len1)
- len1 = len;
- len = strlen (group.ref.file[n].mapset);
- if (len > len2)
- len2 = len;
- }
+ /* check if any files are in the group */
+ if (!I_get_group_ref(group.name, &group.ref))
+ G_fatal_error(_("No imagery defined for group <%s>"), group.name);
-/* write lengths, names to file */
- fwrite (&len1, sizeof (len1), 1, fd);
- fwrite (&len2, sizeof (len2), 1, fd);
- for (n = 0; n < group.ref.nfiles; n++)
- fprintf (fd, "%s %s\n", group.ref.file[idx[n]].name, group.ref.file[idx[n]].mapset);
- fclose (fd);
+ if (group.ref.nfiles <= 0)
+ G_fatal_error(_("Group <%s> contains no imagery"), group.name);
- G_free (idx);
+ /* check if selected source image exists */
+ if (!G_find_file2("cell", group.img, ""))
+ G_fatal_error(_("Source image <%s> does not exist"), group.img);
- return 0;
-}
+ /* check if selected source image is in group */
+ /* split file in name and mapset */
+ if (G_name_is_fully_qualified(group.img, xname, xmapset)) {
+ sname = xname;
+ smapset = xmapset;
+ }
+ else {
+ sname = group.img;
+ smapset = NULL;
+ }
+ check_ok = 0;
+
+ for (i = 0; i < group.ref.nfiles; i++) {
+ if (!strcmp(sname, group.ref.file[i].name)) {
+ if (!smapset)
+ check_ok = 1;
+ else if (!strcmp(smapset, group.ref.file[i].mapset)) {
+ check_ok = 1;
+ }
+ }
+ if (check_ok)
+ break;
+ }
+ if (!check_ok)
+ G_fatal_error(_("Source map <%s> is not in group <%s>"), group.img, group.name);
-static int cmp (const void *aa, const void *bb)
-{
- const int *a = aa, *b = bb;
- int n;
-
- if(n = strcmp (group.ref.file[*a].mapset, group.ref.file[*b].mapset))
- return n;
- return strcmp (group.ref.file[*a].name, group.ref.file[*b].name);
+ return 1;
}
-
-/* ask the user to pick a file */
-int choose_groupfile (char *name,char *mapset)
-{
- int stat;
- stat = ask_gis_files ("raster", group_list, name, mapset, -1);
- return(stat);
-}
Copied: grass-addons/grass7/imagery/i.points.auto/i.points.auto.html (from rev 47350, grass-addons/grass7/imagery/i.points.auto/description.html)
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/i.points.auto.html (rev 0)
+++ grass-addons/grass7/imagery/i.points.auto/i.points.auto.html 2011-08-02 12:25:32 UTC (rev 47351)
@@ -0,0 +1,40 @@
+<H2>DESCRIPTION</H2>
+
+<em>i.points.auto</em> tries to automatically generate the given number
+of new gound control points. It is recommended to use maps filtered with
+the filters DIVERSITY or STDDEV (of GRASS) with a window of 3x3 or 5x5
+pixels. However, the algorithm sometimes works well also with the
+original maps.
+<p>
+The actual number of newly generated ground control points will likely
+be less than the given maximum number of ground control points because
+each generated point is filtered using its FFT correlation
+coefficient and optionally also by the given RMS threshold.
+<p>
+<em>i.points.auto</em> supports the usual transformation orders 1-3 and
+requires the corresponding number of previously set ground control
+points: 3 for order 1, 6 for order 2, 10 for order 3.
+
+<H2>SEE ALSO</H2>
+
+The GRASS 4 <em>
+<A HREF="http://grass.osgeo.org/gdp/imagery/imagery.ps.gz">Image
+Processing manual</A></EM>
+
+<P>
+<EM>
+<A HREF="g.mapsets.html">g.mapsets</A><br>
+<A HREF="i.group.html">i.group</A><br>
+<A HREF="i.rectify.html">i.rectify</A><br>
+<A HREF="i.target.html">i.target</A><br>
+<A HREF="i.vpoints.html">i.vpoints</A><br>
+<a href="wxGUI.GCP_Manager.html">Ground Control Point Manager</a>
+</em>
+
+
+<H2>AUTHORS</H2>
+Ivan Michelazzi<br>
+Luca Miori<br>
+Markus Metz
+
+<p><i>Last changed: $Date: 2006/06/22 07:46:46 $</i></p>
Deleted: grass-addons/grass7/imagery/i.points.auto/input.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/input.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/input.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,296 +0,0 @@
-#include <string.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int active = 0;
-static int replot;
-static int mouse (Objects *,int,int,int);
-static int use_mouse_msg(void);
-static int draw_objects (Objects *);
-static Objects *find (Objects *,int, int);
-static int select_option (Objects *,Objects *);
-static int draw_option_boxes (Objects *);
-static int visible( Objects *);
-
-#define TEXT_COLOR ORANGE /*WHITE*/
-#define FILL_COLOR BLACK /*BLUE*/
-#define OUTLINE_COLOR RED
-
-/* Input: drive mouse. returns status of handler that returns != 0 */
-int Input_pointer (Objects *objects)
-{
- return mouse (objects,0,0,0);
-}
-
-int Input_box (Objects *objects,int ax,int ay)
-{
- return mouse (objects,ax,ay,1);
-}
-
-int Input_other (int (*function)(), char *type)
-{
- int stat;
- char msg[1024];
-
- sprintf (msg, "%s input required", type);
- Menu_msg(msg);
-
- stat = (*function)();
- if (active)
- {
- use_mouse_msg();
- }
-
- Menu_msg("");
- return stat;
-}
-
-static int mouse (Objects *objects,int ax,int ay,int box)
-{
- int first;
- int stat;
- int x,y,button;
- Objects *obj;
- Objects *find();
-
-
- first = !active;
- active = 1;
- if (first)
- use_mouse_msg();
-
- if (box)
- {
- x = ax + 20;
- y = ay + 20;
- }
- stat = 0;
- replot = 1;
- while (stat == 0)
- {
-
-
- draw_objects (objects);
-
- if (box)
- Mouse_box_anchored (ax, ay, &x, &y, &button) ;
- else
- Mouse_pointer (&x, &y, &button) ;
-
- if (!(obj = find (objects, x, y)))
- continue;
-
-
-
- switch (obj->type)
- {
- case MENU_OBJECT:
- case OTHER_OBJECT:
- stat = (*obj->handler)(x,y,button);
- break;
- case OPTION_OBJECT:
- select_option (objects, obj);
- draw_option_boxes(objects);
- break;
- }
-
-
- /*This expression is necessary for the button "Main-Menu". */
- if(m!=0)
- return -1;
-
-
- }
-
-/* if we are first call, mark not active
- * indicate that objects above use must be replotted.
- */
- if (first)
- active = 0;
- Menu_msg("");
-
-
- return stat;
-}
-
-
-static int
-use_mouse_msg (void)
-{
- Curses_write_window (PROMPT_WINDOW, 1, 1, "Use mouse now ...\n");
-
- return 0;
-}
-
-static int draw_objects (Objects *objects)
-{
- Objects *obj;
- int top, bottom, left, right;
- int size, edge;
-
-
-/* erase the menu window */
- Erase_view (VIEW_MENU);
- R_flush();
-
-/* determine sizes and text indentation */
- size = VIEW_MENU->nrows - 4; /* TEXT-SIZE FOR THE BUTTONS */
- edge = 2;
-
- R_text_size (size, size);
-
- left = VIEW_MENU->left;
- top = VIEW_MENU->top;
- bottom = VIEW_MENU->bottom;
-
-
-/* put the (boxed) text on the menu view */
- for (obj = objects; obj->type; obj++)
- {
- if (!visible(obj))
- continue;
- switch (obj->type)
- {
- case OPTION_OBJECT:
- case MENU_OBJECT:
- right = left + 2*edge + Text_width (obj->label);
- if(!strcmp(obj->label,"LINE")){
- obj->left = left+1;
- obj->right = right+1;
- } else {
- obj->left = left;
- obj->right = right;
-
- }
-
- obj->top = top;
- obj->bottom = bottom;
-
- R_standard_color (FILL_COLOR);
- R_box_abs (left, top, right, bottom);
-
- R_standard_color (TEXT_COLOR);
- Text (obj->label, top, bottom, left, right, edge);
-
- if(!strcmp(obj->label,"LINE"))
- R_standard_color(BLUE);
- else R_standard_color (OUTLINE_COLOR);
- Outline_box (top, bottom, left, right);
-
- left = right;
- break;
-
- case INFO_OBJECT:
- if (*obj->label == 0) break;
- if (*obj->status < 0) break;
- right = left + 2*edge + Text_width (obj->label);
- R_standard_color (WHITE);
- Text (obj->label, top, bottom, left, right, edge);
-
- left = right;
- break;
- }
- }
- draw_option_boxes (objects);
- R_flush();
-
- return 0;
-}
-
-static Objects *find (Objects *objects,int x, int y)
-{
- Objects *other;
- other = NULL;
- for (; objects->type; objects++)
- {
- if (!visible (objects))
- continue;
- switch (objects->type)
- {
- case MENU_OBJECT:
- case OPTION_OBJECT:
- if (x >= objects->left && x <= objects->right
- && y >= objects->top && y <= objects->bottom)
- return objects;
- break;
- case OTHER_OBJECT:
- other = objects;
- break;
- }
- }
- return other;
-}
-
-static int select_option (Objects *objects,Objects *obj)
-{
- while (objects->type)
- {
- if (objects->type == OPTION_OBJECT && *objects->status >= 0 &&
- objects->binding == obj->binding)
- *objects->status = 0;
- objects++;
- }
- *obj->status = 1;
-
- return 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;
-}
-
-static int visible( Objects *object)
-{
- if (object->type == OPTION_OBJECT)
- return (*object->status >= 0);
- return (*object->status > 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 (WHITE);
- Text (msg, VIEW_MENU->top, VIEW_MENU->bottom,
- VIEW_MENU->left, VIEW_MENU->right, edge);
- }
- R_flush();
- replot = 1;
-
- return 0;
-}
-
-int
-Start_mouse_in_menu (void)
-{
- Set_mouse_xy (
- (VIEW_MENU->left+2*VIEW_MENU->right)/3,
- (VIEW_MENU->top+VIEW_MENU->bottom)/2);
-
- return 0;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/line.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/line.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/line.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,226 +0,0 @@
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int cancel();
-static int select(int x1,int y1,int button);
-
-
-double temp_e1,temp_e2,temp_n1,temp_n2;
-static int flag;
-void find_position (int *x1, int *x2,int *y1,int *y2);
-int xtemp[2],ytemp[2], first_linex[2],first_liney[2];
-
-int
-line (void)
-{
- int stat,row,col,i;
- static int use = 1;
- double e1,e2,e3,e4,n1,n2,n3,n4;
- static Objects objects1[]=
- {
- MENU("CANCEL",cancel,&use),
- INFO("select first line (left side) ",&use),
- OTHER(select, &use),
- {0}
- };
-
- static Objects objects2[]=
- {
- MENU("CANCEL",cancel,&use),
- INFO("select second line (right side) ",&use),
- OTHER(select, &use),
- {0}
- };
-
-
- flag =0;
- stat= Input_pointer (objects1);
- if (stat==-1) return 0;
-
- e1=temp_e1;
- e2=temp_e2;
- n1=temp_n1;
- n2=temp_n2;
- flag = 1;
-
- for (i=0;i<2;i++)
- {
- first_linex[i]=xtemp[i];
- first_liney[i]=ytemp[i];
- }
-
- stat=Input_pointer (objects2);
- if (stat==-1)
- {
- R_panel_restore (tempfile2); /* serve al ripristino del quadrato che contiene la linea collogante i 2 punti */
- R_panel_restore (tempfile3); /* serve al ripristino del secondo punto*/
- R_panel_restore (tempfile1); /* serve al ripristino del primo punto*/
- R_panel_delete (tempfile1);
- R_panel_delete (tempfile2);
- R_panel_delete (tempfile3);
-
- return 0;
- }
-
-
- e3=temp_e1;
- e4=temp_e2;
- n3=temp_n1;
- n4=temp_n2;
- I_new_control_point (&group.points, e1, n1, e3, n3, 2);
- I_put_control_points (group.name, &group.points);
- Compute_equation();
- display_points(1) ;
- I_new_control_point (&group.points, e2, n2, e4, n4, 3);
- I_put_control_points (group.name, &group.points);
- Compute_equation();
- display_points(1) ;
- R_standard_color (GREEN);
- R_polyline_abs (first_linex ,first_liney,2);
- R_polyline_abs (xtemp ,ytemp,2);
- R_flush();
-
- return 0; /* return, but don't QUIT */
-}
-
-static int select(int x,int y,int button)
-{
- if (button != 1)
- return where (x,y);
-
- if (flag==0) {
- if (VIEW_MAP1->cell.configured && In_view (VIEW_MAP1, x, y))
- select_line (VIEW_MAP1, x, y);
- else if (VIEW_MAP1_ZOOM->cell.configured && In_view (VIEW_MAP1_ZOOM, x, y))
- select_line (VIEW_MAP1_ZOOM, x, y);
- else return 0;
- }
- if (flag==1) {
- if (VIEW_MAP2->cell.configured && In_view (VIEW_MAP2, x, y))
- select_line (VIEW_MAP2, x, y);
- else if (VIEW_MAP2_ZOOM->cell.configured && In_view (VIEW_MAP2_ZOOM, x, y))
- select_line (VIEW_MAP2_ZOOM, x, y);
- else return 0;
- }
- return 1 ; /* return but don't quit */
-
-};
-
-int select_line (View *view,int x1, int y1)
-{
- int col, row;
- int x2,y2,button=0;
- char buf[50];
-
-
-
- col = view_to_col (view, x1);
- temp_e1 = col_to_easting (&view->cell.head, col, 0.5);
- row = view_to_row (view, y1);
- temp_n1 = row_to_northing (&view->cell.head, row, 0.5);
-
- if (flag== 0)
- {
- Curses_clear_window (INFO_WINDOW);
- Curses_clear_window (MENU_WINDOW);
- sprintf (buf, "Point %d marked on image at", group.points.count+1);
- Curses_write_window (MENU_WINDOW, 1, 1, buf);
- sprintf (buf, "East: %10.2f", temp_e1);
- Curses_write_window (MENU_WINDOW, 3, 3, buf);
- sprintf (buf, "North: %10.2f", temp_n1);
- Curses_write_window (MENU_WINDOW, 4, 3, buf);
- }
- else
- {
-
- sprintf (buf, "Point %d marked on target image at", group.points.count+1);
- Curses_write_window (INFO_WINDOW, 1, 1, buf);
- sprintf (buf, "East: %10.2f",temp_e1);
- Curses_write_window (INFO_WINDOW, 3, 3, buf);
- sprintf (buf, "North: %10.2f", temp_n1);
- Curses_write_window (INFO_WINDOW, 4, 3, buf);
- }
-
- R_standard_color (ORANGE);
- R_panel_save (tempfile1, y1-dotsize, y1+dotsize, x1-dotsize, x1+dotsize);
- dot(x1,y1);
-
- while (button!=1)
- {
- R_get_location_with_line (x1,y1,&x2,&y2,&button);
- if( button!=1)
- where (x2,y2);
- if (!(view->cell.configured && In_view (view, x2, y2)))
- button=0;
- }
-
- col = view_to_col (view, x2);
- temp_e2 = col_to_easting (&view->cell.head, col, 0.5);
- row = view_to_row (view, y2);
- temp_n2 = row_to_northing (&view->cell.head, row, 0.5);
-
- if (flag== 0)
- {
- sprintf (buf, "Point %d marked on image at", group.points.count+2);
- Curses_write_window (MENU_WINDOW, 6, 1, buf);
- sprintf (buf, "East: %10.2f", temp_e2);
- Curses_write_window (MENU_WINDOW, 8, 3, buf);
- sprintf (buf, "North: %10.2f", temp_n2);
- Curses_write_window (MENU_WINDOW, 9, 3, buf);
- }
- else
- {
- sprintf (buf, "Point %d marked on target image at", group.points.count+2);
- Curses_write_window (INFO_WINDOW, 6, 1, buf);
- sprintf (buf, "East: %10.2f",temp_e2);
- Curses_write_window (INFO_WINDOW, 8, 3, buf);
- sprintf (buf, "North: %10.2f", temp_n2);
- Curses_write_window (INFO_WINDOW, 9, 3, buf);
- }
-
- R_standard_color (ORANGE);
- R_panel_save (tempfile3, y2-dotsize, y2+dotsize, x2-dotsize, x2+dotsize);
- dot(x2,y2);
-
- xtemp[0]= x1;
- xtemp[1]= x2;
- ytemp[0]= y1;
- ytemp[1]= y2;
-
- find_position (&x1,&x2,&y1,&y2);
- R_panel_save (tempfile2, y1, y2, x1, x2);
- R_polyline_abs (xtemp ,ytemp,2);
-
- return 1 ;
-
- }
-
- void find_position (int *x1, int *x2,int *y1,int *y2)
- { int temp;
- if (*y2<*y1) {
- temp=*y1;
- *y1=*y2;
- *y2= temp;
- }
- else if (*y2==*y1) { *y2= *y2+dotsize;
- *y1= *y1 - dotsize ;
- }
- if (*x2<*x1) {
- temp=*x1;
- *x1=*x2;
- *x2= temp;
- }
- else if (*x2==*x1) { *x2= *x2+dotsize;
- *x1= *x1 - dotsize ;
- }
- }
-
-
- static int cancel()
- {
- return -1 ;
-}
-
-
Modified: grass-addons/grass7/imagery/i.points.auto/local_proto.h
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/local_proto.h 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/local_proto.h 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,142 +1,36 @@
/* analyze.c */
int analyze(void);
-int points_to_line (double, double, double, double, double *, double *);
-/* ask.c */
-int ask_gis_files(char *, char *, char *, char *, int);
-int ask_original_map(char *, char *, char *, char *, int); /* AGGIUNTA */
-/* ask_mag.c */
-int ask_magnification(int *);
-int draw_mag(void);
-/* call.c */
-int call(int (*)(), char *);
-/* cell.c */
-int plotcell(int, int);
+int points_to_line(double, double, double, double, double *, double *);
+
/* cellhd.c */
-int Outline_cellhd(View *, struct Cell_head *);
-/* colors.c */
-int set_colors(struct Colors *);
+int set_target_window(void);
+
/* 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);
-/* curses.c */
-int Begin_curses(void);
-int End_curses(void);
-int Suspend_curses(void);
-int Resume_curses(void);
-int Curses_allow_interrupts(int);
-int Curses_clear_window(Window *);
-int Curses_outline_window(Window *);
-int Curses_write_window(Window *, int, int, char *);
-int Curses_replot_screen(void);
-int Curses_prompt_gets(char *, char *);
-int Beep(void);
-int Curses_getch(int);
-/* debug.c */
-int debug(char *);
-/* digit.c */
-int setup_digitizer(void);
-int digitizer_point(double *, double *);
-/* dot.c */
-int dot(int, int);
-int save_under_dot(int, int);
-int restore_under_dot(void);
-int release_under_dot(void);
-/* drawcell.c */
-int drawcell(View *);
-/* driver.c */
-int driver(void);
+
+/* creat_rand.c */
+void init_rand(void);
+long make_rand(void);
+
/* equ.c */
int Compute_equation(void);
+
/* find_points.c */
-int automated_search(void);
-void Extract_matrix(void);
-void Search_correlation_points(DCELL**, DCELL**, int, int, int, char *,
- int, int, DCELL **, int, int, int, int, int, int, int, int,int,int, int); /*Aggiunta*/
-void Extract_portion_of_double_matrix(int, int, int, int, DCELL**, DCELL**);
+void Extract_matrix_auto(void);
+void Search_correlation_points_auto(DCELL *, DCELL *,
+ int , int , double);
-
-
-/* find_points_semi */
-extern void Extract_matrix_semi(void);
-extern void Search_correlation_points_semi(DCELL**, DCELL**, int, int, int, char *,
- int, int, DCELL **, int, int, int, int, int, int, int, int,int,int);
-extern void Extract_portion_of_double_matrix_semi(int, int, int, int, DCELL**, DCELL**);
-
-
-/* find.c */
-int find_target_files(void);
-/*georef.c*/
-int compute_georef_equations(struct Control_Points *cp, double E12[3], double N12[3], double E21[3], double N21[3]);
-int compute_georef_equations_lp (Lines *ln);
-int georef (double e1,double n1,double *e2,double *n2,double E[3],double N[3]);
-/* graphics.c */
-int Init_graphics(void);
-int Outline_box(int, int, int, int);
-int Text_width(char *);
-int Text(char *, int, int, int, int, int);
-int Uparrow(int, int, int, int);
-int Downarrow(int, int, int, int);
/* group.c */
-int prepare_group_list(void);
-int choose_groupfile(char *, char *);
-/* input.c */
-int Input_pointer(Objects *);
-int Input_box(Objects *, int, int);
-int Input_other(int (*)(), char *);
-int Menu_msg(char *);
-int Start_mouse_in_menu(void);
-/* line.c */
-int line(void);
-int select_line (View *, int, int);
-/* main.c */
-int quit(int);
-int error(char *, int);
-/* mark.c */
-int mark(int, int, int);
-int mark_point(View *, int, int);
-/* mouse.c */
-int Mouse_pointer(int *, int *, int *);
-int Mouse_box_anchored(int, int, int *, int *, int *);
-int Get_mouse_xy(int *, int *);
-int Set_mouse_xy(int, int);
-/* points.c */
-int display_points(int);
-int display_points_in_view(View *, int, double *, double *, int *, int);
-int display_points_in_view_diff_color(View *, int, double *, double *, int *, int);
-int display_points_in_view_diff_color_if_active(View *, int, double *, double *, int *, int);
-int display_one_point(View *, double, double);
+int get_group(void);
+
/* target.c */
int get_target(void);
+int select_env(int);
int select_current_env(void);
int select_target_env(void);
-/* title.c */
-int display_title(View *);
-/* view.c */
-int Configure_view(View *, char *, char *, double, double);
-int In_view(View *, int, int);
-int Erase_view(View *);
-double magnification(View *);
-/* where.c */
-int where(int, int);
-/*write_line.c*/
-int put_control_points ( char *group, struct Control_Points *cp);
-int read_control_points (FILE *fd, struct Control_Points *cp);
-int new_control_point (struct Control_Points *cp,double e1,double n1,double e2,double n2, int status);
-int write_control_points(FILE *fd, struct Control_Points *cp);
-int get_control_points (char *group, struct Control_Points *cp);
-/* zoom.c */
-int zoom(void);
-static int which_zoom(int x, int y, int button);
-/* overlap_area.c */
-int overlap_area(int,int,int,int,int, int,int);
-/* zoom_box.c */
-int zoom_box(int ,int );
-/* zoom_pnt.c */
-int zoom_point(int , int );
-int zoom_pnt (int ,int );
+
+/* overlap.c */
+int overlap(void);
Modified: grass-addons/grass7/imagery/i.points.auto/main.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/main.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/main.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,3 +1,4 @@
+
/*****************************************************************************
*
* MODULE: i.points.auto
@@ -5,6 +6,7 @@
* Ivan Michelazzi, Luca Miori (MSc theses at ITC-irst)
* http://gisws.media.osaka-cu.ac.jp/grass04/viewpaper.php?id=37
* Supervisors: Markus Neteler, Stefano Merler, ITC-irst 2003, 2004
+* Markus Metz: near complete rewrite for GRASS 7
*
* PURPOSE: semi-automated image registration based in FFT correlation
* COPYRIGHT: GPL >=2
@@ -17,188 +19,217 @@
#include <string.h>
#include <signal.h>
#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/glocale.h>
#include "globals.h"
#include "local_proto.h"
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/raster.h>
-#ifdef __GNUC_MINOR__
-int quit (int) __attribute__ ((__noreturn__));
-#else
-int quit (int);
-#endif
-int error (char *, int);
-
-
-
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
- char name[GNAME_MAX], mapset[GMAPSET_MAX];
- struct Cell_head cellhd;
+ struct Option *grp_opt, *order_opt, *src_img_opt, *tgt_img_opt,
+ *detail_opt, *n_points_opt, *threshold_opt;
+ struct Flag *c_flag;
struct GModule *module;
+ int i, npoints;
+ struct Cell_head curr_window_org, tgt_window_org;
- G_gisinit (argv[0]);
+ G_gisinit(argv[0]);
+
module = G_define_module();
+ G_add_keyword(_("imagery"));
+ G_add_keyword(_("ground control points"));
module->description =
- _("Mark or search ground control points on image to be rectified.");
+ _("Generate ground control points for image group to be rectified.");
- G_suppress_masking(); /* need to do this for target location */
+ grp_opt = G_define_standard_option(G_OPT_I_GROUP);
- interrupt_char = G_intr_char();
- tempfile1 = G_tempfile();
- tempfile2 = G_tempfile();
- tempfile3 = G_tempfile();
- cell_list = G_tempfile();
- vect_list = G_tempfile();
- group_list = G_tempfile();
- digit_points = G_tempfile();
- digit_results = G_tempfile();
+ src_img_opt = G_define_standard_option(G_OPT_R_INPUT);
+ src_img_opt->key = "source_image";
+ src_img_opt->required = YES;
- if (R_open_driver() != 0)
- G_fatal_error(_("No graphics device selected"));
+ tgt_img_opt = G_define_standard_option(G_OPT_R_INPUT);
+ tgt_img_opt->key = "target_image";
+ tgt_img_opt->required = YES;
- /* temporary parser code: */
- if(argc == 2) {
- strncpy(group.name, argv[1], GNAME_MAX);
- if(group.name[0] == '-')
- G_fatal_error(_("The parser doesn't work here."));
- }
- else {
- if (!I_ask_group_old (_("Enter imagery group to be registered"), group.name))
- exit(EXIT_FAILURE);
- }
+ order_opt = G_define_option();
+ order_opt->required = NO;
+ order_opt->key = "order";
+ order_opt->type = TYPE_INTEGER;
+ order_opt->options = ("1,2,3");
+ order_opt->answer = ("1");
+ order_opt->description = _("Transformation polynom order (1-3)");
- if (!I_get_group_ref (group.name, &group.ref))
- G_fatal_error ( _("Group [%s] contains no files"), group.name);
+ n_points_opt = G_define_option();
+ n_points_opt->required = NO;
+ n_points_opt->key = "npoints";
+ n_points_opt->type = TYPE_INTEGER;
+ n_points_opt->description = _("Maximum number of points to generate");
- if (group.ref.nfiles <= 0)
- G_fatal_error ( _( "Group [%s] contains no files"), group.name);
+ detail_opt = G_define_option();
+ detail_opt->required = NO;
+ detail_opt->key = "detail";
+ detail_opt->type = TYPE_STRING;
+ detail_opt->options = ("coarse,medium,fine");
+ detail_opt->answer = "fine";
+ detail_opt->description =
+ _("How detailed should the information be to be used.");
-/* write group files to group list file */
- prepare_group_list();
- G_debug(3,"prepare_group_list done");
+ threshold_opt = G_define_option();
+ threshold_opt->required = NO;
+ threshold_opt->key = "threshold";
+ threshold_opt->type = TYPE_DOUBLE;
+ threshold_opt->answer = "0.0";
+ threshold_opt->description =
+ _("RMS error threshold. Recommended: source image resolution or smaller");
-/* get target info and enviroment */
- get_target();
- find_target_files();
- G_debug(3,"find_target_files done");
+ c_flag = G_define_flag();
+ c_flag->key = 'c';
+ c_flag->description =
+ _("Use current region settings in source location instead of source map extends");
-/* 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);
+ if (G_parser(argc, argv))
+ exit(EXIT_FAILURE);
-/* determine tranformation equation */
- G_debug(3, "starting Compute_equation()");
- Compute_equation();
+ Rast_suppress_masking(); /* need to do this for target location */
- signal (SIGINT, SIG_IGN);
-/* signal (SIGQUIT, SIG_IGN); */
+ group.name = grp_opt->answer;
+ group.img = src_img_opt->answer;
+ group.tgt_img = tgt_img_opt->answer;
+ transform_order = atoi(order_opt->answer);
+ n_new_points = atoi(n_points_opt->answer);
+ rms_threshold = atof(threshold_opt->answer);
- R_standard_color (BLUE);
+ if (!detail_opt->answer)
+ detail = 128;
+ else if (!strcmp(detail_opt->answer, "coarse"))
+ detail = 512;
+ else if (!strcmp(detail_opt->answer, "medium"))
+ detail = 128;
+ else if (!strcmp(detail_opt->answer, "fine"))
+ detail = 32;
- Init_graphics();
- display_title (VIEW_MAP1);
+ if (transform_order < 1 || transform_order > 3)
+ G_fatal_error(_("Transformation order must be 1, 2 or 3"));
- G_debug(3, "select_target_env");
- select_target_env ();
- display_title (VIEW_MAP2);
- select_current_env ();
- G_debug(3, "select_target_env done");
+ if (n_new_points < 1)
+ G_fatal_error(_("Number of new points must be > 0"));
+ if (n_new_points > 100)
+ G_warning(_("Generating %d new points will take some time"), n_new_points);
- Begin_curses();
- G_debug(3, "Begin_curses done");
- G_set_error_routine (error);
+ if (rms_threshold < 0.0)
+ G_fatal_error(_("RMS threshold must be >= 0"));
-/*
-#ifdef SIGTSTP
- signal (SIGTSTP, SIG_IGN);
-#endif
-*/
+ G_get_window(&curr_window_org);
+ G_get_window(&curr_window);
-/* ask user for group file to be displayed */
- G_debug(3, "ask user for group file to be displayed");
- do
- {
- if(!choose_groupfile (name, mapset))
- quit(0);
-
-/* display this file in "map1" */
+ /* get group */
+ get_group();
+
+ /* get target */
+ get_target();
+
+ /* check if selected target image exists */
+ select_env(TGT_ENV);
+ if (!G_find_file2("cell", group.tgt_img, "")) {
+ G_message("Location: %s", G_location());
+ G_message("Mapset: %s", G_mapset());
+ G_fatal_error(_("Target image <%s> does not exist"), group.tgt_img);
}
- 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);
- display_points(1);
- R_flush();
+ G__get_window(&tgt_window_org, "", "WIND", G_mapset());
+ G__get_window(&tgt_window, "", "WIND", G_mapset());
+ G_debug(1, "projection: %s", G__projection_name(G_projection()));
+ G_debug(1, "tgt_window projection: %s", G__projection_name(tgt_window.proj));
+
+ /* read group control points, if any */
+ select_env(SRC_ENV);
+ G_debug(1, "read group control points, if any");
+ if (!I_get_control_points(group.name, &group.points))
+ group.points.count = 0;
- Curses_clear_window (PROMPT_WINDOW);
+ /* check GCP number for given order */
+ npoints = 0;
+ for (i = 0; i < group.points.count; i++) {
+ npoints += group.points.status[i];
+ }
+ if (transform_order == 1 && npoints < 3)
+ G_fatal_error(_("Fully automated search not yet implemented"));
+ if (transform_order == 2 && npoints < 6)
+ G_fatal_error(_("Fully automated search not yet implemented"));
+ if (transform_order == 3 && npoints < 10)
+ G_fatal_error(_("Fully automated search not yet implemented"));
- Erase_view (VIEW_MAP1_ZOOM);
+ Rast_get_cellhd(group.img, "", &cellhd1);
+ if (c_flag->answer) {
+ /* check if source current region is within given source image */
+ if (curr_window.north <= cellhd1.south ||
+ curr_window.south >= cellhd1.north ||
+ curr_window.west >= cellhd1.east ||
+ curr_window.east <= cellhd1.west)
+ G_fatal_error(_("Current region does not overlap with selected image"));
-
-/* determine initial input method. */
- setup_digitizer();
- if (use_digitizer)
- {
- from_digitizer = 1;
- from_keyboard = 0;
- from_flag = 1;
+ /* adjust window borders */
+ if (curr_window.north > cellhd1.north)
+ curr_window.north = cellhd1.north;
+ if (curr_window.south < cellhd1.south)
+ curr_window.south = cellhd1.south;
+ if (curr_window.east > cellhd1.east)
+ curr_window.east = cellhd1.east;
+ if (curr_window.west < cellhd1.west)
+ curr_window.west = cellhd1.west;
}
+ else
+ Rast_get_cellhd(group.img, "", &curr_window);
-/* go do the work */
- driver();
+ /* subpixel accuracy */
+ curr_window.ew_res = cellhd1.ew_res / 3;
+ curr_window.ns_res = cellhd1.ns_res / 3;
+ G_adjust_Cell_head(&curr_window, 0, 0);
- quit(0);
-}
+ /* check if extends are large enough for desired detail */
+ if (curr_window.rows < detail || curr_window.cols < detail)
+ G_fatal_error(_("Current region is too small for desired detail. Decrease detail or increase region."));
-int quit (int n)
-{
- char command[1024];
+ /* compute transformation equation */
+ G_debug(1, "starting Compute_equation()");
+ Compute_equation();
+ if (group.equation_stat < 1) {
+ G_fatal_error(_("Not enough points, %d are required"),
+ (transform_order == 1 ? 3 : (transform_order == 2 ? 6 : 10)));
- End_curses();
- R_close_driver();
- if (use_digitizer)
- {
- sprintf (command, "%s/etc/geo.unlock %s",
- G_gisbase(), digit_points);
- system (command);
}
- unlink (tempfile1);
- unlink (tempfile2);
- unlink (tempfile3);
- unlink (cell_list);
- unlink (group_list);
- unlink (vect_list);
- unlink (digit_points);
- unlink (digit_results);
- exit(n);
-}
-int error (char *msg, int fatal)
-{
- char buf[200];
- int x,y,button;
+ /* calculate target extends according to detail, use source image */
+ select_env(TGT_ENV);
+ set_target_window();
+ Rast_get_cellhd(group.tgt_img, "", &cellhd2);
-Curses_clear_window (PROMPT_WINDOW);
-Curses_write_window (PROMPT_WINDOW,1,1, "LOCATION:\n");
-Curses_write_window (PROMPT_WINDOW,1,12,G_location());
-Curses_write_window (PROMPT_WINDOW,2,1, "MAPSET:\n");
-Curses_write_window (PROMPT_WINDOW,2,12,G_location());
- Beep();
- if (fatal)
- sprintf (buf, "ERROR: %s", msg);
- else
- sprintf (buf, "WARNING: %s (click mouse to continue)", msg);
- Menu_msg (buf);
-
- if (fatal)
- quit(1);
- Mouse_pointer (&x, &y, &button);
- Curses_clear_window (PROMPT_WINDOW);
-
- return 0;
+ /* check if source image and target image overlap at all */
+ /* use source current region for this check */
+ if (tgt_window.north <= cellhd2.south ||
+ tgt_window.south >= cellhd2.north ||
+ tgt_window.west >= cellhd2.east ||
+ tgt_window.east <= cellhd2.west) {
+ G_debug(0, "north: %.4G <= %.4G", tgt_window.north, cellhd2.south);
+ G_debug(0, "south: %.4G >= %.4G", tgt_window.south, cellhd2.north);
+ G_debug(0, "west: %.4G >= %.4G", tgt_window.west, cellhd2.east);
+ G_debug(0, "east: %.4G <= %.4G", tgt_window.east, cellhd2.west);
+ if (c_flag->answer)
+ G_fatal_error(_("Source current region and target image do not overlap"));
+ else
+ G_fatal_error(_("Source image and target image do not overlap"));
+ }
+
+ /* shrink regions to overlap */
+ select_env(SRC_ENV);
+ overlap();
+
+ /* hold thumbs */
+ Extract_matrix_auto();
+
+ select_env(SRC_ENV);
+
+ /* bye */
+ exit(EXIT_SUCCESS);
}
-
Deleted: grass-addons/grass7/imagery/i.points.auto/mark.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/mark.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/mark.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,205 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int get_point2 (double *,double *);
-static int keyboard();
-static int _keyboard();
-static int screen (int,int,int);
-static int digitizer();
-static int cancel();
-
-int mark(int x,int y,int button)
-{
- if (button != 1)
- return where (x,y);
-
- if (VIEW_MAP1->cell.configured && In_view (VIEW_MAP1, x, y))
- mark_point (VIEW_MAP1, x, y);
- else if (VIEW_MAP1_ZOOM->cell.configured && In_view (VIEW_MAP1_ZOOM, x, y))
- mark_point (VIEW_MAP1_ZOOM, x, y);
- return 0 ; /* return but don't quit */
-
-
-}
-
-int mark_point (View *view,int x, int y)
-{
- double e1,n1;
- double e2,n2;
- int row,col;
-
- char buf[100];
-
-/* convert x,y to east,north at center of cell */
- col = view_to_col (view, x);
- e1 = col_to_easting (&view->cell.head, col, 0.5);
- row = view_to_row (view, y);
- n1 = row_to_northing (&view->cell.head, row, 0.5);
-
- Curses_clear_window (MENU_WINDOW);
- sprintf (buf, "Point %d marked on image at", group.points.count+1);
- Curses_write_window (MENU_WINDOW, 1, 1, buf);
- sprintf (buf, "East: %10.2f", e1);
- Curses_write_window (MENU_WINDOW, 3, 3, buf);
- sprintf (buf, "North: %10.2f", n1);
- Curses_write_window (MENU_WINDOW, 4, 3, buf);
- Curses_clear_window (INFO_WINDOW);
-
- R_standard_color (ORANGE);
- save_under_dot (x,y);
- dot(x,y);
-
- if (!get_point2(&e2, &n2))
- {
- Curses_clear_window (MENU_WINDOW);
- restore_under_dot();
- }
- else
- {
- Curses_write_window (MENU_WINDOW, 7, 1, "Point located at");
- sprintf (buf, "East: %10.2f", e2);
- Curses_write_window (MENU_WINDOW, 9, 3, buf);
- sprintf (buf, "North: %10.2f", n2);
- Curses_write_window (MENU_WINDOW,10, 3, buf);
- I_new_control_point (&group.points, e1, n1, e2, n2, 1);
- I_put_control_points (group.name, &group.points);
- Compute_equation();
- display_points(1);
- }
- release_under_dot();
-
- return 0;
-}
-
-static double N,E;
-
-static int get_point2 (double *east,double *north)
-{
- int digitizer();
- int keyboard();
- int stat;
- int screen();
- int cancel();
- static int use = 1;
- static Objects objects[] =
- {
- MENU ("CANCEL", cancel, &use),
- INFO ("Mark point on target image", &use),
- OTHER (screen, &use),
- {0}
- };
-
- if (from_digitizer > 0)
- {
- stat = Input_other (digitizer, "Digitizer");
- }
- else if (from_screen > 0)
- {
- set_colors (&VIEW_MAP2->cell.colors);
- stat = Input_pointer(objects) > 0;
- set_colors (&VIEW_MAP1->cell.colors);
- }
- else
- stat = Input_other (keyboard, "Keyboard");
-
- if(stat)
- {
- *east = E;
- *north = N;
- }
-
- return stat ;
-}
-
-static int
-keyboard (void)
-{
- int ok;
- Curses_clear_window (INFO_WINDOW);
- ok = _keyboard ();
- Curses_clear_window (INFO_WINDOW);
- return ok;
-}
-
-static int
-_keyboard (void)
-{
- char buf[100];
-
- while(1)
- {
- Curses_prompt_gets ("Enter coordinates as east north: ", buf);
- G_strip (buf);
- if (*buf == 0)
- {
- return 0;
- }
- if (sscanf (buf, "%lf %lf", &E, &N) != 2)
- {
- Beep();
- continue;
- }
- Curses_clear_window (INFO_WINDOW);
- sprintf (buf, "East: %f\n", E);
- Curses_write_window (INFO_WINDOW, 2, 2, buf);
- sprintf (buf, "North: %f\n", N);
- Curses_write_window (INFO_WINDOW, 3, 2, buf);
- Curses_write_window (INFO_WINDOW, 5, 1, "Look ok? (y/n) ");
-
- while(1)
- {
- int c;
- c = Curses_getch(0);
- if (c == 'y' || c == 'Y')
- return 1;
- if (c == 'n' || c == 'N')
- break;
- Beep();
- }
- }
-
- return 0;
-}
-
-static int
-digitizer (void)
-{
- return digitizer_point (&E, &N);
-}
-
-
-static int screen (int x,int y,int button)
-{
- int row,col;
- char buf[50];
-
- View *view;
- if (In_view (VIEW_MAP2, x, y) && VIEW_MAP2->cell.configured)
- view = VIEW_MAP2;
- else if (In_view (VIEW_MAP2_ZOOM, x, y) && VIEW_MAP2_ZOOM->cell.configured)
- view = VIEW_MAP2_ZOOM;
- else
- return 0; /* ignore mouse event */
-
- col = view_to_col (view, x);
- E = col_to_easting (&view->cell.head, col, 0.5);
- row = view_to_row (view, y);
- N = row_to_northing (&view->cell.head, row, 0.5);
-
- if (button == 1)
- return 1;
-
- sprintf (buf, "East: %10.2f\n", E);
- Curses_write_window (INFO_WINDOW, 2, 2, buf);
- sprintf (buf, "North: %10.2f\n", N);
- Curses_write_window (INFO_WINDOW, 3, 2, buf);
-
- return 0;
-}
-
-static int
-cancel (void)
-{
- return -1;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/mouse.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/mouse.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/mouse.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,59 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-
-static int first = 1;
-static int curx, cury;
-
-int
-Mouse_pointer (int *x, int *y, int *button)
-{
- if (first)
- {
- curx = (SCREEN_LEFT + SCREEN_RIGHT)/2;
- cury = (SCREEN_TOP + SCREEN_BOTTOM)/2;
- first = 0;
- }
- R_get_location_with_pointer (&curx, &cury, button);
- *x = curx;
- *y = cury;
-
-#ifdef BUTTON3
- if (*button == 3) quit(0);
-#endif
-
- return 0;
-}
-
-int
-Mouse_box_anchored (int x1, int y1, int *x2, int *y2, int *button)
-{
- R_get_location_with_box (x1, y1, x2, y2, button);
- curx = *x2;
- cury = *y2;
- first = 0;
-
-#ifdef BUTTON3
- if (*button == 3) quit(0);
-#endif
-
- return 0;
-}
-
-int
-Get_mouse_xy (int *x, int *y)
-{
- *x = curx;
- *y = cury;
-
- return 0;
-}
-
-int
-Set_mouse_xy (int x, int y)
-{
- first = 0;
- curx = x;
- cury = y;
-
- return 0;
-}
Added: grass-addons/grass7/imagery/i.points.auto/overlap.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/overlap.c (rev 0)
+++ grass-addons/grass7/imagery/i.points.auto/overlap.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -0,0 +1,76 @@
+#include <grass/raster.h>
+#include "globals.h"
+#include "local_proto.h"
+
+int overlap(void)
+{
+ double e, n;
+
+ G_debug(1, "overlap()");
+
+ if (tgt_window.north > cellhd2.north)
+ tgt_window.north = cellhd2.north;
+ if (tgt_window.south < cellhd2.south)
+ tgt_window.south = cellhd2.south;
+ if (tgt_window.east > cellhd2.east)
+ tgt_window.east = cellhd2.east;
+ if (tgt_window.west < cellhd2.west)
+ tgt_window.west = cellhd2.west;
+
+ /* NW corner */
+ CRS_georef(tgt_window.west, tgt_window.north, &e, &n,
+ group.E21, group.N21, transform_order);
+
+ curr_window.north = curr_window.south = n;
+ curr_window.east = curr_window.west = e;
+
+ /* NE corner */
+ CRS_georef(tgt_window.east, tgt_window.north, &e, &n,
+ group.E21, group.N21, transform_order);
+
+ if (curr_window.north < n)
+ curr_window.north = n;
+ if (curr_window.south > n)
+ curr_window.south = n;
+ if (curr_window.east < e)
+ curr_window.east = e;
+ if (curr_window.west > e)
+ curr_window.west = e;
+
+ /* SE corner */
+ CRS_georef(tgt_window.east, tgt_window.south, &e, &n,
+ group.E21, group.N21, transform_order);
+
+ if (curr_window.north < n)
+ curr_window.north = n;
+ if (curr_window.south > n)
+ curr_window.south = n;
+ if (curr_window.east < e)
+ curr_window.east = e;
+ if (curr_window.west > e)
+ curr_window.west = e;
+
+ /* SW corner */
+ CRS_georef(tgt_window.west, tgt_window.south, &e, &n,
+ group.E21, group.N21, transform_order);
+
+ if (curr_window.north < n)
+ curr_window.north = n;
+ if (curr_window.south > n)
+ curr_window.south = n;
+ if (curr_window.east < e)
+ curr_window.east = e;
+ if (curr_window.west > e)
+ curr_window.west = e;
+
+ G_adjust_Cell_head(&curr_window, 1, 1);
+ tgt_window.ew_res = (tgt_window.east - tgt_window.west) / curr_window.cols;
+ tgt_window.ns_res = (tgt_window.north - tgt_window.south) / curr_window.rows;
+ tgt_window.cols = curr_window.cols;
+ tgt_window.rows = curr_window.rows;
+ select_env(TGT_ENV);
+ G_adjust_Cell_head(&tgt_window, 0, 0);
+ select_env(SRC_ENV);
+
+ return 1;
+}
Deleted: grass-addons/grass7/imagery/i.points.auto/overlap_area.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/overlap_area.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/overlap_area.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,141 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static View *pick_view, *zoom_view, *main_view;
-static int target_flag;
-
-
-int overlap_area(int xp, int yp, int xs, int ys, int n_img, int ncols, int nrows)
-{
-
- int x_1, y_1, x_2, y_2;
- int tmp_right, tmp_left;
- int tmp_bottom, tmp_top;
- int tmp_ncols;
- int tmp_nrows;
-
- int top, bottom, left, right;
- int row,col;
- struct Cell_head cellhd;
-
-
-
- if(n_img==1)
- {
- pick_view = VIEW_MAP1;
- main_view = VIEW_MAP1;
- zoom_view = VIEW_MAP1_ZOOM;
- target_flag = 0;
- printf("info VIEW_MAP1_ZOOM: nrows=%d ncols=%d",zoom_view->nrows,zoom_view->ncols);
- }
-
- else if (n_img==2)
- {
- pick_view = VIEW_MAP2;
- main_view = VIEW_MAP2;
- zoom_view = VIEW_MAP2_ZOOM;
- target_flag = 1;
- }
-
- else
- return 0;
- if (!pick_view->cell.configured) return 0; /* just to be sure */
-
-
- tmp_right = pick_view->cell.right;
- tmp_left = pick_view->cell.left;
- tmp_ncols = (tmp_right - tmp_left);
-
- tmp_bottom = pick_view->cell.bottom;
- tmp_top = pick_view->cell.top;
- tmp_nrows = (tmp_bottom - tmp_top);
-
-
- x_1 = ((tmp_ncols*xp)/ncols);
- y_1 = (((pick_view->nrows)*yp)/nrows);
- x_2 = ((tmp_ncols*xs)/ncols);
- y_2 = (((pick_view->nrows)*ys)/nrows);
-
-
-
-
- if (x_1 == x_2 || y_1 == y_2) return 0; /* ignore event */
-
-
-
- top = row_to_view (pick_view, y_1);
- left = col_to_view (pick_view, x_1);
- bottom = row_to_view (pick_view, y_2);
- right = col_to_view (pick_view, x_2);
-
-
- if (!In_view (pick_view,right,bottom)) return 0;
-
-
- Menu_msg("");
-
-
- G_copy (&cellhd, &pick_view->cell.head, sizeof(cellhd));
-
-
- 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);
-
-
- 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;
-
- 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);
-
- 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_points(1);
-
-
- return 0;
-
-}
-
-
-static int
-
-cancel (void)
-{
- return -1;
-}
-
-
-
-
-
-
-
-
-
-
Deleted: grass-addons/grass7/imagery/i.points.auto/points.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/points.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/points.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,184 +0,0 @@
-#include <grass/raster.h>
-#include <grass/display.h>
-#include "globals.h"
-#include "local_proto.h"
-
-int display_line (View *view, double *east, double *north,int *status,int count);
-
-int display_points (int in_color)
-{
- display_points_in_view (VIEW_MAP1, in_color,
- group.points.e1, group.points.n1,
- group.points.status, group.points.count);
-
- display_points_in_view (VIEW_MAP1_ZOOM, in_color,
- group.points.e1, group.points.n1,
- group.points.status, group.points.count);
-
- display_points_in_view (VIEW_MAP2, in_color,
- group.points.e2, group.points.n2,
- group.points.status, group.points.count);
-
- display_points_in_view (VIEW_MAP2_ZOOM, in_color,
- group.points.e2, group.points.n2,
- group.points.status, group.points.count);
-
- return 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;
- D_cell_draw_setup(view->top, view->bottom, view->left, view->right);
- D_set_clip_window(view->top, view->bottom, view->left, view->right);
- while (count-- > 0)
- {
- if (in_color && ((*status ==2)||(*status ==-2)))
- display_line(view,east, north, status,count);
- if (in_color && (*status > 0))
- R_standard_color (GREEN);
- else if (in_color && ((*status == 0)||(*status <= -2)))
- R_standard_color (RED);
- else
- R_standard_color (GREEN);
-
- status++;
- display_one_point (view, *east++, *north++);
- }
-
- return 0;
-}
-
-/*The first point is displayed with BLUE, and the others with GREEN */
-int display_points_in_view_diff_color (View *view, int in_color,
- double *east, double *north, int *status, int count)
-{
- if (!view->cell.configured) return 1;
- D_cell_draw_setup(view->top, view->bottom, view->left, view->right);
- D_set_clip_window(view->top, view->bottom, view->left, view->right);
-
- count--;
- if (in_color && (*status > 0))
- R_standard_color (BLUE);
- status++;
- display_one_point (view, *east++, *north++);
-
-
- while (count-- > 0)
- {
- if (in_color && ((*status ==2)||(*status ==-2)))
- display_line(view,east, north, status,count);
- if (in_color && (*status > 0))
- R_standard_color (GREEN);
-
- else if (in_color && ((*status == 0)||(*status <= -2)))
- R_standard_color (RED);
- else
- R_standard_color (GREEN);
-
- status++;
- display_one_point (view, *east++, *north++);
- }
-
- return 0;
-}
-
-
-
-/*Displays only the active points (with GREEN) */
-int display_points_in_view_diff_color_if_active (View *view, int in_color,
- double *east, double *north, int *status, int count)
-{
- if (!view->cell.configured) return 1;
- D_cell_draw_setup(view->top, view->bottom, view->left, view->right);
- D_set_clip_window(view->top, view->bottom, view->left, view->right);
-
- count--;
- if (in_color && (*status > 0))
- R_standard_color (BLUE);
- status++;
- display_one_point (view, *east++, *north++);
-
-
- while (count-- > 0)
- {
- if (in_color && (*status > 0))
- {
- R_standard_color (GREEN);
- status++;
- display_one_point (view, *east++, *north++);
- }
- else if (in_color && ((*status == 0)||(*status <= -2)))
- {
- R_standard_color (RED);
- status++;
- *east++;
- *north++;
- }
- else
- {
- R_standard_color (GREEN);
-
- status++;
- display_one_point (view, *east++, *north++);
- }
-
- }
-
- return 0;
-}
-
-
-
-
-
-
-
-
-
-
-
-int display_one_point (View *view, double east, double north)
-{
- int row, col, x, y;
-
- row = northing_to_row (&view->cell.head, north) + .5;
- col = easting_to_col (&view->cell.head, east) + .5;
- y = row_to_view (view, row);
- x = col_to_view (view, col);
- if (In_view(view, x, y))
- dot (x,y);
-
- return 0;
-}
-
-
-int display_line (View *view, double *east, double *north,int *status,int count)
- {
- int row, col, x[2], y[2];
-
- if (count==0) return 1;
- if ((*(status +1)!=3) && (*(status+1)!=-3)) return 1;
-
- row = northing_to_row (&view->cell.head, *north) + .5;
- col = easting_to_col (&view->cell.head, *east) + .5;
- y[0] = row_to_view (view, row);
- x[0] = col_to_view (view, col);
-
- row = northing_to_row (&view->cell.head, *(north+1)) + .5;
- col = easting_to_col (&view->cell.head, *(east+1)) + .5;
- y[1] = row_to_view (view, row);
- x[1] = col_to_view (view, col);
- if (*status == 2 )
- R_standard_color (GREEN);
-
- else R_standard_color (RED);
- D_move_abs(x[0],y[0]);
- D_cont_abs(x[1],y[1]);
- /* R_polyline_abs (x,y,2); */
- /*plot_line(*east,*north,*(east+1),*(north+1)); */
- R_flush();
- }
-
-
Modified: grass-addons/grass7/imagery/i.points.auto/target.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/target.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/target.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,71 +1,79 @@
#include <unistd.h>
#include <string.h>
#include "globals.h"
+#include <grass/gis.h>
+#include <grass/glocale.h>
/* read the target for the group and cast it into the alternate GRASS env */
static int which_env;
-int get_target (void)
+int get_target(void)
{
- char location[40];
- char mapset[40];
- char buf[1024];
+ char location[GNAME_MAX];
+ char mapset[GNAME_MAX];
+ char buf[GPATH_MAX];
int stat;
- if (!I_get_target(group.name, location, mapset))
- {
- sprintf(buf, "Target information for group [%s] missing\n", group.name);
- goto error;
+ G_debug(1, "get_target()");
+
+ if (!I_get_target(group.name, location, mapset)) {
+ G_fatal_error(_("No target specified for group <%s>"), group.name);
}
- sprintf (buf, "%s/%s", G_gisdbase(), location);
- if (access(buf,0) != 0)
- {
- sprintf (buf,"Target location [%s] not found\n", location);
- goto error;
+ sprintf(buf, "%s/%s", G_gisdbase(), location);
+ if (access(buf, 0) != 0) {
+ G_warning(_("Target location <%s> not found"), location);
+ G_warning(_("Please run i.target for group <%s>"), group.name);
+ G_fatal_error(_("Can not continue"));
}
+
G__create_alt_env();
- G__setenv ("LOCATION_NAME", location);
+ G__setenv("LOCATION_NAME", location);
stat = G__mapset_permissions(mapset);
- if (stat > 0)
- {
- G__setenv ("MAPSET", mapset);
+ if (stat > 0) {
+ G__setenv("MAPSET", mapset);
G__create_alt_search_path();
G__switch_env();
G__switch_search_path();
- which_env = 0;
+ which_env = SRC_ENV;
return 1;
}
- sprintf (buf, "Mapset [%s] in target location [%s] - ",
- mapset, location);
- strcat (buf, stat == 0 ? "permission denied\n" : "not found\n");
-error:
- strcat (buf, "Please run i.target for group ");
- strcat (buf, group.name);
- G_fatal_error (buf);
+ G_fatal_error(_("Mapset <%s> in target location <%s> - %s"),
+ mapset, location, stat == 0 ? _("permission denied") : _("not found"));
+
+ return 0;
}
-int select_current_env (void)
+int select_env(int env)
{
- if (which_env != 0)
- {
+ if (which_env != env) {
G__switch_env();
G__switch_search_path();
- which_env = 0;
+ which_env = env;
}
return 0;
}
-int select_target_env (void)
+int select_current_env(void)
{
- if (which_env != 1)
- {
+ if (which_env != SRC_ENV) {
G__switch_env();
G__switch_search_path();
- which_env = 1;
+ which_env = SRC_ENV;
}
return 0;
}
+
+int select_target_env(void)
+{
+ if (which_env != TGT_ENV) {
+ G__switch_env();
+ G__switch_search_path();
+ which_env = TGT_ENV;
+ }
+
+ return 0;
+}
Deleted: grass-addons/grass7/imagery/i.points.auto/title.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/title.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/title.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,56 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-int
-display_title (View *view)
-{
- View *title;
- char left[100], center[100];
- int size;
- double magnification();
-
- *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 (ORANGE); /*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;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/view.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/view.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/view.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,57 +0,0 @@
-#include <string.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-int Configure_view (
- View *view,
- char *name,
- char *mapset,
- double ns_res,
- double ew_res /* original map resolution */
-)
-{
- Erase_view(view);
- view->cell.configured = 0;
-
-/* copy the cell name into the view */
- strcpy (view->cell.name, name);
- strcpy (view->cell.mapset, mapset);
-
-/* determine the map edges */
- view->cell.left = view->left + (view->ncols - view->cell.head.cols)/2;
- view->cell.right = view->cell.left + view->cell.head.cols - 1;
- view->cell.top = view->top + (view->nrows - view->cell.head.rows)/2;
- view->cell.bottom = view->cell.top + view->cell.head.rows - 1;
-
-/* remember original resolutions */
- view->cell.ns_res = ns_res;
- view->cell.ew_res = ew_res;
-
- view->cell.configured = 1;
-
- return 0;
-}
-
-int
-In_view (View *view, int x, int y)
-{
- return (x >= view->left && x <= view->right && y >= view->top && y <= view->bottom);
-}
-
-int
-Erase_view (View *view)
-{
- R_standard_color (BLUE);
- R_box_abs (view->left, view->top, view->right, view->bottom);
-
- return 0;
-}
-
-double
-magnification (View *view)
-{
- if (!view->cell.configured)
- return ((double) 0.0);
- return (view->cell.ew_res / view->cell.head.ew_res);
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/where.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/where.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/where.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,66 +0,0 @@
-#include "globals.h"
-#include "local_proto.h"
-
-static int where_12 (View *,int,int);
-static int where_21 (View *,int,int);
-static int where_am_i (View *,int,int,Window *,double *,double *,Window *);
-
-int where (int x, int y)
-{
- if (VIEW_MAP1->cell.configured && In_view (VIEW_MAP1, x, y))
- where_12 (VIEW_MAP1, x, y);
- else if (VIEW_MAP1_ZOOM->cell.configured && In_view (VIEW_MAP1_ZOOM, x, y))
- where_12 (VIEW_MAP1_ZOOM, x, y);
- else if (VIEW_MAP2->cell.configured && In_view (VIEW_MAP2, x, y))
- where_21 (VIEW_MAP2, x, y);
- else if (VIEW_MAP2_ZOOM->cell.configured && In_view (VIEW_MAP2_ZOOM, x, y))
- where_21 (VIEW_MAP2_ZOOM, x, y);
- return 0 ; /* return but don't quit */
-}
-
-static int where_12 (View *view,int x, int y)
-{
- where_am_i (view, x, y, MENU_WINDOW, group.E12, group.N12, INFO_WINDOW);
-
- return 0;
-}
-
-static int where_21 (View *view,int x, int y)
-{
- where_am_i (view, x, y, INFO_WINDOW, group.E21, group.N21, MENU_WINDOW);
-
- return 0;
-}
-
-static int where_am_i (View *view,int x, int y,Window *w1,
- double *E,double *N,Window *w2)
-{
- double e1,n1,e2,n2;
- int row,col;
-
- char buf[100];
-
-/* convert x,y to east,north at center of cell */
- col = view_to_col (view, x);
- e1 = col_to_easting (&view->cell.head, col, 0.5);
- row = view_to_row (view, y);
- n1 = row_to_northing (&view->cell.head, row, 0.5);
-
- Curses_clear_window (w1);
- sprintf (buf, "East: %10.2f", e1);
- Curses_write_window (w1, 3, 3, buf);
- sprintf (buf, "North: %10.2f", n1);
- Curses_write_window (w1, 4, 3, buf);
-
-/* if transformation equation is useable, determine point via equation */
- if (group.equation_stat <= 0) return 1;
-
- I_georef (e1, n1, &e2, &n2, E, N);
- Curses_clear_window (w2);
- sprintf (buf, "East: %10.2f", e2);
- Curses_write_window (w2, 3, 3, buf);
- sprintf (buf, "North: %10.2f", n2);
- Curses_write_window (w2, 4, 3, buf);
-
- return 0;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/zoom.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/zoom.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/zoom.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,53 +0,0 @@
-#include "globals.h"
-#include "local_proto.h"
-
-static int cancel();
-static int use_zoom_box = 1;
-static int use_zoom_pnt = 0;
-
-
-
-int zoom()
-{
- static int use = 1;
- int cancel();
- /*static int which_zoom();*/
-
- static Objects objects[]=
- {
- MENU("CANCEL",cancel,&use),
- INFO("Current ZOOM Type.",&use),
- OPTION("BOX", 2, &use_zoom_box),
- OPTION("POINT", 2, &use_zoom_pnt),
- OTHER(which_zoom, &use),
- {0}
- };
-
- Input_pointer (objects);
- return 0; /* return, but don't QUIT */
-}
-
-static int
-which_zoom(int x,int y,int button)
-{
-
- /* Button one to set point, Button 2 & 3 return location */
- if (button != 1)
- return where (x,y);
-
-
- if (use_zoom_box == 1)
- zoom_box(x,y);
- else zoom_pnt(x,y);
-
- return 0;
-}
-
-
-
-
-static int
-cancel (void)
-{
- return -1;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/zoom_box.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/zoom_box.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/zoom_box.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,193 +0,0 @@
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-
-static int zoom2(int,int);
-static int cancel(void);
-
-static int x1, y1, x2, y2;
-static View *pick_view, *zoom_view, *main_view;
-static int target_flag;
-
-
-
-int zoom_box (int x,int y) /* called by Input_pointer */
-{
- static int use = 1;
- int zoom2();
- int cancel();
-
- static Objects objects[] =
- {
- MENU("CANCEL",cancel,&use),
- INFO(" Define the region ",&use),
- OTHER(zoom2,&use),
- {0}
- };
-
-/*
- * user has marked first corner
- * this determines which view is being zoomed
- */
- x1 = x;
- y1 = y;
-
- if (In_view (pick_view = VIEW_MAP1, x1, y1))
- {
- main_view = VIEW_MAP1;
- zoom_view = VIEW_MAP1_ZOOM;
- target_flag = 0;
- printf("info VIEW_MAP1_ZOOM: nrows=%d ncols=%d",zoom_view->nrows,zoom_view->ncols);
- }
- else if (In_view (pick_view = VIEW_MAP2, x1, y1))
- {
- 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, x1, y1))
- {
- 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, x1, y1))
- {
- 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 */
-
- return Input_box (objects, x, y);
-}
-
-
-
-
-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 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_points(1);
- return 1; /* pop back */
-
-}
-
-static int
-
-cancel (void)
-{
- return -1;
-}
Deleted: grass-addons/grass7/imagery/i.points.auto/zoom_pnt.c
===================================================================
--- grass-addons/grass7/imagery/i.points.auto/zoom_pnt.c 2011-08-02 11:59:36 UTC (rev 47350)
+++ grass-addons/grass7/imagery/i.points.auto/zoom_pnt.c 2011-08-02 12:25:32 UTC (rev 47351)
@@ -1,179 +0,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-#include <math.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "local_proto.h"
-
-static int cancel(void);
-
-static View *pick_view, *zoom_view, *main_view;
-static int target_flag;
-
-int zoom_pnt (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
-cancel (void)
-{
- return -1;
-}
More information about the grass-commit
mailing list