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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 19 10:58:52 EDT 2008


Author: martinl
Date: 2008-06-19 10:58:52 -0400 (Thu, 19 Jun 2008)
New Revision: 31759

Added:
   grass-addons/visualization/nviz2/lib/
   grass-addons/visualization/nviz2/lib/Makefile
   grass-addons/visualization/nviz2/lib/nviz.h
   grass-addons/visualization/nviz2/lib/render.c
   grass-addons/visualization/nviz2/lib/render.h
Removed:
   grass-addons/visualization/nviz2/cmd/nviz.h
   grass-addons/visualization/nviz2/cmd/render.c
   grass-addons/visualization/nviz2/cmd/render.h
Modified:
   grass-addons/visualization/nviz2/cmd/Makefile
   grass-addons/visualization/nviz2/cmd/local_proto.h
   grass-addons/visualization/nviz2/cmd/main.c
   grass-addons/visualization/nviz2/wxpython/mapdisp.py
   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: various updates towards wxNVIZ extension (based on nviz_cmd functionality)

Modified: grass-addons/visualization/nviz2/cmd/Makefile
===================================================================
--- grass-addons/visualization/nviz2/cmd/Makefile	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/cmd/Makefile	2008-06-19 14:58:52 UTC (rev 31759)
@@ -24,17 +24,15 @@
 
 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)
+# TODO
+NVIZLIB= -lgrass_nviz $(GISLIB)
+NVIZDEP=$(ARCH_LIBDIR)/$(LIB_PREFIX)grass_nviz$(LIB_SUFFIX)
 
+LIBES = $(GISLIB) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB) $(NVIZLIB)
+DEPENDENCIES = $(GISDEP) $(NVIZDEP)
+
 include $(MODULE_TOPDIR)/include/Make/Module.make
 
 default: cmd

Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h	2008-06-19 14:58:52 UTC (rev 31759)
@@ -1,8 +1,7 @@
 #ifndef __LOCAL_PROTO_H__
 #define __LOCAL_PROTO_H__
 
-#include "render.h"
-#include "nviz.h"
+#include <grass/nviz.h>
 
 /* module flags and parameters */
 struct GParams { 
@@ -69,13 +68,6 @@
 int focus_set_state(int);
 int focus_set_map(int, int);
 
-/* 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_img(const char *, int);
 

Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/cmd/main.c	2008-06-19 14:58:52 UTC (rev 31759)
@@ -20,11 +20,12 @@
 
 #include <grass/gis.h>
 #include <grass/glocale.h>
-#include <grass/gsurf.h>
-#include <grass/gstypes.h>
+#include <grass/nviz.h>
 
 #include "local_proto.h"
 
+static void swap_gl();
+
 int main (int argc, char *argv[])
 {
     struct GModule *module;
@@ -39,7 +40,7 @@
     char *output_name;
 
     nv_data data;
-    render_window offscreen;
+    struct render_window *offscreen;
 
     /* initialize GRASS */
     G_gisinit(argv[0]);
@@ -63,9 +64,10 @@
     GS_set_swap_func(swap_gl);
 
     /* define render window */
-    render_window_init(&offscreen);
-    render_window_create(&offscreen, width, height); /* TOD0: option dim */
-    render_window_make_current(&offscreen);
+    offscreen = Nviz_new_render_window();
+    Nviz_init_render_window(offscreen);
+    Nviz_create_render_window(offscreen, NULL, width, height); /* offscreen display */
+    Nviz_make_current_render_window(offscreen);
 
     /* initialize nviz data */
     nv_data_init(&data);
@@ -224,10 +226,15 @@
     if (!ret)
 	G_fatal_error(_("Unsupported output format"));
 
-    render_window_destroy(&offscreen);
+    Nviz_destroy_render_window(offscreen);
 
     G_free ((void *) output_name);
     G_free ((void *) params);
 
     exit(EXIT_SUCCESS);
 }
+
+void swap_gl()
+{
+    return;
+}

Deleted: grass-addons/visualization/nviz2/cmd/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.h	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/cmd/nviz.h	2008-06-19 14:58:52 UTC (rev 31759)
@@ -1,75 +0,0 @@
-#ifndef __NVIZ_H__
-#define __NVIZ_H__
-
-#include <grass/gsurf.h>
-
-#define MAP_OBJ_UNDEFINED 0
-#define MAP_OBJ_SURF 1
-#define MAP_OBJ_VOL 2
-#define MAP_OBJ_VECT 3
-
-#define RANGE (5 * GS_UNIT_SIZE)
-#define RANGE_OFFSET (2 * GS_UNIT_SIZE)
-#define ZRANGE (3 * GS_UNIT_SIZE)
-#define ZRANGE_OFFSET (1 * GS_UNIT_SIZE)
-
-#define DEFAULT_SURF_COLOR 0x33BBFF
-
-#define RED_MASK 0x000000FF
-#define GRN_MASK 0x0000FF00
-#define BLU_MASK 0x00FF0000
-
-#define FORMAT_PPM 1
-#define FORMAT_TIF 2
-
-/* 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__ */

