21#include <grass/raster3d.h>
22#include <grass/ogsf.h>
23#include <grass/glocale.h>
26static int Vol_ID[MAX_VOLS];
27static int Next_vol = 0;
29static RASTER3D_Region wind3;
30static double Region[6];
39 Rast3d_init_defaults();
40 Rast3d_get_window(&wind3);
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;
59 Rast3d_read_window(&wind3,
NULL);
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;
121 for (i = 0; i < Next_vol && !found; i++) {
122 if (Vol_ID[i] ==
id) {
142 if (Next_vol < MAX_VOLS) {
146 wind3.south + wind3.ns_res / 2., wind3.bottom, wind3.rows,
147 wind3.cols, wind3.depths, wind3.ew_res, wind3.ns_res,
150 Vol_ID[Next_vol] = nvl->gvol_id;
153 G_debug(3,
" id=%d", nvl->gvol_id);
155 return (nvl->gvol_id);
188 ret = (
int *)G_malloc(Next_vol *
sizeof(
int));
192 for (i = 0; i < Next_vol; i++) {
228 for (i = 0; i < Next_vol && !found; i++) {
229 if (Vol_ID[i] ==
id) {
231 for (j = i; j < Next_vol; j++) {
232 Vol_ID[j] = Vol_ID[j + 1];
261 G_debug(3,
"GVL_load_vol(): id=%d, name=%s",
id, filename);
267 G_message(_(
"Loading 3d raster map <%s>..."), filename);
269 if (0 > (handle =
gvl_file_newh(filename, VOL_FTYPE_RASTER3D)))
294 if (0 > gvl->hfile) {
318 *depths = gvl->depths;
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);
342 gvl->x_trans = xtrans;
343 gvl->y_trans = ytrans;
344 gvl->z_trans = ztrans;
366 *xtrans = gvl->x_trans;
367 *ytrans = gvl->y_trans;
368 *ztrans = gvl->z_trans;
386 G_debug(3,
"GVL_set_draw_wire");
391 gvl->draw_wire = draw_wire;
410 if (gvl->draw_wire) {
427 G_debug(3,
"GVL_draw_wire(): id=%d",
id);
445 for (
id = 0;
id < Next_vol;
id++) {
459 for (
id = 0;
id < Next_vol;
id++) {
482 gvl->clientdata = clientd;
505 return (gvl->clientdata);
521 G_debug(3,
"GS_set_focus_center_map");
526 center[
X] = (gvl->xmax - gvl->xmin) / 2.;
527 center[
Y] = (gvl->ymax - gvl->ymin) / 2.;
528 center[Z] = (gvl->zmax - gvl->zmin) / 2.;
553 G_debug(3,
"GVL_isosurf_get_drawres");
558 *xres = gvl->isosurf_x_mod;
559 *yres = gvl->isosurf_y_mod;
560 *zres = gvl->isosurf_z_mod;
580 G_debug(3,
"GVL_isosurf_set_drawres(): id=%d",
id);
582 if (xres < 1 || yres < 1 || zres < 1) {
589 gvl->isosurf_x_mod = xres;
590 gvl->isosurf_y_mod = yres;
591 gvl->isosurf_z_mod = zres;
593 for (i = 0; i < gvl->n_isosurfs; i++) {
619 *mode = gvl->isosurf_draw_mode;
640 G_debug(3,
"GVL_isosurf_set_drawmode(): id=%d mode=%d",
id, mode);
645 gvl->isosurf_draw_mode = mode;
664 geovol_isosurf *isosurf;
666 G_debug(3,
"GVL_isosurf_add() id=%d",
id);
673 if (gvl->n_isosurfs == MAX_ISOSURFS)
676 isosurf = (geovol_isosurf *)G_malloc(
sizeof(geovol_isosurf));
684 gvl->isosurf[gvl->n_isosurfs - 1] = (geovol_isosurf *)isosurf;
701 geovol_isosurf *isosurf;
717 G_free(gvl->isosurf[isosurf_id]);
719 for (i = isosurf_id + 1; i < gvl->n_isosurfs; i++) {
720 gvl->isosurf[i - 1] = gvl->isosurf[i];
742 G_debug(3,
"GVL_isosurf_move_up");
749 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
755 tmp = gvl->isosurf[isosurf_id - 1];
756 gvl->isosurf[isosurf_id - 1] = gvl->isosurf[isosurf_id];
757 gvl->isosurf[isosurf_id] = tmp;
776 G_debug(3,
"GVL_isosurf_move_up");
783 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
786 if (isosurf_id == (gvl->n_isosurfs - 1))
789 tmp = gvl->isosurf[isosurf_id + 1];
790 gvl->isosurf[isosurf_id + 1] = gvl->isosurf[isosurf_id];
791 gvl->isosurf[isosurf_id] = tmp;
810 float *constant,
char *mapname)
813 geovol_isosurf *isosurf;
815 G_debug(3,
"GVL_isosurf_get_att");
823 if (src == CONST_ATT) {
824 *constant = isosurf->att[att].constant;
826 else if (src == MAP_ATT) {
851 geovol_isosurf *isosurf;
853 G_debug(3,
"GVL_isosurf_unset_att");
886 geovol_isosurf *isosurf;
889 "GVL_isosurf_set_att_const() id=%d isosurf_id=%d "
891 id, isosurf_id, att, constant);
923 const char *filename)
925 geovol_isosurf *isosurf;
928 "GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d "
930 id, isosurf_id, att, filename);
953 geovol_isosurf *isosurf;
955 G_debug(3,
"GVL_isosurf_get_flags");
960 *inout = isosurf->inout_mode;
979 geovol_isosurf *isosurf;
981 G_debug(3,
"GVL_isosurf_get_flags");
986 isosurf->inout_mode = inout;
1006 G_debug(3,
"GVL_isosurf_num_isosurfs");
1011 return gvl->n_isosurfs;
1031 geovol_isosurf *isosurf;
1033 G_debug(3,
"GVL_isosurf_set_att_const");
1038 isosurf->att[ATT_MASK].constant = mode;
1058 geovol_isosurf *isosurf;
1063 *mode = isosurf->att[ATT_MASK].constant;
1086 G_debug(3,
"GVL_slice_get_drawres");
1091 *xres = gvl->slice_x_mod;
1092 *yres = gvl->slice_y_mod;
1093 *zres = gvl->slice_z_mod;
1113 G_debug(3,
"GVL_slice_set_drawres(): id=%d",
id);
1115 if (xres < 1 || yres < 1 || zres < 1) {
1122 gvl->slice_x_mod = xres;
1123 gvl->slice_y_mod = yres;
1124 gvl->slice_z_mod = zres;
1126 for (i = 0; i < gvl->n_slices; i++) {
1127 gvl->slice[i]->changed = 1;
1152 *mode = gvl->slice_draw_mode;
1173 G_debug(3,
"GVL_slice_set_drawmode(): id=%d, mode=%d",
id, mode);
1178 gvl->slice_draw_mode = mode;
1197 geovol_slice *slice;
1206 if (gvl->n_slices == MAX_SLICES)
1209 if (
NULL == (slice = (geovol_slice *)G_malloc(
sizeof(geovol_slice)))) {
1216 gvl->slice[gvl->n_slices - 1] = (geovol_slice *)slice;
1233 geovol_slice *slice;
1249 G_free(gvl->slice[slice_id]);
1251 for (i = slice_id + 1; i < gvl->n_slices; i++) {
1252 gvl->slice[i - 1] = gvl->slice[i];
1274 G_debug(3,
"GVL_slice_move_up");
1281 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1287 tmp = gvl->slice[slice_id - 1];
1288 gvl->slice[slice_id - 1] = gvl->slice[slice_id];
1289 gvl->slice[slice_id] = tmp;
1308 G_debug(3,
"GVL_slice_move_up");
1315 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1318 if (slice_id == (gvl->n_slices - 1))
1321 tmp = gvl->slice[slice_id + 1];
1322 gvl->slice[slice_id + 1] = gvl->slice[slice_id];
1323 gvl->slice[slice_id] = tmp;
1340 G_debug(3,
"GVL_isosurf_num_isosurfs");
1345 return gvl->n_slices;
1364 float *y2,
float *z1,
float *z2,
int *dir)
1367 geovol_slice *slice;
1368 int cols, rows, depths;
1380 if (slice->dir ==
X) {
1385 else if (slice->dir ==
Y) {
1390 else if (slice->dir == Z) {
1393 depths = gvl->depths;
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);
1424 float y2,
float z1,
float z2,
int dir)
1427 geovol_slice *slice;
1428 int cols, rows, depths;
1445 else if (dir ==
Y) {
1450 else if (dir == Z) {
1453 depths = gvl->depths;
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);
1485 geovol_slice *slice;
1494 *transp = slice->transp;
1511 geovol_slice *slice;
1520 slice->transp = transp;
void G_free(void *buf)
Free allocated memory.
int G_debug(int level, const char *msg,...)
Print debugging message.
void G_message(const char *msg,...)
Print a message to stderr.
void GS_set_focus(float *realto)
Set focus.
int GVL_slice_get_drawmode(int id, int *mode)
Get slice draw mode.
int GVL_isosurf_unset_att(int id, int isosurf_id, int att)
Unset isosurface attributes.
int GVL_isosurf_get_flags(int id, int isosurf_id, int *inout)
Get isosurface flags.
int GVL_isosurf_num_isosurfs(int id)
Get number of available isosurfaces.
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.
void GVL_draw_wire(int id)
Draw volume in wire mode.
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.
int GVL_slice_move_down(int id, int slice_id)
Move down slice.
int GVL_isosurf_get_att(int id, int isosurf_id, int att, int *set, float *constant, char *mapname)
Get isosurface attributes.
int GVL_slice_num_slices(int id)
Get number or slices.
int GVL_load_vol(int id, const char *filename)
Load 3d raster map to volume set.
void GVL_isosurf_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution for isosurface.
int GVL_slice_set_transp(int id, int slice_id, int transp)
Set slice trans ?
int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant)
Set constant isosurface attribute.
int GVL_slice_set_drawres(int id, int xres, int yres, int zres)
Set slice draw resolution.
int GVL_isosurf_set_drawmode(int id, int mode)
Set isosurface draw mode.
void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution of slice.
int GVL_get_volname(int id, char *filename)
Get volume set name.
int GVL_isosurf_set_flags(int id, int isosurf_id, int inout)
Set isosurface flags.
int GVL_slice_move_up(int id, int slice_id)
Move up slice.
int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
Set isosurface draw resolution.
void * GVL_get_window(void)
Get window.
int GVL_isosurf_set_maskmode(int id, int isosurf_id, int mode)
Set mask attribute mode.
int GVL_delete_vol(int id)
Delete volume set from list.
int GVL_num_vols(void)
Get number of loaded volume sets.
int GVL_slice_get_transp(int id, int slice_id, int *transp)
Get slice trans ?
int GVL_isosurf_del(int id, int isosurf_id)
Delete isosurface.
void GVL_alldraw_vol(void)
Draw all volume sets.
int GVL_isosurf_move_up(int id, int isosurf_id)
Move up isosurface in list.
void GVL_alldraw_wire(void)
Draw all volume sets in wire mode.
int GVL_isosurf_add(int id)
Add isosurface.
void GVL_init_region(void)
Initialize 3D region.
int * GVL_get_vol_list(int *numvols)
Get list of loaded volume sets.
int GVL_slice_set_drawmode(int id, int mode)
Set slice draw mode.
void GVL_libinit(void)
Library initialization for volumes.
void * GVL_Get_ClientData(int id)
Get client data.
int GVL_Set_ClientData(int id, void *clientd)
Set client data for volume set.
void GVL_set_focus_center_map(int id)
Set focus on map center.
int GVL_slice_add(int id)
Add slice.
void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
int GVL_slice_del(int id, int slice_id)
Delete slice.
int GVL_isosurf_move_down(int id, int isosurf_id)
Move down isosurface in list.
int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode)
Get isosurface mask mode.
void GVL_set_draw_wire(int id, int draw_wire)
Set drawing wire box.
int GVL_get_region(float *n, float *s, float *w, float *e, float *t, float *b)
Get region extent settings.
int GVL_isosurf_set_att_map(int id, int isosurf_id, int att, const char *filename)
Set isosurface map attribute.
int GVL_vol_exists(int id)
Check if volume set exists.
void GVL_get_dims(int id, int *rows, int *cols, int *depths)
Get volume dimensions.
int GVL_new_vol(void)
Create new volume set.
int GVL_isosurf_get_drawmode(int id, int *mode)
Get isosurface draw mode.
void GVL_draw_vol(int vid)
Draw volume set.
geovol * gvl_get_new_vol(void)
Allocate new volume set and add it to the list.
int gvl_isosurf_init(geovol_isosurf *isosurf)
Initialize geovol_isosurf struct.
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.
int gvl_isosurf_set_att_map(geovol_isosurf *isosurf, int desc, const char *filename)
Set attribute map.
int gvl_slice_freemem(geovol_slice *slice)
Free geovol_slice struct.
geovol * gvl_get_vol(int id)
Get volume set structure.
int gvl_isosurf_get_att_src(geovol_isosurf *isosurf, int desc)
Get attribute source.
int gvl_isosurf_freemem(geovol_isosurf *isosurf)
Free geovol_isosurf struct.
geovol_slice * gvl_slice_get_slice(int id, int slice_id)
Get geovol_slice struct.
geovol_isosurf * gvl_isosurf_get_isosurf(int id, int isosurf_id)
Get isosurface of given volume set.
int gvl_isosurf_set_att_src(geovol_isosurf *isosurf, int desc, int src)
Set attribute source.
int gvl_isosurf_set_att_changed(geovol_isosurf *isosurf, int desc)
Set attribute changed.
int gvl_isosurf_set_att_const(geovol_isosurf *isosurf, int desc, float constant)
Set isosurface attribute constant.
int gvl_slice_init(geovol_slice *slice)
Initialize geovol_slice struct.
void gvl_delete_vol(int id)
Remove volume set from list.
int gvl_num_vols(void)
Get number of loaded volume sets.
int gvl_file_newh(const char *name, IFLAG file_type)
Get handle for given file name and type.
char * gvl_file_get_name(int id)
Get file name for given handle.
int gvld_wind3_box(geovol *gvl)
Draw volume bounding box.
int gvld_wire_vol(geovol *gvl)
Draw volume in wire mode (bounding box)
int gvld_vol(geovol *gvl)
Draw volume set (slices and isosurfaces)