[GRASS-SVN] r31819 - in grass-addons/visualization/nviz2: cmd lib
wxpython
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 23 05:47:49 EDT 2008
Author: martinl
Date: 2008-06-23 05:47:49 -0400 (Mon, 23 Jun 2008)
New Revision: 31819
Modified:
grass-addons/visualization/nviz2/cmd/main.c
grass-addons/visualization/nviz2/lib/render.c
grass-addons/visualization/nviz2/wxpython/mapdisp.py
grass-addons/visualization/nviz2/wxpython/nviz.py
Log:
nviz2: wxGUI intergration in progress, related to r31818
Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c 2008-06-23 09:46:09 UTC (rev 31818)
+++ grass-addons/visualization/nviz2/cmd/main.c 2008-06-23 09:47:49 UTC (rev 31819)
@@ -71,11 +71,34 @@
/* initialize nviz data */
Nviz_init_data(&data);
+
/* define default attributes for map objects */
Nviz_set_attr_default();
+
/* set background color */
Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer));
+ /* init view */
+ Nviz_init_view();
+ /* set lights */
+ /* TODO: add options */
+ 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);
+ 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);
+
/* load data */
nelev = ncolor_map = ncolor_const = 0;
@@ -153,42 +176,10 @@
}
nvect++;
}
-
- /* init view */
- Nviz_init_view();
+
+ /* focus on loaded data */
Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
- /* set lights */
- /* TODO: add options */
- 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,
- 0.68, -0.68, 0.80, 0.0);
- light_set_bright(&data, 1,
- 0.8);
- light_set_color(&data, 1,
- 1.0, 1.0, 1.0);
- light_set_ambient(&data, 1,
- 0.2, 0.2, 0.2);
- */
-
- 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) {
vp_height = atof(params->height->answer);
@@ -214,6 +205,7 @@
Nviz_draw_cplane(&data, -1, -1);
Nviz_draw_all (&data);
+ /* write to image */
ret = 0;
if (strcmp(params->format->answer, "ppm") == 0)
ret = write_img(output_name, FORMAT_PPM);
Modified: grass-addons/visualization/nviz2/lib/render.c
===================================================================
--- grass-addons/visualization/nviz2/lib/render.c 2008-06-23 09:46:09 UTC (rev 31818)
+++ grass-addons/visualization/nviz2/lib/render.c 2008-06-23 09:47:49 UTC (rev 31819)
@@ -110,7 +110,7 @@
/* create an off-screen GLX rendering area */
rwin->windowId = glXCreateGLXPixmap(rwin->displayId,
- v, rwin->pixmap);
+ v, rwin->pixmap);
if (v) {
XFree(v);
@@ -124,7 +124,8 @@
\param win pointer to render_window struct
- \return 1
+ \return 1 on success
+ \return 0 on failure
*/
int Nviz_make_current_render_window(const struct render_window *rwin)
{
Modified: grass-addons/visualization/nviz2/wxpython/mapdisp.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/mapdisp.py 2008-06-23 09:46:09 UTC (rev 31818)
+++ grass-addons/visualization/nviz2/wxpython/mapdisp.py 2008-06-23 09:47:49 UTC (rev 31819)
@@ -60,7 +60,6 @@
import globalvar
import utils
import gdialogs
-import nviz
from vdigit import VDigitCategoryDialog as VDigitCategoryDialog
from vdigit import VDigitZBulkDialog as VDigitZBulkDialog
from vdigit import VDigitDuplicatesDialog as VDigitDuplicatesDialog
@@ -122,7 +121,16 @@
sys.exit()
-class BufferedWindow(wx.Window):
+class MapWindow(object):
+ """Generic map window class"""
+ def __init__(self, parent, id,
+ pos=wx.DefaultPosition,
+ size=wx.DefaultSize,
+ style=wx.NO_FULL_REPAINT_ON_RESIZE,
+ Map=None, tree=None, gismgr=None):
+ pass
+
+class BufferedWindow(MapWindow, wx.Window):
"""
A Buffered window class.
@@ -138,7 +146,10 @@
style=wx.NO_FULL_REPAINT_ON_RESIZE,
Map=None, tree=None, gismgr=None):
+ MapWindow.__init__(self, parent, id, pos, size, style,
+ Map, tree, gismgr)
wx.Window.__init__(self, parent, id, pos, size, style)
+
self.parent = parent
self.Map = Map
self.tree = tree
@@ -546,7 +557,6 @@
@param render re-render map composition
@param renderVector re-render vector map layer enabled for editing (used for digitizer)
"""
-
start = time.clock()
self.resize = False
@@ -2370,7 +2380,8 @@
#
# Init map display (buffered DC & set default cursor)
#
- self.MapWindow = BufferedWindow(self, id=wx.ID_ANY, Map=self.Map, tree=self.tree, gismgr=self.gismanager)
+ self.MapWindow = BufferedWindow(self, id=wx.ID_ANY,
+ Map=self.Map, tree=self.tree, gismgr=self.gismanager)
self.MapWindow.Bind(wx.EVT_MOTION, self.OnMotion)
self.MapWindow.SetCursor(self.cursors["default"])
self.MapWindowGL = None # used by Nviz (default is 2D display mode)
@@ -2480,6 +2491,7 @@
CloseButton(False).Layer(2))
# nviz
elif name == "nviz":
+ import nviz
# check for GLCanvas and OpenGL
msg = None
if not nviz.haveGLCanvas:
@@ -2501,7 +2513,8 @@
#
# create GL window & NVIZ toolbar
#
- self.MapWindowGL = nviz.GLWindow(self)
+ self.MapWindowGL = nviz.GLWindow(self, id=wx.ID_ANY,
+ Map=self.Map, tree=self.tree, gismgr=self.gismanager)
self.toolbars['nviz'] = toolbars.NvizToolbar(self, self.Map)
#
Modified: grass-addons/visualization/nviz2/wxpython/nviz.py
===================================================================
--- grass-addons/visualization/nviz2/wxpython/nviz.py 2008-06-23 09:46:09 UTC (rev 31818)
+++ grass-addons/visualization/nviz2/wxpython/nviz.py 2008-06-23 09:47:49 UTC (rev 31819)
@@ -4,7 +4,7 @@
@brief 2.5/3D visialization mode for Map Display Window
List of classes:
- - GLCanvas
+ - GLWindow
(C) 2008 by the GRASS Development Team
@@ -12,7 +12,7 @@
License (>=v2). Read the file COPYING that comes with GRASS
for details.
- at author Martin Landa <landa.martin gmail.com>
+ at author Martin Landa <landa.martin gmail.com> (Google SoC 2008)
"""
import wx
@@ -30,6 +30,8 @@
haveOpenGL = False
import globalvar
+from debug import Debug as Debug
+from mapdisp import MapWindow as MapWindow
#try:
nvizPath = os.path.join(globalvar.ETCWXDIR, "nviz")
sys.path.append(nvizPath)
@@ -38,18 +40,27 @@
#except ImportError:
# haveNviz = False
-class GLWindow(glcanvas.GLCanvas):
+class GLWindow(MapWindow, glcanvas.GLCanvas):
"""OpenGL canvas for Map Display Window"""
- def __init__(self, parent):
- self.parent = parent # MapWindow
+ def __init__(self, parent, id,
+ pos=wx.DefaultPosition,
+ size=wx.DefaultSize,
+ style=wx.NO_FULL_REPAINT_ON_RESIZE,
+ Map=None, tree=None, gismgr=None):
- glcanvas.GLCanvas.__init__(self, parent, id=wx.ID_ANY)
-# attribList=[wx.WX_GL_RGBA, wx.GLX_RED_SIZE, 1,
-# wx.GLX_GREEN_SIZE, 1,
-# wx.GLX_BLUE_SIZE, 1,
-# wx.GLX_DEPTH_SIZE, 1,
-# None])
+ glcanvas.GLCanvas.__init__(self, parent, id)
+ # MapWindow.__init__(self, parent, id, pos, size, style,
+ # Map, tree, gismgr)
+
+ self.parent = parent # MapFrame
+
+ # attribList=[wx.WX_GL_RGBA, wx.GLX_RED_SIZE, 1,
+ # wx.GLX_GREEN_SIZE, 1,
+ # wx.GLX_BLUE_SIZE, 1,
+ # wx.GLX_DEPTH_SIZE, 1,
+ # None])
+
self.init = False
#
@@ -63,8 +74,8 @@
self.nvizClass.SetDisplay(self)
# initialize mouse position
- self.lastx = self.x = 30
- self.lasty = self.y = 30
+ # self.lastx = self.x = 30
+ # self.lasty = self.y = 30
self.size = None
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
@@ -78,96 +89,33 @@
pass # do nothing, to avoid flashing on MSW
def OnSize(self, event):
- size = self.size = self.parent.GetClientSize()
+ self.size = self.parent.GetClientSize()
if self.GetContext():
+ Debug.msg(3, "GLCanvas.OnPaint(): w=%d, h=%d" % \
+ (self.size.width, self.size.height))
self.SetCurrent()
- # glViewport(0, 0, size.width, size.height)
- self.nvizClass.ResizeWindow(size.width, size.height)
+ self.nvizClass.ResizeWindow(self.size.width,
+ self.size.height)
event.Skip()
def OnPaint(self, event):
+ Debug.msg(3, "GLCanvas.OnPaint()")
+
dc = wx.PaintDC(self)
self.SetCurrent()
if not self.init:
- # self.InitGL()
- # nvizClass.InitView()
+ self.nvizClass.InitView()
self.nvizClass.LoadRaster("elevation", None, None);
+ self.nvizClass.SetViewportDefault()
+ self.nvizClass.SetLightsDefault()
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)
-
- # position viewer
- glMatrixMode(GL_MODELVIEW)
- glTranslatef(0.0, 0.0, -2.0)
-
- # position object
- glRotatef(self.y, 1.0, 0.0, 0.0)
- glRotatef(self.x, 0.0, 1.0, 0.0)
-
- glEnable(GL_DEPTH_TEST)
- glEnable(GL_LIGHTING)
- glEnable(GL_LIGHT0)
-
def OnDraw(self):
"""Draw data layers"""
- self.nvizClass.Draw()
+ Debug.msg(3, "GLCanvas.OnDraw()")
- def OnDraw1(self):
- # clear color and depth buffers
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
-
- # draw six faces of a cube
- glBegin(GL_QUADS)
- glNormal3f( 0.0, 0.0, 1.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f(-0.5, 0.5, 0.5)
- glVertex3f(-0.5,-0.5, 0.5)
- glVertex3f( 0.5,-0.5, 0.5)
-
- glNormal3f( 0.0, 0.0,-1.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glVertex3f( 0.5, 0.5,-0.5)
- glVertex3f( 0.5,-0.5,-0.5)
-
- glNormal3f( 0.0, 1.0, 0.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f( 0.5, 0.5,-0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glVertex3f(-0.5, 0.5, 0.5)
-
- glNormal3f( 0.0,-1.0, 0.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f( 0.5,-0.5,-0.5)
- glVertex3f( 0.5,-0.5, 0.5)
- glVertex3f(-0.5,-0.5, 0.5)
-
- glNormal3f( 1.0, 0.0, 0.0)
- glVertex3f( 0.5, 0.5, 0.5)
- glVertex3f( 0.5,-0.5, 0.5)
- glVertex3f( 0.5,-0.5,-0.5)
- glVertex3f( 0.5, 0.5,-0.5)
-
- glNormal3f(-1.0, 0.0, 0.0)
- glVertex3f(-0.5,-0.5,-0.5)
- glVertex3f(-0.5,-0.5, 0.5)
- glVertex3f(-0.5, 0.5, 0.5)
- glVertex3f(-0.5, 0.5,-0.5)
- glEnd()
-
- if self.size is None:
- self.size = self.GetClientSize()
- w, h = self.size
- w = max(w, 1.0)
- h = max(h, 1.0)
- xScale = 180.0 / w
- yScale = 180.0 / h
- glRotatef((self.y - self.lasty) * yScale, 1.0, 0.0, 0.0);
- glRotatef((self.x - self.lastx) * xScale, 0.0, 1.0, 0.0);
-
+ self.nvizClass.Draw()
self.SwapBuffers()
+
More information about the grass-commit
mailing list