[GRASS-SVN] r31688 - grass-addons/visualization/nviz2/cmd
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jun 12 07:31:29 EDT 2008
Author: martinl
Date: 2008-06-12 07:31:29 -0400 (Thu, 12 Jun 2008)
New Revision: 31688
Modified:
grass-addons/visualization/nviz2/cmd/args.c
grass-addons/visualization/nviz2/cmd/local_proto.h
grass-addons/visualization/nviz2/cmd/main.c
grass-addons/visualization/nviz2/cmd/nviz.h
grass-addons/visualization/nviz2/cmd/write_img.c
Log:
nviz_cmd: options for output added (name, format, size)
Modified: grass-addons/visualization/nviz2/cmd/args.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/args.c 2008-06-12 08:22:16 UTC (rev 31687)
+++ grass-addons/visualization/nviz2/cmd/args.c 2008-06-12 11:31:29 UTC (rev 31688)
@@ -116,6 +116,29 @@
params->twist->answer = "0";
params->twist->options = "-180-180";
+ /* image */
+ 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");
+
+ params->format = G_define_option();
+ params->format->key = "format";
+ params->format->type = TYPE_STRING;
+ params->format->options = "ppm,tif"; /* TODO: png */
+ params->format->answer = "ppm";
+ params->format->description = _("Graphics file format");
+ params->format->required = YES;
+ params->format->guisection = _("Image");
+
+ params->size = G_define_option();
+ params->size->key = "size";
+ 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->required = YES;
+ params->size->guisection = _("Image");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
Modified: grass-addons/visualization/nviz2/cmd/local_proto.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/local_proto.h 2008-06-12 08:22:16 UTC (rev 31687)
+++ grass-addons/visualization/nviz2/cmd/local_proto.h 2008-06-12 11:31:29 UTC (rev 31688)
@@ -9,7 +9,8 @@
struct Option *elev, *color_map, *color_const, /* raster */
*vector, /* vector */
*exag, *bgcolor, /* misc */
- *pos, *height, *persp, *twist; /* viewpoint */
+ *pos, *height, *persp, *twist, /* viewpoint */
+ *output, *format, *size; /* output */
};
/* args.c */
@@ -76,6 +77,6 @@
void swap_gl();
/* write_img.c */
-int write_ppm(const char *);
+int write_img(const char *, int);
#endif /* __LOCAL_PROTO_H__ */
Modified: grass-addons/visualization/nviz2/cmd/main.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/main.c 2008-06-12 08:22:16 UTC (rev 31687)
+++ grass-addons/visualization/nviz2/cmd/main.c 2008-06-12 11:31:29 UTC (rev 31688)
@@ -16,6 +16,7 @@
*****************************************************************************/
#include <stdlib.h>
+#include <string.h>
#include <grass/gis.h>
#include <grass/glocale.h>
@@ -31,9 +32,11 @@
char *mapset;
unsigned int i;
- int id;
+ int id, ret;
unsigned int nelev, ncolor_map, ncolor_const, nvect;
float vp_height; /* calculated viewpoint height */
+ int width, height; /* output image size */
+ char *output_name;
nv_data data;
render_window offscreen;
@@ -50,6 +53,10 @@
/* define options, call G_parser() */
parse_command(argc, argv, 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);
+
GS_libinit();
/* GVL_libinit(); TODO */
@@ -57,7 +64,7 @@
/* define render window */
render_window_init(&offscreen);
- render_window_create(&offscreen, 640, 480); /* TOD0: option dim */
+ render_window_create(&offscreen, width, height); /* TOD0: option dim */
render_window_make_current(&offscreen);
/* initialize nviz data */
@@ -208,10 +215,18 @@
cplane_draw(&data, -1, -1);
draw_all (&data);
- write_ppm("test.ppm"); /* TODO: option 'format' */
+ ret = 0;
+ if (strcmp(params->format->answer, "ppm") == 0)
+ ret = write_img(output_name, FORMAT_PPM);
+ if (strcmp(params->format->answer, "tif") == 0)
+ ret = write_img(output_name, FORMAT_TIF);
+
+ if (!ret)
+ G_fatal_error(_("Unsupported output format"));
render_window_destroy(&offscreen);
+ G_free ((void *) output_name);
G_free ((void *) params);
exit(EXIT_SUCCESS);
Modified: grass-addons/visualization/nviz2/cmd/nviz.h
===================================================================
--- grass-addons/visualization/nviz2/cmd/nviz.h 2008-06-12 08:22:16 UTC (rev 31687)
+++ grass-addons/visualization/nviz2/cmd/nviz.h 2008-06-12 11:31:29 UTC (rev 31688)
@@ -19,6 +19,9 @@
#define GRN_MASK 0x0000FF00
#define BLU_MASK 0x00FF0000
+#define FORMAT_PPM 1
+#define FORMAT_TIF 2
+
/* data structures */
typedef struct{
int id;
Modified: grass-addons/visualization/nviz2/cmd/write_img.c
===================================================================
--- grass-addons/visualization/nviz2/cmd/write_img.c 2008-06-12 08:22:16 UTC (rev 31687)
+++ grass-addons/visualization/nviz2/cmd/write_img.c 2008-06-12 11:31:29 UTC (rev 31688)
@@ -25,11 +25,19 @@
\brief Save current GL screen to an ppm file.
\param name filename
+
+ \return 1 on success
+ \return 0 on failure (unsupported format)
*/
-int write_ppm(const char *name)
+int write_img(const char *name, int format)
{
- GS_write_ppm(name);
+ if (format == FORMAT_PPM)
+ GS_write_ppm(name);
+ else if (format == FORMAT_TIF)
+ GS_write_tif(name);
+ else
+ return 0;
return 1;
}
More information about the grass-commit
mailing list