[GRASS-SVN] r31648 - grass-addons/visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 6 11:03:37 EDT 2008


Author: martinl
Date: 2008-06-06 11:03:37 -0400 (Fri, 06 Jun 2008)
New Revision: 31648

Added:
   grass-addons/visualization/nviz2/cmd/Makefile
   grass-addons/visualization/nviz2/cmd/args.c
   grass-addons/visualization/nviz2/cmd/change_view.c
   grass-addons/visualization/nviz2/cmd/cplanes_obj.c
   grass-addons/visualization/nviz2/cmd/draw.c
   grass-addons/visualization/nviz2/cmd/lights.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.c
   grass-addons/visualization/nviz2/cmd/nviz.h
   grass-addons/visualization/nviz2/cmd/render.c
   grass-addons/visualization/nviz2/cmd/render.h
   grass-addons/visualization/nviz2/cmd/write_img.c
Log:
Initial experimental NVIZ CLI prototype (under progress)

Added: grass-addons/visualization/nviz2/cmd/Makefile
===================================================================
--- grass-addons/visualization/nviz2/cmd/Makefile	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/Makefile	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,40 @@
+#MODULE_TOPDIR = ../../..
+MODULE_TOPDIR = $(HOME)/src/grass6_devel
+
+PGM = nviz_cmd
+
+ifeq ($(OPENGL_X11),1)
+OGL_LIBS := $(OPENGLULIB) $(OPENGLLIB) $(XLIBPATH) $(XLIB) -lXmu -lXext $(XEXTRALIBS) $(MATHLIB)
+endif
+ifeq ($(OPENGL_WINDOWS),1)
+OGL_LIBS := $(OPENGLULIB) $(OPENGLLIB) -lgdi32 $(MATHLIB)
+endif
+ifeq ($(OPENGL_AQUA),1)
+OGL_LIBS := $(OPENGLULIB) $(OPENGLLIB) $(MATHLIB)
+endif
+
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(INC) \
+	$(TIFFINCPATH) $(DSPINC) \
+	$(VECT_CFLAGS) $(OPENGLINC) 
+
+ifeq ($(OPENGL_X11),1)
+EXTRA_CFLAGS += $(XCFLAGS)
+endif
+
+XTRA_LDFLAGS = $(OGL_LIBS)
+
+LIBES = $(BITMAPLIB) $(LINKMLIB) $(VECTLIB) $(SITESLIB) $(FORMLIB) $(DBMILIB) \
+	$(G3DLIB) $(GISLIB) $(XDRLIB) \
+	$(DATETIMELIB) $(XTRA_LDFLAGS) $(TIFFLIBPATH) $(TIFFLIB) \
+	$(MATHLIB)
+DEPENDENCIES = $(VECTDEP) $(BITMAPDEP) $(LINKMDEP) $(FORMDEP) $(DBMIDEP) $(GISDEP) $(OGSFDEP)	
+
+EXTRA_CFLAGS=$(XCFLAGS) $(XMINC)
+
+LIBES = $(GISLIB) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd


