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

« back to all changes in this revision

Viewing changes to imagery/i.ortho.photo/i.photo.rectify/exec.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
/*
 
2
   exec.c --
 
3
 
 
4
   Loop through all files to be rectified and do the retification.
 
5
   Handles things like support files.
 
6
 */
 
7
 
 
8
#include <string.h>
 
9
#include <unistd.h>
 
10
#include <time.h>
 
11
#include <sys/types.h>
 
12
#include <sys/stat.h>
 
13
#include <fcntl.h>
 
14
#include "global.h"
 
15
 
 
16
int exec_rectify(char *extension, char *interp_method, char *angle_map)
 
17
{
 
18
    char *name;
 
19
    char *mapset;
 
20
    char *result;
 
21
    char *type;
 
22
    int n;
 
23
    struct Colors colr;
 
24
    struct Categories cats;
 
25
    struct History hist;
 
26
    int colr_ok, hist_ok, cats_ok;
 
27
    long start_time, rectify_time;
 
28
    double aver_z;
 
29
    int elevfd;
 
30
    struct cache *ebuffer;
 
31
 
 
32
    G_debug(1, "Open elevation raster: ");
 
33
 
 
34
    /* open elevation raster */
 
35
    select_target_env();
 
36
    G_set_window(&target_window);
 
37
    G_debug(1, "target window: rs=%d cs=%d n=%f s=%f w=%f e=%f\n",
 
38
            target_window.rows, target_window.cols, target_window.north,
 
39
            target_window.south, target_window.west, target_window.east);
 
40
 
 
41
    elevfd = G_open_cell_old(elev_name, elev_mapset);
 
42
    if (elevfd < 0) {
 
43
        G_fatal_error(_("Could not open elevation raster"));
 
44
        return 1;
 
45
    }
 
46
    ebuffer = readcell(elevfd, seg_mb_elev, 1);
 
47
    select_target_env();
 
48
    G_close_cell(elevfd);
 
49
 
 
50
    /* get an average elevation of the control points */
 
51
    /* this is used only if target cells have no elevation */
 
52
    get_aver_elev(&group.control_points, &aver_z);
 
53
 
 
54
    /* rectify each file */
 
55
    for (n = 0; n < group.group_ref.nfiles; n++) {
 
56
        if (!ref_list[n])
 
57
            continue;
 
58
 
 
59
        name = group.group_ref.file[n].name;
 
60
        mapset = group.group_ref.file[n].mapset;
 
61
        result =
 
62
            G_malloc(strlen(group.group_ref.file[n].name) + strlen(extension) + 1);
 
63
        strcpy(result, group.group_ref.file[n].name);
 
64
        strcat(result, extension);
 
65
 
 
66
        G_debug(2, "ORTHO RECTIFYING:");
 
67
        G_debug(2, "NAME %s", name);
 
68
        G_debug(2, "MAPSET %s", mapset);
 
69
        G_debug(2, "RESULT %s", result);
 
70
        G_debug(2, "select_current_env...");
 
71
 
 
72
        G_message(_("Rectified input raster map <%s> will be saved as <%s>"),
 
73
                  name, result);
 
74
 
 
75
        select_current_env();
 
76
 
 
77
        cats_ok = G_read_cats(name, mapset, &cats) >= 0;
 
78
        colr_ok = G_read_colors(name, mapset, &colr) > 0;
 
79
        hist_ok = G_read_history(name, mapset, &hist) >= 0;
 
80
        G_debug(2, "reading was fine...");
 
81
 
 
82
        time(&start_time);
 
83
 
 
84
        G_debug(2, "Starting the rectification...");
 
85
 
 
86
        if (rectify(name, mapset, ebuffer, aver_z, result, interp_method)) {
 
87
            G_debug(2, "Done. Writing results...");
 
88
            select_target_env();
 
89
            if (cats_ok) {
 
90
                G_write_cats(result, &cats);
 
91
                G_free_cats(&cats);
 
92
            }
 
93
            if (colr_ok) {
 
94
                G_write_colors(result, G_mapset(), &colr);
 
95
                G_free_colors(&colr);
 
96
            }
 
97
            if (hist_ok)
 
98
                G_write_history(result, &hist);
 
99
 
 
100
            /* Initialze History */
 
101
            type = "raster";
 
102
            G_short_history(name, type, &hist);
 
103
            G_command_history(&hist);
 
104
            G_write_history(result, &hist);
 
105
 
 
106
            select_current_env();
 
107
            time(&rectify_time);
 
108
            report(rectify_time - start_time, 1);
 
109
        }
 
110
        else
 
111
            report((long)0, 0);
 
112
 
 
113
        G_free(result);
 
114
    }
 
115
    
 
116
    close(ebuffer->fd);
 
117
    release_cache(ebuffer);
 
118
 
 
119
    if (angle_map) {
 
120
        camera_angle(angle_map);
 
121
    }
 
122
    
 
123
    G_done_msg(" ");
 
124
 
 
125
    return 0;
 
126
}