20 #include <grass/gis.h>
21 #include <grass/raster3d.h>
22 #include <grass/ogsf.h>
23 #include <grass/glocale.h>
26 static int Vol_ID[MAX_VOLS];
27 static int Next_vol = 0;
29 static RASTER3D_Region wind3;
30 static 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;
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);
325 "GVL_get_dims(): Attempted to access a null volume structure "
348 gvl->x_trans = xtrans;
349 gvl->y_trans = ytrans;
350 gvl->z_trans = ztrans;
372 *xtrans = gvl->x_trans;
373 *ytrans = gvl->y_trans;
374 *ztrans = gvl->z_trans;
392 G_debug(3,
"GVL_set_draw_wire");
397 gvl->draw_wire = draw_wire;
416 if (gvl->draw_wire) {
433 G_debug(3,
"GVL_draw_wire(): id=%d",
id);
451 for (
id = 0;
id < Next_vol;
id++) {
465 for (
id = 0;
id < Next_vol;
id++) {
488 gvl->clientdata = clientd;
511 return (gvl->clientdata);
527 G_debug(3,
"GS_set_focus_center_map");
532 center[
X] = (gvl->xmax - gvl->xmin) / 2.;
533 center[
Y] = (gvl->ymax - gvl->ymin) / 2.;
534 center[Z] = (gvl->zmax - gvl->zmin) / 2.;
559 G_debug(3,
"GVL_isosurf_get_drawres");
564 *xres = gvl->isosurf_x_mod;
565 *yres = gvl->isosurf_y_mod;
566 *zres = gvl->isosurf_z_mod;
586 G_debug(3,
"GVL_isosurf_set_drawres(): id=%d",
id);
588 if (xres < 1 || yres < 1 || zres < 1) {
595 gvl->isosurf_x_mod = xres;
596 gvl->isosurf_y_mod = yres;
597 gvl->isosurf_z_mod = zres;
599 for (i = 0; i < gvl->n_isosurfs; i++) {
625 *mode = gvl->isosurf_draw_mode;
646 G_debug(3,
"GVL_isosurf_set_drawmode(): id=%d mode=%d",
id, mode);
651 gvl->isosurf_draw_mode = mode;
670 geovol_isosurf *isosurf;
672 G_debug(3,
"GVL_isosurf_add() id=%d",
id);
679 if (gvl->n_isosurfs == MAX_ISOSURFS)
682 isosurf = (geovol_isosurf *)G_malloc(
sizeof(geovol_isosurf));
690 gvl->isosurf[gvl->n_isosurfs - 1] = (geovol_isosurf *)isosurf;
707 geovol_isosurf *isosurf;
723 G_free(gvl->isosurf[isosurf_id]);
725 for (i = isosurf_id + 1; i < gvl->n_isosurfs; i++) {
726 gvl->isosurf[i - 1] = gvl->isosurf[i];
748 G_debug(3,
"GVL_isosurf_move_up");
755 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
761 tmp = gvl->isosurf[isosurf_id - 1];
762 gvl->isosurf[isosurf_id - 1] = gvl->isosurf[isosurf_id];
763 gvl->isosurf[isosurf_id] = tmp;
782 G_debug(3,
"GVL_isosurf_move_up");
789 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1))
792 if (isosurf_id == (gvl->n_isosurfs - 1))
795 tmp = gvl->isosurf[isosurf_id + 1];
796 gvl->isosurf[isosurf_id + 1] = gvl->isosurf[isosurf_id];
797 gvl->isosurf[isosurf_id] = tmp;
816 float *constant,
char *mapname)
819 geovol_isosurf *isosurf;
821 G_debug(3,
"GVL_isosurf_get_att");
829 if (src == CONST_ATT) {
830 *constant = isosurf->att[att].constant;
832 else if (src == MAP_ATT) {
857 geovol_isosurf *isosurf;
859 G_debug(3,
"GVL_isosurf_unset_att");
892 geovol_isosurf *isosurf;
895 "GVL_isosurf_set_att_const() id=%d isosurf_id=%d "
897 id, isosurf_id, att, constant);
929 const char *filename)
931 geovol_isosurf *isosurf;
934 "GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d "
936 id, isosurf_id, att, filename);
959 geovol_isosurf *isosurf;
961 G_debug(3,
"GVL_isosurf_get_flags");
966 *inout = isosurf->inout_mode;
985 geovol_isosurf *isosurf;
987 G_debug(3,
"GVL_isosurf_get_flags");
992 isosurf->inout_mode = inout;
1012 G_debug(3,
"GVL_isosurf_num_isosurfs");
1017 return gvl->n_isosurfs;
1037 geovol_isosurf *isosurf;
1039 G_debug(3,
"GVL_isosurf_set_att_const");
1044 isosurf->att[ATT_MASK].constant = mode;
1064 geovol_isosurf *isosurf;
1069 *mode = isosurf->att[ATT_MASK].constant;
1092 G_debug(3,
"GVL_slice_get_drawres");
1097 *xres = gvl->slice_x_mod;
1098 *yres = gvl->slice_y_mod;
1099 *zres = gvl->slice_z_mod;
1119 G_debug(3,
"GVL_slice_set_drawres(): id=%d",
id);
1121 if (xres < 1 || yres < 1 || zres < 1) {
1128 gvl->slice_x_mod = xres;
1129 gvl->slice_y_mod = yres;
1130 gvl->slice_z_mod = zres;
1132 for (i = 0; i < gvl->n_slices; i++) {
1133 gvl->slice[i]->changed = 1;
1158 *mode = gvl->slice_draw_mode;
1179 G_debug(3,
"GVL_slice_set_drawmode(): id=%d, mode=%d",
id, mode);
1184 gvl->slice_draw_mode = mode;
1203 geovol_slice *slice;
1212 if (gvl->n_slices == MAX_SLICES)
1215 if (
NULL == (slice = (geovol_slice *)G_malloc(
sizeof(geovol_slice)))) {
1222 gvl->slice[gvl->n_slices - 1] = (geovol_slice *)slice;
1239 geovol_slice *slice;
1255 G_free(gvl->slice[slice_id]);
1257 for (i = slice_id + 1; i < gvl->n_slices; i++) {
1258 gvl->slice[i - 1] = gvl->slice[i];
1280 G_debug(3,
"GVL_slice_move_up");
1287 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1293 tmp = gvl->slice[slice_id - 1];
1294 gvl->slice[slice_id - 1] = gvl->slice[slice_id];
1295 gvl->slice[slice_id] = tmp;
1314 G_debug(3,
"GVL_slice_move_up");
1321 if (slice_id < 0 || slice_id > (gvl->n_slices - 1))
1324 if (slice_id == (gvl->n_slices - 1))
1327 tmp = gvl->slice[slice_id + 1];
1328 gvl->slice[slice_id + 1] = gvl->slice[slice_id];
1329 gvl->slice[slice_id] = tmp;
1346 G_debug(3,
"GVL_isosurf_num_isosurfs");
1351 return gvl->n_slices;
1370 float *y2,
float *z1,
float *z2,
int *dir)
1373 geovol_slice *slice;
1374 int cols, rows, depths;
1386 if (slice->dir ==
X) {
1391 else if (slice->dir ==
Y) {
1396 else if (slice->dir == Z) {
1399 depths = gvl->depths;
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);
1430 float y2,
float z1,
float z2,
int dir)
1433 geovol_slice *slice;
1434 int cols, rows, depths;
1451 else if (dir ==
Y) {
1456 else if (dir == Z) {
1459 depths = gvl->depths;
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);
1491 geovol_slice *slice;
1500 *transp = slice->transp;
1517 geovol_slice *slice;
1526 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 ?
void * GVL_get_window(void)
Get window.
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.
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_slice_set_drawmode(int id, int mode)
Set slice draw mode.
void GVL_libinit(void)
Library initialization for volumes.
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_get_vol_list(int *numvols)
Get list of loaded volume sets.
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_Get_ClientData(int id)
Get client data.
void GVL_draw_vol(int vid)
Draw volume set.
geovol_slice * gvl_slice_get_slice(int id, int slice_id)
Get geovol_slice struct.
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.
geovol_isosurf * gvl_isosurf_get_isosurf(int id, int isosurf_id)
Get isosurface of given volume set.
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.
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.
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.
geovol * gvl_get_vol(int id)
Get volume set structure.
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)