GRASS GIS 8 Programmer's Manual 8.3.2(2024)-exported
Loading...
Searching...
No Matches
gvl2.c
Go to the documentation of this file.
1/*!
2 \file lib/ogsf/gvl2.c
3
4 \brief OGSF library - loading and manipulating volumes
5
6 GRASS OpenGL gsurf OGSF Library
7
8 (C) 1999-2008 by the GRASS Development Team
9
10 This program is free software under the
11 GNU General Public License (>=v2).
12 Read the file COPYING that comes with GRASS
13 for details.
14
15 \author Bill Brown UI-GMSL (May 1997)
16 Tomas Paudits (February 2004)
17 */
18
19#include <string.h>
20#include <grass/gis.h>
21#include <grass/raster3d.h>
22#include <grass/ogsf.h>
23#include <grass/glocale.h>
24#include "gsget.h"
25
26static int Vol_ID[MAX_VOLS];
27static int Next_vol = 0;
28
29static RASTER3D_Region wind3;
30static double Region[6];
31
32/*!
33 \brief Library initialization for volumes
34
35 Set region extent (N,S,W,E,T,B)
36 */
37void GVL_libinit(void)
38{
39 Rast3d_init_defaults();
40 Rast3d_get_window(&wind3);
41
42 Region[0] = wind3.north;
43 Region[1] = wind3.south;
44 Region[2] = wind3.west;
45 Region[3] = wind3.east;
46 Region[4] = wind3.top;
47 Region[5] = wind3.bottom;
48
49 return;
50}
51
52/*!
53 \brief Initialize 3D region
54
55 Set region extent (N,S,W,E,T,B)
56 */
58{
59 Rast3d_read_window(&wind3, NULL);
60
61 Region[0] = wind3.north;
62 Region[1] = wind3.south;
63 Region[2] = wind3.west;
64 Region[3] = wind3.east;
65 Region[4] = wind3.top;
66 Region[5] = wind3.bottom;
67
68 return;
69}
70
71/*!
72 \brief Get region extent settings
73
74 \param[out] n,s,w,e north, south, west, east
75 \param[out] t,b top, bottom
76
77 \return 1
78 */
79int GVL_get_region(float *n, float *s, float *w, float *e, float *t, float *b)
80{
81 *n = Region[0];
82 *s = Region[1];
83 *w = Region[2];
84 *e = Region[3];
85 *t = Region[4];
86 *b = Region[5];
87
88 return (1);
89}
90
91/*!
92 \brief Get window
93
94 \todo gvl_file.c use this - change
95
96 \return pointer to RASTER3D_Region struct (static)
97 */
98void *GVL_get_window(void)
99{
100 return &wind3;
101}
102
103/*!
104 \brief Check if volume set exists
105
106 \param id volume set id
107
108 \return 1 found
109 \return 0 not found
110 */
111int GVL_vol_exists(int id)
112{
113 int i, found = 0;
114
115 G_debug(3, "GVL_vol_exists");
116
117 if (NULL == gvl_get_vol(id)) {
118 return (0);
119 }
120
121 for (i = 0; i < Next_vol && !found; i++) {
122 if (Vol_ID[i] == id) {
123 found = 1;
124 }
125 }
126
127 return (found);
128}
129
130/*!
131 \brief Create new volume set
132
133 \return volume set id
134 \return -1 on error
135 */
136int GVL_new_vol(void)
137{
138 geovol *nvl;
139
140 G_debug(3, "GVL_new_vol():");
141
142 if (Next_vol < MAX_VOLS) {
143 nvl = gvl_get_new_vol();
144
145 gvl_init_vol(nvl, wind3.west + wind3.ew_res / 2.,
146 wind3.south + wind3.ns_res / 2., wind3.bottom, wind3.rows,
147 wind3.cols, wind3.depths, wind3.ew_res, wind3.ns_res,
148 wind3.tb_res);
149
150 Vol_ID[Next_vol] = nvl->gvol_id;
151 ++Next_vol;
152
153 G_debug(3, " id=%d", nvl->gvol_id);
154
155 return (nvl->gvol_id);
156 }
157
158 return (-1);
159}
160
161/*!
162 \brief Get number of loaded volume sets
163
164 \return number of volume sets
165 */
167{
168 return (gvl_num_vols());
169}
170
171/*!
172 \brief Get list of loaded volume sets
173
174 Must be freed if not needed!
175
176 \param[out] numvols number of volume sets
177
178 \return pointer to list of volume sets
179 \return NULL on error
180 */
181int *GVL_get_vol_list(int *numvols)
182{
183 int i, *ret;
184
185 *numvols = Next_vol;
186
187 if (Next_vol) {
188 ret = (int *)G_malloc(Next_vol * sizeof(int));
189 if (!ret)
190 return (NULL);
191
192 for (i = 0; i < Next_vol; i++) {
193 ret[i] = Vol_ID[i];
194 }
195
196 return (ret);
197 }
198
199 return (NULL);
200}
201
202/*!
203 \brief Delete volume set from list
204
205 \param id volume set id
206
207 \return 1 on success
208 \return -1 on error (invalid volume set id)
209 */
210int GVL_delete_vol(int id)
211{
212 int i, j, found = 0;
213
214 G_debug(3, "GVL_delete_vol");
215
216 if (GVL_vol_exists(id)) {
217
218 for (i = 0; i < GVL_isosurf_num_isosurfs(id); i++) {
219 GVL_isosurf_del(id, 0);
220 }
221
222 for (i = 0; i < GVL_slice_num_slices(id); i++) {
223 GVL_slice_del(id, 0);
224 }
225
226 gvl_delete_vol(id);
227
228 for (i = 0; i < Next_vol && !found; i++) {
229 if (Vol_ID[i] == id) {
230 found = 1;
231 for (j = i; j < Next_vol; j++) {
232 Vol_ID[j] = Vol_ID[j + 1];
233 }
234 }
235 }
236
237 if (found) {
238 --Next_vol;
239
240 return (1);
241 }
242 }
243
244 return (-1);
245}
246
247/*!
248 \brief Load 3d raster map to volume set
249
250 \param id volume set id
251 \param filename 3d raster map name
252
253 \return -1 on error
254 \return 0 on success
255 */
256int GVL_load_vol(int id, const char *filename)
257{
258 geovol *gvl;
259 int handle;
260
261 G_debug(3, "GVL_load_vol(): id=%d, name=%s", id, filename);
262
263 if (NULL == (gvl = gvl_get_vol(id))) {
264 return (-1);
265 }
266
267 G_message(_("Loading 3d raster map <%s>..."), filename);
268
269 if (0 > (handle = gvl_file_newh(filename, VOL_FTYPE_RASTER3D)))
270 return (-1);
271
272 gvl->hfile = handle;
273
274 return (0);
275}
276
277/*!
278 \brief Get volume set name
279
280 \param id volume set id
281 \param[out] filename name (must be allocated)
282
283 \return -1 on error
284 \return 1 on success
285 */
286int GVL_get_volname(int id, char *filename)
287{
288 geovol *gvl;
289
290 if (NULL == (gvl = gvl_get_vol(id))) {
291 return (-1);
292 }
293
294 if (0 > gvl->hfile) {
295 return (-1);
296 }
297
298 strcpy(filename, gvl_file_get_name(gvl->hfile));
299
300 return (1);
301}
302
303/*!
304 \brief Get volume dimensions
305
306 \param id volume set id
307 \param[out] rows,cols,depths number of rows, cols, depths
308 */
309void GVL_get_dims(int id, int *rows, int *cols, int *depths)
310{
311 geovol *gvl;
312
313 gvl = gvl_get_vol(id);
314
315 if (gvl) {
316 *rows = gvl->rows;
317 *cols = gvl->cols;
318 *depths = gvl->depths;
319 }
320
321 G_debug(3, "GVL_get_dims() id=%d, rows=%d, cols=%d, depths=%d",
322 gvl->gvol_id, gvl->rows, gvl->cols, gvl->depths);
323
324 return;
325}
326
327/*!
328 \brief Set trans ?
329
330 \param id volume set id
331 \param xtrans,ytrans,ztrans x/y/z trans values
332 */
333void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
334{
335 geovol *gvl;
336
337 G_debug(3, "GVL_set_trans");
338
339 gvl = gvl_get_vol(id);
340
341 if (gvl) {
342 gvl->x_trans = xtrans;
343 gvl->y_trans = ytrans;
344 gvl->z_trans = ztrans;
345 }
346
347 return;
348}
349
350/*!
351 \brief Get trans ?
352
353 \param id volume set id
354 \param[out] xtrans,ytrans,ztrans x/y/z trans values
355
356 \return 1 on success
357 \return -1 on error
358 */
359int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
360{
361 geovol *gvl;
362
363 gvl = gvl_get_vol(id);
364
365 if (gvl) {
366 *xtrans = gvl->x_trans;
367 *ytrans = gvl->y_trans;
368 *ztrans = gvl->z_trans;
369
370 return (1);
371 }
372
373 return (-1);
374}
375
376/*!
377 \brief Set drawing wire box
378
379 \param id volume set id
380 \param draw_wire 1 for drawing wire, 0 otherwise
381 */
382void GVL_set_draw_wire(int id, int draw_wire)
383{
384 geovol *gvl;
385
386 G_debug(3, "GVL_set_draw_wire");
387
388 gvl = gvl_get_vol(id);
389
390 if (gvl) {
391 gvl->draw_wire = draw_wire;
392 }
393
394 return;
395}
396
397/*!
398 \brief Draw volume set
399
400 \param vid volume set id
401 */
402void GVL_draw_vol(int vid)
403{
404 geovol *gvl;
405
406 gvl = gvl_get_vol(vid);
407
408 if (gvl) {
409 gvld_vol(gvl);
410 if (gvl->draw_wire) {
411 gvld_wind3_box(gvl);
412 }
413 }
414
415 return;
416}
417
418/*!
419 \brief Draw volume in wire mode
420
421 \param id volume set id
422 */
423void GVL_draw_wire(int id)
424{
425 geovol *gvl;
426
427 G_debug(3, "GVL_draw_wire(): id=%d", id);
428
429 gvl = gvl_get_vol(id);
430
431 if (gvl) {
432 gvld_wire_vol(gvl);
433 }
434
435 return;
436}
437
438/*!
439 \brief Draw all volume sets
440 */
442{
443 int id;
444
445 for (id = 0; id < Next_vol; id++) {
446 GVL_draw_vol(Vol_ID[id]);
447 }
448
449 return;
450}
451
452/*!
453 \brief Draw all volume sets in wire mode
454 */
456{
457 int id;
458
459 for (id = 0; id < Next_vol; id++) {
460 GVL_draw_wire(Vol_ID[id]);
461 }
462
463 return;
464}
465
466/*!
467 \brief Set client data for volume set
468
469 \param id volume set id
470 \param clientd pointer to client data
471
472 \return 1 on success
473 \return -1 on error
474 */
475int GVL_Set_ClientData(int id, void *clientd)
476{
477 geovol *gvl;
478
479 gvl = gvl_get_vol(id);
480
481 if (gvl) {
482 gvl->clientdata = clientd;
483
484 return (1);
485 }
486
487 return (-1);
488}
489
490/*!
491 \brief Get client data
492
493 \param id volume set id
494
495 \return pointer to client data
496 \return NULL on error
497 */
499{
500 geovol *gvl;
501
502 gvl = gvl_get_vol(id);
503
504 if (gvl) {
505 return (gvl->clientdata);
506 }
507
508 return (NULL);
509}
510
511/*!
512 \brief Set focus on map center
513
514 \param id volume set id
515 */
517{
518 float center[3];
519 geovol *gvl;
520
521 G_debug(3, "GS_set_focus_center_map");
522
523 gvl = gvl_get_vol(id);
524
525 if (gvl) {
526 center[X] = (gvl->xmax - gvl->xmin) / 2.;
527 center[Y] = (gvl->ymax - gvl->ymin) / 2.;
528 center[Z] = (gvl->zmax - gvl->zmin) / 2.;
529
530 GS_set_focus(center);
531 }
532
533 return;
534}
535
536/************************************************************************/
537/* ISOSURFACES */
538
539/************************************************************************/
540
541/*!
542 \brief Get draw resolution for isosurface
543
544 \todo error handling
545
546 \param id volume set id
547 \param[out] xres,yres,zres x/y/z resolution value
548 */
549void GVL_isosurf_get_drawres(int id, int *xres, int *yres, int *zres)
550{
551 geovol *gvl;
552
553 G_debug(3, "GVL_isosurf_get_drawres");
554
555 gvl = gvl_get_vol(id);
556
557 if (gvl) {
558 *xres = gvl->isosurf_x_mod;
559 *yres = gvl->isosurf_y_mod;
560 *zres = gvl->isosurf_z_mod;
561 }
562
563 return;
564}
565
566/*!
567 \brief Set isosurface draw resolution
568
569 \param id volume set id
570 \param xres,yres,zres x/y/z resolution value
571
572 \return -1 on error (invalid values/volume set id)
573 \return 0 on success
574 */
575int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
576{
577 geovol *gvl;
578 int i;
579
580 G_debug(3, "GVL_isosurf_set_drawres(): id=%d", id);
581
582 if (xres < 1 || yres < 1 || zres < 1) {
583 return (-1);
584 }
585
586 gvl = gvl_get_vol(id);
587
588 if (gvl) {
589 gvl->isosurf_x_mod = xres;
590 gvl->isosurf_y_mod = yres;
591 gvl->isosurf_z_mod = zres;
592
593 for (i = 0; i < gvl->n_isosurfs; i++) {
594 gvl_isosurf_set_att_changed(gvl->isosurf[i], ATT_TOPO);
595 }
596
597 return (0);
598 }
599
600 return (-1);
601}
602
603/*!
604 \brief Get isosurface draw mode
605
606 \param id volume set id
607 \param[out] mode draw-mode
608
609 \return 1 on success
610 \return -1 on error
611 */
612int GVL_isosurf_get_drawmode(int id, int *mode)
613{
614 geovol *gvl;
615
616 gvl = gvl_get_vol(id);
617
618 if (gvl) {
619 *mode = gvl->isosurf_draw_mode;
620
621 return (1);
622 }
623
624 return (-1);
625}
626
627/*!
628 \brief Set isosurface draw mode
629
630 \param id volume set id
631 \param mode draw mode
632
633 \return 0 on success
634 \return -1 on error (invalid volume set id)
635 */
636int GVL_isosurf_set_drawmode(int id, int mode)
637{
638 geovol *gvl;
639
640 G_debug(3, "GVL_isosurf_set_drawmode(): id=%d mode=%d", id, mode);
641
642 gvl = gvl_get_vol(id);
643
644 if (gvl) {
645 gvl->isosurf_draw_mode = mode;
646
647 return (0);
648 }
649
650 return (-1);
651}
652
653/*!
654 \brief Add isosurface
655
656 \param id volume set id
657
658 \return -1 on error (invalid volume set id
659 \return 1 on success
660 */
662{
663 geovol *gvl;
664 geovol_isosurf *isosurf;
665
666 G_debug(3, "GVL_isosurf_add() id=%d", id);
667
668 gvl = gvl_get_vol(id);
669
670 if (!gvl)
671 return (-1);
672
673 if (gvl->n_isosurfs == MAX_ISOSURFS)
674 return (-1);
675
676 isosurf = (geovol_isosurf *)G_malloc(sizeof(geovol_isosurf));
677 if (!isosurf) {
678 return (-1);
679 }
680
681 gvl_isosurf_init(isosurf);
682
683 gvl->n_isosurfs++;
684 gvl->isosurf[gvl->n_isosurfs - 1] = (geovol_isosurf *)isosurf;
685
686 return (1);
687}
688
689/*!
690 \brief Delete isosurface
691
692 \param id volume set id
693 \param isosurf_id isosurface id
694
695 \return -1 on error
696 \return 1 on success
697 */
698int GVL_isosurf_del(int id, int isosurf_id)
699{
700 geovol *gvl;
701 geovol_isosurf *isosurf;
702 int i;
703
704 G_debug(3, "GVL_isosurf_del");
705
706 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
707
708 if (!isosurf)
709 return (-1);
710
711 if (!gvl_isosurf_freemem(isosurf)) {
712 return (-1);
713 }
714
715 gvl = gvl_get_vol(id);
716
717 G_free(gvl->isosurf[isosurf_id]);
718
719 for (i = isosurf_id + 1; i < gvl->n_isosurfs; i++) {
720 gvl->isosurf[i - 1] = gvl->isosurf[i];
721 }
722
723 gvl->n_isosurfs--;
724
725 return (1);
726}
727
728/*!
729 \brief Move up isosurface in list
730
731 \param id volume set id
732 \param isosurf_id isosurface id
733
734 \return -1 on error
735 \return 1 on success
736 */
737int GVL_isosurf_move_up(int id, int isosurf_id)
738{
739 geovol *gvl;
740 geovol_isosurf *tmp;
741
742 G_debug(3, "GVL_isosurf_move_up");
743
744 gvl = gvl_get_vol(id);
745
746 if (!gvl)
747 return (-1);
748
749 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
750 return (-1);
751
752 if (isosurf_id == 0)
753 return (1);
754
755 tmp = gvl->isosurf[isosurf_id - 1];
756 gvl->isosurf[isosurf_id - 1] = gvl->isosurf[isosurf_id];
757 gvl->isosurf[isosurf_id] = tmp;
758
759 return (1);
760}
761
762/*!
763 \brief Move down isosurface in list
764
765 \param id volume set id
766 \param isosurf_id isosurface id
767
768 \return -1 on error
769 \return 1 on success
770 */
771int GVL_isosurf_move_down(int id, int isosurf_id)
772{
773 geovol *gvl;
774 geovol_isosurf *tmp;
775
776 G_debug(3, "GVL_isosurf_move_up");
777
778 gvl = gvl_get_vol(id);
779
780 if (!gvl)
781 return (-1);
782
783 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
784 return (-1);
785
786 if (isosurf_id == (gvl->n_isosurfs - 1))
787 return (1);
788
789 tmp = gvl->isosurf[isosurf_id + 1];
790 gvl->isosurf[isosurf_id + 1] = gvl->isosurf[isosurf_id];
791 gvl->isosurf[isosurf_id] = tmp;
792
793 return (1);
794}
795
796/*!
797 \brief Get isosurface attributes
798
799 \param id volume set id
800 \param isosurf_id surface id
801 \param att attribute id
802 \param[out] set
803 \param[out] constant
804 \param[out] mapname
805
806 \return -1 on error
807 \return 1 on success
808 */
809int GVL_isosurf_get_att(int id, int isosurf_id, int att, int *set,
810 float *constant, char *mapname)
811{
812 int src;
813 geovol_isosurf *isosurf;
814
815 G_debug(3, "GVL_isosurf_get_att");
816
817 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
818
819 if (isosurf) {
820 if (-1 != (src = gvl_isosurf_get_att_src(isosurf, att))) {
821 *set = src;
822
823 if (src == CONST_ATT) {
824 *constant = isosurf->att[att].constant;
825 }
826 else if (src == MAP_ATT) {
827 strcpy(mapname, gvl_file_get_name(isosurf->att[att].hfile));
828 }
829
830 return (1);
831 }
832
833 return (-1);
834 }
835
836 return (-1);
837}
838
839/*!
840 \brief Unset isosurface attributes
841
842 \param id volume set id
843 \param isosurface_id isosurface id
844 \param att attribute id
845
846 \return ?
847 \return -1 on error
848 */
849int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
850{
851 geovol_isosurf *isosurf;
852
853 G_debug(3, "GVL_isosurf_unset_att");
854
855 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
856
857 if (isosurf) {
858 return (gvl_isosurf_set_att_src(isosurf, att, NOTSET_ATT));
859 }
860
861 return (-1);
862}
863
864/*!
865 \brief Set constant isosurface attribute
866
867 Attributes:
868 - ATT_NORM
869 - ATT_TOPO topography (level) constant
870 - ATT_COLOR color map/constant
871 - ATT_MASK mask map
872 - ATT_TRANSP transparency map/constant
873 - ATT_SHINE shininess map/constant
874 - ATT_EMIT emission map/constant
875
876 \param id volume set id
877 \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
878 \param att attribute descriptor
879 \param constant constant value
880
881 \return 1 on success
882 \return -1 on error
883 */
884int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
885{
886 geovol_isosurf *isosurf;
887
888 G_debug(3,
889 "GVL_isosurf_set_att_const() id=%d isosurf_id=%d "
890 "att=%d const=%f",
891 id, isosurf_id, att, constant);
892
893 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
894
895 if (isosurf) {
896 return (gvl_isosurf_set_att_const(isosurf, att, constant));
897 }
898
899 return (-1);
900}
901
902/*!
903 \brief Set isosurface map attribute
904
905 Attributes:
906 - ATT_NORM
907 - ATT_TOPO topography (level) constant
908 - ATT_COLOR color map/constant
909 - ATT_MASK mask map
910 - ATT_TRANSP transparency map/constant
911 - ATT_SHINE shininess map/constant
912 - ATT_EMIT emission map/constant
913
914 \param id volume set id
915 \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
916 \param att attribute descriptor
917 \param filename map name
918
919 \return 1 on success
920 \return -1 on error
921 */
922int GVL_isosurf_set_att_map(int id, int isosurf_id, int att,
923 const char *filename)
924{
925 geovol_isosurf *isosurf;
926
927 G_debug(3,
928 "GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d "
929 "att=%d map=%s",
930 id, isosurf_id, att, filename);
931
932 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
933
934 if (isosurf) {
935 return gvl_isosurf_set_att_map(isosurf, att, filename);
936 }
937
938 return (-1);
939}
940
941/*!
942 \brief Get isosurface flags
943
944 \param id volume set id
945 \param isosurf_id isosurface id
946 \param[out] inout map name
947
948 \return 1 on success
949 \return -1 on error
950 */
951int GVL_isosurf_get_flags(int id, int isosurf_id, int *inout)
952{
953 geovol_isosurf *isosurf;
954
955 G_debug(3, "GVL_isosurf_get_flags");
956
957 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
958
959 if (isosurf) {
960 *inout = isosurf->inout_mode;
961
962 return (1);
963 }
964 return (-1);
965}
966
967/*!
968 \brief Set isosurface flags
969
970 \param id volume set id
971 \param isosurf_id isosurface id
972 \param inout map name
973
974 \return 1 on success
975 \return -1 on error
976 */
977int GVL_isosurf_set_flags(int id, int isosurf_id, int inout)
978{
979 geovol_isosurf *isosurf;
980
981 G_debug(3, "GVL_isosurf_get_flags");
982
983 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
984
985 if (isosurf) {
986 isosurf->inout_mode = inout;
987
988 return (1);
989 }
990
991 return (-1);
992}
993
994/*!
995 \brief Get number of available isosurfaces
996
997 \param id volume set id
998
999 \return number of isosurfaces
1000 \return -1 on error
1001 */
1003{
1004 geovol *gvl;
1005
1006 G_debug(3, "GVL_isosurf_num_isosurfs");
1007
1008 gvl = gvl_get_vol(id);
1009
1010 if (gvl) {
1011 return gvl->n_isosurfs;
1012 }
1013
1014 return (-1);
1015}
1016
1017/*!
1018 \brief Set mask attribute mode
1019
1020 Mask attribute special: constant is set to indicate invert or no
1021
1022 \param id volume set id
1023 \param isosurf_id isosurface id
1024 \param mode attribute mode
1025
1026 \return mode id
1027 \return -1 on error
1028 */
1029int GVL_isosurf_set_maskmode(int id, int isosurf_id, int mode)
1030{
1031 geovol_isosurf *isosurf;
1032
1033 G_debug(3, "GVL_isosurf_set_att_const");
1034
1035 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
1036
1037 if (isosurf) {
1038 isosurf->att[ATT_MASK].constant = mode;
1039
1040 return (mode);
1041 }
1042
1043 return (-1);
1044}
1045
1046/*!
1047 \brief Get isosurface mask mode
1048
1049 \param id volume set id
1050 \param isosurf_id isosurface id
1051 \param mode attribute mode
1052
1053 \return 1 on success
1054 \return -1 on error
1055 */
1056int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode)
1057{
1058 geovol_isosurf *isosurf;
1059
1060 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
1061
1062 if (isosurf) {
1063 *mode = isosurf->att[ATT_MASK].constant;
1064
1065 return (1);
1066 }
1067
1068 return (-1);
1069}
1070
1071/************************************************************************/
1072/* SLICES */
1073
1074/************************************************************************/
1075
1076/*!
1077 \brief Get draw resolution of slice
1078
1079 \param id volume set id
1080 \param[out] xres,yres,zres x/y/z resolution value
1081 */
1082void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres)
1083{
1084 geovol *gvl;
1085
1086 G_debug(3, "GVL_slice_get_drawres");
1087
1088 gvl = gvl_get_vol(id);
1089
1090 if (gvl) {
1091 *xres = gvl->slice_x_mod;
1092 *yres = gvl->slice_y_mod;
1093 *zres = gvl->slice_z_mod;
1094 }
1095
1096 return;
1097}
1098
1099/*!
1100 \brief Set slice draw resolution
1101
1102 \param id volume set id
1103 \param xres,yres,zres x/y/z resolution value
1104
1105 \return 0 on success
1106 \return -1 on error (invalid value or id)
1107 */
1108int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
1109{
1110 geovol *gvl;
1111 int i;
1112
1113 G_debug(3, "GVL_slice_set_drawres(): id=%d", id);
1114
1115 if (xres < 1 || yres < 1 || zres < 1) {
1116 return (-1);
1117 }
1118
1119 gvl = gvl_get_vol(id);
1120
1121 if (gvl) {
1122 gvl->slice_x_mod = xres;
1123 gvl->slice_y_mod = yres;
1124 gvl->slice_z_mod = zres;
1125
1126 for (i = 0; i < gvl->n_slices; i++) {
1127 gvl->slice[i]->changed = 1;
1128 }
1129
1130 return (0);
1131 }
1132
1133 return (-1);
1134}
1135
1136/*!
1137 \brief Get slice draw mode
1138
1139 \param id volume set id
1140 \param[out] mode draw mode
1141
1142 \return 1 on success
1143 \return -1 on error (invalid id)
1144 */
1145int GVL_slice_get_drawmode(int id, int *mode)
1146{
1147 geovol *gvl;
1148
1149 gvl = gvl_get_vol(id);
1150
1151 if (gvl) {
1152 *mode = gvl->slice_draw_mode;
1153
1154 return (1);
1155 }
1156
1157 return (-1);
1158}
1159
1160/*!
1161 \brief Set slice draw mode
1162
1163 \param id volume set id
1164 \param mode draw mode
1165
1166 \return 0 on success
1167 \return -1 on error (invalid id)
1168 */
1169int GVL_slice_set_drawmode(int id, int mode)
1170{
1171 geovol *gvl;
1172
1173 G_debug(3, "GVL_slice_set_drawmode(): id=%d, mode=%d", id, mode);
1174
1175 gvl = gvl_get_vol(id);
1176
1177 if (gvl) {
1178 gvl->slice_draw_mode = mode;
1179
1180 return (0);
1181 }
1182
1183 return (-1);
1184}
1185
1186/*!
1187 \brief Add slice
1188
1189 \param id volume set id
1190
1191 \return -1 on error
1192 \return 1 on success
1193 */
1194int GVL_slice_add(int id)
1195{
1196 geovol *gvl;
1197 geovol_slice *slice;
1198
1199 G_debug(3, "GVL_slice_add");
1200
1201 gvl = gvl_get_vol(id);
1202
1203 if (!gvl)
1204 return (-1);
1205
1206 if (gvl->n_slices == MAX_SLICES)
1207 return (-1);
1208
1209 if (NULL == (slice = (geovol_slice *)G_malloc(sizeof(geovol_slice)))) {
1210 return (-1);
1211 }
1212
1213 gvl_slice_init(slice);
1214
1215 gvl->n_slices++;
1216 gvl->slice[gvl->n_slices - 1] = (geovol_slice *)slice;
1217
1218 return (1);
1219}
1220
1221/*!
1222 \brief Delete slice
1223
1224 \param id volume set id
1225 \param slice_id slice id
1226
1227 \return -1 on error
1228 \return 1 on success
1229 */
1230int GVL_slice_del(int id, int slice_id)
1231{
1232 geovol *gvl;
1233 geovol_slice *slice;
1234 int i;
1235
1236 G_debug(3, "GVL_slice_del");
1237
1238 slice = gvl_slice_get_slice(id, slice_id);
1239
1240 if (!slice)
1241 return (-1);
1242
1243 if (!gvl_slice_freemem(slice)) {
1244 return (-1);
1245 }
1246
1247 gvl = gvl_get_vol(id);
1248
1249 G_free(gvl->slice[slice_id]);
1250
1251 for (i = slice_id + 1; i < gvl->n_slices; i++) {
1252 gvl->slice[i - 1] = gvl->slice[i];
1253 }
1254
1255 gvl->n_slices--;
1256
1257 return (1);
1258}
1259
1260/*!
1261 \brief Move up slice
1262
1263 \param id volume set id
1264 \param slice_id slice id
1265
1266 \return -1 on error
1267 \return 1 on success
1268 */
1269int GVL_slice_move_up(int id, int slice_id)
1270{
1271 geovol *gvl;
1272 geovol_slice *tmp;
1273
1274 G_debug(3, "GVL_slice_move_up");
1275
1276 gvl = gvl_get_vol(id);
1277
1278 if (!gvl)
1279 return (-1);
1280
1281 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1282 return (-1);
1283
1284 if (slice_id == 0)
1285 return (1);
1286
1287 tmp = gvl->slice[slice_id - 1];
1288 gvl->slice[slice_id - 1] = gvl->slice[slice_id];
1289 gvl->slice[slice_id] = tmp;
1290
1291 return (1);
1292}
1293
1294/*!
1295 \brief Move down slice
1296
1297 \param id volume set id
1298 \param slice_id slice id
1299
1300 \return -1 on error
1301 \return 1 on success
1302 */
1303int GVL_slice_move_down(int id, int slice_id)
1304{
1305 geovol *gvl;
1306 geovol_slice *tmp;
1307
1308 G_debug(3, "GVL_slice_move_up");
1309
1310 gvl = gvl_get_vol(id);
1311
1312 if (!gvl)
1313 return (-1);
1314
1315 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1316 return (-1);
1317
1318 if (slice_id == (gvl->n_slices - 1))
1319 return (1);
1320
1321 tmp = gvl->slice[slice_id + 1];
1322 gvl->slice[slice_id + 1] = gvl->slice[slice_id];
1323 gvl->slice[slice_id] = tmp;
1324
1325 return (1);
1326}
1327
1328/*!
1329 \brief Get number or slices
1330
1331 \param id volume set id
1332
1333 \return number of slices
1334 \return -1 on error
1335 */
1337{
1338 geovol *gvl;
1339
1340 G_debug(3, "GVL_isosurf_num_isosurfs");
1341
1342 gvl = gvl_get_vol(id);
1343
1344 if (gvl) {
1345 return gvl->n_slices;
1346 }
1347
1348 return (-1);
1349}
1350
1351/*!
1352 \brief Get slice position
1353
1354 \param id volume set id
1355 \param slice_id slice id
1356 \param[out] x1,y1,z1 coordinates ?
1357 \param[out] x2,y2,z2 coordinates ?
1358 \param[out] dir direction
1359
1360 \return -1 on error
1361 \return 1 on success
1362 */
1363int GVL_slice_get_pos(int id, int slice_id, float *x1, float *x2, float *y1,
1364 float *y2, float *z1, float *z2, int *dir)
1365{
1366 geovol *gvl;
1367 geovol_slice *slice;
1368 int cols, rows, depths;
1369
1370 gvl = gvl_get_vol(id);
1371
1372 if (!gvl)
1373 return (-1);
1374
1375 slice = gvl_slice_get_slice(id, slice_id);
1376
1377 if (!slice)
1378 return (-1);
1379
1380 if (slice->dir == X) {
1381 cols = gvl->rows;
1382 rows = gvl->depths;
1383 depths = gvl->cols;
1384 }
1385 else if (slice->dir == Y) {
1386 cols = gvl->cols;
1387 rows = gvl->depths;
1388 depths = gvl->rows;
1389 }
1390 else if (slice->dir == Z) {
1391 cols = gvl->cols;
1392 rows = gvl->rows;
1393 depths = gvl->depths;
1394 }
1395 else {
1396 return (-1);
1397 }
1398
1399 *x1 = slice->x1 / (cols - 1);
1400 *x2 = slice->x2 / (cols - 1);
1401 *y1 = slice->y1 / (rows - 1);
1402 *y2 = slice->y2 / (rows - 1);
1403 *z1 = slice->z1 / (depths - 1);
1404 *z2 = slice->z2 / (depths - 1);
1405
1406 *dir = slice->dir;
1407
1408 return (1);
1409}
1410
1411/*!
1412 \brief Get slice position
1413
1414 \param id volume set id
1415 \param slice_id slice id
1416 \param x1,y1,z1 coordinates ?
1417 \param x2,y2,z2 coordinates ?
1418 \param dir direction
1419
1420 \return -1 on error
1421 \return 1 on success
1422 */
1423int GVL_slice_set_pos(int id, int slice_id, float x1, float x2, float y1,
1424 float y2, float z1, float z2, int dir)
1425{
1426 geovol *gvl;
1427 geovol_slice *slice;
1428 int cols, rows, depths;
1429
1430 gvl = gvl_get_vol(id);
1431
1432 if (!gvl)
1433 return (-1);
1434
1435 slice = gvl_slice_get_slice(id, slice_id);
1436
1437 if (!slice)
1438 return (-1);
1439
1440 if (dir == X) {
1441 cols = gvl->rows;
1442 rows = gvl->depths;
1443 depths = gvl->cols;
1444 }
1445 else if (dir == Y) {
1446 cols = gvl->cols;
1447 rows = gvl->depths;
1448 depths = gvl->rows;
1449 }
1450 else if (dir == Z) {
1451 cols = gvl->cols;
1452 rows = gvl->rows;
1453 depths = gvl->depths;
1454 }
1455 else {
1456 return (-1);
1457 }
1458
1459 slice->x1 = ((x1 < 0.) ? 0. : ((x1 > 1.) ? 1. : x1)) * (cols - 1);
1460 slice->x2 = ((x2 < 0.) ? 0. : ((x2 > 1.) ? 1. : x2)) * (cols - 1);
1461 slice->y1 = ((y1 < 0.) ? 0. : ((y1 > 1.) ? 1. : y1)) * (rows - 1);
1462 slice->y2 = ((y2 < 0.) ? 0. : ((y2 > 1.) ? 1. : y2)) * (rows - 1);
1463 slice->z1 = ((z1 < 0.) ? 0. : ((z1 > 1.) ? 1. : z1)) * (depths - 1);
1464 slice->z2 = ((z2 < 0.) ? 0. : ((z2 > 1.) ? 1. : z2)) * (depths - 1);
1465
1466 slice->dir = dir;
1467
1468 slice->changed = 1;
1469
1470 return (1);
1471}
1472
1473/*!
1474 \brief Get slice trans ?
1475
1476 \param id volume set id
1477 \param slice_id slice id
1478 \param[out] transp transp value
1479
1480 \return -1 on error
1481 \return 1 on success
1482 */
1483int GVL_slice_get_transp(int id, int slice_id, int *transp)
1484{
1485 geovol_slice *slice;
1486
1487 G_debug(3, "GVL_get_transp");
1488
1489 slice = gvl_slice_get_slice(id, slice_id);
1490
1491 if (!slice)
1492 return (-1);
1493
1494 *transp = slice->transp;
1495
1496 return (1);
1497}
1498
1499/*!
1500 \brief Set slice trans ?
1501
1502 \param id volume set id
1503 \param slice_id slice id
1504 \param transp transp value
1505
1506 \return -1 on error
1507 \return 1 on success
1508 */
1509int GVL_slice_set_transp(int id, int slice_id, int transp)
1510{
1511 geovol_slice *slice;
1512
1513 G_debug(3, "GVL_set_transp");
1514
1515 slice = gvl_slice_get_slice(id, slice_id);
1516
1517 if (!slice)
1518 return (-1);
1519
1520 slice->transp = transp;
1521
1522 return (1);
1523}
void G_free(void *buf)
Free allocated memory.
Definition alloc.c:150
#define NULL
Definition ccmath.h:32
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition debug.c:66
double b
double t
void G_message(const char *msg,...)
Print a message to stderr.
Definition gis/error.c:89
void GS_set_focus(float *realto)
Set focus.
Definition gs2.c:2517
int GVL_slice_get_drawmode(int id, int *mode)
Get slice draw mode.
Definition gvl2.c:1145
int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
Unset isosurface attributes.
Definition gvl2.c:849
int GVL_isosurf_get_flags(int id, int isosurf_id, int *inout)
Get isosurface flags.
Definition gvl2.c:951
int GVL_isosurf_num_isosurfs(int id)
Get number of available isosurfaces.
Definition gvl2.c:1002
int GVL_slice_get_pos(int id, int slice_id, float *x1, float *x2, float *y1, float *y2, float *z1, float *z2, int *dir)
Get slice position.
Definition gvl2.c:1363
void GVL_draw_wire(int id)
Draw volume in wire mode.
Definition gvl2.c:423
int GVL_slice_set_pos(int id, int slice_id, float x1, float x2, float y1, float y2, float z1, float z2, int dir)
Get slice position.
Definition gvl2.c:1423
int GVL_slice_move_down(int id, int slice_id)
Move down slice.
Definition gvl2.c:1303
int GVL_isosurf_get_att(int id, int isosurf_id, int att, int *set, float *constant, char *mapname)
Get isosurface attributes.
Definition gvl2.c:809
int GVL_slice_num_slices(int id)
Get number or slices.
Definition gvl2.c:1336
int GVL_load_vol(int id, const char *filename)
Load 3d raster map to volume set.
Definition gvl2.c:256
void GVL_isosurf_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution for isosurface.
Definition gvl2.c:549
int GVL_slice_set_transp(int id, int slice_id, int transp)
Set slice trans ?
Definition gvl2.c:1509
int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
Set constant isosurface attribute.
Definition gvl2.c:884
int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
Set slice draw resolution.
Definition gvl2.c:1108
int GVL_isosurf_set_drawmode(int id, int mode)
Set isosurface draw mode.
Definition gvl2.c:636
void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution of slice.
Definition gvl2.c:1082
int GVL_get_volname(int id, char *filename)
Get volume set name.
Definition gvl2.c:286
int GVL_isosurf_set_flags(int id, int isosurf_id, int inout)
Set isosurface flags.
Definition gvl2.c:977
int GVL_slice_move_up(int id, int slice_id)
Move up slice.
Definition gvl2.c:1269
int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
Set isosurface draw resolution.
Definition gvl2.c:575
void * GVL_get_window(void)
Get window.
Definition gvl2.c:98
int GVL_isosurf_set_maskmode(int id, int isosurf_id, int mode)
Set mask attribute mode.
Definition gvl2.c:1029
int GVL_delete_vol(int id)
Delete volume set from list.
Definition gvl2.c:210
int GVL_num_vols(void)
Get number of loaded volume sets.
Definition gvl2.c:166
int GVL_slice_get_transp(int id, int slice_id, int *transp)
Get slice trans ?
Definition gvl2.c:1483
int GVL_isosurf_del(int id, int isosurf_id)
Delete isosurface.
Definition gvl2.c:698
void GVL_alldraw_vol(void)
Draw all volume sets.
Definition gvl2.c:441
int GVL_isosurf_move_up(int id, int isosurf_id)
Move up isosurface in list.
Definition gvl2.c:737
void GVL_alldraw_wire(void)
Draw all volume sets in wire mode.
Definition gvl2.c:455
int GVL_isosurf_add(int id)
Add isosurface.
Definition gvl2.c:661
void GVL_init_region(void)
Initialize 3D region.
Definition gvl2.c:57
int * GVL_get_vol_list(int *numvols)
Get list of loaded volume sets.
Definition gvl2.c:181
int GVL_slice_set_drawmode(int id, int mode)
Set slice draw mode.
Definition gvl2.c:1169
void GVL_libinit(void)
Library initialization for volumes.
Definition gvl2.c:37
void * GVL_Get_ClientData(int id)
Get client data.
Definition gvl2.c:498
int GVL_Set_ClientData(int id, void *clientd)
Set client data for volume set.
Definition gvl2.c:475
void GVL_set_focus_center_map(int id)
Set focus on map center.
Definition gvl2.c:516
int GVL_slice_add(int id)
Add slice.
Definition gvl2.c:1194
void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition gvl2.c:333
int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
Definition gvl2.c:359
int GVL_slice_del(int id, int slice_id)
Delete slice.
Definition gvl2.c:1230
int GVL_isosurf_move_down(int id, int isosurf_id)
Move down isosurface in list.
Definition gvl2.c:771
int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode)
Get isosurface mask mode.
Definition gvl2.c:1056
void GVL_set_draw_wire(int id, int draw_wire)
Set drawing wire box.
Definition gvl2.c:382
int GVL_get_region(float *n, float *s, float *w, float *e, float *t, float *b)
Get region extent settings.
Definition gvl2.c:79
int GVL_isosurf_set_att_map(int id, int isosurf_id, int att, const char *filename)
Set isosurface map attribute.
Definition gvl2.c:922
int GVL_vol_exists(int id)
Check if volume set exists.
Definition gvl2.c:111
void GVL_get_dims(int id, int *rows, int *cols, int *depths)
Get volume dimensions.
Definition gvl2.c:309
int GVL_new_vol(void)
Create new volume set.
Definition gvl2.c:136
int GVL_isosurf_get_drawmode(int id, int *mode)
Get isosurface draw mode.
Definition gvl2.c:612
void GVL_draw_vol(int vid)
Draw volume set.
Definition gvl2.c:402
geovol * gvl_get_new_vol(void)
Allocate new volume set and add it to the list.
Definition gvl.c:148
int gvl_isosurf_init(geovol_isosurf *isosurf)
Initialize geovol_isosurf struct.
Definition gvl.c:520
int gvl_init_vol(geovol *gvl, double ox, double oy, double oz, int rows, int cols, int depths, double xres, double yres, double zres)
Initialize geovol structure.
Definition gvl.c:187
int gvl_isosurf_set_att_map(geovol_isosurf *isosurf, int desc, const char *filename)
Set attribute map.
Definition gvl.c:690
int gvl_slice_freemem(geovol_slice *slice)
Free geovol_slice struct.
Definition gvl.c:782
geovol * gvl_get_vol(int id)
Get volume set structure.
Definition gvl.c:40
int gvl_isosurf_get_att_src(geovol_isosurf *isosurf, int desc)
Get attribute source.
Definition gvl.c:607
int gvl_isosurf_freemem(geovol_isosurf *isosurf)
Free geovol_isosurf struct.
Definition gvl.c:553
geovol_slice * gvl_slice_get_slice(int id, int slice_id)
Get geovol_slice struct.
Definition gvl.c:803
geovol_isosurf * gvl_isosurf_get_isosurf(int id, int isosurf_id)
Get isosurface of given volume set.
Definition gvl.c:580
int gvl_isosurf_set_att_src(geovol_isosurf *isosurf, int desc, int src)
Set attribute source.
Definition gvl.c:632
int gvl_isosurf_set_att_changed(geovol_isosurf *isosurf, int desc)
Set attribute changed.
Definition gvl.c:723
int gvl_isosurf_set_att_const(geovol_isosurf *isosurf, int desc, float constant)
Set isosurface attribute constant.
Definition gvl.c:665
int gvl_slice_init(geovol_slice *slice)
Initialize geovol_slice struct.
Definition gvl.c:756
void gvl_delete_vol(int id)
Remove volume set from list.
Definition gvl.c:244
int gvl_num_vols(void)
Get number of loaded volume sets.
Definition gvl.c:105
int gvl_file_newh(const char *name, IFLAG file_type)
Get handle for given file name and type.
Definition gvl_file.c:269
char * gvl_file_get_name(int id)
Get file name for given handle.
Definition gvl_file.c:165
int gvld_wind3_box(geovol *gvl)
Draw volume bounding box.
Definition gvld.c:774
int gvld_wire_vol(geovol *gvl)
Draw volume in wire mode (bounding box)
Definition gvld.c:69
int gvld_vol(geovol *gvl)
Draw volume set (slices and isosurfaces)
Definition gvld.c:38
#define X(j)
#define Y(j)