forked from springzfx/point-cloud-annotation-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Annotaion.h
246 lines (199 loc) · 5.52 KB
/
Annotaion.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#ifndef Annotaions_H
#define Annotaions_H
#include <common.h>
#include <vtkSmartPointer.h>
using namespace std;
struct BoxLabel
{
BoxLabel(){
type="unknown";
this->detail.center_x=this->detail.center_y=this->detail.center_z=0;
this->detail.yaw=2;
this->detail.length=this->detail.width=this->detail.height=1;
}
BoxLabel(const double p1[3],const double p2[3],string type_="unknown"){
type=type_;
this->detail.center_x=(p1[0]+p2[0])/2;
this->detail.center_y=(p1[1]+p2[1])/2;
this->detail.center_z=(p1[2]+p2[2])/2;
this->detail.yaw=0;
this->detail.length=p2[0]-p1[0];
this->detail.width=p2[1]-p1[1];
this->detail.height=p2[2]-p1[2];
}
string type;
union{
double data[7];
struct{
double center_x;
double center_y;
double center_z;
double length;
double width;
double height;
double yaw;
} detail;
};
string toString(){
char buffer [200];
sprintf(buffer,"%s %f %f %f %f %f %f %f",
type.c_str(),data[0],data[1],data[2],data[3],data[4],data[5],data[6]);
return std::string(buffer);;
}
};
class vtkBoxWidgetCallback0;
class vtkBoxWidgetCallback1;
class vtkAnnotationBoxSource;
class vtkBoxWidgetRestricted;
class vtkTransform;
class vtkRenderWindowInteractor;
class vtkActor;
class vtkPolyDataMapper;
class Annotation
{
public:
/**
* @brief Annotation construct from boxlabel which load from label file
* @param label
* @param visible_
* @param lock_
*/
Annotation(const BoxLabel &label,bool visible_=true,bool lock_=false);
/**
* @brief Annotation construct from part of cloud points
* @param cloud
* @param slice
* @param type_
*/
Annotation(const PointCloudTPtr cloud, vector<int> & slice,string type_);
~Annotation();
/**
* @brief getBoxLabel get boxLabel from annotaion tranformation
* @return
*/
BoxLabel getBoxLabel();
/**
* @brief apply transform to annotation
* @param t
*/
void applyTransform(vtkSmartPointer<vtkTransform> t);
/**
* @brief enter picked state, show boxwidget which allow to adjust annotation
* @param interactor
*/
void picked(vtkRenderWindowInteractor* interactor);
/**
* @brief disable boxWidget
*/
void unpicked();
/**
* @brief keep current orientation, re-compute the center and scale
* to make annotation fit to selected point well enough
*/
void adjustToAnchor();
/**
* @brief change the type of annotation, and color too
* @param value
*/
void setType(const string value);
vtkSmartPointer<vtkActor> getActor() const;
string getType() const;
protected:
void initial();
/**
* @brief color the annotation with given color
* @param color_index
* if color_index>=0,refer to @ref pcl::GlasbeyLUT
* otherwise use color already mapped by type
*/
void colorAnnotation(int color_index=-1);
/**
* @brief copy selected points as anchor to current annotation
* @param cloud
* @param slice
*/
void setAnchorPoint(const PointCloudTPtr cloud, const vector<int> &slice);
/**
* @brief computeScaleAndCenterShift
* @param o direction
* @param scs ["scale", "center shift"]
* @return scale
*/
double computeScaleAndCenterShift(double o[3],double scs[2]);
private:
string type;
vtkSmartPointer<vtkAnnotationBoxSource> source;
vtkSmartPointer<vtkActor> actor;
vtkSmartPointer<vtkPolyDataMapper> mapper;
vtkSmartPointer<vtkTransform> transform;
vtkSmartPointer<vtkBoxWidgetRestricted> boxWidget;
vtkSmartPointer<vtkBoxWidgetCallback0> boxWidgetCallback0;
vtkSmartPointer<vtkBoxWidgetCallback1> boxWidgetCallback1;
vector<double*> anchorPoints;
double center[3];
// NOTE not used
bool visible;
bool lock;
public:
/**
* @brief get types vector pointer
* @return
*/
static vector<string>* getTypes();
/**
* @brief getTypeIndex auto add to vector map if has not
* @param type_
* @return
*/
static int getTypeIndex(string type_);
/**
* @brief getColor map type to color in pcl::GlasbeyLUT
* @param type_
* @return
*/
static pcl::RGB getColor(string type_);
/**
* @brief computeOBB compute max,min [x,y,z] aligned to xyz axis
* @param cloud
* @param slice
* @param p1 min [x,y,z]
* @param p2 max [x,y,z]
*/
static void computeOBB(const PointCloudTPtr cloud, vector<int>& slice, double p1[3], double p2[3]);
private:
/**
* @brief types all annotation type here
*/
static vector<string>* types;
};
class Annotaions
{
public:
/**
* @brief from annotatin box actor to find annotation itself
* @param actor
* @return
*/
Annotation* getAnnotation(vtkActor* actor);
void push_back(Annotation* anno);
void remove(Annotation* anno);
void clear();
int getSize();
/**
* @brief load annotations from file
* @param filename
*/
void loadAnnotations(string filename);
/**
* @brief save annotations to file
* @param filename
*/
void saveAnnotations(string filename);
vector<Annotation *>& getAnnotations();
protected:
/**
* @brief keep all annotation from current cloud
*/
vector<Annotation*> annotations;
};
#endif //Annotaions_H