cgv
Loading...
Searching...
No Matches
cgv::render::volume_renderer Class Reference

renderer that supports point splatting More...

#include <volume_renderer.h>

Inheritance diagram for cgv::render::volume_renderer:
cgv::render::renderer

Public Member Functions

 volume_renderer ()
 initializes position_is_center to true
 
bool init (context &ctx)
 construct shader programs and return whether this was successful, call inside of init method of drawable
 
virtual void clear (const context &ctx)
 clean up
 
bool set_volume_texture (texture *tex)
 sets the 3D volume texture containing scalar values (density or other measured quantities)
 
bool set_transfer_function_texture (texture *tex)
 sets the transfer function used for classification; must be 1D or 2D (as loaded from an image)
 
bool set_gradient_texture (texture *tex)
 sets the gradient texture used for lighting
 
bool set_depth_texture (texture *tex)
 sets the depth texture needed for rendering with additional opaque geometry
 
void set_bounding_box (const box3 &bbox)
 
void transform_to_bounding_box (bool flag)
 
void set_noise_offset (const vec2 &offset)
 
bool enable (context &ctx)
 enables renderer
 
bool validate_attributes (const context &ctx) const
 call to validate, whether essential position attribute is defined
 
bool disable (context &ctx)
 disable renderer
 
void draw (context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
 Draw a range of vertices or indexed elements.
 
- Public Member Functions inherited from cgv::render::renderer
shader_define_mapref_defines ()
 access to shader define map to update defines not handled by render style
 
shader_programref_prog ()
 derived renderer classes have access to shader program
 
void set_prog (shader_program &one_shot_prog)
 set external shader program up to next call to disable() or render()
 
void draw_impl (context &ctx, PrimitiveType pt, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
 default implementation of draw method with support for indexed rendering and different primitive types
 
void draw_impl_instanced (context &ctx, PrimitiveType type, size_t start, size_t count, size_t instance_count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
 default implementation of instanced draw method with support for indexed rendering and different primitive types
 
 renderer ()
 construct and init attribute tracking flags
 
virtual ~renderer ()
 destructor deletes default renderer style
 
void manage_singleton (context &ctx, const std::string &renderer_name, int &ref_count, int ref_count_change)
 used by derived classes to manage singletons
 
virtual void enable_attribute_array_manager (const context &ctx, attribute_array_manager &aam)
 call this before setting attribute arrays to manage attribute array in given manager
 
virtual void disable_attribute_array_manager (const context &ctx, attribute_array_manager &aam)
 call this after last render/draw call to ensure that no other users of renderer change attribute arrays of given manager
 
virtual void set_attribute_array_manager (const context &ctx, attribute_array_manager *_aam_ptr=0)
 this function is deprecated, please use enable_attribute_array_manager() and disable_attribute_manager() instead
 
void set_render_style (const render_style &rs)
 reference given render style
 
bool build_program (context &ctx, shader_program &prog, const render_style &rs)
 build shader program for specific render style
 
template<typename T >
void set_position (const context &ctx, const T &position)
 templated method to set the position attribute from a single position of type T
 
template<typename T >
void set_position_array (const context &ctx, const std::vector< T > &positions)
 templated method to set the position attribute from a vector of positions of type T
 
template<typename T >
void set_position_array (const context &ctx, const T *positions, size_t nr_elements, unsigned stride_in_bytes=0)
 templated method to set the position attribute from a vector of positions of type T
 
void set_position_array (const context &ctx, type_descriptor element_type, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes)
 method to set the position attribute from a vertex buffer object
 
template<typename T >
void set_position_array (const context &ctx, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
 template method to set the position attribute from a vertex buffer object, the element type must be given as explicit template parameter
 
void remove_position_array (const context &ctx)
 remove the position attribute
 
template<typename T >
void set_color (const context &ctx, const T &color)
 templated method to set the color attribute from a single color of type T
 
template<typename T >
void set_color_array (const context &ctx, const std::vector< T > &colors)
 template method to set the color attribute from a vector of colors of type T
 
template<typename T >
void set_color_array (const context &ctx, const T *colors, size_t nr_elements, unsigned stride_in_bytes=0)
 template method to set the color attribute from a vector of colors of type T
 
void set_color_array (const context &ctx, type_descriptor element_type, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
 method to set the color attribute from a vertex buffer object, the element type must be given as explicit template parameter
 
template<typename T >
void set_color_array (const context &ctx, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes=0)
 template method to set the color attribute from a vertex buffer object, the element type must be given as explicit template parameter
 
void remove_color_array (const context &ctx)
 remove the color attribute
 
template<typename T >
bool set_indices (const context &ctx, const std::vector< T > &indices, bool keep_on_cpu=false)
 Set the indices for indexed rendering from a vector.
 
template<typename T >
bool set_indices (const context &ctx, const T *indices, size_t nr_indices, bool keep_on_cpu=false)
 Set the indices for indexed rendering from an array given as a pointer.
 
template<typename T >
bool set_indices (const context &ctx, const vertex_buffer &vbo, size_t count)
 Set the indices for indexed rendering from a GPU buffer.
 
bool has_indices () const
 return whether indices have been defined
 
void remove_indices (const context &ctx)
 remove previously set indices
 
const vertex_bufferget_vertex_buffer_ptr (const context &ctx, const attribute_array_manager &aam, const std::string &attr_name)
 
const vertex_bufferget_index_buffer_ptr (const attribute_array_manager &aam)
 
bool validate_and_enable (context &ctx)
 validate attributes and if successful, enable renderer
 
virtual bool render (context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
 Convenience function that draws vertex or indexed element with this renderer.
 

Protected Member Functions

render_stylecreate_render_style () const
 overload to allow instantiation of volume_renderer
 
void update_defines (shader_define_map &defines)
 update shader defines based on render style
 
bool build_shader_program (context &ctx, shader_program &prog, const shader_define_map &defines)
 build volume program
 
void init_noise_texture (context &ctx)
 initializes the noise texture with random values
 
- Protected Member Functions inherited from cgv::render::renderer
bool has_aam () const
 check for attribute array manager
 
bool has_attribute (const context &ctx, const std::string &name)
 check for attribute
 
const render_styleget_style_ptr () const
 access to render style
 
bool attributes_persist () const
 return whether attributes persist after a call to disable
 
template<typename T >
const T & get_style () const
 access to style
 
int get_prog_attribute_location (const context &ctx, const std::string &name, bool error_check=true)
 
template<typename T >
bool set_attribute_array (const context &ctx, const std::string &name, const T &array)
 
template<typename T >
bool set_attribute_array (const context &ctx, const std::string &name, const T *array_ptr, size_t nr_elements, unsigned stride)
 
bool set_attribute_array (const context &ctx, const std::string &name, type_descriptor element_type, const vertex_buffer &vbo, size_t offset_in_bytes, size_t nr_elements, unsigned stride_in_bytes)
 
template<typename C , typename T >
bool set_composed_attribute_array (const context &ctx, const std::string &name, const C *array_ptr, size_t nr_elements, const T &elem)
 in case that several attributes are stored interleaved, call this function for the first and ref_composed_attribute_array() for all others
 
template<typename C , typename T >
bool ref_composed_attribute_array (const context &ctx, const std::string &name, const std::string &name_ref, const C *array_ptr, size_t nr_elements, const T &elem)
 in case that several attributes are stored interleaved, call set_composed_attribute_array() for the first and this function for all others
 
bool remove_attribute_array (const context &ctx, const std::string &name)
 

Protected Attributes

texturevolume_texture
 the 3D texture used for rendering
 
texturetransfer_function_texture
 the 2D transfer function texture used for classification of the volume values
 
texture noise_texture
 a 2D texture containing random noise used to offset ray start positions in order to reduce ring artifacts
 
texturegradient_texture
 the 3D texture containing vector gradients used for lighting normal calculation
 
texturedepth_texture
 a 2D texture from a frame buffer depth buffer used to combine volume rendering with opaque geometry
 
box3 bounding_box
 the bounding box of the volume in scene units
 
bool apply_bounding_box_transformation
 whether to translate and scale the volume to the given bounding box during rendering
 
vec2 noise_offset
 offset applied to the noise texture (can be used in conjunction with temporal anti aliasing)
 
- Protected Attributes inherited from cgv::render::renderer
bool has_colors
 track whether color attribute is defined
 
bool has_positions
 track whether position attribute is defined
 

Detailed Description

renderer that supports point splatting

Definition at line 116 of file volume_renderer.h.

Constructor & Destructor Documentation

◆ volume_renderer()

Member Function Documentation

◆ build_shader_program()

bool cgv::render::volume_renderer::build_shader_program ( context ctx,
shader_program prog,
const shader_define_map defines 
)
protectedvirtual

build volume program

Reimplemented from cgv::render::renderer.

Definition at line 108 of file volume_renderer.cxx.

References cgv::render::shader_program::build_program().

◆ clear()

void cgv::render::volume_renderer::clear ( const context ctx)
virtual

◆ create_render_style()

render_style * cgv::render::volume_renderer::create_render_style ( ) const
protectedvirtual

overload to allow instantiation of volume_renderer

Implements cgv::render::renderer.

Definition at line 22 of file volume_renderer.cxx.

◆ disable()

◆ draw()

void cgv::render::volume_renderer::draw ( context ctx,
size_t  start,
size_t  count,
bool  use_strips = false,
bool  use_adjacency = false,
uint32_t  strip_restart_index = -1 
)
virtual

Draw a range of vertices or indexed elements.

Call this function only successful enabeling via validate_and_enable() or enable(). Capsulates glDrawArrays and glDrawElements calls. Overloaded implementations of specific renderers choose the to be used gl primitive type and whether to use an instanced draw call.

See also
render()
Parameters
countnumber of to be drawn vertices/elements
startindex of first to be drawn vertex/element
use_stripswhether to generate primitives in strips (only for line or triangle primitives)
use_adjacencywhether to specify adjacency information (only for line or triangle primitives)
strip_restart_indexextraorindary index used to mark end of strips (only for strip based drawing) Strip based drawing can be combined with the use of adjacency information. Default implementation uses triangle primitives.

Reimplemented from cgv::render::renderer.

Definition at line 277 of file volume_renderer.cxx.

References apply_bounding_box_transformation, bounding_box, cgv::render::volume_render_style::clip_box, cgv::media::axis_aligned_box< T, N >::get_center(), cgv::media::axis_aligned_box< T, N >::get_extent(), cgv::media::axis_aligned_box< T, N >::get_max_pnt(), cgv::media::axis_aligned_box< T, N >::get_min_pnt(), cgv::render::context::mul_modelview_matrix(), cgv::render::context::pop_modelview_matrix(), and cgv::render::context::push_modelview_matrix().

◆ enable()

bool cgv::render::volume_renderer::enable ( context ctx)
virtual

enables renderer

if internal program is used, first update defines with update_defines() and rebuild program if it changed due updating or external modification via ref_defines()

Reimplemented from cgv::render::renderer.

Definition at line 213 of file volume_renderer.cxx.

References cgv::render::volume_render_style::ambient_strength, cgv::render::volume_render_style::clip_box, depth_texture, cgv::render::volume_render_style::diffuse_strength, cgv::render::context::disable_depth_test(), cgv::render::texture::enable(), cgv::render::renderer::enable(), cgv::render::context::enable_blending(), cgv::media::axis_aligned_box< T, N >::get_max_pnt(), cgv::media::axis_aligned_box< T, N >::get_min_pnt(), cgv::render::volume_render_style::gradient_lambda, gradient_texture, cgv::render::volume_render_style::isosurface_color, cgv::render::volume_render_style::isovalue, cgv::render::volume_render_style::light_direction, cgv::render::volume_render_style::light_local_to_eye, noise_offset, noise_texture, cgv::render::context::push_blend_state(), cgv::render::context::push_cull_state(), cgv::render::context::push_depth_test_state(), cgv::render::renderer::ref_prog(), cgv::render::volume_render_style::roughness, cgv::render::volume_render_style::scale_adjustment_factor, cgv::render::context::set_blend_func_back_to_front(), cgv::render::context::set_cull_state(), cgv::render::shader_program::set_uniform(), cgv::render::volume_render_style::slice_axis, cgv::render::volume_render_style::slice_coordinate, cgv::render::volume_render_style::slice_opacity, cgv::render::volume_render_style::specular_color_mix, cgv::render::volume_render_style::specular_strength, transfer_function_texture, and volume_texture.

◆ init()

bool cgv::render::volume_renderer::init ( context ctx)
virtual

construct shader programs and return whether this was successful, call inside of init method of drawable

Reimplemented from cgv::render::renderer.

Definition at line 133 of file volume_renderer.cxx.

References cgv::render::renderer::enable_attribute_array_manager(), cgv::render::renderer::init(), init_noise_texture(), cgv::render::render_component::is_created(), noise_texture, and cgv::render::renderer::set_position_array().

◆ init_noise_texture()

void cgv::render::volume_renderer::init_noise_texture ( context ctx)
protected

◆ set_bounding_box()

void cgv::render::volume_renderer::set_bounding_box ( const box3 bbox)

Definition at line 198 of file volume_renderer.cxx.

◆ set_depth_texture()

bool cgv::render::volume_renderer::set_depth_texture ( texture tex)

sets the depth texture needed for rendering with additional opaque geometry

Definition at line 191 of file volume_renderer.cxx.

References depth_texture, and cgv::data::data_format::get_nr_dimensions().

◆ set_gradient_texture()

bool cgv::render::volume_renderer::set_gradient_texture ( texture tex)

sets the gradient texture used for lighting

Definition at line 184 of file volume_renderer.cxx.

References cgv::data::data_format::get_nr_dimensions(), and gradient_texture.

◆ set_noise_offset()

void cgv::render::volume_renderer::set_noise_offset ( const vec2 offset)

Definition at line 208 of file volume_renderer.cxx.

◆ set_transfer_function_texture()

bool cgv::render::volume_renderer::set_transfer_function_texture ( texture tex)

sets the transfer function used for classification; must be 1D or 2D (as loaded from an image)

Definition at line 177 of file volume_renderer.cxx.

References cgv::data::data_format::get_nr_dimensions(), and transfer_function_texture.

◆ set_volume_texture()

bool cgv::render::volume_renderer::set_volume_texture ( texture tex)

sets the 3D volume texture containing scalar values (density or other measured quantities)

Definition at line 170 of file volume_renderer.cxx.

References cgv::data::data_format::get_nr_dimensions(), and volume_texture.

◆ transform_to_bounding_box()

void cgv::render::volume_renderer::transform_to_bounding_box ( bool  flag)

Definition at line 203 of file volume_renderer.cxx.

◆ update_defines()

◆ validate_attributes()

bool cgv::render::volume_renderer::validate_attributes ( const context ctx) const
virtual

call to validate, whether essential position attribute is defined

Reimplemented from cgv::render::renderer.

Definition at line 100 of file volume_renderer.cxx.

References cgv::render::renderer::validate_attributes(), and volume_texture.

Member Data Documentation

◆ apply_bounding_box_transformation

bool cgv::render::volume_renderer::apply_bounding_box_transformation
protected

whether to translate and scale the volume to the given bounding box during rendering

Definition at line 135 of file volume_renderer.h.

Referenced by draw(), and volume_renderer().

◆ bounding_box

box3 cgv::render::volume_renderer::bounding_box
protected

the bounding box of the volume in scene units

Definition at line 133 of file volume_renderer.h.

Referenced by draw(), and volume_renderer().

◆ depth_texture

texture* cgv::render::volume_renderer::depth_texture
protected

a 2D texture from a frame buffer depth buffer used to combine volume rendering with opaque geometry

Definition at line 131 of file volume_renderer.h.

Referenced by disable(), enable(), set_depth_texture(), and volume_renderer().

◆ gradient_texture

texture* cgv::render::volume_renderer::gradient_texture
protected

the 3D texture containing vector gradients used for lighting normal calculation

Definition at line 129 of file volume_renderer.h.

Referenced by disable(), enable(), set_gradient_texture(), and volume_renderer().

◆ noise_offset

vec2 cgv::render::volume_renderer::noise_offset
protected

offset applied to the noise texture (can be used in conjunction with temporal anti aliasing)

Definition at line 137 of file volume_renderer.h.

Referenced by enable(), and volume_renderer().

◆ noise_texture

texture cgv::render::volume_renderer::noise_texture
protected

a 2D texture containing random noise used to offset ray start positions in order to reduce ring artifacts

Definition at line 127 of file volume_renderer.h.

Referenced by clear(), disable(), enable(), init(), init_noise_texture(), and volume_renderer().

◆ transfer_function_texture

texture* cgv::render::volume_renderer::transfer_function_texture
protected

the 2D transfer function texture used for classification of the volume values

Definition at line 125 of file volume_renderer.h.

Referenced by disable(), enable(), set_transfer_function_texture(), update_defines(), and volume_renderer().

◆ volume_texture

texture* cgv::render::volume_renderer::volume_texture
protected

the 3D texture used for rendering

Definition at line 123 of file volume_renderer.h.

Referenced by disable(), enable(), set_volume_texture(), validate_attributes(), and volume_renderer().


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