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

« back to all changes in this revision

Viewing changes to lib/nviz/nviz.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:
1
1
/*!
2
 
   \file nviz.c
 
2
   \file lib/nviz/nviz.c
3
3
 
4
4
   \brief Nviz library -- Data management
5
5
 
6
 
   COPYRIGHT: (C) 2008 by the GRASS Development Team
7
 
 
8
 
   This program is free software under the GNU General Public
9
 
   License (>=v2). Read the file COPYING that comes with GRASS
10
 
   for details.
11
 
 
12
6
   Based on visualization/nviz/src/
13
 
 
14
 
   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
15
 
 
16
 
   \date 2008
 
7
   
 
8
   (C) 2008, 2010 by the GRASS Development Team
 
9
   This program is free software under the GNU General Public License
 
10
   (>=v2). Read the file COPYING that comes with GRASS for details.
 
11
 
 
12
   \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008/2010)
17
13
 */
18
14
 
 
15
#include <grass/colors.h>
 
16
#include <grass/raster.h>
19
17
#include <grass/glocale.h>
20
18
#include <grass/nviz.h>
21
19
 
41
39
    }
42
40
 
43
41
    /* lights */
44
 
    for (i = 0; i < MAX_LIGHTS; i++) {
 
42
    GS_set_light_reset(1);
 
43
    
 
44
    for (i = 0; i < MAX_LIGHTS - 1; i++) {
45
45
        Nviz_new_light(data);
46
46
    }
47
47
 
 
48
    /* fringe */
 
49
    data->num_fringes = 0;
 
50
    data->fringe = NULL;
 
51
 
 
52
    /* north arrow */
 
53
    data->draw_arrow = 0;
 
54
    data->arrow = NULL;
 
55
 
 
56
    /* scale bar*/
 
57
    data->num_scalebars = 0;
 
58
    data->scalebar = NULL;
 
59
 
48
60
    return;
49
61
}
50
62
 
 
63
/*! \brief Free allocated space by nv_data struct
 
64
 
 
65
  \param data nviz data
 
66
*/
 
67
void Nviz_destroy_data(nv_data *data)
 
68
{
 
69
    int i;
 
70
    for (i = 0; data->num_fringes; i++) {
 
71
        G_free(data->fringe[i]);
 
72
        data->fringe[i] = NULL;
 
73
    }
 
74
    data->num_fringes = 0;
 
75
    data->fringe = NULL;
 
76
    
 
77
    if (data->arrow) {
 
78
        G_free(data->arrow);
 
79
        data->arrow = NULL;
 
80
        data->draw_arrow = 0;
 
81
    }
 
82
 
 
83
    for (i = 0; data->num_scalebars; i++) {
 
84
        G_free(data->scalebar[i]);
 
85
        data->scalebar[i] = NULL;
 
86
    }
 
87
    data->num_scalebars = 0;
 
88
    data->scalebar = NULL;
 
89
}
 
90
 
51
91
/*!
52
92
   \brief Set background color
53
93
 
62
102
}
63
103
 
64
104
/*!
 
105
   \brief Get background color
 
106
 
 
107
   \param data nviz data
 
108
 
 
109
   \return color color value
 
110
 */
 
111
int Nviz_get_bgcolor(nv_data * data)
 
112
{
 
113
    return data->bgcolor;
 
114
}
 
115
 
 
116
/*!
65
117
   \brief Get color value from color string (name or RGB triplet)
66
118
 
67
119
   \param color_str color string
81
133
    return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
82
134
        ((int)((blu) << 16) & BLU_MASK);
83
135
}
 
136
 
 
137
/*! Add new fringe
 
138
 
 
139
  \param data nviz data
 
140
  \param id surface id
 
141
  \param color color
 
142
  \param elev fringe elevation
 
143
  \param nw,ne,sw,se 1 (turn on) 0 (turn off)
 
144
 
 
145
  \return pointer to allocated fringe_data structure
 
146
  \return NULL on error
 
147
*/
 
148
struct fringe_data *Nviz_new_fringe(nv_data *data,
 
149
                                    int id, unsigned long color,
 
150
                                    double elev, int nw, int ne, int sw, int se)
 
151
{
 
152
    int num;
 
153
    int *surf;
 
154
    struct fringe_data *f;
 
155
 
 
156
    if (!GS_surf_exists(id)) {
 
157
        /* select first surface from the list */
 
158
        surf = GS_get_surf_list(&num);
 
159
        if (num < 1)
 
160
            return NULL;
 
161
        id = surf[0];
 
162
        G_free(surf);
 
163
    }
 
164
     
 
165
 
 
166
    f = (struct fringe_data *) G_malloc(sizeof(struct fringe_data));
 
167
    f->id = id;
 
168
    f->color = color;
 
169
    f->elev = elev;
 
170
    f->where[0] = nw;
 
171
    f->where[1] = ne;
 
172
    f->where[2] = sw;
 
173
    f->where[3] = se;
 
174
 
 
175
    data->fringe = (struct fringe_data **) G_realloc(data->fringe, data->num_fringes + 1 * sizeof(struct fringe_data *));
 
176
    data->fringe[data->num_fringes++] = f;
 
177
    
 
178
    return f;
 
179
}
 
