Easy3D 2.6.1
Loading...
Searching...
No Matches
State Class Reference

Class representing the rendering state of a drawable. More...

#include <easy3d/renderer/state.h>

Inheritance diagram for State:
Drawable LinesDrawable LinesDrawable2D PointsDrawable TrianglesDrawable

Classes

struct  Material
 

Public Types

enum  Method { UNIFORM_COLOR , COLOR_PROPERTY , SCALAR_FIELD , TEXTURED }
 Available coloring methods. More...
 
enum  Location { VERTEX , FACE , EDGE , HALFEDGE }
 The location of a coloring property. More...
 

Public Member Functions

 State ()
 Default constructor.
 
 State (const State &s)
 Copy constructor.
 
Stateoperator= (const State &rhs)
 Assignment operator.
 
virtual ~State ()=default
 Virtual destructor.
 
bool is_visible () const
 Checks if the drawable is visible.
 
void set_visible (bool v)
 Sets the visibility of the drawable.
 
bool is_selected () const
 Checks if the drawable is selected.
 
void set_selected (bool b)
 Sets the selection state of the drawable.
 

Coloring

void set_uniform_coloring (const vec4 &color)
 Constructs a uniform coloring scheme.
 
void set_property_coloring (Location color_location, const std::string &color_name="")
 Constructs a scheme for rendering a drawable with per-element color.
 
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.
 
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.
 
void set_coloring (Method method, Location location, const std::string &name)
 Sets the coloring.
 
void set_coloring_method (Method method)
 Sets the coloring method.
 
Method coloring_method () const
 Returns the coloring method being used for rendering.
 
const vec4color () const
 Returns the color, which is effective only when the coloring method was set to UNIFORM_COLOR.
 
void set_color (const vec4 &c)
 Sets the color.
 
Location property_location () const
 Returns the location of the color property.
 
const std::string & property_name () const
 Returns the name of the color attribute.
 
bool lighting () const
 Checks if lighting is enabled.
 
void set_lighting (bool l)
 Enables or disables lighting.
 
bool lighting_two_sides () const
 Checks if double-sided lighting is enabled.
 
void set_lighting_two_sides (bool b)
 Enables or disables double-sided lighting.
 
bool distinct_back_color () const
 Checks if a different color is used for rendering the backside of a drawable.
 
void set_distinct_back_color (bool b)
 Enables or disables different backside color.
 
const vec4back_color () const
 Returns the backside color.
 
void set_back_color (const vec4 &c)
 Sets the backside color.
 
const Texturetexture () const
 Returns the texture.
 
void set_texture (const Texture *tex)
 Sets the texture.
 
float texture_repeat () const
 Returns the repeat factor of the texture.
 
void set_texture_repeat (float r)
 Sets the repeat factor of the texture.
 
float texture_fractional_repeat () const
 Returns the fractional repeat factor of the texture.
 
void set_texture_fractional_repeat (float fr)
 Sets the fractional repeat factor of the texture.
 
bool is_ssao_enabled () const
 Checks if SSAO is enabled.
 
void enable_ssao (bool b)
 Enables or disables SSAO.
 
void set_ssao_texture (unsigned int tex)
 Sets the SSAO texture.
 
bool clamp_range () const
 Checks if the value range of a scalar field is clamped.
 
void set_clamp_range (bool b)
 Sets the clamping of the value range of a scalar field.
 
float clamp_lower () const
 Returns the percentage of values clamped at the lower side of the range.
 
void set_clamp_lower (float v)
 Sets the percentage of values clamped at the lower side of the range.
 
float clamp_upper () const
 Returns the percentage of values clamped at the upper side of the range.
 
void set_clamp_upper (float v)
 Sets the percentage of values clamped at the upper side of the range.
 
Materialmaterial ()
 Returns the material.
 
const Materialmaterial () const
 Returns the material (const version).
 
void set_material (const Material &m)
 Sets the material.
 
bool plane_clip_discard_primitive () const
 Controls the behavior for vertex clipping.
 
void set_plane_clip_discard_primitive (bool b)
 Sets the behavior for vertex clipping.
 
