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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 5 13:28:54 PDT 2012


Author: momsen
Date: 2012-06-05 13:28:52 -0700 (Tue, 05 Jun 2012)
New Revision: 51979

Modified:
   grass-addons/grass7/imagery/i.segment/iseg.h
   grass-addons/grass7/imagery/i.segment/parse_args.c
   grass-addons/grass7/imagery/i.segment/write_output.c
Log:
input runs, write_output fails at line 42.

Modified: grass-addons/grass7/imagery/i.segment/iseg.h
===================================================================
--- grass-addons/grass7/imagery/i.segment/iseg.h	2012-06-05 19:54:11 UTC (rev 51978)
+++ grass-addons/grass7/imagery/i.segment/iseg.h	2012-06-05 20:28:52 UTC (rev 51979)
@@ -18,7 +18,7 @@
 {
 	/* int *band_fd, out_fd;   Do I need these, or is the SEGMENT enough? */
 	int nbands;
-	SEGMENT *bands_seg, *out_seg;
+	SEGMENT bands_seg, out_seg;
 	
 	// naming using "bands" to follow i.smap but it doesn't need to be just landsat bands
 	

Modified: grass-addons/grass7/imagery/i.segment/parse_args.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/parse_args.c	2012-06-05 19:54:11 UTC (rev 51978)
+++ grass-addons/grass7/imagery/i.segment/parse_args.c	2012-06-05 20:28:52 UTC (rev 51979)
@@ -27,8 +27,9 @@
 	double *inval;  /* array, to collect data from one column of inbuf to be put into segmentation file */
     char *in_file, *out_file;  /* original functions required const char, new segment_open() does not */
 
+	/*debugging */
+	SEGMENT testseg;
 
-
     group = G_define_standard_option(G_OPT_I_GROUP);
 
 	/* deleted subgroup line, but still appears in input form */
@@ -172,9 +173,8 @@
 	/* size of each element to be stored */
 	
 	inlen = sizeof(double) * Ref.nfiles;
-	outlen = sizeof(int) * 2;
+	outlen = sizeof(int) * 2;  /* change in write_output.c if this value changes TODO: better to save this in the files data structure?*/
 
-
     nrows = Rast_window_rows();
     ncols = Rast_window_cols();
 
@@ -200,20 +200,19 @@
 	G_debug(1, "File names, in: %s, out: %s", in_file, out_file);
 	G_debug(1, "Data element size, in: %d , out: %d ", inlen, outlen);
 	G_debug(1, "number of segments to have in memory: %d", nseg);
-	
-	G_debug(1, "return code from segment_open(): %d", segment_open(files->bands_seg, in_file, nrows, ncols, srows, scols, inlen, nseg ));
-
-/* don't seem to be getting an error code from segment_open().  Program just stops, without G_fatal_error() being called.*/
+	G_debug(1, "hi");
 		
 	/* size: reading all input bands as DCELL  TODO: could consider checking input to see if it is all FCELL or CELL, could reduce memory requirements.*/
 
-/*	if (segment_open(files->bands_seg, in_file, nrows, ncols, srows, scols, inlen, nseg ) != 1)
+	if (segment_open(&files->bands_seg, in_file, nrows, ncols, srows, scols, inlen, nseg ) != 1)
 		G_fatal_error("Unable to create input temporary files");
-	*/
+	
+	/* programmer's manual had G_tempfile() directly in call.  Do I need to know the temp file name to delete it? */
+	
 	G_debug(1, "finished segment_open(...bands_seg...)");
 	
 	/* TODO: signed integer gives a 2 billion segment limit, depending on how the initialization is done, this means 2 billion max input pixels. */
-	if (segment_open(files->out_seg, out_file, nrows, ncols, srows, scols, outlen, nseg ) != 1)
+	if (segment_open(&files->out_seg, out_file, nrows, ncols, srows, scols, outlen, nseg ) != 1)
 		G_fatal_error("Unable to create output temporary files");
 	
 /*
@@ -233,7 +232,7 @@
 			for (n = 0; n < Ref.nfiles; n++){
 				inval[n] = inbuf[n][col];
 			}
-		   segment_put(files->bands_seg, (void *)inval, row, col);
+		   segment_put(&files->bands_seg, (void *)inval, row, col);
 		}
     }
 

Modified: grass-addons/grass7/imagery/i.segment/write_output.c
===================================================================
--- grass-addons/grass7/imagery/i.segment/write_output.c	2012-06-05 19:54:11 UTC (rev 51978)
+++ grass-addons/grass7/imagery/i.segment/write_output.c	2012-06-05 20:28:52 UTC (rev 51979)
@@ -9,32 +9,48 @@
 
 int write_output(struct files *files)
 {
-	int out_fd, row, n;
-	void *outbuf;
-	outbuf = Rast_allocate_buf(files->data_type); 
+	int out_fd, row, col, nrows, ncols;
+	CELL *outbuf;
+	int *outval;
+	
+	outbuf = Rast_allocate_c_buf();
+	outval = (int *) G_malloc(2 * sizeof(int));
 
+	/*picked this up in the file reading as well, just do it again? */
+    nrows = Rast_window_rows();
+    ncols = Rast_window_cols();
+
 	/* Todo: return codes are 1 for these, need to check and react to errors? programmer's manual didn't include it... */
 	
-	segment_flush(files->out_seg); /* force all data to disk */
+	segment_flush(&files->out_seg); /* force all data to disk */
 	
-	
+	G_debug(1, "preparing output raster");
 	/* open output raster map */
 	out_fd = Rast_open_new(files->out_name, files->data_type); /* I assume even if it already exists, this will overwrite it... */
 	
-	/* transfer data row by row */
-	for (row = 0; row < 100; row++) /* need to acces nrows, syntax?  files->out_seg::nrows  ??? */
-	{
-		segment_get_row (files->out_seg, outbuf, row); //segment_get_row (SEGMENT *seg, char *buf, int row)
-		Rast_put_row(out_fd, outbuf, files->data_type);
+	G_debug(1, "start data transfer from segmentation file to raster");
+	/* transfer data from segmentation file to raster*/
+	/* output segmentation file, each element includes the segment ID then the processing flag.  So just need the first part of it. */
+	/* Hmm, does this mean I can't use a buffer, since the length isn't simply integer or float?! */
+
+    for (row = 0; row < nrows; row++) {
+		G_percent(row, nrows, 1);
+		for (col = 0; col < ncols; col++) {
+			G_debug(1, "got here");
+			segment_get(&files->out_seg, &outval, row, col); /* segment_get (&seg, &value, row, col); */
+			G_debug(1, "segment_get() worked");
+			G_debug(1, "outval[0] = %i", outval[0]); /*This didn't work - something is wrong with outval reference */
+			outbuf[col] = outval[0]; /*just want segment assignment, not the other processing flag(s) */
+			}
+		G_debug(1, "just before Rast_put_row()");
+		Rast_put_row(out_fd, outbuf, CELL_TYPE);
 	}
+
 	
 	/* close segmentation files and output raster */
-	
-	for(n = 0; n < files->nbands; n++)
-	{
-		segment_release (files->bands_seg);
-	}
-	segment_release (files->out_seg);
+	G_debug(1, "closing files");
+	segment_release (&files->bands_seg);
+	segment_release (&files->out_seg);
 	close (out_fd);
 
 /* TODO Note: The Segment Library does not know the name of the segment file. It does not attempt to remove the file. If the file is only temporary, the programmer should remove the file after closing it. */



More information about the grass-commit mailing list