180
 
 
181
/*! Set fringe
 
182
 
 
183
  \param data nviz data
 
184
  \param id surface id
 
185
  \param color color
 
186
  \param elev fringe elevation
 
187
  \param nw,ne,sw,se 1 (turn on) 0 (turn off)
 
188
 
 
189
  \return pointer to allocated fringe_data structure
 
190
  \return NULL on error
 
191
*/
 
192
struct fringe_data *Nviz_set_fringe(nv_data *data,
 
193
                                    int id, unsigned long color,
 
194
                                    double elev, int nw, int ne, int sw, int se)
 
195
{
 
196
    int i, num;
 
197
    int *surf;
 
198
    struct fringe_data *f;
 
199
 
 
200
    if (!GS_surf_exists(id)) {
 
201
        /* select first surface from the list */
 
202
        surf = GS_get_surf_list(&num);
 
203
        if (num < 1)
 
204
            return NULL;
 
205
        id = surf[0];
 
206
        G_free(surf);
 
207
    }
 
208
    
 
209
    for (i = 0; i < data->num_fringes; i++) {
 
210
        f = data->fringe[i];
 
211
        if (f->id == id) {
 
212
            f->color = color;
 
213
            f->elev  = elev;
 
214
            f->where[0] = nw;
 
215
            f->where[1] = ne;
 
216
            f->where[2] = sw;
 
217
            f->where[3] = se;
 
218
            
 
219
            return f;
 
220
        }
 
221
    }
 
222
 
 
223
    f = Nviz_new_fringe(data,
 
224
                        id, color,
 
225
                        elev, nw, ne, sw, se);
 
226
    
 
227
    return f;
 
228
}
 
229
/*! Draw fringe
 
230
 
 
231
   \param data nviz data
 
232
 */
 
233
void Nviz_draw_fringe(nv_data *data)
 
234
{
 
235
    int i;
 
236
 
 
237
    for (i = 0; i < data->num_fringes; i++) {
 
238
        struct fringe_data *f = data->fringe[i];
 
239
 
 
240
        GS_draw_fringe(f->id, f->color, f->elev, f->where);
 
241
    }
 
242
}
 
243
/*!
 
244
   \brief Sets the North Arrow position and return world coords
 
245
 
 
246
   \param data nviz data
 
247
   \param sx,sy screen coordinates
 
248
   \param size arrow length
 
249
   \param color arrow/text color
 
250
 */
 
251
int Nviz_set_arrow(nv_data *data,
 
252
                   int sx, int sy, float size,
 
253
                   unsigned int color)
 
254
{
 
255
    int id, pt[2];
 
256
    int *surf_list, num_surfs;
 
257
    float coords[3];
 
258
    struct arrow_data *arw;
 
259
 
 
260
    if (GS_num_surfs() > 0) {
 
261
        surf_list = GS_get_surf_list(&num_surfs);
 
262
        id = surf_list[0];
 
263
        G_free(surf_list);
 
264
 
 
265
        pt[0] = sx;
 
266
        pt[1] = sy;
 
267
 
 
268
        GS_set_Narrow(pt, id, coords);
 
269
 
 
270
        if (data->arrow) {
 
271
            data->arrow->color = color;
 
272
            data->arrow->size  = size;
 
273
            data->arrow->where[0]  = coords[0];
 
274
            data->arrow->where[1]  = coords[1];
 
275
            data->arrow->where[2]  = coords[2];
 
276
        }    
 
277
        else {
 
278
            arw = (struct arrow_data *) G_malloc(sizeof(struct arrow_data));
 
279
            arw->color = color;
 
280
            arw->size  = size;
 
281
            arw->where[0]  = coords[0];
 
282
            arw->where[1]  = coords[1];
 
283
            arw->where[2]  = coords[2];
 
284
 
 
285
            data->arrow = arw;
 
286
        }
 
287
        return 1;
 
288
    }
 
289
    return 0;
 
290
}
 
291
 
 
292
 
 
293
/*!
 
294
   \brief Draws the North Arrow
 
295
 
 
296
   \param data nviz data
 
297
 */
 
298
int Nviz_draw_arrow(nv_data *data)
 
299
{
 
300
 
 
301
    struct arrow_data *arw = data->arrow;
 
302
    GLuint FontBase = 0; /* don't know how to get fontbase*/
 
303
 
 
304
    data->draw_arrow = 1;
 
305
    gsd_north_arrow(arw->where, arw->size, FontBase, arw->color, arw->color);
 
306
 
 
307
    return 1;
 
308
}
 
