Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]

vlVolume::SlicedVolume Class Reference

An actor encapsulating all the geometry and effects needed to directly render a volume using viewport aligned slices. More...

#include <SlicedVolume.hpp>

Inheritance diagram for vlVolume::SlicedVolume:

vl::Actor vl::Object

List of all members.

Public Member Functions

 SlicedVolume ()
 Constructor.
void update (int, vl::Camera *camera, vl::Real)
 Virtual function used to update or animate an Actor during the rendering.
virtual void updateUniforms (vl::Camera *camera)
 Updates the uniforms used by the vl::GLSLProgram to render the volume each time the update() function is called.
void setSliceCount (int count)
 Defines the number of slices used to render the volume: more slices generate a better rendering.
int sliceCount () const
 Returns the number of slices used to render the volume.
vl::Geometrygeometry ()
 Returns the vl::Geometry associated to a SlicedVolume actor.
const vl::Geometrygeometry () const
 Returns the vl::Geometry associated to a SlicedVolume actor.
vl::Effecteffect ()
 Returns the vl::Effect associated to a SlicedVolume actor.
const vl::Effecteffect () const
 Returns the vl::Effect associated to a SlicedVolume actor.
void setBox (const vl::AABB &box)
 Defines the dimensions of the box enclosing the volume.
const vl::AABBbox () const
 Defines the dimensions of the box enclosing the volume.
const vl::fvec3texCoords () const
 Returns the texture coordinates assigned to each of the 8 box corners.
vl::fvec3texCoords ()
 Returns the texture coordinates assigned to each of the 8 box corners.
void generateTextureCoordinates (const vl::ivec3 &size)
 Generates a default set of texture coordinates based on the give texture dimensions.
void generateTextureCoordinates (int width, int height, int depth)
 Generates a default set of texture coordinates based on the give texture dimensions.
void setVolumeImage (vl::Image *volume)
 Defines the image containing the volume to be rendered.
const vl::ImagetransferFunction () const
 Returns the 1D image used as transfer function for the volume rendering.
vl::ImagetransferFunction ()
 Returns the 1D image used as transfer function for the volume rendering.
void setTransferFunction (vl::Image *tfunc)
 Sets the 1D image used as transfer function for the volume rendering. Pass NULL to remove the transfer function.
const vl::Lightlight () const
 Returns the light used to illuminate the volume.
vl::Lightlight ()
 Returns the light used to illuminate the volume.
void setLight (vl::Light *light)
 Defines the light used to illuminate the volume.
const vl::GLSLProgramglslProgram () const
 Returns the GLSL program used for IF_LUMINANCE volume images.
vl::GLSLProgramglslProgram ()
 Returns the GLSL program used for IF_LUMINANCE volume images.

Static Public Member Functions

static vl::ref< vl::ImagegenRGBAVolume (vl::Image *data, vl::Image *trfunc, const vl::fvec3 &light_dir, bool alpha_from_data=true)
 Generates an RGBA image that can be passed to setVolumeImage() based on the given data source and transfer function.
static vl::ref< vl::ImagegenRGBAVolume (vl::Image *data, vl::Image *trfunc, bool alpha_from_data=true)
 Generates an RGBA image that can be passed to setVolumeImage() based on the given data source and transfer function.

Protected Attributes

int mSliceCount
vl::ref< vl::GeometrymGeometry
vl::ref< vl::EffectmEffect
vl::AABB mBox
vl::fmat4 mCache
vl::fvec3 mTexCoord [8]
vl::ref< vl::ImagemTransferFunction
vl::ref< vl::LightmLight
vl::ref< vl::GLSLProgrammGLSLProgram


Detailed Description

An actor encapsulating all the geometry and effects needed to directly render a volume using viewport aligned slices.

Pictures from the Volume Rendering tutorial.

pagGuideSlicedVolume.jpg
pagGuideSlicedVolume_3.jpg
pagGuideSlicedVolume_1.jpg
pagGuideSlicedVolume_2.jpg
pagGuideSlicedVolume_4.jpg
pagGuideSlicedVolume_5.jpg
pagGuideSlicedVolume_6.jpg
pagGuideSlicedVolume_7.jpg
Using the SlicedVolume class is extremely simple, see below. See also the App_VolumeRendering.hpp example.

By default the constructor installs the following shaders /glsl/volume_luminance_light.fs and /glsl/volume_luminance_light.vs and sets the val_threshold uniform variable to 0.5f.

You can change the GLSLProgram settings in the following way:

 glslProgram()->detachAllShaders();
 glslProgram()->attachShader( new vl::GLSLFragmentShader("/mypath/my_fragment_shader.fs") );
 glslProgram()->attachShader( new vl::GLSLVertexShader("/mypath/my_vertex_shader.fs") );
 glslProgram()->gocUniform("my_uniform")->setUniform(value);

You can also reimplement the updateUniforms() method to update your own uniform variables before every rendering frame.

