473,387 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

2D height map to 3D model?

Hi Folks,

I'm looking to write a Python script that will take a 2D BMP (or
height map) and translate it into a 3D model in OBJ format.

Something of a challenge for me but if it were easy life would be
boring :)

Does anyone know if such a script already exists?
Or any pointers would be appreciated.

Thanks,

PhilC
Jul 18 '05 #1
3 4197
Hi Phil - You don't seem to be getting much in the way of replies so I
thought I would put my 2 cents in ...

PhilC <pc****@philc.net> wrote in message news:<sk********************************@4ax.com>. ..
Hi Folks,

I'm looking to write a Python script that will take a 2D BMP (or
height map) and translate it into a 3D model in OBJ format.

I think you're saying that your input data would be a 2-dimensional
array each element of which would indicate an height above sea level
for that X,Y coordinate (the more I read your original question the
more I doubt my assumption but here goes anyway).

Firstly if you can mangle your data into some format which would be
acceptable as format I suspect that this ...

http://thuban.intevation.org/

.... might do that job.

Assuming that you can't do the mangling (I know I couldn't) have you
seen this ...

http://mayavi.sourceforge.net/

.... and as an instance of the output you might get, this ...

http://mayavi.sourceforge.net/docs/g....html#VIZ-DATA

Another option I came across was this ...

http://www.johnny-lin.com/py_pkgs/Ia...l.html#contour

.... I suspect however that you wanted some output that looked, however
roughly, like an aerial photograph - would be interested to know. I
live in a hilly, rather attractive city and have long wondered about
the possibility of being able to build a model of the land in
software.

Sorry this isn't more help. Maybe you could expand on your needs a
little ?

regards

Richard Shea.

Something of a challenge for me but if it were easy life would be
boring :)

Does anyone know if such a script already exists?
Or any pointers would be appreciated.

Thanks,

PhilC

Jul 18 '05 #2
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

Jul 18 '05 #3
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

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: delerious | last post by:
I need to determine an element's width and height in pixels (not including padding, border, and margin) in Javascript. The element will not have width or height styles specified. In Mozilla, I...
17
by: Torbjørn Pettersen | last post by:
I've got a table where I want some of the cells to use a background image. The cells have variable height, so I am using an image with a rather small height to fill up the background of the cells,...
6
by: Robert Lapes | last post by:
I'm just getting into using CSS and I'm having a problem getting Opera to display a Navigation Bar in the same way as IE6. Can someone please point me in the right direction? The site I'm...
6
by: Stanimir Stamenkov | last post by:
May be a FAQ but I haven't found a suitable solution yet. The general (presentational) structure of a document I'm describing is: Header ------- Content ------- Footer I want to make the...
12
by: Stanimir Stamenkov | last post by:
Here are two cases regarding inline-level elements' line-height, padding and background, which I doesn't understand: <div style="background: black; color: white; line-height: 1.5">...
3
by: Raghavendra | last post by:
Hi All, Here is my code. ------------------------------------------- <div style="height:100%"> <BODY> sample text spanning about 30 lines </BODY> </div>...
3
by: TheXenocide | last post by:
Hello, First and foremost I'll describe a bit about my problem: I'm trying to make a site layout using ASP.NET 2.0 in Visual Studio .NET 2005 Beta 2. The site is a table based layout that is...
6
by: jslaybaugh | last post by:
I'm working on an ASP.NET 2.0 application and am having trouble with a very simple table layout. Using ASP.NET 2.0 it defaults to XHTML 1.0 Transitional and I am trying to comply. However, I...
2
by: laszlokenez | last post by:
Tested in IE7 and FF2. I have 2 frames, 2 similar tables in them, similar CSS. (I have 1px cellpadding, and 1px border aroud the cells. From one frame I read the offsetHeight of a cell...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.