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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 19 14:50:41 EDT 2008


Author: martinl
Date: 2008-06-19 14:50:41 -0400 (Thu, 19 Jun 2008)
New Revision: 31762

Added:
   grass-addons/visualization/nviz2/lib/change_view.c
   grass-addons/visualization/nviz2/lib/cplanes_obj.c
   grass-addons/visualization/nviz2/lib/lights.c
   grass-addons/visualization/nviz2/lib/nviz.c
   grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp
Removed:
   grass-addons/visualization/nviz2/cmd/cplanes_obj.c
   grass-addons/visualization/nviz2/cmd/lights.c
   grass-addons/visualization/nviz2/cmd/nviz.c
Modified:
   grass-addons/visualization/nviz2/cmd/change_view.c
   grass-addons/visualization/nviz2/cmd/local_proto.h
   grass-addons/visualization/nviz2/cmd/main.c
   grass-addons/visualization/nviz2/lib/nviz.h
   grass-addons/visualization/nviz2/wxpython/nviz.py
   grass-addons/visualization/nviz2/wxpython/nviz/Makefile
   grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
   grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
Log:
nviz2: wxGUI integration in progress

Modified: grass-addons/visualization/nviz2/cmd/change_view.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/change_view.c	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/cmd/change_view.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -163,23 +163,6 @@
 }
 
 /*!
-  \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();
-}
-
-/*!
   \brief Change z-exag value
 
   \param data nviz data

Deleted: grass-addons/visualization/nviz2/cmd/cplanes_obj.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/cplanes_obj.c	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/cmd/cplanes_obj.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -1,123 +0,0 @@
-/*!
-  \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;
-}

Deleted: grass-addons/visualization/nviz2/cmd/lights.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/lights.c	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/cmd/lights.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -1,154 +0,0 @@
-/*!
-  \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;
-}

Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-19 18:50:41 UTC (rev 31762)
@@ -16,11 +16,6 @@
 void parse_command(int, char**, struct GParams *);
 int color_from_cmd(const char *);
 
-/* 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 *,
@@ -48,21 +43,6 @@
 	     nv_data *);
 void set_att_default();
 
-/* nviz.c */
-void nv_data_init(nv_data *);
-void nv_data_set_bgcolor(nv_data *, int);
-
-/* 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 *);
-
 /* position.c */
 void init_view();
 int focus_set_state(int);

Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -70,11 +70,11 @@
     Nviz_make_current_render_window(offscreen);
 
     /* initialize nviz data */
-    nv_data_init(&data);
+    Nviz_init_data(&data);
     /* define default attributes for map objects */
     set_att_default();
     /* set background color */
-    nv_data_set_bgcolor(&data, color_from_cmd(params->bgcolor->answer)); 
+    Nviz_set_bgcolor(&data, color_from_cmd(params->bgcolor->answer)); 
 
     /* load data */
     nelev = ncolor_map = ncolor_const = 0;
@@ -160,14 +160,14 @@
 
     /* set lights */
     /* TODO: add options */
-    light_set_position(&data, 0,
-		       0.68, -0.68, 0.80, 0.0);
-    light_set_bright(&data, 0,
-		     0.8);
-    light_set_color(&data, 0,
-		    1.0, 1.0, 1.0);
-    light_set_ambient(&data, 0,
-		      0.2, 0.2, 0.2);
+    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);
 
     /*
     light_set_position(&data, 1,
@@ -180,14 +180,14 @@
 		      0.2, 0.2, 0.2);
     */
 
-    light_set_position(&data, 1,
-		       0.0, 0.0, 1.0, 0.0);
-    light_set_bright(&data, 1,
-		     0.5);
-    light_set_color(&data, 1,
-		    1.0, 1.0, 1.0);
-    light_set_ambient(&data, 1,
-		      0.3, 0.3, 0.3);
+    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);
     
     /* define view point */
     if (params->height->answer) {
@@ -208,13 +208,10 @@
     viewpoint_set_persp(&data,
 			atoi(params->persp->answer));
 
-
-    // resize_window(600, 480);
-
     GS_clear(data.bgcolor);
 
     /* draw */
-    cplane_draw(&data, -1, -1);
+    Nviz_draw_cplane(&data, -1, -1);
     draw_all (&data);
 
     ret = 0;

Deleted: grass-addons/visualization/nviz2/cmd/nviz.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.c	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/cmd/nviz.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -1,58 +0,0 @@
-/*!
-  \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);
-    }
-    
-    /* lights */
-    for (i = 0; i < MAX_LIGHTS; i++) {
-	light_new(data);
-    }
-
-    return;
-}
-
-/*!
-  \brief Set background color
-
-  \param color color value
-*/
-void nv_data_set_bgcolor(nv_data *data, int color)
-{
-    data->bgcolor = color;
-    
-    return;
-}

