POV-Ray : Newsgroups : povray.general : creating heightfields from contour maps : Re: creating heightfields from contour maps Server Time
16 Nov 2024 13:23:07 EST (-0500)
  Re: creating heightfields from contour maps  
From: Dan Connelly
Date: 15 Aug 1998 10:48:08
Message: <35D59184.7AB210C3@flash.net>
Adrian Pederson wrote:
>
> My biggest question is where to start. What would be the best
> method for defining and drawing the contour map itself? Should
> it be created as some type of data file or an image map?
> 
> Putting on my cs hat for a minute and abstracting the problem,
> i see that there needs to be a way to define closed or open
> paths and to have an associated height value for each.

The following is all speculation... I will likely experiment
further with it (if I can figure out how to parse Targa in
PERL) when I can get some time on a UNIX system.

The approach I would take is to not define 1-d constraints, but
to use 2-d constraints.

What I would use is two images, plus an alpha channel which has ones
where the constraint image ( z1[x,y] ) should be used, and zeros
where the background, terrain-generator-created terrain ( z0[x,y] )
should be used.  Image 1 would be defined over regions where the
alpha channel is 1, and would be "don't care" elsewhere.

Then to create a smooth transition, two things need to be done:

1. extend image 1 into the non-defined areas...  This is a bit tricky.
   It's easy to come up with O(n^2) formulas based on weighted averages
   over constrained pixels (for example, a weighting factor of 
   1/r^4 might work, where r is the distance to the constrained pixel
   in question), but I am sure more efficient algorithms exist.  The
   extended image 1 field I'll call z1'[x, y] .

2. smooth out the alpha channel : this can be done with a diffusion
   algorithm applied to pixels with sub-unity alpha.  I'll call
   the revised alpha channel a' .

3. combine the images:
   z[x, y] = (1 - a'[x, y]) * z0[x, y] + a'[x, y] * z1'[x, y]


The result is the final image will exactly match the boundary conditions
imposed
by image 0, and will make a smooth transition into image 1 in the
unconstrained
regions.  The length of the transition is determined by the diffusion
algorithm.

BTW, the diffusion algorithm can be something like :

a'[x, y] =
 ( 
   ( a[x, y] * (1 + a[x, y]) ) +
   ( a[x-1,y] + a[x+1,y] + a[x,y-1] + a[x,y+1] ) * ( 1 - a[x,y] ) / 4
 ) / 2;

applied iteratively (of course, between iterations, a' -> a).
Note this tends to retain values which are closer to one, while
values closer to zero get averaged against their
nearest neighbors.  

It remains to be seen if this results in realistic transitions
from the constraint region to the unconstrained region.

Note contours would need to be implemented via
2-d approximations (ie they must be pixellated
at height field resolution).          

-- 
http://www.flash.net/~djconnel/


Post a reply to this message

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