[GRASS-SVN] r32614 - in grass/branches/develbranch_6: include lib/nviz visualization/nviz2/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 7 09:25:31 EDT 2008


Author: martinl
Date: 2008-08-07 09:25:31 -0400 (Thu, 07 Aug 2008)
New Revision: 32614

Added:
   grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c
Modified:
   grass/branches/develbranch_6/include/nviz.h
   grass/branches/develbranch_6/lib/nviz/draw.c
   grass/branches/develbranch_6/lib/nviz/map_obj.c
   grass/branches/develbranch_6/lib/nviz/nvizlib.dox
   grass/branches/develbranch_6/visualization/nviz2/cmd/args.c
   grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h
   grass/branches/develbranch_6/visualization/nviz2/cmd/main.c
   grass/branches/develbranch_6/visualization/nviz2/cmd/surface.c
   grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c
   grass/branches/develbranch_6/visualization/nviz2/cmd/write_img.c
Log:
nviz2: initial steps towards 3d raster data (volumes) support

Modified: grass/branches/develbranch_6/include/nviz.h
===================================================================
--- grass/branches/develbranch_6/include/nviz.h	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/include/nviz.h	2008-08-07 13:25:31 UTC (rev 32614)
@@ -172,6 +172,7 @@
 int Nviz_set_attr(int, int, int, int, const char *, float, nv_data *);
 void Nviz_set_surface_attr_default();
 int Nviz_set_vpoint_attr_default();
+int Nviz_set_volume_attr_default();
 int Nviz_unset_attr(int, int, int);
 
 /* nviz.c */

Modified: grass/branches/develbranch_6/lib/nviz/draw.c
===================================================================
--- grass/branches/develbranch_6/lib/nviz/draw.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/lib/nviz/draw.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -181,6 +181,25 @@
  */
 int Nviz_draw_all_vol(nv_data * dc)
 {
+    int *vol_list, nvols, i;
+
+    vol_list = GVL_get_vol_list(&nvols);
+
+    /* in case transparency is set */
+    GS_set_draw(GSD_BOTH);
+
+    GS_ready_draw();
+
+    for (i = 0; i < nvols; i++) {
+	GVL_draw_vol(vol_list[i]);
+    }
+
+    G_free(vol_list);
+
+    GS_done_draw();
+
+    GS_set_draw(GSD_BACK);
+
     return 1;
 }
 
@@ -198,7 +217,8 @@
     draw_surf = 1;
     draw_vect = 1;
     draw_site = 1;
-    draw_vol = 0;
+    draw_vol = 1;
+    /*
     draw_north_arrow = 0;
     arrow_x = 0;
     draw_label = 0;
@@ -206,7 +226,8 @@
     draw_fringe = 0;
     draw_scalebar = 0;
     draw_bar_x = 0;
-
+    */
+    
     GS_set_draw(GSD_BACK);	/* needs to be BACK to avoid flickering */
 
     GS_ready_draw();

Modified: grass/branches/develbranch_6/lib/nviz/map_obj.c
===================================================================
--- grass/branches/develbranch_6/lib/nviz/map_obj.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/lib/nviz/map_obj.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -143,7 +143,30 @@
 	}
 	G_free(surf_list);
     }
+    /* 3d raster map -> volume */
+    else if (type == MAP_OBJ_VOL) {
+	if (GVL_num_vols() >= MAX_VOLS) {
+	    G_warning(_("Maximum volumes loaded!"));
+	    return -1;
+	}
+	
+	new_id = GVL_new_vol();
 
+	/* load volume */
+	if (0 > GVL_load_vol(new_id, name)) {
+	    GVL_delete_vol(new_id);
+	    G_warning(_("Error loading 3d raster map <%s>"), name);
+	    return -1;
+	}
+
+	/* initilaze volume attributes */
+	Nviz_set_volume_attr_default(new_id);
+    }
+    else {
+	G_warning(_("Nviz_new_map_obj(): unsupported data type"));
+	return -1;
+    }
+
     /* initialize the client data filled for the new map object */
     client_data = (nv_clientdata *) G_malloc(sizeof(nv_clientdata));
 
