int extract_areas(void) { double nullVal; row = col = top = 0; /* get started for read of first */ bottom = 1; /* line from raster map */ area_num = 0; tl_area = 0; G_set_d_null_value(&nullVal, 1); /* represents the "outside", the external null values */ assign_area(nullVal, 0); G_message(_("Extracting areas...")); scan_length = read_next(); while (read_next()) { /* read rest of file, one row at *//* a time */ G_percent(row, n_rows, 2); for (col = 0; col < scan_length - 1; col++) { tl = get_raster_value(buffer[top], col); /* top left in window */ tr = get_raster_value(buffer[top], col + 1); /* top right */ bl = get_raster_value(buffer[bottom], col); /* bottom left */ br = get_raster_value(buffer[bottom], col + 1); /* bottom right */ update_list(nabors()); } if (h_ptr != NULPTR) /* if we have a loose end, */ end_hline(); /* tie it down */ row++; } G_percent(row, n_rows, 2); write_area(a_list, e_list, area_num, n_equiv); G_free(a_list); G_free(e_list); return 0; } /* extract_areas */
int extract_lines(void) { n_alloced_ptrs = 0; row = -3; read_next(); read_next(); G_message(_("Extracting lines...")); switch (data_type) { case CELL_TYPE: { int rows = 1; while (read_next()) { CELL *m = &((CELL *) middle)[1]; CELL *t = &((CELL *) top)[1]; CELL *b = &((CELL *) bottom)[1]; G_percent(rows, n_rows, 2); for (col = 1; col < n_cols - 1; col++, t++, m++, b++) { m = &((CELL *) middle)[col]; t = &((CELL *) top)[col]; b = &((CELL *) bottom)[col]; if ((mc = !Rast_is_c_null_value(m))) { tl = !Rast_is_c_null_value(t - 1); tc = !Rast_is_c_null_value(t); tr = !Rast_is_c_null_value(t + 1); ml = !Rast_is_c_null_value(m - 1); mr = !Rast_is_c_null_value(m + 1); bl = !Rast_is_c_null_value(b - 1); bc = !Rast_is_c_null_value(b); br = !Rast_is_c_null_value(b + 1); update_list(nabors()); } } rows++; } G_percent(rows, n_rows, 2); break; } case FCELL_TYPE: { int rows = 1; while (read_next()) { FCELL *m = &((FCELL *) middle)[1]; FCELL *t = &((FCELL *) top)[1]; FCELL *b = &((FCELL *) bottom)[1]; G_percent(rows, n_rows, 2); for (col = 1; col < n_cols - 1; col++, t++, m++, b++) { m = &((FCELL *) middle)[col]; t = &((FCELL *) top)[col]; b = &((FCELL *) bottom)[col]; if ((mc = !Rast_is_f_null_value(m))) { tl = !Rast_is_f_null_value(t - 1); tc = !Rast_is_f_null_value(t); tr = !Rast_is_f_null_value(t + 1); ml = !Rast_is_f_null_value(m - 1); mr = !Rast_is_f_null_value(m + 1); bl = !Rast_is_f_null_value(b - 1); bc = !Rast_is_f_null_value(b); br = !Rast_is_f_null_value(b + 1); update_list(nabors()); } } rows++; } G_percent(rows, n_rows, 2); break; } case DCELL_TYPE: { int rows = 1; while (read_next()) { DCELL *m = &((DCELL *) middle)[1]; DCELL *t = &((DCELL *) top)[1]; DCELL *b = &((DCELL *) bottom)[1]; G_percent(rows, n_rows, 2); for (col = 1; col < n_cols - 1; col++, t++, m++, b++) { m = &((DCELL *) middle)[col]; t = &((DCELL *) top)[col]; b = &((DCELL *) bottom)[col]; if ((mc = !Rast_is_d_null_value(m))) { tl = !Rast_is_d_null_value(t - 1); tc = !Rast_is_d_null_value(t); tr = !Rast_is_d_null_value(t + 1); ml = !Rast_is_d_null_value(m - 1); mr = !Rast_is_d_null_value(m + 1); bl = !Rast_is_d_null_value(b - 1); bc = !Rast_is_d_null_value(b); br = !Rast_is_d_null_value(b + 1); update_list(nabors()); } } rows++; } G_percent(rows, n_rows, 2); break; } } G_free(top); G_free(middle); G_free(bottom); G_free(v_list); if (n_alloced_ptrs) { /* should not happen */ G_warning("Memory leak: %d points are still in use", n_alloced_ptrs); } return 0; }