/*! \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 Check parameters consistency \param params module parameters */ void check_parameters(const struct GParams *params) { int nelev_map, nelev_const, nelevs; int nmaps, nconsts, ncoords, ncplanes; int nvlines; int nvpoints, nvpoints_pos, nvpoints_layer; int nvolumes, nisosurf, nslices; /* topography */ nelev_map = opt_get_num_answers(params->elev_map); nelev_const = opt_get_num_answers(params->elev_const); nelevs = nelev_map + nelev_const; #if 0 if (nelevs < 1) G_fatal_error(_("At least one <%s> or <%s> required"), params->elev_map->key, params->elev_const->key); #endif /* color */ nmaps = opt_get_num_answers(params->color_map); nconsts = opt_get_num_answers(params->color_const); print_error(nmaps, nconsts, nelevs, params->elev_map->key, params->elev_const->key, params->color_map->key, params->color_const->key); /* mask */ nmaps = opt_get_num_answers(params->mask_map); if (nmaps > 0 && nelevs != nmaps) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->mask_map->key, nmaps); /* transparency */ nmaps = opt_get_num_answers(params->transp_map); nconsts = opt_get_num_answers(params->transp_const); print_error(nmaps, nconsts, nelevs, params->elev_map->key, params->elev_const->key, params->transp_map->key, params->transp_const->key); /* shininess */ nmaps = opt_get_num_answers(params->shine_map); nconsts = opt_get_num_answers(params->shine_const); print_error(nmaps, nconsts, nelevs, params->elev_map->key, params->elev_const->key, params->shine_map->key, params->shine_const->key); /* emit */ nmaps = opt_get_num_answers(params->emit_map); nconsts = opt_get_num_answers(params->emit_const); print_error(nmaps, nconsts, nelevs, params->elev_map->key, params->elev_const->key, params->emit_map->key, params->emit_const->key); /* draw mode */ if (!params->mode_all->answer) { /* use one mode for all surfaces */ nconsts = opt_get_num_answers(params->mode); if (nconsts > 0 && nelevs > 0 && nconsts != nelevs) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->mode->key, nconsts); nconsts = opt_get_num_answers(params->res_fine); if (nconsts > 0 && nelevs > 0 && nconsts != nelevs) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->res_fine->key, nconsts); nconsts = opt_get_num_answers(params->res_coarse); if (nconsts > 0 && nelevs > 0 && nconsts != nelevs) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->res_coarse->key, nconsts); nconsts = opt_get_num_answers(params->style); if (nconsts > 0 && nelevs > 0 && nconsts != nelevs) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->style->key, nconsts); nconsts = opt_get_num_answers(params->shade); if (nconsts > 0 && nelevs > 0 && nconsts != nelevs) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->shade->key, nconsts); nconsts = opt_get_num_answers(params->wire_color); if (nconsts > 0 && nelevs > 0 && nconsts != nelevs) G_fatal_error(_("Inconsistent number of attributes (<%s/%s>: %d vs. <%s>: %d)"), params->elev_map->key, params->elev_const->key, nelevs, params->wire_color->key, nconsts); } /* * Cutting planes */ ncplanes = opt_get_num_answers(params->cplane); ncoords = opt_get_num_answers(params->cplane_pos); if (ncplanes > 0 && ncplanes * 3 != ncoords) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d x 3)"), params->cplane->key, ncplanes, params->cplane_pos->key, ncoords / 3); nconsts = opt_get_num_answers(params->cplane_rot); if (ncplanes > 0 && ncplanes != nconsts) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->cplane->key, ncplanes, params->cplane_rot->key, nconsts); nconsts = opt_get_num_answers(params->cplane_tilt); if (ncplanes > 0 && ncplanes != nconsts) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->cplane->key, ncplanes, params->cplane_tilt->key, nconsts); /* * vector lines */ nvlines = opt_get_num_answers(params->vlines); /* width */ nconsts = opt_get_num_answers(params->vline_width); if (nvlines > 0 && nconsts != nvlines) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vlines->key, nvlines, params->vline_width->key, nconsts); /* color */ nconsts = opt_get_num_answers(params->vline_color); if (nvlines > 0 && nconsts != nvlines) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vlines->key, nvlines, params->vline_color->key, nconsts); /* mode */ nconsts = opt_get_num_answers(params->vline_mode); if (nvlines > 0 && nconsts != nvlines) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vlines->key, nvlines, params->vline_mode->key, nconsts); /* height */ nconsts = opt_get_num_answers(params->vline_height); if (nvlines > 0 && nconsts != nvlines) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vlines->key, nvlines, params->vline_height->key, nconsts); /* position */ nconsts = opt_get_num_answers(params->vline_pos); if (nvlines > 0 && nconsts != 3 * nvlines) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vlines->key, nvlines, params->vline_pos->key, nconsts); /* * vector points */ nvpoints = opt_get_num_answers(params->vpoints); nvpoints_pos = opt_get_num_answers(params->vpoint_pos); nvpoints_layer = opt_get_num_answers(params->vpoint_layer); if (nvpoints && (nvpoints * 3 != nvpoints_pos)) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vpoints->key, nvpoints, params->vpoint_pos->key, nvpoints_pos); if (nvpoints && (nvpoints != nvpoints_layer)) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->vpoints->key, nvpoints, params->vpoint_layer->key, nvpoints_layer); /* TODO */ /* * volumes */ nvolumes = opt_get_num_answers(params->volume); nisosurf = opt_get_num_answers(params->isosurf_level); nslices = opt_get_num_answers(params->slice); /* isosurface transparency */ nmaps = opt_get_num_answers(params->isosurf_transp_map); nconsts = opt_get_num_answers(params->isosurf_transp_const); if ((nmaps + nconsts > 0) && (nisosurf != nmaps + nconsts)) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d, <%s>: %d)"), params->isosurf_level->key, nisosurf, params->isosurf_transp_map->key, nmaps, params->isosurf_transp_const->key, nconsts); /* isosurface shininess */ nmaps = opt_get_num_answers(params->isosurf_shine_map); nconsts = opt_get_num_answers(params->isosurf_shine_const); if ((nmaps + nconsts > 0) && (nisosurf != nmaps + nconsts)) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d, <%s>: %d)"), params->isosurf_level->key, nisosurf, params->isosurf_shine_map->key, nmaps, params->isosurf_shine_const->key, nconsts); /* slice transparency */ nconsts = opt_get_num_answers(params->slice_transp); if (nslices > 0 && nslices != nconsts) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d)"), params->slice->key, nslices, params->slice_transp->key, nconsts); /* slice position */ ncoords = opt_get_num_answers(params->slice_pos); if (nslices > 0 && ncoords != 6 * nslices) G_fatal_error(_("Inconsistent number of attributes (<%s>: %d vs. <%s>: %d x 6)"), params->slice->key, nslices, params->slice_pos->key, ncoords / 6); return; }