Top2maya – A Tool for Converting 2D Topographical Maps to 3D Models.
Rob
Gillespie
Consultant
Visualization,
Media and Imaging Laboratory


Figure
1: left: red blood cells imaged on AFM (J. Gunther),
right:
The resulting 3D model produced using top2maya
Top2maya is a program written in MEL script which changes 2D topographical maps into three-dimensional models and images. This script does this by changing an image into grayscale, then displacing the pixels according to their intensity value. White gets displaced the most on the y-axis, while black does not get displaced at all. The resulting models make it easy to visualize the surface, while the rendered images are suitable for presentation and/or publication. Top2maya is especially useful for transforming data from the AFM, NSOM and confocal microscopes.
This script needs the data image to be an RGB TIFF. If you have any other format it will need to be converted to an RGB TIFF using Adobe Photoshop. NOTE: All TIFFs are not RGB TIFFs. Digital Instrument’s AFM software in the Microscopy Suite uses indexed-color TIFFs. This must be changed. To make sure your data is in the proper format, first open the image in Photoshop. You can then crop it if needed to make sure you only get the part of the image you want. Once the image is ready, go to Image -> Mode and make sure there is a check mark next to RGB color. Once this is set, go to File -> Save as… and set the image type to TIFF. Your data should now be ready for use with top2maya.
Running Maya
Maya is currently installed on Pollock, Hofmann and Arbus in the VMIL. To start the program, go to Start Menu -> Quickfind -> Maya. Once the program is running, you will need to do some initial setup.

Figure
2: The Maya Interface Window
First Time
Users
You
will first need to create a project. A project is a place to store all of your
files in order to avoid mess and confusion. To make a new project go to File
-> Project -> New. In the box that opens click the Use Defaults
button at the bottom. Then enter your username as the project name on top and
set the project path to a folder on drive H:, which is your home directory on
the network. DO NOT use the default path as your project path. This path will
cause your work to be stored in your profile and can make it take a VERY long
time to log in and out of the computers. Once this is done click the Accept
button.
Opening
top2maya (First Time Users)
Next
you will need to source the top2maya script and create a shortcut to it on the
shelf. This only has to be done once per project. A shelf is a customizable row
of buttons which the user can define. It is the second row of buttons from the
top, and each user has two shelves they can use. To add the script to your
shelf, go to Window -> General Editors -> Script Editor. In the
Script Editor, go to File -> Open Script and browse to C:\maya\scripts
and open top2maya.mel. This should place a few lines of text into the Script
Editor. Highlight this text by dragging over it with the right mouse button,
then hold the middle mouse button down over the highlighted text and drag and
drop the text onto the shelf. This will add a button for the script onto your
shelf. The new button will have MEL printed on it. Again, this should only have
to be done once as long as you use the same project.
You
will need to set your project after you load Maya. To do this, go to File
-> Project -> Set. In the window that comes up, you can then browse
for your project name. Once found highlight it and click OK. If you have
previously sourced the top2maya script in this project it will now be on your
shelf. If you have not done this or the icon is not on the shelf, refer to Opening
top2maya above.
Click on your new shelf button to launch the top2maya script. Note that running the top2maya will DELETE everything in the scene. As a precaution, it will prompt you before this is done. If you have any work done in the scene, make sure to save it before running the script. There are several parameters in top2maya which can be set. They are as follows.

