forked from lesterlo/cloud_annotation_tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewer.h
158 lines (125 loc) · 4.27 KB
/
viewer.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef VIEWER_H
#define VIEWER_H
// C++
#include <iostream>
// Qt
#include <QMainWindow>
#include <QFileDialog>
#include <QListWidgetItem>
#include <QProcess>
#include <QDirIterator>
// Point Cloud Library
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/filters/voxel_grid.h>
#include <pcl/filters/extract_indices.h>
#include <pcl/filters/statistical_outlier_removal.h>
#include <pcl/segmentation/sac_segmentation.h>
#include <pcl/segmentation/extract_clusters.h>
#include <pcl/common/centroid.h>
#include <pcl/common/common.h>
#include <pcl/visualization/pcl_visualizer.h>
// Visualization Toolkit (VTK)
#include <vtkRenderWindow.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include "annotatorinteractor.h"
#include <tuple>
#include "json.hpp"
#include <qmenu.h>
using nlohmann::json;
typedef struct feature {
int id;
Eigen::Vector4f centroid;
Eigen::Vector4f min;
Eigen::Vector4f max;
} Feature;
namespace Ui {
class CloudViewer;
}
#define TIED_OP(STRUCT, OP) \
inline bool operator OP(const STRUCT& lhs, const STRUCT& rhs) \
{ \
return lhs.tie() OP rhs.tie(); \
}
#define TIED_COMPARISONS(STRUCT) \
TIED_OP(STRUCT, ==) \
TIED_OP(STRUCT, !=) \
TIED_OP(STRUCT, <) \
TIED_OP(STRUCT, <=) \
TIED_OP(STRUCT, >=) \
TIED_OP(STRUCT, >)
struct ClusterKey {
std::string oclass;
std::string objectid;
std::tuple<std::string, std::string> tie() const { return std::tie(oclass, objectid); }
};
inline void to_json(json& j, const ClusterKey& p) {
j = json{{"oclass", p.oclass}, {"objectid", p.objectid}};
}
inline void from_json(const json& j, ClusterKey& p) {
j.at("oclass").get_to(p.oclass);
j.at("objectid").get_to(p.objectid);
}
TIED_COMPARISONS(ClusterKey)
class CloudViewer: public QMainWindow {
Q_OBJECT
public:
explicit CloudViewer(QWidget *parent = 0);
bool hasSegment(std::string objectClass, std::string objectId);
~CloudViewer();
public slots:
void loadButtonClicked();
void labelButtonClicked();
void fileItemChanged();
void painted(double x, double y, double z, long pointid, bool painting);
protected:
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer;
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr colorize(pcl::PointCloud<pcl::PointXYZ> &source, int r, int g, int b);
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud, cloud_ann;
std::map<ClusterKey, std::vector<int>> segments; // todo must convert to std::set, will be much faster for point stealing ea
void movePointToAnn(double x, double y, double z, long pointid, bool painting);
void createSegmentFromAnn(std::string segment_name);
void saveCurrentCluster();
void loadCluster(std::string oclass, std::string objectid);
void colorizeCloud(pcl::PointCloud<pcl::PointXYZRGBA> &c, char r, char g, char b, char a);
void saveJson();
void resetClippingSpinboxes();
void updateCameraClipping();
void stealPointsFromOtherClusters(ClusterKey k);
void confirmDeleteCurrentCluster();
void renameCurrentCluster();
void flyToCluster(ClusterKey &key);
void flyToSelectedCluster();
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr getCluster(ClusterKey &key);
void loadFile(std::string file_name);
pcl::KdTreeFLANN<pcl::PointXYZRGBA> kdtree;
private slots:
void on_btnSaveCurrent_pressed();
void on_cmbClass_currentTextChanged(const QString &arg1);
void on_txtObjectId_textChanged(const QString &arg1);
void on_tblClusters_itemSelectionChanged();
void on_spPointPicker_valueChanged(double arg1);
private:
Ui::CloudViewer *ui;
QString load_file_path, current_label_path;
bool file_labeled;
bool auto_next;
bool removing_outliers;
bool downsampling;
bool removing_planes;
bool is_dirty = false;
vtkSmartPointer <vtkGenericOpenGLRenderWindow> _renderWindow;
vtkSmartPointer<AnnotatorInteractor> interactorStyle;
std::vector<Feature> features;
std::vector< std::vector<std::string> > labels;
std::fstream label_file;
ClusterKey currentCluster;
const int curCluster_R = 255;
const int curCluster_G = 0;
const int curCluster_B = 0;
const int pasCluster_R = 127;
const int pasCluster_G = 127;
const int pasCluster_B = 0;
std::shared_ptr<QMenu> context;
};
#endif // VIEWER_H