bool highlight () const
 Checks if a subset of primitives of this drawable is highlighted.
 
void set_highlight (bool b)
 Sets the highlight state of a subset of primitives of this drawable.
 
void set_highlight_range (const std::pair< int, int > &range)
 Sets the range of primitives to be highlighted.
 
const std::pair< int, int > & highlight_range () const
 Returns the range of primitives to be highlighted.
 

Detailed Description

Class representing the rendering state of a drawable.

Member Enumeration Documentation

◆ Location

enum Location

The location of a coloring property.

It is denoted by the type of the geometric primitives on which the property is defined.

Enumerator
VERTEX 

Property defined on vertices.

FACE 

Property defined on faces.

EDGE 

Property defined on edges.

HALFEDGE 

Property defined on halfedges.

◆ Method

enum Method

Available coloring methods.

A complete description of a color scheme contains the coloring method, and (if not uniform color) the location and name of a property. Possible properties for coloring a drawable:

  • color properties defined on vertices, faces, or edges. A color property is specified by its name, e.g., "v:color", "f:color", "e:color";
  • scalar fields defined on vertices, faces, or edges. A scalar field is specified by its name, e.g., "v:curvature", "v:height", "f:segment_id";
  • texture coordinates defined on vertices or halfedges. A texture coordinates property is specified by its name, e.g., "v:texcoord", "h:texcoord".
Enumerator
UNIFORM_COLOR 

Uniformly colored.

COLOR_PROPERTY 

Using a color property.

SCALAR_FIELD 

Using a scalar field.

TEXTURED 

Using texture(s)

Constructor & Destructor Documentation

◆ State() [1/2]

State ( )

Default constructor.

Initializes the State object with default values.

◆ State() [2/2]

State ( const State & s)

Copy constructor.

Parameters
sThe State object to copy from.

Creates a new State object as a copy of the given State object.

Member Function Documentation

◆ back_color()

const vec4 & back_color ( ) const
inline

Returns the backside color.

Effective only when two-sides lighting and distinct back color are enabled.

Returns
The backside color.

◆ clamp_lower()

float clamp_lower ( ) const
inline

Returns the percentage of values clamped at the lower side of the range.

Value is in [0, 1] (i.e., 0% to 100%).

Returns
The percentage of values clamped at the lower side.

◆ clamp_range()

bool clamp_range ( ) const
inline

Checks if the value range of a scalar field is clamped.

Returns
true if the value range is clamped, false otherwise.

◆ clamp_upper()

float clamp_upper ( ) const
inline

Returns the percentage of values clamped at the upper side of the range.

Value is in [0, 1] (i.e., 0% to 100%).

Returns
The percentage of values clamped at the upper side.

◆ color()

const vec4 & color ( ) const
inline

Returns the color, which is effective only when the coloring method was set to UNIFORM_COLOR.

Returns
The color.

◆ coloring_method()

Method coloring_method ( ) const
inline

Returns the coloring method being used for rendering.

Returns
The coloring method.

◆ distinct_back_color()

bool distinct_back_color ( ) const
inline

Checks if a different color is used for rendering the backside of a drawable.

Effective only when two-sides lighting is enabled.

Returns
true if a different backside color is used, false otherwise.

◆ enable_ssao()

void enable_ssao ( bool b)
inline

Enables or disables SSAO.

Parameters
btrue to enable SSAO, false to disable.

◆ highlight()

bool highlight ( ) const
inline

Checks if a subset of primitives of this drawable is highlighted.

Returns
true if highlighted, false otherwise.

◆ highlight_range()

const std::pair< int, int > & highlight_range ( ) const
inline

Returns the range of primitives to be highlighted.

Primitives with indices within the range will be highlighted.

Returns
The range of primitives to be highlighted.

◆ is_selected()

bool is_selected ( ) const
inline

Checks if the drawable is selected.

Returns
true if selected, false otherwise.

◆ is_ssao_enabled()

bool is_ssao_enabled ( ) const
inline

Checks if SSAO is enabled.

Returns
true if SSAO is enabled, false otherwise.

