[Fwd: Re: [MAPSERVER-DEV] How to generate 3d image like GPS device?]

Stephen Woodbridge woodbri at swoodbridge.com
Sat Mar 8 19:47:58 EST 2008


Sent this earlier but the original message seems to have the old reply 
to header and my response got held on the old list.

Based on the other follow up posts, I think getting the right 
combinations of rotation, projection and handling for labels will 
require some experimentation. The label part will be trickiest to get 
right so that they are readable, oriented correctly and fade or thin 
with distance.

-Steve W

-------- Original Message --------
Subject: Re: [MAPSERVER-DEV] How to generate 3d image like GPS device?
Date: Sat, 08 Mar 2008 10:53:12 -0500
From: Stephen Woodbridge <woodbri at swoodbridge.com>
To: thomas bonfort <thomas.bonfort at gmail.com>
CC: MAPSERVER-DEV at lists.umn.edu
References: <47C56A5E.9090907 at swoodbridge.com>	 
<4BF377919225F449BB097CB76FFE9BC801988948 at ptolemy.topozone.com>	 
<47C64A47.4040408 at swoodbridge.com> 
<d2b988930803080516k764c3ac3y47f528fcd8d2078 at mail.gmail.com>

Thomas,

Very nice! This option has some significant benefits over the proj
approach in that:

1) labels appear to be painted on the roads
2) the roads taper and shrink in size with distance

I believe both of these features are desirable, although and can see 1)
potentially bening problematic for some use cases.

Obviously because of the perspective, you need to start with a wider
viewport to allow the tapered image to fill the view when you are done.

All in all, very promising proof of concept. Please continue! :)

Thanks for sharing,
   -Steve W



thomas bonfort wrote:
> I've played a bit with this by taking a different approach than the
> proj one, by applying a perspective transform to the created image
> just before saving it.
> the inlined (very ugly) patch applies a hardcoded transform and
> bilinear filtering to the created image, if FORMATOPTION "3D=ON" is
> added to the outputformat. I didn't look into memory management so
> valgrind will swear at you if you run it, and i also didn't look at
> the borders for the filtering (thus a one pixel outline on the
> resulting map)
> 
> this is more for fun than for the real use of 3d output, but I guessed
> I'd keep you updated.
> 
> cheers.
> thomas
> 
> (apply the patch to mapgd.c if you want to try it out)
> 
> 
> Index: .
> ===================================================================
> --- .	(revision 7439)
> +++ .	(working copy)
> @@ -3465,6 +3465,40 @@
>    return img;
>  }
> 
> +int bipix(gdImagePtr img, double u, double v) {
> +       int x = floor(u);
> +       int y = floor(v);
> +       double u_ratio = u - x;
> +       double v_ratio = v - y;
> +       double u_opposite = 1 - u_ratio;
> +       double v_opposite = 1 - v_ratio;
> +       int r,g,b;
> +       r = (gdTrueColorGetRed(img->tpixels[y][x])   * u_opposite  +
> gdTrueColorGetRed(img->tpixels[y][x+1])   * u_ratio) * v_opposite +
> +                       (gdTrueColorGetRed(img->tpixels[y+1][x]) *
> u_opposite  + gdTrueColorGetRed(img->tpixels[y+1][x+1]) * u_ratio) *
> v_ratio;
> +       g = (gdTrueColorGetGreen(img->tpixels[y][x])   * u_opposite  +
> gdTrueColorGetGreen(img->tpixels[y][x+1])   * u_ratio) * v_opposite +
> +
> (gdTrueColorGetRed(img->tpixels[y+1][x]) * u_opposite  +
> gdTrueColorGetGreen(img->tpixels[y+1][x+1]) * u_ratio) * v_ratio;
> +       b = (gdTrueColorGetBlue(img->tpixels[y][x])   * u_opposite  +
> gdTrueColorGetBlue(img->tpixels[y][x+1])   * u_ratio) * v_opposite +
> +
> (gdTrueColorGetBlue(img->tpixels[y+1][x]) * u_opposite  +
> gdTrueColorGetBlue(img->tpixels[y+1][x+1]) * u_ratio) * v_ratio;
> +
> +       return gdTrueColor(r,g,b);
> +}
> +
> +gdImagePtr ms3dimage(gdImagePtr img) {
> +    gdImagePtr nimg = gdImageCreateTrueColor(img->sx, img->sy);
> +    int x,y;
> +    for(y=0;y<img->sy-1;y++) {
> +        int d=img->sy/2+(2*(double)y/(double)img->sy)*(double)img->sx;
> +        for(x=0;x<img->sx-1;x++) {
> +            double nx;
> +            nx=((double)x-((double)img->sx-(double)d)/2.)*((double)img->sx/(double)d);
> +            if(nx>=0 && nx<img->sx) {
> +                nimg->tpixels[y][x]=bipix(img,nx,y);
> +            }
> +        }
> +    }
> +    return nimg;
> +
> +}
>  /* ===========================================================================
>     msSaveImageGD
> 
> @@ -3476,7 +3510,11 @@
>      FILE *stream=NULL;
>      gdIOCtx *ctx = NULL;
>      int retval=MS_FAILURE;
> -
> +
> +    if( strcasecmp("ON", msGetOutputFormatOption( format, "3D", "ON"
> )) == 0 ) {
> +        img = ms3dimage(img);
> +
> +    }
>      /* Try to open a file handle */
>      if (filename != NULL && strlen(filename) > 0)
>      {
> 
> 
> ------------------------------------------------------------------------
> 




More information about the mapserver-dev mailing list