[GRASS-SVN] r52374 - grass/trunk/lib/ogsf

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 15 08:04:26 PDT 2012


Author: annakrat
Date: 2012-07-15 08:04:25 -0700 (Sun, 15 Jul 2012)
New Revision: 52374

Modified:
   grass/trunk/lib/ogsf/gsd_fringe.c
Log:
improved fringe rendering (GL_QUAD_STRIP instead of GL_POLYGON which can't draw concave polygons)

Modified: grass/trunk/lib/ogsf/gsd_fringe.c
===================================================================
--- grass/trunk/lib/ogsf/gsd_fringe.c	2012-07-13 20:57:40 UTC (rev 52373)
+++ grass/trunk/lib/ogsf/gsd_fringe.c	2012-07-15 15:04:25 UTC (rev 52374)
@@ -131,21 +131,23 @@
 }
 
 /*!
-   \brief ADD
+   \brief Draw fringe polygon in x direction
 
-   \param bot
+   \param bot coordinate of fringe bottom
    \param surf surface (geosurf)
-   \param row
+   \param row row along which is fringe drawn
    \param side
  */
 void gsd_fringe_horiz_poly(float bot, geosurf * surf, int row, int side)
 {
     int col;
-    int cnt;
     float pt[4];
     typbuff *buff;
     long offset;
     int xcnt;
+    int row_shift, max_row_shift;
+    
+    max_row_shift = 20;
 
     GS_set_draw(GSD_FRONT);
     gsd_pushmatrix();
@@ -155,7 +157,7 @@
     buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
     xcnt = VCOLS(surf);
 
-    gsd_bgnpolygon();
+    gsd_bgnqstrip();
 
     col = 0;
     /* floor left */
@@ -167,34 +169,44 @@
     gsd_vert_func(pt);
 
     offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-    GET_MAPATT(buff, offset, pt[Z]);
+    
+    /* find nearest row with defined z coordinate  */
+    row_shift = 0;
+    while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
+	row_shift++;
+	if (side)
+	    offset = ((row - row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+	else
+	    offset = ((row + row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+    }
     pt[Z] = pt[Z] * surf->z_exag;
     gsd_vert_func(pt);
 
-    cnt = 1;
     for (col = 0; col < xcnt - 1; col++) {
-	/* bottom right */
+	/* bottom vertex */
 	pt[X] = col * (surf->x_mod * surf->xres);
 	pt[Y] =
 	    ((surf->rows - 1) * surf->yres) -
 	    ((row + side) * (surf->y_mod * surf->yres));
+	pt[Z] = bot;
+	gsd_vert_func(pt);
+	
+	/* map vertex */
 	offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-	GET_MAPATT(buff, offset, pt[Z]);
+	row_shift = 0;
+	while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
+	    row_shift++;
+	    if (side)
+		offset = ((row - row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+	    else
+		offset = ((row + row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+	}
 	pt[Z] = pt[Z] * surf->z_exag;
 	gsd_vert_func(pt);
-	cnt++;
     }
 
-    col--;
-    pt[X] = col * (surf->x_mod * surf->xres);
-    pt[Y] =
-	((surf->rows - 1) * surf->yres) -
-	((row + side) * (surf->y_mod * surf->yres));
-    pt[Z] = bot;
-    gsd_vert_func(pt);
+    gsd_endqstrip();
 
-    gsd_endpolygon();
-
     GS_done_draw();
     gsd_popmatrix();
     gsd_flush();
@@ -203,21 +215,23 @@
 }
 
 /*!
-   \brief ADD
+   \brief Draw fringe outline in x direction
 
-   \param bot
+   \param bot coordinate of fringe bottom
    \param surf surface (geosurf)
-   \param row
+   \param row row along which is fringe drawn
    \param side
  */
 void gsd_fringe_horiz_line(float bot, geosurf * surf, int row, int side)
 {
     int col;
-    int cnt;
     float pt[4];
     typbuff *buff;
     long offset;
     int xcnt;
+    int row_shift, max_row_shift;
+    
+    max_row_shift = 20;
 
     GS_set_draw(GSD_FRONT);
     gsd_pushmatrix();
@@ -239,12 +253,19 @@
     pt[Z] = bot;
     gsd_vert_func(pt);
 
+    /* find nearest row with defined z coordinate  */
     offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-    GET_MAPATT(buff, offset, pt[Z]);
+    row_shift = 0;
+    while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
+	row_shift++;
+	if (side)
+	    offset = ((row - row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+	else
+	    offset = ((row + row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+    }
     pt[Z] = pt[Z] * surf->z_exag;
     gsd_vert_func(pt);
 
-    cnt = 1;
     for (col = 0; col < xcnt - 1; col++) {
 	/* bottom right */
 	pt[X] = col * (surf->x_mod * surf->xres);
@@ -252,10 +273,16 @@
 	    ((surf->rows - 1) * surf->yres) -
 	    ((row + side) * (surf->y_mod * surf->yres));
 	offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-	GET_MAPATT(buff, offset, pt[Z]);
+	row_shift = 0;
+	while (!GET_MAPATT(buff, offset, pt[Z]) && row_shift < max_row_shift) {
+	    row_shift++;
+	    if (side)
+		offset = ((row - row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+	    else
+		offset = ((row + row_shift) * surf->y_mod * surf->cols) + (col * surf->x_mod);
+	}
 	pt[Z] = pt[Z] * surf->z_exag;
 	gsd_vert_func(pt);
-	cnt++;
     }
 
     col--;
@@ -284,29 +311,31 @@
 }
 
 /*!
-   \brief ADD
+   \brief Draw fringe outline in y direction
 
-   \param bot
+   \param bot coordinate of fringe bottom
    \param surf surface (geosurf)
-   \param col
-   \param side [unused]
+   \param col column along which is fringe drawn
+   \param side
  */
 void gsd_fringe_vert_poly(float bot, geosurf * surf, int col, int side)
 {
 
     int row;
-    int cnt;
     float pt[4];
     typbuff *buff;
     long offset;
     int ycnt;
+    int col_shift, max_col_shift;
+    
+    max_col_shift = 20;
 
     GS_set_draw(GSD_FRONT);
     gsd_pushmatrix();
     gsd_do_scale(1);
     gsd_translate(surf->x_trans, surf->y_trans, surf->z_trans);
 
-    gsd_bgnpolygon();
+    gsd_bgnqstrip();
 
     buff = gs_get_att_typbuff(surf, ATT_TOPO, 0);
     ycnt = VROWS(surf);
@@ -319,34 +348,43 @@
     pt[Z] = bot;
     gsd_vert_func(pt);
 
+    /* find nearest row with defined z coordinate  */
     offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-    GET_MAPATT(buff, offset, pt[Z]);
+    col_shift = 0;
+    while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
+	col_shift++;
+	if (side)
+	    offset = (row * surf->y_mod * surf->cols) + ((col - col_shift) * surf->x_mod);
+	else
+	    offset = (row * surf->y_mod * surf->cols) + ((col + col_shift) * surf->x_mod);
+    }
     pt[Z] = pt[Z] * surf->z_exag;
     gsd_vert_func(pt);
 
-    cnt = 1;
     for (row = 0; row < ycnt - 1; row++) {
-	/* bottom right */
+	/* floor */
 	pt[X] = col * (surf->x_mod * surf->xres);
 	pt[Y] =
 	    ((surf->rows - 1) * surf->yres) -
 	    (row * (surf->y_mod * surf->yres));
+	pt[Z] = bot;
+	gsd_vert_func(pt);
+	/* map elevation */
 	offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-	GET_MAPATT(buff, offset, pt[Z]);
+	col_shift = 0;
+	while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
+	    col_shift++;
+	    if (side)
+		offset = (row * surf->y_mod * surf->cols) + ((col - col_shift) * surf->x_mod);
+	    else
+		offset = (row * surf->y_mod * surf->cols) + ((col + col_shift) * surf->x_mod);
+	}
 	pt[Z] = pt[Z] * surf->z_exag;
 	gsd_vert_func(pt);
-	cnt++;
     }
 
-    row--;
-    pt[X] = col * (surf->x_mod * surf->xres);
-    pt[Y] =
-	((surf->rows - 1) * surf->yres) - (row * (surf->y_mod * surf->yres));
-    pt[Z] = bot;
-    gsd_vert_func(pt);
+    gsd_endqstrip();
 
-    gsd_endpolygon();
-
     GS_done_draw();
     gsd_popmatrix();
     gsd_flush();
@@ -355,21 +393,23 @@
 }
 
 /*!                                             
-   \brief ADD
+   \brief Draw fringe outline in y direction
 
-   \param bot
+   \param bot coordinate of fringe bottom
    \param surf surface (geosurf)
-   \param col
-   \param side [unused]
+   \param col column along which is fringe drawn
+   \param side
  */
 void gsd_fringe_vert_line(float bot, geosurf * surf, int col, int side)
 {
     int row;
-    int cnt;
     float pt[4];
     typbuff *buff;
     long offset;
     int ycnt;
+    int col_shift, max_col_shift;
+    
+    max_col_shift = 20;
 
     GS_set_draw(GSD_FRONT);
     gsd_pushmatrix();
@@ -389,12 +429,19 @@
     pt[Z] = bot;
     gsd_vert_func(pt);
 
+    /* find nearest row with defined z coordinate  */
     offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-    GET_MAPATT(buff, offset, pt[Z]);
+    col_shift = 0;
+    while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
+	col_shift++;
+	if (side)
+	    offset = (row * surf->y_mod * surf->cols) + ((col - col_shift) * surf->x_mod);
+	else
+	    offset = (row * surf->y_mod * surf->cols) + ((col + col_shift) * surf->x_mod);
+    }
     pt[Z] = pt[Z] * surf->z_exag;
     gsd_vert_func(pt);
 
-    cnt = 1;
     for (row = 0; row < ycnt - 1; row++) {
 	/* bottom right */
 	pt[X] = col * (surf->x_mod * surf->xres);
@@ -402,10 +449,16 @@
 	    ((surf->rows - 1) * surf->yres) -
 	    (row * (surf->y_mod * surf->yres));
 	offset = (row * surf->y_mod * surf->cols) + (col * surf->x_mod);
-	GET_MAPATT(buff, offset, pt[Z]);
+	col_shift = 0;
+	while (!GET_MAPATT(buff, offset, pt[Z]) && col_shift < max_col_shift) {
+	    col_shift++;
+	    if (side)
+		offset = (row * surf->y_mod * surf->cols) + ((col - col_shift) * surf->x_mod);
+	    else
+		offset = (row * surf->y_mod * surf->cols) + ((col + col_shift) * surf->x_mod);
+	}
 	pt[Z] = pt[Z] * surf->z_exag;
 	gsd_vert_func(pt);
-	cnt++;
     }
 
     row--;



More information about the grass-commit mailing list