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

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/i.photo.2target/zoom.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 "globals.h"
 
2
#include "local_proto.h"
 
3
 
 
4
static int cancel(void);
 
5
 
 
6
int zoom(void)
 
7
{
 
8
    static int use = 1;
 
9
    static Objects objects[] = {
 
10
        MENU("CANCEL", cancel, &use),
 
11
        MENU("BOX", zoom_box, &use),
 
12
        MENU("POINT", zoom_point, &use),
 
13
        INFO("Select type of zoom", &use),
 
14
        {0}
 
15
    };
 
16
 
 
17
    Input_pointer(objects);
 
18
    return 0;                   /* return, but don't QUIT */
 
19
}
 
20
 
 
21
static int cancel(void)
 
22
{
 
23
    return -1;
 
24
}
 
25
 
 
26
/* get target point for source point */
 
27
void source_to_target(double srx, double sry, double *trx, double *try)
 
28
{
 
29
    int i;
 
30
    double spx, spy, spz;       /* source photo */
 
31
    double trz;                 /* target raster */
 
32
 
 
33
    G_debug(2, "source raster: %.0f %.0f", srx, sry);
 
34
 
 
35
    /* Photo coordinates of center on ZOOM1 */
 
36
    I_georef(srx, sry, &spx, &spy, group.E12, group.N12);
 
37
    G_debug(2, "source photo: %.3f %.3f", spx, spy);
 
38
 
 
39
    /* We need height but we don't know point on target ->
 
40
     * get aproximately the point on target and use that 
 
41
     * height for more precise position */
 
42
    spz = 0;
 
43
    for (i = 0; i < 3; i++) {
 
44
        I_inverse_ortho_ref(spx, spy, spz, trx, try, &trz,
 
45
                            &group.camera_ref,
 
46
                            group.XC, group.YC, group.ZC, group.MI);
 
47
 
 
48
        G_debug(2, "target raster: %.0f %.0f", *trx, *try);
 
49
        get_z_from_cell2(*try, *trx, &spz);
 
50
        G_debug(2, "target raster height: %.0f", spz);
 
51
    }
 
52
 
 
53
    G_debug(2, "target rast center: %.0f %.0f", *trx, *try);
 
54
}
 
55
 
 
56
void auto_zoom(void)
 
57
{
 
58
    double srx, sry;            /* source raster */
 
59
    double trx, try;            /* target raster */
 
60
    int vx, vy;
 
61
    double trl, trr;
 
62
    double width, magnific;
 
63
 
 
64
    if (autozoom_off)
 
65
        return;
 
66
 
 
67
    Compute_ortho_equation();
 
68
    if (group.con_equation_stat <= 0)
 
69
        return;
 
70
 
 
71
    /* Calc scale for target */
 
72
    sry = VIEW_MAP1_ZOOM->cell.head.north;
 
73
    srx = VIEW_MAP1_ZOOM->cell.head.west;
 
74
    source_to_target(srx, sry, &trl, &try);
 
75
    srx = VIEW_MAP1_ZOOM->cell.head.east;
 
76
    source_to_target(srx, sry, &trr, &try);
 
77
    width = trr - trl;          /* ZOOM1 width in target units */
 
78
 
 
79
    /* Calc magnification - relation between resolution
 
80
     * in zoom window and cell head */
 
81
    magnific = (VIEW_MAP1_ZOOM->right - VIEW_MAP1_ZOOM->left) / width;
 
82
    G_debug(3, "width = %.0f magnific = %f", width, magnific);
 
83
 
 
84
    /* Raster coordinates of center on ZOOM1 */
 
85
    srx = (VIEW_MAP1_ZOOM->cell.head.east +
 
86
           VIEW_MAP1_ZOOM->cell.head.west) / 2;
 
87
    sry = (VIEW_MAP1_ZOOM->cell.head.north +
 
88
           VIEW_MAP1_ZOOM->cell.head.south) / 2;
 
89
 
 
90
    source_to_target(srx, sry, &trx, &try);
 
91
 
 
92
    vx = easting_to_col(&VIEW_MAP2->cell.head, trx);
 
93
    vy = northing_to_row(&VIEW_MAP2->cell.head, try);
 
94
    G_debug(2, "target rast col, row: %d %d", vx, vy);
 
95
 
 
96
    vx = col_to_view(VIEW_MAP2, vx);
 
97
    vy = row_to_view(VIEW_MAP2, vy);
 
98
 
 
99
    G_debug(2, "target view col, row: %d %d", vx, vy);
 
100
 
 
101
    zoom_point2(vx, vy, 0, magnific);
 
102
}