[GRASS-SVN] r44866 - grass/trunk/raster/r.thin

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 4 08:45:49 EST 2011


Author: mmetz
Date: 2011-01-04 05:45:49 -0800 (Tue, 04 Jan 2011)
New Revision: 44866

Modified:
   grass/trunk/raster/r.thin/io.c
   grass/trunk/raster/r.thin/thin_lines.c
Log:
use NULL instead of zero, zero is a valid number

Modified: grass/trunk/raster/r.thin/io.c
===================================================================
--- grass/trunk/raster/r.thin/io.c	2011-01-04 13:30:40 UTC (rev 44865)
+++ grass/trunk/raster/r.thin/io.c	2011-01-04 13:45:49 UTC (rev 44866)
@@ -85,13 +85,16 @@
 int open_file(char *name)
 {
     int cell_file, buf_len;
-    int i, row, col;
-    char cell[100];
+    int i, row;
     CELL *buf;
 
     /* open raster map */
-    strcpy(cell, name);
-    cell_file = Rast_open_old(cell, "");
+    cell_file = Rast_open_old(name, "");
+    
+    if (Rast_get_map_type(cell_file) != CELL_TYPE) {
+	Rast_close(cell_file);
+	G_fatal_error(_("Input raster must be of type CELL."));
+    }
 
     n_rows = Rast_window_rows();
     n_cols = Rast_window_cols();
@@ -110,8 +113,7 @@
     }
     buf_len = n_cols * sizeof(CELL);
     buf = (CELL *) G_malloc(buf_len);
