the Very Simple Volume Rendering containing a texture and transfer function. More...
Very Simple Volume Rendering Implementation --------------
The VSVR algorithm is implemented as described in the paper http://www.matmidia.mat.puc-rio.br/tomlew/pdfs/vsvr_puc.pdf.
The code is written with the 3D_Ext texture target, but may be changed to simple 3D texture targets by replacing in file vsvr.cpp "_EXT" by "" and "3DExt" by "3D". Without the 3D_Ext extension, the texture's sizes must be powers of 2. Some default GLU libraries on MS Windows system are particularly slow, which harms the interactivity of the rendering. This can be solved recompiling it, or retrieving a decent library.
The class VSVR may be used in other applications, using functions similar to "tex_set_formula" (file glui_tex_gen) and "tf_set_formula" (file glui_tf_gen) for setting the texture and the transfer function. The texture is then displayed using VSVR::gl_render and redisplayed using VSVR::gl_redisplay.
Huge textures can be loaded by instantiating several VSVR classes, displaying them at their respective positions.
You may use the code for your applications freely. We just ask you to cite the paper for any kind of publication or reselling that uses the code. *
VSVR::VSVR | ( | const int | tex_ni = -1 , |
|
const int | tex_nj = -1 , |
|||
const int | tex_nk = -1 , |
|||
const int | tf_size = -1 | |||
) | [inline] |
Main and default constructor
tex_ni | width of the 3D texture (must be a power of 2) | |
tex_nj | depth of the 3D texture (must be a power of 2) | |
tex_nk | height of the 3D texture (must be a power of 2) | |
tf_size | size of the transfer function |
References _xmax, _xmax_wcs, _xmin, _xmin_wcs, _ymax, _ymax_wcs, _ymin, _ymin_wcs, _zmax, _zmax_wcs, _zmin, and _zmin_wcs.
VSVR::~VSVR | ( | ) | [inline] |
Destructor
References _tex, tex_free(), tex_glunload(), tf_free(), and tf_glunload().
void VSVR::display | ( | float | xtrans, | |
float | ytrans, | |||
float | ztrans, | |||
float | tippangle, | |||
float | viewangle, | |||
float | scale | |||
) |
GLUT display () function
References _draw_axes, _draw_grid, _draw_tf, _force_reload, _xmax, _xmin, _ymax, _ymin, _zmax, _zmin, draw_axes(), draw_grid(), draw_transfer(), gl_redisplay(), gl_render(), tex_ni(), tex_nj(), tex_nk(), and tf_size().
Referenced by display().
void VSVR::set_draw_tf | ( | bool | r | ) | [inline] |
void VSVR::set_draw_axes | ( | bool | r | ) | [inline] |
void VSVR::set_draw_grid | ( | bool | r | ) | [inline] |
void VSVR::force_reload | ( | ) | [inline] |
const int VSVR::tex_ni | ( | ) | const [inline] |
accesses the width of the 3D texture
References _tex_ni.
Referenced by display(), draw_grid(), gl_clip(), gl_redisplay(), tex_glload(), and tex_rescale().
const int VSVR::tex_nj | ( | ) | const [inline] |
accesses the depth of the 3D texture
References _tex_nj.
Referenced by display(), draw_grid(), gl_clip(), gl_redisplay(), tex_glload(), and tex_rescale().
const int VSVR::tex_nk | ( | ) | const [inline] |
accesses the height of the 3D texture
References _tex_nk.
Referenced by display(), draw_grid(), gl_clip(), gl_redisplay(), tex_glload(), and tex_rescale().
bool VSVR::tex_set_dimensions | ( | const int | tex_ni, | |
const int | tex_nj, | |||
const int | tex_nk | |||
) |
changes the size of the 3D texture
tex_ni | width of the 3D texture (must be a power of 2) | |
tex_nj | depth of the 3D texture (must be a power of 2) | |
tex_nk | height of the 3D texture (must be a power of 2) |
References _tex_ni, _tex_nj, _tex_nk, and get_max_texture_size().
Referenced by main().
void VSVR::set_world_dimensions | ( | float | xmin, | |
float | xmax, | |||
float | ymin, | |||
float | ymax, | |||
float | zmin, | |||
float | zmax | |||
) | [inline] |
void VSVR::set_axes_dimensions | ( | float | xmin, | |
float | xmax, | |||
float | ymin, | |||
float | ymax, | |||
float | zmin, | |||
float | zmax | |||
) | [inline] |
int VSVR::get_max_texture_size | ( | ) | [inline] |
return the maximum size of a texture in any dimension.
Referenced by tex_set_dimensions().
void VSVR::tex_set_extern | ( | float * | tex | ) | [inline] |
selects to use a 3D texture allocated from another class
tex | is the pointer to the external 3D texture, allocated as a tex_ni*tex_nj*tex_nk vector running in i first. Its values will be rescaled. |
References _rescale, _tex, _tex_extern, and tex_free().
Referenced by main().
void VSVR::tex_set_intern | ( | ) | [inline] |
selects to allocate the 3D texture
References _rescale, _tex, and _tex_extern.
void VSVR::tex_alloc | ( | ) | [inline] |
allocates the 3D texture
References _tex, _tex_ni, _tex_nj, _tex_nk, and tex_free().
void VSVR::tex_free | ( | ) | [inline] |
frees the 3D texture
References _tex, and _tex_extern.
Referenced by tex_alloc(), tex_set_extern(), and ~VSVR().
void VSVR::tex_set_rescale | ( | bool | r | ) | [inline] |
const float VSVR::tex_get | ( | const int | i, | |
const int | j, | |||
const int | k | |||
) | const [inline] |
void VSVR::tex_set | ( | const int | i, | |
const int | j, | |||
const int | k, | |||
const float | val | |||
) | [inline] |
void VSVR::tex_set_minmax | ( | float | tmin, | |
float | tmax | |||
) | [inline] |
const int VSVR::tf_size | ( | ) | const [inline] |
accesses the size of the transfer function
References _tf_size.
Referenced by display(), draw_transfer(), load_default_tf(), load_greyscale_tf(), main(), rescale_data(), tex_rescale(), tf_get(), tf_glload(), and tf_set().
void VSVR::tf_set_size | ( | const int | tf_size | ) | [inline] |
changes the size of the transfer function
tf_size | size of the transfer function |
References _rescale, and _tf_size.
Referenced by load_default_tf(), and load_greyscale_tf().
void VSVR::tf_set_extern | ( | float * | tf | ) | [inline] |
selects to use a transfer function allocated from another class
tf | is the pointer to the external data, allocated as a size_x*size_y*size_z vector running in x first |
References _tf, _tf_extern, and tf_free().
void VSVR::tf_set_intern | ( | ) | [inline] |
selects to allocate the transfer function
References _tf, and _tf_extern.
Referenced by load_default_tf(), and load_greyscale_tf().
void VSVR::tf_alloc | ( | ) | [inline] |
allocates the transfer function
References _tf, _tf_size, and tf_free().
Referenced by load_default_tf(), and load_greyscale_tf().
void VSVR::tf_free | ( | ) | [inline] |
frees the transfer function
References _tf, and _tf_extern.
Referenced by tf_alloc(), tf_set_extern(), and ~VSVR().
void VSVR::load_default_tf | ( | ) |
load a default transfer function
References _opacity, a, color_winter, tf_alloc(), tf_set(), tf_set_intern(), tf_set_size(), and tf_size().
Referenced by keyboard(), and main().
void VSVR::load_greyscale_tf | ( | ) |
References _opacity, a, g, tf_alloc(), tf_set(), tf_set_intern(), tf_set_size(), and tf_size().
Referenced by keyboard(), and main().
void VSVR::set_opacity | ( | float | opacity | ) | [inline] |
void VSVR::tf_get | ( | const int | i, | |
float & | r, | |||
float & | g, | |||
float &245. | 7, | |||
float &442. | 2 | |||
) | const [inline] |
accesses a specific element of the transfer function
i | element index | |
r | returned red component of the color map | |
g | returned green component of the color map | |
b | returned blue component of the color map | |
a | returned transparency of the color map |
References _tf, and tf_size().
Referenced by draw_transfer().
void VSVR::tf_set | ( | const int | i, | |
const float | r, | |||
const float | g, | |||
const float 245. | 7, | |||
const float 442. | 2 | |||
) | [inline] |
sets a specific element of the transfer function
i | element index | |
r | red component of the color map | |
g | green component of the color map | |
b | blue component of the color map | |
a | transparency of the color map |
References _tf, and tf_size().
Referenced by load_default_tf(), and load_greyscale_tf().
bool VSVR::gl_render | ( | int | nslices = 512 |
) | [protected] |
loads the texture and renders
nslices | number of slices cut into the texture | |
opacity | factor to apply to the transfer function |
References _rescale, _tex, _tf, gl_redisplay(), tex_glload(), tex_rescale(), and tf_glload().
Referenced by display().
bool VSVR::gl_redisplay | ( | int | nslices = 512 |
) | const [protected] |
redisplay the texture with the current setting (possibly a different viewpoint)
nslices | number of slices cut into the texture |
References _tex, _tf, gl_clip(), gl_set(), gl_unclip(), gl_unset(), tex_ni(), tex_nj(), and tex_nk().
Referenced by display(), and gl_render().
int VSVR::tex_glid | ( | ) | const [inline, protected] |
accesses the texture name
References _tex_glid.
float VSVR::wcs_x_to_plot | ( | const float | x | ) | const [inline, protected] |
References _xmax, _xmax_wcs, _xmin, and _xmin_wcs.
Referenced by draw_axes_labels().
float VSVR::wcs_y_to_plot | ( | const float | y | ) | const [inline, protected] |
References _ymax, _ymax_wcs, _ymin, and _ymin_wcs.
Referenced by draw_axes_labels().
float VSVR::wcs_z_to_plot | ( | const float | z | ) | const [inline, protected] |
References _zmax, _zmax_wcs, _zmin, and _zmin_wcs.
Referenced by draw_axes_labels().
void VSVR::gl_string | ( | const float | x, | |
const float | y, | |||
const float | z, | |||
char * | text | |||
) | const [protected] |
Draw a string at a given coordinate
Referenced by draw_axes_labels().
float VSVR::suggest_axis_ticks | ( | float | fmin, | |
float | fmax, | |||
float * | f0 | |||
) | const [protected] |
Make a reasonable suggestion for tick-mark spacing
Referenced by draw_axes_labels().
void VSVR::draw_transfer | ( | ) | const [protected] |
void VSVR::draw_axes | ( | ) | const [protected] |
void VSVR::draw_axes_labels | ( | ) | const [protected] |
draw the axis ticksmakrs and labels
References _xmax, _xmax_wcs, _xmin, _xmin_wcs, _ymax, _ymax_wcs, _ymin, _ymin_wcs, _zmax, _zmax_wcs, _zmin_wcs, gl_string(), suggest_axis_ticks(), wcs_x_to_plot(), wcs_y_to_plot(), and wcs_z_to_plot().
Referenced by draw_axes().
void VSVR::draw_grid | ( | float * | viewer | ) | const [protected] |
void VSVR::draw_cube_grid | ( | const float | p0[3], | |
const float | p1[3], | |||
const float | p2[3], | |||
const float | p3[3], | |||
int | g1, | |||
int | g2 | |||
) | const [protected] |
Referenced by draw_grid().
void VSVR::tex_rescale | ( | ) | [protected] |
int VSVR::tex_glload | ( | ) | [protected] |
loads the 3D texture
References _tex, _tex_glid, tex_glunload(), tex_ni(), tex_nj(), and tex_nk().
Referenced by gl_render().
int VSVR::tf_glload | ( | ) | const [protected] |
loads the transfer function
opacity | factor to apply to the transfer function |
References _tf, and tf_size().
Referenced by gl_render().
void VSVR::tex_glunload | ( | ) | [protected] |
void VSVR::tf_glunload | ( | ) | const [protected] |
unloads the transfer function
Referenced by ~VSVR().
void VSVR::gl_set | ( | ) | const [protected] |
sets the openGL attributes
Referenced by gl_redisplay().
void VSVR::gl_unset | ( | ) | const [protected] |
unsets the openGL attributes
Referenced by gl_redisplay().
void VSVR::gl_clip | ( | ) | const [protected] |
sets the clipping planes (uses the 6 first)
References tex_ni(), tex_nj(), and tex_nk().
Referenced by gl_redisplay().
void VSVR::gl_unclip | ( | ) | const [protected] |
unsets the clipping planes
Referenced by gl_redisplay().
bool VSVR::_tex_extern [protected] |
selects wether to allocate the 3D texture or to use one allocated from another class
Referenced by tex_free(), tex_set_extern(), and tex_set_intern().
int VSVR::_tex_ni [protected] |
width of the 3D texture (must be a power of 2)
Referenced by tex_alloc(), tex_get(), tex_ni(), tex_set(), and tex_set_dimensions().
int VSVR::_tex_nj [protected] |
depth of the 3D texture (must be a power of 2)
Referenced by tex_alloc(), tex_get(), tex_nj(), tex_set(), and tex_set_dimensions().
int VSVR::_tex_nk [protected] |
height of the 3D texture (must be a power of 2)
Referenced by tex_alloc(), tex_nk(), and tex_set_dimensions().
float* VSVR::_tex [protected] |
the 3D texture : grid of float values
Referenced by gl_redisplay(), gl_render(), tex_alloc(), tex_free(), tex_get(), tex_glload(), tex_rescale(), tex_set(), tex_set_extern(), tex_set_intern(), and ~VSVR().
float VSVR::_tex_min [protected] |
rescale the texture data to from this interval to [0,1). Defaults to minimum of data
Referenced by tex_rescale(), and tex_set_minmax().
float VSVR::_tex_max [protected] |
rescale the texture data to from this interval to [0,1) Defaults to maximum of data
Referenced by tex_rescale(), and tex_set_minmax().
bool VSVR::_tf_extern [protected] |
selects wether to allocate the transfer function or to use one allocated from another class
Referenced by tf_free(), tf_set_extern(), and tf_set_intern().
int VSVR::_tf_size [protected] |
size of the transfer function
Referenced by tf_alloc(), tf_set_size(), and tf_size().
float* VSVR::_tf [protected] |
the transfer function : colormap with 4 floats (rgba) per color
Referenced by gl_redisplay(), gl_render(), tf_alloc(), tf_free(), tf_get(), tf_glload(), tf_set(), tf_set_extern(), and tf_set_intern().
float VSVR::_opacity [protected] |
the global opacity
Referenced by load_default_tf(), load_greyscale_tf(), and set_opacity().
bool VSVR::_draw_axes [protected] |
show the coordinate axes
Referenced by display(), and set_draw_axes().
bool VSVR::_draw_grid [protected] |
show the grid
Referenced by display(), and set_draw_grid().
bool VSVR::_draw_tf [protected] |
show a colorbar
Referenced by display(), and set_draw_tf().
float VSVR::_xmin [protected] |
Referenced by display(), draw_axes(), draw_axes_labels(), draw_grid(), set_world_dimensions(), VSVR(), and wcs_x_to_plot().
float VSVR::_xmax [protected] |
boundaries of the cube in opengl coordinates
Referenced by display(), draw_axes(), draw_axes_labels(), draw_grid(), set_world_dimensions(), VSVR(), and wcs_x_to_plot().
float VSVR::_ymin [protected] |
Referenced by display(), draw_axes(), draw_axes_labels(), draw_grid(), set_world_dimensions(), VSVR(), and wcs_y_to_plot().
float VSVR::_ymax [protected] |
boundaries of the cube in opengl coordinates
Referenced by display(), draw_axes(), draw_axes_labels(), draw_grid(), set_world_dimensions(), VSVR(), and wcs_y_to_plot().
float VSVR::_zmin [protected] |
Referenced by display(), draw_axes(), draw_grid(), set_world_dimensions(), VSVR(), and wcs_z_to_plot().
float VSVR::_zmax [protected] |
boundaries of the cube in opengl coordinates
Referenced by display(), draw_axes(), draw_axes_labels(), draw_grid(), set_world_dimensions(), VSVR(), and wcs_z_to_plot().
bool VSVR::_force_reload [protected] |
need to reload the texture?
Referenced by display(), and force_reload().
float VSVR::_xmin_wcs [protected] |
Referenced by draw_axes_labels(), set_axes_dimensions(), VSVR(), and wcs_x_to_plot().
float VSVR::_xmax_wcs [protected] |
boundaries of the cube in physical coordinates (for drawing axis labels)
Referenced by draw_axes_labels(), set_axes_dimensions(), VSVR(), and wcs_x_to_plot().
float VSVR::_ymin_wcs [protected] |
Referenced by draw_axes_labels(), set_axes_dimensions(), VSVR(), and wcs_y_to_plot().
float VSVR::_ymax_wcs [protected] |
boundaries of the cube in physical coordinates (for drawing axis labels)
Referenced by draw_axes_labels(), set_axes_dimensions(), VSVR(), and wcs_y_to_plot().
float VSVR::_zmin_wcs [protected] |
Referenced by draw_axes_labels(), set_axes_dimensions(), VSVR(), and wcs_z_to_plot().
float VSVR::_zmax_wcs [protected] |
boundaries of the cube in physical coordinates (for drawing axis labels)
Referenced by draw_axes_labels(), set_axes_dimensions(), VSVR(), and wcs_z_to_plot().
bool VSVR::_rescale [private] |
needs to rescale
Referenced by gl_render(), tex_rescale(), tex_set_extern(), tex_set_intern(), tex_set_rescale(), and tf_set_size().
unsigned int VSVR::_tex_glid [private] |
openGL texture name
Referenced by tex_glid(), tex_glload(), and tex_glunload().