-
Notifications
You must be signed in to change notification settings - Fork 1
/
Visualizer.h
86 lines (68 loc) · 2.36 KB
/
Visualizer.h
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Surface_mesh.h>
#include <CGAL/alpha_wrap_3.h>
#include <CGAL/IO/read_points.h>
#include <CGAL/Real_timer.h>
#include <CGAL/compute_average_spacing.h>
#include <CGAL/remove_outliers.h>
#include <pangolin/pangolin.h>
#include <functional>
#include <iostream>
#include <string>
#include <thread>
#include <mutex>
#include <condition_variable>
namespace AW3 = CGAL::Alpha_wraps_3;
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_3 = K::Point_3;
using Mesh = CGAL::Surface_mesh<Point_3>;
/// @brief Visualizer class that wraps the point cloud and displays the wrap.
/// @details The pose and point cloud update/set functions are thread safe.
class Visualizer
{
private:
std::thread pointCloudConsumerThread;
// The main visualizer thread. Pangolin is used.
std::thread poseConsumerThread;
// House keeping for threads ----------------
// Note that I refrained from using more mutexes and condition variables than this for ease of development.
// Mutex for all point cloud and mesh related data structures (including the draw function).
std::mutex pointCloudMutex;
std::condition_variable pointCloudSignal;
// Mutex for all pose related data structures.
std::mutex poseMutex;
std::condition_variable poseSignal;
bool pointCloudReady = false;
bool poseReady = false;
// Function pointer to hold the draw function
std::function<void()> drawFunction;
// ------------------------------------------
double diag_length;
double alpha;
double offset;
double relative_alpha;
double relative_offset;
double outlier_percentage = 0.1;
std::vector<Point_3> pointsToProcess;
std::vector<Point_3> pointsProcessed;
Mesh previewMesh;
Mesh finalMesh;
Point_3 pose;
// Functions -------------------------------
void pointCloudConsumer();
void poseConsumer();
void processPointCloud();
void initDiagonalLength(std::vector<Point_3> points);
void drawPointCloud(std::vector<Point_3> points);
void drawPreviewMesh(Mesh mesh);
void drawMesh(Mesh mesh);
void drawPose(Point_3 pose);
public:
Visualizer(double relative_alpha, double relative_offset);
~Visualizer();
Mesh getFinalMesh();
void addPointCloud(std::vector<Point_3> points);
void setPointCloud(std::vector<Point_3> points);
void updatePose(Point_3 pose);
void triggerWrap();
};