[GRASS-SVN] r31764 - in grass-addons/visualization/nviz2: cmd lib wxpython wxpython/nviz

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 20 07:23:53 EDT 2008


Author: martinl
Date: 2008-06-20 07:23:53 -0400 (Fri, 20 Jun 2008)
New Revision: 31764

Added:
   grass-addons/visualization/nviz2/lib/draw.c
   grass-addons/visualization/nviz2/lib/exag.c
   grass-addons/visualization/nviz2/lib/map_obj.c
   grass-addons/visualization/nviz2/lib/position.c
   grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/lights.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/load.cpp
Removed:
   grass-addons/visualization/nviz2/cmd/change_view.c
   grass-addons/visualization/nviz2/cmd/draw.c
   grass-addons/visualization/nviz2/cmd/exag.c
   grass-addons/visualization/nviz2/cmd/map_obj.c
   grass-addons/visualization/nviz2/cmd/position.c
Modified:
   grass-addons/visualization/nviz2/cmd/args.c
   grass-addons/visualization/nviz2/cmd/local_proto.h
   grass-addons/visualization/nviz2/cmd/main.c
   grass-addons/visualization/nviz2/lib/change_view.c
   grass-addons/visualization/nviz2/lib/nviz.c
   grass-addons/visualization/nviz2/lib/nviz.h
   grass-addons/visualization/nviz2/wxpython/nviz.py
   grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
Log:
nviz2: progress in wxnviz integration

Modified: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/args.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -144,23 +144,3 @@
 
     return;
 }
-
-/*!
-  \brief Get color value from color string (name or RGB triplet)
-
-  \param color_str color string
-
-  \return color value
-*/
-int color_from_cmd(const char *color_str)
-{
-    int red, grn, blu;
-
-    if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
-	G_warning (_("Invalid color (%s), using \"white\" as default"),
-		   color_str);
-	red = grn = blu = 255;
-    }
-
-    return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) + ((int)((blu) << 16) & BLU_MASK);
-}

Deleted: grass-addons/visualization/nviz2/cmd/change_view.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/change_view.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/change_view.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -1,187 +0,0 @@
-/*!
-  \file change_view.c
- 
-  \brief Change view settings
-  
-  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/change_view.c
-
-  \author Updated/modified by Martin Landa <landa.martin gmail.com>
-
-  \date 2008
-*/
-
-#include <stdlib.h>
-
-#include <grass/gsurf.h>
-#include <grass/gstypes.h>
-
-#include "local_proto.h"
-
-/*!
-  \brief Update ranges
-
-  Call whenever a new surface is added, deleted, or exag changes
-
-  \return 1
-*/
-int update_ranges(nv_data *dc)
-{
-    float zmin, zmax, exag;
-
-    GS_get_longdim(&(dc->xyrange));
-
-    dc->zrange = 0.;
-
-    /* Zrange is based on a minimum of Longdim */
-    if (GS_global_exag()) {
-	exag = GS_global_exag();
-	dc->zrange = dc->xyrange / exag;
-    }
-    else {
-	exag = 1.0;
-    }
-
-    GS_get_zrange_nz(&zmin, &zmax);	/* actual */
-
-    zmax = zmin + (3. * dc->xyrange / exag);
-    zmin = zmin - (2. * dc->xyrange / exag);
-
-    if ((zmax - zmin) > dc->zrange)
-	dc->zrange = zmax - zmin;
-
-    return 1;
-}
-
-/*!
-  \brief Change position of view
-
-  \param data nviz data
-  \param x_pos,y_pos x,y position (model coordinates)
-
-  \return 1
-*/
-int viewpoint_set_position(nv_data *data,
-			   float x_pos, float y_pos)
-{
-    float xpos, ypos, from[3];
-    float tempx, tempy;
-    
-    xpos = x_pos;
-    xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
-    ypos = 1.0 - y_pos;
-    ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
-
-    GS_get_from(from);
-    
-    tempx = xpos * RANGE - RANGE_OFFSET;
-    tempy = ypos * RANGE - RANGE_OFFSET;
-
-    if ((from[X] != tempx) || (from[Y] != tempy)) {
-
-	from[X] = tempx;
-	from[Y] = tempy;
-
-	GS_moveto(from);
-
-	draw_quick(data);
-    }
-
-    return 1;
-}
-
-/*!
-  \brief Change viewpoint height
-
-  \param data nviz data
-  \param height height value (world coordinates)
-
-  \return 1
-*/
-int viewpoint_set_height(nv_data *data, float height)
-{
-    float from[3];
-
-    GS_get_from_real(from);
-
-    if (height != from[Z]) {
-	from[Z] = height;
-
-	GS_moveto_real(from);
-
-	/*
-	   normalize (from);
-	   GS_setlight_position(1, from[X], from[Y], from[Z], 0);
-	*/
-
-	draw_quick(data);
-    }
-
-    return 1;
-}
-
-/*!
-  \brief Change viewpoint perspective (field of view)
-
-  \param data nviz data
-  \param persp perspective value (0-100, in degrees)
-
-  \return 1
-*/
-int viewpoint_set_persp(nv_data *data, int persp)
-{
-    int fov;
-
-    fov = (int) (10 * persp);
-    GS_set_fov(fov);
-
-    draw_quick(data);
-
-    return 1;
-}
-
-/*!
-  \brief Change viewpoint twist
-
-  \param data nviz data
-  \param persp twist value (-180-180, in degrees)
-
-  \return 1
-*/
-int viewpoint_set_twist(nv_data *data, int twist)
-{
-    GS_set_twist(10 * twist);
-    
-    draw_quick(data);
-
-    return 1;
-}
-
-/*!
-  \brief Change z-exag value
-
-  \param data nviz data
-  \param exag exag value
-
-  \return 1
-*/
-int change_exag(nv_data *data, float exag)
-{
-    float temp;
-
-    temp = GS_global_exag();
-
-    if (exag != temp) {
-	GS_set_global_exag(exag);
-	update_ranges(data);
-	
-	draw_quick(data);
-    }
-
-    return 1;
-}