◆ is_visible()

bool is_visible ( ) const
inline

Checks if the drawable is visible.

Returns
true if visible, false otherwise.

◆ lighting()

bool lighting ( ) const
inline

Checks if lighting is enabled.

Returns
true if lighting is enabled, false otherwise.

◆ lighting_two_sides()

bool lighting_two_sides ( ) const
inline

Checks if double-sided lighting is enabled.

Returns
true if double-sided lighting is enabled, false otherwise.

◆ material() [1/2]

Material & material ( )
inline

Returns the material.

Returns
The material.

◆ material() [2/2]

const Material & material ( ) const
inline

Returns the material (const version).

Returns
The material.

◆ operator=()

State & operator= ( const State & rhs)

Assignment operator.

Parameters
rhsThe State object to assign from.
Returns
A reference to this State object.

Performs a deep copy of all member variables from the given State object.

◆ plane_clip_discard_primitive()

bool plane_clip_discard_primitive ( ) const
inline

Controls the behavior for vertex clipping.

If plane_clip_discard_primitive() is false (default value, standard plane clip), the clip distances will be linearly interpolated across the primitive (e.g., line, triangle) and the portion of the primitive with interpolated distances less than 0.0 will be clipped. If plane_clip_discard_primitive() is true, a primitive will be completely discarded if one of its vertices has a negative clip distance.

Returns
true if the primitive is discarded, false otherwise.

◆ property_location()

Location property_location ( ) const
inline

Returns the location of the color property.

Returns
The location of the color property.

◆ property_name()

const std::string & property_name ( ) const
inline

Returns the name of the color attribute.

Returns
The name of the color attribute.

◆ set_back_color()

void set_back_color ( const vec4 & c)
inline

Sets the backside color.

Effective only when two-sides lighting and distinct back color are enabled.

Parameters
cThe backside color.

◆ set_clamp_lower()

void set_clamp_lower ( float v)
inline

Sets the percentage of values clamped at the lower side of the range.

Value is in [0, 1] (i.e., 0% to 100%).

Parameters
vThe percentage of values clamped at the lower side.

◆ set_clamp_range()

void set_clamp_range ( bool b)
inline

Sets the clamping of the value range of a scalar field.

Parameters
btrue to clamp the value range, false to disable clamping.

◆ set_clamp_upper()

void set_clamp_upper ( float v)
inline

Sets the percentage of values clamped at the upper side of the range.

Value is in [0, 1] (i.e., 0% to 100%).

Parameters
vThe percentage of values clamped at the upper side.

◆ set_color()

void set_color ( const vec4 & c)
inline

Sets the color.

Parameters
cThe color.

◆ set_coloring()

void set_coloring ( Method method,
Location location,
const std::string & name )

Sets the coloring.

A generic version of the set_[method]_coloring() method.

Parameters
methodThe coloring method.
locationThe location of the coloring property.
nameThe name of the coloring property.

◆ set_coloring_method()

void set_coloring_method ( Method method)
inline

Sets the coloring method.

It has the same effect as if set_coloring() is called without changing the location (2nd argument) and name (3rd argument) of the coloring property.

Parameters
methodThe coloring method.

◆ set_distinct_back_color()

void set_distinct_back_color ( bool b)
inline

Enables or disables different backside color.

Effective only when two-sides lighting is enabled.

Parameters
btrue to enable different backside color, false to disable.

◆ set_highlight()

void set_highlight ( bool b)
inline

Sets the highlight state of a subset of primitives of this drawable.

Parameters
btrue to highlight, false to un-highlight.

◆ set_highlight_range()

void set_highlight_range ( const std::pair< int, int > & range)
inline

Sets the range of primitives to be highlighted.

Primitives with indices within the range will be highlighted.

Parameters
rangeSpecifies the min and max indices of the primitives to be highlighted. Providing [-1, -1] will un-highlight any previously highlighted primitives.
Attention
For non-triangular surface meshes, all polygonal faces are internally triangulated to allow a unified rendering APIs. The range must be given on the triangulated faces! If you have face range, you should convert the face range to triangle range. For each face, its triangles are defined on SurfaceMesh::face_property<std::pair<int, int> >("f:triangle_range").

