~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to raster/r.out.vrml/main.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 *
4
4
 * MODULE:       r.out.vrml
5
5
 * AUTHOR(S):    Bill Brown (CERL/UIUC GMSL Laboratory) (original contributor), 
6
 
 *               Hamish Bowman <hamish_nospam yahoo.com>, 
 
6
 *               Hamish Bowman <hamish_b yahoo.com>, 
7
7
 *               Jachym Cepicky <jachym les-ejk.cz>,
8
8
 *               Markus Neteler <neteler itc.it>
9
9
 * PURPOSE:      This module exports a GRASS raster map to the Virtual Reality
19
19
#include <string.h>
20
20
#include <stdlib.h>
21
21
#include <grass/gis.h>
 
22
#include <grass/raster.h>
22
23
#include <grass/glocale.h>
23
24
#include "pv.h"
24
25
 
30
31
 
31
32
    struct Option *rast_el, *rast_co, *out;
32
33
    struct Option *exag_opt;
33
 
    char *t_mapset;
34
34
    int elevfd = 0, colorfd = 0;
35
35
    FILE *vout = NULL;
36
36
    struct Colors colr;
37
 
    char errbuf[100], outfile[256];
 
37
    char outfile[GPATH_MAX];
38
38
    int shh, color_ok;
39
39
    double exag, min, max;
40
40
    struct GModule *module;
44
44
    shh = color_ok = 0;
45
45
 
46
46
    module = G_define_module();
47
 
    module->keywords = _("raster, export, VRML");
 
47
    G_add_keyword(_("raster"));
 
48
    G_add_keyword(_("export"));
 
49
    G_add_keyword(_("VRML"));
48
50
    module->description =
49
 
        _("Export a raster map to the Virtual Reality Modeling Language (VRML)");
50
 
 
51
 
    rast_el = G_define_option();
52
 
    rast_el->key = "elev";
53
 
    rast_el->type = TYPE_STRING;
54
 
    rast_el->required = YES;
55
 
    rast_el->gisprompt = "old,cell,raster";
56
 
    rast_el->description = _("Name of elevation map");
57
 
 
58
 
    rast_co = G_define_option();
 
51
        _("Exports a raster map to the Virtual Reality Modeling Language (VRML).");
 
52
 
 
53
    rast_el = G_define_standard_option(G_OPT_R_ELEV);
 
54
 
 
55
    rast_co = G_define_standard_option(G_OPT_R_INPUT);
59
56
    rast_co->key = "color";
60
 
    rast_co->type = TYPE_STRING;
61
57
    rast_co->required = NO;
62
 
    rast_co->gisprompt = "old,cell,raster";
63
 
    rast_co->description = _("Name of color file");
 
58
    rast_co->description = _("Name of input color map");
64
59
 
65
60
    exag_opt = G_define_option();
66
 
    exag_opt->key = "exag";
 
61
    exag_opt->key = "exaggeration";
67
62
    exag_opt->type = TYPE_DOUBLE;
68
63
    exag_opt->required = NO;
69
64
    exag_opt->answer = "1.0";
70
65
    exag_opt->description = _("Vertical exaggeration");
71
66
 
72
 
    out = G_define_option();
73
 
    out->key = "output";
74
 
    out->type = TYPE_STRING;
 
67
    out = G_define_standard_option(G_OPT_F_OUTPUT);
75
68
    out->required = YES;
76
 
    out->gisprompt = "new_file,file,output";
77
 
    out->description = _("Name for new VRML file");
 
69
    out->description = _("Name for output VRML file");
78
70
 
79
71
    if (G_parser(argc, argv))
80
72
        exit(EXIT_FAILURE);
81
73
 
82
74
    G_get_set_window(&W);
83
75
 
84
 
    t_mapset = NULL;
85
 
    t_mapset = G_find_file2("cell", rast_el->answer, "");
86
 
    if (!t_mapset) {
87
 
        sprintf(errbuf, "Couldn't find raster map %s", rast_el->answer);
88
 
        G_fatal_error(errbuf);
89
 
    }
90
 
    if ((elevfd = G_open_cell_old(rast_el->answer, t_mapset)) == -1) {
91
 
        sprintf(errbuf, "Not able to open cellfile for [%s]",
92
 
                rast_el->answer);
93
 
        G_fatal_error(errbuf);
94
 
    }
 
76
    elevfd = Rast_open_old(rast_el->answer, "");
95
77
 
