Easy3D 2.6.1
Loading...
Searching...
No Matches
state.h
1/********************************************************************
2 * Copyright (C) 2015 Liangliang Nan <liangliang.nan@gmail.com>
3 * https://3d.bk.tudelft.nl/liangliang/
4 *
5 * This file is part of Easy3D. If it is useful in your research/work,
6 * I would be grateful if you show your appreciation by citing it:
7 * ------------------------------------------------------------------
8 * Liangliang Nan.
9 * Easy3D: a lightweight, easy-to-use, and efficient C++ library
10 * for processing and rendering 3D data.
11 * Journal of Open Source Software, 6(64), 3255, 2021.
12 * ------------------------------------------------------------------
13 *
14 * Easy3D is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License Version 3
16 * as published by the Free Software Foundation.
17 *
18 * Easy3D is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 ********************************************************************/
26
27#ifndef EASY3D_RENDERER_STATE_H
28#define EASY3D_RENDERER_STATE_H
29
30#include <string>
31
32#include <easy3d/core/types.h>
33
34
35namespace easy3d {
36
37 class Texture;
38
43 class State {
44 public:
45
63
74
78 struct Material {
83 Material() = default;
91 Material(const vec4 &ambi, const vec4 &spec, float shin);
92
94 //vec3 diffuse; // we have per face/point/line color!
96 float shininess;
97 };
98
99 public:
104 State();
110 State(const State& s);
117 State& operator=(const State& rhs);
121 virtual ~State() = default;
122
127 bool is_visible() const { return visible_; }
132 void set_visible(bool v) { visible_ = v; }
133
138 bool is_selected() const { return selected_; }
143 void set_selected(bool b) { selected_ = b; }
144
146
147
152 void set_uniform_coloring(const vec4 &color);
153
159 void set_property_coloring(Location color_location, const std::string &color_name = "");
160
170 void set_texture_coloring(Location texcoord_location, const std::string &texcoord_name,
171 const Texture *texture = nullptr, float repeat = 1.0f,
172 float repeat_fraction = 0.0f);
173
183 void set_scalar_coloring(Location scalar_location, const std::string &scalar_name,
184 const Texture *texture = nullptr, float clamp_lower = 0.05f,
185 float clamp_upper = 0.05f);
186
194 void set_coloring(Method method, Location location, const std::string &name);
195
202 void set_coloring_method(Method method) { coloring_method_ = method; }
207 Method coloring_method() const { return coloring_method_; }
208
213 const vec4 &color() const { return color_; }
218 void set_color(const vec4& c) { color_ = c; }
219
224 Location property_location() const { return property_location_; }
225
230 const std::string &property_name() const { return property_name_; }
231
233
238 bool lighting() const { return lighting_; }
243 void set_lighting(bool l) { lighting_ = l; }
244
249 bool lighting_two_sides() const { return lighting_two_sides_; }
254 void set_lighting_two_sides(bool b) { lighting_two_sides_ = b; }
255
261 bool distinct_back_color() const { return distinct_back_color_; }
267 void set_distinct_back_color(bool b) { distinct_back_color_ = b; }
268
274 const vec4 &back_color() const { return back_color_; }
280 void set_back_color(const vec4 &c) { back_color_ = c; }
281
287 const Texture *texture() const { return texture_; }
292 void set_texture(const Texture *tex) { texture_ = tex; }
293
298 float texture_repeat() const { return texture_repeat_; }
303 void set_texture_repeat(float r) { texture_repeat_ = r; }
304
310 float texture_fractional_repeat() const { return texture_fractional_repeat_; }
316 void set_texture_fractional_repeat(float fr) { texture_fractional_repeat_ = fr; }
317
322 bool is_ssao_enabled() const { return ssao_enabled_; }
327 void enable_ssao(bool b) { ssao_enabled_ = b; }
332 void set_ssao_texture(unsigned int tex) { ssao_texture_ = tex; }
333
338 bool clamp_range() const { return clamp_range_; }
343 void set_clamp_range(bool b) { clamp_range_ = b; }
344
350 float clamp_lower() const { return clamp_lower_; }
356 void set_clamp_lower(float v) { clamp_lower_ = v; }
357
363 float clamp_upper() const { return clamp_upper_; }
369 void set_clamp_upper(float v) { clamp_upper_ = v; }
370
375 Material &material() { return material_; }
380 const Material &material() const { return material_; }
385 void set_material(const Material &m) { material_ = m; }
386
396 bool plane_clip_discard_primitive() const { return plane_clip_discard_primitive_; }
406 void set_plane_clip_discard_primitive(bool b) { plane_clip_discard_primitive_ = b; }
407
412 bool highlight() const { return highlight_; }
417 void set_highlight(bool b) { highlight_ = b; }
428 void set_highlight_range(const std::pair<int, int> &range) { highlight_range_ = range; }
434 const std::pair<int, int> &highlight_range() const { return highlight_range_; }
435
436 protected:
437 // Create a default texture.
438 // Default texture file: "/textures/checkerboard.png";
439 Texture* create_color_texture();
440
441 // Create a default texture for rendering scalar fields.
442 // Default texture file: "/colormaps/default.png";
443 Texture* create_scalar_texture();
444
445 protected:
446 bool visible_;
447 bool selected_;
448
449 Method coloring_method_;
450 vec4 color_; // valid when color method is UNIFORM_COLOR
451 Location property_location_;
452 std::string property_name_;
453
454 bool lighting_;
455
456 bool lighting_two_sides_;
457 bool distinct_back_color_;
458 vec4 back_color_;
459
460 // texture
461 const Texture *texture_;
462 // How many times do you want to repeat the texture?
463 float texture_repeat_;
464 // Control at a finer level: 100 fractional repeat == 1 repeat.
465 float texture_fractional_repeat_;
466
467 bool ssao_enabled_;
468 unsigned int ssao_texture_;
469
470 bool clamp_range_;
471 float clamp_lower_;
472 float clamp_upper_;
473
474 Material material_;
475
476 // Clipping plane behavior.
477 // - true: completely discard a primitive if one of its vertices has a negative clip distance
478 // - false: linearly interpolated (standard plane clipping behavior)
479 bool plane_clip_discard_primitive_;
480
481 // highlight the primitives within the range [highlight_id_low_, highlight_id_high_]
482 bool highlight_;
483 std::pair<int, int> highlight_range_;
484 };
485
486}
487
488
489#endif // EASY3D_RENDERER_STATE_H
void set_lighting(bool l)
Enables or disables lighting.
Definition state.h:243
void set_texture_fractional_repeat(float fr)
Sets the fractional repeat factor of the texture.
Definition state.h:316
Location property_location() const
Returns the location of the color property.
Definition state.h:224
void set_highlight(bool b)
Sets the highlight state of a subset of primitives of this drawable.
Definition state.h:417
Method
Available coloring methods.
Definition state.h:57
@ TEXTURED
Using texture(s)
Definition state.h:61
@ UNIFORM_COLOR
Uniformly colored.
Definition state.h:58
@ COLOR_PROPERTY
Using a color property.
Definition state.h:59
@ SCALAR_FIELD
Using a scalar field.
Definition state.h:60
void set_scalar_coloring(Location scalar_location, const std::string &scalar_name, const Texture *texture=nullptr, float clamp_lower=0.05f, float clamp_upper=0.05f)
Constructs a scheme for rendering scalar fields.
Definition state.cpp:125
void set_ssao_texture(unsigned int tex)
Sets the SSAO texture.
Definition state.h:332
Method coloring_method() const
Returns the coloring method being used for rendering.
Definition state.h:207
float clamp_lower() const
Returns the percentage of values clamped at the lower side of the range.
Definition state.h:350
bool is_visible() const
Checks if the drawable is visible.
Definition state.h:127
State & operator=(const State &rhs)
Assignment operator.
Definition state.cpp:67
const vec4 & color() const
Returns the color, which is effective only when the coloring method was set to UNIFORM_COLOR.
Definition state.h:213
float clamp_upper() const
Returns the percentage of values clamped at the upper side of the range.
Definition state.h:363
const std::pair< int, int > & highlight_range() const
Returns the range of primitives to be highlighted.
Definition state.h:434
bool distinct_back_color() const
Checks if a different color is used for rendering the backside of a drawable.
Definition state.h:261
void set_uniform_coloring(const vec4 &color)
Constructs a uniform coloring scheme.
Definition state.cpp:92
float texture_repeat() const
Returns the repeat factor of the texture.
Definition state.h:298
bool is_ssao_enabled() const
Checks if SSAO is enabled.
Definition state.h:322
bool highlight() const
Checks if a subset of primitives of this drawable is highlighted.
Definition state.h:412
void set_clamp_lower(float v)
Sets the percentage of values clamped at the lower side of the range.
Definition state.h:356
void set_clamp_upper(float v)
Sets the percentage of values clamped at the upper side of the range.
Definition state.h:369
void set_texture_coloring(Location texcoord_location, const std::string &texcoord_name, const Texture *texture=nullptr, float repeat=1.0f, float repeat_fraction=0.0f)
Constructs a scheme for textured rendering.
Definition state.cpp:107
State()
Default constructor.
Definition state.cpp:42
float texture_fractional_repeat() const
Returns the fractional repeat factor of the texture.
Definition state.h:310
const vec4 & back_color() const
Returns the backside color.
Definition state.h:274
void set_clamp_range(bool b)
Sets the clamping of the value range of a scalar field.
Definition state.h:343
void set_visible(bool v)
Sets the visibility of the drawable.
Definition state.h:132
virtual ~State()=default
Virtual destructor.
void set_back_color(const vec4 &c)
Sets the backside color.
Definition state.h:280
void set_selected(bool b)
Sets the selection state of the drawable.
Definition state.h:143
const std::string & property_name() const
Returns the name of the color attribute.
Definition state.h:230
void set_coloring(Method method, Location location, const std::string &name)
Sets the coloring.
Definition state.cpp:141
bool lighting() const
Checks if lighting is enabled.
Definition state.h:238
bool plane_clip_discard_primitive() const
Controls the behavior for vertex clipping.
Definition state.h:396
void set_color(const vec4 &c)
Sets the color.
Definition state.h:218
void set_property_coloring(Location color_location, const std::string &color_name="")
Constructs a scheme for rendering a drawable with per-element color.
Definition state.cpp:100
void set_highlight_range(const std::pair< int, int > &range)
Sets the range of primitives to be highlighted.
Definition state.h:428
const Texture * texture() const
Returns the texture.
Definition state.h:287
bool lighting_two_sides() const
Checks if double-sided lighting is enabled.
Definition state.h:249
bool clamp_range() const
Checks if the value range of a scalar field is clamped.
Definition state.h:338
Material & material()
Returns the material.
Definition state.h:375
void set_distinct_back_color(bool b)
Enables or disables different backside color.
Definition state.h:267
bool is_selected() const
Checks if the drawable is selected.
Definition state.h:138
void set_material(const Material &m)
Sets the material.
Definition state.h:385
void set_texture(const Texture *tex)
Sets the texture.
Definition state.h:292
void set_coloring_method(Method method)
Sets the coloring method.
Definition state.h:202
const Material & material() const
Returns the material (const version).
Definition state.h:380
void set_texture_repeat(float r)
Sets the repeat factor of the texture.
Definition state.h:303
Location
The location of a coloring property.
Definition state.h:68
@ VERTEX
Property defined on vertices.
Definition state.h:69
@ FACE
Property defined on faces.
Definition state.h:70
@ HALFEDGE
Property defined on halfedges.
Definition state.h:72
@ EDGE
Property defined on edges.
Definition state.h:71
void set_lighting_two_sides(bool b)
Enables or disables double-sided lighting.
Definition state.h:254
void set_plane_clip_discard_primitive(bool b)
Sets the behavior for vertex clipping.
Definition state.h:406
void enable_ssao(bool b)
Enables or disables SSAO.
Definition state.h:327
OpenGL texture.
Definition texture.h:42
Definition collider.cpp:182
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46
Definition state.h:78
vec4 specular
Specular color.
Definition state.h:95
float shininess
Specular power.
Definition state.h:96
vec4 ambient
Ambient color.
Definition state.h:93
Material()=default
Default constructor.