Using an IF_RGBA volume (no GLSL)
 vl::ref<vlVolume::SlicedVolume> volume = new SlicedVolume;
 // loads an IF_RGBA volume (no transfer function is needed in this case)
 vl::ref<vl::Image> rgba_img = vl::loadImage("myvolume.dat"); 
 // installs the IF_RGBA volume
 volume->setVolumeImage(rgba_img.get());
 // disable GLSL shader
 volume->setTransferFunction(NULL);

Generating an IF_RGBA volume from an IF_LUMINANCE volume + transfer function (no GLSL)
 vl::ref<vlVolume::SlicedVolume> volume = new SlicedVolume;
 // loads an IF_LUMINANCE volume
 vl::ref<vl::Image> img      = vl::loadImage("myvolume.dat"); 
 // generates a transfer function
 vl::ref<vl::Image> trfunc   = vl::Image::makeColorSpectrum(128, vlut::black, vlut::blue, vlut::green, vlut::yellow, vlut::red);
 // computes an IF_RGBA volume using the transfer function and with lighting
 vl::ref<vl::Image> rgba_img = vlVolume::SlicedVolume::genRGBAVolume(img.get(), trfunc.get(), vl::fvec3(1.0f,1.0f,0.0f));
 // installs the IF_RGBA volume
 volume->setVolumeImage(rgba_img.get());
 // disable GLSL shader
 volume->setTransferFunction(NULL);

Using IF_LUMINANCE volume + transfer function with GLSL (with dynamic Blinn-Phong lighting)
 vl::ref<vlVolume::SlicedVolume> volume = new SlicedVolume;
 // generates and install a transfer function to be used with an IF_LUMINANCE volume.
 vl::ref<vl::Image> trfunc = vl::Image::makeColorSpectrum(128, vlut::black, vlut::blue, vlut::green, vlut::yellow, vlut::red);
 // setTransferFunction() also enables the GLSL shader
 volume->setTransferFunction(trfunc.get());
 // loads and install an IF_LUMINANCE volume.
 vl::ref<vl::Image> img = vl::loadImage("myvolume.dat");
 volume->setVolumeImage(img.get());

Constructor & Destructor Documentation

SlicedVolume::SlicedVolume (  ) 

Constructor.


Member Function Documentation

void vlVolume::SlicedVolume::update ( int  ,
vl::Camera ,
vl::Real   
) [virtual]

Virtual function used to update or animate an Actor during the rendering.

Parameters:
lod the LOD (level of detail) currently selected for the rendering.
camera the camera used for the current rendering.
cur_t the current animation time.
Note:
  • is called after the actor resulted to be visible
  • is called only once per frame
  • is called before setting up the rendering states
See also:

Reimplemented from vl::Actor.

void SlicedVolume::updateUniforms ( vl::Camera camera  )  [virtual]

Updates the uniforms used by the vl::GLSLProgram to render the volume each time the update() function is called.

You can reimplement this function in order to setup your own uniform variable for your GLSLProgram.

The default implementation of this function updates the following two uniforms:

  • light_position Light position in object space, used to compute Blinn-Phong lighting in /glsl/volume_luminance_light.fs
  • eye_position Camera position in object space, used to compute Blinn-Phong lighting in /glsl/volume_luminance_light.fs

void vlVolume::SlicedVolume::setSliceCount ( int  count  )  [inline]

Defines the number of slices used to render the volume: more slices generate a better rendering.

int vlVolume::SlicedVolume::sliceCount (  )  const [inline]

Returns the number of slices used to render the volume.

vl::Geometry* vlVolume::SlicedVolume::geometry (  )  [inline]

Returns the vl::Geometry associated to a SlicedVolume actor.

const vl::Geometry* vlVolume::SlicedVolume::geometry (  )  const [inline]

Returns the vl::Geometry associated to a SlicedVolume actor.

vl::Effect* vlVolume::SlicedVolume::effect (  )  [inline]

Returns the vl::Effect associated to a SlicedVolume actor.

Reimplemented from vl::Actor.

const vl::Effect* vlVolume::SlicedVolume::effect (  )  const [inline]

Returns the vl::Effect associated to a SlicedVolume actor.

Reimplemented from vl::Actor.

void SlicedVolume::setBox ( const vl::AABB box  ) 

Defines the dimensions of the box enclosing the volume.

const vl::AABB& vlVolume::SlicedVolume::box (  )  const [inline]

Defines the dimensions of the box enclosing the volume.

const vl::fvec3* vlVolume::SlicedVolume::texCoords (  )  const [inline]

Returns the texture coordinates assigned to each of the 8 box corners.

vl::fvec3* vlVolume::SlicedVolume::texCoords (  )  [inline]

Returns the texture coordinates assigned to each of the 8 box corners.

void SlicedVolume::generateTextureCoordinates ( const vl::ivec3 size  ) 

Generates a default set of texture coordinates based on the give texture dimensions.

The texture coordinate generated by this function should be used with TexParameter wrap mode vl::TPW_REPEAT, ie:.

