浏览代码

Fix lat/lon wrapping in D_* functions
Fix clipping tests to handle lower-left origin
Replace separate D_*_{cull,clip} functions with D_set_clip_mode()
Eliminate use of G_plot_fx()


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33225 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 年之前
父节点
当前提交
b2c28c06c9

+ 1 - 6
display/d.geodesic/local_proto.h

@@ -1,6 +1 @@
-/* mouse.c */
-void mouse(int, int);
-
-/* plot.c */
-int setup_plot(void);
-int plot(double, double, double, double, int, int);
+void plot(double, double, double, double, int, int);

+ 2 - 2
display/d.geodesic/main.c

@@ -115,9 +115,9 @@ int main(int argc, char *argv[])
     else
 	text_color = D_translate_color(parm.tcolor->answer);
 
-    setup_plot();
     plot(lon1, lat1, lon2, lat2, line_color, text_color);
 
     R_close_driver();
-    exit(0);
+
+    exit(EXIT_SUCCESS);
 }

+ 43 - 105
display/d.geodesic/plot.c

@@ -3,136 +3,74 @@
 #include <grass/raster.h>
 #include <grass/gis.h>
 #include <stdio.h>
+#include "local_proto.h"
 
 #define METERS_TO_MILES(x) ((x) * 6.213712e-04)
 
-static int min_range[5], max_range[5];
-static int which_range;
-static int change_range;
-
-static int get_text_x(void);
-static int geodesic(int);
-static int move(int, int);
-static int cont(int, int);
-
-int setup_plot(void)
+void plot(double lon1, double lat1, double lon2, double lat2,
+     int line_color, int text_color)
 {
+    double distance;
+    double text_x, text_y;
     double a, e2;
+    int nsteps = 1000;
+    int i;
 
     /* establish the current graphics window */
-    D_setup_unity(0);
-    D_clip_to_map();
-
-    /* setup the G plot to use the D routines */
-    G_setup_plot(D_get_d_north(), D_get_d_south(),
-		 D_get_d_west(), D_get_d_east(),
-		 move, cont);
+    D_setup(0);
 
     G_get_ellipsoid_parameters(&a, &e2);
     G_begin_geodesic_distance(a, e2);
-    R_text_size(10, 10);
 
-    return 0;
-}
+    D_use_color(line_color);
 
-int
-plot(double lon1, double lat1, double lon2, double lat2, int line_color,
-     int text_color)
-{
-    double distance;
-    char buf[100];
-    int text_x, text_y;
+    G_shortest_way(&lon1, &lon2);
 
-    which_range = -1;
-    change_range = 1;
-    D_use_color(line_color);
     if (lon1 != lon2) {
-	G_shortest_way(&lon1, &lon2);
 	G_begin_geodesic_equation(lon1, lat1, lon2, lat2);
-	G_plot_fx(G_geodesic_lat_from_lon, lon1, lon2);
-	text_x = get_text_x();
-	if (text_x >= 0)
-	    text_y = geodesic(text_x);
-    }
-    else {
-	G_plot_where_xy(lon1, (lat1 + lat2) / 2, &text_x, &text_y);
-	G_plot_line(lon1, lat1, lon2, lat2);
-    }
 
-    distance = G_geodesic_distance(lon1, lat1, lon2, lat2);
-    sprintf(buf, "%.0f miles\n", METERS_TO_MILES(distance));
-    if ((text_x >= 0) && (text_color != -1)) {
-	if (text_y + 10 <= D_get_d_north())
-	    text_y = D_get_d_north() - 10;
-	if (text_x + 10 * strlen(buf) >= D_get_d_east())
-	    text_x = D_get_d_east() - 10 * strlen(buf);
-	D_move_abs(text_x, text_y);
-	D_use_color(text_color);
-	R_text(buf);
-    }
-
-    return 0;
-}
+	for (i = 0; i <= nsteps; i++) {
+	    double lon = lon1 + (lon2 - lon1) * i / nsteps;
+	    double lat = G_geodesic_lat_from_lon(lon);
+	    if (i == 0)
+		D_move_abs(lon, lat);
+	    else
+		D_cont_abs(lon, lat);
+	}
 
