[GRASS-SVN] r36160 - grass/branches/develbranch_6/raster/r.los
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Mar 1 07:18:15 EST 2009
Author: hamish
Date: 2009-03-01 07:18:15 -0500 (Sun, 01 Mar 2009)
New Revision: 36160
Modified:
grass/branches/develbranch_6/raster/r.los/delete.c
grass/branches/develbranch_6/raster/r.los/main.c
grass/branches/develbranch_6/raster/r.los/point.h
grass/branches/develbranch_6/raster/r.los/pts_elim.c
Log:
bugfix for #111 by Benjamin Ducke; fix for calc'ing cell neighbourhoods in combination with raster masks by Mark Lake
Modified: grass/branches/develbranch_6/raster/r.los/delete.c
===================================================================
--- grass/branches/develbranch_6/raster/r.los/delete.c 2009-03-01 11:50:49 UTC (rev 36159)
+++ grass/branches/develbranch_6/raster/r.los/delete.c 2009-03-01 12:18:15 UTC (rev 36160)
@@ -33,18 +33,61 @@
segment_put(seg_out_p, value,
row_viewpt - PT_TO_DELETE_Y, PT_TO_DELETE_X + col_viewpt);
- if (PT_TO_DELETE == head) { /* first one ? */
+ /* If first and last point. This fixes a bug in r.los. See pts_elim.c for details */
+ if ((PT_TO_DELETE == head) && (PT_NEXT_TO_DELETED == NULL)) {
NEXT_PT_BACK_PTR = NULL;
head = PT_NEXT_TO_DELETED;
G_free(PT_TO_DELETE);
return (head);
}
+ if (PT_TO_DELETE == head) { /* first one ? */
+ NEXT_PT_BACK_PTR = NULL;
+ head = PT_NEXT_TO_DELETED;
+ /*
+ We cannot delete this point right now, as pts_elim.c might still
+ reference it. Thus, we only mark it for deletion now by pointing
+ the global DELAYED_DELETE to it and free it the next time we
+ get here!
+ */
+ if ( DELAYED_DELETE != NULL ) {
+ G_free ( DELAYED_DELETE );
+ DELAYED_DELETE = NULL;
+ } else {
+ if ( PT_TO_DELETE != NULL ) {
+ DELAYED_DELETE = PT_TO_DELETE;
+ }
+ }
+
+ return (head);
+ }
+
+ /* If last point. This fixes a bug in r.los. See pts_elim.c for details */
+ if (PT_NEXT_TO_DELETED == NULL) {
+ PREVIOUS_PT_NEXT_PTR = PT_NEXT_TO_DELETED;
+ G_free(PT_TO_DELETE);
+ return (head);
+ }
+
/* otherwise */
NEXT_PT_BACK_PTR = PT_PREVIOUS_TO_DELETED;
PREVIOUS_PT_NEXT_PTR = PT_NEXT_TO_DELETED;
- G_free(PT_TO_DELETE);
+
+ /*
+ We cannot delete this point right now, as pts_elim.c might still
+ reference it. Thus, we only mark it for deletion now by pointing
+ the global DELAYED_DELETE to it and free it the next time we
+ get here!
+ */
+ if ( DELAYED_DELETE != NULL ) {
+ G_free ( DELAYED_DELETE );
+ DELAYED_DELETE = NULL;
+ } else {
+ if ( PT_TO_DELETE != NULL ) {
+ DELAYED_DELETE = PT_TO_DELETE;
+ }
+ }
return (head);
Modified: grass/branches/develbranch_6/raster/r.los/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.los/main.c 2009-03-01 11:50:49 UTC (rev 36159)
+++ grass/branches/develbranch_6/raster/r.los/main.c 2009-03-01 12:18:15 UTC (rev 36160)
@@ -125,6 +125,8 @@
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+ /* initialize delayed point deletion */
+ DELAYED_DELETE = NULL;
G_scan_easting(opt3->answers[0], &east, G_projection());
G_scan_northing(opt3->answers[1], &north, G_projection());
@@ -410,5 +412,10 @@
G_command_history(&history);
G_write_history(out_layer, &history);
+ /* release that last tiny bit of memory ... */
+ if ( DELAYED_DELETE != NULL ) {
+ G_free ( DELAYED_DELETE );
+ }
+
exit(EXIT_SUCCESS);
}
Modified: grass/branches/develbranch_6/raster/r.los/point.h
===================================================================
--- grass/branches/develbranch_6/raster/r.los/point.h 2009-03-01 11:50:49 UTC (rev 36159)
+++ grass/branches/develbranch_6/raster/r.los/point.h 2009-03-01 12:18:15 UTC (rev 36160)
@@ -48,6 +48,12 @@
struct point *segment(int, int, int, double, double,
int, int, int, int, SEGMENT *, SEGMENT *, SEGMENT *,
int, int, int, int, double);
+/*
+ For delayed deletion of points (see delete3.c).
+ Initially set to NULL in main.c.
+*/
+struct point *DELAYED_DELETE;
+
#endif
/****************************************************************/
Modified: grass/branches/develbranch_6/raster/r.los/pts_elim.c
===================================================================
--- grass/branches/develbranch_6/raster/r.los/pts_elim.c 2009-03-01 11:50:49 UTC (rev 36159)
+++ grass/branches/develbranch_6/raster/r.los/pts_elim.c 2009-03-01 12:18:15 UTC (rev 36160)
@@ -198,7 +198,20 @@
segment_get(seg_patt_p, &mask, row_viewpt - BLOCKING_PT_Y,
col_viewpt + BLOCKING_PT_X);
if (mask == 0 || G_is_null_value(&mask, CELL_TYPE)) {
- if (NEXT_BLOCKING_PT != NULL)
+
+ /* Commenting out the following fixes a bug in r.los.
+ In that program the 8 cells around the viewpoint
+ are marked as visible (when visible)
+ even if they fall outside the area of interest
+ specified by the patt_map. This occurs because
+ these cells are always the last blocking points
+ on the segment lists, and therefore don't get
+ deleted when they should. This fix allows them
+ to be deleted, but it required modifications
+ to delete.c. MWL 25/6/99 */
+
+ /* if (NEXT_BLOCKING_PT != NULL) */
+
head = delete(BLOCKING_PT, head, seg_out_p,
row_viewpt, col_viewpt);
}
More information about the grass-commit
mailing list