#include <display3d.h>
This class is a simple volume renderer. The rendered planes are aligned with the screen.
A human heart
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... |
Display::Volume::Volume | ( | ) |
Display::Volume::~Volume | ( | ) |
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
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
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
lut | RGBA values, ranges from 0..1 | |
lutSize | number of RGBA entries, ranges from all posible data intensities |
void Display::Volume::updateLut | ( | const Lut & | lut | ) | [inline] |
update lookup table with an external lut object
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) |
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
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
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().
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
min,max | min and max intensity value of the data |
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
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
Mode Display::Volume::m_rendering_mode [protected] |
Rendering mode (default is VRT).
float Display::Volume::m_quality [protected] |
Rendering quality, this affects the number of rendering planes.
GLint Display::Volume::m_interpolation [protected] |
GLuint Display::Volume::m_data_texture [protected] |
unsigned int Display::Volume::m_max_texture_size[3] [protected] |
float Display::Volume::m_texture_scale[3] [protected] |
float Display::Volume::m_intensity_range[2] [protected] |
float Display::Volume::m_mpr_matrix[16] [protected] |
mpr plane matrix
GLuint Display::Volume::m_gpu_program [protected] |
GLuint Display::Volume::m_fragment_shader [protected] |
handle on the fragment shader
float* Display::Volume::m_internal_lut [protected] |
GLuint Display::Volume::m_lut_texture [protected] |