309
 
 
310
/*!
 
311
   \brief Deletes the North Arrow
 
312
 
 
313
   \param data nviz data
 
314
 */
 
315
void Nviz_delete_arrow(nv_data *data)
 
316
{
 
317
    data->draw_arrow = 0;
 
318
 
 
319
    return;
 
320
}
 
321
 
 
322
/*! Add new scalebar
 
323
 
 
324
  \param data nviz data
 
325
  \param bar_id scale bar id
 
326
  \param coords real(?) coordinates
 
327
  \param size scale bar length
 
328
  \param color scalebar/text color
 
329
 
 
330
  \return pointer to allocated scalebar_data structure
 
331
  \return NULL on error
 
332
*/
 
333
 
 
334
struct scalebar_data *Nviz_new_scalebar(nv_data *data,
 
335
                      int bar_id, float *coords, float size,
 
336
                      unsigned int color)
 
337
{
 
338
    struct scalebar_data *s;
 
339
     
 
340
 
 
341
    s = (struct scalebar_data *) G_malloc(sizeof(struct scalebar_data));
 
342
    s->id = bar_id;
 
343
    s->color = color;
 
344
    s->size = size;
 
345
    s->where[0] = coords[0];
 
346
    s->where[1] = coords[1];
 
347
    s->where[2] = coords[2];
 
348
 
 
349
    data->scalebar = (struct scalebar_data **) G_realloc(data->scalebar,
 
350
                      (data->num_scalebars + 1) * sizeof(struct scalebar_data *));
 
351
    data->scalebar[data->num_scalebars++] = s;
 
352
 
 
353
    return s;
 
354
 
 
355
}
 
356
/*!
 
357
   \brief Sets the scale bar position and return world coords
 
358
 
 
359
   \param data nviz data
 
360
   \param bar_id scale bar id
 
361
   \param sx,sy screen coordinates
 
362
   \param size scale bar length
 
363
   \param color scalebar/text color
 
364
 
 
365
   \return pointer to allocated scalebar_data structure
 
366
   \return NULL when there's no surface
 
367
 */
 
368
struct scalebar_data *Nviz_set_scalebar(nv_data *data, int bar_id,
 
369
                      int sx, int sy, float size,
 
370
                      unsigned int color)
 
371
{
 
372
    int i, id, pt[2];
 
373
    int *surf_list, num_surfs;
 
374
    float coords[3];
 
375
    struct scalebar_data *s;
 
376
 
 
377
    if (GS_num_surfs() > 0) {
 
378
        surf_list = GS_get_surf_list(&num_surfs);
 
379
        id = surf_list[0];
 
380
        G_free(surf_list);
 
381
 
 
382
        pt[0] = sx;
 
383
        pt[1] = sy;
 
384
 
 
385
        GS_set_Narrow(pt, id, coords); /* the same like arrow */
 
386
 
 
387
        for (i = 0; i < data->num_scalebars; i++) {
 
388
        if (data->scalebar[i]) {
 
389
            s = data->scalebar[i];
 
390
            if (s->id == bar_id) {
 
391
                s->color = color;
 
392
                s->size = size;
 
393
                s->where[0] = coords[0];
 
394
                s->where[1] = coords[1];
 
395
                s->where[2] = coords[2];
 
396
 
 
397
            return s;
 
398
            }
 
399
        }
 
400
        }
 
401
        
 
402
        s = Nviz_new_scalebar(data, bar_id, coords, size, color);
 
403
 
 
404
        return s;
 
405
    }
 
406
    return NULL;
 
407
}
 
408
/*!
 
409
   \brief Draws the Scale bar
 
410
 
 
411
   \param data nviz data
 
412
 */
 
413
void Nviz_draw_scalebar(nv_data *data)
 
414
{
 
415
    int i;
 
416
 
 
417
    GLuint FontBase = 0; /* don't know how to get fontbase*/
 
418
 
 
419
    for (i = 0; i < data->num_scalebars; i++) {
 
420
        if (data->scalebar[i]) {
 
421
            struct scalebar_data *s = data->scalebar[i];
 
422
 
 
423
            gsd_scalebar_v2(s->where, s->size, FontBase, s->color, s->color);
 
424
        }
 
425
    }
 
426
}
 
427
 
 
428
/*!
 
429
   \brief Deletes scale bar
 
430
   
 
431
   When scalebar is freed, array then contains NULL,
 
432
   which must be tested during drawing.
 
433
 
 
434
   \param data nviz data
 
435
 */
 
436
void Nviz_delete_scalebar(nv_data *data, int bar_id)
 
437
{
 
438
    if (bar_id < data->num_scalebars && data->scalebar[bar_id] != NULL) {
 
439
        G_free(data->scalebar[bar_id]);
 
440
        data->scalebar[bar_id] = NULL;
 
441
    }
 
442
}