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