GRASS 8 Programmer's Manual 8.6.0dev(2026)-5f4f7ad06c
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{
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) {
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 */
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 G_debug(3, "GVL_get_dims() id=%d, rows=%d, cols=%d, depths=%d",
321 gvl->gvol_id, gvl->rows, gvl->cols, gvl->depths);
322 }
323 else {
324 G_debug(2,
325 "GVL_get_dims(): Attempted to access a null volume structure "
326 "for id=%d",
327 id);
328 }
329
330 return;
331}
332
333/*!
334 \brief Set trans ?
335
336 \param id volume set id
337 \param xtrans,ytrans,ztrans x/y/z trans values
338 */
339void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
340{
341 geovol *gvl;
342
343 G_debug(3, "GVL_set_trans");
344
345 gvl = gvl_get_vol(id);
346
347 if (gvl) {
348 gvl->x_trans = xtrans;
349 gvl->y_trans = ytrans;
350 gvl->z_trans = ztrans;
351 }
352
353 return;
354}
355
356/*!
357 \brief Get trans ?
358
359 \param id volume set id
360 \param[out] xtrans,ytrans,ztrans x/y/z trans values
361
362 \return 1 on success
363 \return -1 on error
364 */
365int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
366{
367 geovol *gvl;
368
369 gvl = gvl_get_vol(id);
370
371 if (gvl) {
372 *xtrans = gvl->x_trans;
373 *ytrans = gvl->y_trans;
374 *ztrans = gvl->z_trans;
375
376 return (1);
377 }
378
379 return (-1);
380}
381
382/*!
383 \brief Set drawing wire box
384
385 \param id volume set id
386 \param draw_wire 1 for drawing wire, 0 otherwise
387 */
388void GVL_set_draw_wire(int id, int draw_wire)
389{
390 geovol *gvl;
391
392 G_debug(3, "GVL_set_draw_wire");
393
394 gvl = gvl_get_vol(id);
395
396 if (gvl) {
397 gvl->draw_wire = draw_wire;
398 }
399
400 return;
401}
402
403/*!
404 \brief Draw volume set
405
406 \param vid volume set id
407 */
409{
410 geovol *gvl;
411
413
414 if (gvl) {
415 gvld_vol(gvl);
416 if (gvl->draw_wire) {
418 }
419 }
420
421 return;
422}
423
424/*!
425 \brief Draw volume in wire mode
426
427 \param id volume set id
428 */
429void GVL_draw_wire(int id)
430{
431 geovol *gvl;
432
433 G_debug(3, "GVL_draw_wire(): id=%d", id);
434
435 gvl = gvl_get_vol(id);
436
437 if (gvl) {
439 }
440
441 return;
442}
443
444/*!
445 \brief Draw all volume sets
446 */
448{
449 int id;
450
451 for (id = 0; id < Next_vol; id++) {
452 GVL_draw_vol(Vol_ID[id]);
453 }
454
455 return;
456}
457
458/*!
459 \brief Draw all volume sets in wire mode
460 */
462{
463 int id;
464
465 for (id = 0; id < Next_vol; id++) {
466 GVL_draw_wire(Vol_ID[id]);
467 }
468
469 return;
470}
471
472/*!
473 \brief Set client data for volume set
474
475 \param id volume set id
476 \param clientd pointer to client data
477
478 \return 1 on success
479 \return -1 on error
480 */
481int GVL_Set_ClientData(int id, void *clientd)
482{
483 geovol *gvl;
484
485 gvl = gvl_get_vol(id);
486
487 if (gvl) {
488 gvl->clientdata = clientd;
489
490 return (1);
491 }
492
493 return (-1);
494}
495
496/*!
497 \brief Get client data
498
499 \param id volume set id
500
501 \return pointer to client data
502 \return NULL on error
503 */
505{
506 geovol *gvl;
507
508 gvl = gvl_get_vol(id);
509
510 if (gvl) {
511 return (gvl->clientdata);
512 }
513
514 return (NULL);
515}
516
517/*!
518 \brief Set focus on map center
519
520 \param id volume set id
521 */
523{
524 float center[3];
525 geovol *gvl;
526
527 G_debug(3, "GS_set_focus_center_map");
528
529 gvl = gvl_get_vol(id);
530
531 if (gvl) {
532 center[X] = (gvl->xmax - gvl->xmin) / 2.;
533 center[Y] = (gvl->ymax - gvl->ymin) / 2.;
534 center[Z] = (gvl->zmax - gvl->zmin) / 2.;
535
537 }
538
539 return;
540}
541
542/************************************************************************/
543/* ISOSURFACES */
544
545/************************************************************************/
546
547/*!
548 \brief Get draw resolution for isosurface
549
550 \todo error handling
551
552 \param id volume set id
553 \param[out] xres,yres,zres x/y/z resolution value
554 */
555void GVL_isosurf_get_drawres(int id, int *xres, int *yres, int *zres)
556{
557 geovol *gvl;
558
559 G_debug(3, "GVL_isosurf_get_drawres");
560
561 gvl = gvl_get_vol(id);
562
563 if (gvl) {
564 *xres = gvl->isosurf_x_mod;
565 *yres = gvl->isosurf_y_mod;
566 *zres = gvl->isosurf_z_mod;
567 }
568
569 return;
570}
571
572/*!
573 \brief Set isosurface draw resolution
574
575 \param id volume set id
576 \param xres,yres,zres x/y/z resolution value
577
578 \return -1 on error (invalid values/volume set id)
579 \return 0 on success
580 */
581int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
582{
583 geovol *gvl;
584 int i;
585
586 G_debug(3, "GVL_isosurf_set_drawres(): id=%d", id);
587
588 if (xres < 1 || yres < 1 || zres < 1) {
589 return (-1);
590 }
591
592 gvl = gvl_get_vol(id);
593
594 if (gvl) {
595 gvl->isosurf_x_mod = xres;
596 gvl->isosurf_y_mod = yres;
597 gvl->isosurf_z_mod = zres;
598
599 for (i = 0; i < gvl->n_isosurfs; i++) {
601 }
602
603 return (0);
604 }
605
606 return (-1);
607}
608
609/*!
610 \brief Get isosurface draw mode
611
612 \param id volume set id
613 \param[out] mode draw-mode
614
615 \return 1 on success
616 \return -1 on error
617 */
618int GVL_isosurf_get_drawmode(int id, int *mode)
619{
620 geovol *gvl;
621
622 gvl = gvl_get_vol(id);
623
624 if (gvl) {
625 *mode = gvl->isosurf_draw_mode;
626
627 return (1);
628 }
629
630 return (-1);
631}
632
633/*!
634 \brief Set isosurface draw mode
635
636 \param id volume set id
637 \param mode draw mode
638
639 \return 0 on success
640 \return -1 on error (invalid volume set id)
641 */
642int GVL_isosurf_set_drawmode(int id, int mode)
643{
644 geovol *gvl;
645
646 G_debug(3, "GVL_isosurf_set_drawmode(): id=%d mode=%d", id, mode);
647
648 gvl = gvl_get_vol(id);
649
650 if (gvl) {
651 gvl->isosurf_draw_mode = mode;
652
653 return (0);
654 }
655
656 return (-1);
657}
658
659/*!
660 \brief Add isosurface
661
662 \param id volume set id
663
664 \return -1 on error (invalid volume set id
665 \return 1 on success
666 */
668{
669 geovol *gvl;
670 geovol_isosurf *isosurf;
671
672 G_debug(3, "GVL_isosurf_add() id=%d", id);
673
674 gvl = gvl_get_vol(id);
675
676 if (!gvl)
677 return (-1);
678
679 if (gvl->n_isosurfs == MAX_ISOSURFS)
680 return (-1);
681
682 isosurf = (geovol_isosurf *)G_malloc(sizeof(geovol_isosurf));
683 if (!isosurf) {
684 return (-1);
685 }
686
687 gvl_isosurf_init(isosurf);
688
689 gvl->n_isosurfs++;
690 gvl->isosurf[gvl->n_isosurfs - 1] = (geovol_isosurf *)isosurf;
691
692 return (1);
693}
694
695/*!
696 \brief Delete isosurface
697
698 \param id volume set id
699 \param isosurf_id isosurface id
700
701 \return -1 on error
702 \return 1 on success
703 */
705{
706 geovol *gvl;
707 geovol_isosurf *isosurf;
708 int i;
709
710 G_debug(3, "GVL_isosurf_del");
711
712 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
713
714 if (!isosurf)
715 return (-1);
716
717 if (!gvl_isosurf_freemem(isosurf)) {
718 return (-1);
719 }
720
721 gvl = gvl_get_vol(id);
722
723 G_free(gvl->isosurf[isosurf_id]);
724
725 for (i = isosurf_id + 1; i < gvl->n_isosurfs; i++) {
726 gvl->isosurf[i - 1] = gvl->isosurf[i];
727 }
728
729 gvl->n_isosurfs--;
730
731 return (1);
732}
733
734/*!
735 \brief Move up isosurface in list
736
737 \param id volume set id
738 \param isosurf_id isosurface id
739
740 \return -1 on error
741 \return 1 on success
742 */
744{
745 geovol *gvl;
746 geovol_isosurf *tmp;
747
748 G_debug(3, "GVL_isosurf_move_up");
749
750 gvl = gvl_get_vol(id);
751
752 if (!gvl)
753 return (-1);
754
755 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
756 return (-1);
757
758 if (isosurf_id == 0)
759 return (1);
760
761 tmp = gvl->isosurf[isosurf_id - 1];
762 gvl->isosurf[isosurf_id - 1] = gvl->isosurf[isosurf_id];
763 gvl->isosurf[isosurf_id] = tmp;
764
765 return (1);
766}
767
768/*!
769 \brief Move down isosurface in list
770
771 \param id volume set id
772 \param isosurf_id isosurface id
773
774 \return -1 on error
775 \return 1 on success
776 */
778{
779 geovol *gvl;
780 geovol_isosurf *tmp;
781
782 G_debug(3, "GVL_isosurf_move_up");
783
784 gvl = gvl_get_vol(id);
785
786 if (!gvl)
787 return (-1);
788
789 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
790 return (-1);
791
792 if (isosurf_id == (gvl->n_isosurfs - 1))
793 return (1);
794
795 tmp = gvl->isosurf[isosurf_id + 1];
796 gvl->isosurf[isosurf_id + 1] = gvl->isosurf[isosurf_id];
797 gvl->isosurf[isosurf_id] = tmp;
798
799 return (1);
800}
801
802/*!
803 \brief Get isosurface attributes
804
805 \param id volume set id
806 \param isosurf_id surface id
807 \param att attribute id
808 \param[out] set
809 \param[out] constant
810 \param[out] mapname
811
812 \return -1 on error
813 \return 1 on success
814 */
815int GVL_isosurf_get_att(int id, int isosurf_id, int att, int *set,
816 float *constant, char *mapname)
817{
818 int src;
819 geovol_isosurf *isosurf;
820
821 G_debug(3, "GVL_isosurf_get_att");
822
823 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
824
825 if (isosurf) {
826 if (-1 != (src = gvl_isosurf_get_att_src(isosurf, att))) {
827 *set = src;
828
829 if (src == CONST_ATT) {
830 *constant = isosurf->att[att].constant;
831 }
832 else if (src == MAP_ATT) {
833 strcpy(mapname, gvl_file_get_name(isosurf->att[att].hfile));
834 }
835
836 return (1);
837 }
838
839 return (-1);
840 }
841
842 return (-1);
843}
844
845/*!
846 \brief Unset isosurface attributes
847
848 \param id volume set id
849 \param isosurf_id isosurface id
850 \param att attribute id
851
852 \return ?
853 \return -1 on error
854 */
855int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
856{
857 geovol_isosurf *isosurf;
858
859 G_debug(3, "GVL_isosurf_unset_att");
860
861 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
862
863 if (isosurf) {
864 return (gvl_isosurf_set_att_src(isosurf, att, NOTSET_ATT));
865 }
866
867 return (-1);
868}
869
870/*!
871 \brief Set constant isosurface attribute
872
873 Attributes:
874 - ATT_NORM
875 - ATT_TOPO topography (level) constant
876 - ATT_COLOR color map/constant
877 - ATT_MASK mask map
878 - ATT_TRANSP transparency map/constant
879 - ATT_SHINE shininess map/constant
880 - ATT_EMIT emission map/constant
881
882 \param id volume set id
883 \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
884 \param att attribute descriptor
885 \param constant constant value
886
887 \return 1 on success
888 \return -1 on error
889 */
890int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
891{
892 geovol_isosurf *isosurf;
893
894 G_debug(3,
895 "GVL_isosurf_set_att_const() id=%d isosurf_id=%d "
896 "att=%d const=%f",
897 id, isosurf_id, att, constant);
898
899 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
900
901 if (isosurf) {
902 return (gvl_isosurf_set_att_const(isosurf, att, constant));
903 }
904
905 return (-1);
906}
907
908/*!
909 \brief Set isosurface map attribute
910
911 Attributes:
912 - ATT_NORM
913 - ATT_TOPO topography (level) constant
914 - ATT_COLOR color map/constant
915 - ATT_MASK mask map
916 - ATT_TRANSP transparency map/constant
917 - ATT_SHINE shininess map/constant
918 - ATT_EMIT emission map/constant
919
920 \param id volume set id
921 \param isosurf_id isosurface id (0 - MAX_ISOSURFS)
922 \param att attribute descriptor
923 \param filename map name
924
925 \return 1 on success
926 \return -1 on error
927 */
928int GVL_isosurf_set_att_map(int id, int isosurf_id, int att,
929 const char *filename)
930{
931 geovol_isosurf *isosurf;
932
933 G_debug(3,
934 "GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d "
935 "att=%d map=%s",
936 id, isosurf_id, att, filename);
937
938 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
939
940 if (isosurf) {
941 return gvl_isosurf_set_att_map(isosurf, att, filename);
942 }
943
944 return (-1);
945}
946
947/*!
948 \brief Get isosurface flags
949
950 \param id volume set id
951 \param isosurf_id isosurface id
952 \param[out] inout map name
953
954 \return 1 on success
955 \return -1 on error
956 */
958{
959 geovol_isosurf *isosurf;
960
961 G_debug(3, "GVL_isosurf_get_flags");
962
963 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
964
965 if (isosurf) {
966 *inout = isosurf->inout_mode;
967
968 return (1);
969 }
970 return (-1);
971}
972
973/*!
974 \brief Set isosurface flags
975
976 \param id volume set id
977 \param isosurf_id isosurface id
978 \param inout map name
979
980 \return 1 on success
981 \return -1 on error
982 */
984{
985 geovol_isosurf *isosurf;
986
987 G_debug(3, "GVL_isosurf_get_flags");
988
989 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
990
991 if (isosurf) {
992 isosurf->inout_mode = inout;
993
994 return (1);
995 }
996
997 return (-1);
998}
999
1000/*!
1001 \brief Get number of available isosurfaces
1002
1003 \param id volume set id
1004
1005 \return number of isosurfaces
1006 \return -1 on error
1007 */
1009{
1010 geovol *gvl;
1011
1012 G_debug(3, "GVL_isosurf_num_isosurfs");
1013
1014 gvl = gvl_get_vol(id);
1015
1016 if (gvl) {
1017 return gvl->n_isosurfs;
1018 }
1019
1020 return (-1);
1021}
1022
1023/*!
1024 \brief Set mask attribute mode
1025
1026 Mask attribute special: constant is set to indicate invert or no
1027
1028 \param id volume set id
1029 \param isosurf_id isosurface id
1030 \param mode attribute mode
1031
1032 \return mode id
1033 \return -1 on error
1034 */
1035int GVL_isosurf_set_maskmode(int id, int isosurf_id, int mode)
1036{
1037 geovol_isosurf *isosurf;
1038
1039 G_debug(3, "GVL_isosurf_set_att_const");
1040
1041 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
1042
1043 if (isosurf) {
1044 isosurf->att[ATT_MASK].constant = mode;
1045
1046 return (mode);
1047 }
1048
1049 return (-1);
1050}
1051
1052/*!
1053 \brief Get isosurface mask mode
1054
1055 \param id volume set id
1056 \param isosurf_id isosurface id
1057 \param mode attribute mode
1058
1059 \return 1 on success
1060 \return -1 on error
1061 */
1062int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode)
1063{
1064 geovol_isosurf *isosurf;
1065
1066 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id);
1067
1068 if (isosurf) {
1069 *mode = isosurf->att[ATT_MASK].constant;
1070
1071 return (1);
1072 }
1073
1074 return (-1);
1075}
1076
1077/************************************************************************/
1078/* SLICES */
1079
1080/************************************************************************/
1081
1082/*!
1083 \brief Get draw resolution of slice
1084
1085 \param id volume set id
1086 \param[out] xres,yres,zres x/y/z resolution value
1087 */
1088void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres)
1089{
1090 geovol *gvl;
1091
1092 G_debug(3, "GVL_slice_get_drawres");
1093
1094 gvl = gvl_get_vol(id);
1095
1096 if (gvl) {
1097 *xres = gvl->slice_x_mod;
1098 *yres = gvl->slice_y_mod;
1099 *zres = gvl->slice_z_mod;
1100 }
1101
1102 return;
1103}
1104
1105/*!
1106 \brief Set slice draw resolution
1107
1108 \param id volume set id
1109 \param xres,yres,zres x/y/z resolution value
1110
1111 \return 0 on success
1112 \return -1 on error (invalid value or id)
1113 */
1114int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
1115{
1116 geovol *gvl;
1117 int i;
1118
1119 G_debug(3, "GVL_slice_set_drawres(): id=%d", id);
1120
1121 if (xres < 1 || yres < 1 || zres < 1) {
1122 return (-1);
1123 }
1124
1125 gvl = gvl_get_vol(id);
1126
1127 if (gvl) {
1128 gvl->slice_x_mod = xres;
1129 gvl->slice_y_mod = yres;
1130 gvl->slice_z_mod = zres;
1131
1132 for (i = 0; i < gvl->n_slices; i++) {
1133 gvl->slice[i]->changed = 1;
1134 }
1135
1136 return (0);
1137 }
1138
1139 return (-1);
1140}
1141
1142/*!
1143 \brief Get slice draw mode
1144
1145 \param id volume set id
1146 \param[out] mode draw mode
1147
1148 \return 1 on success
1149 \return -1 on error (invalid id)
1150 */
1151int GVL_slice_get_drawmode(int id, int *mode)
1152{
1153 geovol *gvl;
1154
1155 gvl = gvl_get_vol(id);
1156
1157 if (gvl) {
1158 *mode = gvl->slice_draw_mode;
1159
1160 return (1);
1161 }
1162
1163 return (-1);
1164}
1165
1166/*!
1167 \brief Set slice draw mode
1168
1169 \param id volume set id
1170 \param mode draw mode
1171
1172 \return 0 on success
1173 \return -1 on error (invalid id)
1174 */
1175int GVL_slice_set_drawmode(int id, int mode)
1176{
1177 geovol *gvl;
1178
1179 G_debug(3, "GVL_slice_set_drawmode(): id=%d, mode=%d", id, mode);
1180
1181 gvl = gvl_get_vol(id);
1182
1183 if (gvl) {
1184 gvl->slice_draw_mode = mode;
1185
1186 return (0);
1187 }
1188
1189 return (-1);
1190}
1191
1192/*!
1193 \brief Add slice
1194
1195 \param id volume set id
1196
1197 \return -1 on error
1198 \return 1 on success
1199 */
1200int GVL_slice_add(int id)
1201{
1202 geovol *gvl;
1203 geovol_slice *slice;
1204
1205 G_debug(3, "GVL_slice_add");
1206
1207 gvl = gvl_get_vol(id);
1208
1209 if (!gvl)
1210 return (-1);
1211
1212 if (gvl->n_slices == MAX_SLICES)
1213 return (-1);
1214
1215 if (NULL == (slice = (geovol_slice *)G_malloc(sizeof(geovol_slice)))) {
1216 return (-1);
1217 }
1218
1219 gvl_slice_init(slice);
1220
1221 gvl->n_slices++;
1222 gvl->slice[gvl->n_slices - 1] = (geovol_slice *)slice;
1223
1224 return (1);
1225}
1226
1227/*!
1228 \brief Delete slice
1229
1230 \param id volume set id
1231 \param slice_id slice id
1232
1233 \return -1 on error
1234 \return 1 on success
1235 */
1236int GVL_slice_del(int id, int slice_id)
1237{
1238 geovol *gvl;
1239 geovol_slice *slice;
1240 int i;
1241
1242 G_debug(3, "GVL_slice_del");
1243
1244 slice = gvl_slice_get_slice(id, slice_id);
1245
1246 if (!slice)
1247 return (-1);
1248
1249 if (!gvl_slice_freemem(slice)) {
1250 return (-1);
1251 }
1252
1253 gvl = gvl_get_vol(id);
1254
1255 G_free(gvl->slice[slice_id]);
1256
1257 for (i = slice_id + 1; i < gvl->n_slices; i++) {
1258 gvl->slice[i - 1] = gvl->slice[i];
1259 }
1260
1261 gvl->n_slices--;
1262
1263 return (1);
1264}
1265
1266/*!
1267 \brief Move up slice
1268
1269 \param id volume set id
1270 \param slice_id slice id
1271
1272 \return -1 on error
1273 \return 1 on success
1274 */
1276{
1277 geovol *gvl;
1278 geovol_slice *tmp;
1279
1280 G_debug(3, "GVL_slice_move_up");
1281
1282 gvl = gvl_get_vol(id);
1283
1284 if (!gvl)
1285 return (-1);
1286
1287 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1288 return (-1);
1289
1290 if (slice_id == 0)
1291 return (1);
1292
1293 tmp = gvl->slice[slice_id - 1];
1294 gvl->slice[slice_id - 1] = gvl->slice[slice_id];
1295 gvl->slice[slice_id] = tmp;
1296
1297 return (1);
1298}
1299
1300/*!
1301 \brief Move down slice
1302
1303 \param id volume set id
1304 \param slice_id slice id
1305
1306 \return -1 on error
1307 \return 1 on success
1308 */
1310{
1311 geovol *gvl;
1312 geovol_slice *tmp;
1313
1314 G_debug(3, "GVL_slice_move_up");
1315
1316 gvl = gvl_get_vol(id);
1317
1318 if (!gvl)
1319 return (-1);
1320
1321 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1322 return (-1);
1323
1324 if (slice_id == (gvl->n_slices - 1))
1325 return (1);
1326
1327 tmp = gvl->slice[slice_id + 1];
1328 gvl->slice[slice_id + 1] = gvl->slice[slice_id];
1329 gvl->slice[slice_id] = tmp;
1330
1331 return (1);
1332}
1333
1334/*!
1335 \brief Get number or slices
1336
1337 \param id volume set id
1338
1339 \return number of slices
1340 \return -1 on error
1341 */
1343{
1344 geovol *gvl;
1345
1346 G_debug(3, "GVL_isosurf_num_isosurfs");
1347
1348 gvl = gvl_get_vol(id);
1349
1350 if (gvl) {
1351 return gvl->n_slices;
1352 }
1353
1354 return (-1);
1355}
1356
1357/*!
1358 \brief Get slice position
1359
1360 \param id volume set id
1361 \param slice_id slice id
1362 \param[out] x1,y1,z1 coordinates ?
1363 \param[out] x2,y2,z2 coordinates ?
1364 \param[out] dir direction
1365
1366 \return -1 on error
1367 \return 1 on success
1368 */
1369int GVL_slice_get_pos(int id, int slice_id, float *x1, float *x2, float *y1,
1370 float *y2, float *z1, float *z2, int *dir)
1371{
1372 geovol *gvl;
1373 geovol_slice *slice;
1374 int cols, rows, depths;
1375
1376 gvl = gvl_get_vol(id);
1377
1378 if (!gvl)
1379 return (-1);
1380
1381 slice = gvl_slice_get_slice(id, slice_id);
1382
1383 if (!slice)
1384 return (-1);
1385
1386 if (slice->dir == X) {
1387 cols = gvl->rows;
1388 rows = gvl->depths;
1389 depths = gvl->cols;
1390 }
1391 else if (slice->dir == Y) {
1392 cols = gvl->cols;
1393 rows = gvl->depths;
1394 depths = gvl->rows;
1395 }
1396 else if (slice->dir == Z) {
1397 cols = gvl->cols;
1398 rows = gvl->rows;
1399 depths = gvl->depths;
1400 }
1401 else {
1402 return (-1);
1403 }
1404
1405 *x1 = slice->x1 / (cols - 1);
1406 *x2 = slice->x2 / (cols - 1);
1407 *y1 = slice->y1 / (rows - 1);
1408 *y2 = slice->y2 / (rows - 1);
1409 *z1 = slice->z1 / (depths - 1);
1410 *z2 = slice->z2 / (depths - 1);
1411
1412 *dir = slice->dir;
1413
1414 return (1);
1415}
1416
1417/*!
1418 \brief Get slice position
1419
1420 \param id volume set id
1421 \param slice_id slice id
1422 \param x1,y1,z1 coordinates ?
1423 \param x2,y2,z2 coordinates ?
1424 \param dir direction
1425
1426 \return -1 on error
1427 \return 1 on success
1428 */
1429int GVL_slice_set_pos(int id, int slice_id, float x1, float x2, float y1,
1430 float y2, float z1, float z2, int dir)
1431{
1432 geovol *gvl;
1433 geovol_slice *slice;
1434 int cols, rows, depths;
1435
1436 gvl = gvl_get_vol(id);
1437
1438 if (!gvl)
1439 return (-1);
1440
1441 slice = gvl_slice_get_slice(id, slice_id);
1442
1443 if (!slice)
1444 return (-1);
1445
1446 if (dir == X) {
1447 cols = gvl->rows;
1448 rows = gvl->depths;
1449 depths = gvl->cols;
1450 }
1451 else if (dir == Y) {
1452 cols = gvl->cols;
1453 rows = gvl->depths;
1454 depths = gvl->rows;
1455 }
1456 else if (dir == Z) {
1457 cols = gvl->cols;
1458 rows = gvl->rows;
1459 depths = gvl->depths;
1460 }
1461 else {
1462 return (-1);
1463 }
1464
1465 slice->x1 = ((x1 < 0.) ? 0. : ((x1 > 1.) ? 1. : x1)) * (cols - 1);
1466 slice->x2 = ((x2 < 0.) ? 0. : ((x2 > 1.) ? 1. : x2)) * (cols - 1);
1467 slice->y1 = ((y1 < 0.) ? 0. : ((y1 > 1.) ? 1. : y1)) * (rows - 1);
1468 slice->y2 = ((y2 < 0.) ? 0. : ((y2 > 1.) ? 1. : y2)) * (rows - 1);
1469 slice->z1 = ((z1 < 0.) ? 0. : ((z1 > 1.) ? 1. : z1)) * (depths - 1);
1470 slice->z2 = ((z2 < 0.) ? 0. : ((z2 > 1.) ? 1. : z2)) * (depths - 1);
1471
1472 slice->dir = dir;
1473
1474 slice->changed = 1;
1475
1476 return (1);
1477}
1478
1479/*!
1480 \brief Get slice trans ?
1481
1482 \param id volume set id
1483 \param slice_id slice id
1484 \param[out] transp transp value
1485
1486 \return -1 on error
1487 \return 1 on success
1488 */
1489int GVL_slice_get_transp(int id, int slice_id, int *transp)
1490{
1491 geovol_slice *slice;
1492
1493 G_debug(3, "GVL_get_transp");
1494
1495 slice = gvl_slice_get_slice(id, slice_id);
1496
1497 if (!slice)
1498 return (-1);
1499
1500 *transp = slice->transp;
1501
1502 return (1);
1503}
1504
1505/*!
1506 \brief Set slice trans ?
1507
1508 \param id volume set id
1509 \param slice_id slice id
1510 \param transp transp value
1511
1512 \return -1 on error
1513 \return 1 on success
1514 */
1515int GVL_slice_set_transp(int id, int slice_id, int transp)
1516{
1517 geovol_slice *slice;
1518
1519 G_debug(3, "GVL_set_transp");
1520
1521 slice = gvl_slice_get_slice(id, slice_id);
1522
1523 if (!slice)
1524 return (-1);
1525
1526 slice->transp = transp;
1527
1528 return (1);
1529}
#define NULL
Definition ccmath.h:32
void G_free(void *)
Free allocated memory.
Definition gis/alloc.c:147
#define G_malloc(n)
Definition defs/gis.h:139
void G_message(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int gvl_file_newh(const char *, IFLAG)
int gvl_slice_freemem(geovol_slice *)
Free geovol_slice struct.
Definition gvl.c:782
geovol * gvl_get_new_vol(void)
Allocate new volume set and add it to the list.
Definition gvl.c:148
geovol * gvl_get_vol(int)
Get volume set structure.
Definition gvl.c:40
int gvl_isosurf_set_att_map(geovol_isosurf *, int, const char *)
Set attribute map.
Definition gvl.c:690
int gvl_slice_init(geovol_slice *)
Initialize geovol_slice struct.
Definition gvl.c:756
int gvld_vol(geovol *)
Draw volume set (slices and isosurfaces)
Definition gvld.c:38
geovol_isosurf * gvl_isosurf_get_isosurf(int, int)
Get isosurface of given volume set.
Definition gvl.c:580
int gvl_isosurf_set_att_changed(geovol_isosurf *, int)
Set attribute changed.
Definition gvl.c:723
int gvl_isosurf_init(geovol_isosurf *)
Initialize geovol_isosurf struct.
Definition gvl.c:520
int gvl_isosurf_set_att_const(geovol_isosurf *, int, float)
Set isosurface attribute constant.
Definition gvl.c:665
void GS_set_focus(float *)
Set focus.
Definition gs2.c:2520
int gvl_isosurf_set_att_src(geovol_isosurf *, int, int)
Set attribute source.
Definition gvl.c:632
int gvl_isosurf_freemem(geovol_isosurf *)
Free geovol_isosurf struct.
Definition gvl.c:553
int gvld_wire_vol(geovol *)
Draw volume in wire mode (bounding box)
Definition gvld.c:69
geovol_slice * gvl_slice_get_slice(int, int)
Get geovol_slice struct.
Definition gvl.c:803
int gvld_wind3_box(geovol *)
Draw volume bounding box.
Definition gvld.c:787
int gvl_isosurf_get_att_src(geovol_isosurf *, int)
Get attribute source.
Definition gvl.c:607
void gvl_delete_vol(int)
Remove volume set from list.
Definition gvl.c:244
int gvl_init_vol(geovol *, double, double, double, int, int, int, double, double, double)
Initialize geovol structure.
Definition gvl.c:187
char * gvl_file_get_name(int)
Get file name for given handle.
Definition gvl_file.c:165
int gvl_num_vols(void)
Get number of loaded volume sets.
Definition gvl.c:105
int Rast3d_read_window(RASTER3D_Region *, const char *)
Reads window from the file specified by windowName. The name is converted by the rules defined in win...
Definition windowio.c:132
void Rast3d_init_defaults(void)
Initializes the default values described in RASTER3D Defaults. Applications have to use this function...
Definition defaults.c:282
void Rast3d_get_window(RASTER3D_Region *)
Stores the current default window in window.
#define _(str)
Definition glocale.h:10
int GVL_slice_get_drawmode(int id, int *mode)
Get slice draw mode.
Definition gvl2.c:1151
int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
Unset isosurface attributes.
Definition gvl2.c:855
int GVL_isosurf_get_flags(int id, int isosurf_id, int *inout)
Get isosurface flags.
Definition gvl2.c:957
int GVL_isosurf_num_isosurfs(int id)
Get number of available isosurfaces.
Definition gvl2.c:1008
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:1369
void GVL_draw_wire(int id)
Draw volume in wire mode.
Definition gvl2.c:429
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:1429
int GVL_slice_move_down(int id, int slice_id)
Move down slice.
Definition gvl2.c:1309
int GVL_isosurf_get_att(int id, int isosurf_id, int att, int *set, float *constant, char *mapname)
Get isosurface attributes.
Definition gvl2.c:815
int GVL_slice_num_slices(int id)
Get number or slices.
Definition gvl2.c:1342
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:555
int GVL_slice_set_transp(int id, int slice_id, int transp)
Set slice trans ?
Definition gvl2.c:1515
int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
Set constant isosurface attribute.
Definition gvl2.c:890
int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
Set slice draw resolution.
Definition gvl2.c:1114
int GVL_isosurf_set_drawmode(int id, int mode)
Set isosurface draw mode.
Definition gvl2.c:642
void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution of slice.
Definition gvl2.c:1088
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:983
int GVL_slice_move_up(int id, int slice_id)
Move up slice.
Definition gvl2.c:1275
int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
Set isosurface draw resolution.
Definition gvl2.c:581
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:1035
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:1489
int GVL_isosurf_del(int id, int isosurf_id)
Delete isosurface.
Definition gvl2.c:704
void GVL_alldraw_vol(void)
Draw all volume sets.
Definition gvl2.c:447
int GVL_isosurf_move_up(int id, int isosurf_id)
Move up isosurface in list.
Definition gvl2.c:743
void GVL_alldraw_wire(void)
Draw all volume sets in wire mode.
Definition gvl2.c:461
int GVL_isosurf_add(int id)
Add isosurface.
Definition gvl2.c:667
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:1175
void GVL_libinit(void)
Library initialization for volumes.
Definition gvl2.c:37
void * GVL_Get_ClientData(int id)
Get client data.
Definition gvl2.c:504
int GVL_Set_ClientData(int id, void *clientd)
Set client data for volume set.
Definition gvl2.c:481
void GVL_set_focus_center_map(int id)
Set focus on map center.
Definition gvl2.c:522
int GVL_slice_add(int id)
Add slice.
Definition gvl2.c:1200
void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
Definition gvl2.c:339
int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
Definition gvl2.c:365
int GVL_slice_del(int id, int slice_id)
Delete slice.
Definition gvl2.c:1236
int GVL_isosurf_move_down(int id, int isosurf_id)
Move down isosurface in list.
Definition gvl2.c:777
int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode)
Get isosurface mask mode.
Definition gvl2.c:1062
void GVL_set_draw_wire(int id, int draw_wire)
Set drawing wire box.
Definition gvl2.c:388
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:928
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:618
void GVL_draw_vol(int vid)
Draw volume set.
Definition gvl2.c:408
OGSF header file (structures)
#define NOTSET_ATT
Definition ogsf.h:84
#define ATT_MASK
Definition ogsf.h:77
#define X
Definition ogsf.h:140
#define MAX_ISOSURFS
Definition ogsf.h:48
#define ATT_TOPO
Definition ogsf.h:75
#define Z
Definition ogsf.h:142
#define Y
Definition ogsf.h:141
#define MAP_ATT
Definition ogsf.h:85
#define MAX_VOLS
Definition ogsf.h:43
#define VOL_FTYPE_RASTER3D
Definition ogsf.h:131
#define CONST_ATT
Definition ogsf.h:86
#define MAX_SLICES
Definition ogsf.h:49
#define strcpy
Definition parson.c:66
double b
Definition r_raster.c:39
double t
Definition r_raster.c:39
Definition ogsf.h:500
geovol_isosurf_att att[7]
Definition ogsf.h:485
int inout_mode
Definition ogsf.h:484
float z1
Definition ogsf.h:493
float x1
Definition ogsf.h:493
float z2
Definition ogsf.h:493
float y1
Definition ogsf.h:493
int changed
Definition ogsf.h:495
int dir
Definition ogsf.h:492
float x2
Definition ogsf.h:493
float y2
Definition ogsf.h:493
int transp
Definition ogsf.h:497