Re: 2D height map to 3D model?

From: Mike C. Fletcher (mcfletch_at_rogers.com)
Date: 10/11/04


Date: Mon, 11 Oct 2004 10:37:24 -0400
To: python-list@python.org

Didn't see the original question, but going from the subject, you want
to generate a 3D mesh from a height field (such as seen in an image).
The algorithm for doing that is fairly straightforward:

rectangles = []
for m in range(dim1-1):
    for n in range(dim2-1):
       vertices = []
       vertices.append( (m,n,heights[m,n]))
       vertices.append( (m+1,n,heights[m+1,n]))
       vertices.append( (m+1,n+1,heights[m+1,n+1]))
       vertices.append( (m,n+1,heights[m,n+1]))
       rectangles.append( vertices )

However, that dramatically increases the size of your geometry in memory
(you're storing 12 doubles for almost every data-point). It's easier to
use a format where you define vertices and a separate topology (via
indices into the vertices). Same basic approach works there, you just
have to add m+(n*dim1) to get the index for a corner of the quad. There
you're storing only 3 doubles for each vertex.

If you have a format that allows for triangle/quadrilateral strips, you
can make the rendering far more efficient using them. There you render
(m,n), (m+1,n), (m+1,n+1), (m,n+1), (m+1,n+2), (m,n+2), (m+1,n+3),...
That reduces the size of your index-set as well, but most of the speedup
is going to come from having fewer primitive operations.

Good luck,
Mike

PhilC wrote:

>Thanks Richard,
>
>I was actually thinking of faces but an aerial photograph would be
>similar. I'll check through those links and see if they help.
>
>Again my appreciation for your reply.
>
>PhilC
>
>
>

-- 
________________________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://www.vrplumber.com
  http://blog.vrplumber.com


Relevant Pages

  • Re: Review: 4th Ed
    ... The underlying format for the comments seems to be similar. ... I'm a VSS user for source code control locally (due to familiarity, ... Direct3D wins for high performance rendering. ... I went with OpenGL for portability; DirectX... ...
    (rec.games.frp.dnd)
  • Re: avi / mpeg2 files
    ... exact same capture format and bitrate for all archived video -- don't change ... Any differences in format between 2 or more files ... may trigger undesirable re-compression while rendering. ... audio transforms are easily accomplished independent of video compression. ...
    (microsoft.public.windowsxp.moviemaker)
  • ZPack update
    ... of note, a few additions have been made to the format, in particular: ... building an indexing structure and storing it to disk may make sense. ... index structure at load time, which may make the most sense for directories ... nature of the format (most implementations of b-trees I have seen have been ...
    (comp.compression)
  • Re: Binary files
    ... Let us assume we have a platform/implementation with bytes of ... IEEE doubles. ... Storing a number as text takes up to 23 ... and can further use your old data files. ...
    (comp.lang.c)
  • Re: Output Pin Custom Allocator
    ... is started it attempts to reagree format with upstream filter via ... you don't support ARGB32. ... renderer can revert to GDI rendering, so it first connects with a media ... then it switches to a hardware accelerated surface after you run the ...
    (microsoft.public.win32.programmer.directx.video)