Image Path: This is the path of the image you are going to
change into a 3D model. If nothing is entered in the next field it is also the
image used to color the new model. When typing in the image path, use the
forward slash ‘/’, not the backslash ‘\’ for the path. Maya does not
recognize the backslash and the model will not work properly if you use it. The
browse button may also be used to browse to the image.
Enter Path to Map a
Different File for Shading:
If you would like to generate the model with one topographical map and then
shade, or color it, with a different image, you can enter the path of that image
here. It must be in the same format as previously discussed in the Getting
Data Ready for Use With Top2maya section. By doing this you can visualize
multiple properties on one model (i.e. mapping a color representation of
magnetic properties on top of a topographical 3D model of your data).
Lights Checkbox: Make sure this is checked if you would like
lights in your scene. Without lights your output will be black. The only reason
this should be unchecked is if you want to do your own lighting design.
Animate Checkbox: Check this to set up an animated sequence to
show off the model. This animation rotates the model 360 degrees then towards
the end tilts it up and holds. Even if you are not going to use an animation it
is recommended to use this option in order to set up the camera to bring the
model into the proper scale.
StereoAnimation Radio
Button:
If you would like to render out the complete animation for three-dimensional
viewing with the crystal-eyes glasses, you will need to render one animation
with this button unchecked and then redo it with this button checked. This sets
up a stereo view so it can be put into Entomon. Entomon is a program written by
Daniel Weber, which sets up 3D images and animations using crystal-eyes glasses.
For more information on Entomon talk to Daniel Weber. For more information on
setting up stereo effects, see Setting Up Stereo Effects near the
end of this report.
(Dan Weber).
StereoStill Radio Button: If you would like to render out an image for
three-dimensional viewing with the crystal-eyes glasses, you will need to select
this button and follow the on screen instructions. This will set up a stereo
view of the image so it can be put into Entomon. For more information on this
see Setting up Stereo Effects near the end of this report.
None Radio Button: If
you do not want to render any stereo images, but instead just want the normal
three-dimensional image on the screen, this is the radio button which should be
selected. This button is selected by default.
Tessellation U and V:
These are the tessellation numbers in the U and V directions. This says how many
polygons are going to be set up across the height and width of each grid unit.
The default values should get all the detail out of almost any image. If you
have a very large image or a very rough surface you may need to raise these
values. The best method for determining these values is trial and error.
Grid Units U and V:
This is how many units the grid is divided into. These can be raised instead of
or in addition to the tessellation values to increase accuracy. The defaults are
set to accommodate most data types.
Displace Geometry: Once you have all the fields set, click this
button to make the 3D model.
You
can either export an animation or a single frame. If you want to export an
animation, you can skip this section and go straight to Setting Up for Export.
To
export a frame you will first need to set up the view you wish to export. To get
the proper size proportions, you should first go to View -> Camera
Settings -> Resolution Gate. This is in the window pull down menus, not
the main menus on the top. This will set up a resolution gate showing you the
size of the area actually being rendered. You can now position the model within
the box. In order to position the model properly, there are several movement
functions you will need to know. To move around in the window you have 3
functions:
Alt-Middle Mouse Button –
Pan
Alt-Left and Middle Mouse
Button – Zoom
By holding down the Alt key and using these button combinations you can orbit around, center and zoom in on your model to get the proper orientation. Another variable you may wish to adjust is the height scaling of the model. To do this, you first need to click on the model to select it. Once selected the wireframe of the model should be highlighted in green. In the channel box on the right side of the screen under nurbsPlane1_displacement1 there is an attribute titled scale Y that is set to 0.13. By raising or lowering this value you can change the height, or maximum displacement, of the model.
General
Export Settings (Frame and Animation)
You
are now ready to set up your export options. Choose Window -> Render Globals…
to open a dialog box. In the Image File Output section, set the File Name Prefix
to what you would like the images to be titled. Do not use spaces in the file
name. Under the Image File Output section you can also set the Image Format.
This can be whatever file type you would like your output to be, ie. TIFF, JPG,
IFF, YUV, etc. In the Image File Output section you must also set the Camera
field to Camera1. This will make sure you are exporting what you are looking at.
Next
open up the Resolution section by clicking on the arrow. Pick the
resolution you would like your image to be rendered at (ie. 320x240, 640x480,
etc.) Finally open up the Anti-Aliasing Quality section. Here you can set
the quality of your render. For good quality it is recommended to set the Presents
field to Production Quality.
If you would like to export a single frame, close this window and continue on to the Rendering section of this document.
To set up to render an animation you need to change a few more fields in the Window -> Render Globals… dialog box. In the File Output section you will need to set the Frame/Animation Ext option to name.#.ext for Windows NT or name.ext.# on an SGI. You will also need to change the End Frame property to 135. Everything should now be set up to render your animation. Continue on to the Rendering Section of this document.
To
render out your frames or animation you will need to make sure you are in the Rendering
Menu set. This can be selected in the pull down dialog box at the top left
side of the screen under the Edit and File menus. Make sure it says Rendering
in this box. Next go to Render -> Save (Batch) Render. This will open
up a browser. Type in a file in order to save the animation scene. The animation
scene is not your actual rendered images, but a Maya Binary scene file. When
done, press the Save/Render button. Your image(s) are now being rendered
out. If you are rendering a lot of images at a high resolution this could take
some time. To follow the progress of the rendering you can go to Window ->
General Editors -> Script Editor and the progress will be displayed in
the window. Your images will be saved into the project you set earlier in a
folder called “images.”
In order to have a stereo animation you need to render out two copies of the animation. To do this, run top2maya with the Animate Checkbox on, and the StereoAnimation radio button off (set on None.) Now render this animation out. Next you will need to rerun the script on the same image with the Animate Checkbox on and also the StereoAnimation radio button selected. Render this out under a different name than the previous animation. These two animations will be offset so they will appear to form one three-dimensional animation when viewed in Entomon.
To
render out your frames or animation you will need to make sure you are in the Rendering
Menu set. This can be selected in the pull down dialog box at the top left
side of the screen under the Edit and File menus. Make sure it says Rendering
in this box. Next go to Render -> Save (Batch) Render. This will open
up a browser. Type in a file in order to save the animation scene. The animation
scene is not your actual rendered images, but a Maya Binary scene file. When
done, press the Save/Render button. Your image(s) are now being rendered
out. If you are rendering a lot of images at a high resolution this could take
some time. To follow the progress of the rendering you can go to Window ->
General Editors -> Script Editor and the progress will be displayed in
the window. Your images will be saved into the project you set earlier in a
folder called “images.”
To
render out a StereoStill, or a single image that can be viewed with
crystal-eyes stereo glasses, you will need to select the StereoStill
radio button on the top2maya interface window. The Animate Checkbox can
be checked or unchecked. Once the script has been executed another window will
open giving directions on how to get a StereoStill. You will first need to pan,
zoom and rotate around the object until you get the view you wish to render.
Once you have the view selected, you will need to go to the Render Globals
menu and set it up to render out a TIFF image at whatever resolution and Anti-Aliasing
you desire. You will also need to set the Frame/Animation Ext. option to
Frame.ext. Then on the render menu set go to Render -> Save (Batch)
Render to render out the image. Once it is rendered out, click the button
labeled GetStereo on the stereo control box. This will adjust the camera
to a stereo view for the image you previously selected. Follow the same
directions to render this image out. Make sure it has a different name in the Render
Globals File Name Prefix setting so you do not save over the previous data.
Once you have these two images rendered out, they are ready to be brought into
Entomon for three-dimensional viewing.

