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
44
44
shh = color_ok = 0;
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)");
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");
58
rast_co = G_define_option();
51
_("Exports a raster map to the Virtual Reality Modeling Language (VRML).");
53
rast_el = G_define_standard_option(G_OPT_R_ELEV);
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");
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");
72
out = G_define_option();
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");
79
71
if (G_parser(argc, argv))
80
72
exit(EXIT_FAILURE);
82
74
G_get_set_window(&W);
85
t_mapset = G_find_file2("cell", rast_el->answer, "");
87
sprintf(errbuf, "Couldn't find raster map %s", rast_el->answer);
88
G_fatal_error(errbuf);
90
if ((elevfd = G_open_cell_old(rast_el->answer, t_mapset)) == -1) {
91
sprintf(errbuf, "Not able to open cellfile for [%s]",
93
G_fatal_error(errbuf);
76
elevfd = Rast_open_old(rast_el->answer, "");
101
83
struct FPRange fp_range;
103
is_fp = G_raster_map_is_fp(rast_el->answer, t_mapset);
85
is_fp = Rast_map_is_fp(rast_el->answer, "");
105
if (G_read_fp_range(rast_el->answer, t_mapset, &fp_range) != 1) {
107
"Range info for [%s] not available (run r.support)\n",
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)"),
111
G_get_fp_range_min_max(&fp_range, &dmin, &dmax);
91
Rast_get_fp_range_min_max(&fp_range, &dmin, &dmax);
116
if (G_read_range(rast_el->answer, t_mapset, &range) == -1) {
118
"Range info for [%s] not available (run r.support)\n",
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)"),
122
G_get_range_min_max(&range, &cmin, &cmax);
100
Rast_get_range_min_max(&range, &cmin, &cmax);
128
106
if (rast_co->answer) {
130
t_mapset = G_find_file2("cell", rast_co->answer, "");
132
sprintf(errbuf, "Couldn't find raster map %s", rast_co->answer);
135
else if ((colorfd = G_open_cell_old(rast_co->answer, t_mapset)) == -1) {
136
sprintf(errbuf, "Not able to open cellfile for [%s]",
141
G_read_colors(rast_co->answer, t_mapset, &colr);
107
colorfd = Rast_open_old(rast_co->answer, "");
108
Rast_read_colors(rast_co->answer, "", &colr);
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);
221
186
Zrange = (w->rows - 1) * w->ns_res;
222
187
Xrange = (w->cols - 1) * w->ew_res;
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));
228
193
if (Zrange >= Xrange && Zrange >= Yrange) { /* northing biggest */