[GRASS-SVN] r31975 - in grass/trunk: gui/wxpython/gui_modules
gui/wxpython/icons gui/wxpython/icons/silk visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 2 18:55:47 EDT 2008
Author: martinl
Date: 2008-07-02 18:55:47 -0400 (Wed, 02 Jul 2008)
New Revision: 31975
Added:
grass/trunk/visualization/nviz2/cmd/surface.c
Modified:
grass/trunk/gui/wxpython/gui_modules/nviz.py
grass/trunk/gui/wxpython/gui_modules/toolbars.py
grass/trunk/gui/wxpython/icons/icon.py
grass/trunk/gui/wxpython/icons/silk/__init__.py
grass/trunk/visualization/nviz2/cmd/args.c
grass/trunk/visualization/nviz2/cmd/local_proto.h
grass/trunk/visualization/nviz2/cmd/main.c
Log:
nviz2: wxGUI minor fixes, cmd module updated (in progress)
Modified: grass/trunk/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/nviz.py 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/gui/wxpython/gui_modules/nviz.py 2008-07-02 22:55:47 UTC (rev 31975)
@@ -167,8 +167,8 @@
else:
value = self.view['persp']['step']
self.view['persp']['value'] += value
- if self.view['persp']['value'] < 0:
- self.view['persp']['value'] = 0
+ if self.view['persp']['value'] < 1:
+ self.view['persp']['value'] = 1
elif self.view['persp']['value'] > 100:
self.view['persp']['value'] = 100
@@ -390,12 +390,12 @@
btnSave.SetDefault()
# bindings
btnApply.Bind(wx.EVT_BUTTON, self.OnApply)
- btnApply.SetToolTipString(_("Apply changes for this session"))
+ btnApply.SetToolTipString(_("Apply changes and update display"))
btnApply.SetDefault()
btnSave.Bind(wx.EVT_BUTTON, self.OnSave)
- btnSave.SetToolTipString(_("Close dialog and save changes to user settings file"))
+ btnSave.SetToolTipString(_("Apply changes, update display and save changes to layer settings"))
btnCancel.Bind(wx.EVT_BUTTON, self.OnClose)
- btnCancel.SetToolTipString(_("Close dialog and ignore changes"))
+ btnCancel.SetToolTipString(_("Hide dialog and ignore changes"))
# sizer
btnSizer = wx.StdDialogButtonSizer()
btnSizer.AddButton(btnApply)
@@ -827,7 +827,8 @@
# spin.SetRange(self.settings[name]['min'],
# self.settings[name]['max'])
- spin.Bind(wx.EVT_SPINCTRL, self.OnViewChange)
+ # no 'changed' event ... (FIXME)
+ spin.Bind(wx.EVT_SPINCTRL, self.OnViewChangedSpin)
self.win['view'][name]['spin'] = spin.GetId()
def UpdateSettings(self):
@@ -877,10 +878,15 @@
def OnViewChanged(self, event):
"""View changed, render in full resolution"""
- print '#'
self.mapWindow.render = True
self.mapWindow.Refresh(False)
+ def OnViewChangedSpin(self, event):
+ """View changed, render in full resolution"""
+ self.OnViewChange(event)
+ self.mapWindow.render = True
+ self.mapWindow.Refresh(False)
+
def OnResetView(self, event):
"""Reset to default view (view page)"""
self.mapWindow.ResetView()
@@ -995,8 +1001,6 @@
layer = self.mapWindow.GetSelectedLayer()
id = self.mapWindow.GetMapObjId(layer)
- print self.mapWindow.update
-
#
# surface
#
@@ -1225,7 +1229,7 @@
#
for attr in ('topo', 'color'):
self.SetSurfaceUseMap(attr, True) # -> map
- if layer.type == 'raster':
+ if layer and layer.type == 'raster':
self.FindWindowById(self.win['surface'][attr]['map']).SetValue(layer.name)
else:
self.FindWindowById(self.win['surface'][attr]['map']).SetValue('')
@@ -1317,7 +1321,6 @@
self.pdc.DrawToDC(dc)
def OnMouse(self, event):
- print event.LeftIsDown(), event.LeftUp()
if event.LeftIsDown():
x, y = event.GetPosition()
self.Draw(pos=(x, y))
Modified: grass/trunk/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/toolbars.py 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/gui/wxpython/gui_modules/toolbars.py 2008-07-02 22:55:47 UTC (rev 31975)
@@ -1033,15 +1033,22 @@
def ToolbarData(self):
"""Toolbar data"""
+ self.settings = wx.NewId()
self.quit = wx.NewId()
# tool, label, bitmap, kind, shortHelp, longHelp, handler
return (
+ (self.settings, "settings", Icons["nvizSettings"].GetBitmap(),
+ wx.ITEM_NORMAL, Icons["nvizSettings"].GetLabel(), Icons["nvizSettings"].GetDesc(),
+ self.OnSettings),
(self.quit, 'quit', Icons["quit"].GetBitmap(),
wx.ITEM_NORMAL, Icons["quit"].GetLabel(), Icons["quit"].GetDesc(),
self.OnExit),
)
+ def OnSettings(self, event):
+ pass
+
def OnExit (self, event=None):
"""Quit nviz tool (swith to 2D mode)"""
Modified: grass/trunk/gui/wxpython/icons/icon.py
===================================================================
--- grass/trunk/gui/wxpython/icons/icon.py 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/gui/wxpython/icons/icon.py 2008-07-02 22:55:47 UTC (rev 31975)
@@ -133,6 +133,8 @@
"grGcpDelete" : wx.ART_ERROR, # FIXME
"grGcpReload" : 'gui-redraw.gif',
"grSettings" : 'edit-color.gif',
+ # nviz
+ "nvizSettings" : 'settings.gif',
}
# merge icons dictionaries, join paths
@@ -418,6 +420,10 @@
"grSettings": MetaIcon (img=icons_img["grSettings"],
label=_("Settings"),
desc=_("Settings dialog for georectification tool")),
+ # nviz
+ "nvizSettings": MetaIcon (img=icons_img["nvizSettings"],
+ label=_("Settings"),
+ desc=_("Show Nviz settings dialog")),
}
# testing ...
Modified: grass/trunk/gui/wxpython/icons/silk/__init__.py
===================================================================
--- grass/trunk/gui/wxpython/icons/silk/__init__.py 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/gui/wxpython/icons/silk/__init__.py 2008-07-02 22:55:47 UTC (rev 31975)
@@ -93,4 +93,6 @@
"grGcpDelete" : 'bullet_delete.png',
"grGcpReload" : 'arrow_refresh.png',
"grSettings" : 'color_swatch.png',
+ # nviz
+ "nvizSettings" : 'color_swatch.png',
}
Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/visualization/nviz2/cmd/args.c 2008-07-02 22:55:47 UTC (rev 31975)
@@ -15,6 +15,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
@@ -32,8 +33,16 @@
*/
void parse_command(int argc, char* argv[], struct GParams *params)
{
- /* surface */
+ params->mode_all = G_define_flag();
+ params->mode_all->key = 'a';
+ params->mode_all->description = _("Use draw mode for all loaded surfaces");
+
+ /*
+ surface attributes
+ */
+ /* topography */
params->elev_map = G_define_standard_option(G_OPT_R_ELEV);
+ params->elev_map->key = "elevation_map";
params->elev_map->required = NO;
params->elev_map->multiple = YES;
params->elev_map->description = _("Name of raster map(s) for elevation");
@@ -48,6 +57,7 @@
params->elev_const->description = _("Elevation value(s)");
params->elev_const->guisection = _("Surface");
+ /* color */
params->color_map = G_define_standard_option(G_OPT_R_MAP);
params->color_map->multiple = YES;
params->color_map->required = NO;
@@ -62,6 +72,7 @@
params->color_const->key = "color_value";
params->color_const->answer = NULL;
+ /* mask */
params->mask_map = G_define_standard_option(G_OPT_R_MAP);
params->mask_map->multiple = YES;
params->mask_map->required = NO;
@@ -69,6 +80,7 @@
params->mask_map->guisection = _("Surface");
params->mask_map->key = "mask_map";
+ /* transparency */
params->transp_map = G_define_standard_option(G_OPT_R_MAP);
params->transp_map->multiple = YES;
params->transp_map->required = NO;
@@ -86,6 +98,7 @@
params->transp_const->guisection = _("Surface");
params->transp_const->options = "0-255";
+ /* shininess */
params->shine_map = G_define_standard_option(G_OPT_R_MAP);
params->shine_map->multiple = YES;
params->shine_map->required = NO;
@@ -103,6 +116,7 @@
params->shine_const->guisection = _("Surface");
params->shine_const->options = "0-255";
+ /* emission */
params->emit_map = G_define_standard_option(G_OPT_R_MAP);
params->emit_map->multiple = YES;
params->emit_map->required = NO;
@@ -120,7 +134,79 @@
params->emit_const->guisection = _("Surface");
params->emit_const->options = "0-255";
- /* vector */
+ /*
+ draw
+ */
+ /* mode */
+ params->mode = G_define_option();
+ params->mode->key = "mode";
+ params->mode->key_desc = "string";
+ params->mode->type = TYPE_STRING;
+ params->mode->required = YES;
+ params->mode->multiple = YES;
+ params->mode->description = _("Draw mode");
+ params->mode->options = "coarse,fine,both";
+ params->mode->answer = "fine";
+ params->mode->guisection = _("Draw");
+
+ /* resolution fine */
+ params->res_fine = G_define_option();
+ params->res_fine->key = "resolution_fine";
+ params->res_fine->key_desc = "value";
+ params->res_fine->type = TYPE_INTEGER;
+ params->res_fine->required = YES;
+ params->res_fine->multiple = YES;
+ params->res_fine->description = _("Fine resolution");
+ params->res_fine->answer = "6";
+ params->res_fine->guisection = _("Draw");
+
+ /* resolution coarse */
+ params->res_coarse = G_define_option();
+ params->res_coarse->key = "resolution_coarse";
+ params->res_coarse->key_desc = "value";
+ params->res_coarse->type = TYPE_INTEGER;
+ params->res_coarse->required = YES;
+ params->res_coarse->multiple = YES;
+ params->res_coarse->description = _("Coarse resolution");
+ params->res_coarse->answer = "9";
+ params->res_coarse->guisection = _("Draw");
+
+ /* style */
+ params->style = G_define_option();
+ params->style->key = "style";
+ params->style->key_desc = "string";
+ params->style->type = TYPE_STRING;
+ params->style->required = YES;
+ params->style->multiple = YES;
+ params->style->description = _("Draw style");
+ params->style->options = "wire,surface";
+ params->style->answer = "surface";
+ params->style->guisection = _("Draw");
+
+ /* shading */
+ params->shade = G_define_option();
+ params->shade->key = "shading";
+ params->shade->key_desc = "string";
+ params->shade->type = TYPE_STRING;
+ params->shade->required = YES;
+ params->shade->multiple = YES;
+ params->shade->description = _("Shading");
+ params->shade->options = "flat,gouraud";
+ params->shade->answer = "gouraud";
+ params->shade->guisection = _("Draw");
+
+ /* wire color */
+ params->wire_color = G_define_standard_option(G_OPT_C_FG);
+ params->wire_color->multiple = YES;
+ params->wire_color->required = YES;
+ params->wire_color->label = _("Wire color");
+ params->wire_color->key = "wire_color";
+ params->wire_color->answer = "136:136:136";
+ params->wire_color->guisection = _("Draw");
+
+ /*
+ vector
+ */
params->vector = G_define_standard_option(G_OPT_V_MAP);
params->vector->multiple = YES;
params->vector->required = NO;
@@ -128,18 +214,16 @@
params->vector->guisection = _("Vector");
params->vector->key = "vector";
- /* misc */
- params->exag = G_define_option();
- params->exag->key = "zexag";
- params->exag->key_desc = "value";
- params->exag->type = TYPE_DOUBLE;
- params->exag->required = NO;
- params->exag->multiple = NO;
- params->exag->description = _("Vertical exaggeration");
-
+ /*
+ misc
+ */
+ /* background color */
params->bgcolor = G_define_standard_option(G_OPT_C_BG);
- /* viewpoint */
+ /*
+ viewpoint
+ */
+ /* position */
params->pos = G_define_option();
params->pos->key = "position";
params->pos->key_desc = "x,y";
@@ -150,6 +234,7 @@
params->pos->guisection = _("Viewpoint");
params->pos->answer = "0.85,0.85";
+ /* height */
params->height = G_define_option();
params->height->key = "height";
params->height->key_desc = "value";
@@ -159,6 +244,7 @@
params->height->description = _("Viewpoint height (in map units)");
params->height->guisection = _("Viewpoint");
+ /* perspective */
params->persp = G_define_option();
params->persp->key = "perspective";
params->persp->key_desc = "value";
@@ -170,6 +256,7 @@
params->persp->answer = "40";
params->persp->options = "1-100";
+ /* twist */
params->twist = G_define_option();
params->twist->key = "twist";
params->twist->key_desc = "value";
@@ -181,11 +268,25 @@
params->twist->answer = "0";
params->twist->options = "-180-180";
- /* image */
+ /* z-exag */
+ params->exag = G_define_option();
+ params->exag->key = "zexag";
+ params->exag->key_desc = "value";
+ params->exag->type = TYPE_DOUBLE;
+ params->exag->required = NO;
+ params->exag->multiple = NO;
+ params->exag->description = _("Vertical exaggeration");
+
+
+ /*
+ image
+ */
+ /* output */
params->output = G_define_standard_option(G_OPT_F_OUTPUT);
params->output->description = _("Name for output file (do not add extension)");
params->output->guisection = _("Image");
+ /* format */
params->format = G_define_option();
params->format->key = "format";
params->format->type = TYPE_STRING;
@@ -195,6 +296,7 @@
params->format->required = YES;
params->format->guisection = _("Image");
+ /* size */
params->size = G_define_option();
params->size->key = "size";
params->size->type = TYPE_INTEGER;
@@ -209,3 +311,64 @@
return;
}
+
+/*!
+ \brief Get number of answers of given option
+
+ \param pointer to option
+
+ \return number
+*/
+int opt_get_num_answers(const struct Option *opt)
+{
+ int i, num;
+ i = num = 0;
+ if (opt->answer) {
+ while (opt->answers[i]) {
+ if (strcmp(opt->answers[i], "")) {
+ num++; /* skip empty values */
+ }
+ i++;
+ }
+ }
+
+ return i;
+}
+
+/*!
+ \brief Check parameters consistency
+
+ \param params module parameters
+*/
+void check_parameters(const struct GParams * params)
+{
+ int nelevs;
+ int ncolor_map, ncolor_const, nmasks, ntransps;
+ int nshines, nemits;
+
+ nelevs = opt_get_num_answers(params->elev_map);
+ nelevs += opt_get_num_answers(params->elev_const);
+
+ if (nelevs < 1)
+ G_fatal_error(_("At least one <%s> or <%s> required"),
+ params->elev_map->key, params->elev_const->key);
+
+ ncolor_map = opt_get_num_answers(params->color_map);
+ ncolor_const = opt_get_num_answers(params->color_const);
+
+ if (nelevs != ncolor_map + ncolor_const)
+ G_fatal_error(_("Invalid number of color attributes (<%s> %d, <%s> %d"),
+ params->color_map->key, ncolor_map,
+ params->color_const->key, ncolor_const);
+
+ nmasks = opt_get_num_answers(params->mask_map);
+ ntransps = opt_get_num_answers(params->transp_map);
+ ntransps += opt_get_num_answers(params->transp_const);
+ nshines = opt_get_num_answers(params->shine_map);
+ nshines += opt_get_num_answers(params->shine_const);
+ nemits = opt_get_num_answers(params->emit_map);
+ nemits += opt_get_num_answers(params->emit_const);
+
+
+ return;
+}
Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h 2008-07-02 22:55:47 UTC (rev 31975)
@@ -5,10 +5,13 @@
/* module flags and parameters */
struct GParams {
+ struct Flag *mode_all;
/* raster */
struct Option *elev_map, *elev_const, *color_map, *color_const,
*mask_map, *transp_map, *transp_const, *shine_map, *shine_const,
*emit_map, *emit_const,
+ /* draw */
+ *mode, *res_fine, *res_coarse, *style, *shade, *wire_color,
/* vector */
*vector,
/* misc */
@@ -22,7 +25,14 @@
/* args.c */
void parse_command(int, char**, struct GParams *);
int color_from_cmd(const char *);
+int opt_get_num_answers(const struct Option *);
+void check_parameters(const struct GParams *);
+/* surface.c */
+int load_rasters(const struct GParams *,
+ nv_data *data);
+void set_draw_mode(const struct GParams *);
+
/* write_img.c */
int write_img(const char *, int);
Modified: grass/trunk/visualization/nviz2/cmd/main.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/main.c 2008-07-02 20:37:08 UTC (rev 31974)
+++ grass/trunk/visualization/nviz2/cmd/main.c 2008-07-02 22:55:47 UTC (rev 31975)
@@ -25,7 +25,6 @@
#include "local_proto.h"
static void swap_gl();
-static int opt_get_num_answers(const struct Option *);
int main (int argc, char *argv[])
{
@@ -33,12 +32,7 @@
struct GParams *params;
char *mapset;
- unsigned int i;
- unsigned int ncolor_map, ncolor_const, nmask_map;
- unsigned int ntransp_map, ntransp_const, nshine_map, nshine_const;
- unsigned int nemit_map, nemit_const;
- int *surf_list, nsurfs;
- int id, ret;
+ int i, ret;
float vp_height, z_exag; /* calculated viewpoint height, z-exag */
int width, height; /* output image size */
char *output_name;
@@ -58,6 +52,9 @@
/* define options, call G_parser() */
parse_command(argc, argv, params);
+ /* check parameters consistency */
+ check_parameters(params);
+
width = atoi(params->size->answers[0]);
height = atoi(params->size->answers[1]);
G_asprintf(&output_name, "%s.%s", params->output->answer, params->format->answer);
@@ -103,127 +100,11 @@
Nviz_set_light_ambient(&data, 1,
0.3, 0.3, 0.3);
- /*
- * load raster maps (surface topography) map/constant
- */
- if (params->elev_map->answer) {
- /* maps */
- for (i = 0; params->elev_map->answers[i]; i++) {
- mapset = G_find_cell2 (params->elev_map->answers[i], "");
- if (mapset == NULL) {
- G_fatal_error(_("Raster map <%s> not found"),
- params->elev_map->answers[i]);
- }
-
- /* topography */
- id = Nviz_new_map_obj(MAP_OBJ_SURF,
- G_fully_qualified_name(params->elev_map->answers[i], mapset), 0.0,
- &data);
- }
- }
+ /* load raster maps (surface topography) & set attributes (map/constant) */
+ load_rasters(params, &data);
+ /* set draw mode for loaded surfaces */
+ set_draw_mode(params);
- ncolor_map = opt_get_num_answers(params->color_map);
- ncolor_const = opt_get_num_answers(params->color_const);
- if (params->elev_const->answer) {
- /* constants */
- float value;
- surf_list = GS_get_surf_list(&nsurfs);
- for (i = 0; params->elev_const->answers[i]; i++) {
- value = atof(params->elev_const->answers[i]);
- /* check for color */
- if (i + nsurfs >= ncolor_map + ncolor_const) {
- G_fatal_error (_("Missing color settings for elevation value %f"),
- value);
- /* topography */
- id = Nviz_new_map_obj(MAP_OBJ_SURF,
- NULL, value,
- &data);
- }
- }
- }
-
- /* set surface attributes */
- surf_list = GS_get_surf_list(&nsurfs);
- nmask_map = opt_get_num_answers(params->mask_map);
- ntransp_map = opt_get_num_answers(params->transp_map);
- ntransp_const = opt_get_num_answers(params->transp_const);
- nshine_map = opt_get_num_answers(params->shine_map);
- nshine_const = opt_get_num_answers(params->shine_const);
- nemit_map = opt_get_num_answers(params->emit_map);
- nemit_const = opt_get_num_answers(params->emit_const);
- for (i = 0; i < (unsigned int) nsurfs; i++) {
- id = surf_list[i];
- /* color */
- if (i < ncolor_map) {
- mapset = G_find_cell2 (params->color_map->answers[i], "");
- if (mapset == NULL) {
- G_fatal_error(_("Raster map <%s> not found"),
- params->color_map->answers[i]);
- }
-
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
- G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
- &data);
- }
- else if (i < ncolor_map + ncolor_const) { /* check for color value */
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
- NULL, Nviz_color_from_str(params->color_const->answers[i]),
- &data);
- }
- else { /* use by default elevation map for coloring */
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
- G_fully_qualified_name(params->elev_map->answers[i], mapset), -1.0,
- &data);
- }
- /* mask */
- if (i < nmask_map) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT,
- G_fully_qualified_name(params->mask_map->answers[i], mapset), -1.0,
- &data);
- }
-
- /* transparency */
- if (i < ntransp_map) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT,
- G_fully_qualified_name(params->transp_map->answers[i], mapset), -1.0,
- &data);
- }
- else if (i < ntransp_map + ntransp_const) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, CONST_ATT,
- NULL, atof(params->transp_const->answers[i-ntransp_map]),
- &data);
- }
-
- /* shininess */
- if (i < nshine_map) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT,
- G_fully_qualified_name(params->shine_map->answers[i], mapset), -1.0,
- &data);
- }
- else if (i < nshine_map + nshine_const) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, CONST_ATT,
- NULL, atof(params->shine_const->answers[i-nshine_map]),
- &data);
- }
-
- /* emission */
- if (i < nemit_map) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT,
- G_fully_qualified_name(params->emit_map->answers[i], mapset), -1.0,
- &data);
- }
- else if (i < nemit_map + nemit_const) {
- Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, CONST_ATT,
- NULL, atof(params->emit_const->answers[i-nemit_map]),
- &data);
- }
-
- /*
- if (i > 1)
- set_default_wirecolors(data, i);
- */
- }
-
/* load vectors */
if (params->vector->answer) {
if (!params->elev_map->answer && GS_num_surfs() == 0) { /* load base surface if no loaded */
@@ -310,25 +191,3 @@
{
return;
}
-
-/*!
- \brief Get number of answers of given option
-
- \param pointer to option
-
- \return number
-*/
-int opt_get_num_answers(const struct Option *opt)
-{
- int i, num;
- i = num = 0;
- if (opt->answer) {
- while (opt->answers[i]) {
- if (strcmp(opt->answers[i++], "")) {
- num++; /* skip empty values */
- }
- }
- }
-
- return i;
-}
Added: grass/trunk/visualization/nviz2/cmd/surface.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/surface.c (rev 0)
+++ grass/trunk/visualization/nviz2/cmd/surface.c 2008-07-02 22:55:47 UTC (rev 31975)
@@ -0,0 +1,246 @@
+/*!
+ \file surface.c
+
+ \brief Surface procedures
+
+ 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> (Google SoC 2008)
+
+ \date 2008
+*/
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/*!
+ \brief Load raster maps/constants and set their attributes
+
+ \param params module parameters
+ \param data nviz data
+*/
+int load_rasters(const struct GParams *params,
+ nv_data *data)
+{
+ char *mapset;
+ int i;
+ int ncolors, nmask_map;
+ int ntransp_map, ntransp_const, nshine_map, nshine_const;
+ int nemit_map, nemit_const;
+ int *surf_list, nsurfs;
+ int id;
+
+ /* topography */
+ if (params->elev_map->answer) {
+ /* maps */
+ for (i = 0; params->elev_map->answers[i]; i++) {
+ mapset = G_find_cell2 (params->elev_map->answers[i], "");
+ if (mapset == NULL) {
+ G_fatal_error(_("Raster map <%s> not found"),
+ params->elev_map->answers[i]);
+ }
+
+ id = Nviz_new_map_obj(MAP_OBJ_SURF,
+ G_fully_qualified_name(params->elev_map->answers[i], mapset), 0.0,
+ data);
+ }
+ }
+
+ /* color */
+ ncolors = opt_get_num_answers(params->color_map);
+ if (params->elev_const->answer) {
+ /* constants */
+ float value;
+ surf_list = GS_get_surf_list(&nsurfs);
+ for (i = 0; i < nsurfs; i++) {
+ if (i < ncolors) { /* check map first */
+ value = atof(params->elev_const->answers[i]);
+ }
+ /* check for color */
+ if (i + nsurfs >= ncolors) {
+ G_fatal_error (_("Missing color settings for elevation value %f"),
+ value);
+ /* topography */
+ id = Nviz_new_map_obj(MAP_OBJ_SURF,
+ NULL, value,
+ data);
+ }
+ }
+ }
+
+ /* set surface attributes */
+ surf_list = GS_get_surf_list(&nsurfs);
+ nmask_map = opt_get_num_answers(params->mask_map);
+ ntransp_map = opt_get_num_answers(params->transp_map);
+ ntransp_const = opt_get_num_answers(params->transp_const);
+ nshine_map = opt_get_num_answers(params->shine_map);
+ nshine_const = opt_get_num_answers(params->shine_const);
+ nemit_map = opt_get_num_answers(params->emit_map);
+ nemit_const = opt_get_num_answers(params->emit_const);
+ for (i = 0; i < nsurfs; i++) {
+ id = surf_list[i];
+ /* color */
+ if (i < ncolors) {
+ mapset = G_find_cell2 (params->color_map->answers[i], "");
+ if (mapset == NULL) {
+ G_fatal_error(_("Raster map <%s> not found"),
+ params->color_map->answers[i]);
+ }
+
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+ G_fully_qualified_name(params->color_map->answers[i], mapset), -1.0,
+ data);
+ }
+ else if (i < ncolors) { /* check for color value */
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, CONST_ATT,
+ NULL, Nviz_color_from_str(params->color_const->answers[i]),
+ data);
+ }
+ else { /* use by default elevation map for coloring */
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_COLOR, MAP_ATT,
+ G_fully_qualified_name(params->elev_map->answers[i], mapset), -1.0,
+ data);
+ }
+ /* mask */
+ if (i < nmask_map) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_MASK, MAP_ATT,
+ G_fully_qualified_name(params->mask_map->answers[i], mapset), -1.0,
+ data);
+ }
+
+ /* transparency */
+ if (i < ntransp_map) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, MAP_ATT,
+ G_fully_qualified_name(params->transp_map->answers[i], mapset), -1.0,
+ data);
+ }
+ else if (i < ntransp_map + ntransp_const) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_TRANSP, CONST_ATT,
+ NULL, atof(params->transp_const->answers[i-ntransp_map]),
+ data);
+ }
+
+ /* shininess */
+ if (i < nshine_map) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, MAP_ATT,
+ G_fully_qualified_name(params->shine_map->answers[i], mapset), -1.0,
+ data);
+ }
+ else if (i < nshine_map + nshine_const) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_SHINE, CONST_ATT,
+ NULL, atof(params->shine_const->answers[i-nshine_map]),
+ data);
+ }
+
+ /* emission */
+ if (i < nemit_map) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, MAP_ATT,
+ G_fully_qualified_name(params->emit_map->answers[i], mapset), -1.0,
+ data);
+ }
+ else if (i < nemit_map + nemit_const) {
+ Nviz_set_attr(id, MAP_OBJ_SURF, ATT_EMIT, CONST_ATT,
+ NULL, atof(params->emit_const->answers[i-nemit_map]),
+ data);
+ }
+
+ /*
+ if (i > 1)
+ set_default_wirecolors(data, i);
+ */
+ }
+
+ return nsurfs;
+}
+
+/*!
+ \brief Set draw mode for loaded surfaces
+
+ \param params module parameters
+*/
+void set_draw_mode(const struct GParams *params)
+{
+ int *surf_list, nsurfs;
+ int i, id, draw_mode;
+ int resol_fine, resol_coarse;
+
+ char *mode, *style, *shade, *res_fine, *res_coarse, *wire_color;
+
+ surf_list = GS_get_surf_list(&nsurfs);
+
+ for (i = 0; i < nsurfs; i++) {
+ draw_mode = 0;
+ id = surf_list[i];
+ if (!GS_surf_exists(id))
+ G_fatal_error (_("Surface id %d doesn't exist"), id);
+
+ if (params->mode_all->answer) { /* use one mode for all surfaces */
+ mode = params->mode->answers[0];
+ style = params->style->answers[0];
+ shade = params->shade->answers[0];
+ res_fine = params->res_fine->answers[0];
+ res_coarse = params->res_coarse->answers[0];
+ wire_color = params->wire_color->answers[0];
+ }
+ else {
+ mode = params->mode->answers[i];
+ style = params->style->answers[i];
+ shade = params->shade->answers[i];
+ res_fine = params->res_fine->answers[i];
+ res_coarse = params->res_coarse->answers[i];
+ wire_color = params->wire_color->answers[i];
+ }
+
+ /* mode */
+ if (strcmp(mode, "coarse") == 0) {
+ draw_mode |= DM_WIRE;
+ }
+ else if (strcmp(mode, "fine") == 0) {
+ draw_mode |= DM_POLY;
+ }
+ else { /* both */
+ draw_mode |= DM_WIRE_POLY;
+ }
+
+ /* style */
+ if (strcmp(params->style->answers[i], "wire") == 0) {
+ draw_mode |= DM_GRID_WIRE;
+ }
+ else { /* surface */
+ draw_mode |= DM_GRID_SURF;
+ }
+
+ /* shading */
+ if (strcmp(params->shade->answers[i], "flat") == 0) {
+ draw_mode |= DM_FLAT;
+ }
+ else { /* gouraud */
+ draw_mode |= DM_GOURAUD;
+ }
+
+ if (GS_set_drawmode(id, draw_mode) < 0)
+ G_fatal_error (_("Unable to set draw mode for surface id %d"),
+ id);
+
+ /* resolution */
+ resol_fine = atoi(res_fine);
+ resol_coarse = atoi(res_coarse);
+ if (GS_set_drawres(id, resol_fine, resol_fine,
+ resol_coarse, resol_coarse) < 0)
+ G_fatal_error (_("Unable to set draw mode for surface id %d"),
+ id);
+
+ /* wire color */
+ GS_set_wire_color(id, Nviz_color_from_str(wire_color));
+ }
+
+ return;
+}
Property changes on: grass/trunk/visualization/nviz2/cmd/surface.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