In order to calculate the proper position of the stereo view, a vector length is calculated from the camera to the center of the object. Then, at 10 different vector lengths ranging from very close to far away, 10 different stereo images were taken. For a given length the stereo images were taken from 10 different angles with the center of rotation being at the center of the object being viewed. These were then viewed with Entomon to determine which angle difference was best for each of the 10 vector lengths. Once all this data was obtained, the data was brought into CricketGraph for analysis. The points were plotted on a graph and then the graph was broken down into four sections. Once this was done, the curve fit option was used to approximate a curve to hit each of the four sections. These curve equations were then put into the top2maya script in order to calculate the angle distance needed for good stereo for a given vector length. This allows the user to get stereo images from any camera view desired. Once the camera is positioned and the Get Stereo button is pressed, a vector length is calculated. Top2maya analyzes this to determine which range it is in, then used the appropriate equation to calculate the change in the angle needed for good stereo at that length.
To send to the ACCOM, you will need the Image Format property in the File Output section in Render Globals to Quantel (YUV). You will also need to open the Resolution section and set the Width field to 720 and the Height field to 486. Once rendered out, see the documentation at http://www.itg.uiuc.edu/help/accom/ This will take you through the rest of the steps needed to put your frames or animation onto video.
Viewing
the Final Output
Depending on your image format, there may be several ways to view your output. If you have just single images in a TIFF or JPG format you can view them in any imaging software such as Adobe Photoshop. If you are using a not so common image format, for example YUV or the Maya default IFF file type you will need to use Fcheck. You can start this by running it in Start menu -> Quickfind -> Fcheck. Fcheck can be used to view animations or images. To view an image go to File -> Open Image… and then select the image you wish to view from the browser. To view an animation go to File -> Open Animation… and select the first frame in the animation. This first time through the animation will be slow and choppy as everything is being loaded into memory. Once the first pass is done it should speed up considerably. For further help on manipulating animations in Fcheck, open Help -> Animation Controls in the Fcheck program.
To
send to the ACCOM, you will need the Image Format property in the File
Output section in Render Globals to Quantel (YUV). You will also need
to open the Resolution section and set the Width field to 720 and
the Height field to 486. Once rendered out, see the documentation at http://www.itg.uiuc.edu/help/accom/
This will take you through the rest of the steps needed to put your frames or
animation onto video.
Additional
References
If you wish to use more advanced techniques than described in this report, there are several resources available. In the lab you can refer to the Maya Manuals, Maya Complete 2, and Learning Maya 2. Help is also available on the Web at http://www.highend3d.com/.
Author: Rob Gillespie
Last Revised: 04/2001