Deleted: grass-addons/visualization/nviz2/cmd/draw.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/draw.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/draw.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -1,368 +0,0 @@
-/*!
-  \file draw.c
- 
-  \brief Draw map objects to GLX context
-  
-  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/draw.c and
-  visualization/nviz/src/togl_flythrough.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"
-
-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;
-    int sortSurfs[MAX_SURFS], sorti[MAX_SURFS];
-    int *surf_list;
-    float x, y, z;
-    int num, w;
-
-/* Get position for Light 1 */
-    num = 1;
-    x = dc->light[num].x;
-    y = dc->light[num].y;
-    z = dc->light[num].z;
-    w = dc->light[num].z;
-
-    surf_list = GS_get_surf_list(&nsurfs);
-
-    sort_surfs_max(surf_list, sortSurfs, sorti, nsurfs);
-
-    G_free (surf_list);
-
-/* re-initialize lights */
-    GS_setlight_position(num, x, y, z, w);
-    num = 2;
-    GS_setlight_position(num, 0., 0., 1., 0);
-
-    for (i = 0; i < nsurfs; i++) {
-	if (!check_blank(sortSurfs[i])) {
-	    GS_draw_surf(sortSurfs[i]);
-	}
-    }
-    
-    /* GS_draw_cplane_fence params will change - surfs aren't used anymore */
-    for (i = 0; i < MAX_CPLANES; i++) {
-	if (dc->cp_on[i])
-	    GS_draw_cplane_fence(sortSurfs[0], sortSurfs[1], i);
-    }
-
-    return 1;
-}
-
-/*!
-  \brief Sorts surfaces by max elevation, lowest to highest.
-
-  Puts ordered id numbers in id_sort, leaving id_orig unchanged.
-  Puts ordered indices of surfaces from id_orig in indices.
-
-  \param surf pointer to surface array
-  \param id_sort
-  \param indices
-  \param num
-
-  \return 1
-*/
-int sort_surfs_max(int *surf, int *id_sort, int *indices, int num)
-{
-    int i, j;
-    float maxvals[MAX_SURFS];
-    float tmp, max=0., tmin, tmax, tmid;
-
-    for (i = 0; i < num; i++) {
-	GS_get_zextents(surf[i], &tmin, &tmax, &tmid);
-	if (i == 0)
-	    max = tmax;
-	else
-	    max = max < tmax ? tmax : max;
-	maxvals[i] = tmax;
-    }
-
-    for (i = 0; i < num; i++) {
-	tmp = maxvals[0];
-	indices[i] = 0;
-	for (j = 0; j < num; j++) {
-	    if (maxvals[j] < tmp) {
-		tmp = maxvals[j];
-		indices[i] = j;
-	    }
-	}
-
-	maxvals[indices[i]] = max + 1;
-	id_sort[i] = surf[indices[i]];
-    }
-
-    return 1;
-}
-
-/*
-  \brief Check if a specific map object should be blanked for
-  a draw.
-
-  This option is used by one of the script tools for
-  blanking maps during specific frames.
-  
-  \param map_id map object id
-
-  \return 0 not blank
-  \return 1 blank
-*/
-int check_blank(int map_id)
-{
-    return 0;
-}
-
-int draw_all(nv_data *data)
-{
-    int draw_surf, draw_vect, draw_site, draw_vol;
-    int draw_north_arrow, arrow_x, draw_label, draw_legend;
-    int draw_fringe, draw_scalebar, draw_bar_x;
-    // const char* draw_is_drawing = Tcl_GetVar(interp, "is_drawing", TCL_GLOBAL_ONLY);
-    // const char* EMPTYSTRING = "";
-
-    draw_surf = 1;
-    draw_vect = 1;
-    draw_site = 0;
-    draw_vol = 0;
-    draw_north_arrow = 0;
-    arrow_x = 0;
-    draw_label = 0;
-    draw_legend = 0;
-    draw_fringe = 0;
-    draw_scalebar = 0;
-    draw_bar_x = 0;
-
-    /*
-    if (buf_is_drawing && atoi(buf_is_drawing))
-	return (TCL_OK);
-    */
-
-    // Tcl_SetVar(interp, "is_drawing", "1", TCL_GLOBAL_ONLY);
-    
-    GS_set_draw(GSD_BACK); /* needs to be BACK to avoid flickering */
-    GS_clear(data->bgcolor);
-    GS_ready_draw();
-
-/*
-    buf_surf     = Tcl_GetVar(interp, "surface", TCL_GLOBAL_ONLY);
-    buf_vect     = Tcl_GetVar(interp, "vector", TCL_GLOBAL_ONLY);
-    buf_site     = Tcl_GetVar(interp, "sites", TCL_GLOBAL_ONLY);
-    buf_vol      = Tcl_GetVar(interp, "volume", TCL_GLOBAL_ONLY);
-    buf_north_arrow = Tcl_GetVar(interp, "n_arrow", TCL_GLOBAL_ONLY);
-    arrow_x      = Tcl_GetVar(interp, "n_arrow_x", TCL_GLOBAL_ONLY);
-    buf_label    = Tcl_GetVar(interp, "labels", TCL_GLOBAL_ONLY);
-    buf_legend   = Tcl_GetVar(interp, "legend", TCL_GLOBAL_ONLY);
-    buf_fringe   = Tcl_GetVar(interp, "fringe", TCL_GLOBAL_ONLY);
-    buf_scalebar = Tcl_GetVar(interp, "scalebar", TCL_GLOBAL_ONLY);
-    bar_x        = Tcl_GetVar(interp, "scalebar_x", TCL_GLOBAL_ONLY);
-*/  
-    if (draw_surf)
-	draw_all_surf(data);
-
-    if (draw_vect)
-	draw_all_vect (data);
-
-    if (draw_site)
-	; // site_draw_all_together(data, interp);
-
-    if (draw_vol)
-	; // vol_draw_all_cmd(data, interp, argc, argv);
-    
-    GS_done_draw();
-    GS_set_draw(GSD_BACK);
-    
-    if (!draw_north_arrow)
-	; // draw_north_arrow = EMPTYSTRING; 
-    
-    if (!arrow_x)
-	; // arrow_x = EMPTYSTRING; 
-    
-    if (!draw_scalebar)
-	; // draw_scalebar = EMPTYSTRING; 
-    
-    if (!draw_bar_x)
-	; // bar_x = EMPTYSTRING; 
-    
-    if (!draw_fringe)
-	; // draw_fringe = EMPTYSTRING; 
-    
-    if (!draw_label)
-	; // draw_label = EMPTYSTRING; 
-    
-    if (!draw_legend)
-	; // draw_legend = EMPTYSTRING; 
-    
-    /* Draw decorations */
-    
-    /* North Arrow
-    if (atoi(draw_north_arrow) == 1 && atoi(arrow_x) != 999 ) {
-	const char *arrow_y, *arrow_z, *arrow_len;
-	float coords[3], len;
-	int arrow_clr, text_clr;
-	
-	arrow_y = Tcl_GetVar(interp, "n_arrow_y", TCL_GLOBAL_ONLY);
-	arrow_z = Tcl_GetVar(interp, "n_arrow_z", TCL_GLOBAL_ONLY);
-	arrow_len = Tcl_GetVar(interp, "n_arrow_size", TCL_GLOBAL_ONLY);
-	arrow_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "arw_clr", TCL_GLOBAL_ONLY));
-	text_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "arw_text_clr", TCL_GLOBAL_ONLY));
-	coords[0] = atoi(arrow_x);
-	coords[1] = atoi(arrow_y);
-	coords[2] = atoi(arrow_z);
-	len = atof(arrow_len);
-	
-	FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
-	gsd_north_arrow(coords, len, FontBase, arrow_clr, text_clr);
-    }
-    */
-
-    /* Scale Bar
-    if (atoi(draw_scalebar) == 1 && atoi(bar_x) != 999 ) {
-	const char *bar_y, *bar_z, *bar_len;
-	float coords[3], len;
-	int bar_clr, text_clr;
-	
-	bar_y = Tcl_GetVar(interp, "scalebar_y", TCL_GLOBAL_ONLY);
-	bar_z = Tcl_GetVar(interp, "scalebar_z", TCL_GLOBAL_ONLY);
-	bar_len = Tcl_GetVar(interp, "scalebar_size", TCL_GLOBAL_ONLY);
-	bar_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "bar_clr", TCL_GLOBAL_ONLY));
-	text_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "bar_text_clr", TCL_GLOBAL_ONLY));
-	coords[0] = atoi(bar_x);
-	coords[1] = atoi(bar_y);
-	coords[2] = atoi(bar_z);
-	len = atof(bar_len);
-	
-	FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
-	gsd_scalebar(coords, len, FontBase, bar_clr, bar_clr);
-    }
-    */
-
-    /* fringe
-    if (atoi(draw_fringe) == 1) {
-	const char *fringe_ne, *fringe_nw, *fringe_se, *fringe_sw;
-	const char *surf_id;
-	int flags[4], id;
-	int fringe_clr;
-	float fringe_elev;
-	
-	fringe_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "fringe_color", TCL_GLOBAL_ONLY));
-	fringe_elev = (float) atof(Tcl_GetVar(interp, "fringe_elev", TCL_GLOBAL_ONLY));
-	fringe_ne = Tcl_GetVar(interp, "fringe_ne", TCL_GLOBAL_ONLY);
-	fringe_nw = Tcl_GetVar(interp, "fringe_nw", TCL_GLOBAL_ONLY);
-	fringe_se = Tcl_GetVar(interp, "fringe_se", TCL_GLOBAL_ONLY);
-	fringe_sw = Tcl_GetVar(interp, "fringe_sw", TCL_GLOBAL_ONLY);
-	flags[0] = atoi(fringe_nw);
-	flags[1] = atoi(fringe_ne);
-	flags[2] = atoi(fringe_sw);
-	flags[3] = atoi(fringe_se);
-	surf_id = Tcl_GetVar2(interp, "Nv_", "CurrSurf", TCL_GLOBAL_ONLY);
-	id = atoi(surf_id);
-	
-	GS_draw_fringe(id, fringe_clr, fringe_elev, flags);
-    }
-    */
-
-    /* Legend and/or labels
-    if (atoi(draw_label) == 1 || atoi(draw_legend) == 1)
-	GS_draw_all_list();
-    */
-
-    // Tcl_SetVar(interp, "is_drawing", "0", TCL_GLOBAL_ONLY);
-    // flythrough_postdraw_cb();
-    
-    return 1;
-}
-
-int draw_quick(nv_data *dc)
-{
-    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(surf_list[i])) {
-	    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();
-
-    // flythrough_postdraw_cb();
-
-    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;
-}

