Reading Geoff's post on creating a heightfield got me thinking about the best way to do it.

Starting with contour lines (which are basically quantized heightfields) how can I go back and get the heightfield I started with (or least a close approximation)

Ideally, this should retain the detailed information of the contour lines, while providing a smooth representation of the heightfield between.

The common suggestion seems to stack up the contour lines, filling each band with colours reflecting the elevations, then blur them all. The problems I have experienced are that 1) with too little blur, we get steps, and with too much blur, all definition of the shape and detail at the contour lines is lost.

Look at these full size, the thumbnailer really messed these up!

So I drew a problematic (sharp edges, variable slopes) heightfield:
Click image for larger version. 

Name:	hf_orig.png 
Views:	167 
Size:	18.7 KB 
ID:	1790

This represents my best case 3d render:
Click image for larger version. 

Name:	r_hf_orig.png 
Views:	113 
Size:	90.6 KB 
ID:	1794

Now I quantized the image with 8 levels to represent what I could get from contour lines:
Click image for larger version. 

Name:	hf_q.png 
Views:	139 
Size:	25.0 KB 
ID:	1791

I ran this with three different blur amounts, 5px, 35px and 50px. Unfortunately stepping was horible in the 5 px, noticeable in the 35, and minimal in the 50, but all detail was lost in the 50, with the image looking like a smooth hump.

So I pulled the quantized image into inkscape, ran the bitmap tracer on it to get the 8 paths representing the countour levels, then interpolated the colour with 8 steps between each of the adjacent contour paths. This produces pretty good results, but the small interpolation were visible as fine steps, so I applied a 2% blur to all the objects in Inkscape and ran it one last time.

The results here were quite good! there is still a small band at each of the contour lines...due (I think) to double copies of each of the original contour lines. The detail however is excellent, with the original shape very well preserved:
Click image for larger version. 

Name:	r_hf_ink_blur.png 
Views:	140 
Size:	92.6 KB 
ID:	1795

Lastly, here is a test sheet with all of them for comparison purposes:
Click image for larger version. 

Name:	comparison.png 
Views:	194 
Size:	733.9 KB 
ID:	1793

This technique works well for single shapes...but I am not sure how well it would work for complex shapes... they may break the interpolate function. Something to play with later, I guess...

-Rob A>