cgv
Loading...
Searching...
No Matches
line_render_data.h
1#pragma once
2
3#include "line_renderer.h"
4#include "render_data_base.h"
5
6namespace cgv {
7namespace render {
8
11template <typename ColorType = rgb>
12class line_render_data : public render_data_base<line_renderer, line_render_style, ColorType> {
13private:
14 // Base class we're going to use virtual functions from
16
17 line_renderer& ref_renderer_singleton(context& ctx, int ref_count_change = 0) override {
18 return ref_line_renderer(ctx, ref_count_change);
19 }
20
21protected:
23 bool transfer(context& ctx, line_renderer& r) override {
24 if(super::transfer(ctx, r)) {
25 CGV_RDB_TRANSFER_ARRAY(normal, normals);
26 CGV_RDB_TRANSFER_ARRAY(line_width, widths);
27 return true;
28 }
29 return false;
30 }
31
32public:
34 std::vector<vec3> normals;
36 std::vector<float> widths;
37
38 void clear() {
40 normals.clear();
41 widths.clear();
42 }
43
44 void add_normal(const vec3& normal) {
45 normals.push_back(normal);
46 }
47
48 void add_width(const float width) {
49 widths.push_back(width);
50 }
51
52 void add_segment_normal(const vec3& normal) {
53 add_normal(normal);
54 add_normal(normal);
55 }
56
57 void add_segment_width(const float width) {
58 add_width(width);
59 add_width(width);
60 }
61
62 void add_segment_color(const ColorType& color) {
63 super::add_color(color);
64 super::add_color(color);
65 }
66
67 // Explicitly use add from the base class since it is shadowed by the overloaded versions
68 using super::add;
69
70 void add(const vec3& start_position, const vec3& end_position) {
71 super::add_position(start_position);
72 super::add_position(end_position);
73 }
74
75 void add(const vec3& start_position, const vec3& end_position, const ColorType& color) {
76 add(start_position, end_position);
77 add_segment_color(color);
78 }
79
80 void add(const vec3& start_position, const vec3& end_position, const vec3& normal) {
81 add(start_position, end_position);
82 add_segment_normal(normal);
83 }
84
85 void add(const vec3& start_position, const vec3& end_position, const float width) {
86 add(start_position, end_position);
87 add_segment_width(width);
88 }
89
90 void add(const vec3& start_position, const vec3& end_position, const ColorType& color, const float width) {
91 add(start_position, end_position);
92 add_segment_color(color);
93 add_segment_width(width);
94 }
95
96 void add(const float start_width, const float end_width) {
97 add_width(start_width);
98 add_width(end_width);
99 }
100
101 void add(const ColorType& start_color, const ColorType& end_color) {
102 super::add_color(start_color);
103 super::add_color(end_color);
104 }
105
106 void fill_normals(const vec3& normal) {
107 super::fill(normals, normal);
108 }
109
110 void fill_widths(const float width) {
111 super::fill(widths, width);
112 }
113};
114
115}
116}
base class for all drawables, which is independent of the used rendering API.
Definition context.h:621
Render data for line geometry with support for the line_renderer.
std::vector< float > widths
array of widths
bool transfer(context &ctx, line_renderer &r) override
See render_data_base::transfer.
std::vector< vec3 > normals
array of normals
renderer that supports point splatting
A base class for storing render data and style usable with the default renderers provided in the cgv:...
virtual bool transfer(context &ctx, RendererType &r)
Transfers the data stored in members to the attribute array.
void clear()
Clear the stored data and set state out of date.
void fill(std::vector< T > &vector, const T &value)
Template for filling a member array to the size of the render data.
the cgv namespace
Definition print.h:11
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:669