Deleted: grass-addons/visualization/nviz2/cmd/exag.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/exag.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/exag.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -1,72 +0,0 @@
-/*!
-  \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;
-}

Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-20 11:23:53 UTC (rev 31764)
@@ -16,38 +16,6 @@
 void parse_command(int, char**, struct GParams *);
 int color_from_cmd(const char *);
 
-/* change_view.c */
-int update_ranges(nv_data *);
-int viewpoint_set_position(nv_data *,
-			   float, float);
-int viewpoint_set_height(nv_data *,
-			 float);
-int viewpoint_set_persp(nv_data *, int);
-int viewpoint_set_twist(nv_data *, int);
-void resize_window(int, int);
-int change_exag(nv_data *, float);
-
-/* draw.c */
-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 *);
-int set_attr(int, int, int, int, const char *, float,
-	     nv_data *);
-void set_att_default();
-
-/* position.c */
-void init_view();
-int focus_set_state(int);
-int focus_set_map(int, int);
-
 /* write_img.c */
 int write_img(const char *, int);
 

Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -72,9 +72,9 @@
     /* initialize nviz data */
     Nviz_init_data(&data);
     /* define default attributes for map objects */
-    set_att_default();
+    Nviz_set_attr_default();
     /* set background color */
-    Nviz_set_bgcolor(&data, color_from_cmd(params->bgcolor->answer)); 
+    Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer)); 
 
     /* load data */
     nelev = ncolor_map = ncolor_const = 0;
@@ -97,9 +97,9 @@
 	    }
 	    
 	    /* topography */
-	    id = new_map_obj(MAP_OBJ_SURF,
-			     G_fully_qualified_name(params->elev->answers[i], mapset),
-			     &data);
+	    id = Nviz_new_map_obj(MAP_OBJ_SURF,
+				  G_fully_qualified_name(params->elev->answers[i], mapset),
+				  &data);
 
 	    if (i < ncolor_map) { /* check for color map */
 		mapset = G_find_cell2 (params->color_map->answers[i], "");
@@ -108,19 +108,19 @@
 				  params->color_map->answers[i]);
 		}
 
-		set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
-			 G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
-			 &data);
+		Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+			      G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
+			      &data);
 	    }
 	    else if (i < ncolor_const) { /* check for color value */
-		set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
-			 NULL, color_from_cmd(params->color_const->answers[i]),
-			 &data);
+		Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+			      NULL, Nviz_color_from_str(params->color_const->answers[i]),
+			      &data);
 	    }
 	    else { /* use by default elevation map for coloring */
-		set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
-			 G_fully_qualified_name(params->elev->answers[i], mapset), -1.0,
-			 &data);
+		Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+			      G_fully_qualified_name(params->elev->answers[i], mapset), -1.0,
+			      &data);
 	    }
 	    
 	    /*
@@ -136,7 +136,7 @@
 	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);
+	    Nviz_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);
@@ -148,15 +148,15 @@
 		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);
+	    Nviz_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);
+    Nviz_init_view();
+    Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
 
     /* set lights */
     /* TODO: add options */
@@ -194,25 +194,25 @@
 	vp_height = atof(params->height->answer);
     }
     else {
-	exag_get_height(&vp_height, NULL, NULL);
+	Nviz_get_exag_height(&vp_height, NULL, NULL);
     }
-    viewpoint_set_height(&data,
-			 vp_height);
-    change_exag(&data,
-		atof(params->exag->answer));
-    viewpoint_set_position(&data,
-			   atof(params->pos->answers[0]),
-			   atof(params->pos->answers[1]));
-    viewpoint_set_twist(&data,
-			atoi(params->twist->answer));
-    viewpoint_set_persp(&data,
-			atoi(params->persp->answer));
+    Nviz_set_viewpoint_height(&data,
+			      vp_height);
+    Nviz_change_exag(&data,
+		     atof(params->exag->answer));
+    Nviz_set_viewpoint_position(&data,
+				atof(params->pos->answers[0]),
+				atof(params->pos->answers[1]));
+    Nviz_set_viewpoint_twist(&data,
+			     atoi(params->twist->answer));
+    Nviz_set_viewpoint_persp(&data,
+			     atoi(params->persp->answer));
 
     GS_clear(data.bgcolor);
 
     /* draw */
     Nviz_draw_cplane(&data, -1, -1);
-    draw_all (&data);
+    Nviz_draw_all (&data);
 
     ret = 0;
     if (strcmp(params->format->answer, "ppm") == 0)

