27#ifndef EASY3D_RENDERER_RENDERER_H
28#define EASY3D_RENDERER_RENDERER_H
34#include <easy3d/core/types.h>
35#include <easy3d/core/point_cloud.h>
36#include <easy3d/core/surface_mesh.h>
43 class TrianglesDrawable;
162 const std::vector<PointsDrawable *> &
points_drawables()
const {
return points_drawables_; }
167 const std::vector<LinesDrawable *> &
lines_drawables()
const {
return lines_drawables_; }
228 template<
typename FT>
243 template<
typename FT>
258 template<
typename FT>
271 std::vector<PointsDrawable *> points_drawables_;
272 std::vector<LinesDrawable *> lines_drawables_;
273 std::vector<TrianglesDrawable *> triangles_drawables_;
283#include <easy3d/core/random.h>
288 template<
typename FT>
inline
292 LOG(WARNING) <<
"model has no valid geometry";
297 LOG(WARNING) <<
"the surface mesh does not have face property \'" << segments.
name() <<
"\'";
301 LOG(WARNING) <<
"color property not allocated";
306 for (
auto f : mesh->
faces())
307 max_index = std::max(max_index,
static_cast<int>(segments[f]));
310 std::vector<vec3> color_table(max_index + 1);
311 for (
auto &c : color_table)
314 for (
auto f : mesh->
faces()) {
315 int idx =
static_cast<int>(segments[f]);
317 colors[f] =
vec3(0, 0, 0);
319 colors[f] = color_table[idx];
324 template<
typename FT>
inline
328 LOG(WARNING) <<
"model has no valid geometry";
333 LOG(WARNING) <<
"the surface mesh does not have vertex property \'" << segments.
name() <<
"\'";
337 LOG(WARNING) <<
"color property not allocated";
343 max_index = std::max(max_index,
static_cast<int>(segments[v]));
346 std::vector<vec3> color_table(max_index + 1);
347 for (
auto &c : color_table)
351 int idx =
static_cast<int>(segments[v]);
353 colors[v] =
vec3(0, 0, 0);
355 colors[v] = color_table[idx];
360 template<
typename FT>
inline
364 if (cloud->
empty()) {
365 LOG(WARNING) <<
"model has no valid geometry";
370 LOG(WARNING) <<
"the point cloud does not have vertex property \'" << segments.
name() <<
"\'";
374 LOG(WARNING) <<
"color property not allocated" <<
"\'";
380 max_index = std::max(max_index,
static_cast<int>(segments[v]));
383 std::vector<vec3> color_table(max_index + 1);
384 for (
auto &c : color_table)
388 int idx =
static_cast<int>(segments[v]);
390 colors[v] =
vec3(0, 0, 0);
392 colors[v] = color_table[idx];
The drawable for rendering a set of line segments, e.g., edges of a mesh, vector fields.
Definition: drawable_lines.h:40
The base class of renderable 3D models.
Definition: model.h:49
bool empty() const
Tests if the model is empty.
Definition: model.h:83
Vertex property of type T.
Definition: point_cloud.h:107
A data structure for point clouds.
Definition: point_cloud.h:45
VertexContainer vertices() const
returns vertex container for C++11 range-based for-loops
Definition: point_cloud.h:444
The drawable for rendering a set of points, e.g., point clouds, vertices of a mesh.
Definition: drawable_points.h:42
const std::string & name() const
Return the name of the property.
Definition: property.h:318
A Renderer manages the drawables (and thus the rendering) of a model.
Definition: renderer.h:61
const std::vector< TrianglesDrawable * > & triangles_drawables() const
Definition: renderer.h:172
LinesDrawable * get_lines_drawable(const std::string &name) const
Definition: renderer.cpp:295
static void create_default_drawables(Model *model)
Create default drawables for rendering.
Definition: renderer.cpp:61
Model * model()
The model to which this renderer is attached.
Definition: renderer.h:89
bool is_visible() const
Returns whether the model is currently visible.
Definition: renderer.h:94
PointsDrawable * add_points_drawable(const std::string &name)
Definition: renderer.cpp:313
LinesDrawable * add_lines_drawable(const std::string &name)
Definition: renderer.cpp:327
TrianglesDrawable * add_triangles_drawable(const std::string &name)
Definition: renderer.cpp:346
Renderer(Model *model, bool create_drawables=true)
Constructor.
Definition: renderer.cpp:40
const std::vector< LinesDrawable * > & lines_drawables() const
Definition: renderer.h:167
void set_selected(bool b)
Select/Deselect the model. The state of all its drawables will change accordingly.
Definition: renderer.cpp:265
PointsDrawable * get_points_drawable(const std::string &name) const
Definition: renderer.cpp:286
TrianglesDrawable * get_triangles_drawable(const std::string &name) const
Definition: renderer.cpp:304
const std::vector< PointsDrawable * > & points_drawables() const
Definition: renderer.h:162
static void set_default_rendering_state(PointCloud *model, PointsDrawable *drawable)
Set the default rendering state of the "vertices" drawable of a point cloud.
Definition: renderer.cpp:159
bool is_selected() const
Returns whether the model has been selected.
Definition: renderer.h:100
void set_visible(bool b)
Shows/Hides the model.
Definition: renderer.h:97
void update()
Invalidates the rendering buffers of the model and thus updates the rendering (delayed in rendering).
Definition: renderer.cpp:276
static void color_from_segmentation(SurfaceMesh *mesh, SurfaceMesh::FaceProperty< FT > segments, SurfaceMesh::FaceProperty< vec3 > colors)
Generates random colors for visualizing face-based segmentation of a SurfaceMesh.
Definition: renderer.h:289
Definition: surface_mesh.h:257
Definition: surface_mesh.h:185
A halfedge data structure for polygonal meshes of 2-manifold.
Definition: surface_mesh.h:52
VertexContainer vertices() const
returns vertex container for C++11 range-based for-loops
Definition: surface_mesh.h:1631
FaceContainer faces() const
returns face container for C++11 range-based for-loops
Definition: surface_mesh.h:1685
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition: drawable_triangles.h:46
Definition: collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition: types.h:45
vec3 random_color(bool allow_dark=false)
Generates a random color. The parameter allow_dark controls if too dark colors are allowed.
Definition: random.h:49