-    for (col = 0; col < n_cols; col++)
-	buf[col] = 0;
+    Rast_set_c_null_value(buf, n_cols);
     for (i = 0; i < PAD; i++) {
 	if (write(work_file, buf, buf_len) != buf_len) {
 	    unlink(work_file_name);
@@ -121,10 +123,6 @@
     }
     for (row = 0; row < n_rows; row++) {
 	Rast_get_c_row(cell_file, buf + PAD, row);
-	for (col = 0; col < n_cols; col++) {
-	    if (Rast_is_c_null_value(&buf[col]))
-		buf[col] = 0;
-	}
 	if (write(work_file, buf, buf_len) != buf_len) {
 	    unlink(work_file_name);
 	    G_fatal_error(_("%s: Error writing temporary file"),
@@ -132,8 +130,7 @@
 	}
     }
 
-    for (col = 0; col < n_cols; col++)
-	buf[col] = 0;
+    Rast_set_c_null_value(buf, n_cols);
 
     for (i = 0; i < PAD; i++) {
 	if (write(work_file, buf, buf_len) != buf_len) {
@@ -154,7 +151,7 @@
 int close_file(char *name)
 {
     int cell_file, row, k;
-    int row_count, col_count, col;
+    int row_count, col_count;
     CELL *buf;
 
     cell_file = Rast_open_c_new(name);
@@ -167,10 +164,6 @@
 
     for (row = 0, k = PAD; row < row_count; row++, k++) {
 	buf = get_a_row(k);
-	for (col = 0; col < n_cols; col++) {
-	    if (buf[col] == 0)
-		Rast_set_null_value(&buf[col], 1, CELL_TYPE);
-	}
 	Rast_put_row(cell_file, buf + PAD, CELL_TYPE);
     }
     Rast_close(cell_file);

Modified: grass/trunk/raster/r.thin/thin_lines.c
===================================================================
--- grass/trunk/raster/r.thin/thin_lines.c	2011-01-04 13:30:40 UTC (rev 44865)
+++ grass/trunk/raster/r.thin/thin_lines.c	2011-01-04 13:45:49 UTC (rev 44866)
@@ -49,7 +49,8 @@
 	top = bottom;		/* line above the one we're changing */
 	bottom = get_a_row(row);	/* line we're working on now */
 	for (col = pad_size; col < n_cols - pad_size; col++) {
-	    if (bottom[col]) {	/* not background pixel */
+	    /* skip background cells */
+	    if (!Rast_is_c_null_value(&(bottom[col]))) {
 		if (col < box_left)	/* find bounding box which will */
 		    box_left = col;	/*   cover part of raster map which */
 		if (col > box_right)	/*   has lines in it */
@@ -107,11 +108,9 @@
     N_Templ[7] = /* 00000010 */ 2;
 
     new_med = (CELL *) G_malloc(sizeof(CELL) * (n_cols));
-    for (i = 0; i < n_cols; i++)
-	new_med[i] = 0;
+    Rast_set_c_null_value(new_med, n_cols);
     row_buf = (CELL *) G_malloc(sizeof(CELL) * (n_cols));
-    for (i = 0; i < n_cols; i++)
-	row_buf[i] = 0;
+    Rast_set_c_null_value(row_buf, n_cols);
 
     deleted = 1;
     i = 1;
@@ -137,7 +136,7 @@
 		    new_med[col] = med[col];
 		bottom = get_a_row(row + 1);
 		for (col = box_left; col <= box_right; col++) {
-		    if (med[col]) {	/* if pixel is not blank */
+		    if (!Rast_is_c_null_value(&(med[col]))) {	/* if cell is not NULL */
 			W = encode_neighbours(top, med, bottom, col, 1);
 			/* current window */
 			N_W = encode_neighbours(top, med, bottom, col, -1);
@@ -150,7 +149,7 @@
 			     ((N_Templ[ind3] & N_W) == N_Templ[ind3]))) {
 			    /* fprintf(stdout, "col: %d,   row: %d\n", col, row); */
 			    deleted++;
-			    new_med[col] = 0;
+			    Rast_set_c_null_value(&(new_med[col]), 1);
 			}
 
 		    }		/* end blank pixel */
@@ -188,25 +187,23 @@
 
     T = 0;
     if (neg > 0)
-	T = (((middle[col + 1] != 0) << 5) | ((top[col + 1] !=
-					       0) << 6) | ((top[col] !=
-							    0) << 7) |
-	     ((top[col - 1] != 0)) | ((middle[col - 1] !=
-				       0) << 1) | ((bottom[col - 1] !=
-						    0) << 2) | ((bottom[col]
-								 !=
-								 0) << 3) |
-	     ((bottom[col + 1] != 0) << 4));
+	T = (((!Rast_is_c_null_value(&(middle[col + 1]))) << 5) |
+	     ((!Rast_is_c_null_value(&(top[col + 1]))) << 6) |
+	     ((!Rast_is_c_null_value(&(top[col]))) << 7) |
+	     ((!Rast_is_c_null_value(&(top[col - 1])))) |
+	     ((!Rast_is_c_null_value(&(middle[col - 1]))) << 1) |
+	     ((!Rast_is_c_null_value(&(bottom[col - 1]))) << 2) |
+	     ((!Rast_is_c_null_value(&(bottom[col]))) << 3) |
+	     ((!Rast_is_c_null_value(&(bottom[col + 1]))) << 4));
     else
-	T = (((middle[col + 1] == 0) << 5) | ((top[col + 1] ==
-					       0) << 6) | ((top[col] ==
-							    0) << 7) |
-	     ((top[col - 1] == 0)) | ((middle[col - 1] ==
-				       0) << 1) | ((bottom[col - 1] ==
-						    0) << 2) | ((bottom[col]
-								 ==
-								 0) << 3) |
-	     ((bottom[col + 1] == 0) << 4));
+	T = (((Rast_is_c_null_value(&(middle[col + 1]))) << 5) |
+	     ((Rast_is_c_null_value(&(top[col + 1]))) << 6) |
+	     ((Rast_is_c_null_value(&(top[col]))) << 7) |
+	     ((Rast_is_c_null_value(&(top[col - 1])))) |
+	     ((Rast_is_c_null_value(&(middle[col - 1]))) << 1) |
+	     ((Rast_is_c_null_value(&(bottom[col - 1]))) << 2) |
+	     ((Rast_is_c_null_value(&(bottom[col]))) << 3) |
+	     ((Rast_is_c_null_value(&(bottom[col + 1]))) << 4));
 
     return (T);
 }



More information about the grass-commit mailing list