zMol
A viewer for molecular data using OpenGL and ambient occlusion
Public Types | Public Member Functions
zmol::molecule_renderer Class Reference

#include <molecule_renderer.hpp>

Inherits zmol::noncopyable_::noncopyable.

List of all members.

Public Types

enum  rendering_modes { rendering_mode_space_filling, rendering_mode_balls_and_sticks, rendering_mode_licorice }
enum  atom_color_modes { atom_color_mode_per_element, atom_color_mode_per_chain }
typedef cml::matrix44f_c matrix

Public Member Functions

 molecule_renderer (molecule_shaders &p_molecule_shaders, molecule_data const &p_data, unsigned int const p_initial_left_viewport_offset, unsigned int const p_initial_top_viewport_offset, unsigned int const p_initial_viewport_width, unsigned int const p_initial_viewport_height, unsigned int const p_initial_atlas_size, float const p_initial_radius_scale=1.0f, rendering_modes const p_initial_rendering_mode=rendering_mode_space_filling, atom_color_modes const p_initial_atom_color_mode=atom_color_mode_per_element)
 molecule_renderer (molecule_shaders &p_molecule_shaders, molecule_data &&p_data, unsigned int const p_initial_left_viewport_offset, unsigned int const p_initial_top_viewport_offset, unsigned int const p_initial_viewport_width, unsigned int const p_initial_viewport_height, unsigned int const p_initial_atlas_size, float const p_initial_radius_scale=1.0f, rendering_modes const p_initial_rendering_mode=rendering_mode_space_filling, atom_color_modes const p_initial_atom_color_mode=atom_color_mode_per_element)
void set_rendering_mode (rendering_modes const p_new_rendering_mode)
void set_atom_color_mode (atom_color_modes const p_new_atom_color_mode)
void set_viewport (unsigned int const p_new_left_viewport_offset, unsigned int const p_new_top_viewport_offset, unsigned int const p_new_viewport_width, unsigned int const p_new_viewport_height)
void set_radius_scale (float const p_new_radius_scale)
void set_border_width (float const p_new_border_width)
void set_border_variance (float const p_new_border_variance)
void set_ao_strength (float const p_new_ao_strength)
void set_direct_lighting_strength (float const p_new_direct_lighting_strength)
void set_shininess (float const p_new_shininess)
void set_glossiness (float const p_new_glossiness)
void set_flatness (float const p_new_flatness)
void set_atlas_size (unsigned int const p_new_atlas_size)
void render (cml::quaternionf const &p_rotation)
matrix const & get_projection () const

Detailed Description

Class for rendering molecule data.

This class takes molecule_data input, creates impostor geometry data out of it, and renders said impostors. In addition, it calculates ambient occlusion, and stores the results in a texture atlas.

The renderer uses its own orthogonal projection matrix, and paints into a designated viewport region. It is not possible to use a custom projection matrix.

The class is not stateless, but mostly immutable; no other molecule_data can be passed to it after construction. Certain parameters, such as the atlas texture size, the screen size, the rendering mode, are mutable.


Member Typedef Documentation

typedef cml::matrix44f_c zmol::molecule_renderer::matrix

4x4 matrix type.


Member Enumeration Documentation

Atom color modes, defining how each atom is colored.

Enumerator:
atom_color_mode_per_element 

Color atoms by their individual element

atom_color_mode_per_chain 

Color atoms by the chain they belong to

Rendering modes.

Enumerator:
rendering_mode_space_filling 

Space-filling rendering mode: Atoms are drawn as spheres. Their radius depends on the atomic element. Bonds are not rendered.

rendering_mode_balls_and_sticks 

Balls-and-sticks rendering mode: Atoms are drawn as spheres. Bonds are drawn as cylinders. All cylinders use the same radius. Compared to space-filling, the spheres are smaller.

rendering_mode_licorice 

Licorice rendering mode: Similar to balls-and-sticks, but the spheres' radius equals the cylinder's.