Deleted: grass-addons/visualization/nviz2/cmd/map_obj.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/map_obj.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/map_obj.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -1,285 +0,0 @@
-/*!
-  \file map_obj.c
- 
-  \brief Define creation and interface functions for map objects.
-  
-  Map objects are considered to be surfaces, vector plots,
-  or site files.
-
-  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/map_obj.c
-
-  \author Updated/modified by Martin Landa <landa.martin gmail.com>
-
-  \date 2008
-*/
-
-#include <stdlib.h>
-#include <time.h>
-
-#include <grass/gsurf.h>
-#include <grass/gstypes.h>
-#include <grass/glocale.h>
-
-#include "local_proto.h"
-
-/*!
-  \brief Create a new map object which can be one of surf, vect, vol or site.
-
-  This routine creates the object
-  internally in the gsf library and links a new tcl/tk
-  command to the general object command parser below.
-  Optionally, a logical name may be specified for the new map
-  object.  If no name is specified, a logical name is assigned to
-  the new object automatically.  Note that maintaining unique
-  logical names is not the responsibility of the library (currently).
-  
-  Initially map objects contain no data, use the
-  attribute commands to set attributes such as topology,
-  color, etc.
-
-  \param data
-  \param interp
-  \param argc
-  \param argv
-
-  \return map object id
-  \return -1 on error
-*/
-int new_map_obj(int type, const char *name,
-		nv_data *data)
-{
-    int new_id, i;
-    int num_surfs, *surf_list;
-
-    nv_clientdata *client_data;
-
-/*
- * For each type of map obj do the following --
- *   1) Verify we havn't maxed out the number of
- *      allowed objects.
- *   2) Call the internal library to generate a new
- *      map object of the specified type.
- *   3) Create a new tcl/tk command with the new object
- *      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!"));
-	    return -1;
-	}
-
-	new_id = GS_new_surface();
-
-	if (new_id < 0) {
-	    return -1;
-	}
-	
-	if (name) {
-	    /* map */
-	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, MAP_ATT, name, -1.0,
-			  data)) {
-		return -1;
-	    }
-	}
-	else {
-	    /* constant */
-	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, NULL, 0.0,
-			  data)) {
-		return -1;
-	    }
-	}	  
-    }
-    /* vector overlay */
-    else if (type == MAP_OBJ_VECT) {
-	if (GV_num_vects() >= MAX_VECTS) {
-	    G_warning (_("Maximum vectors loaded!"));
-	    return -1;
-	}
-
-	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) {
-	client_data->logical_name = G_store(name);
-    }
-    else {
-	char temp_space[80];
-	time_t tp;
-	
-	/* Need to generate a random id */
-	time(&tp);
-	switch (type) {
-	case MAP_OBJ_SURF: {
-	    sprintf(temp_space, "%s*%ld", "surface", tp);
-	    break;
-	}
-	default: {
-	    sprintf(temp_space, "%s*%ld", "unknown", tp);
-	    break;
-	}
-	}
-	client_data->logical_name = G_store (temp_space);
-    }
-    
-    G_debug(3, "new_map_obj(): logical name=%s",
-	    client_data->logical_name);
-    
-    GS_Set_ClientData(new_id, (void *) client_data);
-    
-    return new_id;
-}
-
-/*!
-  Set map object attribute
-
-  \param id map object id
-  \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
-  \param desc attribute descriptors
-  \param src attribute sources
-  \param str_value attribute value as string (if NULL, check for <i>num_value</i>)
-  \param num_value attribute value as float 
-
-  \return 1 on success
-  \return 0 on failure
-*/
-int set_attr(int id, int type, int desc, int src,
-	     const char *str_value, float num_value,
-	     nv_data *data)
-{
-    int ret;
-    float value;
-    
-    switch (type) {
-    case(MAP_OBJ_SURF): {
-	/* Basically two cases, either we are setting to a constant field, or
-	 * we are loading an actual file. Setting a constant is the easy part
-	 * so we try and do that first.
-	 */
-	if (src == CONST_ATT) {
-	    /* Get the value for the constant
-	     * Note that we require the constant to be an integer
-	     */
-	    if (str_value)
-		value = (float) atof(str_value);
-	    else
-		value = num_value;
-	    
-	    /* Only special case is setting constant color.
-	     * In this case we have to decode the constant Tcl
-	     * returns so that the gsf library understands it.
-	     */
-	    if (desc == ATT_COLOR) {
-		/* TODO check this - sometimes gets reversed when save state
-		   saves a surface with constant color
-
-		int r, g, b;
-		r = (((int) value) & RED_MASK) >> 16;
-		g = (((int) value) & GRN_MASK) >> 8;
-		b = (((int) value) & BLU_MASK);
-		value = r + (g << 8) + (b << 16);
-		*/
-	    }
-	    
-	    /* Once the value is parsed, set it */
-	    ret = GS_set_att_const(id, desc, value);
-	}
-	else if (src == MAP_ATT) {
-	    ret = GS_load_att_map(id, str_value, desc);
-	}
-	
-	/* After we've loaded a constant map or a file,
-	 * may need to adjust resolution if we are resetting
-	 * topology (for example)
-	 */
-	if (0 <= ret) {
-	    if (desc == ATT_TOPO) {
-		int rows, cols, max;
-		int max2;
-		
-		/* If topology attribute is being set then need to set
-		 * resolution of incoming map to some sensible value so we
-		 * don't wait all day for drawing.
-		 */
-		GS_get_dims(id, &rows, &cols);
-		max = (rows > cols) ? rows : cols;
-		max = max / 50;
-		if (max < 1)
-		    max = 1;
-		max2 = max / 5;
-		if (max2 < 1)
-		    max2 = 1;
-		/* reset max to finer for coarse surf drawing */
-		max = max2 + max2/2;
-		if (max < 1)
-		    max = 1;
-		
-		GS_set_drawres(id, max2, max2, max, max);
-		GS_set_drawmode(id, DM_GOURAUD | DM_POLY | DM_GRID_SURF);
-	    }
-	    
-	    /* Not sure about this next line, should probably just
-	     * create separate routines to figure the Z range as well
-	     * as the XYrange
-	     */
-	    update_ranges(data);
-	    
-	    break;
-	}
-	default: {
-	    return 0;
-	}
-    }
-    }
-    
-    return 1;
-}
-
-/*!
-  \brief Set default map object attributes
-*/
-void set_att_default()
-{
-    float defs[MAX_ATTS];
-    
-    defs[ATT_TOPO] = 0;
-    defs[ATT_COLOR] = DEFAULT_SURF_COLOR;
-    defs[ATT_MASK] = 0;
-    defs[ATT_TRANSP] = 0;
-    defs[ATT_SHINE] = 60;
-    defs[ATT_EMIT] = 0;
-
-    GS_set_att_defaults(defs, defs);
-
-    return;
-}
-

Deleted: grass-addons/visualization/nviz2/cmd/position.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/position.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/cmd/position.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -1,108 +0,0 @@
-/*!
-  \file position.c
- 
-  \brief Position, focus settings
-  
-  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/position.c
-
-  \author Updated/modified by Martin Landa <landa.martin gmail.com>
-
-  \date 2008
-*/
-
-#include <grass/gsurf.h>
-#include <grass/gstypes.h>
-#include <grass/glocale.h>
-
-#include "local_proto.h"
-
-/*!
-  Initialize view and position settings (focus)
-
-  Set position to center of view
-*/
-void init_view()
-{
-    GS_init_view();
-    focus_set_state(1); /* center of view */
-
-    return;
-}
-
-/*!
-  \brief Set focus state
-
-  \param state_flag 1 for center view, 0 use viewdir
-
-  \return 1 on success
-  \return 0 on failure
-*/
-int focus_set_state(int state_flag)
-{
-    if (state_flag == 1)
-	GS_set_infocus(); /* return center of view */
-    else if (state_flag == 0)
-	GS_set_nofocus(); /* no center of view -- use viewdir */
-    else {
-	G_warning (_("Unable to set focus"));
-	return 0;
-    }
-    
-    return 1;
-}
-
-/*!
-  \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 focus_set_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;
-}

Modified: grass-addons/visualization/nviz2/lib/change_view.c
===================================================================
--- grass-addons/visualization/nviz2/lib/change_view.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/lib/change_view.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -49,3 +49,166 @@
 
     return ret;
 }
+
+/*!
+  \brief Update ranges
+
+  Call whenever a new surface is added, deleted, or exag changes
+
+  \return 1
+*/
+int Nviz_update_ranges(nv_data *dc)
+{
+    float zmin, zmax, exag;
+
+    GS_get_longdim(&(dc->xyrange));
+
+    dc->zrange = 0.;
+
+    /* Zrange is based on a minimum of Longdim */
+    if (GS_global_exag()) {
+	exag = GS_global_exag();
+	dc->zrange = dc->xyrange / exag;
+    }
+    else {
+	exag = 1.0;
+    }
+
+    GS_get_zrange_nz(&zmin, &zmax);	/* actual */
+
+    zmax = zmin + (3. * dc->xyrange / exag);
+    zmin = zmin - (2. * dc->xyrange / exag);
+
+    if ((zmax - zmin) > dc->zrange)
+	dc->zrange = zmax - zmin;
+
+    return 1;
+}
+
+/*!
+  \brief Change position of view
+
+  \param data nviz data
+  \param x_pos,y_pos x,y position (model coordinates)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_position(nv_data *data,
+				float x_pos, float y_pos)
+{
+    float xpos, ypos, from[3];
+    float tempx, tempy;
+    
+    xpos = x_pos;
+    xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
+    ypos = 1.0 - y_pos;
+    ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
+
+    GS_get_from(from);
+    
+    tempx = xpos * RANGE - RANGE_OFFSET;
+    tempy = ypos * RANGE - RANGE_OFFSET;
+
+    if ((from[X] != tempx) || (from[Y] != tempy)) {
+
+	from[X] = tempx;
+	from[Y] = tempy;
+
+	GS_moveto(from);
+
+	Nviz_draw_quick(data);
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Change viewpoint height
+
+  \param data nviz data
+  \param height height value (world coordinates)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_height(nv_data *data, float height)
+{
+    float from[3];
+
+    GS_get_from_real(from);
+
+    if (height != from[Z]) {
+	from[Z] = height;
+
+	GS_moveto_real(from);
+
+	/*
+	   normalize (from);
+	   GS_setlight_position(1, from[X], from[Y], from[Z], 0);
+	*/
+
+	Nviz_draw_quick(data);
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Change viewpoint perspective (field of view)
+
+  \param data nviz data
+  \param persp perspective value (0-100, in degrees)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_persp(nv_data *data, int persp)
+{
+    int fov;
+
+    fov = (int) (10 * persp);
+    GS_set_fov(fov);
+
+    Nviz_draw_quick(data);
+
+    return 1;
+}
+
+/*!
+  \brief Change viewpoint twist
+
+  \param data nviz data
+  \param persp twist value (-180-180, in degrees)
+
+  \return 1
+*/
+int Nviz_set_viewpoint_twist(nv_data *data, int twist)
+{
+    GS_set_twist(10 * twist);
+    
+    Nviz_draw_quick(data);
+
+    return 1;
+}
+
+/*!
+  \brief Change z-exag value
+
+  \param data nviz data
+  \param exag exag value
+
+  \return 1
+*/
+int Nviz_change_exag(nv_data *data, float exag)
+{
+    float temp;
+
+    temp = GS_global_exag();
+
+    if (exag != temp) {
+	GS_set_global_exag(exag);
+	Nviz_update_ranges(data);
+	
+	Nviz_draw_quick(data);
+    }
+
+    return 1;
+}

