[GRASS-SVN] r42607 - in grass/trunk: include lib/nviz
visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jun 20 15:02:52 EDT 2010
Author: martinl
Date: 2010-06-20 19:02:52 +0000 (Sun, 20 Jun 2010)
New Revision: 42607
Modified:
grass/trunk/include/nviz.h
grass/trunk/lib/nviz/change_view.c
grass/trunk/lib/nviz/draw.c
grass/trunk/lib/nviz/exag.c
grass/trunk/lib/nviz/lights.c
grass/trunk/lib/nviz/map_obj.c
grass/trunk/lib/nviz/position.c
grass/trunk/visualization/nviz2/cmd/args.c
grass/trunk/visualization/nviz2/cmd/local_proto.h
grass/trunk/visualization/nviz2/cmd/main.c
Log:
minor clean up of nvizlib
lights settings implemented in nviz_cmd
Modified: grass/trunk/include/nviz.h
===================================================================
--- grass/trunk/include/nviz.h 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/include/nviz.h 2010-06-20 19:02:52 UTC (rev 42607)
@@ -141,11 +141,11 @@
/* change_view.c */
int Nviz_resize_window(int, int);
int Nviz_update_ranges(nv_data *);
-int Nviz_set_viewpoint_position(nv_data *, float, float);
-int Nviz_set_viewpoint_height(nv_data *, float);
-int Nviz_set_viewpoint_persp(nv_data *, int);
-int Nviz_set_viewpoint_twist(nv_data *, int);
-int Nviz_change_exag(nv_data *, float);
+int Nviz_set_viewpoint_position(double, double);
+int Nviz_set_viewpoint_height(double);
+int Nviz_set_viewpoint_persp(int);
+int Nviz_set_viewpoint_twist(int);
+int Nviz_change_exag(nv_data *, double);
/* cplanes_obj.c */
int Nviz_new_cplane(nv_data *, int);
@@ -154,27 +154,27 @@
/* draw.c */
int Nviz_draw_all_surf(nv_data *);
-int Nviz_draw_all_vect(nv_data *);
-int Nviz_draw_all_site(nv_data *);
-int Nviz_draw_all_vol(nv_data *);
+int Nviz_draw_all_vect();
+int Nviz_draw_all_site();
+int Nviz_draw_all_vol();
int Nviz_draw_all(nv_data *);
int Nviz_draw_quick(nv_data *, int);
/* exag.c */
-int Nviz_get_exag_height(float *, float *, float *);
-float Nviz_get_exag();
+int Nviz_get_exag_height(double *, double *, double *);
+double Nviz_get_exag();
/* 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_set_light_position(nv_data *, int, double, double, double, double);
+int Nviz_set_light_bright(nv_data *, int, double);
+int Nviz_set_light_color(nv_data *, int, int, int, int);
+int Nviz_set_light_ambient(nv_data *, int, double, double, double);
int Nviz_init_light(nv_data *, int);
int Nviz_new_light(nv_data *);
/* map_obj.c */
-int Nviz_new_map_obj(int, const char *, float, nv_data *);
-int Nviz_set_attr(int, int, int, int, const char *, float, nv_data *);
+int Nviz_new_map_obj(int, const char *, double, nv_data *);
+int Nviz_set_attr(int, int, int, int, const char *, double, nv_data *);
void Nviz_set_surface_attr_default();
int Nviz_set_vpoint_attr_default();
int Nviz_set_volume_attr_default();
@@ -186,7 +186,7 @@
int Nviz_color_from_str(const char *);
/* position.c */
-void Nviz_init_view();
+void Nviz_init_view(nv_data *);
int Nviz_set_focus_state(int);
int Nviz_set_focus_map(int, int);
Modified: grass/trunk/lib/nviz/change_view.c
===================================================================
--- grass/trunk/lib/nviz/change_view.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/lib/nviz/change_view.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -90,7 +90,7 @@
\return 1
*/
-int Nviz_set_viewpoint_position(nv_data * data, float x_pos, float y_pos)
+int Nviz_set_viewpoint_position(double x_pos, double y_pos)
{
float xpos, ypos, from[3];
float tempx, tempy;
@@ -132,7 +132,7 @@
\return 1
*/
-int Nviz_set_viewpoint_height(nv_data * data, float height)
+int Nviz_set_viewpoint_height(double height)
{
float from[3];
@@ -162,7 +162,7 @@
\return 1
*/
-int Nviz_set_viewpoint_persp(nv_data * data, int persp)
+int Nviz_set_viewpoint_persp(int persp)
{
int fov;
@@ -182,7 +182,7 @@
\return 1
*/
-int Nviz_set_viewpoint_twist(nv_data * data, int twist)
+int Nviz_set_viewpoint_twist(int twist)
{
GS_set_twist(10 * twist);
@@ -199,9 +199,9 @@
\return 1
*/
-int Nviz_change_exag(nv_data * data, float exag)
+int Nviz_change_exag(nv_data * data, double exag)
{
- float temp;
+ double temp;
temp = GS_global_exag();
Modified: grass/trunk/lib/nviz/draw.c
===================================================================
--- grass/trunk/lib/nviz/draw.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/lib/nviz/draw.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -111,11 +111,9 @@
/*!
\brief Draw all loaded vector sets (lines)
- \param dc nviz data
-
\return 1
*/
-int Nviz_draw_all_vect(nv_data * dc)
+int Nviz_draw_all_vect()
{
// GS_set_cancel(0);
@@ -138,11 +136,9 @@
/*!
\brief Draw all loaded vector point sets
- \param dc nviz data
-
\return 1
*/
-int Nviz_draw_all_site(nv_data * dc)
+int Nviz_draw_all_site()
{
int i;
int *site_list, nsites;
@@ -168,12 +164,10 @@
/*!
\brief Draw all loaded volume sets
-
- \param dc nviz data
\return 1
*/
-int Nviz_draw_all_vol(nv_data * dc)
+int Nviz_draw_all_vol()
{
int *vol_list, nvols, i;
@@ -205,8 +199,6 @@
int Nviz_draw_all(nv_data * data)
{
int draw_surf, draw_vect, draw_site, draw_vol;
- int draw_north_arrow, arrow_x, draw_label, draw_legend;
- int draw_fringe, draw_scalebar, draw_bar_x;
draw_surf = 1;
draw_vect = 1;
Modified: grass/trunk/lib/nviz/exag.c
===================================================================
--- grass/trunk/lib/nviz/exag.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/lib/nviz/exag.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -25,7 +25,7 @@
\return 1
*/
-int Nviz_get_exag_height(float *val, float *min, float *max)
+int Nviz_get_exag_height(double *val, double *min, double *max)
{
float longdim, exag, texag, hmin, hmax, fmin, fmax;
int nsurfs, i, *surf_list;
@@ -70,7 +70,7 @@
\return value
*/
-float Nviz_get_exag()
+double Nviz_get_exag()
{
float exag, texag;
int nsurfs, i, *surf_list;
Modified: grass/trunk/lib/nviz/lights.c
===================================================================
--- grass/trunk/lib/nviz/lights.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/lib/nviz/lights.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -25,17 +25,17 @@
\return 1
*/
int Nviz_set_light_position(nv_data * data, int num,
- float x, float y, float z, float w)
+ double x, double y, double z, double w)
{
- float xpos, ypos;
+ double xpos, ypos;
xpos = x;
xpos = (xpos < 0) ? 0 : (xpos > 1.0) ? 1.0 : xpos;
ypos = 1.0 - y;
ypos = (ypos < 0) ? 0 : (ypos > 1.0) ? 1.0 : ypos;
if (x < 0.0 || x > 1.0 || y < 0.0 || y > 1.0) {
- G_debug(3, "Invalid view position coordinates, using %f,%f",
- xpos, 1.0 - ypos);
+ G_debug(0, "Invalid light position coordinates (%f,%f), using %f,%f",
+ x, y, xpos, 1.0 - ypos);
}
num--;
@@ -45,7 +45,7 @@
data->light[num].z = z;
data->light[num].w = w;
- G_debug(3, "Nviz_set_light_position(): num = %d x = %f y = %f z = %f w = %f",
+ G_debug(0, "Nviz_set_light_position(): num = %d x = %f y = %f z = %f w = %f",
num + 1, x, y, z, w);
GS_setlight_position(num + 1, x, y, z, w);
@@ -59,9 +59,9 @@
\param num light num (starts at 1)
\param value brightness value
*/
-int Nviz_set_light_bright(nv_data * data, int num, float value)
+int Nviz_set_light_bright(nv_data * data, int num, double value)
{
- float r, g, b;
+ double r, g, b;
num--;
data->light[num].brt = value;
@@ -70,8 +70,8 @@
g = data->light[num].g * data->light[num].brt;
b = data->light[num].b * data->light[num].brt;
- G_debug(3, "Nviz_set_light_bright(): num = %d r = %f g = %f b = %f",
- num + 1, r, g, b);
+ G_debug(0, "Nviz_set_light_bright(): num = %d value = %f r = %f g = %f b = %f",
+ num + 1, value, r, g, b);
GS_setlight_color(num + 1, r, g, b);
return 1;
@@ -82,23 +82,23 @@
\param data nviz data
\param num light num (starts at 1)
- \param red,green,blue rGB values (0-1)
+ \param red,green,blue RGB values (0-255)
*/
int Nviz_set_light_color(nv_data * data, int num,
- float red, float green, float blue)
+ int red, int green, int blue)
{
- float r, g, b;
+ double r, g, b;
num--;
- data->light[num].r = red;
- data->light[num].g = green;
- data->light[num].b = blue;
+ data->light[num].r = red / 255.;
+ data->light[num].g = green / 255.;
+ data->light[num].b = blue / 255.;
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;
- G_debug(3, "Nviz_set_light_color(): num = %d r = %f g = %f b = %f",
+ G_debug(0, "Nviz_set_light_color(): num = %d r = %f g = %f b = %f",
num + 1, r, g, b);
GS_setlight_color(num + 1, r, g, b);
@@ -113,14 +113,14 @@
\param red,green,blue rGB values (0-1)
*/
int Nviz_set_light_ambient(nv_data * data, int num,
- float red, float green, float blue)
+ double red, double green, double blue)
{
num--;
data->light[num].ar = red;
data->light[num].ag = green;
data->light[num].ab = blue;
- G_debug(3, "Nviz_set_light_ambient(): num = %d r = %f g = %f b = %f",
+ G_debug(0, "Nviz_set_light_ambient(): num = %d r = %f g = %f b = %f",
num + 1, red, green, blue);
GS_setlight_ambient(num + 1, red, green, blue);
@@ -179,3 +179,4 @@
return 1;
}
+
Modified: grass/trunk/lib/nviz/map_obj.c
===================================================================
--- grass/trunk/lib/nviz/map_obj.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/lib/nviz/map_obj.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -41,7 +41,7 @@
\return map object id
\return -1 on error
*/
-int Nviz_new_map_obj(int type, const char *name, float value, nv_data * data)
+int Nviz_new_map_obj(int type, const char *name, double value, nv_data * data)
{
int new_id, i;
int num_surfs, *surf_list;
@@ -203,16 +203,16 @@
\param desc attribute descriptor
\param src attribute source
\param str_value attribute value as string (if NULL, check for <i>num_value</i>)
- \param num_value attribute value as float
+ \param num_value attribute value as double
\return 1 on success
\return 0 on failure
*/
int Nviz_set_attr(int id, int type, int desc, int src,
- const char *str_value, float num_value, nv_data * data)
+ const char *str_value, double num_value, nv_data * data)
{
int ret;
- float value;
+ double value;
switch (type) {
case (MAP_OBJ_SURF):{
@@ -225,7 +225,7 @@
* Note that we require the constant to be an integer
*/
if (str_value)
- value = (float)atof(str_value);
+ value = (double)atof(str_value);
else
value = num_value;
@@ -328,7 +328,6 @@
*/
int Nviz_set_vpoint_attr_default(int id)
{
- int i;
geosite *gp;
gp = gp_get_site(id);
Modified: grass/trunk/lib/nviz/position.c
===================================================================
--- grass/trunk/lib/nviz/position.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/lib/nviz/position.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -16,15 +16,25 @@
#include <grass/nviz.h>
/*!
- Initialize view and position settings (focus)
+ Initialize view, position, lighting settings (focus)
Set position to center of view
*/
-void Nviz_init_view()
+void Nviz_init_view(nv_data *data)
{
GS_init_view();
Nviz_set_focus_state(1); /* center of view */
-
+
+ /* set default lights (1 & 2) */
+ Nviz_set_light_position(data, 1, 0.68, 0.68, 0.80, 0.0);
+ Nviz_set_light_bright(data, 1, 0.8);
+ Nviz_set_light_color(data, 1, 1.0, 1.0, 1.0);
+ Nviz_set_light_ambient(data, 1, 0.2, 0.2, 0.2);
+ Nviz_set_light_position(data, 2, 0.0, 0.0, 1.0, 0.0);
+ Nviz_set_light_bright(data, 2, 0.5);
+ Nviz_set_light_color(data, 2, 1.0, 1.0, 1.0);
+ Nviz_set_light_ambient(data, 2, 0.3, 0.3, 0.3);
+
return;
}
Modified: grass/trunk/visualization/nviz2/cmd/args.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/args.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/visualization/nviz2/cmd/args.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -29,6 +29,7 @@
static void args_vpoint(struct GParams *);
static void args_viewpoint(struct GParams *);
static void args_volume(struct GParams *);
+static void args_lighting(struct GParams *);
/*!
\brief Parse command
@@ -66,11 +67,14 @@
/*** viewpoint ***/
args_viewpoint(params);
+ /*** lighting ***/
+ args_lighting(params);
+
/*** output image ***/
/* output */
params->output = G_define_standard_option(G_OPT_F_OUTPUT);
params->output->description =
- _("Name for output file (without extension)");
+ _("Name for output image file (without extension)");
params->output->guisection = _("Image");
/* format */
@@ -93,7 +97,7 @@
params->size->type = TYPE_INTEGER;
params->size->key_desc = "width,height";
params->size->answer = "640,480";
- params->size->description = _("Width and height of output image");
+ params->size->description = _("Size (width, height) of output image");
params->size->required = YES;
params->size->guisection = _("Image");
@@ -134,8 +138,6 @@
params->color_const->multiple = YES;
params->color_const->label = _("Color value(s)");
params->color_const->guisection = _("Surfaces");
- params->color_const->key = "color_value";
- params->color_const->answer = NULL;
/* mask */
params->mask_map = G_define_standard_option(G_OPT_R_MAP);
@@ -284,7 +286,7 @@
/* position */
params->surface_pos = G_define_option();
- params->surface_pos->key = "position";
+ params->surface_pos->key = "surface_position";
params->surface_pos->key_desc = "x,y,z";
params->surface_pos->type = TYPE_INTEGER;
params->surface_pos->required = NO;
@@ -445,7 +447,7 @@
params->pos->description =
_("Viewpoint position (x,y model coordinates)");
params->pos->guisection = _("Viewpoint");
- params->pos->answer = "0.85,0.85";
+ params->pos->answer = "0.84,0.16";
/* height */
params->height = G_define_option();
@@ -559,6 +561,46 @@
return;
}
+void args_lighting(struct GParams *params)
+{
+ params->light_pos = G_define_option();
+ params->light_pos->key = "light_position";
+ params->light_pos->key_desc = "x,y,z";
+ params->light_pos->type = TYPE_DOUBLE;
+ params->light_pos->required = NO;
+ params->light_pos->multiple = NO;
+ params->light_pos->description =
+ _("Light position (x,y,z model coordinates)");
+ params->light_pos->guisection = _("Lighting");
+ params->light_pos->answer = "0.68,0.68,0.80";
+
+ params->light_color = G_define_standard_option(G_OPT_C_FG);
+ params->light_color->key = "light_color";
+ params->light_color->label = _("Light color");
+ params->light_color->guisection = _("Lighting");
+ params->light_color->answer = "white";
+
+ params->light_bright = G_define_option();
+ params->light_bright->key = "light_brightness";
+ params->light_bright->type = TYPE_INTEGER;
+ params->light_bright->required = NO;
+ params->light_bright->multiple = NO;
+ params->light_bright->description = _("Light brightness");
+ params->light_bright->guisection = _("Lighting");
+ params->light_bright->answer = "80";
+ params->light_bright->options="0-100";
+
+ params->light_ambient = G_define_option();
+ params->light_ambient->key = "light_ambient";
+ params->light_ambient->type = TYPE_INTEGER;
+ params->light_ambient->required = NO;
+ params->light_ambient->multiple = NO;
+ params->light_ambient->description = _("Light ambient");
+ params->light_ambient->guisection = _("Lighting");
+ params->light_ambient->answer = "20";
+ params->light_ambient->options="0-100";
+}
+
/*!
\brief Get number of answers of given option
Modified: grass/trunk/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/trunk/visualization/nviz2/cmd/local_proto.h 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/visualization/nviz2/cmd/local_proto.h 2010-06-20 19:02:52 UTC (rev 42607)
@@ -11,22 +11,24 @@
struct Option
/* surface */
*elev_map, *elev_const, *color_map, *color_const,
- *mask_map, *transp_map, *transp_const, *shine_map, *shine_const,
- *emit_map, *emit_const,
+ *mask_map, *transp_map, *transp_const, *shine_map, *shine_const,
+ *emit_map, *emit_const,
/* surface draw mode */
- *mode, *res_fine, *res_coarse, *style, *shade, *wire_color, *surface_pos,
+ *mode, *res_fine, *res_coarse, *style, *shade, *wire_color, *surface_pos,
/* vector lines */
- *vlines, *vline_width, *vline_color, *vline_mode, *vline_height, *vline_pos,
+ *vlines, *vline_width, *vline_color, *vline_mode, *vline_height, *vline_pos,
/* vector points */
- *vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width, *vpoint_pos,
+ *vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width, *vpoint_pos,
/* volumes */
- *volume, *volume_mode, *volume_shade, *volume_pos, *volume_res, *isosurf_level,
+ *volume, *volume_mode, *volume_shade, *volume_pos, *volume_res, *isosurf_level,
/* misc */
- *exag, *bgcolor,
+ *exag, *bgcolor,
/* viewpoint */
- *pos, *height, *persp, *twist,
+ *pos, *height, *persp, *twist,
/* output */
- *output, *format, *size;
+ *output, *format, *size,
+ /* lighting */
+ *light_pos, *light_color, *light_bright, *light_ambient;
};
/* args.c */
Modified: grass/trunk/visualization/nviz2/cmd/main.c
===================================================================
--- grass/trunk/visualization/nviz2/cmd/main.c 2010-06-20 19:00:37 UTC (rev 42606)
+++ grass/trunk/visualization/nviz2/cmd/main.c 2010-06-20 19:02:52 UTC (rev 42607)
@@ -19,6 +19,7 @@
#include <string.h>
#include <grass/gis.h>
+#include <grass/colors.h>
#include <grass/glocale.h>
#include <grass/nviz.h>
@@ -32,7 +33,9 @@
struct GParams *params;
int ret;
- float vp_height, z_exag; /* calculated viewpoint height, z-exag */
+ int red, grn, blu;
+ double vp_height, z_exag; /* calculated viewpoint height, z-exag */
+ double light_ambient;
int width, height; /* output image size */
char *output_name;
@@ -85,19 +88,25 @@
/* set background color */
Nviz_set_bgcolor(&data, Nviz_color_from_str(params->bgcolor->answer));
- /* init view */
- Nviz_init_view();
+ /* init view, lights */
+ Nviz_init_view(&data);
+
/* 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);
-
+ Nviz_set_light_position(&data, 1,
+ atof(params->light_pos->answers[0]),
+ atof(params->light_pos->answers[1]),
+ atof(params->light_pos->answers[2]),
+ 0.0);
+ Nviz_set_light_bright(&data, 1,
+ atoi(params->light_bright->answer) / 100.0);
+ if(G_str_to_color(params->light_color->answer, &red, &grn, &blu) != 1) {
+ red = grn = blu = 255;
+ }
+ Nviz_set_light_color(&data, 1, red, grn, blu);
+ light_ambient = atof(params->light_ambient->answer) / 100.0;
+ Nviz_set_light_ambient(&data, 1,
+ light_ambient, light_ambient, light_ambient);
+
/* load raster maps (surface topography) & set attributes (map/constant) */
load_rasters(params, &data);
/* set draw mode of loaded surfaces */
@@ -149,13 +158,12 @@
G_message(_("Viewpoint height not given, using calculated value %.0f"),
vp_height);
}
- Nviz_set_viewpoint_height(&data, vp_height);
+ Nviz_set_viewpoint_height(vp_height);
- Nviz_set_viewpoint_position(&data,
- atof(params->pos->answers[0]),
+ Nviz_set_viewpoint_position(atof(params->pos->answers[0]),
atof(params->pos->answers[1]));
- Nviz_set_viewpoint_twist(&data, atoi(params->twist->answer));
- Nviz_set_viewpoint_persp(&data, atoi(params->persp->answer));
+ Nviz_set_viewpoint_twist(atoi(params->twist->answer));
+ Nviz_set_viewpoint_persp(atoi(params->persp->answer));
GS_clear(data.bgcolor);
More information about the grass-commit
mailing list