Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics
[Home] [Tutorials] [All Classes] [Grouped Classes]
Public Member Functions | Static Public Member Functions | Protected Attributes

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::ActorEventCallback vl::Object

List of all members.

Public Member Functions

 SlicedVolume ()
 Constructor.
void onActorRenderStarted (vl::Actor *actor, vl::Real frame_clock, const vl::Camera *cam, vl::Renderable *renderable, const vl::Shader *shader, int pass)
 Event generated just before an Actor is rendered but after the render states are ready and setup.
void onActorDelete (vl::Actor *)
 Event notifying that an Actor is being deleted.
void bindActor (vl::Actor *)
virtual void updateUniforms (const vl::Camera *camera, vl::Actor *)
 Updates the uniforms used by the vl::GLSLProgram to render the volume each time the onActorRenderStarted() method 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.
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, vl::Shader *shader)
 Defines the image containing the volume to be rendered.
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.

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::AABB mBox
vl::fmat4 mCache
vl::fvec3 mTexCoord [8]
vl::ref< vl::LightmLight

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 SlicedVolume::onActorRenderStarted ( vl::Actor actor,
vl::Real  frame_clock,
const vl::Camera cam,
vl::Renderable renderable,
const vl::Shader shader,
int  pass 
) [virtual]

Event generated just before an Actor is rendered but after the render states are ready and setup.

Reimplement to react to this event.

Parameters:
actorThe Actor bound to this rendering callback.
frame_clockThe current rendering frame time, usually used for animation purposes.
camThe camera used for the current rendering.
renderableThe currently selected Actor LOD.
shaderThe currently active Shader.
passThe current Actor[s] rendering pass.

Implements vl::ActorEventCallback.

void vlVolume::SlicedVolume::onActorDelete ( vl::Actor actor ) [inline, virtual]

Event notifying that an Actor is being deleted.

Implements vl::ActorEventCallback.

void SlicedVolume::bindActor ( vl::Actor actor )
void SlicedVolume::updateUniforms ( const vl::Camera camera,
vl::Actor actor 
) [virtual]

Updates the uniforms used by the vl::GLSLProgram to render the volume each time the onActorRenderStarted() method 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.

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,
vl::Shader shader 
)

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::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.

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:
dataThe 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.
trfuncAn 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_dirThe direction of the light in object space.
alpha_from_dataIf 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:
dataThe 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.
trfuncAn 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_dataIf 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


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

Visualization Library v2010.11.1125 Reference Documentation
Copyright 2005-2009 Michele Bosi. All rights reserved.
Updated on Fri Nov 26 2010 10:33:56.
Permission is granted to use this page to write and publish articles regarding Visualization Library.