Step 4: Displaying and Animating the Images
SVS images typically do not come with an underlying image of the
Earth's surface showing through. This is not a problem for images that
completely cover the globe. But many SVS animations make no sense
unless they're superimposed on a globe with base imagery of Earth
terrain. EarthFlicks addresses this by implementing an Earth model
that's covered with NASA's Blue Marble imagery, shown in Figure 6.

Figure 6.
The Blue Marble imagery
Several resolutions of the Blue Marble imagery are
available. EarthFlicks uses three of those, automatically switching to
the most appropriate and efficient as the user zooms in and out.
The SVS images can
be overlaid onto the Earth's surface. There are many ways to do
this. I chose to create a solid sphere matching the base globe, and
apply the SVS images as texture maps to that. The code for this is in
the EarthFlicks Shell class, in the Globe
package. That class computes the vertices of triangle strips to
represent the surface, and assigns appropriate texture coordinates to
fit each SVS image to the correct latitudes and longitudes.
Applying the texture to the shell is both simplified and
complicated by the texture cache EarthFlicks uses. To best use the
computer's graphics memory, EarthFlicks maintains a cache that keeps
the most recently used textures in memory. This cache is responsible
for opening texture files when they are first needed, managing them in memory,
and binding them to OpenGL texture
identifiers. The TextureCache class does all of this. The
code for that class also shows how EarthFlicks specifies textures and
makes them current in OpenGL.
I've found that the fastest way to get an image from disk to memory
is by memory mapping the image
file. Java's java.nio.MappedByteBuffer makes this very
easy. EarthFlicks maintains a singleton mapped-file cache that maps
and manages memory-mapped image files. The implementation is in
the MappedFileCache class in the Globe
package.
This mapped-file cache is the third cache I've described for
EarthFlicks. To recap, there's one cache to hold
the converted images to be used as texture maps permanently on disk.
There's another cache
to manage run-time texture loading and binding to OpenGL. Finally, there's
a third cache to manage memory-mapped image files.
Playing with the Globe
At this point, there exist sequences of images from the SVS
server converted from PNG to images that can be used by OpenGL as
texture maps, all cached on a local disk. There's also code to map
these images into memory, bind them to OpenGL, and display them on a
globe with a pretty Blue Marble background surface. But these images
do not "play" as animations yet.
Playing the images is probably the simplest part of all. The ImagePlayer class in EarthFlicks accepts an
image sequence and plays it by setting a timer and displaying
consecutive images of the animation at each timer
tick. Its start() method kicks off the animation. When
all the images in the sequence have been displayed, ImagePlayer
invokes a callback to EarthFlicks' Controller class to return the user
interface to the pre-animation state, ready for the animation to be
run again.
If an image sequence is specific to a region of the
globe, ImagePlayer positions the viewpoint over that
region before playing the animation. It also has methods to stop,
pause, and resume the animation, and to remove it from the globe.
One last thing to do is provide a means for the user to turn the
globe and zoom in and out. EarthFlicks implements a very simple
mechanism for this: a rectangular region defined by latitude and
longitude is defined as a viewing window onto the globe. Moving this
region makes the globe appear to rotate. Expanding or contracting it
has the effect of zooming in and out. This is not a full 3D
manipulation model that allows the user to "fly around" in any
orientation. The user is always looking directly at the globe, and the
viewing direction is always perpendicular to the Earth's surface. If
EarthFlicks were to more realistically represent the Earth by applying
surface elevation, this manipulation model would be inadequate.
This manipulation scheme does have a couple of advantages: it allows
for a very quick, high-level clipping scheme to avoid drawing regions
of the globe that are not in view. And it keeps the user oriented to
the globe so that "up" is always north.
Conclusion
The SVS animations are designed to be used in visualization
programs for education. I've described in this article how to retrieve
the images composing those animations and display them on a 3D model
of the Earth. There isn't room here to describe or even list all the
code involved in doing that, so I've tried to identify, explain, and
illustrate the tasks unique to this type of application and the SVS
imagery. Much of this information, of course, can also apply to images
and image sequences available from other WMS servers.
Resources
The author can be reached at
Creation of this article and the example application was funded by NASA.
Tom Gaskins is the technical director for NASA Learning Technologies.