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

thomas bonfort thomas.bonfort at gmail.com
Sat Mar 8 08:19:25 EST 2008


reposting as my attachment got rejected.
you can find it at http://terriscope.fr/ms_tmp/3d.png

On Sat, Mar 8, 2008 at 2:16 PM, thomas bonfort <thomas.bonfort at gmail.com> 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