cgv
Loading...
Searching...
No Matches
sphere_renderer.cxx
1#include "sphere_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7 sphere_renderer& ref_sphere_renderer(context& ctx, int ref_count_change)
8 {
9 static int ref_count = 0;
10 static sphere_renderer r;
11 r.manage_singleton(ctx, "sphere_renderer", ref_count, ref_count_change);
12 return r;
13 }
16 {
18 if (has_attribute(ctx, "radius"))
19 has_radii = true;
20 }
28 has_radii = false;
29 remove_attribute_array(ctx, "radius");
30 }
32 void sphere_renderer::set_y_view_angle(float _y_view_angle)
33 {
34 y_view_angle = _y_view_angle;
35 }
37 {
38 const sphere_render_style& srs = get_style<sphere_render_style>();
40 if (!has_group_radii && srs.use_group_radius) {
41 ctx.error("sphere_renderer::validate_attributes() group_radii not set");
42 res = false;
43 }
44 return res;
45 }
47 {
48 const sphere_render_style& srs = get_style<sphere_render_style>();
49
51 return false;
52
53 if (!ref_prog().is_linked())
54 return false;
55
56 if (!has_radii)
57 ref_prog().set_attribute(ctx, "radius", srs.radius);
58
59 ref_prog().set_uniform(ctx, "use_group_radius", srs.use_group_radius);
60 ref_prog().set_uniform(ctx, "radius_scale", srs.radius_scale);
61 float pixel_extent_per_depth = (float)(2.0*tan(0.5*0.0174532925199*y_view_angle) / ctx.get_height());
62 ref_prog().set_uniform(ctx, "pixel_extent_per_depth", pixel_extent_per_depth);
63 ref_prog().set_uniform(ctx, "blend_width_in_pixel", srs.blend_width_in_pixel);
64 ref_prog().set_uniform(ctx, "percentual_halo_width", 0.01f*srs.percentual_halo_width);
65 ref_prog().set_uniform(ctx, "halo_width_in_pixel", srs.halo_width_in_pixel);
66 ref_prog().set_uniform(ctx, "halo_color", srs.halo_color);
67 ref_prog().set_uniform(ctx, "halo_color_strength", srs.halo_color_strength);
68 return true;
69 }
70
72 {
73 const sphere_render_style& srs = get_style<sphere_render_style>();
74
75 if (!attributes_persist()) {
76 has_radii = false;
77 has_group_radii = false;
78 }
79 return surface_renderer::disable(ctx);
80 }
81
82 void sphere_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
83 {
84 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
85 }
86
87 bool sphere_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
88 {
89 return
90 rh.reflect_base(*static_cast<surface_render_style*>(this)) &&
91 rh.reflect_member("radius", radius) &&
92 rh.reflect_member("use_group_radius", use_group_radius) &&
93 rh.reflect_member("radius_scale", radius_scale) &&
94 rh.reflect_member("blend_width_in_pixel", blend_width_in_pixel) &&
95 rh.reflect_member("halo_width_in_pixel", halo_width_in_pixel) &&
96 rh.reflect_member("halo_color", halo_color) &&
97 rh.reflect_member("halo_color_strength", halo_color_strength) &&
98 rh.reflect_member("percentual_halo_width", percentual_halo_width);
99 }
100
102 {
104 }
105 }
106}
107
108#include <cgv/gui/provider.h>
109
110namespace cgv {
111 namespace gui {
112
114 {
116 bool create(provider* p, const std::string& label,
117 void* value_ptr, const std::string& value_type,
118 const std::string& gui_type, const std::string& options, bool*)
119 {
121 return false;
122 cgv::render::sphere_render_style* srs_ptr = reinterpret_cast<cgv::render::sphere_render_style*>(value_ptr);
123 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
124
125 p->add_member_control(b, "Default Radius", srs_ptr->radius, "value_slider", "min=0.01;max=100;log=true;ticks=true");
126 p->add_member_control(b, "Use Group Radius", srs_ptr->use_group_radius, "check");
127 p->add_member_control(b, "Radius Scale", srs_ptr->radius_scale, "value_slider", "min=0.01;max=100;log=true;ticks=true");
128 bool show = p->begin_tree_node("Halo", srs_ptr->halo_color, false, "options='w=120';level=3;align=''");
129 p->add_member_control(b, "Color", srs_ptr->halo_color, "", "w=50");
130 if (show) {
131 p->align("\a");
132 p->add_member_control(b, "Halo Color Strength", srs_ptr->halo_color_strength, "value_slider", "min=0;max=1;ticks=true");
133 p->add_member_control(b, "Halo Width in Pixel", srs_ptr->halo_width_in_pixel, "value_slider", "min=-10;max=10;ticks=true");
134 p->add_member_control(b, "Percentual Halo Width", srs_ptr->percentual_halo_width, "value_slider", "min=-100;max=100;ticks=true");
135 p->add_member_control(b, "Blend Width in Pixel", srs_ptr->blend_width_in_pixel, "value_slider", "min=0;max=3;ticks=true");
136 p->align("\b");
137 p->end_tree_node(srs_ptr->halo_color);
138 }
139 p->add_gui("surface_render_style", *static_cast<cgv::render::surface_render_style*>(srs_ptr));
140 return true;
141 }
142 };
143
144#include "gl/lib_begin.h"
145
146CGV_API cgv::gui::gui_creator_registration<sphere_render_style_gui_creator> sphere_rs_gc_reg("sphere_render_style_gui_creator");
147
148 }
149}
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:627
virtual void error(const std::string &message, const render_component *rc=0) const
error handling
Definition context.cxx:219
virtual unsigned int get_height() const =0
return the height of the window
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.h:62
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:79
bool attributes_persist() const
return whether attributes persist after a call to disable
Definition renderer.h:70
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:248
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...
renderer that supports splatting of spheres
void remove_radius_array(const context &ctx)
remove the radius attribute
bool enable(context &ctx) override
overload to activate group style
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 disable(context &ctx) override
disable renderer
bool validate_attributes(const context &ctx) const override
check additionally the group attributes
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
Draw a range of vertices or indexed elements.
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 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
sphere_renderer & ref_sphere_renderer(context &ctx, int ref_count_change)
reference to a singleton sphere 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 ...
render style for sphere rendere
float radius
default value assigned to radius attribute in enable method of sphere renderer, set to 1 in construct...
cgv::rgba halo_color
color of halo with opacity channel
float halo_width_in_pixel
set to 0 in constructor
bool use_group_radius
whether to use the group radius
float percentual_halo_width
set to 0 in constructor
float radius_scale
multiplied to the sphere radii, initialized to 1
float halo_color_strength
strength in [0,1] of halo color with respect to color of primitive
float blend_width_in_pixel
set to 1 in constructor
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54