cgv
Loading...
Searching...
No Matches
slab_renderer.cxx
1#include "slab_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7 slab_renderer& ref_slab_renderer(context& ctx, int ref_count_change)
8 {
9 static int ref_count = 0;
10 static slab_renderer r;
11 r.manage_singleton(ctx, "slab_renderer", ref_count, ref_count_change);
12 return r;
13 }
14
19
21 {
22 thickness_scale = 1.0f;
23 tex_unit = 0;
24 tf_tex_unit = 1;
26 tf_source_channel = 0;
29 step_size = 0.02f;
30 opacity = 1.0f;
31 falloff_mix = 1.0f;
32 falloff_strength = 1.0f;
33 scale = 20.0f;
34 }
35
37 {
38 has_extents = false;
39 position_is_center = true;
40 has_translations = false;
41 has_rotations = false;
42 has_texture_indices = false;
43 }
46 {
48 if (has_attribute(ctx, "extent"))
49 has_extents = true;
50 if (has_attribute(ctx, "translation"))
51 has_translations = true;
52 if (has_attribute(ctx, "rotation"))
53 has_rotations = true;
54 if (has_attribute(ctx, "texture_index"))
56 }
66
68 void slab_renderer::set_position_is_center(bool _position_is_center)
69 {
70 position_is_center = _position_is_center;
71 }
72
74 {
75 // validate set attributes
76 const slab_render_style& srs = get_style<slab_render_style>();
78 if (!has_extents) {
79 ctx.error("slab_renderer::enable() extent attribute not set");
80 res = false;
81 }
82 return res;
83 }
86 {
87 return prog.build_program(ctx, "slab.glpr", true, defines);
88 }
91 {
92 const slab_render_style& srs = get_style<slab_render_style>();
93
94 if (!group_renderer::enable(ctx))
95 return false;
96 ref_prog().set_uniform(ctx, "position_is_center", position_is_center);
97 ref_prog().set_uniform(ctx, "has_rotations", has_rotations);
98 ref_prog().set_uniform(ctx, "has_translations", has_translations);
99 ref_prog().set_uniform(ctx, "has_texture_indices", has_texture_indices);
100 ref_prog().set_uniform(ctx, "thickness_scale", srs.thickness_scale);
101 ref_prog().set_uniform(ctx, "tex", srs.tex_unit);
102 ref_prog().set_uniform(ctx, "tf_tex", srs.tf_tex_unit);
103 ref_prog().set_uniform(ctx, "use_transfer_function", srs.use_transfer_function);
104 ref_prog().set_uniform(ctx, "tf_source_channel", srs.tf_source_channel);
105 ref_prog().set_uniform(ctx, "tex_idx_offset", srs.tex_idx_offset);
106 ref_prog().set_uniform(ctx, "tex_idx_stride", srs.tex_idx_stride);
107 ref_prog().set_uniform(ctx, "step_size", srs.step_size);
108 ref_prog().set_uniform(ctx, "opacity_scale", srs.opacity);
109 ref_prog().set_uniform(ctx, "falloff_mix", srs.falloff_mix);
110 ref_prog().set_uniform(ctx, "falloff_strength", srs.falloff_strength);
111 ref_prog().set_uniform(ctx, "scale", srs.scale);
112
113 glCullFace(GL_FRONT);
114 glEnable(GL_CULL_FACE);
115 return true;
116 }
119 {
120 if (!attributes_persist()) {
121 has_extents = false;
122 position_is_center = true;
123 has_rotations = false;
124 has_translations = false;
125 }
126
127 glDisable(GL_BLEND);
128 glDisable(GL_CULL_FACE);
129
130 return group_renderer::disable(ctx);
131 }
132
133 void slab_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
134 {
135 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
136 }
137
138 bool slab_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
139 {
140 return
141 rh.reflect_base(*static_cast<slab_render_style*>(this)) &&
142 rh.reflect_member("thickness", thickness_scale) &&
143 rh.reflect_member("tex_unit", tex_unit);
144 }
145
147 {
149 }
150 }
151}
152
153#include <cgv/gui/provider.h>
154
155namespace cgv {
156 namespace gui {
157
160 bool create(provider* p, const std::string& label,
161 void* value_ptr, const std::string& value_type,
162 const std::string& gui_type, const std::string& options, bool*) {
164 return false;
165 cgv::render::slab_render_style* srs_ptr = reinterpret_cast<cgv::render::slab_render_style*>(value_ptr);
166 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
167
168 p->add_member_control(b, "thickness scale", srs_ptr->thickness_scale, "value_slider", "min=0.001;step=0.0001;max=10.0;log=true;ticks=true");
169 p->add_member_control(b, "texture unit", srs_ptr->tex_unit, "value_slider", "min=0;step=1;max=9;log=false;ticks=true");
170 p->add_member_control(b, "transfer function unit", srs_ptr->tf_tex_unit, "value_slider", "min=0;step=1;max=9;log=false;ticks=true");
171 p->add_member_control(b, "use transfer function", srs_ptr->use_transfer_function, "check");
172 p->add_member_control(b, "tf source channel", srs_ptr->tf_source_channel, "value_slider", "min=0;step=1;max=3;log=false;ticks=true");
173
174 p->add_member_control(b, "step_size", srs_ptr->step_size, "value_slider", "min=0.001;step=0.001;max=0.5;log=true;ticks=true");
175 p->add_member_control(b, "opacity scale", srs_ptr->opacity, "value_slider", "min=0.0;step=0.0001;max=1.0;log=true;ticks=true");
176 p->add_member_control(b, "falloff mix", srs_ptr->falloff_mix, "value_slider", "min=0.0;step=0.0001;max=1.0;ticks=true");
177 p->add_member_control(b, "falloff strength", srs_ptr->falloff_strength, "value_slider", "min=0.0;step=0.0001;max=10.0;log=true;ticks=true");
178 p->add_member_control(b, "scale", srs_ptr->scale, "value_slider", "min=0.0;step=0.0001;max=100.0;log=true;ticks=true");
179
180 //p->add_gui("group_render_style", *static_cast<cgv::render::group_render_style*>(srs_ptr));
181 return true;
182 }
183 };
184
185#include "gl/lib_begin.h"
186
187 CGV_API cgv::gui::gui_creator_registration<slab_render_style_gui_creator> slab_rs_gc_reg("slab_render_style_gui_creator");
188 }
189}
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
helper template for registration of gui creators
Definition gui_creator.h:32
derive from this class to provide a gui to the current viewer
Definition provider.h:64
data::ref_ptr< control< T > > add_member_control(cgv::base::base *base_ptr, const std::string &label, T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
add control with callback to cgv::base::on_set method on cgv::gui::control::value_change
Definition provider.h:137
the self reflection handler is passed to the virtual self_reflect() method of cgv::base::base.
bool reflect_base(B &base_ref)
reflect a base class with its members
bool reflect_member(const std::string &member_name, T &member_ref, bool hard_cast=false)
call this to reflect a member by member name and reference to the member.
attribute array manager used to upload arrays to gpu
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:219
bool disable(context &ctx)
disable renderer
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
bool validate_attributes(const context &ctx) const
check additionally the group attributes
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 arra...
bool enable(context &ctx)
overload to activate group 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
Definition renderer.cxx:23
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
Definition renderer.h:60
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:75
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:66
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 type...
Definition renderer.cxx:253
a shader program combines several shader code fragments to a complete definition of the shading pipel...
bool set_uniform(const context &ctx, const std::string &name, const T &value, bool generate_error=false)
Set the value of a uniform by name, where the type can be any of int, unsigned, float,...
bool build_program(const context &ctx, const std::string &file_name, bool show_error=false, const shader_define_map &defines=shader_define_map())
successively calls create, attach_program and link.
renderer that supports point splatting
bool has_extents
store whether extent array has been specified
bool has_texture_indices
whether array with per slab texture index has been specified
render_style * create_render_style() const
overload to allow instantiation of box_renderer
bool enable(context &ctx)
overload to activate group style
bool disable(context &ctx)
disable renderer
slab_renderer()
initializes position_is_center to true
bool has_translations
whether array with per slab translations has been specified
void set_position_is_center(bool _position_is_center)
set the flag, whether the position is interpreted as the slab center, true by default
bool position_is_center
whether position is slab center, if not it is lower left bottom corner
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
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.
bool validate_attributes(const context &ctx) const
check additionally the group attributes
bool has_rotations
whether array with per slab rotations has been specified
bool build_shader_program(context &ctx, shader_program &prog, const shader_define_map &defines)
build slab program
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 arra...
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
slab_renderer & ref_slab_renderer(context &ctx, int ref_count_change)
reference to a singleton slab renderer that is shared among drawables
the cgv namespace
Definition print.h:11
interface for gui creators
Definition gui_creator.h:14
bool create(provider *p, const std::string &label, void *value_ptr, const std::string &value_type, const std::string &gui_type, const std::string &options, bool *)
attempt to create a gui and return whether this was successful
this reflection traits implementation is used for external self_reflect implementations of instances ...
base class for all render styles
Definition renderer.h:16
float falloff_mix
overall influence of the falloff
float opacity
multiplied to the input opacity value during rendering to change the overall opacity of the slabs
float falloff_strength
strength of the opacity falloff in the slabs normal direction
int tf_tex_unit
unit used to access the volume transfer function texture, initialized to 1, must be a 1d texture
float step_size
constant step size for volume ray integration over all slabs
int tex_idx_offset
used to offset the texture index of each slab when specified
float scale
compensates for the overall slab scale
int tex_unit
unit used to access the slab texture values, initialized to 0, must point to a 2d texture array
slab_render_style()
construct with default values
bool use_transfer_function
whether to use a transfer function or interpret the luminance as alpha, initialized to false
float thickness_scale
multiplied to the thickness, initialized to 1
int tex_idx_stride
multiplied to the texture index of each slab
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54