Copied: grass-addons/visualization/nviz2/lib/draw.c (from rev 31762, grass-addons/visualization/nviz2/cmd/draw.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/draw.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/draw.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,365 @@
+/*!
+  \file draw.c
+ 
+  \brief Nviz library -- Draw map objects to GLX context
+  
+  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/draw.c and
+  visualization/nviz/src/togl_flythrough.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/nviz.h>
+
+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 Nviz_draw_all_surf(nv_data *dc)
+{
+    int i, nsurfs;
+    int sortSurfs[MAX_SURFS], sorti[MAX_SURFS];
+    int *surf_list;
+    float x, y, z;
+    int num, w;
+
+/* Get position for Light 1 */
+    num = 1;
+    x = dc->light[num].x;
+    y = dc->light[num].y;
+    z = dc->light[num].z;
+    w = dc->light[num].z;
+
+    surf_list = GS_get_surf_list(&nsurfs);
+
+    sort_surfs_max(surf_list, sortSurfs, sorti, nsurfs);
+
+    G_free (surf_list);
+
+/* re-initialize lights */
+    GS_setlight_position(num, x, y, z, w);
+    num = 2;
+    GS_setlight_position(num, 0., 0., 1., 0);
+
+    for (i = 0; i < nsurfs; i++) {
+	if (!check_blank(sortSurfs[i])) {
+	    GS_draw_surf(sortSurfs[i]);
+	}
+    }
+    
+    /* GS_draw_cplane_fence params will change - surfs aren't used anymore */
+    for (i = 0; i < MAX_CPLANES; i++) {
+	if (dc->cp_on[i])
+	    GS_draw_cplane_fence(sortSurfs[0], sortSurfs[1], i);
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Sorts surfaces by max elevation, lowest to highest.
+
+  Puts ordered id numbers in id_sort, leaving id_orig unchanged.
+  Puts ordered indices of surfaces from id_orig in indices.
+
+  \param surf pointer to surface array
+  \param id_sort
+  \param indices
+  \param num
+
+  \return 1
+*/
+int sort_surfs_max(int *surf, int *id_sort, int *indices, int num)
+{
+    int i, j;
+    float maxvals[MAX_SURFS];
+    float tmp, max=0., tmin, tmax, tmid;
+
+    for (i = 0; i < num; i++) {
+	GS_get_zextents(surf[i], &tmin, &tmax, &tmid);
+	if (i == 0)
+	    max = tmax;
+	else
+	    max = max < tmax ? tmax : max;
+	maxvals[i] = tmax;
+    }
+
+    for (i = 0; i < num; i++) {
+	tmp = maxvals[0];
+	indices[i] = 0;
+	for (j = 0; j < num; j++) {
+	    if (maxvals[j] < tmp) {
+		tmp = maxvals[j];
+		indices[i] = j;
+	    }
+	}
+
+	maxvals[indices[i]] = max + 1;
+	id_sort[i] = surf[indices[i]];
+    }
+
+    return 1;
+}
+
+/*
+  \brief Check if a specific map object should be blanked for
+  a draw.
+
+  This option is used by one of the script tools for
+  blanking maps during specific frames.
+  
+  \param map_id map object id
+
+  \return 0 not blank
+  \return 1 blank
+*/
+int check_blank(int map_id)
+{
+    return 0;
+}
+
+int Nviz_draw_all(nv_data *data)
+{
+    int draw_surf, draw_vect, draw_site, draw_vol;
+    int draw_north_arrow, arrow_x, draw_label, draw_legend;
+    int draw_fringe, draw_scalebar, draw_bar_x;
+    // const char* draw_is_drawing = Tcl_GetVar(interp, "is_drawing", TCL_GLOBAL_ONLY);
+    // const char* EMPTYSTRING = "";
+
+    draw_surf = 1;
+    draw_vect = 1;
+    draw_site = 0;
+    draw_vol = 0;
+    draw_north_arrow = 0;
+    arrow_x = 0;
+    draw_label = 0;
+    draw_legend = 0;
+    draw_fringe = 0;
+    draw_scalebar = 0;
+    draw_bar_x = 0;
+
+    /*
+    if (buf_is_drawing && atoi(buf_is_drawing))
+	return (TCL_OK);
+    */
+
+    // Tcl_SetVar(interp, "is_drawing", "1", TCL_GLOBAL_ONLY);
+    
+    GS_set_draw(GSD_BACK); /* needs to be BACK to avoid flickering */
+    GS_clear(data->bgcolor);
+    GS_ready_draw();
+
+/*
+    buf_surf     = Tcl_GetVar(interp, "surface", TCL_GLOBAL_ONLY);
+    buf_vect     = Tcl_GetVar(interp, "vector", TCL_GLOBAL_ONLY);
+    buf_site     = Tcl_GetVar(interp, "sites", TCL_GLOBAL_ONLY);
+    buf_vol      = Tcl_GetVar(interp, "volume", TCL_GLOBAL_ONLY);
+    buf_north_arrow = Tcl_GetVar(interp, "n_arrow", TCL_GLOBAL_ONLY);
+    arrow_x      = Tcl_GetVar(interp, "n_arrow_x", TCL_GLOBAL_ONLY);
+    buf_label    = Tcl_GetVar(interp, "labels", TCL_GLOBAL_ONLY);
+    buf_legend   = Tcl_GetVar(interp, "legend", TCL_GLOBAL_ONLY);
+    buf_fringe   = Tcl_GetVar(interp, "fringe", TCL_GLOBAL_ONLY);
+    buf_scalebar = Tcl_GetVar(interp, "scalebar", TCL_GLOBAL_ONLY);
+    bar_x        = Tcl_GetVar(interp, "scalebar_x", TCL_GLOBAL_ONLY);
+*/  
+    if (draw_surf)
+	Nviz_draw_all_surf(data);
+
+    if (draw_vect)
+	Nviz_draw_all_vect (data);
+
+    if (draw_site)
+	; // site_draw_all_together(data, interp);
+
+    if (draw_vol)
+	; // vol_draw_all_cmd(data, interp, argc, argv);
+    
+    GS_done_draw();
+    GS_set_draw(GSD_BACK);
+    
+    if (!draw_north_arrow)
+	; // draw_north_arrow = EMPTYSTRING; 
+    
+    if (!arrow_x)
+	; // arrow_x = EMPTYSTRING; 
+    
+    if (!draw_scalebar)
+	; // draw_scalebar = EMPTYSTRING; 
+    
+    if (!draw_bar_x)
+	; // bar_x = EMPTYSTRING; 
+    
+    if (!draw_fringe)
+	; // draw_fringe = EMPTYSTRING; 
+    
+    if (!draw_label)
+	; // draw_label = EMPTYSTRING; 
+    
+    if (!draw_legend)
+	; // draw_legend = EMPTYSTRING; 
+    
+    /* Draw decorations */
+    
+    /* North Arrow
+    if (atoi(draw_north_arrow) == 1 && atoi(arrow_x) != 999 ) {
+	const char *arrow_y, *arrow_z, *arrow_len;
+	float coords[3], len;
+	int arrow_clr, text_clr;
+	
+	arrow_y = Tcl_GetVar(interp, "n_arrow_y", TCL_GLOBAL_ONLY);
+	arrow_z = Tcl_GetVar(interp, "n_arrow_z", TCL_GLOBAL_ONLY);
+	arrow_len = Tcl_GetVar(interp, "n_arrow_size", TCL_GLOBAL_ONLY);
+	arrow_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "arw_clr", TCL_GLOBAL_ONLY));
+	text_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "arw_text_clr", TCL_GLOBAL_ONLY));
+	coords[0] = atoi(arrow_x);
+	coords[1] = atoi(arrow_y);
+	coords[2] = atoi(arrow_z);
+	len = atof(arrow_len);
+	
+	FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
+	gsd_north_arrow(coords, len, FontBase, arrow_clr, text_clr);
+    }
+    */
+
+    /* Scale Bar
+    if (atoi(draw_scalebar) == 1 && atoi(bar_x) != 999 ) {
+	const char *bar_y, *bar_z, *bar_len;
+	float coords[3], len;
+	int bar_clr, text_clr;
+	
+	bar_y = Tcl_GetVar(interp, "scalebar_y", TCL_GLOBAL_ONLY);
+	bar_z = Tcl_GetVar(interp, "scalebar_z", TCL_GLOBAL_ONLY);
+	bar_len = Tcl_GetVar(interp, "scalebar_size", TCL_GLOBAL_ONLY);
+	bar_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "bar_clr", TCL_GLOBAL_ONLY));
+	text_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "bar_text_clr", TCL_GLOBAL_ONLY));
+	coords[0] = atoi(bar_x);
+	coords[1] = atoi(bar_y);
+	coords[2] = atoi(bar_z);
+	len = atof(bar_len);
+	
+	FontBase = load_font(TOGL_BITMAP_HELVETICA_18);
+	gsd_scalebar(coords, len, FontBase, bar_clr, bar_clr);
+    }
+    */
+
+    /* fringe
+    if (atoi(draw_fringe) == 1) {
+	const char *fringe_ne, *fringe_nw, *fringe_se, *fringe_sw;
+	const char *surf_id;
+	int flags[4], id;
+	int fringe_clr;
+	float fringe_elev;
+	
+	fringe_clr = (int) tcl_color_to_int(Tcl_GetVar(interp, "fringe_color", TCL_GLOBAL_ONLY));
+	fringe_elev = (float) atof(Tcl_GetVar(interp, "fringe_elev", TCL_GLOBAL_ONLY));
+	fringe_ne = Tcl_GetVar(interp, "fringe_ne", TCL_GLOBAL_ONLY);
+	fringe_nw = Tcl_GetVar(interp, "fringe_nw", TCL_GLOBAL_ONLY);
+	fringe_se = Tcl_GetVar(interp, "fringe_se", TCL_GLOBAL_ONLY);
+	fringe_sw = Tcl_GetVar(interp, "fringe_sw", TCL_GLOBAL_ONLY);
+	flags[0] = atoi(fringe_nw);
+	flags[1] = atoi(fringe_ne);
+	flags[2] = atoi(fringe_sw);
+	flags[3] = atoi(fringe_se);
+	surf_id = Tcl_GetVar2(interp, "Nv_", "CurrSurf", TCL_GLOBAL_ONLY);
+	id = atoi(surf_id);
+	
+	GS_draw_fringe(id, fringe_clr, fringe_elev, flags);
+    }
+    */
+
+    /* Legend and/or labels
+    if (atoi(draw_label) == 1 || atoi(draw_legend) == 1)
+	GS_draw_all_list();
+    */
+
+    // Tcl_SetVar(interp, "is_drawing", "0", TCL_GLOBAL_ONLY);
+    // flythrough_postdraw_cb();
+    
+    return 1;
+}
+
+int Nviz_draw_quick(nv_data *dc)
+{
+    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(surf_list[i])) {
+	    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();
+
+    // flythrough_postdraw_cb();
+
+    return 1;
+}
+
+/*!
+  \brief Draw all loaded vector sets
+
+  \param dc nviz data
+
+  \return 1
+*/
+int Nviz_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;
+}

Copied: grass-addons/visualization/nviz2/lib/exag.c (from rev 31762, grass-addons/visualization/nviz2/cmd/exag.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/exag.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/exag.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,69 @@
+/*!
+  \file exag.c
+ 
+  \brief Nviz library -- 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> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/nviz.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 Nviz_get_exag_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;
+}

Copied: grass-addons/visualization/nviz2/lib/map_obj.c (from rev 31762, grass-addons/visualization/nviz2/cmd/map_obj.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/map_obj.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/map_obj.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,282 @@
+/*!
+  \file map_obj.c
+ 
+  \brief Nviz library -- Define creation and interface functions for map objects.
+  
+  Map objects are considered to be surfaces, vector plots,
+  or site files.
+
+  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/map_obj.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <stdlib.h>
+#include <time.h>
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief Create a new map object which can be one of surf, vect, vol or site.
+
+  This routine creates the object
+  internally in the gsf library and links a new tcl/tk
+  command to the general object command parser below.
+  Optionally, a logical name may be specified for the new map
+  object.  If no name is specified, a logical name is assigned to
+  the new object automatically.  Note that maintaining unique
+  logical names is not the responsibility of the library (currently).
+  
+  Initially map objects contain no data, use the
+  attribute commands to set attributes such as topology,
+  color, etc.
+
+  \param data
+  \param interp
+  \param argc
+  \param argv
+
+  \return map object id
+  \return -1 on error
+*/
+int Nviz_new_map_obj(int type, const char *name,
+		     nv_data *data)
+{
+    int new_id, i;
+    int num_surfs, *surf_list;
+
+    nv_clientdata *client_data;
+
+/*
+ * For each type of map obj do the following --
+ *   1) Verify we havn't maxed out the number of
+ *      allowed objects.
+ *   2) Call the internal library to generate a new
+ *      map object of the specified type.
+ *   3) Create a new tcl/tk command with the new object
+ *      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!"));
+	    return -1;
+	}
+
+	new_id = GS_new_surface();
+
+	if (new_id < 0) {
+	    return -1;
+	}
+	
+	if (name) {
+	    /* map */
+	    if (!Nviz_set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, MAP_ATT, name, -1.0,
+			  data)) {
+		return -1;
+	    }
+	}
+	else {
+	    /* constant */
+	    if (!Nviz_set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, NULL, 0.0,
+			       data)) {
+		return -1;
+	    }
+	}	  
+    }
+    /* vector overlay */
+    else if (type == MAP_OBJ_VECT) {
+	if (GV_num_vects() >= MAX_VECTS) {
+	    G_warning (_("Maximum vectors loaded!"));
+	    return -1;
+	}
+
+	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) {
+	client_data->logical_name = G_store(name);
+    }
+    else {
+	char temp_space[80];
+	time_t tp;
+	
+	/* Need to generate a random id */
+	time(&tp);
+	switch (type) {
+	case MAP_OBJ_SURF: {
+	    sprintf(temp_space, "%s*%ld", "surface", tp);
+	    break;
+	}
+	default: {
+	    sprintf(temp_space, "%s*%ld", "unknown", tp);
+	    break;
+	}
+	}
+	client_data->logical_name = G_store (temp_space);
+    }
+    
+    G_debug(3, "new_map_obj(): logical name=%s",
+	    client_data->logical_name);
+    
+    GS_Set_ClientData(new_id, (void *) client_data);
+    
+    return new_id;
+}
+
+/*!
+  Set map object attribute
+
+  \param id map object id
+  \param type map object type (MAP_OBJ_SURF, MAP_OBJ_VECT, ...)
+  \param desc attribute descriptors
+  \param src attribute sources
+  \param str_value attribute value as string (if NULL, check for <i>num_value</i>)
+  \param num_value attribute value as float 
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_set_attr(int id, int type, int desc, int src,
+		  const char *str_value, float num_value,
+		  nv_data *data)
+{
+    int ret;
+    float value;
+    
+    switch (type) {
+    case(MAP_OBJ_SURF): {
+	/* Basically two cases, either we are setting to a constant field, or
+	 * we are loading an actual file. Setting a constant is the easy part
+	 * so we try and do that first.
+	 */
+	if (src == CONST_ATT) {
+	    /* Get the value for the constant
+	     * Note that we require the constant to be an integer
+	     */
+	    if (str_value)
+		value = (float) atof(str_value);
+	    else
+		value = num_value;
+	    
+	    /* Only special case is setting constant color.
+	     * In this case we have to decode the constant Tcl
+	     * returns so that the gsf library understands it.
+	     */
+	    if (desc == ATT_COLOR) {
+		/* TODO check this - sometimes gets reversed when save state
+		   saves a surface with constant color
+
+		int r, g, b;
+		r = (((int) value) & RED_MASK) >> 16;
+		g = (((int) value) & GRN_MASK) >> 8;
+		b = (((int) value) & BLU_MASK);
+		value = r + (g << 8) + (b << 16);
+		*/
+	    }
+	    
+	    /* Once the value is parsed, set it */
+	    ret = GS_set_att_const(id, desc, value);
+	}
+	else if (src == MAP_ATT) {
+	    ret = GS_load_att_map(id, str_value, desc);
+	}
+	
+	/* After we've loaded a constant map or a file,
+	 * may need to adjust resolution if we are resetting
+	 * topology (for example)
+	 */
+	if (0 <= ret) {
+	    if (desc == ATT_TOPO) {
+		int rows, cols, max;
+		int max2;
+		
+		/* If topology attribute is being set then need to set
+		 * resolution of incoming map to some sensible value so we
+		 * don't wait all day for drawing.
+		 */
+		GS_get_dims(id, &rows, &cols);
+		max = (rows > cols) ? rows : cols;
+		max = max / 50;
+		if (max < 1)
+		    max = 1;
+		max2 = max / 5;
+		if (max2 < 1)
+		    max2 = 1;
+		/* reset max to finer for coarse surf drawing */
+		max = max2 + max2/2;
+		if (max < 1)
+		    max = 1;
+		
+		GS_set_drawres(id, max2, max2, max, max);
+		GS_set_drawmode(id, DM_GOURAUD | DM_POLY | DM_GRID_SURF);
+	    }
+	    
+	    /* Not sure about this next line, should probably just
+	     * create separate routines to figure the Z range as well
+	     * as the XYrange
+	     */
+	    Nviz_update_ranges(data);
+	    
+	    break;
+	}
+	default: {
+	    return 0;
+	}
+    }
+    }
+    
+    return 1;
+}
+
+/*!
+  \brief Set default map object attributes
+*/
+void Nviz_set_attr_default()
+{
+    float defs[MAX_ATTS];
+    
+    defs[ATT_TOPO] = 0;
+    defs[ATT_COLOR] = DEFAULT_SURF_COLOR;
+    defs[ATT_MASK] = 0;
+    defs[ATT_TRANSP] = 0;
+    defs[ATT_SHINE] = 60;
+    defs[ATT_EMIT] = 0;
+
+    GS_set_att_defaults(defs, defs);
+
+    return;
+}
+