Constructor & Destructor Documentation

zmol::molecule_renderer::molecule_renderer ( molecule_shaders p_molecule_shaders,
molecule_data const &  p_data,
unsigned int const  p_initial_left_viewport_offset,
unsigned int const  p_initial_top_viewport_offset,
unsigned int const  p_initial_viewport_width,
unsigned int const  p_initial_viewport_height,
unsigned int const  p_initial_atlas_size,
float const  p_initial_radius_scale = 1.0f,
rendering_modes const  p_initial_rendering_mode = rendering_mode_space_filling,
atom_color_modes const  p_initial_atom_color_mode = atom_color_mode_per_element 
)
explicit

Constructor.

Creates the impostor geometry out of the molecule structure information described by p_data, sets the initial viewport, and calculates the ambient occlusion, whose results are stored in a texture atlas. It uses a molecule_data instance as input. The molecule_data structure referred to by p_data is copied internally, so the referred structure can be destroyed safely after the constructor was executed.

Note:
Unlike p_data, the instance referred to by p_molecule_shaders is not copied internally, only a reference is kept around. Do not destroy it before this molecule_renderer is!
The constructor expects a valid OpenGL context to be initialized already, and invokes OpenGL functions. If no OpenGL context exists, the behavior is undefined (it will most likely crash).
Parameters:
p_molecule_shadersShaders structure to use for rendering
p_dataInput molecule data; an internal copy of it is made by the constructor
p_initial_left_viewport_offsetInitial left viewport offset
p_initial_top_viewport_offsetInitial top viewport offset
p_initial_viewport_widthInitial viewport width
p_initial_viewport_heightInitial viewport height
p_initial_atlas_sizeInitial texture atlas size (= sidelength; the atlas texture is always a square)
p_initial_radius_scaleInitial molecule scale, default value 1.0f (= 100%)
p_initial_rendering_modeInitial rendering mode, default mode is rendering_mode_space_filling
p_initial_atom_color_modeInitial color mode, default mode is atom_color_mode_per_element
zmol::molecule_renderer::molecule_renderer ( molecule_shaders p_molecule_shaders,
molecule_data &&  p_data,
unsigned int const  p_initial_left_viewport_offset,
unsigned int const  p_initial_top_viewport_offset,
unsigned int const  p_initial_viewport_width,
unsigned int const  p_initial_viewport_height,
unsigned int const  p_initial_atlas_size,
float const  p_initial_radius_scale = 1.0f,
rendering_modes const  p_initial_rendering_mode = rendering_mode_space_filling,
atom_color_modes const  p_initial_atom_color_mode = atom_color_mode_per_element 
)
explicit

Constructor.

Creates the impostor geometry out of the molecule structure information described by p_data, sets the initial viewport, and calculates the ambient occlusion, whose results are stored in a texture atlas. It uses a molecule_data instance as input. The molecule_data structure referred to by p_data is moved to an internal instance; after the constructor ran, do not use the referred to by p_data anymore.

Note:
Unlike p_data, the instance referred to by p_molecule_shaders is not moved to an internal instance, only a reference is kept around. Do not destroy it before this molecule_renderer is!
The constructor expects a valid OpenGL context to be initialized already, and invokes OpenGL functions. If no OpenGL context exists, the behavior is undefined (it will most likely crash).
Parameters:
p_molecule_shadersShaders structure to use for rendering
p_dataInput molecule data; its contents are moved to an internal molecule_data instance (see C++11 move semantics)
p_initial_left_viewport_offsetInitial left viewport offset
p_initial_top_viewport_offsetInitial top viewport offset
p_initial_viewport_widthInitial viewport width
p_initial_viewport_heightInitial viewport height
p_initial_atlas_sizeInitial atlas texture size (= sidelength; the atlas texture is always a square)
p_initial_radius_scaleInitial molecule scale, default value 1.0f (= 100%)
p_initial_rendering_modeInitial rendering mode, default mode is rendering_mode_space_filling
p_initial_atom_color_modeInitial color mode, default mode is atom_color_mode_per_element

