[GRASS-SVN] r51896 - grass-addons/grass7/imagery/i.segment

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 30 14:49:45 PDT 2012


Author: momsen
Date: 2012-05-30 14:49:44 -0700 (Wed, 30 May 2012)
New Revision: 51896

Added:
   grass-addons/grass7/imagery/i.segment/Makefile
   grass-addons/grass7/imagery/i.segment/get_input.c
   grass-addons/grass7/imagery/i.segment/i.segment.html
   grass-addons/grass7/imagery/i.segment/main.c
   grass-addons/grass7/imagery/i.segment/segment.h
Log:
File structure framework, step 1 to collect input.

Added: grass-addons/grass7/imagery/i.segment/Makefile
===================================================================
--- grass-addons/grass7/imagery/i.segment/Makefile	                        (rev 0)
+++ grass-addons/grass7/imagery/i.segment/Makefile	2012-05-30 21:49:44 UTC (rev 51896)
@@ -0,0 +1,10 @@
+MODULE_TOPDIR = ../..
+
+PGM = i.segment
+
+LIBES = $(GISLIB)
+DEPENDENCIES = $(GISDEP)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd

Added: grass-addons/grass7/imagery/i.segment/get_input.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/get_input.c	                        (rev 0)
+++ grass-addons/grass7/imagery/i.segment/get_input.c	2012-05-30 21:49:44 UTC (rev 51896)
@@ -0,0 +1,72 @@
+/****************************************************************************
+ *
+ * MODULE:       i.segment
+ * AUTHOR(S):    Eric Momsen <eric.momsen at gmail com>
+ * PURPOSE:      Parse and validate the input
+ * COPYRIGHT:    (C) 2012 by Eric Momsen, and the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the COPYING file that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+
+//Should this type of comment block go at the beginning of all sub files?
+
+#include <stdlib.h>
+#include <grass/gis.h>
+#include <grass/glocale.h>
+#include "segment.h"
+
+int get_input(int argc, char *argv[])
+{
+	//reference: http://grass.osgeo.org/programming7/gislib.html#Command_Line_Parsing
+	
+	input = G_define_standard_option(G_OPT_R_INPUT);   /* Request a pointer to memory for each option */
+	input->key = "input"; /* TODO: update to allow groups.  Maybe this needs a group/subgroup variables, or we can check if the input is group/subgroup/raster */
+	input->type = TYPE_STRING;
+	input->required = YES;
+	input->description = _("Raster map to be segmented.");
+	
+	seeds = G_define_standard_option(G_OPT_V_INPUT);
+	seeds->key = "seeds";
+	seeds->type = TYPE_STRING;
+	seeds->required = NO;
+	seeds->description = _("Optional vector map with starting seeds.");
+	
+	output = G_define_standard_option(G_OPT_R_OUTPUT);
+	output->key = "output";
+	output->type = TYPE_STRING;
+	output->required = YES;
+	output->description = _("Name of output raster map.");
+//TODO: when put in a new raster map, error message:
+//~ Command 'd.rast map=testing at samples' failed
+//~ Details: Raster map <testing at samples> not found
+
+//Also, that error seems to be accumulated, putting in a new output map names results in:
+//~ Command 'd.rast map=testing at samples' failed
+//~ Details: Raster map <testing at samples> not found
+//~ Command 'd.rast map=test2 at samples' failed
+//~ Details: Raster map <test2 at samples> not found
+	
+	method = G_define_option();
+	method->key = "method";
+	method->type = TYPE_STRING;
+	method->required = NO;
+	method->answer = _("region growing");
+	method->options = "region growing, mean shift";
+	method->description = _("Segmentation method.");
+	
+	threshold = G_define_option();
+	threshold->key = "threshold";
+	threshold->type = TYPE_DOUBLE;
+	threshold->required = YES;
+	threshold->description = _("Similarity threshold.");
+	
+	//use checker for any of the data validation steps!?
+	
+	if (G_parser(argc, argv))
+        exit (EXIT_FAILURE);
+
+	return 0;
+}