Deleted: grass-addons/visualization/nviz2/cmd/render.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/render.c	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/cmd/render.c	2008-06-19 14:58:52 UTC (rev 31759)
@@ -1,154 +0,0 @@
-/*!
-  \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;
-}

Deleted: grass-addons/visualization/nviz2/cmd/render.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/render.h	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/cmd/render.h	2008-06-19 14:58:52 UTC (rev 31759)
@@ -1,44 +0,0 @@
-#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__ */

Added: grass-addons/visualization/nviz2/lib/Makefile
===================================================================
--- grass-addons/visualization/nviz2/lib/Makefile	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/Makefile	2008-06-19 14:58:52 UTC (rev 31759)
@@ -0,0 +1,17 @@
+#MODULE_TOPDIR = ../../..
+MODULE_TOPDIR = $(HOME)/src/grass6_devel
+
+# LIB_NAME = $(NVIZ_LIBNAME)
+LIB_NAME = grass_nviz
+
+DEPENDENCIES = $(VECTDEP) $(BITMAPDEP) $(LINKMDEP) $(FORMDEP) $(DBMIDEP) $(GISDEP) $(OGSFDEP)
+
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(INC) \
+	$(TIFFINCPATH) $(DSPINC) \
+	$(VECT_CFLAGS) $(OPENGLINC) 
+EXTRA_LIBS = $(GISLIB) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB)
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+default: lib

Copied: grass-addons/visualization/nviz2/lib/nviz.h (from rev 31709, grass-addons/visualization/nviz2/cmd/nviz.h)
===================================================================
--- grass-addons/visualization/nviz2/lib/nviz.h	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/nviz.h	2008-06-19 14:58:52 UTC (rev 31759)
@@ -0,0 +1,122 @@
+#ifndef GRASS_NVIZ_H
+#define GRASS_NVIZ_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
+
+#define MAP_OBJ_UNDEFINED 0
+#define MAP_OBJ_SURF 1
+#define MAP_OBJ_VOL 2
+#define MAP_OBJ_VECT 3
+
+#define RANGE (5 * GS_UNIT_SIZE)
+#define RANGE_OFFSET (2 * GS_UNIT_SIZE)
+#define ZRANGE (3 * GS_UNIT_SIZE)
+#define ZRANGE_OFFSET (1 * GS_UNIT_SIZE)
+
+#define DEFAULT_SURF_COLOR 0x33BBFF
+
+#define RED_MASK 0x000000FF
+#define GRN_MASK 0x0000FF00
+#define BLU_MASK 0x00FF0000
+
+#define FORMAT_PPM 1
+#define FORMAT_TIF 2
+
+/* 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;
+
+struct render_window {
+    Display *displayId;   /* display connection */
+    GLXContext contextId; /* GLX rendering context */
+    Pixmap pixmap;
+    GLXPixmap windowId;
+};
+
+/* 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 */