Property changes on: grass-addons/visualization/nviz2/cmd/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/x-sh
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/args.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,87 @@
+/*!
+  \file args.c
+ 
+  \brief Parse command
+  
+  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.
+
+  \author Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/*!
+   \brief Parse command
+
+   \param argc number of arguments
+   \param argv arguments array
+   \param params GRASS parameters
+
+   \return 1
+*/
+void parse_command(int argc, char* argv[], struct GParams *params)
+{
+    params->elev = G_define_standard_option(G_OPT_R_ELEV);
+    params->elev->required = YES;
+    params->elev->multiple = YES;
+    params->elev->description = _("Name of raster map(s) for elevation");
+    params->elev->guisection = _("Raster");
+
+    params->pos = G_define_option();
+    params->pos->key = "position";
+    params->pos->key_desc = "x,y";
+    params->pos->type = TYPE_DOUBLE;
+    params->pos->required = NO;
+    params->pos->multiple = NO;
+    params->pos->description = _("Viewpoint position (x,y model coordinates)");
+    params->pos->guisection = _("Viewpoint");
+    params->pos->answer = "0.85,0.85";
+
+    params->height = G_define_option();
+    params->height->key = "height";
+    params->height->key_desc = "value";
+    params->height->type = TYPE_INTEGER;
+    params->height->required = NO;
+    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";
+    params->persp->key_desc = "value";
+    params->persp->type = TYPE_INTEGER;
+    params->persp->required = NO;
+    params->persp->multiple = NO;
+    params->persp->description = _("Viewpoint field of view (in degrees)");
+    params->persp->guisection = _("Viewpoint");
+    params->persp->answer = "40";
+    params->persp->options = "0-100";
+
+    params->twist = G_define_option();
+    params->twist->key = "twist";
+    params->twist->key_desc = "value";
+    params->twist->type = TYPE_INTEGER;
+    params->twist->required = NO;
+    params->twist->multiple = NO;
+    params->twist->description = _("Viewpoint twist angle (in degrees)");
+    params->twist->guisection = _("Viewpoint");
+    params->twist->answer = "0";
+    params->twist->options = "-180-180";
+
+    if (G_parser(argc, argv))
+        exit(EXIT_FAILURE);
+
+    return;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/args.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/change_view.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/change_view.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/change_view.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,180 @@
+/*!
+  \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 Map canvas resized
+
+  \param width window width
+  \param height window height
+ */
+void resize_window(int width, int height)
+{
+    GS_set_viewport(0, width, 0, height);
+
+/*   GS_clear(0x0000FF); causes red flash - debug only */
+    GS_set_draw(GSD_BACK);
+    GS_ready_draw();
+    GS_alldraw_wire();
+    GS_done_draw();
+}


Property changes on: grass-addons/visualization/nviz2/cmd/change_view.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/cplanes_obj.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/cplanes_obj.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/cplanes_obj.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,123 @@
+/*!
+  \file cplanes_obj.c
+ 
+  \brief Clip planes manipulation
+  
+  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/cutplanes_obj.c
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include "local_proto.h"
+
+static void cp_draw(nv_data *, int, int, int);
+
+/*!
+  \brief Creates a clip plane object
+   
+  The number of clip planes is fixed (MAX_CPLANES) and
+  we'll create them all ahead of time anyway we just let
+  the user decide on the id for each.
+*/
+int cplane_new(nv_data *data, int id)
+{
+    data->num_cplanes++;
+    /* Initialize internal attributes for this cutplane */
+    data->cp_rot[id][X] = data->cp_rot[id][Y] = data->cp_rot[id][Z] = 0.0;
+    data->cp_trans[id][X] = data->cp_trans[id][Y] = data->cp_trans[id][Z] = 0.0;
+    data->cp_on[id] = 0;
+
+    return 1;
+}
+
+/*!
+  \brief Turn off (make inactive) the given clip plane
+
+  \param data nviz data
+  \param cplane id
+*/
+int cplane_off(nv_data *data, int id)
+{
+    data->cp_on[id] = 0;
+    GS_unset_cplane(id);
+
+    return 1;
+}
+
+/*!
+   \brief Draw the clip plane
+
+   \param bound1
+   \param bound2
+*/
+int cplane_draw(nv_data *data, int bound1, int bound2)
+{
+    cp_draw(data, data->cur_cplane, bound1, bound2);
+
+    return 1;
+}
+
+/*!
+  \brief Draw current clip plane
+
+  \param data nviz data
+  \param current id of current clip plane
+  \param surf1 first surface id
+  \param surf2 second surface id
+*/
+void cp_draw(nv_data *data, int current, int surf1, int surf2)
+{
+    int i, nsurfs;
+    int surf_min=0, surf_max=0, temp;
+    int *surf_list;
+
+    GS_set_draw(GSD_BACK);
+    GS_clear(data->bgcolor);
+    GS_ready_draw();
+
+    /* If surf boundaries present then find them */
+    surf_list = GS_get_surf_list(&nsurfs);
+    if ((surf1 != -1) && (surf2 != -1)) {
+	for (i = 0; i < nsurfs; i++) {
+	    if (surf_list[i] == surf1)
+		surf_min = i;
+	    if (surf_list[i] == surf2)
+		surf_max = i;
+	}
+
+	if (surf_max < surf_min) {
+	    temp = surf_min;
+	    surf_min = surf_max;
+	    surf_max = temp;
+	}
+
+	surf_max++;
+    }
+    else {
+	surf_min = 0;
+	surf_max = nsurfs;
+    }
+
+    if (nsurfs > 1) {
+	for (i = 0; i < MAX_CPLANES; i++) {
+	    if (data->cp_on[i])
+		GS_draw_cplane_fence(surf_list[0], surf_list[1], i);
+	}
+    }
+
+    for (i = surf_min; i < surf_max; i++) {
+	GS_draw_wire(surf_list[i]);
+    }
+
+    GS_done_draw();
+
+    return;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/cplanes_obj.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/draw.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/draw.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/draw.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,325 @@
+/*!
+  \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);
+
+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 = 0;
+    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)
+	; // vect_draw_all_together(data, interp);
+
+    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;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/draw.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/lights.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/lights.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/lights.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,154 @@
+/*!
+  \file lights.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/lights.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"
+
+/*!
+  \brief Set light position
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param x,y,z,w position, model coordinates
+*/
+int light_set_position(nv_data *data, int num,
+		       float x, float y, float z, float w)
+{
+    data->light[num].id = num + 1;
+    data->light[num].x = x;
+    data->light[num].y = y;
+    data->light[num].z = z;
+    data->light[num].w = w;
+
+    GS_setlight_position(num + 1, x, y, z, w);
+
+    return 1;
+}
+
+/*!
+  \brief Set light brightness
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param value brightness value
+*/
+int light_set_bright(nv_data * data, int num, float value)
+{
+    float r, g, b;
+
+    data->light[num].brt = value;
+
+    r = data->light[num].r * data->light[num].brt;
+    g = data->light[num].g * data->light[num].brt;
+    b = data->light[num].b * data->light[num].brt;
+
+    GS_setlight_color(num + 1, r, g, b);
+
+    return 1;
+}
+
+/*!
+  \brief Set light color
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param red,green,blue rGB values (0-1)
+*/
+int light_set_color(nv_data * data, int num,
+		    float red, float green, float blue)
+{
+    float r, g, b;
+
+    data->light[num].r = red;
+    data->light[num].g = green;
+    data->light[num].b = blue;
+
+    r = data->light[num].r * data->light[num].brt;
+    g = data->light[num].g * data->light[num].brt;
+    b = data->light[num].b * data->light[num].brt;
+
+    GS_setlight_color(num + 1, r, g, b);
+
+    return 1;
+}
+
+/*!
+  \brief Set light ambient
+
+  \param data nviz data
+  \param num light num (starts with 0)
+  \param red,green,blue rGB values (0-1)
+*/
+int light_set_ambient(nv_data *data, int num,
+		      float red, float green, float blue)
+{
+    data->light[num].ar = red;
+    data->light[num].ag = green;
+    data->light[num].ab = blue;
+
+    GS_setlight_ambient(num + 1, red, green, blue);
+
+    return 1;
+}
+
+/*!
+  \brief Init new light
+
+  \param data nviz data
+  \param num light num (starts with 0)
+*/
+int light_init(nv_data *data, int num)
+{
+    if (num >= MAX_LIGHTS) {
+	return 0;
+    }
+
+    data->light[num].id = 0;
+    data->light[num].brt = 0.8;
+    data->light[num].ar = 0.3;
+    data->light[num].ag = 0.3;
+    data->light[num].ab = 0.3;
+    data->light[num].r = 1.0;
+    data->light[num].b = 1.0;
+    data->light[num].g = 1.0;
+    data->light[num].x = 1.0;
+    data->light[num].y = 1.0;
+    data->light[num].z = 1.0;
+    data->light[num].w = 1.0;
+
+    return 1;
+}
+
+int light_new(nv_data *data)
+{
+    int num;
+
+    num = GS_new_light();
+
+    if (num < 1) {
+	G_warning(_("Unable to define new light"));
+	return 0;
+    }
+
+    light_init(data, num - 1);
+
+    return 1;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/lights.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,67 @@
+#ifndef __LOCAL_PROTO_H__
+#define __LOCAL_PROTO_H__
+
+#include "render.h"
+#include "nviz.h"
+
+/* module flags and parameters */
+struct GParams { 
+  struct Option *elev, /* data */
+    *pos, *height, *persp, *twist; /* viewpoint */
+};
+
+/* args.c */
+void parse_command(int, char**, struct GParams *);
+
+/* cplanes_obj.c */
+int cplane_new(nv_data *, int);
+int cplane_off(nv_data *, int);
+int cplane_draw(nv_data *, int, int);
+
+/* 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);
+
+/* draw.c */
+int draw_all_surf(nv_data *);
+int draw_all(nv_data *);
+int draw_quick(nv_data *);
+
+/* map_obj.c */
+int new_map_obj(int, const char *,
+		nv_data *);
+int set_attr(int, int, int, int, const char *,
+	     nv_data *);
+void set_att_default();
+
+/* nviz.c */
+void nv_data_init(nv_data *);
+
+/* lights.c */
+int light_set_position(nv_data *, int,
+		       float, float, float, float);
+int light_set_bright(nv_data *, int, float);
+int light_set_color(nv_data *, int,
+		    float, float, float);
+int light_set_ambient(nv_data *, int,
+		      float, float, float);
+int light_init(nv_data *, int);
+int light_new(nv_data *);
+
+/* render.c */
+void render_window_init(render_window *);
+int render_window_create(render_window *, int, int);
+int render_window_destroy(render_window *);
+int render_window_make_current(const render_window *);
+void swap_gl();
+
+/* write_img.c */
+int write_ppm(const char *);
+
+#endif /* __LOCAL_PROTO_H__ */


Property changes on: grass-addons/visualization/nviz2/cmd/local_proto.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,146 @@
+/****************************************************************************
+ *
+ * MODULE:       nviz_cmd
+ *               
+ * AUTHOR(S):    Martin Landa <landa.martin gmail.com>
+ *               
+ * PURPOSE:      Experimental NVIZ CLI prototype
+ *               
+ * 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.
+ *
+ *****************************************************************************/
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+#include "local_proto.h"
+
+int main (int argc, char *argv[])
+{
+    struct GModule *module;
+    struct GParams *params;
+
+    char *mapset;
+    unsigned int i;
+    int id;
+
+    nv_data data;
+    render_window offscreen;
+
+    /* initialize GRASS */
+    G_gisinit(argv[0]);
+
+    module = G_define_module();
+    module->keywords = _("visualization, raster, vector");
+    module->description = _("Experimental NVIZ CLI prototype.");
+
+    params = (struct GParams*) G_malloc(sizeof (struct GParams));
+
+    /* define options, call G_parser() */
+    parse_command(argc, argv, params);
+
+    GS_libinit();
+    /* GVL_libinit(); TODO */
+
+    GS_set_swap_func(swap_gl);
+
+    /* define render window */
+    render_window_init(&offscreen);
+    render_window_create(&offscreen, 640, 480); /* TOD0: option dim */
+    render_window_make_current(&offscreen);
+
+    /* initialize nviz data */
+    nv_data_init(&data);
+    /* define default attributes for map objects */
+    set_att_default();
+
+    /* load data */
+    if (params->elev->answers) {
+	for (i = 0; params->elev->answers[i]; i++) {
+	    mapset = G_find_cell2 (params->elev->answers[i], "");
+	    if (mapset == NULL) {
+		G_fatal_error(_("Raster map <%s> not found"),
+			      params->elev->answers[i]);
+	    }
+	    
+	    /* topography */
+	    id = new_map_obj(MAP_OBJ_SURF,
+			     G_fully_qualified_name(params->elev->answers[i], mapset),
+			     &data);
+
+	    /* color TODO: option */
+	    set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+		     G_fully_qualified_name(params->elev->answers[i], mapset),
+		     &data);
+
+	    /*
+	      if (i > 1)
+	      set_default_wirecolors(data, i);
+	    */
+	}
+    }
+
+    /* define view point */
+    GS_init_view();
+    viewpoint_set_height(&data,
+			 atof(params->height->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));
+
+
+    /* resize_window(400, 400); */
+
+    /*
+    light_set_position(&data, 0,
+		       0.68, -0.68, 0.80, 0.0);
+    light_set_position(&data, 1,
+		       0.68, -0.68, 0.80, 0.0);
+    light_set_position(&data, 2,
+		       0.0, 0.0, 1.0, 0.0);
+    light_set_bright(&data, 0,
+		     0.8);
+    light_set_bright(&data, 1,
+		     0.8);
+    light_set_bright(&data, 2,
+		     0.5);
+    light_set_color(&data, 0,
+		    1.0, 1.0, 1.0);
+    light_set_color(&data, 1,
+		    1.0, 1.0, 1.0);
+    light_set_color(&data, 2,
+		    1.0, 1.0, 1.0);
+    light_set_ambient(&data, 0,
+		      0.2, 0.2, 0.2);
+    light_set_ambient(&data, 1,
+		      0.2, 0.2, 0.2);
+    light_set_ambient(&data, 2,
+		      0.3, 0.3, 0.3);
+    */
+
+
+    GS_clear(data.bgcolor);
+
+    cplane_draw(&data, -1, -1);
+    draw_all (&data);
+
+    write_ppm("test.ppm");
+
+    render_window_destroy(&offscreen);
+
+    G_free ((void *) params);
+
+    exit(EXIT_SUCCESS);
+}


Property changes on: grass-addons/visualization/nviz2/cmd/main.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/map_obj.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/map_obj.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/map_obj.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,248 @@
+/*!
+  \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;
+
+    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.
+ */
+    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,
+			  data)) {
+		return -1;
+	    }
+	}
+	else {
+	    /* constant */
+	    if (!set_attr(new_id, MAP_OBJ_SURF, ATT_TOPO, CONST_ATT, "0",
+			  data)) {
+		return -1;
+	    }
+	}	  
+    }
+
+    /* 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
+
+  \return 1 on success
+  \return 0 on failure
+*/
+int set_attr(int id, int type, int desc, int src, const char *str_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
+	     */
+	    value = (float) atof(str_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 */
+		/* Tcl code and C code reverse RGB to BGR (sigh) */
+		int r, g, b;
+		r = (((int) value) & 0xff0000) >> 16;
+		g = (((int) value) & 0x00ff00) >> 8;
+		b = (((int) value) & 0x0000ff);
+		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;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/map_obj.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/nviz.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/nviz.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,48 @@
+/*!
+  \file nviz.c
+ 
+  \brief Nviz subroutines
+  
+  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/
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+#include "local_proto.h"
+
+void nv_data_init(nv_data *data)
+{
+    unsigned int i;
+
+    /* data range */
+    data->zrange = 0;
+    data->xyrange = 0;
+    
+    /* clip planes, turn off by default*/
+    data->num_cplanes = 0;
+    data->cur_cplane = 0;
+    for (i = 0; i < MAX_CPLANES; i++) {
+	cplane_new(data, i);
+	cplane_off(data, i);
+    }
+    
+    data->bgcolor = 16777215; /* TODO: option bgcolor */
+
+    /* lights */
+    for (i = 0; i < MAX_LIGHTS; i++) {
+	light_new(data);
+    }
+
+    return;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/nviz.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.h	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/nviz.h	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,65 @@
+#ifndef __NVIZ_H__
+#define __NVIZ_H__
+
+#include <grass/gsurf.h>
+
+#define MAP_OBJ_SURF 1
+
+#define RANGE (5 * GS_UNIT_SIZE)
+#define RANGE_OFFSET (2 * GS_UNIT_SIZE)
+#define ZRANGE (3 * GS_UNIT_SIZE)
+#define ZRANGE_OFFSET (1 * GS_UNIT_SIZE)
+
+#define DEFAULT_SURF_COLOR 0x33BBFF
+
+/* data structures */
+typedef struct{
+    int id;
+    float brt;
+    float r, g, b;
+    float ar, ag, ab;  /* ambient rgb */
+    float x, y, z, w; /* position */
+} light_data;
+
+typedef struct {
+    /* ranges */
+    float zrange, xyrange;
+    
+    /* cplanes */
+    int num_cplanes;
+    int cur_cplane, cp_on[MAX_CPLANES];
+    float cp_trans[MAX_CPLANES][3];
+    float cp_rot[MAX_CPLANES][3];
+    
+    /* light */
+    light_data light[MAX_LIGHTS];
+    
+    /* background color */
+    int bgcolor;
+} nv_data;
+
+/* The following structure is used to associate client data with surfaces.
+ * We do this so that we don't have to rely on the surface ID (which is libal to change
+ * between subsequent executions of nviz) when saving set-up info to files.
+ */
+
+typedef struct {
+    /* We use logical names to assign textual names to map objects.
+       When Nviz needs to refer to a map object it uses the logical name
+       rather than the map ID.  By setting appropriate logical names, we
+       can reuse names inbetween executions of Nviz.  The Nviz library
+       also provides a mechanism for aliasing between logical names.
+       Thus several logical names may refer to the same map object.
+       Aliases are meant to support the case in which two logical names
+       happen to be the same.  The Nviz library automatically assigns
+       logical names uniquely if they are not specified in the creation
+       of a map object.  When loading a saved file containing several map
+       objects, it is expected that the map 0bjects will be aliased to
+       their previous names.  This ensures that old scripts will work.
+    */
+    
+    char *logical_name;
+    
+} nv_clientdata;
+
+#endif /* __NVIZ_H__ */


Property changes on: grass-addons/visualization/nviz2/cmd/nviz.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/render.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/render.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/render.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,154 @@
+/*!
+  \file render.c
+ 
+  \brief GLX context manipulation
+  
+  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/togl.c etc.
+
+  \author Updated/modified by Martin Landa <landa.martin gmail.com>
+
+  \date 2008
+*/
+
+#include <grass/gis.h>
+#include <grass/glocale.h>
+
+#include "render.h"
+
+/*!
+  \brief Initialize render window
+
+  \param win pointer to render_window struct
+*/
+void render_window_init(render_window * win)
+{
+    win->displayId = NULL;
+    win->contextId = NULL;
+    win->pixmap = 0;
+    win->windowId = 0;
+}
+
+/*!
+  \brief Create rendew window
+
+  \param win pointer to render_window struct
+  \param width window width
+  \param height window height
+
+  \return 1
+*/
+int render_window_create(render_window *win, int width, int height)
+{
+    XVisualInfo  *v;
+
+    int attributeList[] = { GLX_RGBA, GLX_RED_SIZE, 1,
+			    GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
+			    GLX_DEPTH_SIZE, 1, None };
+    /*
+    int attributeList[] = { GLX_USE_GL, GLX_RED_SIZE, 1,
+			    GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
+			    GLX_DEPTH_SIZE, 1, GLX_DOUBLEBUFFER,
+			    None };
+    */
+    /* get the default display connection */
+    win->displayId = XOpenDisplay((char *) NULL);
+    if (!win->displayId) {
+	G_fatal_error (_("Bad X server connection"));
+    }
+
+    /* get visual info and set up pixmap buffer */
+    v = glXChooseVisual(win->displayId,
+			DefaultScreen(win->displayId),
+			attributeList);
+
+    win->contextId = glXCreateContext(win->displayId,
+				      v, NULL, GL_FALSE);
+    if (!win->contextId) {
+	G_fatal_error (_("Unable to create GLX rendering context"));
+    }
+
+    /* create win pixmap to render to (same depth as RootWindow) */
+    win->pixmap = XCreatePixmap(win->displayId,
+				RootWindow(win->displayId, v->screen),
+				width,
+				height,
+				v->depth);
+
+    /* create an off-screen GLX rendering area */
+    win->windowId = glXCreateGLXPixmap(win->displayId,
+				       v, win->pixmap);
+
+    if (v) {
+	XFree(v);
+    }
+
+    /*
+    this->MakeCurrent();
+
+    glMatrixMode( GL_MODELVIEW );
+
+    glDepthFunc( GL_LEQUAL );
+    glEnable( GL_DEPTH_TEST );
+    glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
+    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
+    glEnable(GL_BLEND);
+    glEnable( GL_NORMALIZE );
+    glAlphaFunc(GL_GREATER,0);
+    this->Mapped = 0; // if its mapped, then it trys windowgetattributes which fails!
+    this->SwapBuffers = 0;
+    this->DoubleBuffer = 0;
+    */
+
+    return 1;
+}
+
+/*!
+  \brief Free render window
+
+  \param win pointer to render_window struct
+
+  \return 1
+*/
+int render_window_destroy(render_window *win)
+{
+    glXDestroyContext(win->displayId, win->contextId);
+    XFreePixmap(win->displayId, win->pixmap);
+
+    render_window_init(win);
+
+    return 1;
+}
+
+/*!
+  \brief Make window current for rendering
+
+  \param win pointer to render_window struct
+
+  \return 1
+*/
+int render_window_make_current(const render_window *win)
+{
+    if (!win->displayId || !win->contextId)
+	return 0;
+
+    if (win->contextId == glXGetCurrentContext())
+	return 1;
+
+    glXMakeCurrent(win->displayId, win->windowId,
+		   win->contextId);
+
+    /* TODO: AQUA */
+
+    return 1;
+}
+
+void swap_gl()
+{
+    return;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/render.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/render.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/render.h	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/render.h	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,44 @@
+#ifndef __RENDER_H__
+#define __RENDER_H__
+
+#include <grass/gsurf.h>
+#include <grass/gstypes.h>
+
+/*** Windows headers ***/
+#if defined(OPENGL_WINDOWS)
+#  define WIN32_LEAN_AND_MEAN
+#  include <windows.h>
+#  undef WIN32_LEAN_AND_MEAN
+#  include <winnt.h>
+
+/*** X Window System headers ***/
+#elif defined(OPENGL_X11)
+#  include <X11/Xlib.h>
+#  include <X11/Xutil.h>
+#  include <X11/Xatom.h>        /* for XA_RGB_DEFAULT_MAP atom */
+#  if defined(__vms)
+#    include <X11/StdCmap.h>    /* for XmuLookupStandardColormap */
+#  else
+#    include <X11/Xmu/StdCmap.h>        /* for XmuLookupStandardColormap */
+#  endif
+#  include <GL/glx.h>
+
+/*** Mac headers ***/
+#elif defined(OPENGL_AQUA)
+#  define Cursor QDCursor
+#  include <AGL/agl.h>
+#  undef Cursor
+#  include <ApplicationServices/ApplicationServices.h>
+
+#else /* make sure only one platform defined */
+#  error Unsupported platform, or confused platform defines...
+#endif
+
+typedef struct {
+    Display *displayId; /* display connection */
+    GLXContext contextId; /* GLX rendering context */
+    Pixmap pixmap;
+    GLXPixmap windowId;
+} render_window;
+
+#endif /* __RENDER_H__ */


Property changes on: grass-addons/visualization/nviz2/cmd/render.h
___________________________________________________________________
Name: svn:mime-type
   + text/x-chrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Added: grass-addons/visualization/nviz2/cmd/write_img.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/write_img.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/cmd/write_img.c	2008-06-06 15:03:37 UTC (rev 31648)
@@ -0,0 +1,35 @@
+/*!
+  \file write_img.c
+ 
+  \brief Save current GL screen to image file.
+  
+  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/anim_support.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 Save current GL screen to an ppm file.
+
+  \param name filename
+*/
+
+int write_ppm(const char *name)
+{
+    GS_write_ppm(name);
+    
+    return 1;
+}


Property changes on: grass-addons/visualization/nviz2/cmd/write_img.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native



More information about the grass-commit mailing list