Added: grass-addons/visualization/nviz2/lib/change_view.c
===================================================================
--- grass-addons/visualization/nviz2/lib/change_view.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/change_view.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -0,0 +1,51 @@
+/*!
+  \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> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/nviz.h>
+
+/*!
+  \brief GL canvas resized
+
+  \param width window width
+  \param height window height
+
+  \return 1 on success
+  \return 0 on failure (window resized by dafault to 20x20 px)
+ */
+int Nviz_resize_window(int width, int height)
+{
+    int ret;
+
+    ret = 1;
+
+    if (width < 1 || height < 1) {
+	width = 20;
+	height = 20;
+	ret = 0;
+    }
+
+    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();
+
+    return ret;
+}

Copied: grass-addons/visualization/nviz2/lib/cplanes_obj.c (from rev 31709, grass-addons/visualization/nviz2/cmd/cplanes_obj.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/cplanes_obj.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/cplanes_obj.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -0,0 +1,123 @@
+/*!
+  \file cplanes_obj.c
+ 
+  \brief Nviz library -- 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> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/nviz.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 Nviz_new_cplane(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 Nviz_off_cplane(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 Nviz_draw_cplane(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;
+}

Copied: grass-addons/visualization/nviz2/lib/lights.c (from rev 31709, grass-addons/visualization/nviz2/cmd/lights.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/lights.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/lights.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -0,0 +1,151 @@
+/*!
+  \file lights.c
+ 
+  \brief Nviz library -- 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> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.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 Nviz_set_light_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 Nviz_set_light_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 Nviz_set_light_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 Nviz_set_light_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 Nviz_init_light(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 Nviz_new_light(nv_data *data)
+{
+    int num;
+
+    num = GS_new_light();
+
+    if (num < 1) {
+	G_warning(_("Unable to define new light"));
+	return 0;
+    }
+
+    Nviz_init_light(data, num - 1);
+
+    return 1;
+}

Copied: grass-addons/visualization/nviz2/lib/nviz.c (from rev 31709, grass-addons/visualization/nviz2/cmd/nviz.c)
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/nviz.c	2008-06-19 18:50:41 UTC (rev 31762)
@@ -0,0 +1,61 @@
+/*!
+  \file nviz.c
+ 
+  \brief Nviz library -- Data management
+  
+  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> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/nviz.h>
+
+/*!
+  \brief Initialize Nviz data
+
+  \param data nviz data
+*/
+void Nviz_init_data(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++) {
+	Nviz_new_cplane(data, i);
+	Nviz_off_cplane(data, i);
+    }
+    
+    /* lights */
+    for (i = 0; i < MAX_LIGHTS; i++) {
+	Nviz_new_light(data);
+    }
+
+    return;
+}
+
+/*!
+  \brief Set background color
+
+  \param data nviz data
+  \param color color value
+*/
+void Nviz_set_bgcolor(nv_data *data, int color)
+{
+    data->bgcolor = color;
+    
+    return;
+}

Modified: grass-addons/visualization/nviz2/lib/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.h	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/lib/nviz.h	2008-06-19 18:50:41 UTC (rev 31762)
@@ -110,13 +110,35 @@
     GLXPixmap windowId;
 };
 
+/* change_view.c */
+int Nviz_resize_window(int, int);
+
+/* 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);
+
+/* lights.c */
+int Nviz_set_light_position(nv_data *, int,
+			    float, float, float, float);
+int Nviz_set_light_bright(nv_data *, int, float);
+int Nviz_set_light_color(nv_data *, int,
+			 float, float, float);
+int Nviz_set_light_ambient(nv_data *, int,
+			   float, float, float);
+int Nviz_init_light(nv_data *, int);
+int Nviz_new_light(nv_data *);
+
+/* nviz.c */
+void Nviz_init_data(nv_data *);
+void Nviz_set_bgcolor(nv_data *, int);
+
 /* render.c */
 struct render_window* Nviz_new_render_window();
 void Nviz_init_render_window(struct render_window*);
 void Nviz_destroy_render_window(struct render_window *);
 int Nviz_create_render_window(struct render_window *, void *,
 			      int, int);
-
 int Nviz_make_current_render_window(const struct render_window *);
 
 #endif /* GRASS_NVIZ_H */