Modified: grass-addons/visualization/nviz2/lib/nviz.c
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.c	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/lib/nviz.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -16,6 +16,7 @@
   \date 2008
 */
 
+#include <grass/glocale.h>
 #include <grass/nviz.h>
 
 /*!
@@ -59,3 +60,23 @@
     
     return;
 }
+
+/*!
+  \brief Get color value from color string (name or RGB triplet)
+
+  \param color_str color string
+
+  \return color value
+*/
+int Nviz_color_from_str(const char *color_str)
+{
+    int red, grn, blu;
+
+    if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
+	G_warning (_("Invalid color (%s), using \"white\" as default"),
+		   color_str);
+	red = grn = blu = 255;
+    }
+
+    return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) + ((int)((blu) << 16) & BLU_MASK);
+}

Modified: grass-addons/visualization/nviz2/lib/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.h	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/lib/nviz.h	2008-06-20 11:23:53 UTC (rev 31764)
@@ -112,12 +112,29 @@
 
 /* change_view.c */
 int Nviz_resize_window(int, int);
+int Nviz_update_ranges(nv_data *);
+int Nviz_set_viewpoint_position(nv_data *,
+				float, float);
+int Nviz_set_viewpoint_height(nv_data *,
+			      float);
+int Nviz_set_viewpoint_persp(nv_data *, int);
+int Nviz_set_viewpoint_twist(nv_data *, int);
+int Nviz_change_exag(nv_data *, float);
 
 /* cplanes_obj.c */
 int Nviz_new_cplane(nv_data *, int);
 int Nviz_off_cplane(nv_data *, int);
 int Nviz_draw_cplane(nv_data *, int, int);
 
