Display::Volume Class Reference

#include <display3d.h>

List of all members.


Detailed Description

3D volume renderer

This class is a simple volume renderer. The rendered planes are aligned with the screen.

displayvolume.png

A human heart

A 3D texture is used to render the volume and a fragment shader changes the way the volume is colorized with a lookup table.

When drawing the volume it is centered at (0,0,0) and has the unit size (1,1,1). You can scale or modify its orientation with glScale() and glMultMatrix() when drawing it in your application.

Here is an example of code:

        unsigned short* volume; // also fill the data
        Display::Volume disp;

        disp.update(volume, 100,100,100);
        disp.updateRamp(0,500);
        disp.display();

If you want to blend an object with the volume, enable GL_DEPTH_TEST and draw the objects first before the volume.

Internally, it uses 3D texture, as well as a fragment shader. That means you need to load OpenGL extensions before using this code. You can do it with for instance Glew, GLee.

Internally, the lookup table has typically 4096 bins (the maximum texture size). This may be a problem if you have more than 4096 values in your volume, the lut resolution decreases.

Internally, it creates a temporary volume with normalized intensities with the right opengl compatible size. If the volume is too large the texture data is going to be smaller. This can be set with setMaxTextureSize().

Different display modes are available: VRT - the regular volume renderer where intensities accumulates MIP - maximum intensity projection where only the max intensity is displayed MPR - shows an arbitrary slice of the volume, it might be usefull to use this mode with alignWithScreen() to display the mpr in a 2D window with other geometries, and with setMprMatrix() to set the mpr plane orientation and position

Public Types

enum  Mode { VRT, MIP, MPR }

Public Member Functions

 Volume ()
 ~Volume ()
template<typename DataType>
void update (const DataType *data, unsigned int w, unsigned int h, unsigned int d)
void display () const
void setMode (Mode mode)
Mode getMode () const
void setMprMatrix (const float matrix[])
void updateRamp (float min, float max)
void updateLut (const float *lut, unsigned int lutSize)
template<typename Lut>
void updateLut (const Lut &lut)
void alignWithScreen () const
void setQuality (float quality)
void setInterpolation (int interpolation)
void setMaxTextureSize (unsigned int w, unsigned int h, unsigned int d)
void getIntensityRange (float &min, float &max) const

Protected Member Functions

void initShader ()
void render () const
void renderSlice (const float m[]) const
int getNbRenderingPlanes () const

Static Protected Member Functions

static void getTextureSize (const unsigned int data_size[], unsigned int texture_size[], const unsigned int max_texture_size[])
template<typename DataType, typename DataOutType>
static DataOutType * createTextureData (const DataType *data, const unsigned int data_size[], DataType &min, DataType &max, const unsigned int texture_size[])
static void transf (const float p[], const float m[], float pp[])
static void transp (float m[])
static void normalize (float m[])

Protected Attributes

Mode m_rendering_mode
 Rendering mode (default is VRT).
float m_quality
 Rendering quality, this affects the number of rendering planes.
GLint m_interpolation
 what interpolation to use
GLuint m_data_texture
 handle on 3D texture
unsigned int m_max_texture_size [3]
 maximum texture size (default is 256^3)
float m_texture_scale [3]
 texture scale (scale to opengl compatible size)
float m_intensity_range [2]
 data intensity range (min and max value of the data)
float m_mpr_matrix [16]
 mpr plane matrix
GLuint m_gpu_program
 handle on the GPU program (0 when uninitialized)
GLuint m_fragment_shader
 handle on the fragment shader
float * m_internal_lut
 normalized lookup table (0..GL_MAX_TEXTURE_SIZE)
GLuint m_lut_texture
 handle on lookup table texture

Classes

struct  OpenGLArgs
 provides usefull constants depending on the data type More...


Member Enumeration Documentation

Enumerator:
VRT  Volume Rendering Technique, accumulate voxel intensities (default).
MIP  Maximum Intensity Projection, display the brightest voxels.
MPR  Multi Planar Reconstruction, an arbitrary slice of the volume.


Constructor & Destructor Documentation

Display::Volume::Volume (  ) 

Display::Volume::~Volume (  ) 


Member Function Documentation

template<typename DataType>
void Display::Volume::update ( const DataType *  data,
unsigned int  width,
unsigned int  height,
unsigned int  depth 
) [inline]

update visualizer with a new volume this creates a 3D texture on the graphic memory (the max size is set with setMaxTextureSize)

Create a 3D texture Template tools creates the right 3D texture Initialize shader is this is the first update

References getTextureSize(), initShader(), LOCATE, m_data_texture, m_gpu_program, m_intensity_range, m_interpolation, m_max_texture_size, m_texture_scale, and updateRamp().

void Display::Volume::display (  )  const

display the 3D volume

void Display::Volume::setMode ( Mode  mode  ) 

set rendering mode

Parameters:
mode rendering mode can be either VRT, MIP, MPR

Mode Display::Volume::getMode (  )  const

get rendering mode

