19 #include <grass/gis.h>
20 #include <grass/G3d.h>
21 #include <grass/gstypes.h>
22 #include <grass/glocale.h>
25 static int Vol_ID[MAX_VOLS];
26 static int Next_vol = 0;
28 static G3D_Region wind3;
29 static double Region[6];
41 Region[0] = wind3.north;
42 Region[1] = wind3.south;
43 Region[2] = wind3.west;
44 Region[3] = wind3.east;
45 Region[4] = wind3.top;
46 Region[5] = wind3.bottom;
101 for (i = 0; i < Next_vol && !found; i++) {
102 if (Vol_ID[i] ==
id) {
122 if (Next_vol < MAX_VOLS) {
126 wind3.south + wind3.ns_res / 2., wind3.bottom,
127 wind3.rows, wind3.cols, wind3.depths,
128 wind3.ew_res, wind3.ns_res, wind3.tb_res);
130 Vol_ID[Next_vol] = nvl->gvol_id;
133 G_debug(3,
" id=%d", nvl->gvol_id);
135 return (nvl->gvol_id);
168 ret = (
int *)G_malloc(Next_vol *
sizeof(
int));
172 for (i = 0; i < Next_vol; i++) {
208 for (i = 0; i < Next_vol && !found; i++) {
209 if (Vol_ID[i] ==
id) {
211 for (j = i; j < Next_vol; j++) {
212 Vol_ID[j] = Vol_ID[j + 1];
241 G_debug(3,
"GVL_load_vol(): id=%d, name=%s",
248 G_message(_(
"Loading 3d raster map <%s>..."), filename);
275 if (0 > gvl->hfile) {
299 *depths = gvl->depths;
301 G_debug(3,
"GVL_get_dims() id=%d, rows=%d, cols=%d, depths=%d",
302 gvl->gvol_id, gvl->rows, gvl->cols, gvl->depths);
323 gvl->x_trans = xtrans;
324 gvl->y_trans = ytrans;
325 gvl->z_trans = ztrans;
347 *xtrans = gvl->x_trans;
348 *ytrans = gvl->y_trans;
349 *ztrans = gvl->z_trans;
384 G_debug(3,
"GVL_draw_wire(): id=%d",
id);
402 for (
id = 0;
id < Next_vol;
id++) {
416 for (
id = 0;
id < Next_vol;
id++) {
439 gvl->clientdata = clientd;
462 return (gvl->clientdata);
478 G_debug(3,
"GS_set_focus_center_map");
483 center[
X] = (gvl->xmax - gvl->xmin) / 2.;
484 center[
Y] = (gvl->ymax - gvl->ymin) / 2.;
485 center[Z] = (gvl->zmax - gvl->zmin) / 2.;
510 G_debug(3,
"GVL_isosurf_get_drawres");
515 *xres = gvl->isosurf_x_mod;
516 *yres = gvl->isosurf_y_mod;
517 *zres = gvl->isosurf_z_mod;
537 G_debug(3,
"GVL_isosurf_set_drawres(): id=%d",
id);
539 if (xres < 1 || yres < 1 || zres < 1) {
546 gvl->isosurf_x_mod = xres;
547 gvl->isosurf_y_mod = yres;
548 gvl->isosurf_z_mod = zres;
550 for (i = 0; i < gvl->n_isosurfs; i++) {
576 *mode = gvl->isosurf_draw_mode;
597 G_debug(3,
"GVL_isosurf_set_drawmode(): id=%d mode=%d",
id, mode);
602 gvl->isosurf_draw_mode =
mode;
621 geovol_isosurf *isosurf;
623 G_debug(3,
"GVL_isosurf_add() id=%d",
id);
630 if (gvl->n_isosurfs == MAX_ISOSURFS)
633 isosurf = (geovol_isosurf *) G_malloc(
sizeof(geovol_isosurf));
641 gvl->isosurf[gvl->n_isosurfs - 1] = (geovol_isosurf *) isosurf;
658 geovol_isosurf *isosurf;
674 G_free(gvl->isosurf[isosurf_id]);
676 for (i = isosurf_id + 1; i < gvl->n_isosurfs; i++) {
677 gvl->isosurf[i - 1] = gvl->isosurf[i];
699 G_debug(3,
"GVL_isosurf_move_up");
706 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
712 tmp = gvl->isosurf[isosurf_id - 1];
713 gvl->isosurf[isosurf_id - 1] = gvl->isosurf[isosurf_id];
714 gvl->isosurf[isosurf_id] = tmp;
733 G_debug(3,
"GVL_isosurf_move_up");
740 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
743 if (isosurf_id == (gvl->n_isosurfs - 1))
746 tmp = gvl->isosurf[isosurf_id + 1];
747 gvl->isosurf[isosurf_id + 1] = gvl->isosurf[isosurf_id];
748 gvl->isosurf[isosurf_id] = tmp;
767 int att,
int *
set,
float *constant,
char *mapname)
770 geovol_isosurf *isosurf;
772 G_debug(3,
"GVL_isosurf_get_att");
780 if (src == CONST_ATT) {
781 *constant = isosurf->att[att].constant;
783 else if (src == MAP_ATT) {
808 geovol_isosurf *isosurf;
810 G_debug(3,
"GVL_isosurf_unset_att");
843 geovol_isosurf *isosurf;
845 G_debug(3,
"GVL_isosurf_set_att_const() id=%d isosurf_id=%d "
846 "att=%d const=%f",
id, isosurf_id, att, constant);
878 const char *filename)
880 geovol_isosurf *isosurf;
882 G_debug(3,
"GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d "
883 "att=%d map=%s",
id, isosurf_id, att, filename);
906 geovol_isosurf *isosurf;
908 G_debug(3,
"GVL_isosurf_get_flags");
913 *inout = isosurf->inout_mode;
932 geovol_isosurf *isosurf;
934 G_debug(3,
"GVL_isosurf_get_flags");
939 isosurf->inout_mode = inout;
959 G_debug(3,
"GVL_isosurf_num_isosurfs");
964 return gvl->n_isosurfs;
984 geovol_isosurf *isosurf;
986 G_debug(3,
"GVL_isosurf_set_att_const");
991 isosurf->att[ATT_MASK].constant =
mode;
1011 geovol_isosurf *isosurf;
1016 *mode = isosurf->att[ATT_MASK].constant;
1039 G_debug(3,
"GVL_slice_get_drawres");
1044 *xres = gvl->slice_x_mod;
1045 *yres = gvl->slice_y_mod;
1046 *zres = gvl->slice_z_mod;
1066 G_debug(3,
"GVL_slice_set_drawres(): id=%d",
id);
1068 if (xres < 1 || yres < 1 || zres < 1) {
1075 gvl->slice_x_mod = xres;
1076 gvl->slice_y_mod = yres;
1077 gvl->slice_z_mod = zres;
1079 for (i = 0; i < gvl->n_slices; i++) {
1080 gvl->slice[i]->changed = 1;
1105 *mode = gvl->slice_draw_mode;
1126 G_debug(3,
"GVL_slice_set_drawmode(): id=%d, mode=%d",
id, mode);
1131 gvl->slice_draw_mode =
mode;
1150 geovol_slice *slice;
1159 if (gvl->n_slices == MAX_SLICES)
1162 if (
NULL == (slice = (geovol_slice *) G_malloc(
sizeof(geovol_slice)))) {
1169 gvl->slice[gvl->n_slices - 1] = (geovol_slice *) slice;
1186 geovol_slice *slice;
1202 G_free(gvl->slice[slice_id]);
1204 for (i = slice_id + 1; i < gvl->n_slices; i++) {
1205 gvl->slice[i - 1] = gvl->slice[i];
1227 G_debug(3,
"GVL_slice_move_up");
1234 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1240 tmp = gvl->slice[slice_id - 1];
1241 gvl->slice[slice_id - 1] = gvl->slice[slice_id];
1242 gvl->slice[slice_id] = tmp;
1261 G_debug(3,
"GVL_slice_move_up");
1268 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1271 if (slice_id == (gvl->n_slices - 1))
1274 tmp = gvl->slice[slice_id + 1];
1275 gvl->slice[slice_id + 1] = gvl->slice[slice_id];
1276 gvl->slice[slice_id] = tmp;
1293 G_debug(3,
"GVL_isosurf_num_isosurfs");
1298 return gvl->n_slices;
1317 float *x1,
float *x2,
float *y1,
float *y2,
float *z1,
1318 float *z2,
int *dir)
1321 geovol_slice *slice;
1322 int cols, rows, depths;
1334 if (slice->dir ==
X) {
1339 else if (slice->dir ==
Y) {
1344 else if (slice->dir == Z) {
1347 depths = gvl->depths;
1353 *x1 = slice->x1 / (cols - 1);
1354 *x2 = slice->x2 / (cols - 1);
1355 *y1 = slice->y1 / (rows - 1);
1356 *y2 = slice->y2 / (rows - 1);
1357 *z1 = slice->z1 / (depths - 1);
1358 *z2 = slice->z2 / (depths - 1);
1378 float x1,
float x2,
float y1,
float y2,
float z1,
1382 geovol_slice *slice;
1383 int cols, rows, depths;
1400 else if (dir ==
Y) {
1405 else if (dir == Z) {
1408 depths = gvl->depths;
1414 slice->x1 = ((x1 < 0.) ? 0. : ((x1 > 1.) ? 1. : x1)) * (cols - 1);
1415 slice->x2 = ((x2 < 0.) ? 0. : ((x2 > 1.) ? 1. : x2)) * (cols - 1);
1416 slice->y1 = ((y1 < 0.) ? 0. : ((y1 > 1.) ? 1. : y1)) * (rows - 1);
1417 slice->y2 = ((y2 < 0.) ? 0. : ((y2 > 1.) ? 1. : y2)) * (rows - 1);
1418 slice->z1 = ((z1 < 0.) ? 0. : ((z1 > 1.) ? 1. : z1)) * (depths - 1);
1419 slice->z2 = ((z2 < 0.) ? 0. : ((z2 > 1.) ? 1. : z2)) * (depths - 1);
1440 geovol_slice *slice;
1449 *transp = slice->transp;
1466 geovol_slice *slice;
1475 slice->transp = transp;
int GVL_slice_move_down(int id, int slice_id)
Move down slice.
int GVL_slice_get_transp(int id, int slice_id, int *transp)
Get slice trans ?
int GVL_isosurf_move_up(int id, int isosurf_id)
Move up isosurface in list.
void G_free(void *buf)
Free allocated memory.
int GVL_delete_vol(int id)
Delete volume set from list.
int GVL_new_vol(void)
Create new volume set.
int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans)
Get trans ?
int GVL_slice_move_up(int id, int slice_id)
Move up slice.
void * GVL_Get_ClientData(int id)
Get client data.
int gvl_num_vols(void)
Get number of loaded volume sets.
int GVL_slice_del(int id, int slice_id)
Delete slice.
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.
void GVL_get_dims(int id, int *rows, int *cols, int *depths)
Get volume dimensions.
int GVL_isosurf_num_isosurfs(int id)
Get number of available isosurfaces.
int gvl_isosurf_set_att_map(geovol_isosurf *isosurf, int desc, const char *filename)
Set attribute map.
int GVL_num_vols(void)
Get number of loaded volume sets.
char * gvl_file_get_name(int id)
Get file name for given handle.
char * G_strcpy(char *T, const char *F)
Copies characters from the string F into the string T.
void GVL_draw_wire(int id)
Draw volume in wire mode.
void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution of slice.
void GVL_alldraw_wire(void)
Draw all volume sets in wire mode.
void G3d_getWindow(G3D_Region *window)
Stores the current default window in window.
int gvl_isosurf_set_att_src(geovol_isosurf *isosurf, int desc, int src)
Set attribute source.
geovol * gvl_get_new_vol(void)
Allocate new volume set and add it to the list.
int GVL_Set_ClientData(int id, void *clientd)
Set client data for volume set.
void GVL_draw_vol(int vid)
Draw volume set.
void GVL_libinit(void)
Library intialization for volumes.
int GVL_load_vol(int id, const char *filename)
Load 3d raster map to volume set.
int GVL_isosurf_get_drawmode(int id, int *mode)
Get isosurface draw mode.
int GVL_isosurf_set_drawmode(int id, int mode)
Set isosurface draw mode.
int gvl_slice_init(geovol_slice *slice)
Initialize geovol_slice struct.
int gvl_isosurf_get_att_src(geovol_isosurf *isosurf, int desc)
Get attribute source.
void G_message(const char *msg,...)
Print a message to stderr.
int GVL_isosurf_get_att(int id, int isosurf_id, int att, int *set, float *constant, char *mapname)
Get isosurface attributes.
int gvl_file_newh(const char *name, IFLAG file_type)
Get handle for given file name and type.
void GVL_alldraw_vol(void)
Draw all volume sets.
int GVL_slice_add(int id)
Add slice.
int GVL_slice_set_drawmode(int id, int mode)
Set slice draw mode.
int gvl_isosurf_set_att_changed(geovol_isosurf *isosurf, int desc)
Set attribute changed.
int GVL_get_region(float *n, float *s, float *w, float *e, float *t, float *b)
Get region extent settings.
int gvld_wire_vol(geovol *gvl)
Draw volume in wire mode (bounding box)
void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans)
Set trans ?
void GVL_set_focus_center_map(int id)
Set focus on map center.
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.
void GVL_isosurf_get_drawres(int id, int *xres, int *yres, int *zres)
Get draw resolution for isosurface.
geovol * gvl_get_vol(int id)
Get volume set structure.
geovol_slice * gvl_slice_get_slice(int id, int slice_id)
Get geovol_slice struct.
int GVL_isosurf_get_flags(int id, int isosurf_id, int *inout)
Get isosurface flags.
int gvl_slice_freemem(geovol_slice *slice)
Free geovol_slice struct.
int GVL_slice_num_slices(int id)
Get number or slices.
int gvl_isosurf_init(geovol_isosurf *isosurf)
Initialize geovol_isosurf struct.
int GVL_slice_set_transp(int id, int slice_id, int transp)
Set slice trans ?
geovol_isosurf * gvl_isosurf_get_isosurf(int id, int isosurf_id)
Get isosurface of given volume set.
int gvl_isosurf_set_att_const(geovol_isosurf *isosurf, int desc, float constant)
Set isosurface attribute constant.
void G3d_initDefaults(void)
Initializes the default values described in G3D Defaults. Applications have to use this function only...
int gvl_isosurf_freemem(geovol_isosurf *isosurf)
Free geovol_isosurf struct.
int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode)
Get isosurface mask mode.
int G_debug(int level, const char *msg,...)
Print debugging message.
void * GVL_get_window()
Get window.
int GVL_isosurf_set_att_map(int id, int isosurf_id, int att, const char *filename)
Set isosurface map attribute.
int gvld_vol(geovol *gvl)
Draw volume set (slices and isosurfaces)
int * GVL_get_vol_list(int *numvols)
Get list of loaded volume sets.
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.
int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres)
Set isosurface draw resolution.
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_isosurf_set_flags(int id, int isosurf_id, int inout)
Set isosurface flags.
int GVL_isosurf_move_down(int id, int isosurf_id)
Move down isosurface in list.
int GVL_vol_exists(int id)
Check if volume set exists.
int GVL_isosurf_set_maskmode(int id, int isosurf_id, int mode)
Set mask attribute mode.
int GVL_get_volname(int id, char *filename)
Get volume set name.
int GVL_isosurf_add(int id)
Add isosurface.
void gvl_delete_vol(int id)
Remove volume set from list.
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_del(int id, int isosurf_id)
Delete isosurface.