Member Function Documentation

matrix const& zmol::molecule_renderer::get_projection ( ) const
inline

Retrieves the current projection matrix.

Returns:
Current projection matrix
void zmol::molecule_renderer::render ( cml::quaternionf const &  p_rotation)

Renders one frame into the current viewport.

Note:
This call expects glViewport() to have been called, which is done by set_viewport. If glViewport is called by some other code, make sure the viewport is set back to the original values, otherwise the rendering might not be correct.
Parameters:
p_rotationRotation quaternion to use as the molecule rendering's rotation.
void zmol::molecule_renderer::set_ao_strength ( float const  p_new_ao_strength)

Sets the ambient occlusion strength.

Parameters:
p_new_ao_strengthThe new ambient occlusion strength to use.
void zmol::molecule_renderer::set_atlas_size ( unsigned int const  p_new_atlas_size)

Sets the atlas texture size.

Parameters:
p_new_atlas_sizeThe new atlas texture size (= sidelength; the atlas texture is always a square)
void zmol::molecule_renderer::set_atom_color_mode ( atom_color_modes const  p_new_atom_color_mode)

Sets the current atom color mode.

This call reinitialozes the impostor geometry, but does not recalculate the ambient occlusion (since it would not change). If p_new_atom_color_mode equals the currently set atom color mode, this call does nothing.

Parameters:
p_new_atom_color_modeNew atom color mode to use
void zmol::molecule_renderer::set_border_variance ( float const  p_new_border_variance)

Sets the border variance.

Parameters:
p_new_border_varianceThe new border variance to use. Minimum valid value is 0.0f.
void zmol::molecule_renderer::set_border_width ( float const  p_new_border_width)

Sets the border width.

Parameters:
p_new_border_widthThe new border width to use. Minimum valid value is 0.0f (= no border).
void zmol::molecule_renderer::set_direct_lighting_strength ( float const  p_new_direct_lighting_strength)

Sets the direct lighting strength.

Parameters:
p_new_direct_lighting_strengthThe new direct lighting strength to use.
void zmol::molecule_renderer::set_flatness ( float const  p_new_flatness)

Sets the flatness.

Parameters:
p_new_flatnessThe new flatness to use.
void zmol::molecule_renderer::set_glossiness ( float const  p_new_glossiness)

Sets the glossiness.

Parameters:
p_new_glossinessThe new glossiness to use.
void zmol::molecule_renderer::set_radius_scale ( float const  p_new_radius_scale)

Sets the radiu´s scale.

Parameters:
p_new_radius_scaleThe new relative scale to use. 1.0f means 100% (= the original radius scale).
void zmol::molecule_renderer::set_rendering_mode ( rendering_modes const  p_new_rendering_mode)

Sets the current rendering mode.

This call reinitializes the impostor geometry appropiately, and also recalculates the ambient occlusion. If p_new_rendering_mode equals the currently set rendering mode, this call does nothing.

Parameters:
p_new_rendering_modeNew rendering mode to use
void zmol::molecule_renderer::set_shininess ( float const  p_new_shininess)

Sets the shininess.

Parameters:
p_new_shininessThe new shininess to use.
void zmol::molecule_renderer::set_viewport ( unsigned int const  p_new_left_viewport_offset,
unsigned int const  p_new_top_viewport_offset,
unsigned int const  p_new_viewport_width,
unsigned int const  p_new_viewport_height 
)

Sets the current viewport.

It does not impostor geometry and ambient occlusion data intact, so it is safe to call this often, for example, when a rendering window gets resized by the user.

Parameters:
p_new_left_viewport_offsetNew left viewport offset
p_new_top_viewport_offsetNew top viewport offset
p_new_viewport_widthNew viewport width
p_new_viewport_heightNew viewport height