cgv
Loading...
Searching...
No Matches
surfel_renderer.cxx
1#include "surfel_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7 surfel_renderer& ref_surfel_renderer(context& ctx, int ref_count_change)
8 {
9 static int ref_count = 0;
10 static surfel_renderer r;
11 r.manage_singleton(ctx, "surfel_renderer", ref_count, ref_count_change);
12 return r;
13 }
14
17 {
19 if (has_attribute(ctx, "point_size"))
20 has_point_sizes = true;
21 if (has_attribute(ctx, "color_index"))
22 has_indexed_colors = true;
23 }
26 {
28 has_point_sizes = false;
29 has_indexed_colors = false;
30 }
32 has_point_sizes = false;
33 remove_attribute_array(ctx, "point_size");
34 }
36 has_indexed_colors = false;
37 remove_attribute_array(ctx, "indexed_color");
38 }
39 void surfel_renderer::set_reference_point_size(float _reference_point_size)
40 {
41 reference_point_size = _reference_point_size;
42 }
43 void surfel_renderer::set_y_view_angle(float _y_view_angle)
44 {
45 y_view_angle = _y_view_angle;
46 }
48 {
49 const surfel_render_style& srs = get_style<surfel_render_style>();
50 bool res;
51 if (!srs.use_group_color) {
52 if (has_indexed_colors) {
53 if (has_colors)
54 ctx.error("surfel_renderer::validate_attributes() both point color and color index attributes set, using color index");
55 bool tmp = has_colors;
56 has_colors = true;
58 has_colors = tmp;
59 }
60 else
62 }
63 else
65 if (!has_group_point_sizes && srs.use_group_point_size) {
66 ctx.error("surfel_renderer::validate_attributes() group_point_sizes not set");
67 res = false;
68 }
69 return res;
70 }
72 {
73 const surfel_render_style& srs = get_style<surfel_render_style>();
74
75 bool res;
76 if (!srs.use_group_color && has_indexed_colors) {
77 bool tmp = has_colors;
78 has_colors = true;
79 res = surface_renderer::enable(ctx);
80 has_colors = tmp;
81 }
82 else
83 res = surface_renderer::enable(ctx);
84
85 glPointSize(srs.point_size);
86 if (srs.blend_points) {
87 ctx.push_blend_state();
88 ctx.enable_blending();
90 }
91 if (ref_prog().is_linked()) {
92 if (!has_normals)
93 ref_prog().set_attribute(ctx, "normal", cgv::vec3(0.0f, 0.0f, 1.0f));
94 if (!has_point_sizes)
95 ref_prog().set_attribute(ctx, "point_size", srs.point_size);
96 ref_prog().set_uniform(ctx, "use_color_index", has_indexed_colors);
97 ref_prog().set_uniform(ctx, "measure_point_size_in_pixel", srs.measure_point_size_in_pixel);
98 ref_prog().set_uniform(ctx, "reference_point_size", reference_point_size);
99 ref_prog().set_uniform(ctx, "use_group_point_size", srs.use_group_point_size);
100 ref_prog().set_uniform(ctx, "orient_splats", srs.orient_splats);
101 float pixel_extent_per_depth = (float)(2.0*tan(0.5*0.0174532925199*y_view_angle) / ctx.get_height());
102 ref_prog().set_uniform(ctx, "pixel_extent_per_depth", pixel_extent_per_depth);
103 ref_prog().set_uniform(ctx, "blend_width_in_pixel", srs.blend_width_in_pixel);
104 ref_prog().set_uniform(ctx, "percentual_halo_width", 0.01f*srs.percentual_halo_width);
105 ref_prog().set_uniform(ctx, "halo_width_in_pixel", srs.halo_width_in_pixel);
106 ref_prog().set_uniform(ctx, "halo_color", srs.halo_color);
107 ref_prog().set_uniform(ctx, "halo_color_strength", srs.halo_color_strength);
108 ref_prog().set_uniform(ctx, "surface_offset", srs.surface_offset);
109 }
110 return res;
111 }
112
114 {
115 const surfel_render_style& srs = get_style<surfel_render_style>();
116 if (srs.blend_points) {
117 ctx.pop_blend_state();
118 }
119 if (!attributes_persist()) {
120 has_indexed_colors = false;
121 has_point_sizes = false;
122 }
123 return surface_renderer::disable(ctx);
124 }
125
126 void surfel_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
127 {
128 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
129 }
130
131 bool surfel_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
132 {
133 return
134 rh.reflect_base(*static_cast<cgv::render::surface_render_style*>(this)) &&
135 rh.reflect_member("point_size", point_size) &&
136 rh.reflect_member("use_group_point_size", use_group_point_size) &&
137 rh.reflect_member("measure_point_size_in_pixel", measure_point_size_in_pixel) &&
138 rh.reflect_member("blend_points", blend_points) &&
139 rh.reflect_member("orient_splats", orient_splats) &&
140 rh.reflect_member("blend_width_in_pixel", blend_width_in_pixel) &&
141 rh.reflect_member("halo_width_in_pixel", halo_width_in_pixel) &&
142 rh.reflect_member("halo_color", halo_color) &&
143 rh.reflect_member("halo_color_strength", halo_color_strength) &&
144 rh.reflect_member("percentual_halo_width", percentual_halo_width);
145 }
146
148 {
150 }
151 }
152}
153
154#include <cgv/gui/provider.h>
155
156namespace cgv {
157 namespace gui {
158
160 {
162 bool create(provider* p, const std::string& label,
163 void* value_ptr, const std::string& value_type,
164 const std::string& gui_type, const std::string& options, bool*)
165 {
167 return false;
168 cgv::render::surfel_render_style* srs_ptr = reinterpret_cast<cgv::render::surfel_render_style*>(value_ptr);
169 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
170
171 bool show = p->begin_tree_node("Splatting", srs_ptr->point_size, false, "options='w=60';level=3;align=''");
172 p->add_member_control(b, "Point Size", srs_ptr->point_size, "value_slider", "label='';w=130;min=0.01;max=50;log=true;ticks=true", "");
173 p->add_member_control(b, "px", srs_ptr->measure_point_size_in_pixel, "toggle", "w=16");
174 if (show) {
175 p->align("\a");
176 p->add_member_control(b, "Blend", srs_ptr->blend_points, "toggle", "w=90", " ");
177 p->add_member_control(b, "Orient", srs_ptr->orient_splats, "toggle", "w=90");
178 p->add_member_control(b, "Surface Offset", srs_ptr->surface_offset, "value_slider", "min=0;max=0.1;step=0.0001;log=true;ticks=true");
179 p->align("\b");
180 p->end_tree_node(srs_ptr->point_size);
181 }
182 show = p->begin_tree_node("Halo", srs_ptr->halo_color, false, "options='w=120';level=3;align=''");
183 p->add_member_control(b, "Color", srs_ptr->halo_color, "", "w=50");
184 if (show) {
185 p->align("\a");
186 p->add_member_control(b, "Halo Color Strength", srs_ptr->halo_color_strength, "value_slider", "min=0;max=1;ticks=true");
187 p->add_member_control(b, "Halo Width in Pixel", srs_ptr->halo_width_in_pixel, "value_slider", "min=-10;max=10;ticks=true");
188 p->add_member_control(b, "Percentual Halo Width", srs_ptr->percentual_halo_width, "value_slider", "min=-100;max=100;ticks=true");
189 p->add_member_control(b, "Blend Width in Pixel", srs_ptr->blend_width_in_pixel, "value_slider", "min=0;max=3;ticks=true");
190 p->align("\b");
191 p->end_tree_node(srs_ptr->halo_color);
192 }
193 if (p->begin_tree_node("Surface", srs_ptr->use_group_color, false, "level=3")) {
194 p->align("\a");
195 p->add_gui("surface_render_style", *static_cast<cgv::render::surface_render_style*>(srs_ptr));
196 p->align("\b");
197 p->end_tree_node(srs_ptr->use_group_color);
198 }
199 return true;
200 }
201 };
202
203#include "gl/lib_begin.h"
204
205CGV_API cgv::gui::gui_creator_registration<surfel_render_style_gui_creator> surfel_rs_gc_reg("surfel_render_style_gui_creator");
206
207 }
208}
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
bool add_gui(const std::string &label, T &value, const std::string &gui_type="", const std::string &options="")
Add a composed gui of the given gui_type for the given value.
Definition provider.h:247
void align(const std::string &_align)
send pure alignment information
Definition provider.cxx:36
bool begin_tree_node(const std::string &label, const T &value, bool initial_visibility=false, const std::string &options="", gui_group_ptr ggp=gui_group_ptr())
Begin a sub tree of a tree structured gui.
Definition provider.h:212
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
void end_tree_node(const T &value)
template specialization that allows to specify value reference plus node_instance by using the result...
Definition provider.h:222
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:672
void set_blend_func_back_to_front()
set the default blend function for back to front blending (source = BF_SRC_ALPHA, destination = BF_ON...
Definition context.cxx:1858
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:306
void push_blend_state()
push a copy of the current blend state onto the stack saved attributes: blend enablement,...
Definition context.cxx:1822
void pop_blend_state()
pop the top of the current culling state from the stack
Definition context.cxx:1826
virtual unsigned int get_height() const =0
return the height of the window
virtual void enable_blending()
enable blending
Definition context.cxx:1862
bool validate_attributes(const context &ctx) const
check additionally the group attributes
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:10
bool has_attribute(const context &ctx, const std::string &name)
check for attribute
Definition renderer.cxx:48
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:129
bool has_colors
track whether color attribute is defined
Definition renderer.h:140
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:120
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:252
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 set_attribute(const context &ctx, const std::string &name, const T &value)
set constant default value of a vertex attribute by attribute name, if name does not specify an attri...
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this before setting attribute arrays to manage attribute array in given manager
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
bool enable(context &ctx) override
overload to activate group style
bool disable(context &ctx) override
disable renderer
renderer that supports point splatting
bool enable(context &ctx) override
overload to activate group style
bool validate_attributes(const context &ctx) const override
check additionally the group attributes
void disable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this after last render/draw call to ensure that no other users of renderer change attribute arra...
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1) override
convenience function to render with default settings
void enable_attribute_array_manager(const context &ctx, attribute_array_manager &aam) override
call this before setting attribute arrays to manage attribute array in given manager
void remove_point_size_array(const context &ctx)
remove the point size attribute
void remove_indexed_color_array(const context &ctx)
remove the indexed color attribute
bool disable(context &ctx) override
disable renderer
surfel_renderer & ref_surfel_renderer(context &ctx, int ref_count_change)
reference to a singleton surfel renderer that can be 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 ...
bool use_group_color
whether to use group colors indexed through group index, defaults to false
float percentual_halo_width
set to 0 in constructor
float point_size
default value assigned to point size attribute in enable method of point renderer,...
bool measure_point_size_in_pixel
whether to measure point size in pixels or in world space relative to reference_pixel_size passed to ...
float surface_offset
position offset in normal direction to prevent z-figthing if surfels are placed directly on flat surf...
bool use_group_point_size
whether to use the
bool orient_splats
set to true in constructor
float halo_width_in_pixel
set to 0 in constructor
float blend_width_in_pixel
set to 1 in constructor
bool blend_points
set to false in constructor
rgba halo_color
color of halo with opacity channel
float halo_color_strength
strength in [0,1] of halo color with respect to color of primitive
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54