96
78
    {
97
79
        CELL cmin, cmax;
100
82
        DCELL dmin, dmax;
101
83
        struct FPRange fp_range;
102
84
 
103
 
        is_fp = G_raster_map_is_fp(rast_el->answer, t_mapset);
 
85
        is_fp = Rast_map_is_fp(rast_el->answer, "");
104
86
        if (is_fp) {
105
 
            if (G_read_fp_range(rast_el->answer, t_mapset, &fp_range) != 1) {
106
 
                sprintf(errbuf,
107
 
                        "Range info for [%s] not available (run r.support)\n",
108
 
                        rast_el->answer);
109
 
                G_fatal_error(errbuf);
 
87
            if (Rast_read_fp_range(rast_el->answer, "", &fp_range) != 1) {
 
88
                G_fatal_error(_("Range info for [%s] not available (run r.support)"),
 
89
                              rast_el->answer);
110
90
            }
111
 
            G_get_fp_range_min_max(&fp_range, &dmin, &dmax);
 
91
            Rast_get_fp_range_min_max(&fp_range, &dmin, &dmax);
112
92
            min = dmin;
113
93
            max = dmax;
114
94
        }
115
95
        else {
116
 
            if (G_read_range(rast_el->answer, t_mapset, &range) == -1) {
117
 
                sprintf(errbuf,
118
 
                        "Range info for [%s] not available (run r.support)\n",
119
 
                        rast_el->answer);
120
 
                G_fatal_error(errbuf);
 
96
            if (Rast_read_range(rast_el->answer, "", &range) == -1) {
 
97
                G_fatal_error(_("Range info for <%s> not available (run r.support)"),
 
98
                              rast_el->answer);
121
99
            }
122
 
            G_get_range_min_max(&range, &cmin, &cmax);
 
100
            Rast_get_range_min_max(&range, &cmin, &cmax);
123
101
            min = cmin;
124
102
            max = cmax;
125
103
        }
126
104
    }
127
105
 
128
106
    if (rast_co->answer) {
129
 
        t_mapset = NULL;
130
 
        t_mapset = G_find_file2("cell", rast_co->answer, "");
131
 
        if (!t_mapset) {
132
 
            sprintf(errbuf, "Couldn't find raster map %s", rast_co->answer);
133
 
            G_warning(errbuf);
134
 
        }
135
 
        else if ((colorfd = G_open_cell_old(rast_co->answer, t_mapset)) == -1) {
136
 
            sprintf(errbuf, "Not able to open cellfile for [%s]",
137
 
                    rast_co->answer);
138
 
            G_warning(errbuf);
139
 
        }
140
 
        else {
141
 
            G_read_colors(rast_co->answer, t_mapset, &colr);
142
 
            color_ok = 1;
143
 
        }
 
107
        colorfd = Rast_open_old(rast_co->answer, "");
 
108
        Rast_read_colors(rast_co->answer, "", &colr);
 
109
        color_ok = 1;
144
110
    }
145
111
 
146
112
    /* TODO: if file exists, just append new objects */
162
128
        /* open file for writing VRML */
163
129
        G_message(_("Opening %s for writing... "), outfile);
164
130
        if (NULL == (vout = fopen(outfile, "w"))) {
165
 
            sprintf(errbuf, "Couldn't open output file %s", outfile);
166
 
            G_fatal_error(errbuf);
 
131
            G_fatal_error(_("Unable to open output file <%s>"), outfile);
167
132
        }
168
133
    }
169
134
 
183
148
    vrml_end(vout);
184
149
 
185
150
 
186
 
    G_close_cell(elevfd);
 
151
    Rast_close(elevfd);
187
152
    if (color_ok)
188
 
        G_close_cell(colorfd);
 
153
        Rast_close(colorfd);
189
154
 
190
155
    return (EXIT_SUCCESS);
191
156
 
221
186
    Zrange = (w->rows - 1) * w->ns_res;
222
187
    Xrange = (w->cols - 1) * w->ew_res;
223
188
 
224
 
    transX = -(G_col_to_easting(0.5, w));
225
 
    transZ = -(G_row_to_northing(0.5, w));
 
189
    transX = -(Rast_col_to_easting(0.5, w));
 
190
    transZ = -(Rast_row_to_northing(0.5, w));
226
191
    transY = -min;
227
192
 
228
193
    if (Zrange >= Xrange && Zrange >= Yrange) { /* northing biggest */