Added: grass-addons/visualization/nviz2/lib/render.c
===================================================================
--- grass-addons/visualization/nviz2/lib/render.c	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/render.c	2008-06-19 14:58:52 UTC (rev 31759)
@@ -0,0 +1,143 @@
+/*!
+  \file render.c
+ 
+  \brief Nviz library -- 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> (Google SoC 2008)
+
+  \date 2008
+*/
+
+#include <grass/glocale.h>
+#include <grass/nviz.h>
+
+/*!
+  \brief Allocate memory for render window
+
+  \return pointer to render_window struct
+  \return NULL on failure
+*/
+struct render_window *Nviz_new_render_window()
+{
+  struct render_window *rwin;
+
+  /* G_malloc() calls G_fatal_error() on failure */
+  rwin = (struct render_window *) G_malloc (sizeof (struct render_window));
+  
+  return rwin;
+}
+					    
+/*!
+  \brief Initialize render window
+
+  \param win pointer to render_window struct
+*/
+void Nviz_init_render_window(struct render_window *rwin)
+{
+    rwin->displayId = NULL;
+    rwin->contextId = NULL;
+    rwin->pixmap = 0;
+    rwin->windowId = 0;
+
+    return;
+}
+
+/*!
+  \brief Free render window
+
+  \param win pointer to render_window struct
+*/
+void Nviz_destroy_render_window(struct render_window *rwin)
+{
+    glXDestroyContext(rwin->displayId, rwin->contextId);
+    XFreePixmap(rwin->displayId, rwin->pixmap);
+
+    G_free ((void *) rwin);
+
+    return;
+}
+
+/*!
+  \brief Create render window
+
+  \param rwin pointer to render_window struct
+  \param display display instance (NULL for offscreen)
+  \param width window width
+  \param height window height
+
+  \return 1
+*/
+int Nviz_create_render_window(struct render_window *rwin, void *display,
+			      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 };
+
+    /* get the default display connection */
+    rwin->displayId = XOpenDisplay((char *) display);
+    if (!rwin->displayId) {
+	G_fatal_error (_("Bad X server connection"));
+    }
+
+    /* get visual info and set up pixmap buffer */
+    v = glXChooseVisual(rwin->displayId,
+			DefaultScreen(rwin->displayId),
+			attributeList);
+
+    rwin->contextId = glXCreateContext(rwin->displayId,
+				      v, NULL, GL_FALSE);
+    if (!rwin->contextId) {
+	G_fatal_error (_("Unable to create GLX rendering context"));
+    }
+
+    /* create win pixmap to render to (same depth as RootWindow) */
+    rwin->pixmap = XCreatePixmap(rwin->displayId,
+				RootWindow(rwin->displayId, v->screen),
+				width,
+				height,
+				v->depth);
+
+    /* create an off-screen GLX rendering area */
+    rwin->windowId = glXCreateGLXPixmap(rwin->displayId,
+				       v, rwin->pixmap);
+
+    if (v) {
+	XFree(v);
+    }
+
+    return 1;
+}
+
+/*!
+  \brief Make window current for rendering
+
+  \param win pointer to render_window struct
+
+  \return 1
+*/
+int Nviz_make_current_render_window(const struct render_window *rwin)
+{
+    if (!rwin->displayId || !rwin->contextId)
+	return 0;
+
+    if (rwin->contextId == glXGetCurrentContext())
+	return 1;
+
+    glXMakeCurrent(rwin->displayId, rwin->windowId,
+		   rwin->contextId);
+
+    /* TODO: AQUA */
+
+    return 1;
+}

Copied: grass-addons/visualization/nviz2/lib/render.h (from rev 31709, grass-addons/visualization/nviz2/cmd/render.h)
===================================================================
--- grass-addons/visualization/nviz2/lib/render.h	                        (rev 0)
+++ grass-addons/visualization/nviz2/lib/render.h	2008-06-19 14:58:52 UTC (rev 31759)
@@ -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__ */

Modified: grass-addons/visualization/nviz2/wxpython/mapdisp.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/mapdisp.py	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/wxpython/mapdisp.py	2008-06-19 14:58:52 UTC (rev 31759)
@@ -542,19 +542,7 @@
         """
         Updates the canvas anytime there is a change to the
         underlaying images or to the geometry of the canvas.
-        """
-        if self.parent.toolbars['nviz']:
-            self.UpdateMap3D() # OpenGL
-        else:
-            self.UpdateMap2D(render, renderVector)
 
-    def UpdateMap2D(self, render=True, renderVector=True):
-        """
-        Updates the canvas anytime there is a change to the
-        underlaying images or to the geometry of the canvas.
-
-        This method works in 2D mode.
-
         @param render re-render map composition
         @param renderVector re-render vector map layer enabled for editing (used for digitizer)
         """
@@ -674,49 +662,11 @@
         ### self.Map.SetRegion()
         self.parent.StatusbarUpdate()
 
