cgv
Loading...
Searching...
No Matches
plot3d.cxx
1#include "plot3d.h"
2#include <libs/cgv_gl/gl/gl.h>
3#include <cgv/math/ftransform.h>
4
5namespace cgv {
6 namespace plot {
7
8
9void plot3d_config::set_colors(const rgb& base_color)
10{
12 surface_color = 0.1f * rgb(1, 1, 1) + 0.9f * base_color;
13}
14
17{
18 /*
19 collect_tick_geometry(0, 1, &domain_min(0), &domain_max(0), &extent(0));
20 collect_tick_geometry(0, 2, &domain_min(0), &domain_max(0), &extent(0));
21 collect_tick_geometry(1, 0, &domain_min(0), &domain_max(0), &extent(0));
22 collect_tick_geometry(1, 2, &domain_min(0), &domain_max(0), &extent(0));
23 collect_tick_geometry(2, 0, &domain_min(0), &domain_max(0), &extent(0));
24 collect_tick_geometry(2, 1, &domain_min(0), &domain_max(0), &extent(0));
25 */
26}
27
28plot3d_config::plot3d_config(const std::string& _name) : plot_base_config(_name, 3)
29{
30 show_points = true;
31 show_lines = true;
33 show_bars = false;
35 show_surface = true;
36 wireframe = false;
37 surface_color = rgb(0.7f,0.4f,0);
38 face_illumination = PFI_PER_FACE;
40}
41
42bool plot3d::compute_sample_coordinate_interval(int i, int ai, float& samples_min, float& samples_max)
43{
44 // compute bounding box
45 bool found_sample = false;
46 float min_value, max_value;
47 for (unsigned j = 0; j < samples[i].size(); ++j) {
48 if (found_sample) {
49 min_value = std::min(min_value, samples[i][j](ai));
50 max_value = std::max(max_value, samples[i][j](ai));
51 }
52 else {
53 min_value = samples[i][j](ai);
54 max_value = samples[i][j](ai);
55 found_sample = true;
56 }
57 }
58 if (found_sample) {
59 samples_min = min_value;
60 samples_max = max_value;
61 return true;
62 }
63 return false;
64}
65
66plot3d::plot3d(unsigned nr_attributes) : plot_base(3, nr_attributes)
67{
69 acs[0].name = "x"; acs[0].color = rgb(0.4f, 0.2f, 0.2f);
70 acs[1].name = "y"; acs[1].color = rgb(0.2f, 0.4f, 0.2f);
71 acs[2].name = "z"; acs[2].color = rgb(0.2f, 0.2f, 0.4f);
72 for (unsigned ai = 0; ai < nr_attributes; ++ai)
73 acs[ai + 3].name = std::string("attribute_") + cgv::utils::to_string(ai);
74
75 brs.culling_mode = cgv::render::CM_FRONTFACE;
76 brs.map_color_to_material = cgv::render::CM_COLOR;
77 brs.illumination_mode = cgv::render::IM_TWO_SIDED;
78
80
81 legend_location[2] = 0.01f;
82}
83
84unsigned plot3d::add_sub_plot(const std::string& name)
85{
86 // determine index of new sub plot
87 unsigned i = get_nr_sub_plots();
88
89 // create new config
90 if (i == 0)
91 configs.push_back(new plot3d_config(name));
92 else {
93 configs.push_back(new plot3d_config(ref_sub_plot3d_config(i - 1)));
94 ref_sub_plot_config(i).name = name;
95 }
96
97 // create new point container
98 samples.push_back(std::vector<vec3>());
100 attribute_source_arrays.back().attribute_sources.push_back(attribute_source(i, 0, 0, 3 * sizeof(float)));
101 attribute_source_arrays.back().attribute_sources.push_back(attribute_source(i, 1, 0, 3 * sizeof(float)));
102 attribute_source_arrays.back().attribute_sources.push_back(attribute_source(i, 2, 0, 3 * sizeof(float)));
103
104 // return sub plot index
105 return i;
106}
107
109{
110 delete configs[i];
111 configs[i] = 0;
112 configs.erase(configs.begin() + i);
113 samples.erase(samples.begin() + i);
114}
115
117void plot3d::set_samples_per_row(unsigned i, unsigned N)
118{
120}
121
123unsigned plot3d::get_samples_per_row(unsigned i) const
124{
125 return const_cast<plot3d*>(this)->ref_sub_plot3d_config(i).samples_per_row;
126}
127
130{
131 return static_cast<plot3d_config&>(ref_sub_plot_config(i));
132}
133
134
136std::vector<vec3>& plot3d::ref_sub_plot_samples(unsigned i)
137{
138 return samples[i];
139}
140
141
143{
144 bool success = true;
145 if (!sphere_prog.build_program(ctx, "plot3d_sphere.glpr")) {
146 success = false;
147 std::cerr << "could not build GLSL program from plot3d_sphere.glpr" << std::endl;
148 }
149 else
150 sphere_prog.allow_context_to_set_color(false);
151 if (!stick_prog.build_program(ctx, "plot3d_stick.glpr")) {
152 success = false;
153 std::cerr << "could not build GLSL program from plot3d_stick.glpr" << std::endl;
154 }
155 else
156 stick_prog.allow_context_to_set_color(false);
157 if (!tick_label_prog.build_program(ctx, "plot3d_tick_label.glpr")) {
158 success = false;
159 std::cerr << "could not build GLSL program from plot3d_tick_label.glpr" << std::endl;
160 }
161 else
162 tick_label_prog.allow_context_to_set_color(false);
163 if (!box_prog.build_program(ctx, "plot3d_box.glpr")) {
164 std::cerr << "could not build GLSL program from plot3d_box.glpr" << std::endl;
165 success = false;
166 }
167 else
168 box_prog.allow_context_to_set_color(false);
169 if (!wirebox_prog.build_program(ctx, "plot3d_box_wire.glpr")) {
170 success = false;
171 std::cerr << "could not build GLSL program from plot3d_box_wire.glpr" << std::endl;
172 }
173 else
174 wirebox_prog.allow_context_to_set_color(false);
175 if (!tube_prog.build_program(ctx, "plot3d_tube.glpr", true)) {
176 std::cerr << "could not build GLSL program from plot3d_tube.glpr" << std::endl;
177 success = false;
178 }
179 else {
180 tube_prog.set_uniform(ctx, "map_color_to_material", 3);
181 tube_prog.allow_context_to_set_color(false);
182 }
183
184 //if (!surface_prog.is_created()) {
185 // if (!surface_prog.build_program(ctx, "plot3d_surface.glpr")) {
186 // std::cerr << "could not build GLSL program from plot3d_surface.glpr" << std::endl;
187 // }
188 //}
189 aam_domain.init(ctx);
192 return plot_base::init(ctx);
193}
194
195void plot3d::draw_sub_plots(cgv::render::context& ctx)
196{
197 float rs = 0.2f*get_domain_config_ptr()->reference_size;
198 vecn extent = this->extent.to_vec();
199 double y_view_angle = 45.0f;
200 if (view_ptr)
201 y_view_angle = view_ptr->get_y_view_angle();
202 float pixel_extent_per_depth = (float)(2.0 * tan(0.5 * 0.0174532925199 * y_view_angle) / ctx.get_height());
203
204 for (unsigned i = 0; i < get_nr_sub_plots(); ++i) {
205 size_t count = enable_attributes(ctx, i, samples);
206 if (count > 0) {
207 const plot3d_config& spc = ref_sub_plot3d_config(i);
208 if (spc.show_plot) {
209 if (spc.show_points) {
210 set_plot_uniforms(ctx, sphere_prog);
211 set_mapping_uniforms(ctx, sphere_prog);
212 sphere_prog.set_uniform(ctx, "radius_scale", spc.point_size.size * rs);
213 sphere_prog.set_uniform(ctx, "map_color_to_material", 7);
214 sphere_prog.set_uniform(ctx, "blend_width_in_pixel", get_domain_config_ptr()->blend_width_in_pixel);
215 sphere_prog.set_uniform(ctx, "pixel_extent_per_depth", pixel_extent_per_depth);
216 sphere_prog.set_uniform(ctx, "halo_width_in_pixel", 0.0f);
217 sphere_prog.set_uniform(ctx, "halo_color_strength", 1.0f);
218 sphere_prog.set_uniform(ctx, "percentual_halo_width", spc.point_halo_width.size / spc.point_size.size);
219 sphere_prog.set_uniform(ctx, "color_index", spc.point_color.color_idx);
220 sphere_prog.set_uniform(ctx, "secondary_color_index", spc.point_halo_color.color_idx);
221 sphere_prog.set_uniform(ctx, "opacity_index", spc.point_color.opacity_idx);
222 sphere_prog.set_uniform(ctx, "secondary_opacity_index", spc.point_halo_color.opacity_idx);
223 sphere_prog.set_uniform(ctx, "size_index", spc.point_size.size_idx);
224 sphere_prog.set_uniform(ctx, "secondary_size_index", spc.point_halo_width.size_idx);
225 sphere_prog.set_attribute(ctx, sphere_prog.get_color_index(), spc.point_color.color);
226 sphere_prog.set_attribute(ctx, "secondary_color", spc.point_halo_color.color);
227 sphere_prog.set_attribute(ctx, "size", spc.point_size.size);
228 sphere_prog.enable(ctx);
229 draw_sub_plot_samples(int(count), spc);
230 sphere_prog.disable(ctx);
231 }
232 if (spc.show_bars) {
233 unsigned N = (unsigned)count;
234 unsigned M = (unsigned)count;
235 if (spc.samples_per_row > 0) {
236 N = spc.samples_per_row;
237 M /= spc.samples_per_row;
238 }
239 float box_width = spc.bar_percentual_width.size * extent((spc.bar_coordinate_index + 1) % 3) / N;
240 float box_depth = spc.bar_percentual_depth.size * extent((spc.bar_coordinate_index + 2) % 3) / M;
241 if (spc.bar_outline_width.size > 0) {
242 //glLineWidth(spc.bar_outline_width.size);
243 set_plot_uniforms(ctx, wirebox_prog);
244 set_mapping_uniforms(ctx, wirebox_prog);
245 wirebox_prog.set_uniform(ctx, "box_width", box_width);
246 wirebox_prog.set_uniform(ctx, "box_depth", box_depth);
247 wirebox_prog.set_uniform(ctx, "box_coordinate_index", spc.bar_coordinate_index);
248 wirebox_prog.set_uniform(ctx, "box_base_window", spc.bar_base_window);
249 wirebox_prog.set_uniform(ctx, "color_index", spc.bar_outline_color.color_idx);
250 wirebox_prog.set_uniform(ctx, "secondary_color_index", -1);
251 wirebox_prog.set_uniform(ctx, "opacity_index", spc.bar_outline_color.opacity_idx);
252 wirebox_prog.set_uniform(ctx, "secondary_opacity_index", -1);
253 wirebox_prog.set_uniform(ctx, "size_index", spc.bar_percentual_width.size_idx);
254 wirebox_prog.set_uniform(ctx, "secondary_size_index", spc.bar_percentual_depth.size_idx);
255 wirebox_prog.set_attribute(ctx, wirebox_prog.get_color_index(), spc.bar_outline_color.color);
256 wirebox_prog.enable(ctx);
257 draw_sub_plot_samples(int(count), spc);
258 wirebox_prog.disable(ctx);
259 }
260 set_plot_uniforms(ctx, box_prog);
261 set_mapping_uniforms(ctx, box_prog);
262 box_prog.set_uniform(ctx, "map_color_to_material", 7);
263 box_prog.set_uniform(ctx, "box_width", box_width);
264 box_prog.set_uniform(ctx, "box_depth", box_depth);
265 box_prog.set_uniform(ctx, "box_base_window", spc.bar_base_window);
266 box_prog.set_uniform(ctx, "box_coordinate_index", spc.bar_coordinate_index);
267 box_prog.set_uniform(ctx, "color_index", spc.bar_color.color_idx);
268 box_prog.set_uniform(ctx, "secondary_color_index", -1);
269 box_prog.set_uniform(ctx, "opacity_index", spc.bar_color.opacity_idx);
270 box_prog.set_uniform(ctx, "secondary_opacity_index", -1);
271 box_prog.set_uniform(ctx, "size_index", spc.bar_percentual_width.size_idx);
272 box_prog.set_uniform(ctx, "secondary_size_index", spc.bar_percentual_depth.size_idx);
273 box_prog.set_attribute(ctx, box_prog.get_color_index(), spc.bar_color.color);
274 box_prog.enable(ctx);
275 draw_sub_plot_samples(int(count), spc);
276 box_prog.disable(ctx);
277 }
278 if (spc.show_sticks) {
279 set_plot_uniforms(ctx, stick_prog);
280 set_mapping_uniforms(ctx, stick_prog);
281 stick_prog.set_uniform(ctx, "radius_scale", 1.0f);
282 stick_prog.set_uniform(ctx, "stick_coordinate_index", spc.stick_coordinate_index);
283 stick_prog.set_uniform(ctx, "stick_base_window", spc.stick_base_window);
284 stick_prog.set_uniform(ctx, "map_color_to_material", 7);
285 stick_prog.set_uniform(ctx, "color_index", spc.stick_color.color_idx);
286 stick_prog.set_uniform(ctx, "secondary_color_index", -1);
287 stick_prog.set_uniform(ctx, "opacity_index", spc.stick_color.opacity_idx);
288 stick_prog.set_uniform(ctx, "secondary_opacity_index", -1);
289 stick_prog.set_uniform(ctx, "size_index", spc.stick_width.size_idx);
290 stick_prog.set_uniform(ctx, "secondary_size_index", -1);
291 stick_prog.set_attribute(ctx, stick_prog.get_color_index(), spc.stick_color.color);
292 stick_prog.set_attribute(ctx, "secondary_color", spc.stick_color.color);
293 stick_prog.set_attribute(ctx, "size", spc.stick_width.size * rs);
294 stick_prog.set_attribute(ctx, "secondary_size", spc.stick_width.size * rs);
295 stick_prog.enable(ctx);
296 draw_sub_plot_samples(int(count), spc);
297 stick_prog.disable(ctx);
298 }
299 if (spc.show_lines) {
300 set_plot_uniforms(ctx, tube_prog);
301 set_mapping_uniforms(ctx, tube_prog);
302 tube_prog.set_uniform(ctx, "radius_scale", 1.0f);
303 tube_prog.set_uniform(ctx, "map_color_to_material", 7);
304 tube_prog.set_uniform(ctx, "color_index", spc.line_color.color_idx);
305 tube_prog.set_uniform(ctx, "secondary_color_index", -1);
306 tube_prog.set_uniform(ctx, "opacity_index", spc.line_color.opacity_idx);
307 tube_prog.set_uniform(ctx, "secondary_opacity_index", -1);
308 tube_prog.set_uniform(ctx, "size_index", spc.line_width.size_idx);
309 tube_prog.set_uniform(ctx, "secondary_size_index", -1);
310 tube_prog.set_attribute(ctx, tube_prog.get_color_index(), spc.line_color.color);
311 tube_prog.set_attribute(ctx, "size", spc.line_width.size * rs);
312 tube_prog.enable(ctx);
313 draw_sub_plot_samples(int(count), spc, true);
314 tube_prog.disable(ctx);
315 }
316 }
317 }
318 disable_attributes(ctx, i);
319 }
320}
321
322void plot3d::draw_domain(cgv::render::context& ctx)
323{
324 tick_labels.clear();
325 tick_batches.clear();
326 const domain_config& dc = *get_domain_config_ptr();
327 vecn E = get_extent();
329 if (dc.fill) {
330 vec3 origin(0.0f);
333 bool tmp = br.ref_prog().does_context_set_color();
334 br.ref_prog().allow_context_to_set_color(false);
335 br.set_render_style(brs);
336 br.set_position(ctx, origin);
337 br.set_extent(ctx, extent);
338 br.set_position_is_center(true);
339 br.set_color(ctx, dc.color);
340 br.render(ctx, 0, 1);
341 br.ref_prog().allow_context_to_set_color(tmp);
342 }
343 // draw axes
344 std::vector<vec3> P;
345 std::vector<rgb> C;
346 std::vector<float> R;
348 for (unsigned ai = 0; ai < 3; ++ai) {
349 int aj = (ai + 1) % 3;
350 int ak = (ai + 2) % 3;
351 axis_config& ac = get_domain_config_ptr()->axis_configs[ai];
352 axis_config& ao = get_domain_config_ptr()->axis_configs[aj];
353 axis_config& ap = get_domain_config_ptr()->axis_configs[ak];
354 float lw = rs * ac.line_width;
355 rgb col = ac.color;
356 vec3 D = 0.5f * extent;
357 unsigned cnt = 4;
358 float c[5][2] = { {-D[aj],-D[ak]}, {D[aj],-D[ak]}, {D[aj],D[ak]}, {-D[aj],D[ak]} };
359 // axis line
360 if (ao.get_attribute_min() < 0 && ao.get_attribute_max() > 0 &&
361 ap.get_attribute_min() < 0 && ap.get_attribute_max() > 0) {
362 c[cnt][0] = ao.plot_space_from_attribute_space(0.0f);
363 c[cnt][1] = ap.plot_space_from_attribute_space(0.0f);
364 ++cnt;
365 }
366 vec3 p;
367 for (unsigned ci = 0; ci < cnt; ++ci) {
368 p[ai] = -D[ai];
369 p[aj] = c[ci][0];
370 p[ak] = c[ci][1];
371 P.push_back(p);
372 C.push_back(col);
373 R.push_back(lw);
374 p[ai] = D[ai];
375 P.push_back(p);
376 C.push_back(col);
377 R.push_back(lw);
378
379 for (unsigned ti = 0; ti < 2; ++ti) {
380 tick_config& tc = ti == 0 ? ac.primary_ticks : ac.secondary_ticks;
381 if (tc.type == TT_NONE)
382 continue;
383 tick_batches.push_back(tick_batch_info(ai, aj, ti == 0, 0, (unsigned)tick_labels.size()));
384 float min_tick = ac.tick_space_from_attribute_space(ac.get_attribute_min());
385 float max_tick = ac.tick_space_from_attribute_space(ac.get_attribute_max());
386 int min_i = (int)ceil(min_tick / tc.step - std::numeric_limits<float>::epsilon());
387 int max_i = (int)((max_tick - fmod(max_tick, tc.step)) / tc.step);
388 // ignore secondary ticks on domain boundary
389 if (ti == 1 && min_i * tc.step - min_tick < std::numeric_limits<float>::epsilon())
390 ++min_i;
391 if (ti == 1 && max_i * tc.step - max_tick > -std::numeric_limits<float>::epsilon())
392 --max_i;
393 float lw = 0.5f * get_domain_config_ptr()->reference_size * tc.line_width;
394 float dl = 0.5f * get_domain_config_ptr()->reference_size * tc.length;
395 for (int i = min_i; i <= max_i; ++i) {
396 float c_tick = (float)(i * tc.step);
397 float c_attr = ac.attribute_space_from_tick_space(c_tick);
398 std::string label_str;
399 if (tc.label)
400 label_str = cgv::utils::to_string(c_attr);
401 float c_plot = ac.plot_space_from_window_space(ac.window_space_from_tick_space(c_tick));
402 switch (tc.type) {
403 case TT_DASH:
404 p[ai] = c_plot;
405 p[aj] = c[ci][0]-dl;
406 p[ak] = c[ci][1];
407 P.push_back(p);
408 C.push_back(col);
409 R.push_back(lw);
410 p[aj] = c[ci][0]+dl;
411 P.push_back(p);
412 C.push_back(col);
413 R.push_back(lw);
414 if (!label_str.empty())
415 tick_labels.push_back(label_info(p.to_vec(), label_str, ai == 0 ? cgv::render::TA_BOTTOM : cgv::render::TA_LEFT));
416 p[aj] = c[ci][0];
417 p[ak] = c[ci][1]-dl;
418 P.push_back(p);
419 C.push_back(col);
420 R.push_back(lw);
421 p[ak] = c[ci][1]+dl;
422 P.push_back(p);
423 C.push_back(col);
424 R.push_back(lw);
425// if (!label_str.empty())
426// tick_labels.push_back(label_info(p.to_vec(), label_str, ai == 0 ? cgv::render::TA_BOTTOM : cgv::render::TA_LEFT));
427 break;
428 case TT_LINE:
429 case TT_PLANE:
430 if (ci < 4) {
431 p[ai] = c_plot;
432 p[aj] = c[ci][0];
433 p[ak] = c[ci][1];
434 if (!label_str.empty())
435 tick_labels.push_back(label_info(p.to_vec(), label_str, ai == 0 ? cgv::render::TA_BOTTOM : cgv::render::TA_LEFT));
436 P.push_back(p);
437 C.push_back(col);
438 R.push_back(lw);
439 p[aj] = c[(ci + 1) % 4][0];
440 p[ak] = c[(ci + 1) % 4][1];
441 P.push_back(p);
442 C.push_back(col);
443 R.push_back(lw);
444 }
445 else {
446 p[ai] = c_plot;
447 p[aj] = c[ci][0];
448 p[ak] = c[ci][1];
449 if (!label_str.empty())
450 tick_labels.push_back(label_info(p.to_vec(), label_str, ai == 0 ? cgv::render::TA_BOTTOM : cgv::render::TA_LEFT));
451 p[ak] = -D[ak];
452 P.push_back(p);
453 C.push_back(col);
454 R.push_back(lw);
455 p[ak] = D[ak];
456 P.push_back(p);
457 C.push_back(col);
458 R.push_back(lw);
459 p[aj] = -D[aj];
460 p[ak] = c[ci][1];
461 P.push_back(p);
462 C.push_back(col);
463 R.push_back(lw);
464 p[aj] = D[aj];
465 P.push_back(p);
466 C.push_back(col);
467 R.push_back(lw);
468 }
469 break;
470 }
471 }
472 tick_batches.back().label_count = (unsigned)(tick_labels.size() - tick_batches.back().first_label);
473 }
474 }
475 }
476 set_extent(E);
477
478 auto& rcr = cgv::render::ref_cone_renderer(ctx);
479 rcr.set_render_style(rcrs);
480 rcr.enable_attribute_array_manager(ctx, aam_domain);
481 rcr.set_position_array(ctx, P);
482 rcr.set_color_array(ctx, C);
483 rcr.set_radius_array(ctx, R);
484 rcr.render(ctx, 0, P.size());
485 rcr.disable_attribute_array_manager(ctx, aam_domain);
486}
487
488void plot3d::draw_ticks(cgv::render::context& ctx)
489{
490 if (tick_labels.empty())
491 return;
493 for (const auto& tbc : tick_batches) if (tbc.label_count > 0) {
494 ctx.set_color(get_domain_config_ptr()->axis_configs[tbc.ai].color);
495 for (unsigned i = tbc.first_label; i < tbc.first_label + tbc.label_count; ++i) {
496 const label_info& li = tick_labels[i];
497 ctx.set_cursor(li.position, li.label, li.align);
498 ctx.output_stream() << li.label;
499 ctx.output_stream().flush();
500 }
501 }
502}
503
505{
507
508 GLboolean blend = glIsEnabled(GL_BLEND);
509 GLenum blend_src, blend_dst, depth;
510 glGetIntegerv(GL_BLEND_DST, reinterpret_cast<GLint*>(&blend_dst));
511 glGetIntegerv(GL_BLEND_SRC, reinterpret_cast<GLint*>(&blend_src));
512 glGetIntegerv(GL_DEPTH_FUNC, reinterpret_cast<GLint*>(&depth));
513
514 glEnable(GL_BLEND);
515 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
516 glDepthFunc(GL_LEQUAL);
517
519 mat4 R;
521 ctx.mul_modelview_matrix(cgv::math::translate4<float>(center_location) * R);
522 if (get_domain_config_ptr()->show_domain) {
523 draw_domain(ctx);
524 draw_ticks(ctx);
525 }
526 if (legend_components != LC_HIDDEN)
527 draw_legend(ctx);
528
529 draw_sub_plots(ctx);
531
532 if (!blend)
533 glDisable(GL_BLEND);
534 glDepthFunc(depth);
535 glBlendFunc(blend_src, blend_dst);
536}
537
539{
540 sphere_prog.destruct(ctx);
541 box_prog.destruct(ctx);
542 wirebox_prog.destruct(ctx);
543 stick_prog.destruct(ctx);
544 tube_prog.destruct(ctx);
545// surface_prog.destruct(ctx);
548 aam_domain.destruct(ctx);
549 plot_base::clear(ctx);
550}
551
553{
555 plot3d_config& p3bc = reinterpret_cast<plot3d_config&>(pbc);
556 p.add_member_control(bp, "show_orientation", p3bc.show_line_orientation, "check");
557}
559{
561 plot3d_config& p3bc = reinterpret_cast<plot3d_config&>(pbc);
562 add_mapped_size_control(p, bp, "depth", p3bc.bar_percentual_depth, "min=0.01;max=1;log=true;ticks=true");
563}
564
566{
569 bool show = p.begin_tree_node("surface", pbc.show_surface, false, "level=3;w=100;align=' '");
570 p.add_member_control(bp, "show", pbc.show_surface, "toggle", "w=50");
571 if (show) {
572 p.align("\a");
573 p.add_view("samples per row", pbc.samples_per_row);
574 p.add_member_control(bp, "wireframe", pbc.wireframe, "check");
575 p.add_member_control(bp, "color", pbc.surface_color);
576 p.add_member_control(bp, "wireframe", pbc.face_illumination, "dropdown", "enums='none,face,vertex'");
577 p.align("\b");
579 }
580}
581
583{
584 p.add_decorator("plot3d", "heading");
586 if (p.begin_tree_node("rounded cones", rcrs)) {
587 p.align("\a");
588 p.add_gui("rcrs", rcrs);
589 p.align("\b");
590 p.end_tree_node(rcrs);
591 }
592}
593
594 }
595}
base class for all classes that can be registered with support for dynamic properties (see also secti...
Definition base.h:75
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
cgv::base::base_ptr add_decorator(const std::string &label, const std::string &decorator_type, const std::string &options="", const std::string &align="\n")
add a newly created decorator to the group
Definition provider.cxx:168
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
data::ref_ptr< view< T > > add_view(const std::string &label, const T &value, const std::string &gui_type="", const std::string &options="", const std::string &align="\n")
use this to add a new view to the gui with a given value type, gui type and init options
Definition provider.h:112
vec< T > to_vec() const
conversion to vector type
Definition fvec.h:730
void put_homogeneous_matrix(hmat_type &M) const
compute equivalent homogeneous 4x4 rotation matrix
Definition quaternion.h:154
color()
standard constructor does not initialize components
Definition color.h:589
The plot3d class draws 2d plots with potentially several sub plots of different plot configuration.
Definition plot3d.h:46
std::vector< vec3 > & ref_sub_plot_samples(unsigned i=0)
return the samples of the i-th sub plot
Definition plot3d.cxx:136
void draw(cgv::render::context &ctx)
overload to draw the content of this drawable
Definition plot3d.cxx:504
void compute_tick_render_information()
overloaded in derived classes to compute complete tick render information
Definition plot3d.cxx:16
plot3d_config & ref_sub_plot3d_config(unsigned i=0)
return a reference to the plot3d configuration of the i-th plot
Definition plot3d.cxx:129
bool init(cgv::render::context &ctx)
this method is called after creation or recreation of the context, return whether all necessary funct...
Definition plot3d.cxx:142
void create_bar_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a bar subplot
Definition plot3d.cxx:558
void clear(cgv::render::context &ctx)
clear all objects living in the context like textures or display lists
Definition plot3d.cxx:538
void create_gui(cgv::base::base *bp, cgv::gui::provider &p)
create a gui for the plot with gui for all configs
Definition plot3d.cxx:582
void set_samples_per_row(unsigned i, unsigned N)
set the number of samples of the i-th sub plot to N
Definition plot3d.cxx:117
void delete_sub_plot(unsigned i)
delete the i-th sub plot
Definition plot3d.cxx:108
unsigned get_samples_per_row(unsigned i) const
return the number of samples per row
Definition plot3d.cxx:123
void create_line_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a line subplot
Definition plot3d.cxx:552
plot3d(unsigned nr_attributes=0)
construct 3d plot with given number of additional attributes and default parameters
Definition plot3d.cxx:66
unsigned add_sub_plot(const std::string &name)
add sub plot and return reference to samples
Definition plot3d.cxx:84
void create_config_gui(cgv::base::base *bp, cgv::gui::provider &p, unsigned i)
create the gui for a subplot configuration
Definition plot3d.cxx:565
base class for plot2d and plot3d, which can have several sub plots each
Definition plot_base.h:282
virtual void create_config_gui(cgv::base::base *bp, cgv::gui::provider &p, unsigned i)
create the gui for a subplot configuration
virtual void create_bar_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a bar subplot
virtual void create_line_config_gui(cgv::base::base *bp, cgv::gui::provider &p, plot_base_config &pbc)
create the gui for a line subplot
const domain_config * get_domain_config_ptr() const
return const pointer to domain configuration
void clear(cgv::render::context &ctx)
destruct shader programs
unsigned get_nr_sub_plots() const
return current number of sub plots
LegendComponent legend_components
whether to show legend
Definition plot_base.h:366
std::vector< attribute_source_array > attribute_source_arrays
attribute sources
Definition plot_base.h:429
vecn get_extent() const
query the plot extend in 2D coordinates
quat orientation
orientiation quaternion mapping from domain to world coordinates
Definition plot_base.h:354
void set_mapping_uniforms(cgv::render::context &ctx, cgv::render::shader_program &prog)
set the uniforms for defining the mappings to visual variables
vec3 center_location
center location of domain in world coordinates
Definition plot_base.h:356
std::vector< plot_base_config * > configs
store one configuration per sub plot
Definition plot_base.h:348
std::vector< label_info > tick_labels
all tick labels
Definition plot_base.h:319
plot_base_config & ref_sub_plot_config(unsigned i)
return a reference to the plot base configuration of the i-th plot
unsigned nr_attributes
number of additional attributes
Definition plot_base.h:342
void prepare_extents()
prepare extents for drawing
virtual void create_gui(cgv::base::base *bp, cgv::gui::provider &p)
create a gui for the plot with gui for all configs
vec3 legend_location
center location of legend in domain coordinates
Definition plot_base.h:368
std::vector< tick_batch_info > tick_batches
twice number of axis pairs with index of first tick label and number of tick labels for primary and s...
Definition plot_base.h:321
void set_extent(const vecn &new_extent)
set the plot extend in 2D coordinates
void set_plot_uniforms(cgv::render::context &ctx, cgv::render::shader_program &prog)
set the uniforms for plot configurations
bool init(cgv::render::context &ctx)
build legend prog and create aab
cgv::media::font::font_face_ptr label_font_face
store pointer to label font face
Definition plot_base.h:419
vec3 extent
extents used for drawing current
Definition plot_base.h:437
renderer that supports point splatting
void set_extent(const context &ctx, const T &extent)
specify a single extent for all boxes
void set_position_is_center(bool _position_is_center)
set the flag, whether the position is interpreted as the box center, true by default
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
virtual std::ostream & output_stream()
returns an output stream whose output is printed at the current cursor location, which is managed by ...
Definition context.cxx:901
virtual void mul_modelview_matrix(const dmat4 &MV)
multiply given matrix from right to current modelview matrix
Definition context.cxx:1808
virtual void set_color(const rgba &clr)
set the current color
Definition context.cxx:1617
virtual unsigned int get_height() const =0
return the height of the window
virtual void enable_font_face(media::font::font_face_ptr font_face, float font_size)
enable the given font face with the given size in pixels
Definition context.cxx:906
virtual void set_cursor(int x, int y)
flush the output_stream and set a new cursor position given in opengl coordinates with (0,...
Definition context.cxx:1959
void pop_modelview_matrix()
see push_V for an explanation
Definition context.cxx:1814
void push_modelview_matrix()
push the current viewing matrix onto a matrix stack for viewing matrices.
Definition context.cxx:1802
void show()
show the drawable
Definition drawable.cxx:26
shader_program & ref_prog()
derived renderer classes have access to shader program
Definition renderer.h:75
void set_color(const context &ctx, const T &color)
templated method to set the color attribute from a single color of type T
Definition renderer.h:189
void set_render_style(const render_style &rs)
reference given render style
Definition renderer.cxx:140
void set_position(const context &ctx, const T &position)
templated method to set the position attribute from a single position of type T
Definition renderer.h:173
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.
Definition renderer.cxx:342
bool enable(context &ctx)
enable the shader program
bool disable(context &ctx)
disable shader program and restore fixed functionality
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,...
void destruct(const context &ctx)
destruct shader program
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...
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.
double get_y_view_angle() const
query opening angle (degrees) of view in y-direction
Definition view.cxx:63
@ TA_BOTTOM
center of bottom edge of text bounds
Definition context.h:278
@ TA_LEFT
center of left edge of text bounds
Definition context.h:275
cone_renderer & ref_cone_renderer(context &ctx, int ref_count_change)
reference to a singleton cone renderer that is shared among drawables
box_renderer & ref_box_renderer(context &ctx, int ref_count_change)
reference to a singleton box renderer that is shared among drawables
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
the cgv namespace
Definition print.h:11
cgv::math::vec< float > vecn
declare type of single precision floating point vector with varying dimension
Definition vec.h:1187
cgv::media::color< float, cgv::media::RGB > rgb
declare rgb color type with 32 bit components
Definition color.h:853
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:669
struct that manages attribute sources and corresponding gpu objects per subplot
Definition plot_base.h:252
store source of a single plot attribute (one coordinate axis or one float attribute)
Definition plot_base.h:228
float reference_size
store size of virtual pixel based measurement
Definition plot_base.h:52
std::vector< axis_config > axis_configs
store a vector of axis configurations (2/3 for plot2/3d plus several attribute axes)
Definition plot_base.h:56
rgb color
color of the domain fill
Definition plot_base.h:48
float blend_width_in_pixel
store blend width in screen pixels used for antialiasing
Definition plot_base.h:54
extend common plot configuration with parameters specific to 2d plot
Definition plot3d.h:23
rgb surface_color
color of faces
Definition plot3d.h:35
PlotFaceIllumination face_illumination
how to illuminate the surface
Definition plot3d.h:37
unsigned samples_per_row
if samples per row > 0, the samples are interpreted as regular grid
Definition plot3d.h:29
void set_colors(const rgb &base_color)
add tube and surface color
Definition plot3d.cxx:9
mapped_size bar_percentual_depth
provide second dimension of bar extend
Definition plot3d.h:27
plot3d_config(const std::string &_name)
construct with default values
Definition plot3d.cxx:28
bool wireframe
whether to turn on wireframe
Definition plot3d.h:33
bool show_line_orientation
whether to illustrate line orientation
Definition plot3d.h:25
bool show_surface
whether to show faces
Definition plot3d.h:31
plot independent configuration parameters of one sub plot in a 2d or 3d plot
Definition plot_base.h:130
int bar_coordinate_index
extended bar information
Definition plot_base.h:188
virtual void set_colors(const rgb &base_color)
set all colors from reference color
Definition plot_base.cxx:84
mapped_size line_width
line width
Definition plot_base.h:166
mapped_size bar_percentual_width
percentual width of bar computed assuming a uniform y-sampling distance
Definition plot_base.h:194
std::string name
name of sub plot
Definition plot_base.h:132
float stick_base_window
base window position of stick
Definition plot_base.h:179
bool show_lines
whether to connect data points with lines
Definition plot_base.h:164
mapped_rgba stick_color
color of the stick line
Definition plot_base.h:183
bool show_bars
whether to show bars
Definition plot_base.h:186
mapped_size bar_outline_width
line width of bar outlines
Definition plot_base.h:192
bool show_points
whether to show data points
Definition plot_base.h:152
mapped_size stick_width
line width of stick
Definition plot_base.h:181
mapped_rgba bar_color
bar fill color
Definition plot_base.h:196
mapped_rgba point_color
point color
Definition plot_base.h:157
int stick_coordinate_index
extended stick information
Definition plot_base.h:177
bool show_plot
whether to show sub plot
Definition plot_base.h:140
bool show_sticks
whether to show straight lines to the bottom of the plot, which are called sticks
Definition plot_base.h:175
mapped_rgba line_color
line color
Definition plot_base.h:168
mapped_size point_halo_width
width of point halo in pixel
Definition plot_base.h:159
mapped_rgba bar_outline_color
bar outline color
Definition plot_base.h:198
mapped_size point_size
point size in pixels
Definition plot_base.h:154
mapped_rgba point_halo_color
color of point halo
Definition plot_base.h:161
CullingMode culling_mode
culling mode for point splats, set to CM_OFF in constructor
ColorMapping map_color_to_material
material side[s] where color is to be mapped to the diffuse material component, defaults to MS_FRONT_...
IlluminationMode illumination_mode
illumination mode defaults to IM_ONE_SIDED
cgv::media::illum::surface_material::color_type surface_color
default value for color when map color to material is used