POV-Ray : Newsgroups : povray.bugreports : List of bugs : Re: List of bugs - image map fix Server Time
28 Sep 2024 11:05:25 EDT (-0400)
  Re: List of bugs - image map fix  
From: Darius Davis
Date: 7 Dec 1998 05:37:44
Message: <366CAB56.28C9@acm.org>
Hi all,

OK, enough silly games, this time I'll remember to paste the text for
the fix into the news message :)

> =========================
> image map interpolation
> =========================
>   thread: "interpolate wraparound & once"
>   bug: Interpolation assumes wrap-around even when the once keyword
>        is used.
>   fix: not done yet.. shouldn't be too hard

Well, it's done now.  This code will stretch the image a bit if both
'interpolate 'and 'once' are specified.  This makes the edges line up
neatly.  I've given it a bit of testing, but more would always be
appreciated.  The code is for 3.02, which has a different style of
function declaration to 3.1, but that isn't difficult to fix :)  I
haven't sent this to the POV-Team yet, I'll wait for any feedback first.

Cheers,

Darius

---------------------------------------------------------------

To fix, add a new function in IMAGE.C:

int once_map(once_flag, interpolate_flag, image_dimension, x, result)
int once_flag, interpolate_flag;
DBL image_dimension, x;
DBL *result;
{
    if (once_flag)
    {
      /*
       * With 'once' specified, a mapping is only present within 0..1,
and
       * the edges of the image are not used for interpolation!
       */
      if ((x < 0.0) || (x >= 1.0))
      {
        return 0;
      }

      if (interpolate_flag)
      {
        *result = (x * (image_dimension - 1.0));
      }
      else
      {
        *result = (x * image_dimension);
      }
      return 1;
    }

    /*
     * 'once' is not specified, use entire image
     */

    *result = fmod(x * image_dimension, image_dimension);
    return 1;
}

Replace the following lines of cylindrical_image_map:

  if ((Image->Once_Flag) && ((y < 0.0) || (y > 1.0)))
  {
    return 0;
  }

  *v = fmod(y * Image->height, Image->height);

with these:

  if (once_map(Image->Once_Flag, (Image->Interpolation_Type !=
NO_INTERPOLATION), Image->height, y, v) == 0)
  {
    return 0;
  }

and replace function planar_image_map with the following:

static int planar_image_map(EPoint, Image, u, v)
VECTOR EPoint;
IMAGE *Image;
DBL *u, *v;
{
  int i;

  for (i = X; i <= Z; i++)
  {
    if (Image->Gradient[i] > 0.0)
    {
      if (once_map(Image->Once_Flag, (Image->Interpolation_Type !=
NO_INTERPOLATION), Image->width, EPoint[i], u) == 0)
      {
        return 0;
      }
    }
    else
    if (Image->Gradient[i] < 0.0)
    {
      if (once_map(Image->Once_Flag, (Image->Interpolation_Type !=
NO_INTERPOLATION), Image->height, EPoint[i], v) == 0)
      {
        return 0;
      }
    }
  }

  return 1;
}


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.