Modified: grass-addons/visualization/nviz2/wxpython/nviz/Makefile
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/Makefile	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/wxpython/nviz/Makefile	2008-06-19 18:50:41 UTC (rev 31762)
@@ -3,12 +3,16 @@
 
 include $(MODULE_TOPDIR)/include/Make/Lib.make
 
+# TODO
+NVIZLIB= -lgrass_nviz $(GISLIB)
+# NVIZDEP=$(ARCH_LIBDIR)/$(LIB_PREFIX)grass_nviz$(LIB_SUFFIX)
+
 LIB_NAME = grass6_wxnviz
 SOURCES := $(wildcard *.cpp) $(LIB_NAME)_wrap.cpp
 SHLIB_OBJS := $(patsubst %.cpp, $(OBJDIR)/%.o, $(SOURCES))
 
 EXTRA_CFLAGS = $(SHLIB_CFLAGS) $(GDALCFLAGS) $(PYTHONCFLAGS) $(WXWIDGETSCXXFLAGS) $(XCFLAGS) $(XMINC)
-EXTRA_LIBS = $(GISLIB) $(WXWIDGETSLIB) $(PYTHONLDFLAGS) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB)
+EXTRA_LIBS = $(GISLIB) $(WXWIDGETSLIB) $(PYTHONLDFLAGS) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB) $(NVIZLIB)
 
 LOCAL_HEADERS = nviz.h
 

Added: grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp	                        (rev 0)
+++ grass-addons/visualization/nviz2/wxpython/nviz/change_view.cpp	2008-06-19 18:50:41 UTC (rev 31762)
@@ -0,0 +1,33 @@
+/**
+   \file change_view.cpp
+   
+   \brief Experimental C++ wxWidgets Nviz prototype -- Change viewport
+
+   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 GL canvas resized
+
+  \param width window width
+  \param height window height
+
+  \return 1 on success
+  \return 0 on failure (window resized by dafault to 20x20 px)
+ */
+int Nviz::ResizeWindow(int width, int height)
+{
+    return Nviz_resize_window(width, height);
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-19 18:50:41 UTC (rev 31762)
@@ -48,26 +48,26 @@
 }
 
 /*!
-  \brief Swap GL buffers
-*/
-void swap_gl()
-{
-    return;
-}
-
-/*!
   \brief Associate display with render window
 
   \return 1 on success
   \return 0 on failure
 */
-int Nviz::SetDisplay(void *display, int width, int height)
+int Nviz::SetDisplay(void *display)
 {
     if (!rwind)
 	return 0;
 
-    Nviz_create_render_window(rwind, display, width, height);
-    Nviz_make_current_render_window(rwind);
+    glCanvas = (wxGLCanvas *) display;
 
+    //Nviz_create_render_window(rwind, display, width, height);
+    //Nviz_make_current_render_window(rwind);
+
     return 1;
 }
+
+void swap_gl()
+{
+    return;
+}
+

Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-19 18:50:41 UTC (rev 31762)
@@ -8,11 +8,25 @@
 #include <grass/nviz.h>
 }
 
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+// Include your minimal set of headers here, or wx.h
+#include <wx/wx.h>
+#endif
+
+#include <wx/glcanvas.h>
+
 class Nviz
 {
 private:
-    // struct render_window *rwind;
     struct render_window *rwind;
+    wxGLCanvas *glCanvas;
 
 public:
     /* constructor */
@@ -22,7 +36,8 @@
     ~Nviz();
 
     /* set */
-    int SetDisplay(void *, int, int);
+    int SetDisplay(void *);
+    int ResizeWindow(int, int);
 };
 
 #endif /* __NVIZ_H__ */

Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-19 18:25:31 UTC (rev 31761)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-19 18:50:41 UTC (rev 31762)
@@ -49,8 +49,13 @@
         #
         # create nviz instance
         #
-        nvizClass = wxnviz.Nviz()
+        self.nvizClass = wxnviz.Nviz()
 
+        #
+        # set current display
+        #
+        self.nvizClass.SetDisplay(self)
+
         # initialize mouse position
         self.lastx = self.x = 30
         self.lasty = self.y = 30
@@ -70,7 +75,8 @@
         size = self.size = self.parent.GetClientSize()
         if self.GetContext():
             self.SetCurrent()
-            glViewport(0, 0, size.width, size.height)
+            # glViewport(0, 0, size.width, size.height)
+            self.nvizClass.ResizeWindow(size.width, size.height)
         
         event.Skip()
 
@@ -78,11 +84,13 @@
         dc = wx.PaintDC(self)
         self.SetCurrent()
         if not self.init:
-            self.InitGL()
+            # self.InitGL()
+            nvizClass.InitView()
             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)



More information about the grass-commit mailing list