openmicroscopy/bioformats-examples — pull request #1 by rleigh-dundee (2013-11-11 23:44:08+00:00)
Title: Add GLView C++ viewer for 3D volume surfaces

While this does not yet support the bioformats API, this is a proof of concept viewer for rendering 3D volumes with OpenGL. Note that it's currently restricted to loading a single file (/ome/team/rleigh/qtgltest/vessels.ome.tiff) and the path to the image is hardcoded in the sources; you'll need to edit the path before you build. This restriction will be lifted once we can switch it to using the bioformats reader API.

Prerequisites:
- CMake
- Qt5.x with OpenGL support enabled
- OpenGL (libGL)
- libtiff
- GLm (http://glm.g-truc.net)

To build:
- Create and cd into a build directory
- run `cmake /path/to/sources`. Set `CMAKE_PREFIX_PATH` in the environment if Qt5 isn't found automatically.
- run `make`

To run:
- Run the `glview` binary

GLView works by creating a 3D texture per channel, and then uploading the image data to the GPU memory per strip. You might notice a delay as it computes the mipmaps. The sampling is set to the highest quality linear interpolation with mipmaps for high quality minification samples. You'll also need sufficient graphics memory to cover the ~600MB of 16 bit data, plus all the mipmaps, probably about 1GB. If you don't have sufficient memory, you could tweak the sources to comment out the mipmap generation and/or set the internal format to 8bit rather than 16 to halve the memory requirements. The GPU must support OpenGL 2.x with vertex and pixel shaders.

Once the 3D texture data is loaded, this is used to render the surfaces of a cuboid. The first three sliders control the x/y/z rotation, which can also be achieved by dragging the mouse with or without shift to switch y/z. Sliders 4 and 5 control the min and max for linear contrast; the GL fragment shader uses these to adjust the levels in realtime (per frame); you should see smooth response at 60Hz (or your monitor refresh rate). This adjusts both the red and green channels (but the green channel is artificially limited to 1/2 the red channel level--it's just autofluorescence). The last slider adjusts the z depth of the volume to allow virtual sectioning through the cuboid, also in realtime. The depth adjustment triggers recomputing of the cuboid geometry and its 3D texture coordinates.

(With additional work, the viewer could slab through the volume at abitrary angles; the 3D texture may be sampled across arbitrary planes. We could also introduce proper transparency to allow viewing of the 3D intensity/opacity of the whole volume. And the UI is very primitive at this point; there are a lot of obvious improvements to be made; it only exists at present to drive the realtime rendering adjustments.)

![glview](https://f.cloud.github.com/assets/1528953/1517685/79f6bb6e-4b26-11e3-884b-12ed987a4c36.png)