cgv
Loading...
Searching...
No Matches
arrow_renderer.cxx
1#include "arrow_renderer.h"
2#include <cgv_gl/gl/gl.h>
3#include <cgv_gl/gl/gl_tools.h>
4
5namespace cgv {
6 namespace render {
7 arrow_renderer& ref_arrow_renderer(context& ctx, int ref_count_change)
8 {
9 static int ref_count = 0;
10 static arrow_renderer r;
11 r.manage_singleton(ctx, "arrow_renderer", ref_count, ref_count_change);
12 return r;
13 }
14
19
21 {
22 radius_lower_bound = 0.00001f;
23 radius_relative_to_length = 0.1f;
24 head_radius_scale = 2.0f;
25 head_length_mode = AHLM_MINIMUM_OF_RADIUS_AND_LENGTH;
26 head_length_relative_to_radius = 2.0f;
27 head_length_relative_to_length = 0.3f;
28 length_scale = 1.0f;
29 color_scale = 1.0f;
30 normalize_length = false;
31 relative_location_of_position = 0.0f;
32 length_eps = 0.000001f;
33 }
36 {
38 if (has_attribute(ctx, "direction"))
39 has_directions = true;
40 }
48 has_directions = false;
49 direction_is_end_point = false;
50 remove_attribute_array(ctx, "direction");
51 }
53 has_directions = false;
54 direction_is_end_point = true;
55 remove_attribute_array(ctx, "direction");
56 }
57 arrow_renderer::arrow_renderer()
58 {
59 has_directions = false;
60 position_is_center = false;
61 direction_is_end_point = false;
62 }
64 {
65 prog.allow_context_to_set_color(false);
66 return prog.build_program(ctx, "arrow.glpr", true, defines);
67 }
68
70 {
71 const arrow_render_style& ars = get_style<arrow_render_style>();
73 return false;
74
75 if (!has_directions) {
76 ctx.error("arrow_renderer::validate_attributes() neither direction nor end_point attribute set");
77 return false;
78 }
79 return true;
80 }
82 {
83 const arrow_render_style& ars = get_style<arrow_render_style>();
84
85 bool res = surface_renderer::enable(ctx);
86
87 if (ref_prog().is_linked()) {
88 ref_prog().set_uniform(ctx, "radius_lower_bound", ars.radius_lower_bound);
89 ref_prog().set_uniform(ctx, "radius_relative_to_length", ars.radius_relative_to_length);
90 ref_prog().set_uniform(ctx, "head_radius_scale", ars.head_radius_scale);
91 ref_prog().set_uniform(ctx, "head_length_mode", (int&)ars.head_length_mode);
92 ref_prog().set_uniform(ctx, "head_length_relative_to_radius", ars.head_length_relative_to_radius);
93 ref_prog().set_uniform(ctx, "head_length_relative_to_length", ars.head_length_relative_to_length);
94 ref_prog().set_uniform(ctx, "length_scale", ars.length_scale);
95 ref_prog().set_uniform(ctx, "color_scale", ars.color_scale);
96 ref_prog().set_uniform(ctx, "length_eps", ars.length_eps);
97 ref_prog().set_uniform(ctx, "normalize_length", ars.normalize_length);
98 ref_prog().set_uniform(ctx, "direction_is_end_point", direction_is_end_point);
99 ref_prog().set_uniform(ctx, "relative_location_of_position", ars.relative_location_of_position);
100 }
101 return res;
102 }
103
105 {
106 const arrow_render_style& ars = get_style<arrow_render_style>();
107 if (!attributes_persist()) {
108 has_directions = false;
109 }
110 return surface_renderer::disable(ctx);
111 }
112
113 void arrow_renderer::draw(context& ctx, size_t start, size_t count, bool use_strips, bool use_adjacency, uint32_t strip_restart_index)
114 {
115 const arrow_render_style& ars = get_style<arrow_render_style>();
116 draw_impl(ctx, PT_POINTS, start, count, false, false, -1);
117 }
118
119 bool arrow_render_style_reflect::self_reflect(cgv::reflect::reflection_handler& rh)
120 {
121 return
122 rh.reflect_base(*static_cast<cgv::render::surface_render_style*>(this)) &&
123 rh.reflect_member("radius_lower_bound", radius_lower_bound) &&
124 rh.reflect_member("radius_relative_to_length", radius_relative_to_length) &&
125 rh.reflect_member("head_radius_scale", head_radius_scale) &&
126 rh.reflect_member("head_length_relative_to_radius", head_length_relative_to_radius) &&
127 rh.reflect_member("head_length_relative_to_length", head_length_relative_to_length) &&
128 rh.reflect_member("length_scale", length_scale) &&
129 rh.reflect_member("color_scale", color_scale) &&
130 rh.reflect_member("length_eps", length_eps) &&
131 rh.reflect_member("normalize_length", normalize_length) &&
132 rh.reflect_member("relative_location_of_position", relative_location_of_position);
133 }
134
136 {
138 }
139 }
140}
141
142#include <cgv/gui/provider.h>
143
144namespace cgv {
145 namespace gui {
146
148 {
150 bool create(provider* p, const std::string& label,
151 void* value_ptr, const std::string& value_type,
152 const std::string& gui_type, const std::string& options, bool*)
153 {
155 return false;
156 cgv::render::arrow_render_style* ars_ptr = reinterpret_cast<cgv::render::arrow_render_style*>(value_ptr);
157 cgv::base::base* b = dynamic_cast<cgv::base::base*>(p);
158
159 p->add_member_control(b, "Relative Location of Position", ars_ptr->relative_location_of_position, "value_slider", "min=0;max=1;ticks=true");
160 p->add_member_control(b, "Color Scale", ars_ptr->color_scale, "value_slider", "min=0.01;max=100;log=true;ticks=true");
161 if (p->begin_tree_node("Length", ars_ptr->length_scale, true, "level=3")) {
162 p->align("\a");
163 p->add_member_control(b, "Normalize Length", ars_ptr->normalize_length, "toggle");
164 p->add_member_control(b, "Length Scale", ars_ptr->length_scale, "value_slider", "min=0.01;max=100;log=true;ticks=true");
165 p->add_member_control(b, "Length Epsilon", ars_ptr->length_eps, "value_slider", "min=0.00000001;step=0.000000001;max=1;log=true;ticks=true");
166 p->align("\b");
167 p->end_tree_node(ars_ptr->length_scale);
168 }
169 if (p->begin_tree_node("Radius", ars_ptr->radius_lower_bound, true, "level=3")) {
170 p->align("\a");
171 p->add_member_control(b, "Radius Relative to Length", ars_ptr->radius_relative_to_length, "value_slider", "min=0;max=1;ticks=true");
172 p->add_member_control(b, "Radius Lower Bound", ars_ptr->radius_lower_bound, "value_slider", "min=0.00000001;step=0.000000001;max=0.01;log=true;ticks=true");
173 p->align("\b");
175 }
176 if (p->begin_tree_node("Head Radius", ars_ptr->head_radius_scale, true, "level=3")) {
177 p->align("\a");
178 p->add_member_control(b, "Head Length Mode", ars_ptr->head_length_mode, "dropdown", "enums='Relative to Radius=1,Relative to Length=2,Minimum of Radius and Length=3'");
179 p->add_member_control(b, "Head Length Relative to Radius", ars_ptr->head_length_relative_to_radius, "value_slider", "min=0.1;max=5;ticks=true");
180 p->add_member_control(b, "Head Length Relative to Length", ars_ptr->head_length_relative_to_length, "value_slider", "min=0;max=1;ticks=true");
181 p->add_member_control(b, "Head Radius Scale", ars_ptr->head_radius_scale, "value_slider", "min=1;max=3;ticks=true");
182 p->align("\b");
183 p->end_tree_node(ars_ptr->head_radius_scale);
184 }
185 if (p->begin_tree_node("Surface Rendering", ars_ptr->use_group_color, false, "level=3")) {
186 p->align("\a");
187 p->add_gui("surface_render_style", *static_cast<cgv::render::surface_render_style*>(ars_ptr));
188 p->align("\b");
189 p->end_tree_node(ars_ptr->use_group_color);
190 }
191 return true;
192 }
193 };
194
195#include "gl/lib_begin.h"
196
197CGV_API cgv::gui::gui_creator_registration<arrow_render_style_gui_creator> arrow_rs_gc_reg("arrow_render_style_gui_creator");
198
199 }
200}
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.
renderer that supports point splatting
bool validate_attributes(const context &ctx) const
call to validate, whether essential position attribute is defined
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 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
render_style * create_render_style() const
overload to allow instantiation of arrow_renderer
bool enable(context &ctx)
enables renderer
bool build_shader_program(context &ctx, shader_program &prog, const shader_define_map &defines)
build arrow program
void remove_direction_array(const context &ctx)
remove the direction attribute
void draw(context &ctx, size_t start, size_t count, bool use_strips=false, bool use_adjacency=false, uint32_t strip_restart_index=-1)
convenience function to render with default settings
void remove_end_point_array(const context &ctx)
remove the end point attribute
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 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: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.
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...
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 disable(context &ctx)
disable renderer
bool enable(context &ctx)
overload to activate group style
std::map< std::string, std::string > shader_define_map
typedef for shader define map data structure
Definition shader_code.h:52
arrow_renderer & ref_arrow_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
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
interface for gui creators
Definition gui_creator.h:14
this reflection traits implementation is used for external self_reflect implementations of instances ...
arrow_render_style()
construct with default values
float head_radius_scale
scaling factor of head radius with respect to tail radius
float radius_lower_bound
smallest value for the radius
bool use_group_color
whether to use group colors indexed through group index, defaults to false
base class for all render styles
Definition renderer.h:16
traits class with a static function get_name() of type const char* that returns the type name of the ...
Definition type_name.h:54