[GRASS-SVN] r51917 - grass-addons/grass7/imagery/i.segment
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jun 1 06:49:08 PDT 2012
Author: momsen
Date: 2012-06-01 06:49:07 -0700 (Fri, 01 Jun 2012)
New Revision: 51917
Added:
grass-addons/grass7/imagery/i.segment/iseg.h
Removed:
grass-addons/grass7/imagery/i.segment/segment.h
Modified:
grass-addons/grass7/imagery/i.segment/get_input.c
grass-addons/grass7/imagery/i.segment/main.c
Log:
rename to avoid use of word -segment-
Modified: grass-addons/grass7/imagery/i.segment/get_input.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/get_input.c 2012-06-01 12:29:05 UTC (rev 51916)
+++ grass-addons/grass7/imagery/i.segment/get_input.c 2012-06-01 13:49:07 UTC (rev 51917)
@@ -28,11 +28,21 @@
input->required = YES;
input->description = _("Raster map to be segmented.");
- seeds = G_define_standard_option(G_OPT_V_INPUT);
+ //~ 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.");
+//~ need to add a secondary part of this input (centroids or points) and validate 0 or both optional parameters are used.
+ //~ The vector input seems more user friendly, but raster will be more straightforward to implement.
+ //~ Is there any concern that the raster seeds will cover more than one pixel if the resolution is changed?
+ //~ That might be a reason to switch back to points later.
+//~
+ seeds = G_define_standard_option(G_OPT_R_INPUT);
seeds->key = "seeds";
seeds->type = TYPE_STRING;
seeds->required = NO;
- seeds->description = _("Optional vector map with starting seeds.");
+ seeds->description = _("Optional raster map with starting seeds.");
output = G_define_standard_option(G_OPT_R_OUTPUT);
output->key = "output";
@@ -63,8 +73,19 @@
threshold->required = YES;
threshold->description = _("Similarity threshold.");
+ diagonal = G_define_flag();
+ diagonal->key = 'd';
+ diagonal->description = _("Use 8 neighbors (3x3 neighborhood) instead of the default 4 neighbors for each pixel.");
+
//use checker for any of the data validation steps!?
+ //~ G_debug(1, "testing debug!");
+ //~ When put this in, get an error (only when DEBUG is set, if not set, it runs fine)
+ //~
+ //~ Error box:
+ //~ Unable to fetch interface description for command 'i.segment'.
+ //~ Details: D1/1: testing debug!
+
if (G_parser(argc, argv))
exit (EXIT_FAILURE);
Copied: grass-addons/grass7/imagery/i.segment/iseg.h (from rev 51916, grass-addons/grass7/imagery/i.segment/segment.h)
===================================================================
--- grass-addons/grass7/imagery/i.segment/iseg.h (rev 0)
+++ grass-addons/grass7/imagery/i.segment/iseg.h 2012-06-01 13:49:07 UTC (rev 51917)
@@ -0,0 +1,20 @@
+/****************************************************************************
+ *
+ * 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;
+extern struct Flag *diagonal;
+extern int in_fd, out_fd;
+
+/* get_input.c */
+int get_input(int, char *[]);
Modified: grass-addons/grass7/imagery/i.segment/main.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/main.c 2012-06-01 12:29:05 UTC (rev 51916)
+++ grass-addons/grass7/imagery/i.segment/main.c 2012-06-01 13:49:07 UTC (rev 51917)
@@ -18,6 +18,7 @@
#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 <grass/raster.h>
#include "segment.h"
//~ (for my reference, order for headers), adding them only as needed...
@@ -28,9 +29,15 @@
struct GModule *module;
struct Option *input, *seeds, *output, *method, *threshold; /* Establish an Option pointer for each option */
+struct Flag *diagonal; /* Establish a Flag pointer for each option */
+int in_fd, out_fd;
-// ? Any reasons not to use global variables for this application?
+RASTER_MAP_TYPE data_type;
+int row, col, nrows, ncols;
+void *inbuf;
+// ? Any reasons not to use "modular global" variables for this application?
+
int main(int argc, char *argv[])
{
G_gisinit(argv[0]);
@@ -42,23 +49,47 @@
get_input(argc, argv);
- //debug/testing stuff... delete when done.
- G_message("For the option <%s> you chose: <%s>",
+ G_debug(1, "For the option <%s> you chose: <%s>",
input->description, input->answer);
- G_message("For the option <%s> you chose: <%s>",
+ G_debug(1, "For the option <%s> you chose: <%s>",
seeds->description, seeds->answer);
- G_message("For the option <%s> you chose: <%s>",
+ G_debug(1, "For the option <%s> you chose: <%s>",
output->description, output->answer);
- G_message("For the option <%s> you chose: <%s>",
+ G_debug(1, "For the option <%s> you chose: <%s>",
method->description, method->answer);
- G_message("For the option <%s> you chose: <%s>",
+ G_debug(1, "For the option <%s> you chose: <%s>",
threshold->description, threshold->answer);
-
- G_done_msg("Any other messages?");
+ G_debug(1, "The value of the diagonal flag is: %d", diagonal->answer);
+
+
+
+ in_fd = Rast_open_old(input->answer, "");
+ data_type = Rast_get_map_type(in_fd); /*TODO: when add group/subgroup, need to check if all input are same data_type*/
+ out_fd = Rast_open_new(output->answer, data_type);
+ inbuf = Rast_allocate_buf(data_type);
+
+ nrows = Rast_window_rows();
+ ncols = Rast_window_cols();
+
+ for (row = 0; row < nrows; row++) {
+ Rast_get_row(in_fd, inbuf, row, data_type);
+ //~ for (col = 0; col < ncols; col++) {
+ //~
+ //~ }
+
+ Rast_put_row(out_fd, inbuf, data_type);
+ }
+
+ G_free(inbuf);
+ Rast_close(in_fd);
+ Rast_close(out_fd);
+
+ G_done_msg("Number of segments created: ");
+
exit(EXIT_SUCCESS);
}
Deleted: grass-addons/grass7/imagery/i.segment/segment.h
===================================================================
--- grass-addons/grass7/imagery/i.segment/segment.h 2012-06-01 12:29:05 UTC (rev 51916)
+++ grass-addons/grass7/imagery/i.segment/segment.h 2012-06-01 13:49:07 UTC (rev 51917)
@@ -1,18 +0,0 @@
-/****************************************************************************
- *
- * 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