Added: grass-addons/grass7/imagery/i.segment/i.segment.html
===================================================================
--- grass-addons/grass7/imagery/i.segment/i.segment.html	                        (rev 0)
+++ grass-addons/grass7/imagery/i.segment/i.segment.html	2012-05-30 21:49:44 UTC (rev 51896)
@@ -0,0 +1,8 @@
+<h2>DESCRIPTION</h2>
+<H2>NOTES</h2>
+<H2>EXAMPLES</h2>
+<h2>TODO</h2>
+<h2>BUGS</h2>
+<H2>REFERENCES</h2>
+<h2>SEE ALSO</h2>
+<h2>AUTHORS</h2>

Added: grass-addons/grass7/imagery/i.segment/main.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/main.c	                        (rev 0)
+++ grass-addons/grass7/imagery/i.segment/main.c	2012-05-30 21:49:44 UTC (rev 51896)
@@ -0,0 +1,64 @@
+/****************************************************************************
+ *
+ * MODULE:       i.segment
+ * AUTHOR(S):    Eric Momsen <eric.momsen at gmail com>
+ * PURPOSE:      Provide short description of module here...
+ * COPYRIGHT:    (C) 2012 by Eric Momsen, and the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the COPYING file that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+
+// #include <grass/config.h>
+
+#include <stdlib.h>
+// #include <unistd.h>
+#include <grass/gis.h>
+//#include <grass/imagery.h>
+#include <grass/glocale.h>   //defines _()  what exactly is that doing...(something about local language translation?) anything else in glocale.h that I should be aware of...
+#include "segment.h"
+
+//~ (for my reference, order for headers), adding them only as needed...
+//~ 1. Core system headers (stdio.h, ctype.h, ...)
+//~ 2. Headers for non-core system components (X11, libraries).
+//~ 3. Headers for core systems of the package being compiled (grass/gis.h, grass/glocale.h, ...)
+//~ 4. Headers for the specific library/program being compiled (geodesic.h, ...)
+
+struct GModule *module;
+struct Option *input, *seeds, *output, *method, *threshold;       /* Establish an Option pointer for each option */
+
+// ? Any reasons not to use global variables for this application?
+
+int main(int argc, char *argv[])
+{
+	G_gisinit(argv[0]);
+		
+	module = G_define_module();
+	G_add_keyword(_("imagery"));
+	G_add_keyword(_("segmentation"));
+	module->description = _("Segments an image.");
+
+	get_input(argc, argv);
+	
+	//debug/testing stuff... delete when done.
+	G_message("For the option <%s> you chose: <%s>",
+		  input->description, input->answer);
+	 
+	G_message("For the option <%s> you chose: <%s>",
+		  seeds->description, seeds->answer);
+	
+	G_message("For the option <%s> you chose: <%s>",
+		  output->description, output->answer);
+	
+	G_message("For the option <%s> you chose: <%s>",
+		  method->description, method->answer);
+		  
+	G_message("For the option <%s> you chose: <%s>",
+		  threshold->description, threshold->answer);
+		  
+	G_done_msg("Any other messages?");
+	
+	exit(EXIT_SUCCESS);
+}

Added: grass-addons/grass7/imagery/i.segment/segment.h
===================================================================
--- grass-addons/grass7/imagery/i.segment/segment.h	                        (rev 0)
+++ grass-addons/grass7/imagery/i.segment/segment.h	2012-05-30 21:49:44 UTC (rev 51896)
@@ -0,0 +1,18 @@
+/****************************************************************************
+ *
+ * MODULE:       i.segment
+ * AUTHOR(S):    Eric Momsen <eric.momsen at gmail com>
+ * PURPOSE:      global variable and function listing
+ * COPYRIGHT:    (C) 2012 by Eric Momsen, and the GRASS Development Team
+ *
+ *               This program is free software under the GNU General Public
+ *               License (>=v2). Read the COPYING file that comes with GRASS
+ *               for details.
+ *
+ *****************************************************************************/
+
+extern struct GModule *module;
+extern struct Option *input, *seeds, *output, *method, *threshold;
+
+/* get_input.c */
+int get_input(int, char *[]);



More information about the grass-commit mailing list