Drawables are typically for rendering 3D models (e.g., point clouds, meshes, graphs) that are loaded from files or generated by some algorithms. The use of drawables for visualization is quite flexible. Drawables are normally attached to a 3D model. For example, you can attach a TrianglesDrawable to a surface mesh to visualize its surface and a PointsDrawable to visualize its vertices. Easy3D also allows visualizing stand-alone drawables (without creating a model).
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/renderer/drawable_lines.h>
29#include <easy3d/renderer/drawable_points.h>
30#include <easy3d/renderer/drawable_triangles.h>
31#include <easy3d/core/types.h>
32#include <easy3d/util/resource.h>
33#include <easy3d/util/initializer.h>
60int main(
int argc,
char **argv) {
68 Viewer viewer(EXAMPLE_TITLE);
76 const std::vector<vec3> &points = resource::bunny_vertices;
79 const std::vector<unsigned int> &indices = resource::bunny_indices;
86 surface->update_vertex_buffer(points);
88 surface->update_element_buffer(indices);
90 viewer.add_drawable(std::shared_ptr<TrianglesDrawable>(surface));
97 vertices->update_vertex_buffer(points);
99 vertices->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
105 vertices->set_impostor_type(PointsDrawable::SPHERE);
107 vertices->set_point_size(10);
109 viewer.add_drawable(std::shared_ptr<PointsDrawable>(vertices));
116 const Box3 &box = geom::bounding_box<Box3, std::vector<vec3> >(points);
124 const std::vector<vec3> bbox_points = {
125 vec3(xmin, ymin, zmax),
vec3(xmax, ymin, zmax),
126 vec3(xmin, ymax, zmax),
vec3(xmax, ymax, zmax),
127 vec3(xmin, ymin, zmin),
vec3(xmax, ymin, zmin),
128 vec3(xmin, ymax, zmin),
vec3(xmax, ymax, zmin)
131 const std::vector<unsigned int> bbox_indices = {
132 0, 1, 2, 3, 4, 5, 6, 7,
133 0, 2, 4, 6, 1, 3, 5, 7,
134 0, 4, 2, 6, 1, 5, 3, 7
137 bbox_drawable->update_vertex_buffer(bbox_points);
139 bbox_drawable->update_element_buffer(bbox_indices);
141 bbox_drawable->set_uniform_coloring(
vec4(0.0f, 0.0f, 1.0f, 1.0f));
143 bbox_drawable->set_line_width(5.0f);
145 viewer.add_drawable(std::shared_ptr<LinesDrawable>(bbox_drawable));
158int main(
int argc,
char **argv) {
166 Viewer viewer(EXAMPLE_TITLE);
167 viewer.set_usage(
"");
174 const std::vector<vec3> &points = resource::bunny_vertices;
177 const std::vector<unsigned int> &indices = resource::bunny_indices;
183 surface->set_update_func([&points, &indices](
Model* m,
Drawable* d) {
191 viewer.add_drawable(std::shared_ptr<TrianglesDrawable>(surface));
203 vertices->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
209 vertices->set_impostor_type(PointsDrawable::SPHERE);
211 vertices->set_point_size(10);
213 viewer.add_drawable(std::shared_ptr<PointsDrawable>(vertices));
220 bbox_drawable->set_update_func([&points](
Model* m,
Drawable* d) {
221 const Box3 &box = geom::bounding_box<Box3, std::vector<vec3> >(points);
229 const std::vector<vec3> bbox_points = {
230 vec3(xmin, ymin, zmax),
vec3(xmax, ymin, zmax),
231 vec3(xmin, ymax, zmax),
vec3(xmax, ymax, zmax),
232 vec3(xmin, ymin, zmin),
vec3(xmax, ymin, zmin),
233 vec3(xmin, ymax, zmin),
vec3(xmax, ymax, zmin)
236 const std::vector<unsigned int> bbox_indices = {
237 0, 1, 2, 3, 4, 5, 6, 7,
238 0, 2, 4, 6, 1, 3, 5, 7,
239 0, 4, 2, 6, 1, 5, 3, 7
249 bbox_drawable->set_uniform_coloring(
vec4(0.0f, 0.0f, 1.0f, 1.0f));
251 bbox_drawable->set_line_width(5.0f);
253 viewer.add_drawable(std::shared_ptr<LinesDrawable>(bbox_drawable));
271 void update_buffers_internal() {
273 const std::vector<vec3> &points = resource::bunny_vertices;
276 const std::vector<unsigned int> &indices = resource::bunny_indices;
279 update_vertex_buffer(points);
281 update_element_buffer(indices);
288 MyLinesDrawable(
const std::string& name =
"") :
LinesDrawable(name) {}
291 void update_buffers_internal() {
293 const std::vector<vec3> &points = resource::bunny_vertices;
294 const Box3 &box = geom::bounding_box<Box3, std::vector<vec3> >(points);
302 const std::vector<vec3> bbox_points = {
303 vec3(xmin, ymin, zmax),
vec3(xmax, ymin, zmax),
304 vec3(xmin, ymax, zmax),
vec3(xmax, ymax, zmax),
305 vec3(xmin, ymin, zmin),
vec3(xmax, ymin, zmin),
306 vec3(xmin, ymax, zmin),
vec3(xmax, ymax, zmin)
309 const std::vector<unsigned int> bbox_indices = {
310 0, 1, 2, 3, 4, 5, 6, 7,
311 0, 2, 4, 6, 1, 3, 5, 7,
312 0, 4, 2, 6, 1, 5, 3, 7
315 update_vertex_buffer(bbox_points);
317 update_element_buffer(bbox_indices);
324 MyPointsDrawable(
const std::string& name =
"") :
PointsDrawable(name) {}
327 void update_buffers_internal() {
329 const std::vector<vec3> &points = resource::bunny_vertices;
331 update_vertex_buffer(points);
336int main(
int argc,
char **argv) {
344 Viewer viewer(EXAMPLE_TITLE);
345 viewer.set_usage(
"");
354 auto surface =
new MyTrianglesDrawable(
"faces");
356 viewer.add_drawable(std::shared_ptr<MyTrianglesDrawable>(surface));
361 auto vertices =
new MyPointsDrawable(
"vertices");
363 viewer.add_drawable(std::shared_ptr<MyPointsDrawable>(vertices));
365 vertices->set_uniform_coloring(
vec4(1.0f, 0.0f, 0.0f, 1.0f));
371 vertices->set_impostor_type(PointsDrawable::SPHERE);
373 vertices->set_point_size(10);
379 auto bbox_drawable =
new MyLinesDrawable(
"bbox");
381 viewer.add_drawable(std::shared_ptr<MyLinesDrawable>(bbox_drawable));
383 bbox_drawable->set_uniform_coloring(
vec4(0.0f, 0.0f, 1.0f, 1.0f));
385 bbox_drawable->set_line_width(5.0f);
The base class for drawable objects. A drawable represent a set of points, line segments,...
Definition drawable.h:58
void update_vertex_buffer(const std::vector< vec3 > &vertices, bool dynamic=false)
Creates/Updates the vertex buffer.
Definition drawable.cpp:139
void update_element_buffer(const std::vector< unsigned int > &elements)
Updates the element buffer.
Definition drawable.cpp:190
FT max_coord(unsigned int axis) const
Return a component of the coordinates of the max corner.
Definition box.h:141
FT min_coord(unsigned int axis) const
Return a component of the coordinates of the min corner.
Definition box.h:129
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:50
The drawable for rendering a set of points, e.g., point clouds, vertices of a mesh.
Definition drawable_points.h:42
The drawable for rendering a set of triangles, e.g., the surface of a triangular mesh.
Definition drawable_triangles.h:46
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182
void initialize(bool info_to_stdout, bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition initializer.cpp:39