GRASS Programmer's Manual
6.4.2(2012)
|
00001 00019 #include <grass/gis.h> 00020 #include <grass/G3d.h> 00021 #include <grass/gstypes.h> 00022 #include <grass/glocale.h> 00023 #include "gsget.h" 00024 00025 static int Vol_ID[MAX_VOLS]; 00026 static int Next_vol = 0; 00027 00028 static G3D_Region wind3; 00029 static double Region[6]; 00030 00036 void GVL_libinit(void) 00037 { 00038 G3d_initDefaults(); 00039 G3d_getWindow(&wind3); 00040 00041 Region[0] = wind3.north; 00042 Region[1] = wind3.south; 00043 Region[2] = wind3.west; 00044 Region[3] = wind3.east; 00045 Region[4] = wind3.top; 00046 Region[5] = wind3.bottom; 00047 00048 return; 00049 } 00050 00059 int GVL_get_region(float *n, float *s, float *w, float *e, float *t, float *b) 00060 { 00061 *n = Region[0]; 00062 *s = Region[1]; 00063 *w = Region[2]; 00064 *e = Region[3]; 00065 *t = Region[4]; 00066 *b = Region[5]; 00067 00068 return (1); 00069 } 00070 00078 void *GVL_get_window() 00079 { 00080 return &wind3; 00081 } 00082 00091 int GVL_vol_exists(int id) 00092 { 00093 int i, found = 0; 00094 00095 G_debug(3, "GVL_vol_exists"); 00096 00097 if (NULL == gvl_get_vol(id)) { 00098 return (0); 00099 } 00100 00101 for (i = 0; i < Next_vol && !found; i++) { 00102 if (Vol_ID[i] == id) { 00103 found = 1; 00104 } 00105 } 00106 00107 return (found); 00108 } 00109 00116 int GVL_new_vol(void) 00117 { 00118 geovol *nvl; 00119 00120 G_debug(3, "GVL_new_vol():"); 00121 00122 if (Next_vol < MAX_VOLS) { 00123 nvl = gvl_get_new_vol(); 00124 00125 gvl_init_vol(nvl, wind3.west + wind3.ew_res / 2., 00126 wind3.south + wind3.ns_res / 2., wind3.bottom, 00127 wind3.rows, wind3.cols, wind3.depths, 00128 wind3.ew_res, wind3.ns_res, wind3.tb_res); 00129 00130 Vol_ID[Next_vol] = nvl->gvol_id; 00131 ++Next_vol; 00132 00133 G_debug(3, " id=%d", nvl->gvol_id); 00134 00135 return (nvl->gvol_id); 00136 } 00137 00138 return (-1); 00139 } 00140 00146 int GVL_num_vols(void) 00147 { 00148 return (gvl_num_vols()); 00149 } 00150 00161 int *GVL_get_vol_list(int *numvols) 00162 { 00163 int i, *ret; 00164 00165 *numvols = Next_vol; 00166 00167 if (Next_vol) { 00168 ret = (int *)G_malloc(Next_vol * sizeof(int)); 00169 if (!ret) 00170 return (NULL); 00171 00172 for (i = 0; i < Next_vol; i++) { 00173 ret[i] = Vol_ID[i]; 00174 } 00175 00176 return (ret); 00177 } 00178 00179 return (NULL); 00180 } 00181 00190 int GVL_delete_vol(int id) 00191 { 00192 int i, j, found = 0; 00193 00194 G_debug(3, "GVL_delete_vol"); 00195 00196 if (GVL_vol_exists(id)) { 00197 00198 for (i = 0; i < GVL_isosurf_num_isosurfs(id); i++) { 00199 GVL_isosurf_del(id, 0); 00200 } 00201 00202 for (i = 0; i < GVL_slice_num_slices(id); i++) { 00203 GVL_slice_del(id, 0); 00204 } 00205 00206 gvl_delete_vol(id); 00207 00208 for (i = 0; i < Next_vol && !found; i++) { 00209 if (Vol_ID[i] == id) { 00210 found = 1; 00211 for (j = i; j < Next_vol; j++) { 00212 Vol_ID[j] = Vol_ID[j + 1]; 00213 } 00214 } 00215 } 00216 00217 if (found) { 00218 --Next_vol; 00219 00220 return (1); 00221 } 00222 } 00223 00224 return (-1); 00225 } 00226 00236 int GVL_load_vol(int id, const char *filename) 00237 { 00238 geovol *gvl; 00239 int handle; 00240 00241 G_debug(3, "GVL_load_vol(): id=%d, name=%s", 00242 id, filename); 00243 00244 if (NULL == (gvl = gvl_get_vol(id))) { 00245 return (-1); 00246 } 00247 00248 G_message(_("Loading 3d raster map <%s>..."), filename); 00249 00250 if (0 > (handle = gvl_file_newh(filename, VOL_FTYPE_G3D))) 00251 return (-1); 00252 00253 gvl->hfile = handle; 00254 00255 return (0); 00256 } 00257 00267 int GVL_get_volname(int id, char *filename) 00268 { 00269 geovol *gvl; 00270 00271 if (NULL == (gvl = gvl_get_vol(id))) { 00272 return (-1); 00273 } 00274 00275 if (0 > gvl->hfile) { 00276 return (-1); 00277 } 00278 00279 G_strcpy(filename, gvl_file_get_name(gvl->hfile)); 00280 00281 return (1); 00282 } 00283 00290 void GVL_get_dims(int id, int *rows, int *cols, int *depths) 00291 { 00292 geovol *gvl; 00293 00294 gvl = gvl_get_vol(id); 00295 00296 if (gvl) { 00297 *rows = gvl->rows; 00298 *cols = gvl->cols; 00299 *depths = gvl->depths; 00300 00301 G_debug(3, "GVL_get_dims() id=%d, rows=%d, cols=%d, depths=%d", 00302 gvl->gvol_id, gvl->rows, gvl->cols, gvl->depths); 00303 } 00304 00305 return; 00306 } 00307 00314 void GVL_set_trans(int id, float xtrans, float ytrans, float ztrans) 00315 { 00316 geovol *gvl; 00317 00318 G_debug(3, "GVL_set_trans"); 00319 00320 gvl = gvl_get_vol(id); 00321 00322 if (gvl) { 00323 gvl->x_trans = xtrans; 00324 gvl->y_trans = ytrans; 00325 gvl->z_trans = ztrans; 00326 } 00327 00328 return; 00329 } 00330 00340 int GVL_get_trans(int id, float *xtrans, float *ytrans, float *ztrans) 00341 { 00342 geovol *gvl; 00343 00344 gvl = gvl_get_vol(id); 00345 00346 if (gvl) { 00347 *xtrans = gvl->x_trans; 00348 *ytrans = gvl->y_trans; 00349 *ztrans = gvl->z_trans; 00350 00351 return (1); 00352 } 00353 00354 return (-1); 00355 } 00356 00362 void GVL_draw_vol(int vid) 00363 { 00364 geovol *gvl; 00365 00366 gvl = gvl_get_vol(vid); 00367 00368 if (gvl) { 00369 gvld_vol(gvl); 00370 } 00371 00372 return; 00373 } 00374 00380 void GVL_draw_wire(int id) 00381 { 00382 geovol *gvl; 00383 00384 G_debug(3, "GVL_draw_wire(): id=%d", id); 00385 00386 gvl = gvl_get_vol(id); 00387 00388 if (gvl) { 00389 gvld_wire_vol(gvl); 00390 } 00391 00392 return; 00393 } 00394 00398 void GVL_alldraw_vol(void) 00399 { 00400 int id; 00401 00402 for (id = 0; id < Next_vol; id++) { 00403 GVL_draw_vol(Vol_ID[id]); 00404 } 00405 00406 return; 00407 } 00408 00412 void GVL_alldraw_wire(void) 00413 { 00414 int id; 00415 00416 for (id = 0; id < Next_vol; id++) { 00417 GVL_draw_wire(Vol_ID[id]); 00418 } 00419 00420 return; 00421 } 00422 00432 int GVL_Set_ClientData(int id, void *clientd) 00433 { 00434 geovol *gvl; 00435 00436 gvl = gvl_get_vol(id); 00437 00438 if (gvl) { 00439 gvl->clientdata = clientd; 00440 00441 return (1); 00442 } 00443 00444 return (-1); 00445 } 00446 00455 void *GVL_Get_ClientData(int id) 00456 { 00457 geovol *gvl; 00458 00459 gvl = gvl_get_vol(id); 00460 00461 if (gvl) { 00462 return (gvl->clientdata); 00463 } 00464 00465 return (NULL); 00466 } 00467 00473 void GVL_set_focus_center_map(int id) 00474 { 00475 float center[3]; 00476 geovol *gvl; 00477 00478 G_debug(3, "GS_set_focus_center_map"); 00479 00480 gvl = gvl_get_vol(id); 00481 00482 if (gvl) { 00483 center[X] = (gvl->xmax - gvl->xmin) / 2.; 00484 center[Y] = (gvl->ymax - gvl->ymin) / 2.; 00485 center[Z] = (gvl->zmax - gvl->zmin) / 2.; 00486 00487 GS_set_focus(center); 00488 } 00489 00490 return; 00491 } 00492 00493 /************************************************************************/ 00494 /* ISOSURFACES */ 00495 00496 /************************************************************************/ 00497 00506 void GVL_isosurf_get_drawres(int id, int *xres, int *yres, int *zres) 00507 { 00508 geovol *gvl; 00509 00510 G_debug(3, "GVL_isosurf_get_drawres"); 00511 00512 gvl = gvl_get_vol(id); 00513 00514 if (gvl) { 00515 *xres = gvl->isosurf_x_mod; 00516 *yres = gvl->isosurf_y_mod; 00517 *zres = gvl->isosurf_z_mod; 00518 } 00519 00520 return; 00521 } 00522 00532 int GVL_isosurf_set_drawres(int id, int xres, int yres, int zres) 00533 { 00534 geovol *gvl; 00535 int i; 00536 00537 G_debug(3, "GVL_isosurf_set_drawres(): id=%d", id); 00538 00539 if (xres < 1 || yres < 1 || zres < 1) { 00540 return (-1); 00541 } 00542 00543 gvl = gvl_get_vol(id); 00544 00545 if (gvl) { 00546 gvl->isosurf_x_mod = xres; 00547 gvl->isosurf_y_mod = yres; 00548 gvl->isosurf_z_mod = zres; 00549 00550 for (i = 0; i < gvl->n_isosurfs; i++) { 00551 gvl_isosurf_set_att_changed(gvl->isosurf[i], ATT_TOPO); 00552 } 00553 00554 return (0); 00555 } 00556 00557 return (-1); 00558 } 00559 00569 int GVL_isosurf_get_drawmode(int id, int *mode) 00570 { 00571 geovol *gvl; 00572 00573 gvl = gvl_get_vol(id); 00574 00575 if (gvl) { 00576 *mode = gvl->isosurf_draw_mode; 00577 00578 return (1); 00579 } 00580 00581 return (-1); 00582 } 00583 00593 int GVL_isosurf_set_drawmode(int id, int mode) 00594 { 00595 geovol *gvl; 00596 00597 G_debug(3, "GVL_isosurf_set_drawmode(): id=%d mode=%d", id, mode); 00598 00599 gvl = gvl_get_vol(id); 00600 00601 if (gvl) { 00602 gvl->isosurf_draw_mode = mode; 00603 00604 return (0); 00605 } 00606 00607 return (-1); 00608 } 00609 00618 int GVL_isosurf_add(int id) 00619 { 00620 geovol *gvl; 00621 geovol_isosurf *isosurf; 00622 00623 G_debug(3, "GVL_isosurf_add() id=%d", id); 00624 00625 gvl = gvl_get_vol(id); 00626 00627 if (!gvl) 00628 return (-1); 00629 00630 if (gvl->n_isosurfs == MAX_ISOSURFS) 00631 return (-1); 00632 00633 isosurf = (geovol_isosurf *) G_malloc(sizeof(geovol_isosurf)); 00634 if (!isosurf) { 00635 return (-1); 00636 } 00637 00638 gvl_isosurf_init(isosurf); 00639 00640 gvl->n_isosurfs++; 00641 gvl->isosurf[gvl->n_isosurfs - 1] = (geovol_isosurf *) isosurf; 00642 00643 return (1); 00644 } 00645 00655 int GVL_isosurf_del(int id, int isosurf_id) 00656 { 00657 geovol *gvl; 00658 geovol_isosurf *isosurf; 00659 int i; 00660 00661 G_debug(3, "GVL_isosurf_del"); 00662 00663 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00664 00665 if (!isosurf) 00666 return (-1); 00667 00668 if (!gvl_isosurf_freemem(isosurf)) { 00669 return (-1); 00670 } 00671 00672 gvl = gvl_get_vol(id); 00673 00674 G_free(gvl->isosurf[isosurf_id]); 00675 00676 for (i = isosurf_id + 1; i < gvl->n_isosurfs; i++) { 00677 gvl->isosurf[i - 1] = gvl->isosurf[i]; 00678 } 00679 00680 gvl->n_isosurfs--; 00681 00682 return (1); 00683 } 00684 00694 int GVL_isosurf_move_up(int id, int isosurf_id) 00695 { 00696 geovol *gvl; 00697 geovol_isosurf *tmp; 00698 00699 G_debug(3, "GVL_isosurf_move_up"); 00700 00701 gvl = gvl_get_vol(id); 00702 00703 if (!gvl) 00704 return (-1); 00705 00706 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1)) 00707 return (-1); 00708 00709 if (isosurf_id == 0) 00710 return (1); 00711 00712 tmp = gvl->isosurf[isosurf_id - 1]; 00713 gvl->isosurf[isosurf_id - 1] = gvl->isosurf[isosurf_id]; 00714 gvl->isosurf[isosurf_id] = tmp; 00715 00716 return (1); 00717 } 00718 00728 int GVL_isosurf_move_down(int id, int isosurf_id) 00729 { 00730 geovol *gvl; 00731 geovol_isosurf *tmp; 00732 00733 G_debug(3, "GVL_isosurf_move_up"); 00734 00735 gvl = gvl_get_vol(id); 00736 00737 if (!gvl) 00738 return (-1); 00739 00740 if (isosurf_id < 0 || isosurf_id > (gvl->n_isosurfs - 1)) 00741 return (-1); 00742 00743 if (isosurf_id == (gvl->n_isosurfs - 1)) 00744 return (1); 00745 00746 tmp = gvl->isosurf[isosurf_id + 1]; 00747 gvl->isosurf[isosurf_id + 1] = gvl->isosurf[isosurf_id]; 00748 gvl->isosurf[isosurf_id] = tmp; 00749 00750 return (1); 00751 } 00752 00766 int GVL_isosurf_get_att(int id, int isosurf_id, 00767 int att, int *set, float *constant, char *mapname) 00768 { 00769 int src; 00770 geovol_isosurf *isosurf; 00771 00772 G_debug(3, "GVL_isosurf_get_att"); 00773 00774 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00775 00776 if (isosurf) { 00777 if (-1 != (src = gvl_isosurf_get_att_src(isosurf, att))) { 00778 *set = src; 00779 00780 if (src == CONST_ATT) { 00781 *constant = isosurf->att[att].constant; 00782 } 00783 else if (src == MAP_ATT) { 00784 G_strcpy(mapname, gvl_file_get_name(isosurf->att[att].hfile)); 00785 } 00786 00787 return (1); 00788 } 00789 00790 return (-1); 00791 } 00792 00793 return (-1); 00794 } 00795 00806 int GVL_isosurf_unset_att(int id, int isosurf_id, int att) 00807 { 00808 geovol_isosurf *isosurf; 00809 00810 G_debug(3, "GVL_isosurf_unset_att"); 00811 00812 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00813 00814 if (isosurf) { 00815 return (gvl_isosurf_set_att_src(isosurf, att, NOTSET_ATT)); 00816 } 00817 00818 return (-1); 00819 } 00820 00841 int GVL_isosurf_set_att_const(int id, int isosurf_id, int att, float constant) 00842 { 00843 geovol_isosurf *isosurf; 00844 00845 G_debug(3, "GVL_isosurf_set_att_const() id=%d isosurf_id=%d " 00846 "att=%d const=%f", id, isosurf_id, att, constant); 00847 00848 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00849 00850 if (isosurf) { 00851 return (gvl_isosurf_set_att_const(isosurf, att, constant)); 00852 } 00853 00854 return (-1); 00855 } 00856 00877 int GVL_isosurf_set_att_map(int id, int isosurf_id, int att, 00878 const char *filename) 00879 { 00880 geovol_isosurf *isosurf; 00881 00882 G_debug(3, "GVL_isosurf_set_att_map(): id=%d, isosurf_id=%d " 00883 "att=%d map=%s", id, isosurf_id, att, filename); 00884 00885 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00886 00887 if (isosurf) { 00888 return gvl_isosurf_set_att_map(isosurf, att, filename); 00889 } 00890 00891 return (-1); 00892 } 00893 00904 int GVL_isosurf_get_flags(int id, int isosurf_id, int *inout) 00905 { 00906 geovol_isosurf *isosurf; 00907 00908 G_debug(3, "GVL_isosurf_get_flags"); 00909 00910 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00911 00912 if (isosurf) { 00913 *inout = isosurf->inout_mode; 00914 00915 return (1); 00916 } 00917 return (-1); 00918 } 00919 00930 int GVL_isosurf_set_flags(int id, int isosurf_id, int inout) 00931 { 00932 geovol_isosurf *isosurf; 00933 00934 G_debug(3, "GVL_isosurf_get_flags"); 00935 00936 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00937 00938 if (isosurf) { 00939 isosurf->inout_mode = inout; 00940 00941 return (1); 00942 } 00943 00944 return (-1); 00945 } 00946 00955 int GVL_isosurf_num_isosurfs(int id) 00956 { 00957 geovol *gvl; 00958 00959 G_debug(3, "GVL_isosurf_num_isosurfs"); 00960 00961 gvl = gvl_get_vol(id); 00962 00963 if (gvl) { 00964 return gvl->n_isosurfs; 00965 } 00966 00967 return (-1); 00968 } 00969 00982 int GVL_isosurf_set_maskmode(int id, int isosurf_id, int mode) 00983 { 00984 geovol_isosurf *isosurf; 00985 00986 G_debug(3, "GVL_isosurf_set_att_const"); 00987 00988 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 00989 00990 if (isosurf) { 00991 isosurf->att[ATT_MASK].constant = mode; 00992 00993 return (mode); 00994 } 00995 00996 return (-1); 00997 } 00998 01009 int GVL_isosurf_get_maskmode(int id, int isosurf_id, int *mode) 01010 { 01011 geovol_isosurf *isosurf; 01012 01013 isosurf = gvl_isosurf_get_isosurf(id, isosurf_id); 01014 01015 if (isosurf) { 01016 *mode = isosurf->att[ATT_MASK].constant; 01017 01018 return (1); 01019 } 01020 01021 return (-1); 01022 } 01023 01024 /************************************************************************/ 01025 /* SLICES */ 01026 01027 /************************************************************************/ 01028 01035 void GVL_slice_get_drawres(int id, int *xres, int *yres, int *zres) 01036 { 01037 geovol *gvl; 01038 01039 G_debug(3, "GVL_slice_get_drawres"); 01040 01041 gvl = gvl_get_vol(id); 01042 01043 if (gvl) { 01044 *xres = gvl->slice_x_mod; 01045 *yres = gvl->slice_y_mod; 01046 *zres = gvl->slice_z_mod; 01047 } 01048 01049 return; 01050 } 01051 01061 int GVL_slice_set_drawres(int id, int xres, int yres, int zres) 01062 { 01063 geovol *gvl; 01064 int i; 01065 01066 G_debug(3, "GVL_slice_set_drawres(): id=%d", id); 01067 01068 if (xres < 1 || yres < 1 || zres < 1) { 01069 return (-1); 01070 } 01071 01072 gvl = gvl_get_vol(id); 01073 01074 if (gvl) { 01075 gvl->slice_x_mod = xres; 01076 gvl->slice_y_mod = yres; 01077 gvl->slice_z_mod = zres; 01078 01079 for (i = 0; i < gvl->n_slices; i++) { 01080 gvl->slice[i]->changed = 1; 01081 } 01082 01083 return (0); 01084 } 01085 01086 return (-1); 01087 } 01088 01098 int GVL_slice_get_drawmode(int id, int *mode) 01099 { 01100 geovol *gvl; 01101 01102 gvl = gvl_get_vol(id); 01103 01104 if (gvl) { 01105 *mode = gvl->slice_draw_mode; 01106 01107 return (1); 01108 } 01109 01110 return (-1); 01111 } 01112 01122 int GVL_slice_set_drawmode(int id, int mode) 01123 { 01124 geovol *gvl; 01125 01126 G_debug(3, "GVL_slice_set_drawmode(): id=%d, mode=%d", id, mode); 01127 01128 gvl = gvl_get_vol(id); 01129 01130 if (gvl) { 01131 gvl->slice_draw_mode = mode; 01132 01133 return (0); 01134 } 01135 01136 return (-1); 01137 } 01138 01147 int GVL_slice_add(int id) 01148 { 01149 geovol *gvl; 01150 geovol_slice *slice; 01151 01152 G_debug(3, "GVL_slice_add"); 01153 01154 gvl = gvl_get_vol(id); 01155 01156 if (!gvl) 01157 return (-1); 01158 01159 if (gvl->n_slices == MAX_SLICES) 01160 return (-1); 01161 01162 if (NULL == (slice = (geovol_slice *) G_malloc(sizeof(geovol_slice)))) { 01163 return (-1); 01164 } 01165 01166 gvl_slice_init(slice); 01167 01168 gvl->n_slices++; 01169 gvl->slice[gvl->n_slices - 1] = (geovol_slice *) slice; 01170 01171 return (1); 01172 } 01173 01183 int GVL_slice_del(int id, int slice_id) 01184 { 01185 geovol *gvl; 01186 geovol_slice *slice; 01187 int i; 01188 01189 G_debug(3, "GVL_slice_del"); 01190 01191 slice = gvl_slice_get_slice(id, slice_id); 01192 01193 if (!slice) 01194 return (-1); 01195 01196 if (!gvl_slice_freemem(slice)) { 01197 return (-1); 01198 } 01199 01200 gvl = gvl_get_vol(id); 01201 01202 G_free(gvl->slice[slice_id]); 01203 01204 for (i = slice_id + 1; i < gvl->n_slices; i++) { 01205 gvl->slice[i - 1] = gvl->slice[i]; 01206 } 01207 01208 gvl->n_slices--; 01209 01210 return (1); 01211 } 01212 01222 int GVL_slice_move_up(int id, int slice_id) 01223 { 01224 geovol *gvl; 01225 geovol_slice *tmp; 01226 01227 G_debug(3, "GVL_slice_move_up"); 01228 01229 gvl = gvl_get_vol(id); 01230 01231 if (!gvl) 01232 return (-1); 01233 01234 if (slice_id < 0 || slice_id > (gvl->n_slices - 1)) 01235 return (-1); 01236 01237 if (slice_id == 0) 01238 return (1); 01239 01240 tmp = gvl->slice[slice_id - 1]; 01241 gvl->slice[slice_id - 1] = gvl->slice[slice_id]; 01242 gvl->slice[slice_id] = tmp; 01243 01244 return (1); 01245 } 01246 01256 int GVL_slice_move_down(int id, int slice_id) 01257 { 01258 geovol *gvl; 01259 geovol_slice *tmp; 01260 01261 G_debug(3, "GVL_slice_move_up"); 01262 01263 gvl = gvl_get_vol(id); 01264 01265 if (!gvl) 01266 return (-1); 01267 01268 if (slice_id < 0 || slice_id > (gvl->n_slices - 1)) 01269 return (-1); 01270 01271 if (slice_id == (gvl->n_slices - 1)) 01272 return (1); 01273 01274 tmp = gvl->slice[slice_id + 1]; 01275 gvl->slice[slice_id + 1] = gvl->slice[slice_id]; 01276 gvl->slice[slice_id] = tmp; 01277 01278 return (1); 01279 } 01280 01289 int GVL_slice_num_slices(int id) 01290 { 01291 geovol *gvl; 01292 01293 G_debug(3, "GVL_isosurf_num_isosurfs"); 01294 01295 gvl = gvl_get_vol(id); 01296 01297 if (gvl) { 01298 return gvl->n_slices; 01299 } 01300 01301 return (-1); 01302 } 01303 01316 int GVL_slice_get_pos(int id, int slice_id, 01317 float *x1, float *x2, float *y1, float *y2, float *z1, 01318 float *z2, int *dir) 01319 { 01320 geovol *gvl; 01321 geovol_slice *slice; 01322 int cols, rows, depths; 01323 01324 gvl = gvl_get_vol(id); 01325 01326 if (!gvl) 01327 return (-1); 01328 01329 slice = gvl_slice_get_slice(id, slice_id); 01330 01331 if (!slice) 01332 return (-1); 01333 01334 if (slice->dir == X) { 01335 cols = gvl->rows; 01336 rows = gvl->depths; 01337 depths = gvl->cols; 01338 } 01339 else if (slice->dir == Y) { 01340 cols = gvl->cols; 01341 rows = gvl->depths; 01342 depths = gvl->rows; 01343 } 01344 else if (slice->dir == Z) { 01345 cols = gvl->cols; 01346 rows = gvl->rows; 01347 depths = gvl->depths; 01348 } 01349 else { 01350 return (-1); 01351 } 01352 01353 *x1 = slice->x1 / (cols - 1); 01354 *x2 = slice->x2 / (cols - 1); 01355 *y1 = slice->y1 / (rows - 1); 01356 *y2 = slice->y2 / (rows - 1); 01357 *z1 = slice->z1 / (depths - 1); 01358 *z2 = slice->z2 / (depths - 1); 01359 01360 *dir = slice->dir; 01361 01362 return (1); 01363 } 01364 01377 int GVL_slice_set_pos(int id, int slice_id, 01378 float x1, float x2, float y1, float y2, float z1, 01379 float z2, int dir) 01380 { 01381 geovol *gvl; 01382 geovol_slice *slice; 01383 int cols, rows, depths; 01384 01385 gvl = gvl_get_vol(id); 01386 01387 if (!gvl) 01388 return (-1); 01389 01390 slice = gvl_slice_get_slice(id, slice_id); 01391 01392 if (!slice) 01393 return (-1); 01394 01395 if (dir == X) { 01396 cols = gvl->rows; 01397 rows = gvl->depths; 01398 depths = gvl->cols; 01399 } 01400 else if (dir == Y) { 01401 cols = gvl->cols; 01402 rows = gvl->depths; 01403 depths = gvl->rows; 01404 } 01405 else if (dir == Z) { 01406 cols = gvl->cols; 01407 rows = gvl->rows; 01408 depths = gvl->depths; 01409 } 01410 else { 01411 return (-1); 01412 } 01413 01414 slice->x1 = ((x1 < 0.) ? 0. : ((x1 > 1.) ? 1. : x1)) * (cols - 1); 01415 slice->x2 = ((x2 < 0.) ? 0. : ((x2 > 1.) ? 1. : x2)) * (cols - 1); 01416 slice->y1 = ((y1 < 0.) ? 0. : ((y1 > 1.) ? 1. : y1)) * (rows - 1); 01417 slice->y2 = ((y2 < 0.) ? 0. : ((y2 > 1.) ? 1. : y2)) * (rows - 1); 01418 slice->z1 = ((z1 < 0.) ? 0. : ((z1 > 1.) ? 1. : z1)) * (depths - 1); 01419 slice->z2 = ((z2 < 0.) ? 0. : ((z2 > 1.) ? 1. : z2)) * (depths - 1); 01420 01421 slice->dir = dir; 01422 01423 slice->changed = 1; 01424 01425 return (1); 01426 } 01427 01438 int GVL_slice_get_transp(int id, int slice_id, int *transp) 01439 { 01440 geovol_slice *slice; 01441 01442 G_debug(3, "GVL_get_transp"); 01443 01444 slice = gvl_slice_get_slice(id, slice_id); 01445 01446 if (!slice) 01447 return (-1); 01448 01449 *transp = slice->transp; 01450 01451 return (1); 01452 } 01453 01464 int GVL_slice_set_transp(int id, int slice_id, int transp) 01465 { 01466 geovol_slice *slice; 01467 01468 G_debug(3, "GVL_set_transp"); 01469 01470 slice = gvl_slice_get_slice(id, slice_id); 01471 01472 if (!slice) 01473 return (-1); 01474 01475 slice->transp = transp; 01476 01477 return (1); 01478 }