+/* draw.c */
+int Nviz_draw_all_surf(nv_data *);
+int Nviz_draw_all(nv_data *);
+int Nviz_draw_quick(nv_data *);
+int Nviz_draw_all_vect(nv_data *);
+
+/* exag.c */
+int Nviz_get_exag_height(float *, float *, float *);
+
 /* lights.c */
 int Nviz_set_light_position(nv_data *, int,
 			    float, float, float, float);
@@ -129,10 +146,23 @@
 int Nviz_init_light(nv_data *, int);
 int Nviz_new_light(nv_data *);
 
+/* map_obj.c */
+int Nviz_new_map_obj(int, const char *,
+		     nv_data *);
+int Nviz_set_attr(int, int, int, int, const char *, float,
+		  nv_data *);
+void Nviz_set_attr_default();
+
 /* nviz.c */
 void Nviz_init_data(nv_data *);
 void Nviz_set_bgcolor(nv_data *, int);
+int Nviz_color_from_str(const char *);
 
+/* position.c */
+void Nviz_init_view();
+int Nviz_set_focus_state(int);
+int Nviz_set_focus_map(int, int);
+
 /* render.c */
 struct render_window* Nviz_new_render_window();
 void Nviz_init_render_window(struct render_window*);

Copied: grass-addons/visualization/nviz2/lib/position.c (from rev 31762, grass-addons/visualization/nviz2/cmd/position.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/position.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/position.c	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,105 @@
+/*!
+  \file position.c
+ 
+  \brief Nviz library -- Position, focus settings
+  
+  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/position.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  Initialize view and position settings (focus)
+
+  Set position to center of view
+*/
+void Nviz_init_view()
+{
+    GS_init_view();
+    Nviz_set_focus_state(1); /* center of view */
+
+    return;
+}
+
+/*!
+  \brief Set focus state
+
+  \param state_flag 1 for center view, 0 use viewdir
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz_set_focus_state(int state_flag)
+{
+    if (state_flag == 1)
+	GS_set_infocus(); /* return center of view */
+    else if (state_flag == 0)
+	GS_set_nofocus(); /* no center of view -- use viewdir */
+    else {
+	G_warning (_("Unable to set focus"));
+	return 0;
+    }
+    
+    return 1;
+}
+
+/*!
+  \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;
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp	2008-06-20 11:23:53 UTC (rev 31764)
@@ -31,3 +31,23 @@
 {
     return Nviz_resize_window(width, height);
 }
+
+void Nviz::SetViewportDefault()
+{
+    float vp_height;
+    /* determine height */
+    Nviz_get_exag_height(&vp_height, NULL, NULL);
+
+    Nviz_set_viewpoint_height(data,
+			      vp_height);
+    Nviz_change_exag(data,
+		     1.0);
+    Nviz_set_viewpoint_position(data,
+				0.85, 0.85);
+    Nviz_set_viewpoint_twist(data,
+			     0.0);
+    Nviz_set_viewpoint_persp(data,
+			     40);
+
+    return;
+}

