This example shows how to use another thread for repeatedly modifying a model and updating the viewer thread.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <easy3d/viewer/viewer.h>
28#include <easy3d/core/point_cloud.h>
29#include <easy3d/core/random.h>
30#include <easy3d/renderer/renderer.h>
31#include <easy3d/renderer/drawable_points.h>
32#include <easy3d/util/initializer.h>
33#include <easy3d/util/timer.h>
34
39
41
42
43
44
47 return;
48
50 for (int i = 0; i < 100; ++i) {
53 }
54
55
57
58 viewer->update();
59
60 std::cout <<
"#points: " << cloud->
n_vertices() << std::endl;
61}
62
63
64int main(int argc, char **argv) {
65
67
68
69 Viewer viewer(EXAMPLE_TITLE);
70
71
73
75 for (int i = 0; i < 100; ++i) {
77
78 colors[v] =
vec3(1.0f, 0.0f, 0.0f);
79 }
80
81 viewer.add_model(std::shared_ptr<PointCloud>(cloud));
82
83
84 auto drawable = cloud->renderer()->get_points_drawable("vertices");
85
86 drawable->set_point_size(10.0f);
87
89
90
91#if 1
94
95
97#else
99
100 for (int i = 0; i < 50; ++i) {
101
102 std::this_thread::sleep_for(std::chrono::milliseconds(300));
103 std::thread t(edit_model, cloud, &viewer);
104 t.detach();
105 }
106 });
107#endif
108
109
110 return viewer.run();
111}
Renderer * renderer()
Gets the renderer of this model.
Definition model.cpp:66
A data structure for point clouds.
Definition point_cloud.h:45
VertexProperty< T > vertex_property(const std::string &name, const T t=T())
Gets or adds a vertex property of type T with name name.
Definition point_cloud.h:539
VertexProperty< T > add_vertex_property(const std::string &name, const T t=T())
Add a vertex property of type T with name name and default value t.
Definition point_cloud.h:488
unsigned int n_vertices() const
Returns number of vertices in the cloud.
Definition point_cloud.h:422
Vertex add_vertex(const vec3 &p)
Add a new vertex with position p.
Definition point_cloud.cpp:177
void update()
Invalidates the rendering buffers of the model and thus updates the rendering (delayed in rendering).
Definition renderer.cpp:322
@ COLOR_PROPERTY
Using a color property.
Definition state.h:59
@ VERTEX
Property defined on vertices.
Definition state.h:69
A light-weight implementation of the timer mechanism.
Definition timer.h:47
void set_interval(int interval, std::function< void(Args...)> const &func, Args... args) const
Executes function func for every interval milliseconds.
Definition timer.h:275
void stop()
Stops the timer. After a timer is stopped, it cannot be restarted again. If you want to temporarily p...
Definition timer.h:163
static void single_shot(int delay, std::function< void(Args...)> const &func, Args... args)
Executes function func after delay milliseconds.
Definition timer.h:202
The built-in Easy3D viewer.
Definition viewer.h:63
Definition collider.cpp:182
Vec< 3, float > vec3
A 3D point/vector of float type.
Definition types.h:44
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
float random_float()
Random real in [0, 1].
Definition random.h:39