[GRASS-SVN] r31685 - grass-addons/visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 11 17:48:04 EDT 2008
Author: martinl
Date: 2008-06-11 17:48:03 -0400 (Wed, 11 Jun 2008)
New Revision: 31685
Added:
grass-addons/visualization/nviz2/cmd/exag.c
Modified:
grass-addons/visualization/nviz2/cmd/args.c
grass-addons/visualization/nviz2/cmd/draw.c
grass-addons/visualization/nviz2/cmd/local_proto.h
grass-addons/visualization/nviz2/cmd/main.c
grass-addons/visualization/nviz2/cmd/map_obj.c
grass-addons/visualization/nviz2/cmd/nviz.h
Log:
nviz_cmd: calculate viewpoint height, load vectors
Modified: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c 2008-06-11 20:02:51 UTC (rev 31684)
+++ grass-addons/visualization/nviz2/cmd/args.c 2008-06-11 21:48:03 UTC (rev 31685)
@@ -32,8 +32,9 @@
*/
void parse_command(int argc, char* argv[], struct GParams *params)
{
+ /* raster */
params->elev = G_define_standard_option(G_OPT_R_ELEV);
- params->elev->required = YES;
+ params->elev->required = NO;
params->elev->multiple = YES;
params->elev->description = _("Name of raster map(s) for elevation");
params->elev->guisection = _("Raster");
@@ -52,6 +53,15 @@
params->color_const->key = "color_value";
params->color_const->answer = NULL;
+ /* vector */
+ params->vector = G_define_standard_option(G_OPT_V_MAP);
+ params->vector->multiple = YES;
+ params->vector->required = NO;
+ params->vector->description = _("Name of vector overlay map(s)");
+ params->vector->guisection = _("Vector");
+ params->vector->key = "vector";
+
+ /* misc */
params->exag = G_define_option();
params->exag->key = "zexag";
params->exag->key_desc = "value";
@@ -83,7 +93,6 @@
params->height->multiple = NO;
params->height->description = _("Viewpoint height (in map units)");
params->height->guisection = _("Viewpoint");
- params->height->answer = "10561";
params->persp = G_define_option();
params->persp->key = "perspective";
Modified: grass-addons/visualization/nviz2/cmd/draw.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/draw.c 2008-06-11 20:02:51 UTC (rev 31684)
+++ grass-addons/visualization/nviz2/cmd/draw.c 2008-06-11 21:48:03 UTC (rev 31685)
@@ -25,6 +25,13 @@
static int sort_surfs_max(int *, int *, int *, int);
static int check_blank(int);
+/*!
+ \brief Draw all loaded surfaces
+
+ \param dc nviz data
+
+ \return 1
+*/
int draw_all_surf(nv_data *dc)
{
int i, nsurfs;
@@ -137,7 +144,7 @@
// const char* EMPTYSTRING = "";
draw_surf = 1;
- draw_vect = 0;
+ draw_vect = 1;
draw_site = 0;
draw_vol = 0;
draw_north_arrow = 0;
@@ -173,10 +180,10 @@
bar_x = Tcl_GetVar(interp, "scalebar_x", TCL_GLOBAL_ONLY);
*/
if (draw_surf)
- draw_all_surf (data);
+ draw_all_surf(data);
if (draw_vect)
- ; // vect_draw_all_together(data, interp);
+ draw_all_vect (data);
if (draw_site)
; // site_draw_all_together(data, interp);
@@ -323,3 +330,39 @@
return 1;
}
+
+/*!
+ \brief Draw all loaded vector sets
+
+ \param dc nviz data
+
+ \return 1
+*/
+int draw_all_vect(nv_data *dc)
+{
+ int i, nvects;
+ int *vect_list;
+
+ // GS_set_cancel(0);
+ vect_list = GV_get_vect_list(&nvects);
+
+ /* in case transparency is set */
+ GS_set_draw(GSD_BOTH);
+
+ GS_ready_draw();
+
+ for (i = 0; i < nvects; i++) {
+ if (!check_blank(vect_list[i])) {
+ GV_draw_vect(vect_list[i]);
+ }
+ }
+ G_free (vect_list);
+
+ GS_done_draw();
+
+ GS_set_draw(GSD_BACK);
+
+ // GS_set_cancel(0);
+
+ return 1;
+}
Added: grass-addons/visualization/nviz2/cmd/exag.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/exag.c (rev 0)
+++ grass-addons/visualization/nviz2/cmd/exag.c 2008-06-11 21:48:03 UTC (rev 31685)
@@ -0,0 +1,72 @@
+/*!
+ \file exag.c
+
+ \brief Exaggeration functions
+
+ COPYRIGHT: (C) 2008 by the GRASS Development Team
+
+ This program is free software under the GNU General Public
+ License (>=v2). Read the file COPYING that comes with GRASS
+ for details.
+
+ Based on visualization/nviz/src/exag.c
+
+ \author Updated/modified by Martin Landa <landa.martin gmail.com>
+
+ \date 2008
+*/
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+#include "local_proto.h"
+
+/*!
+ \brief Get viewpoint height
+
+ Call after initial data has been loaded
+
+ \param data nviz data
+ \param[out] val height value
+ \param[out] min min value (or NULL)
+ \param[out] max max value (or NULL)
+
+ \return 1
+*/
+int exag_get_height(float *val, float *min, float *max)
+{
+ float longdim, exag, texag, hmin, hmax, fmin, fmax;
+ int nsurfs, i, *surf_list;
+
+ 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;
+ }
+
+ *val = fmin + (fmax - fmin) / 2.0;
+
+ if (min)
+ *min = fmin;
+
+ if (max)
+ *max = fmax;
+
+ return 1;
+}
Property changes on: grass-addons/visualization/nviz2/cmd/exag.c
___________________________________________________________________
Name: svn:mime-type
+ text/x-csrc
Name: svn:keywords
+ Author Date Id
Name: svn:eol-style
+ native
Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h 2008-06-11 20:02:51 UTC (rev 31684)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h 2008-06-11 21:48:03 UTC (rev 31685)
@@ -6,7 +6,8 @@
/* module flags and parameters */
struct GParams {
- struct Option *elev, *color_map, *color_const, /* data */
+ struct Option *elev, *color_map, *color_const, /* raster */
+ *vector, /* vector */
*exag, *bgcolor, /* misc */
*pos, *height, *persp, *twist; /* viewpoint */
};
@@ -35,7 +36,11 @@
int draw_all_surf(nv_data *);
int draw_all(nv_data *);
int draw_quick(nv_data *);
+int draw_all_vect(nv_data *);
+/* exag.c */
+int exag_get_height(float *, float *, float *);
+
/* map_obj.c */
int new_map_obj(int, const char *,
nv_data *);
Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c 2008-06-11 20:02:51 UTC (rev 31684)
+++ grass-addons/visualization/nviz2/cmd/main.c 2008-06-11 21:48:03 UTC (rev 31685)
@@ -32,7 +32,8 @@
char *mapset;
unsigned int i;
int id;
- unsigned int nelev, ncolor_map, ncolor_const;
+ unsigned int nelev, ncolor_map, ncolor_const, nvect;
+ float vp_height; /* calculated viewpoint height */
nv_data data;
render_window offscreen;
@@ -77,7 +78,8 @@
while(params->color_const->answer && params->color_const->answers[i++])
ncolor_const++;
- if (params->elev->answers) {
+ /* load rasters */
+ if (params->elev->answer) {
for (i = 0; params->elev->answers[i]; i++) {
mapset = G_find_cell2 (params->elev->answers[i], "");
if (mapset == NULL) {
@@ -120,6 +122,29 @@
}
}
+ /* load vectors */
+ if (params->vector->answer) {
+ if (!params->elev->answer && GS_num_surfs() == 0) { /* load base surface if no loaded */
+ int *surf_list, nsurf;
+
+ new_map_obj(MAP_OBJ_SURF, NULL, &data);
+
+ surf_list = GS_get_surf_list(&nsurf);
+ GS_set_att_const(surf_list[0], ATT_TRANSP, 255);
+ }
+
+ for (i = 0; params->vector->answers[i]; i++) {
+ mapset = G_find_vector2 (params->vector->answers[i], "");
+ if (mapset == NULL) {
+ G_fatal_error(_("Vector map <%s> not found"),
+ params->vector->answers[i]);
+ }
+ new_map_obj(MAP_OBJ_VECT,
+ G_fully_qualified_name(params->vector->answers[i], mapset), &data);
+ }
+ nvect++;
+ }
+
/* init view */
init_view();
focus_set_map(MAP_OBJ_UNDEFINED, -1);
@@ -156,8 +181,14 @@
0.3, 0.3, 0.3);
/* define view point */
+ if (params->height->answer) {
+ vp_height = atof(params->height->answer);
+ }
+ else {
+ exag_get_height(&vp_height, NULL, NULL);
+ }
viewpoint_set_height(&data,
- atof(params->height->answer));
+ vp_height);
change_exag(&data,
atof(params->exag->answer));
viewpoint_set_position(&data,
Modified: grass-addons/visualization/nviz2/cmd/map_obj.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/map_obj.c 2008-06-11 20:02:51 UTC (rev 31684)
+++ grass-addons/visualization/nviz2/cmd/map_obj.c 2008-06-11 21:48:03 UTC (rev 31685)
@@ -54,7 +54,8 @@
int new_map_obj(int type, const char *name,
nv_data *data)
{
- int new_id;
+ int new_id, i;
+ int num_surfs, *surf_list;
nv_clientdata *client_data;
@@ -68,6 +69,7 @@
* id number and link it to the Nmap_obj_cmd routine
* below.
*/
+ /* raster -> surface */
if (type == MAP_OBJ_SURF) {
if (GS_num_surfs() >= MAX_SURFS) {
G_warning (_("Maximum surfaces loaded!"));
@@ -95,8 +97,36 @@
}
}
}
+ /* vector overlay */
+ else if (type == MAP_OBJ_VECT) {
+ if (GV_num_vects() >= MAX_VECTS) {
+ G_warning (_("Maximum vectors loaded!"));
+ return -1;
+ }
- /* Initialize the client data filled for the new map object */
+ new_id = GV_new_vector();
+
+ if (name) {
+ if (GV_load_vector(new_id, name) < 0) {
+ GV_delete_vector(new_id);
+ G_warning (_("Error loading vector <%s>"), name);
+ return -1;
+ }
+ }
+
+ /* initialize display parameters
+ automatically select all surfaces to draw vector */
+ GV_set_vectmode(new_id, 1, 0xFF0000, 2, 0);
+ surf_list = GS_get_surf_list(&num_surfs);
+ if (num_surfs) {
+ for (i = 0; i < num_surfs; i++) {
+ GV_select_surf(new_id, surf_list[i]);
+ }
+ }
+ G_free (surf_list);
+ }
+
+ /* initialize the client data filled for the new map object */
client_data = (nv_clientdata *) G_malloc (sizeof(nv_clientdata));
if (name) {
@@ -252,3 +282,4 @@
return;
}
+
Modified: grass-addons/visualization/nviz2/cmd/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.h 2008-06-11 20:02:51 UTC (rev 31684)
+++ grass-addons/visualization/nviz2/cmd/nviz.h 2008-06-11 21:48:03 UTC (rev 31685)
@@ -6,6 +6,7 @@
#define MAP_OBJ_UNDEFINED 0
#define MAP_OBJ_SURF 1
#define MAP_OBJ_VOL 2
+#define MAP_OBJ_VECT 3
#define RANGE (5 * GS_UNIT_SIZE)
#define RANGE_OFFSET (2 * GS_UNIT_SIZE)
More information about the grass-commit
mailing list