Added: grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp	                        (rev 0)
+++ grass-addons/visualization/nviz2/wxpython/nviz/draw.cpp	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,30 @@
+/*!
+  \file draw.cpp
+ 
+  \brief Experimental C++ wxWidgets Nviz prototype -- Draw map objects to GLX context
+  
+  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/draw.c and
+  visualization/nviz/src/togl_flythrough.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include "nviz.h"
+
+void Nviz::Draw()
+{
+    GS_clear(data->bgcolor);
+
+    Nviz_draw_cplane(data, -1, -1);
+    Nviz_draw_all (data);
+
+    return;
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-20 11:23:53 UTC (rev 31764)
@@ -15,7 +15,6 @@
 
    \date 2008
 */
-
 #include "nviz.h"
 
 static void swap_gl();
@@ -32,9 +31,30 @@
 
     GS_set_swap_func(swap_gl);
 
+    data = (nv_data*) G_malloc(sizeof (nv_data));
+
     /* initialize render window */
     rwind = Nviz_new_render_window();
     Nviz_init_render_window(rwind);
+
+    /* GLCanvas */
+    glCanvas = NULL;
+
+    /* initialize nviz data */
+    Nviz_init_data(data);
+    /* define default attributes for map objects */
+    Nviz_set_attr_default();
+    /* set background color */
+    Nviz_set_bgcolor(data, Nviz_color_from_str("white")); /* TODO */
+
+    /* initialize view */
+    Nviz_init_view();
+
+    /* set default lighting model */
+    SetLightsDefault();
+
+    /* clear window */
+    GS_clear(data->bgcolor);
 }
 
 /*!
@@ -45,6 +65,11 @@
     Nviz_destroy_render_window(rwind);
 
     G_free((void *) rwind);
+    G_free((void *) data);
+
+    rwind = NULL;
+    data = NULL;
+    glCanvas = NULL;
 }
 
 /*!
@@ -70,4 +95,3 @@
 {
     return;
 }
-

Added: grass-addons/visualization/nviz2/wxpython/nviz/lights.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/lights.cpp	                        (rev 0)
+++ grass-addons/visualization/nviz2/wxpython/nviz/lights.cpp	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,47 @@
+/**
+   \file load.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- light manipulation
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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.
+
+   \author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+
+#include "nviz.h"
+
+/*!
+  \brief Set default lighting model
+*/
+void Nviz::SetLightsDefault()
+{
+    /* first */
+    Nviz_set_light_position(data, 0,
+			    0.68, -0.68, 0.80, 0.0);
+    Nviz_set_light_bright(data, 0,
+			  0.8);
+    Nviz_set_light_color(data, 0,
+			 1.0, 1.0, 1.0);
+    Nviz_set_light_ambient(data, 0,
+			   0.2, 0.2, 0.2);
+
+    /* second */
+    Nviz_set_light_position(data, 1,
+			    0.0, 0.0, 1.0, 0.0);
+    Nviz_set_light_bright(data, 1,
+			  0.5);
+    Nviz_set_light_color(data, 1,
+			 1.0, 1.0, 1.0);
+    Nviz_set_light_ambient(data, 1,
+			   0.3, 0.3, 0.3);
+
+    return;
+}

Added: grass-addons/visualization/nviz2/wxpython/nviz/load.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/load.cpp	                        (rev 0)
+++ grass-addons/visualization/nviz2/wxpython/nviz/load.cpp	2008-06-20 11:23:53 UTC (rev 31764)
@@ -0,0 +1,82 @@
+/**
+   \file load.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- load data layers
+
+   Used by wxGUI Nviz extension.
+
+   Copyright: (C) 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.
+
+   \author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
+
+   \date 2008
+*/
+
+#include "nviz.h"
+
+extern "C" {
+#include <grass/glocale.h>
+}
+
+/*!
+  \brief Load raster map (surface)
+
+  \param name raster map name
+  \param color_name raster map for color (NULL for color_value)
+  \param color_value color string (named color or RGB triptet)
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int Nviz::LoadRaster(const char* name, const char *color_name, const char *color_value)
+{
+    char *mapset;
+    int id;
+
+    mapset = G_find_cell2 (name, "");
+    if (mapset == NULL) {
+	G_warning(_("Raster map <%s> not found"),
+		  name);
+	return 0;
+    }
+	    
+    /* topography */
+    id = Nviz_new_map_obj(MAP_OBJ_SURF,
+			  G_fully_qualified_name(name, mapset),
+			  data);
+
+    if (color_name) { /* check for color map */
+	mapset = G_find_cell2 (color_name, "");
+	if (mapset == NULL) {
+	    G_warning(_("Raster map <%s> not found"),
+		      color_name);
+	    GS_delete_surface(id);
+	    return 0;
+	}
+
+	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+		      G_fully_qualified_name(color_name, mapset), -1.0,
+		      data);
+    }
+    else if (color_value) { /* check for color value */
+	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+		      NULL, Nviz_color_from_str(color_value),
+		      data);
+    }
+    else { /* use by default elevation map for coloring */
+	Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+		      G_fully_qualified_name(name, mapset), -1.0,
+		      data);
+    }
+	    
+    /*
+      if (i > 1)
+      set_default_wirecolors(data, i);
+    */
+
+    return 1;
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-20 11:23:53 UTC (rev 31764)
@@ -26,6 +26,7 @@
 {
 private:
     struct render_window *rwind;
+    nv_data *data;
     wxGLCanvas *glCanvas;
 
 public:
@@ -35,9 +36,22 @@
     /* destructor */
     ~Nviz();
 
+    int ResizeWindow(int, int);
+
     /* set */
     int SetDisplay(void *);
-    int ResizeWindow(int, int);
+
+    /* lights */
+    void SetLightsDefault();
+    
+    /* viewport */
+    void SetViewportDefault();
+
+    /* load data */
+    int LoadRaster(const char*, const char *, const char *);
+
+    /* draw */
+    void Draw();
 };
 
 #endif /* __NVIZ_H__ */

Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-19 18:55:57 UTC (rev 31763)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-20 11:23:53 UTC (rev 31764)
@@ -43,7 +43,13 @@
     def __init__(self, parent):
         self.parent = parent # MapWindow
 
-        glcanvas.GLCanvas.__init__(self, parent, wx.ID_ANY)
+        glcanvas.GLCanvas.__init__(self, parent, id=wx.ID_ANY)
+#                                    attribList=[wx.WX_GL_RGBA, wx.GLX_RED_SIZE, 1,
+#                                                wx.GLX_GREEN_SIZE, 1,
+#                                                wx.GLX_BLUE_SIZE, 1,
+#                                                wx.GLX_DEPTH_SIZE, 1,
+#                                                None])
+
         self.init = False
 
         #
@@ -85,12 +91,12 @@
         self.SetCurrent()
         if not self.init:
             # self.InitGL()
-            nvizClass.InitView()
+            # nvizClass.InitView()
+            self.nvizClass.LoadRaster("elevation", None, None);
             self.init = True
         self.OnDraw()
 
     def InitGL(self):
-
         # set viewing projection
         glMatrixMode(GL_PROJECTION)
         glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0)
@@ -108,6 +114,10 @@
         glEnable(GL_LIGHT0)
 
     def OnDraw(self):
+        """Draw data layers"""
+        self.nvizClass.Draw()
+
+    def OnDraw1(self):
         # clear color and depth buffers
         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
 



More information about the grass-commit mailing list