Easy3D 2.5.3
Tutorial_205_MultiView
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
28#include <easy3d/viewer/multi_viewer.h>
29#include <easy3d/core/model.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/renderer/drawable_points.h>
32#include <easy3d/renderer/drawable_lines.h>
33#include <easy3d/renderer/drawable_triangles.h>
34#include <easy3d/util/resource.h>
35#include <easy3d/util/initializer.h>
36
37using namespace easy3d;
38
39
40// This example shows how to use the built-in multi-view viewer.
41
42int main(int argc, char** argv) {
43 // initialize Easy3D.
44 initialize();
45
46 // create a 2 by 2 MultiViewer
47 MultiViewer viewer(2, 2, EXAMPLE_TITLE);
48
49 // ---------------------------------------------------------------------------
50 // setup content for view(0, 0): the graph model (vertices and edges)
51 const std::string file_graph = resource::directory() + "/data/graph.ply";
52 auto graph = viewer.add_model(file_graph, true);
53 if (graph)
54 viewer.assign(0, 0, graph);
55 else
56 LOG(ERROR) << "failed to load model from file: " << file_graph;
57
58 // ---------------------------------------------------------------------------
59 // setup content for view(0, 1): the surface of the sphere model
60 const std::string file_sphere = resource::directory() + "/data/sphere.obj";
61 auto sphere = viewer.add_model(file_sphere, true);
62 if (sphere) {
63 auto sphere_faces = sphere->renderer()->get_triangles_drawable("faces");
64 viewer.assign(0, 1, sphere_faces);
65 }
66 else
67 LOG(ERROR) << "failed to load model from file: " << file_sphere;
68
69 // ---------------------------------------------------------------------------
70 // setup content for view(1, 0): the wireframe of the sphere model
71 auto sphere_wireframe = sphere->renderer()->get_lines_drawable("edges");
72 sphere_wireframe->set_impostor_type(LinesDrawable::CYLINDER);
73 sphere_wireframe->set_line_width(5);
74 sphere_wireframe->set_uniform_coloring(vec4(0.7f, 0.7f, 1.0f, 1.0f));
75 viewer.assign(1, 0, sphere_wireframe);
76
77 // ---------------------------------------------------------------------------
78 // setup content for view(1, 1): the vertices of the sphere model
79 auto sphere_vertices = sphere->renderer()->get_points_drawable("vertices");
80 sphere_vertices->set_impostor_type(PointsDrawable::SPHERE);
81 sphere_vertices->set_point_size(15);
82 viewer.assign(1, 1, sphere_vertices);
83
84 // run the viewer
85 return viewer.run();
86}
Renderer * renderer()
Gets the renderer of this model.
Definition: model.h:94
A viewer that supports multiple views (arranged in a grid layout).
Definition: multi_viewer.h:44
void assign(int row, int col, const Model *m)
Assigns the model m to the view at position (row, col).
Definition: multi_viewer.cpp:74
TrianglesDrawable * get_triangles_drawable(const std::string &name) const
Definition: renderer.cpp:304
virtual Model * add_model(const std::string &file_name, bool create_default_drawables=true)
Add a model from a file to the viewer to be visualized. On success, the viewer will be in charge of t...
Definition: viewer.cpp:1204
int run(bool see_all=true)
Run the viewer.
Definition: viewer.cpp:1090
Definition: collider.cpp:182
void initialize(bool use_log_file, bool use_setting_file, const std::string &resource_dir)
Initialization of Easy3D.
Definition: initializer.cpp:35