vl::ref<vl::Texture> texture = new vl::Texture;
texture->getTexParameter()->setWrapS(vl::TPW_REPEAT);
texture->getTexParameter()->setWrapT(vl::TPW_REPEAT);
texture->getTexParameter()->setWrapR(vl::TPW_REPEAT);

void vlVolume::SlicedVolume::generateTextureCoordinates ( int  width,
int  height,
int  depth 
) [inline]

Generates a default set of texture coordinates based on the give texture dimensions.

void SlicedVolume::setVolumeImage ( vl::Image volume  ) 

Defines the image containing the volume to be rendered.

This function also generates a 3D texture based on the given image and generates an appropriate set of texture coordinates.

const vl::Image* vlVolume::SlicedVolume::transferFunction (  )  const [inline]

Returns the 1D image used as transfer function for the volume rendering.

vl::Image* vlVolume::SlicedVolume::transferFunction (  )  [inline]

Returns the 1D image used as transfer function for the volume rendering.

void SlicedVolume::setTransferFunction ( vl::Image tfunc  ) 

Sets the 1D image used as transfer function for the volume rendering. Pass NULL to remove the transfer function.

Selecting a transfer function != NULL automatically enables the GLSL shader returned by glslProgram().

Call setTransferFunction(NULL) to disable the GLSL program. Based on the img format an appropriate rendering method is selected:

  • If tfunc is NULL then it is assumed that the image set by setVolumeImage() contains already the appropriate colors and alpha values as a result of a transfer function and/or lighting computations (see genRGBAVolume()). This is the preferred method for legacy hardware as it does not require GLSL support but can require 4 times more memory and cannot perform realtime-animated lighting.
  • If tfunc is non-NULL then the image set by setVolumeImage() should have IF_LUMINANCE format() and contains the raw volume data. A GLSL program is used in order to execute the transfer function and the lighting computations. In this case the tranfer function tfunc is used. This method requires GLSL support, needs less memory and can perform realtime-animated Blinn-Phong lighting.

const vl::Light* vlVolume::SlicedVolume::light (  )  const [inline]

Returns the light used to illuminate the volume.

vl::Light* vlVolume::SlicedVolume::light (  )  [inline]

Returns the light used to illuminate the volume.

void vlVolume::SlicedVolume::setLight ( vl::Light light  )  [inline]

Defines the light used to illuminate the volume.

const vl::GLSLProgram* vlVolume::SlicedVolume::glslProgram (  )  const [inline]

Returns the GLSL program used for IF_LUMINANCE volume images.

vl::GLSLProgram* vlVolume::SlicedVolume::glslProgram (  )  [inline]

Returns the GLSL program used for IF_LUMINANCE volume images.

ref< Image > SlicedVolume::genRGBAVolume ( vl::Image data,
vl::Image trfunc,
const vl::fvec3 light_dir,
bool  alpha_from_data = true 
) [static]

Generates an RGBA image that can be passed to setVolumeImage() based on the given data source and transfer function.

Parameters:
data The vl::Image used as the volume data source. It must have format() equal to IF_LUMINANCE and type() equal to IT_UNSIGNED_BYTE, IT_UNSIGNED_SHORT or IT_UNSIGNED_FLOAT.
trfunc An 1D vl::Image used as transfer function that is used to assign to each value in data an RGBA quadruplets in the new image. The vl::Image pointed by trfunc must mast have type() IT_UNSIGNED_BYTE and format() IF_RGBA.
light_dir The direction of the light in object space.
alpha_from_data If set to true the alpha channel of the generated image will be taken from data otherwise from the transfer function.

ref< Image > SlicedVolume::genRGBAVolume ( vl::Image data,
vl::Image trfunc,
bool  alpha_from_data = true 
) [static]

Generates an RGBA image that can be passed to setVolumeImage() based on the given data source and transfer function.

Parameters:
data The vl::Image used as the volume data source. It must have format() equal to IF_LUMINANCE and type() equal to IT_UNSIGNED_BYTE, IT_UNSIGNED_SHORT or IT_UNSIGNED_FLOAT.
trfunc An 1D vl::Image used as transfer function that is used to assign to each value in data an RGBA quadruplets in the new image. The vl::Image pointed by trfunc must mast have type() IT_UNSIGNED_BYTE and format() IF_RGBA.
alpha_from_data If set to true the alpha channel of the generated image will be taken from data otherwise from the transfer function.
Unlike genRGBAVolume(vl::Image* data, vl::Image* trfunc, const vl::fvec3& light_dir, bool alpha_from_data=true) this function does not compute lighting.


Member Data Documentation

Reimplemented from vl::Actor.


The documentation for this class was generated from the following files:

Visualization Library v2010.06 Reference Documentation
Copyright 2005-2009 Michele Bosi. All rights reserved.
Updated on Tue Jun 1 00:57:39 2010.
Permission is granted to use this page to write and publish articles regarding Visualization Library.