@@ -324,6 +347,44 @@
 }
 
 /*!
+   \brief Set default volume attributes
+
+   \param id volume set id
+
+   \return 1 on success
+   \return 0 on failure
+ */
+int Nviz_set_volume_attr_default(int id)
+{
+    int rows, cols, depths;
+    int max;
+
+    GVL_get_dims(id, &rows, &cols, &depths);
+    max = (rows > cols) ? rows : cols;
+    max = (depths > max) ? depths : max;
+    max = max / 35;
+    if (max < 1)
+	max = 1;
+    
+    if (max > cols)
+	max = cols / 2;
+    if (max > rows)
+	max = rows / 2;
+    if (max > depths)
+	max = depths / 2;
+    
+    /* set default drawres and drawmode for isosurfaces */
+    GVL_isosurf_set_drawres(id, max, max, max);
+    GVL_isosurf_set_drawmode(id, DM_GOURAUD);
+    
+    /* set default drawres and drawmode for slices */
+    GVL_slice_set_drawres(id, 1, 1, 1);
+    GVL_slice_set_drawmode(id, DM_GOURAUD | DM_POLY);
+
+    return 1;
+}
+
+/*!
    Unset map object attribute
 
    \param id map object id

Modified: grass/branches/develbranch_6/lib/nviz/nvizlib.dox
===================================================================
--- grass/branches/develbranch_6/lib/nviz/nvizlib.dox	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/lib/nviz/nvizlib.dox	2008-08-07 13:25:31 UTC (rev 32614)
@@ -61,6 +61,10 @@
 
  - Nviz_set_surface_attr_default()
 
+ - Nviz_set_vpoint_attr_default()
+
+ - Nviz_set_volume_attr_default()
+
  - Nviz_unset_attr()
 
 \subsection nvizLights Lights settings

Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/args.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/args.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/args.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -3,7 +3,7 @@
 
    \brief Parse command
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
+   (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
@@ -30,6 +30,7 @@
 static void args_vline(struct GParams *);
 static void args_vpoint(struct GParams *);
 static void args_viewpoint(struct GParams *);
+static void args_volume(struct GParams *);
 
 /*!
    \brief Parse command
@@ -47,35 +48,26 @@
     params->mode_all->description =
 	_("Use draw mode for all loaded surfaces");
 
-    /*
-       surface attributes
-     */
+    /*** surface attributes ***/
     args_surface(params);
 
-    /*
-       vector lines
-     */
+    /*** vector lines ***/
     args_vline(params);
 
-    /*
-       vector points
-     */
+    /*** vector points ***/
     args_vpoint(params);
 
-    /*
-       misc
-     */
+    /*** volumes ***/
+    args_volume(params);
+
+    /*** misc ***/
     /* background color */
     params->bgcolor = G_define_standard_option(G_OPT_C_BG);
 
-    /*
-       viewpoint
-     */
+    /*** viewpoint ***/
     args_viewpoint(params);
 
-    /*
-       image
-     */
+    /*** output image ***/
     /* output */
     params->output = G_define_standard_option(G_OPT_F_OUTPUT);
     params->output->description =
@@ -465,6 +457,16 @@
     return;
 }
 
+void args_volume(struct GParams *params)
+{
+    params->volume = G_define_standard_option(G_OPT_R3_MAPS);
+    params->volume->required = NO;
+    params->volume->guisection = _("Volume");
+    params->volume->key = "rast3d";
+
+    return;
+}
+
 /*!
    \brief Get number of answers of given option
 

Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/local_proto.h	2008-08-07 13:25:31 UTC (rev 32614)
@@ -7,22 +7,26 @@
 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 lines */