-static int cont(int x, int y)
-{
-    if (D_cont_abs_clip(x, y)) {	/* clipped */
-	change_range = 1;
+	text_x = (lon1 + lon2) / 2;
+	text_y = G_geodesic_lat_from_lon(text_x);
     }
-    else {			/* keep track of left,right x for lines drawn in window */
-
-	if (change_range) {
-	    which_range++;
-	    min_range[which_range] = max_range[which_range] = x;
-	    change_range = 0;
-	}
-	else {
-	    if (x < min_range[which_range])
-		min_range[which_range] = x;
-	    else if (x > max_range[which_range])
-		max_range[which_range] = x;
-	}
+    else {
+	D_line_abs(lon1, lat1, lon2, lat2);
+	text_x = (lon1 + lon2) / 2;
+	text_y = (lat1 + lat2) / 2;
     }
 
-    return 0;
-}
+    if (text_color != -1) {
+	double t, b, l, r;
+	char buf[100];
 
-static int move(int x, int y)
-{
-    D_move_abs(x, y);
+	R_text_size(10, 10);
 
-    return 0;
-}
+	distance = G_geodesic_distance(lon1, lat1, lon2, lat2);
+	sprintf(buf, "%.0f miles", METERS_TO_MILES(distance));
 
-static int geodesic(int x)
-{
-    double lon, lat;
+	D_move_abs(text_x, text_y);
+	D_get_text_box(buf, &t, &b, &l, &r);
 
-    lon = D_d_to_u_col((double)x);
-    lat = G_geodesic_lat_from_lon(lon);
-    return (int)D_u_to_d_row(lat);
+	if (t - D_get_u_north() > 0)
+	    text_y -= t - D_get_u_north();
+	if (b - D_get_u_south() < 0)
+	    text_y -= b - D_get_u_south();
+	if (r - D_get_u_east() > 0)
+	    text_x -= r - D_get_u_east();
+	if (l - D_get_u_west() < 0)
+	    text_x -= l - D_get_u_west();
 
-    return 0;
-}
+	D_use_color(text_color);
 
-static int get_text_x(void)
-{
-    int n;
-    int len;
-    int max;
-    int which;
-
-    which = -1;
-    max = 0;
-    for (n = 0; n <= which_range; n++) {
-	len = max_range[n] - min_range[n];
-	if (len >= max) {
-	    max = len;
-	    which = n;
-	}
+	D_move_abs(text_x, text_y);
+	R_text(buf);
     }
-    if (which < 0)
-	return -1;
-
-    return (max_range[which] + min_range[which]) / 2;
 }

+ 1 - 6
display/d.rhumbline/local_proto.h

@@ -1,6 +1 @@
-/* mouse.c */
-int mouse(int, int);
-
-/* plot.c */
-int setup_plot(void);
-int plot(double, double, double, double, int, int);
+void plot(double, double, double, double, int, int);

+ 2 - 2
display/d.rhumbline/main.c

@@ -119,9 +119,9 @@ int main(int argc, char *argv[])
 	text_color = D_translate_color(deftcolor);
 #endif
 
-    setup_plot();
     plot(lon1, lat1, lon2, lat2, line_color, text_color);
 
     R_close_driver();
-    exit(0);
+
+    exit(EXIT_SUCCESS);
 }

+ 25 - 42
display/d.rhumbline/plot.c

@@ -3,56 +3,39 @@
 #include <grass/gis.h>
 #include <grass/display.h>
 #include <grass/raster.h>
+#include "local_proto.h"
 
-static int move(int, int);
-static int cont(int, int);
-
-#define METERS_TO_MILES(x) ((x) * 6.213712e-04)
-
-int setup_plot(void)
+void plot(double lon1, double lat1, double lon2, double lat2,
+	  int line_color, int text_color)
 {
-    /* establish the current graphics window */
-    D_setup_unity(0);
-
-    /* setup the G plot to use the D routines */
-    G_setup_plot(D_get_d_north(),
-		 D_get_d_south(), D_get_d_west(), D_get_d_east(), move, cont);
-
-    R_text_size(10, 10);
+    int nsteps = 1000;
+    int i;
 
-    return 0;
-}
-
-int
-plot(double lon1, double lat1, double lon2, double lat2, int line_color,
-     int text_color)
-{
-    int text_x, text_y;
+    D_setup(0);
 
     D_use_color(line_color);
-    if (lon1 != lon2) {
-	G_shortest_way(&lon1, &lon2);
-	G_begin_rhumbline_equation(lon1, lat1, lon2, lat2);
-	G_plot_fx(G_rhumbline_lat_from_lon, lon1, lon2);
-    }
-    else {
-	G_plot_where_xy(lon1, (lat1 + lat2) / 2, &text_x, &text_y);
-	G_plot_line(lon1, lat1, lon2, lat2);
-    }
 
-    return 0;
-}
+    if (lon1 == lon2) {
+	D_line_abs(lon1, lat1, lon2, lat2);
+	return;
+    }
 
-static int cont(int x, int y)
-{
-    D_cont_abs(x, y);
+    if (lon1 > lon2) {
+	double tmp = lon1;
+	lon1 = lon2;
+	lon2 = tmp;
+    }
 
-    return 0;
-}
+    G_shortest_way(&lon1, &lon2);
 
-static int move(int x, int y)
-{
-    D_move_abs(x, y);
+    G_begin_rhumbline_equation(lon1, lat1, lon2, lat2);
 
-    return 0;
+    for (i = 0; i <= nsteps; i++) {
+	double lon = lon1 + (lon2 - lon1) * i / nsteps;
+	double lat = G_rhumbline_lat_from_lon(lon);
+	if (i == 0)
+	    D_move_abs(lon, lat);
+	else
+	    D_cont_abs(lon, lat);
+    }
 }

+ 3 - 3
display/d.thematic.area/area.c

@@ -155,7 +155,7 @@ int dareatheme(struct Map_info *Map, struct cat_list *Clist,
 
 	/* plot polygon in class color */
 	D_RGB_color(colors[i].r, colors[i].g, colors[i].b);
-	plot_polygon(Points->x, Points->y, Points->n_points);
+	D_polygon_abs(Points->x, Points->y, Points->n_points);
 
 	/* XXX rewrite boundary */
 	if (bcolor) {
@@ -164,12 +164,12 @@ int dareatheme(struct Map_info *Map, struct cat_list *Clist,
 	    Vect_get_area_points(Map, area, Points);
 	    D_RGB_color(bcolor->r, bcolor->g, bcolor->b);
 	    /*use different user defined render methods */
-	    plot_polyline(Points->x, Points->y, Points->n_points);
+	    D_polyline_abs(Points->x, Points->y, Points->n_points);
 	    for (i = 0; i < n_isles; i++) {
 		isle = Vect_get_area_isle(Map, area, i);
 		Vect_get_isle_points(Map, isle, Points);
 		/*use different user defined render methods */
-		plot_polyline(Points->x, Points->y, Points->n_points);
+		D_polyline_abs(Points->x, Points->y, Points->n_points);
 	    }
 	}
     }				/* end for loop over areas */

+ 0 - 2
display/d.thematic.area/local_proto.h

@@ -10,7 +10,5 @@ int plot1(struct Map_info *, int, int, struct cat_list *,
 int dareatheme(struct Map_info *, struct cat_list *, dbCatValArray *,
 	       double *, int, const struct color_rgb *,
 	       const struct color_rgb *, int, struct Cell_head *, int);
-void plot_polygon(double *, double *, int);
-void plot_polyline(double *, double *, int);
 
 int dcmp(const void *, const void *);

+ 0 - 24
display/d.thematic.area/main.c

@@ -53,7 +53,6 @@ int main(int argc, char **argv)
     struct Option *bwidth_opt;
     struct Option *where_opt;
     struct Option *field_opt;
-    struct Option *render_opt;
     struct Option *legend_file_opt;
     struct Flag *legend_flag, *algoinfo_flag, *nodraw_flag;
 
@@ -147,20 +146,6 @@ int main(int argc, char **argv)
     bcolor_opt->guisection = _("Boundaries");
     bcolor_opt->gisprompt = GISPROMPT_COLOR;
 
-    render_opt = G_define_option();
-    render_opt->key = "render";
-    render_opt->type = TYPE_STRING;
-    render_opt->required = NO;
-    render_opt->multiple = NO;
-    render_opt->answer = "l";
-    render_opt->options = "d,c,l";
-    render_opt->description = _("Rendering method for filled polygons");
-    render_opt->descriptions =
-	_("d;use the display library basic functions (features: polylines);"
-	  "c;use the display library clipping functions (features: clipping);"
-	  "l;use the display library culling functions (features: culling, polylines)");
-
-
     legend_file_opt = G_define_standard_option(G_OPT_F_OUTPUT);
     legend_file_opt->key = "legendfile";
     legend_file_opt->description =
@@ -185,15 +170,6 @@ int main(int argc, char **argv)
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    if (G_strcasecmp(render_opt->answer, "d") == 0)
-	render = RENDER_DP;
-    else if (G_strcasecmp(render_opt->answer, "c") == 0)
-	render = RENDER_DPC;
-    else if (G_strcasecmp(render_opt->answer, "l") == 0)
-	render = RENDER_DPL;
-    else
-	G_fatal_error(_("Invalid rendering method <%s>"), render_opt->answer);
-
     if (G_verbose() > G_verbose_std())
 	verbose = TRUE;
 

+ 2 - 41
display/d.thematic.area/plot1.c

@@ -35,45 +35,6 @@ struct rgb_color palette[16] = {
     {0, 139, 139}		/* 16: dark cyan */
 };
 
-/*global render switch */
-int render;
-
-/* *************************************************************** */
-/* function to use different render methods for polylines ******** */
-/* *************************************************************** */
-void plot_polyline(double *xf, double *yf, int n)
-{
-    switch (render) {
-    case RENDER_DP:
-	D_polyline_abs(xf, yf, n);
-	break;
-    case RENDER_DPC:
-	D_polyline_abs_clip(xf, yf, n);
-	break;
-    case RENDER_DPL:
-	D_polyline_abs_cull(xf, yf, n);
-	break;
-    }
-}
-
-/* *************************************************************** */
-/* function to use different render methods for polygons  ******** */
-/* *************************************************************** */
-void plot_polygon(double *xf, double *yf, int n)
-{
-    switch (render) {
-    case RENDER_DP:
-	D_polygon_abs(xf, yf, n);
-	break;
-    case RENDER_DPC:
-	D_polygon_abs_clip(xf, yf, n);
-	break;
-    case RENDER_DPL:
-	D_polygon_abs_cull(xf, yf, n);
-	break;
-    }
-}
-
 /* *************************************************************** */
 /* *************************************************************** */
 /* *************************************************************** */
@@ -447,9 +408,9 @@ int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist,
 
 	    /* Plot the lines */
 	    if (Points->n_points == 1)	/* line with one coor */
-		D_polydots_abs_clip(x, y, Points->n_points);
+		D_polydots_abs(x, y, Points->n_points);
 	    else		/*use different user defined render methods */
-		plot_polyline(x, y, Points->n_points);
+		D_polyline_abs(x, y, Points->n_points);
 	}
     }
 

+ 4 - 4
display/d.vect/area.c

@@ -358,7 +358,7 @@ int darea(struct Map_info *Map, struct cat_list *Clist,
 	if (fcolor || (z_color_flag && Vect_is_3d(Map))) {
 	    if (!table_colors_flag && !cats_color_flag && !z_color_flag) {
 		D_RGB_color(fcolor->r, fcolor->g, fcolor->b);
-		plot_polygon(Points->x, Points->y, Points->n_points);
+		D_polygon_abs(Points->x, Points->y, Points->n_points);
 	    }
 	    else {
 		if (rgb) {
@@ -369,7 +369,7 @@ int darea(struct Map_info *Map, struct cat_list *Clist,
 		    D_RGB_color(fcolor->r, fcolor->g, fcolor->b);
 		}
 		if (cat >= 0) {
-		    plot_polygon(Points->x, Points->y, Points->n_points);
+		    D_polygon_abs(Points->x, Points->y, Points->n_points);
 		}
 	    }
 	}
@@ -387,12 +387,12 @@ int darea(struct Map_info *Map, struct cat_list *Clist,
 		D_RGB_color(bcolor->r, bcolor->g, bcolor->b);
 	    }
 	    /*use different user defined render methods */
-	    plot_polyline(Points->x, Points->y, Points->n_points);
+	    D_polyline_abs(Points->x, Points->y, Points->n_points);
 	    for (i = 0; i < n_isles; i++) {
 		isle = Vect_get_area_isle(Map, area, i);
 		Vect_get_isle_points(Map, isle, Points);
 		/*use different user defined render methods */
-		plot_polyline(Points->x, Points->y, Points->n_points);
+		D_polyline_abs(Points->x, Points->y, Points->n_points);
 	    }
 	}
     }				/* end for */

+ 0 - 2
display/d.vect/local_proto.h

@@ -16,7 +16,5 @@ int darea(struct Map_info *, struct cat_list *, const struct color_rgb *,
 int attr(struct Map_info *, int, char *, struct cat_list *, LATTR *, int);
 int zcoor(struct Map_info *, int, LATTR *);
 int test_bg_color(const char *);
-void plot_polygon(double *, double *, int);
-void plot_polyline(double *, double *, int);
 void show_label(double *, double *, LATTR *, const char *);
 void show_label_line(const struct line_pnts *, int, LATTR *, const char *);

+ 0 - 36
display/d.vect/main.c

@@ -100,8 +100,6 @@ int main(int argc, char **argv)
     struct Option *lsize_opt, *font_opt, *enc_opt, *xref_opt, *yref_opt;
     struct Option *attrcol_opt, *maxreg_opt, *minreg_opt;
     struct Option *width_opt, *wcolumn_opt, *wscale_opt;
-    struct Option *render_opt;
-    struct Flag *verbose_flag;	/* please remove before GRASS 7 released */
     struct Flag *id_flag, *table_acolors_flag, *cats_acolors_flag,
 	*zcol_flag;
     struct cat_list *Clist;
@@ -323,24 +321,6 @@ int main(int argc, char **argv)
 	_("Maximum region size (average from height and width) "
 	  "when map is displayed");
 
-    render_opt = G_define_option();
-    render_opt->key = "render";
-    render_opt->type = TYPE_STRING;
-    render_opt->required = NO;
-    render_opt->multiple = NO;
-    render_opt->answer = "l";
-    render_opt->options = "d,c,l";
-    render_opt->description = _("Rendering method for filled polygons");
-    render_opt->descriptions =
-	_("d;use the display library basic functions (features: polylines);"
-	  "c;use the display library clipping functions (features: clipping);"
-	  "l;use the display library culling functions (features: culling, polylines)");
-
-    /* please remove before GRASS 7 released */
-    verbose_flag = G_define_flag();
-    verbose_flag->key = 'v';
-    verbose_flag->description = _("Run verbosely");
-
     /* Colors */
     table_acolors_flag = G_define_flag();
     table_acolors_flag->key = 'a';
@@ -369,22 +349,6 @@ int main(int argc, char **argv)
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
-    if (G_strcasecmp(render_opt->answer, "d") == 0)
-	render = RENDER_DP;
-    else if (G_strcasecmp(render_opt->answer, "c") == 0)
-	render = RENDER_DPC;
-    else if (G_strcasecmp(render_opt->answer, "l") == 0)
-	render = RENDER_DPL;
-    else
-	G_fatal_error(_("Invalid rendering method <%s>"), render_opt->answer);
-
-    /* please remove -v flag before GRASS 7 released */
-    if (verbose_flag->answer) {
-	G_putenv("GRASS_VERBOSE", "3");
-	G_warning(_("The '-v' flag is superseded and will be removed "
-		    "in future. Please use '--verbose' instead."));
-    }
-    /* but keep this */
     if (G_verbose() > G_verbose_std())
 	verbose = TRUE;
 

+ 2 - 41
display/d.vect/plot1.c

@@ -35,45 +35,6 @@ struct rgb_color palette[16] = {
     {0, 139, 139}		/* 16: dark cyan */
 };
 
-/*global render switch */
-int render;
-
-/* *************************************************************** */
-/* function to use different render methods for polylines ******** */
-/* *************************************************************** */
-void plot_polyline(double *xf, double *yf, int n)
-{
-    switch (render) {
-    case RENDER_DP:
-	D_polyline_abs(xf, yf, n);
-	break;
-    case RENDER_DPC:
-	D_polyline_abs_clip(xf, yf, n);
-	break;
-    case RENDER_DPL:
-	D_polyline_abs_cull(xf, yf, n);
-	break;
-    }
-}
-
-/* *************************************************************** */
-/* function to use different render methods for polygons  ******** */
-/* *************************************************************** */
-void plot_polygon(double *xf, double *yf, int n)
-{
-    switch (render) {
-    case RENDER_DP:
-	D_polygon_abs(xf, yf, n);
-	break;
-    case RENDER_DPC:
-	D_polygon_abs_clip(xf, yf, n);
-	break;
-    case RENDER_DPL:
-	D_polygon_abs_cull(xf, yf, n);
-	break;
-    }
-}
-
 /* *************************************************************** */
 /* *************************************************************** */
 /* *************************************************************** */
@@ -463,9 +424,9 @@ int plot1(struct Map_info *Map, int type, int area, struct cat_list *Clist,
 
 	    /* Plot the lines */
 	    if (Points->n_points == 1)	/* line with one coor */
-		D_polydots_abs_clip(x, y, Points->n_points);
+		D_polydots_abs(x, y, Points->n_points);
 	    else		/*use different user defined render methods */
-		plot_polyline(x, y, Points->n_points);
+		D_polyline_abs(x, y, Points->n_points);
 	}
     }
 

+ 8 - 26
include/display.h

@@ -74,32 +74,6 @@ void D_clip_to_map(void);
 void D_line_width(double);
 void D_get_text_box(const char *, double *, double *, double *, double *);
 
-int D_cont_abs_cull(double, double);
-int D_cont_rel_cull(double, double);
-int D_line_abs_cull(double, double, double, double);
-int D_line_rel_cull(double, double, double, double);
-void D_polydots_abs_cull(const double *, const double *, int);
-void D_polydots_rel_cull(const double *, const double *, int);
-void D_polyline_abs_cull(const double *, const double *, int);
-void D_polyline_rel_cull(const double *, const double *, int);
-void D_polygon_abs_cull(const double *, const double *, int);
-void D_polygon_rel_cull(const double *, const double *, int);
-void D_box_abs_cull(double, double, double, double);
-void D_box_rel_cull(double, double);
-
-int D_cont_abs_clip(double, double);
-int D_cont_rel_clip(double, double);
-int D_line_abs_clip(double, double, double, double);
-int D_line_rel_clip(double, double, double, double);
-void D_polydots_abs_clip(const double *, const double *, int);
-void D_polydots_rel_clip(const double *, const double *, int);
-void D_polyline_abs_clip(const double *, const double *, int);
-void D_polyline_rel_clip(const double *, const double *, int);
-void D_polygon_abs_clip(const double *, const double *, int);
-void D_polygon_rel_clip(const double *, const double *, int);
-void D_box_abs_clip(double, double, double, double);
-void D_box_rel_clip(double, double);
-
 void D_move_abs(double, double);
 void D_move_rel(double, double);
 void D_cont_abs(double, double);
@@ -115,6 +89,14 @@ void D_polygon_rel(const double *, const double *, int);
 void D_box_abs(double, double, double, double);
 void D_box_rel(double, double);
 
+enum clip_mode {
+    D_MODE_NONE,
+    D_MODE_CULL,
+    D_MODE_CLIP,
+};
+
+void D_set_clip_mode(int);
+
 /* icon.c */
 void D_plot_icon(double, double, int, double, double);
 

文件差异内容过多而无法显示
+ 482 - 307
lib/display/draw2.c