~ubuntu-branches/ubuntu/precise/grass/precise

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/i.photo.2image/zoom_pnt.c

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Paolo Lovergine
  • Date: 2011-04-13 17:08:41 UTC
  • mfrom: (8.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20110413170841-ss1t9bic0d0uq0gz
Tags: 6.4.1-1
* New upstream version.
* Now build-dep on libjpeg-dev and current libreadline6-dev.
* Removed patch swig: obsolete.
* Policy bumped to 3.9.2, without changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <math.h>
 
2
#include <grass/gis.h>
 
3
#include <grass/raster.h>
 
4
#include "globals.h"
 
5
 
 
6
 
 
7
static View *pick_view, *zoom_view, *main_view;
 
8
static int target_flag;
 
9
static int zoom1(int, int);
 
10
static int cancel(void);
 
11
 
 
12
 
 
13
int zoom_point(void)
 
14
{
 
15
    static int use = 1;
 
16
 
 
17
    static Objects objects[] = {
 
18
        MENU("CANCEL", cancel, &use),
 
19
        INFO(" Mark center of area to be zoomed ", &use),
 
20
        OTHER(zoom1, &use),
 
21
        {0}
 
22
    };
 
23
 
 
24
    Input_pointer(objects);
 
25
    return 1;
 
26
}
 
27
 
 
28
static int zoom1(int x, int y)
 
29
{                               /* called by Input_pointer */
 
30
    int top, bottom, left, right;
 
31
    int n, row, col;
 
32
    int nrows, ncols;
 
33
    struct Cell_head cellhd;
 
34
    int mag;
 
35
    double north, south, east, west;
 
36
 
 
37
    if (In_view(pick_view = VIEW_MAP1, x, y)) {
 
38
        main_view = VIEW_MAP1;
 
39
        zoom_view = VIEW_MAP1_ZOOM;
 
40
        target_flag = 0;
 
41
    }
 
42
    /*
 
43
       else if (In_view (pick_view = VIEW_MAP2, x, y))
 
44
       {
 
45
       if (!pick_view->cell.configured)
 
46
       return 0;    *//* ignore the mouse event *//*
 
47
       main_view = VIEW_MAP2;
 
48
       zoom_view = VIEW_MAP2_ZOOM;
 
49
       target_flag = 1;
 
50
       }
 
51
     */
 
52
    else if (In_view(pick_view = VIEW_MAP1_ZOOM, x, y)) {
 
53
        if (!pick_view->cell.configured)
 
54
            return 0;           /* ignore the mouse event */
 
55
        main_view = VIEW_MAP1;
 
56
        zoom_view = VIEW_MAP1_ZOOM;
 
57
        target_flag = 0;
 
58
    }
 
59
    /*
 
60
       else if (In_view (pick_view = VIEW_MAP2_ZOOM, x, y))
 
61
       {
 
62
       if (!pick_view->cell.configured)
 
63
       return 0;   *//* ignore the mouse event *//*
 
64
       main_view = VIEW_MAP2;
 
65
       zoom_view = VIEW_MAP2_ZOOM;
 
66
       target_flag = 1;
 
67
       }
 
68
     */
 
69
    else
 
70
        return 0;               /* ignore the mouse event */
 
71
    if (!pick_view->cell.configured)
 
72
        return 0;               /* just to be sure */
 
73
    /*
 
74
     * make sure point is within edges of image as well
 
75
     */
 
76
    if (x <= pick_view->cell.left)
 
77
        return 0;
 
78
    if (x >= pick_view->cell.right)
 
79
        return 0;
 
80
    if (y <= pick_view->cell.top)
 
81
        return 0;
 
82
    if (y >= pick_view->cell.bottom)
 
83
        return 0;
 
84
 
 
85
 
 
86
    /*
 
87
     * ok, erase menu messages
 
88
     */
 
89
    Menu_msg("");
 
90
 
 
91
    /* determine magnification of zoom */
 
92
    if (zoom_view->cell.configured) {
 
93
        if (zoom_view == pick_view)
 
94
            mag = floor(magnification(zoom_view) + 1.0) + .1;
 
95
        else
 
96
            mag = ceil(magnification(zoom_view)) + .1;
 
97
    }
 
98
    else {
 
99
        mag = floor(magnification(main_view) + 1.0) + .1;
 
100
    }
 
101
    if (!ask_magnification(&mag))
 
102
        return 1;
 
103
    /* 
 
104
     * Determine the the zoom window (ie, cellhd)
 
105
     */
 
106
 
 
107
    G_copy(&cellhd, &main_view->cell.head, sizeof(cellhd));
 
108
    cellhd.ns_res = main_view->cell.ns_res / mag;
 
109
    cellhd.ew_res = main_view->cell.ew_res / mag;
 
110
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;
 
111
    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;
 
112
 
 
113
 
 
114
    /* convert x,y to col,row */
 
115
 
 
116
    col = view_to_col(pick_view, x);
 
117
    east = col_to_easting(&pick_view->cell.head, col, 0.5);
 
118
    col = easting_to_col(&cellhd, east);
 
119
 
 
120
    row = view_to_row(pick_view, y);
 
121
    north = row_to_northing(&pick_view->cell.head, row, 0.5);
 
122
    row = northing_to_row(&cellhd, north);
 
123
 
 
124
    ncols = zoom_view->ncols;
 
125
    nrows = zoom_view->nrows;
 
126
 
 
127
 
 
128
    n = cellhd.cols - col;
 
129
    if (n > col)
 
130
        n = col;
 
131
    if (n + n + 1 >= ncols) {
 
132
        n = ncols / 2;
 
133
        if (n + n + 1 >= ncols)
 
134
            n--;
 
135
    }
 
136
    left = col - n;
 
137
    right = col + n;
 
138
 
 
139
    n = cellhd.rows - row;
 
140
    if (n > row)
 
141
        n = row;
 
142
    if (n + n + 1 >= nrows) {
 
143
        n = nrows / 2;
 
144
        if (n + n + 1 >= nrows)
 
145
            n--;
 
146
    }
 
147
    top = row - n;
 
148
    bottom = row + n;
 
149
 
 
150
 
 
151
    north = row_to_northing(&cellhd, top, 0.0);
 
152
    west = col_to_easting(&cellhd, left, 0.0);
 
153
    south = row_to_northing(&cellhd, bottom, 1.0);
 
154
    east = col_to_easting(&cellhd, right, 1.0);
 
155
 
 
156
 
 
157
    cellhd.north = north;
 
158
    cellhd.south = south;
 
159
    cellhd.east = east;
 
160
    cellhd.west = west;
 
161
 
 
162
    cellhd.rows = (cellhd.north - cellhd.south) / cellhd.ns_res;
 
163
    cellhd.cols = (cellhd.east - cellhd.west) / cellhd.ew_res;
 
164
 
 
165
    /*
 
166
     * Outline the zoom window on the main map
 
167
     * Turn previous one to grey.
 
168
     */
 
169
    if (zoom_view->cell.configured) {
 
170
        R_standard_color(GREY);
 
171
        Outline_cellhd(main_view, &zoom_view->cell.head);
 
172
    }
 
173
    R_standard_color(RED);
 
174
    Outline_cellhd(main_view, &cellhd);
 
175
 
 
176
 
 
177
    /*
 
178
     * zoom
 
179
     */
 
180
    if (target_flag)
 
181
        select_target_env();
 
182
    G_copy(&zoom_view->cell.head, &cellhd, sizeof(cellhd));
 
183
    Configure_view(zoom_view, pick_view->cell.name, pick_view->cell.mapset,
 
184
                   pick_view->cell.ns_res, pick_view->cell.ew_res);
 
185
    drawcell(zoom_view);
 
186
    select_current_env();
 
187
    display_ref_points(1);
 
188
 
 
189
    return 1;                   /* pop back */
 
190
}
 
191
 
 
192
static int cancel(void)
 
193
{
 
194
    return -1;
 
195
}