-     *vlines, *vline_width, *vline_color, *vline_mode, *vline_height,
-	/* vector points */
-     *vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width,
-	/* misc */
-     *exag, *bgcolor,
-	/* viewpoint */
-     *pos, *height, *persp, *twist,
-	/* output */
-     *output, *format, *size;
+
+    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,
+    /* surface draw mode */
+      *mode, *res_fine, *res_coarse, *style, *shade, *wire_color,
+    /* vector lines */
+      *vlines, *vline_width, *vline_color, *vline_mode, *vline_height,
+    /* vector points */
+      *vpoints, *vpoint_size, *vpoint_marker, *vpoint_color, *vpoint_width,
+    /* volumes */
+      *volume,
+    /* misc */
+      *exag, *bgcolor,
+    /* viewpoint */
+      *pos, *height, *persp, *twist,
+    /* output */
+      *output, *format, *size;
 };
 
 /* args.c */
@@ -41,6 +45,9 @@
 int vlines_set_attrb(const struct GParams *);
 int vpoints_set_attrb(const struct GParams *);
 
+/* volume.c */
+int load_volume(const struct GParams *, nv_data *);
+
 /* write_img.c */
 int write_img(const char *, int);
 

Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/main.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/main.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/main.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -60,7 +60,7 @@
 	       params->format->answer);
 
     GS_libinit();
-    /* GVL_libinit(); TODO */
+    GVL_libinit();
 
     GS_set_swap_func(swap_gl);
 
@@ -111,6 +111,11 @@
 	vpoints_set_attrb(params);
     }
 
+    /* load volumes */
+    if (params->volume->answer) {
+	load_volume(params, &data);
+    }
+
     /* focus on loaded data */
     Nviz_set_focus_map(MAP_OBJ_UNDEFINED, -1);
 

Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/surface.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/surface.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/surface.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -3,7 +3,7 @@
 
    \brief Surface subroutines
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
+   (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

Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/vector.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -3,7 +3,7 @@
 
    \brief Vector subroutines
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
+   (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

Added: grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c	                        (rev 0)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -0,0 +1,51 @@
+/*!
+   \file volume.c
+
+   \brief Volume subroutines
+
+   (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 <grass/G3d.h>
+#include <grass/glocale.h>
+
+#include "local_proto.h"
+
+/*!
+   \brief Load 3d raster map layers -> volume
+
+   \param params module parameters
+   \param data nviz data
+
+   \return number of loaded volumes
+ */
+int load_volume(const struct GParams *params, nv_data *data)
+{
+    int i, nvol;
+    char *mapset;
+    
+    nvol = opt_get_num_answers(params->volume);
+
+    for (i = 0; i < nvol; i++) {
+	mapset = G_find_grid3(params->volume->answers[i], "");
+	if (mapset == NULL) {
+	    G_fatal_error(_("3d raster map <%s> not found"),
+			  params->volume->answers[i]);
+	}
+
+	Nviz_new_map_obj(MAP_OBJ_VOL,
+			 G_fully_qualified_name(params->volume->answers[i],
+						mapset),
+			 0.0, data);
+    }
+
+    return 1;
+}


Property changes on: grass/branches/develbranch_6/visualization/nviz2/cmd/volume.c
___________________________________________________________________
Name: svn:mime-type
   + text/x-csrc
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Modified: grass/branches/develbranch_6/visualization/nviz2/cmd/write_img.c
===================================================================
--- grass/branches/develbranch_6/visualization/nviz2/cmd/write_img.c	2008-08-07 13:23:36 UTC (rev 32613)
+++ grass/branches/develbranch_6/visualization/nviz2/cmd/write_img.c	2008-08-07 13:25:31 UTC (rev 32614)
@@ -3,7 +3,7 @@
 
    \brief Save current GL screen to image file.
 
-   COPYRIGHT: (C) 2008 by the GRASS Development Team
+   (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



More information about the grass-commit mailing list