Easy3D 2.6.1
Loading...
Searching...
No Matches
Tutorial_205_MultiView/main.cpp

This example shows how to use the built-in multi-view viewer.

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
41
42using namespace easy3d;
43
44
45int main(int argc, char** argv) {
46 // initialize Easy3D.
47 initialize();
48
49 // create a 2 by 2 MultiViewer
50 MultiViewer viewer(2, 2, EXAMPLE_TITLE);
51
52 // ---------------------------------------------------------------------------
53 // setup content for view(0, 0): the graph model (vertices and edges)
54 const std::string file_graph = resource::directory() + "/data/graph.ply";
55 auto graph = viewer.add_model(file_graph);
56 if (graph)
57 viewer.assign(0, 0, graph);
58 else
59 LOG(ERROR) << "failed to load model from file: " << file_graph;
60
61 // ---------------------------------------------------------------------------
62 // setup content for view(0, 1): the surface of the sphere model
63 const std::string file_sphere = resource::directory() + "/data/sphere.obj";
64 auto sphere = viewer.add_model(file_sphere);
65 if (sphere) {
66 auto sphere_faces = sphere->renderer()->get_triangles_drawable("faces");
67 viewer.assign(0, 1, sphere_faces);
68 }
69 else
70 LOG(ERROR) << "failed to load model from file: " << file_sphere;
71
72 // ---------------------------------------------------------------------------
73 // setup content for view(1, 0): the wireframe of the sphere model
74 auto sphere_wireframe = sphere->renderer()->get_lines_drawable("edges");
75 sphere_wireframe->set_impostor_type(LinesDrawable::CYLINDER);
76 sphere_wireframe->set_line_width(5);
77 sphere_wireframe->set_uniform_coloring(vec4(0.7f, 0.7f, 1.0f, 1.0f));
78 viewer.assign(1, 0, sphere_wireframe);
79
80 // ---------------------------------------------------------------------------
81 // setup content for view(1, 1): the vertices of the sphere model
82 auto sphere_vertices = sphere->renderer()->get_points_drawable("vertices");
83 sphere_vertices->set_impostor_type(PointsDrawable::SPHERE);
84 sphere_vertices->set_point_size(15);
85 viewer.assign(1, 1, sphere_vertices);
86
87 // run the viewer
88 return viewer.run();
89}
@ CYLINDER
The lines will be drawn as cylinders.
Definition drawable_lines.h:60
A viewer that supports multiple views (arranged in a grid layout).
Definition multi_viewer.h:43
@ SPHERE
The points will be drawn as spheres.
Definition drawable_points.h:62
std::string directory()
Returns the resource directory (containing color maps, shaders, textures, fonts, etc....
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
Vec< 4, float > vec4
A 4D point/vector of float type.
Definition types.h:46