-        Debug.msg (2, "BufferedWindow.UpdateMap2D(): render=%s, renderVector=%s -> time=%g" % \
+        Debug.msg (2, "BufferedWindow.UpdateMap(): render=%s, renderVector=%s -> time=%g" % \
                    (render, renderVector, (stop-start)))
 
         return True
 
-    def UpdateMap3D(self):
-        """
-        Updates the canvas anytime there is a change to the
-        underlaying images or to the geometry of the canvas.
-
-        This method works in 3D mode.
-
-        Instead PseudoDC is used GLCanvas
-        """
-        if not self.parent.toolbars['nviz']:
-            return False
-
-        start = time.clock()
-
-        self.resize = False
-
-        #
-        # clear current canvas first
-        #
-        self.pdc.Clear()
-        self.pdc.RemoveAll()
-        self.pdcTmp.Clear()
-        self.pdcTmp.RemoveAll()
-        self.Draw(self.pdc, pdctype='clear')
-
-        stop = time.clock()
-
-        #
-        # update statusbar
-        #
-        ### self.Map.SetRegion()
-        self.parent.StatusbarUpdate()
-
-        Debug.msg (2, "BufferedWindow.UpdateMap3D(): time=%g" % \
-                   (stop-start))
-
-        return True
-
     def DrawCompRegionExtent(self):
         """Draw computational region extent in the display
         
@@ -2538,6 +2488,9 @@
             if not nviz.haveOpenGL:
                 msg = _("Unable to start Nviz. The OpenGL package was not found. You can get it "
                         "at http://PyOpenGL.sourceforge.net. Switching back to 2D display mode.")
+            if not nviz.haveNviz:
+                msg = _("Unable to start Nviz. Python extension for Nviz was not found. "
+                        "Switching back to 2D display mode.")
 
             if msg:
                 wx.MessageBox(parent=self,

Modified: grass-addons/visualization/nviz2/wxpython/nviz/Makefile
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/Makefile	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/wxpython/nviz/Makefile	2008-06-19 14:58:52 UTC (rev 31759)
@@ -7,8 +7,8 @@
 SOURCES := $(wildcard *.cpp) $(LIB_NAME)_wrap.cpp
 SHLIB_OBJS := $(patsubst %.cpp, $(OBJDIR)/%.o, $(SOURCES))
 
-EXTRA_CFLAGS = $(SHLIB_CFLAGS) $(GDALCFLAGS) $(PYTHONCFLAGS) $(WXWIDGETSCXXFLAGS)
-EXTRA_LIBS = $(VECTLIB) $(GISLIB) $(GDALLIBS) $(VEDITLIB) $(WXWIDGETSLIB) $(PYTHONLDFLAGS)
+EXTRA_CFLAGS = $(SHLIB_CFLAGS) $(GDALCFLAGS) $(PYTHONCFLAGS) $(WXWIDGETSCXXFLAGS) $(XCFLAGS) $(XMINC)
+EXTRA_LIBS = $(GISLIB) $(WXWIDGETSLIB) $(PYTHONLDFLAGS) $(XLIBPATH) $(XMLIB) $(XTLIB) $(XLIB) $(XEXTRALIBS) $(OGSFLIB)
 
 LOCAL_HEADERS = nviz.h
 

Modified: grass-addons/visualization/nviz2/wxpython/nviz/init.cpp
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/wxpython/nviz/init.cpp	2008-06-19 14:58:52 UTC (rev 31759)
@@ -18,21 +18,56 @@
 
 #include "nviz.h"
 
+static void swap_gl();
+
 /*!
-  \brief Initialize Nviz class
+  \brief Initialize Nviz class instance
 */
 Nviz::Nviz()
 {
+    G_gisinit(""); /* GRASS functions */
+
     GS_libinit();
     /* GVL_libinit(); TODO */
 
-    //GS_set_swap_func(swap_gl);
+    GS_set_swap_func(swap_gl);
+
+    /* initialize render window */
+    rwind = Nviz_new_render_window();
+    Nviz_init_render_window(rwind);
 }
 
 /*!
+  \brief Destroy Nviz class instance
+*/
+Nviz::~Nviz()
+{
+    Nviz_destroy_render_window(rwind);
+
+    G_free((void *) rwind);
+}
+
+/*!
   \brief Swap GL buffers
 */
-void Nviz::swap_gl()
+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)
+{
+    if (!rwind)
+	return 0;
+
+    Nviz_create_render_window(rwind, display, width, height);
+    Nviz_make_current_render_window(rwind);
+
+    return 1;
+}

Modified: grass-addons/visualization/nviz2/wxpython/nviz/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/wxpython/nviz/nviz.h	2008-06-19 14:58:52 UTC (rev 31759)
@@ -2,18 +2,27 @@
 #define __NVIZ_H__
 
 extern "C" {
+#include <grass/gis.h>
 #include <grass/gsurf.h>
 #include <grass/gstypes.h>
+#include <grass/nviz.h>
 }
 
 class Nviz
 {
 private:
-    void swap_gl();
-  
+    // struct render_window *rwind;
+    struct render_window *rwind;
+
 public:
     /* constructor */
     Nviz();
+
+    /* destructor */
+    ~Nviz();
+
+    /* set */
+    int SetDisplay(void *, int, int);
 };
 
 #endif /* __NVIZ_H__ */

Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-19 14:14:48 UTC (rev 31758)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py	2008-06-19 14:58:52 UTC (rev 31759)
@@ -29,13 +29,28 @@
 except ImportError:
     haveOpenGL = False
 
+import globalvar
+#try:
+nvizPath = os.path.join(globalvar.ETCWXDIR, "nviz")
+sys.path.append(nvizPath)
+import grass6_wxnviz as wxnviz
+haveNviz = True
+#except ImportError:
+#    haveNviz = False
+
 class GLWindow(glcanvas.GLCanvas):
     """OpenGL canvas for Map Display Window"""
     def __init__(self, parent):
         self.parent = parent # MapWindow
+
         glcanvas.GLCanvas.__init__(self, parent, wx.ID_ANY)
         self.init = False
 
+        #
+        # create nviz instance
+        #
+        nvizClass = wxnviz.Nviz()
+
         # initialize mouse position
         self.lastx = self.x = 30
         self.lasty = self.y = 30



More information about the grass-commit mailing list