◆ set_lighting()

void set_lighting ( bool l)
inline

Enables or disables lighting.

Parameters
ltrue to enable lighting, false to disable.

◆ set_lighting_two_sides()

void set_lighting_two_sides ( bool b)
inline

Enables or disables double-sided lighting.

Parameters
btrue to enable double-sided lighting, false to disable.

◆ set_material()

void set_material ( const Material & m)
inline

Sets the material.

Parameters
mThe material.

◆ set_plane_clip_discard_primitive()

void set_plane_clip_discard_primitive ( bool b)
inline

Sets the behavior for vertex clipping.

If plane_clip_discard_primitive() is false (default value, standard plane clip), the clip distances will be linearly interpolated across the primitive (e.g., line, triangle) and the portion of the primitive with interpolated distances less than 0.0 will be clipped. If plane_clip_discard_primitive() is true, a primitive will be completely discarded if one of its vertices has a negative clip distance.

Parameters
btrue to discard the primitive, false otherwise.

◆ set_property_coloring()

void set_property_coloring ( Location color_location,
const std::string & color_name = "" )

Constructs a scheme for rendering a drawable with per-element color.

Parameters
color_locationThe location of the color property.
color_nameThe name of the color property.
Examples
Tutorial_310_TextMesher/main.cpp.

◆ set_scalar_coloring()

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.

Parameters
scalar_locationThe location of the scalar field.
scalar_nameThe name of the scalar field.
textureThe pointer to the texture. Default is nullptr, a scalar default texture will be created from "/colormaps/default.png". Client code can provide a more suitable texture at a later stage.
clamp_lowerThe percentage of values to be clamped at the lower side of the range. Default is 5%.
clamp_upperThe percentage of values to be clamped at the upper side of the range. Default is 5%.

◆ set_selected()

void set_selected ( bool b)
inline

Sets the selection state of the drawable.

Parameters
btrue to select, false to deselect.

◆ set_ssao_texture()

void set_ssao_texture ( unsigned int tex)
inline

Sets the SSAO texture.

Parameters
texThe SSAO texture.

◆ set_texture()

void set_texture ( const Texture * tex)
inline

Sets the texture.

Parameters
texThe texture.

◆ set_texture_coloring()

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.

Parameters
texcoord_locationThe location of texture coordinate.
texcoord_nameThe name of the texture coordinate property.
textureThe pointer to the texture. If nullptr, a default texture will be created from "textures/checkerboard.png". Client code is expected to provide a meaningful texture at a later stage.
repeatThe repeat factor of the texture. Default value is 1.0.
repeat_fractionThe fractional repeat factor of the texture. Default value is 0.0.

◆ set_texture_fractional_repeat()

void set_texture_fractional_repeat ( float fr)
inline

Sets the fractional repeat factor of the texture.

Controls the texture repeat at a finer level: 100 fractional repeat == 1 repeat.

Parameters
frThe fractional repeat factor.

◆ set_texture_repeat()

void set_texture_repeat ( float r)
inline

Sets the repeat factor of the texture.

Parameters
rThe repeat factor.

◆ set_uniform_coloring()

void set_uniform_coloring ( const vec4 & color)

Constructs a uniform coloring scheme.

Parameters
colorThe color.

◆ set_visible()

void set_visible ( bool v)
inline

Sets the visibility of the drawable.

Parameters
vtrue to make visible, false to hide.

◆ texture()

const Texture * texture ( ) const
inline

Returns the texture.

Memory management of textures is the user's responsibility.

Returns
The texture.

◆ texture_fractional_repeat()

float texture_fractional_repeat ( ) const
inline

Returns the fractional repeat factor of the texture.

Controls the texture repeat at a finer level: 100 fractional repeat == 1 repeat.

Returns
The fractional repeat factor.

◆ texture_repeat()

float texture_repeat ( ) const
inline

Returns the repeat factor of the texture.

Returns
The repeat factor.

The documentation for this class was generated from the following files: