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

« back to all changes in this revision

Viewing changes to gui/wxpython/nviz/load.cpp

  • 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
 
   \file nviz/load.cpp
3
 
 
4
 
   \brief wxNviz extension (3D view mode) - load data layers
5
 
   
6
 
   This program is free software under the GNU General Public
7
 
   License (>=v2). Read the file COPYING that comes with GRASS
8
 
   for details.
9
 
   
10
 
   (C) 2008-2009 by Martin Landa, and the GRASS development team
11
 
   
12
 
   \author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
13
 
*/
14
 
 
15
 
#include "nviz.h"
16
 
 
17
 
extern "C" {
18
 
#include <grass/G3d.h>
19
 
#include <grass/glocale.h>
20
 
}
21
 
 
22
 
/*!
23
 
  \brief Load raster map (surface)
24
 
 
25
 
  \param name raster map name
26
 
  \param color_name raster map for color (NULL for color_value)
27
 
  \param color_value color string (named color or RGB triptet)
28
 
 
29
 
  \return object id
30
 
  \return -1 on failure
31
 
*/
32
 
int Nviz::LoadSurface(const char* name, const char *color_name, const char *color_value)
33
 
{
34
 
    char *mapset;
35
 
    int id;
36
 
 
37
 
    mapset = G_find_cell2 (name, "");
38
 
    if (mapset == NULL) {
39
 
        G_warning(_("Raster map <%s> not found"),
40
 
                  name);
41
 
        return -1;
42
 
    }
43
 
            
44
 
    /* topography */
45
 
    id = Nviz_new_map_obj(MAP_OBJ_SURF,
46
 
                          G_fully_qualified_name(name, mapset), 0.0,
47
 
                          data);
48
 
 
49
 
    if (color_name) { /* check for color map */
50
 
        mapset = G_find_cell2 (color_name, "");
51
 
        if (mapset == NULL) {
52
 
            G_warning(_("Raster map <%s> not found"),
53
 
                      color_name);
54
 
            GS_delete_surface(id);
55
 
            return -1;
56
 
        }
57
 
 
58
 
        Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
59
 
                      G_fully_qualified_name(color_name, mapset), -1.0,
60
 
                      data);
61
 
    }
62
 
    else if (color_value) { /* check for color value */
63
 
        Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
64
 
                      NULL, Nviz_color_from_str(color_value),
65
 
                      data);
66
 
    }
67
 
    else { /* use by default elevation map for coloring */
68
 
        Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
69
 
                      G_fully_qualified_name(name, mapset), -1.0,
70
 
                      data);
71
 
    }
72
 
            
73
 
    /*
74
 
      if (i > 1)
75
 
      set_default_wirecolors(data, i);
76
 
    */
77
 
 
78
 
    /* focus on loaded data */
79
 
    Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
80
 
 
81
 
    G_debug(1, "Nviz::LoadRaster(): name=%s -> id=%d", name, id);
82
 
 
83
 
    return id;
84
 
}
85
 
 
86
 
/*!
87
 
  \brief Unload surface
88
 
 
89
 
  \param id surface id
90
 
 
91
 
  \return 1 on success
92
 
  \return 0 on failure
93
 
*/
94
 
int Nviz::UnloadSurface(int id)
95
 
{
96
 
    if (!GS_surf_exists(id)) {
97
 
        return 0;
98
 
    }
99
 
 
100
 
    G_debug(1, "Nviz::UnloadSurface(): id=%d", id);
101
 
 
102
 
    if (GS_delete_surface(id) < 0)
103
 
      return 0;
104
 
 
105
 
    return 1;
106
 
}
107
 
 
108
 
/*!
109
 
  \brief Load vector map overlay
110
 
 
111
 
  \param name vector map name
112
 
  \param points if true load 2d points rather then 2d lines
113
 
 
114
 
  \return object id
115
 
  \return -1 on failure
116
 
*/
117
 
int Nviz::LoadVector(const char *name, bool points)
118
 
{
119
 
    int id;
120
 
    char *mapset;
121
 
 
122
 
    if (GS_num_surfs() == 0) { /* load base surface if no loaded */
123
 
        int *surf_list, nsurf;
124
 
        
125
 
        Nviz_new_map_obj(MAP_OBJ_SURF, NULL, 0.0, data);
126
 
 
127
 
        surf_list = GS_get_surf_list(&nsurf);
128
 
        GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
129
 
    }
130
 
 
131
 
    mapset = G_find_vector2 (name, "");
132
 
    if (mapset == NULL) {
133
 
        G_warning(_("Vector map <%s> not found"),
134
 
                  name);
135
 
    }
136
 
 
137
 
    if (points) {
138
 
      id = Nviz_new_map_obj(MAP_OBJ_SITE,
139
 
                            G_fully_qualified_name(name, mapset), 0.0,
140
 
                            data);
141
 
    }
142
 
    else {
143
 
      id = Nviz_new_map_obj(MAP_OBJ_VECT,
144
 
                            G_fully_qualified_name(name, mapset), 0.0,
145
 
                            data);
146
 
    }
147
 
 
148
 
    G_debug(1, "Nviz::LoadVector(): name=%s -> id=%d", name, id);
149
 
 
150
 
    return id;
151
 
}
152
 
  
153
 
/*!
154
 
  \brief Unload vector set
155
 
 
156
 
  \param id vector set id
157
 
  \param points vector points or lines set
158
 
 
159
 
  \return 1 on success
160
 
  \return 0 on failure
161
 
*/
162
 
int Nviz::UnloadVector(int id, bool points)
163
 
{
164
 
    G_debug(1, "Nviz::UnloadVector(): id=%d", id);
165
 
 
166
 
    if (points) {
167
 
        if (!GP_site_exists(id)) {
168
 
            return 0;
169
 
        }
170
 
        
171
 
        if (GP_delete_site(id) < 0)
172
 
            return 0;
173
 
    }
174
 
    else {
175
 
        if (!GV_vect_exists(id)) {
176
 
            return 0;
177
 
        }
178
 
        
179
 
        if (GV_delete_vector(id) < 0)
180
 
            return 0;
181
 
    }
182
 
 
183
 
    return 1;
184
 
}
185
 
 
186
 
/*!
187
 
  \brief Load 3d raster map (volume)
188
 
 
189
 
  \param name 3d raster map name
190
 
  \param color_name 3d raster map for color (NULL for color_value)
191
 
  \param color_value color string (named color or RGB triptet)
192
 
 
193
 
  \return object id
194
 
  \return -1 on failure
195
 
*/
196
 
int Nviz::LoadVolume(const char* name, const char *color_name, const char *color_value)
197
 
{
198
 
    char *mapset;
199
 
    int id;
200
 
 
201
 
    mapset = G_find_grid3(name, "");
202
 
    if (mapset == NULL) {
203
 
        G_warning(_("3d raster map <%s> not found"),
204
 
                  name);
205
 
        return -1;
206
 
    }
207
 
            
208
 
    /* topography */
209
 
    id = Nviz_new_map_obj(MAP_OBJ_VOL,
210
 
                          G_fully_qualified_name(name, mapset), 0.0,
211
 
                          data);
212
 
 
213
 
    if (color_name) { /* check for color map */
214
 
        mapset = G_find_grid3(color_name, "");
215
 
        if (mapset == NULL) {
216
 
            G_warning(_("3d raster map <%s> not found"),
217
 
                      color_name);
218
 
            GVL_delete_vol(id);
219
 
            return -1;
220
 
        }
221
 
 
222
 
        Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
223
 
                      G_fully_qualified_name(color_name, mapset), -1.0,
224
 
                      data);
225
 
    }
226
 
    else if (color_value) { /* check for color value */
227
 
        Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, CONST_ATT,
228
 
                      NULL, Nviz_color_from_str(color_value),
229
 
                      data);
230
 
    }
231
 
    else { /* use by default elevation map for coloring */
232
 
        Nviz_set_attr(id, MAP_OBJ_VOL, ATT_COLOR, MAP_ATT,
233
 
                      G_fully_qualified_name(name, mapset), -1.0,
234
 
                      data);
235
 
    }
236
 
    
237
 
    G_debug(1, "Nviz::LoadVolume(): name=%s -> id=%d", name, id);
238
 
 
239
 
    return id;
240
 
}
241
 
 
242
 
/*!
243
 
  \brief Unload volume
244
 
 
245
 
  \param id volume id
246
 
 
247
 
  \return 1 on success
248
 
  \return 0 on failure
249
 
*/
250
 
int Nviz::UnloadVolume(int id)
251
 
{
252
 
    if (!GVL_vol_exists(id)) {
253
 
        return 0;
254
 
    }
255
 
 
256
 
    G_debug(1, "Nviz::UnloadVolume(): id=%d", id);
257
 
 
258
 
    if (GVL_delete_vol(id) < 0)
259
 
      return 0;
260
 
 
261
 
    return 1;
262
 
}
263