int Nquick_draw_cmd(Nv_data * dc, Tcl_Interp * interp) { int i, max; int *surf_list, *vol_list; GS_set_draw(GSD_BACK); GS_clear(dc->BGcolor); GS_ready_draw(); surf_list = GS_get_surf_list(&max); max = GS_num_surfs(); for (i = 0; i < max; i++) { if (check_blank(interp, surf_list[i]) == 0) { GS_draw_wire(surf_list[i]); } } G_free(surf_list); vol_list = GVL_get_vol_list(&max); max = GVL_num_vols(); for (i = 0; i < max; i++) { if (check_blank(interp, vol_list[i]) == 0) { GVL_draw_wire(vol_list[i]); } } GS_done_draw(); /*** ACS_MODIFY flythrough ONE LINE ***************/ flythrough_postdraw_cb(); return (TCL_OK); }
int Nget_first_exag_cmd(Nv_data * data, Tcl_Interp * interp, /* Current interpreter. */ int argc, char **argv) { float exag, texag; int nsurfs, i, *surf_list; char buf[128]; surf_list = GS_get_surf_list(&nsurfs); exag = 0.0; for (i = 0; i < nsurfs; i++) { if (GS_get_exag_guess(surf_list[i], &texag) > -1) { if (texag) exag = (texag > exag) ? texag : exag; } } if (exag == 0.0) exag = 1.0; sprintf(buf, "%f", exag); if (nsurfs) free(surf_list); Tcl_SetResult(interp, buf, TCL_VOLATILE); return TCL_OK; }
/*! Add new fringe \param data nviz data \param id surface id \param color color \param elev fringe elevation \param nw,ne,sw,se 1 (turn on) 0 (turn off) \return pointer to allocated fringe_data structure \return NULL on error */ struct fringe_data *Nviz_new_fringe(nv_data *data, int id, unsigned long color, double elev, int nw, int ne, int sw, int se) { int num; int *surf; struct fringe_data *f; if (!GS_surf_exists(id)) { /* select first surface from the list */ surf = GS_get_surf_list(&num); if (num < 1) return NULL; id = surf[0]; G_free(surf); } f = (struct fringe_data *) G_malloc(sizeof(struct fringe_data)); f->id = id; f->color = color; f->elev = elev; f->where[0] = nw; f->where[1] = ne; f->where[2] = sw; f->where[3] = se; data->fringe = (struct fringe_data **) G_realloc(data->fringe, data->num_fringes + 1 * sizeof(struct fringe_data *)); data->fringe[data->num_fringes++] = f; return f; }
/* after initial data has been loaded, & maybe again later */ int Nget_height_cmd(Nv_data * data, Tcl_Interp * interp, /* Current interpreter. */ int argc, char **argv) { float longdim, exag, texag, hmin, hmax; int nsurfs, i, *surf_list; char min[128]; char max[128]; char val[128]; float fmin, fmax; char *list[4]; surf_list = GS_get_surf_list(&nsurfs); if (nsurfs) { GS_get_longdim(&longdim); GS_get_zrange_nz(&hmin, &hmax); exag = 0.0; for (i = 0; i < nsurfs; i++) { if (GS_get_exag_guess(surf_list[i], &texag) > -1) if (texag) exag = texag > exag ? texag : exag; } if (exag == 0.0) exag = 1.0; fmin = hmin - (2. * longdim / exag); fmax = hmin + (3 * longdim / exag); } else { fmax = 10000.0; fmin = 0.0; } /* The one decimal place of accuracy is necessary to force Tcl to */ /* parse these values as floating point rather than integers. This */ /* avoids problems with integers which are too large to represent. */ sprintf(min, "%.1f", fmin); sprintf(max, "%.1f", fmax); sprintf(val, "%.1f", fmin + (fmax - fmin) / 2.0); list[0] = val; list[1] = min; list[2] = max; list[3] = NULL; Tcl_SetResult(interp, Tcl_Merge(3, list), TCL_DYNAMIC); return TCL_OK; }
/*! \brief Draw current clip plane \param data nviz data \param current id of current clip plane \param surf1 first surface id \param surf2 second surface id */ void cp_draw(nv_data * data, int current, int surf1, int surf2) { int i, nsurfs; int surf_min = 0, surf_max = 0, temp; int *surf_list; GS_set_draw(GSD_BACK); GS_clear(data->bgcolor); GS_ready_draw(); /* If surf boundaries present then find them */ surf_list = GS_get_surf_list(&nsurfs); if ((surf1 != -1) && (surf2 != -1)) { for (i = 0; i < nsurfs; i++) { if (surf_list[i] == surf1) surf_min = i; if (surf_list[i] == surf2) surf_max = i; } if (surf_max < surf_min) { temp = surf_min; surf_min = surf_max; surf_max = temp; } surf_max++; } else { surf_min = 0; surf_max = nsurfs; } if (nsurfs > 1) { for (i = 0; i < MAX_CPLANES; i++) { if (data->cp_on[i]) GS_draw_cplane_fence(surf_list[0], surf_list[1], i); } } for (i = surf_min; i < surf_max; i++) { GS_draw_wire(surf_list[i]); } GS_done_draw(); return; }
int load_vectors(const struct Option *elev_map, const struct Option *elev_const, const struct Option *vect, const struct Option *position, int map_obj_type, nv_data * data) { int i, id; int nvects; const char *mapset; double x, y, z; if ((!elev_map->answer || elev_const->answer) && GS_num_surfs() == 0) { /* load base surface if no loaded */ int *surf_list, nsurf; Nviz_new_map_obj(MAP_OBJ_SURF, NULL, 0.0, data); surf_list = GS_get_surf_list(&nsurf); GS_set_att_const(surf_list[0], ATT_TRANSP, 255); } nvects = 0; for (i = 0; vect->answers[i]; i++) { mapset = G_find_vector2(vect->answers[i], ""); if (mapset == NULL) { G_fatal_error(_("Vector map <%s> not found"), vect->answers[i]); } id = Nviz_new_map_obj(map_obj_type, G_fully_qualified_name(vect->answers[i], mapset), 0.0, data); /* set position */ x = atof(position->answers[i*3+0]); y = atof(position->answers[i*3+1]); z = atof(position->answers[i*3+2]); if (map_obj_type == MAP_OBJ_VECT) GV_set_trans(id, x, y, z); else GP_set_trans(id, x, y, z); nvects++; } return nvects; }
/*! \brief Sets the scale bar position and return world coords \param data nviz data \param bar_id scale bar id \param sx,sy screen coordinates \param size scale bar length \param color scalebar/text color \return pointer to allocated scalebar_data structure \return NULL when there's no surface */ struct scalebar_data *Nviz_set_scalebar(nv_data *data, int bar_id, int sx, int sy, float size, unsigned int color) { int i, id, pt[2]; int *surf_list, num_surfs; float coords[3]; struct scalebar_data *s; if (GS_num_surfs() > 0) { surf_list = GS_get_surf_list(&num_surfs); id = surf_list[0]; G_free(surf_list); pt[0] = sx; pt[1] = sy; GS_set_Narrow(pt, id, coords); /* the same like arrow */ for (i = 0; i < data->num_scalebars; i++) { if (data->scalebar[i]) { s = data->scalebar[i]; if (s->id == bar_id) { s->color = color; s->size = size; s->where[0] = coords[0]; s->where[1] = coords[1]; s->where[2] = coords[2]; return s; } } } s = Nviz_new_scalebar(data, bar_id, coords, size, color); return s; } return NULL; }
/*! \brief Sets the North Arrow position and return world coords \param data nviz data \param sx,sy screen coordinates \param size arrow length \param color arrow/text color */ int Nviz_set_arrow(nv_data *data, int sx, int sy, float size, unsigned int color) { int id, pt[2]; int *surf_list, num_surfs; float coords[3]; struct arrow_data *arw; if (GS_num_surfs() > 0) { surf_list = GS_get_surf_list(&num_surfs); id = surf_list[0]; G_free(surf_list); pt[0] = sx; pt[1] = sy; GS_set_Narrow(pt, id, coords); if (data->arrow) { data->arrow->color = color; data->arrow->size = size; data->arrow->where[0] = coords[0]; data->arrow->where[1] = coords[1]; data->arrow->where[2] = coords[2]; } else { arw = (struct arrow_data *) G_malloc(sizeof(struct arrow_data)); arw->color = color; arw->size = size; arw->where[0] = coords[0]; arw->where[1] = coords[1]; arw->where[2] = coords[2]; data->arrow = arw; } return 1; } return 0; }
/*! \brief Set focus based on loaded map If <i>map</i> is MAP_OBJ_UNDEFINED, set focus from first surface/volume in the list. \param type map object type \param id map object id \return 0 on no focus \return id id of map object used for setting focus */ int Nviz_set_focus_map(int type, int id) { if (GS_num_surfs() < 0 && GVL_num_vols() < 0) { GS_set_nofocus(); return 0; } if (type == MAP_OBJ_UNDEFINED) { int *surf_list, num_surfs, *vol_list; if (GS_num_surfs() > 0) { surf_list = GS_get_surf_list(&num_surfs); id = surf_list[0]; G_free(surf_list); GS_set_focus_center_map(id); } if (GVL_num_vols() > 0) { vol_list = GVL_get_vol_list(&num_surfs); id = vol_list[0]; G_free(vol_list); GVL_set_focus_center_map(id); } return id; } if (type == MAP_OBJ_SURF) { GS_set_focus_center_map(id); } else if (type == MAP_OBJ_VOL) { GVL_set_focus_center_map(id); } return id; }
/*! Set fringe \param data nviz data \param id surface id \param color color \param elev fringe elevation \param nw,ne,sw,se 1 (turn on) 0 (turn off) \return pointer to allocated fringe_data structure \return NULL on error */ struct fringe_data *Nviz_set_fringe(nv_data *data, int id, unsigned long color, double elev, int nw, int ne, int sw, int se) { int i, num; int *surf; struct fringe_data *f; if (!GS_surf_exists(id)) { /* select first surface from the list */ surf = GS_get_surf_list(&num); if (num < 1) return NULL; id = surf[0]; G_free(surf); } for (i = 0; i < data->num_fringes; i++) { f = data->fringe[i]; if (f->id == id) { f->color = color; f->elev = elev; f->where[0] = nw; f->where[1] = ne; f->where[2] = sw; f->where[3] = se; return f; } } f = Nviz_new_fringe(data, id, color, elev, nw, ne, sw, se); return f; }
/*! \brief Load raster maps/constants and set surface attributes \param params module parameters \param data nviz data */ int load_rasters(const struct GParams *params, nv_data * data) { const char *mapset; int i; int nelevs, nelev_map, nelev_const, ncolor_map, ncolor_const, nmask_map; int ntransp_map, ntransp_const, nshine_map, nshine_const; int nemit_map, nemit_const; int *surf_list, nsurfs; int id; double x, y, z; nelev_map = opt_get_num_answers(params->elev_map); nelev_const = opt_get_num_answers(params->elev_const); nelevs = nelev_const + nelev_map; /* topography (required) */ for (i = 0; i < nelevs; i++) { /* check maps */ if (i < nelev_map && strcmp(params->elev_map->answers[i], "")) { mapset = G_find_raster2(params->elev_map->answers[i], ""); if (mapset == NULL) { G_fatal_error(_("Raster map <%s> not found"), params->elev_map->answers[i]); } id = Nviz_new_map_obj(MAP_OBJ_SURF, G_fully_qualified_name(params->elev_map-> answers[i], mapset), 0.0, data); } else { if (i-nelev_map < nelev_const && strcmp(params->elev_const->answers[i-nelev_map], "")) { id = Nviz_new_map_obj(MAP_OBJ_SURF, NULL, atof(params->elev_const->answers[i-nelev_map]), data); } else { G_fatal_error(_("Missing topography attribute for surface %d"), i + 1); } } /* set position */ if (opt_get_num_answers(params->surface_pos) != 3 * nelevs){ x = atof(params->surface_pos->answers[0]); y = atof(params->surface_pos->answers[1]); z = atof(params->surface_pos->answers[2]); } else{ x = atof(params->surface_pos->answers[i*3+0]); y = atof(params->surface_pos->answers[i*3+1]); z = atof(params->surface_pos->answers[i*3+2]); } GS_set_trans(id, x, y, z); } /* set surface attributes */ surf_list = GS_get_surf_list(&nsurfs); ncolor_map = opt_get_num_answers(params->color_map); ncolor_const = opt_get_num_answers(params->color_const); nmask_map = opt_get_num_answers(params->mask_map); ntransp_map = opt_get_num_answers(params->transp_map); ntransp_const = opt_get_num_answers(params->transp_const); nshine_map = opt_get_num_answers(params->shine_map); nshine_const = opt_get_num_answers(params->shine_const); nemit_map = opt_get_num_answers(params->emit_map); nemit_const = opt_get_num_answers(params->emit_const); for (i = 0; i < nsurfs; i++) { id = surf_list[i]; /* color */ /* check for color map */ if (i < ncolor_map && strcmp(params->color_map->answers[i], "")) { mapset = G_find_raster2(params->color_map->answers[i], ""); if (mapset == NULL) { G_fatal_error(_("Raster map <%s> not found"), params->color_map->answers[i]); } Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT, G_fully_qualified_name(params->color_map-> answers[i], mapset), -1.0, data); } /* check for color value */ else if (i-ncolor_map < ncolor_const && strcmp(params->color_const->answers[i-ncolor_map], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT, NULL, Nviz_color_from_str(params->color_const-> answers[i-ncolor_map]), data); } else { /* use by default elevation map for coloring */ if (nelev_map > 0){ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT, G_fully_qualified_name(params->elev_map->answers[i], mapset), -1.0, data); G_verbose_message(_("Color attribute not defined, using default <%s>"), G_fully_qualified_name(params->elev_map-> answers[i], mapset)); } else{ G_fatal_error(_("Missing color attribute for surface %d"), i + 1); } } /* mask */ if (i < nmask_map && strcmp(params->mask_map->answers[i], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT, G_fully_qualified_name(params->mask_map->answers[i], mapset), -1.0, data); } /* transparency */ if (i < ntransp_map && strcmp(params->transp_map->answers[i], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT, G_fully_qualified_name(params->transp_map-> answers[i], mapset), -1.0, data); } else if (i-ntransp_map < ntransp_const && strcmp(params->transp_const->answers[i-ntransp_map], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, CONST_ATT, NULL, atof(params->transp_const->answers[i-ntransp_map]), data); } /* shininess */ if (i < nshine_map && strcmp(params->shine_map->answers[i], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT, G_fully_qualified_name(params->shine_map-> answers[i], mapset), -1.0, data); } else if (i-nshine_map < nshine_const && strcmp(params->shine_const->answers[i-nshine_map], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, CONST_ATT, NULL, atof(params->shine_const->answers[i-nshine_map]), data); } /* emission */ if (i < nemit_map && strcmp(params->emit_map->answers[i], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT, G_fully_qualified_name(params->emit_map->answers[i], mapset), -1.0, data); } else if (i-nemit_map < nemit_const && strcmp(params->emit_const->answers[i-nemit_map], "")) { Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, CONST_ATT, NULL, atof(params->emit_const->answers[i-nemit_map]), data); } /* if (i > 1) set_default_wirecolors(data, i); */ } return nsurfs; }
/*! \brief Set draw mode for loaded surfaces \param params module parameters */ void surface_set_draw_mode(const struct GParams *params) { int *surf_list, nsurfs; int i, id, draw_mode; int resol_fine, resol_coarse; char *mode, *style, *shade, *res_fine, *res_coarse, *wire_color; surf_list = GS_get_surf_list(&nsurfs); for (i = 0; i < nsurfs; i++) { draw_mode = 0; id = surf_list[i]; if (!GS_surf_exists(id)) G_fatal_error(_("Surface id %d doesn't exist"), id); if (params->mode_all->answer) { /* use one mode for all surfaces */ mode = params->mode->answers[0]; style = params->style->answers[0]; shade = params->shade->answers[0]; res_fine = params->res_fine->answers[0]; res_coarse = params->res_coarse->answers[0]; wire_color = params->wire_color->answers[0]; } else { mode = params->mode->answers[i]; style = params->style->answers[i]; shade = params->shade->answers[i]; res_fine = params->res_fine->answers[i]; res_coarse = params->res_coarse->answers[i]; wire_color = params->wire_color->answers[i]; } /* mode */ if (strcmp(mode, "coarse") == 0) { draw_mode |= DM_WIRE; } else if (strcmp(mode, "fine") == 0) { draw_mode |= DM_POLY; } else { /* both */ draw_mode |= DM_WIRE_POLY; } /* style */ if (strcmp(style, "wire") == 0) { draw_mode |= DM_GRID_WIRE; } else { /* surface */ draw_mode |= DM_GRID_SURF; } /* shading */ if (strcmp(shade, "flat") == 0) { draw_mode |= DM_FLAT; } else { /* gouraud */ draw_mode |= DM_GOURAUD; } if (GS_set_drawmode(id, draw_mode) < 0) G_fatal_error(_("Unable to set draw mode for surface id %d"), id); /* resolution */ resol_fine = atoi(res_fine); resol_coarse = atoi(res_coarse); if (GS_set_drawres(id, resol_fine, resol_fine, resol_coarse, resol_coarse) < 0) G_fatal_error(_("Unable to set draw mode for surface id %d"), id); /* wire color */ GS_set_wire_color(id, Nviz_color_from_str(wire_color)); } return; }