void Display::Volume::setMprMatrix ( const float  matrix[]  ) 

set mpr plane matrix

void Display::Volume::updateRamp ( float  min,
float  max 
)

update the lookup table, this uses a ramp to defines redish colors

Parameters:
min lower bound of the ramp
max higher bound of the ramp

Referenced by update().

void Display::Volume::updateLut ( const float *  lut,
unsigned int  lutSize 
)

update lookup table, this uses an arbitrary lut

Parameters:
lut RGBA values, ranges from 0..1
lutSize number of RGBA entries, ranges from all posible data intensities

template<typename Lut>
void Display::Volume::updateLut ( const Lut &  lut  )  [inline]

update lookup table with an external lut object

Parameters:
lut lut object, must implement the method "get(intensity, r,g,b,a)" which takes an intensity and returns the corresponding rgba (normalized between 0..1)
See also:
Tools::TransferFunction::Ramp

Tools::TransferFunction::Trapezoid

Tools::TransferFunction::Editor

References m_gpu_program, m_intensity_range, m_internal_lut, and m_lut_texture.

void Display::Volume::alignWithScreen (  )  const

align geometry with screen all further geometry will be aligned with the screen, it multiplies the modelview matrix by the inverse of the mpr plane matrix make sure to apply all transformations (e.g., scaling) before aligning with screen usefull when displaying the mpr plane

void Display::Volume::setQuality ( float  quality  ) 

set the rendering quality (default is 1) it changes the number of rendering planes, usefull when interactivity becomes important

Parameters:
quality if quality is < 1, less planes are used however the rendering is much faster if the quality is > 1, more planes are used, however the rendering gets slower

void Display::Volume::setInterpolation ( int  interpolation  ) 

use interpolation to generate intervoxels

Parameters:
interpolation 0 (no interpolation, use the nearest neighbor), 1 (use linear interpolation)

void Display::Volume::setMaxTextureSize ( unsigned int  w,
unsigned int  h,
unsigned int  d 
)

set the maximum texture size this must be a opengl compatible size (2^m)

void Display::Volume::getIntensityRange ( float &  min,
float &  max 
) const

get the intensity range of the displayed volume (values casted to float)

void Display::Volume::initShader (  )  [protected]

initialize the shader

Referenced by update().

static void Display::Volume::getTextureSize ( const unsigned int  data_size[],
unsigned int  texture_size[],
const unsigned int  max_texture_size[] 
) [static, protected]

get the texture size the texture size is opengl compatible

Referenced by update().

template<typename DataType, typename DataOutType>
DataOutType * Display::Volume::createTextureData ( const DataType *  data,
const unsigned int  data_size[],
DataType &  min,
DataType &  max,
const unsigned int  texture_size[] 
) [inline, static, protected]

create texture data the texture size is opengl compatible intensities are normalized for a better lut resolution

Parameters:
min,max min and max intensity value of the data
create texture data the texture size is opengl compatible intensities are normalized for a better lut resolution

void Display::Volume::render (  )  const [protected]

render the planes in 3D this is the actual volume renderer

void Display::Volume::renderSlice ( const float  m[]  )  const [protected]

render a slice in 3D

Parameters:
m plane matrix

int Display::Volume::getNbRenderingPlanes (  )  const [protected]

compute the number of rendering planes evaluate how many pixels are used to display the volume

static void Display::Volume::transf ( const float  p[],
const float  m[],
float  pp[] 
) [static, protected]

transform a point with a matrix (pp = m*pp)

static void Display::Volume::transp ( float  m[]  )  [static, protected]

transpose, also invert a orthonormal matrix

static void Display::Volume::normalize ( float  m[]  )  [static, protected]

normalize the rotation part of the matrix


Member Data Documentation

Rendering mode (default is VRT).

float Display::Volume::m_quality [protected]

Rendering quality, this affects the number of rendering planes.

what interpolation to use

Referenced by update().

GLuint Display::Volume::m_data_texture [protected]

handle on 3D texture

Referenced by update().

unsigned int Display::Volume::m_max_texture_size[3] [protected]

maximum texture size (default is 256^3)

Referenced by update().

float Display::Volume::m_texture_scale[3] [protected]

texture scale (scale to opengl compatible size)

Referenced by update().

float Display::Volume::m_intensity_range[2] [protected]

data intensity range (min and max value of the data)

Referenced by update(), and updateLut().

float Display::Volume::m_mpr_matrix[16] [protected]

mpr plane matrix

GLuint Display::Volume::m_gpu_program [protected]

handle on the GPU program (0 when uninitialized)

Referenced by update(), and updateLut().

handle on the fragment shader

float* Display::Volume::m_internal_lut [protected]

normalized lookup table (0..GL_MAX_TEXTURE_SIZE)

Referenced by updateLut().

GLuint Display::Volume::m_lut_texture [protected]

handle on lookup table texture

Referenced by updateLut().


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

Generated on Tue Aug 4 17:57:43 2009 for libvd by  doxygen 1.5.5