-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCheckpointWriter.cpp
130 lines (108 loc) · 3.92 KB
/
CheckpointWriter.cpp
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
#include "CheckpointWriter.h"
int CheckpointWriter::_checkpoint_num=0;
mutex CheckpointWriter::jpeg_mutex;
ofstream CheckpointWriter::jpeg;
void CheckpointWriter::writeJpegByte(unsigned char oneByte)
{
jpeg << oneByte;
}
void CheckpointWriter::checkpoint(const string prefix, int32_t width, int32_t height, TelemetryPoint scan_data[], int scan_size, MapPoint map[], LocalizedOrigin *location){
int scale_factor = 3;
unique_lock<mutex> lock(jpeg_mutex);
int32_t img_width = width/scale_factor;
int32_t img_height = height/scale_factor;
unsigned char *pixels = new unsigned char[img_width*img_height*channels];
for(int32_t i = 0; i < img_height*img_width*channels; i= i+3){
pixels[i] = 255;
pixels[i+1] = 255;
pixels[i+2] = 255;
}
for(int32_t i = 0; i < height*width; i++){
if(map[i].occupancy > 0) {
int x = i % width;
int y = height - ((i - x)/height) - 1;
int r = 255;
int g = 0;
int b = 0;
if(map[i].occupancy >=9){
r = 0;
g = 0;
b = 0;
} else if(map[i].occupancy >= 6){
r = 0;
g = 0;
b = 255;
}
addScanData(pixels, img_width, img_height, x/scale_factor, y/scale_factor, r, g ,b , 255, 2);
}
}
for(int i = 0; i < scan_size; i++){
addScanData(pixels, img_width, img_height, (width/2 + scan_data[i].x + location->x_offset)/scale_factor, (height/2 + (-1 * (scan_data[i].y+ location->y_offset)))/scale_factor
, 0, 0 ,255 , 255, 1);
}
addScanData(pixels, img_width, img_height, (width/2 + location->x_offset)/scale_factor, (height/2 - location->y_offset)/scale_factor, 255, 128 ,30 , 255, 8);
char buffer [40];
sprintf (buffer, "./maps/map_%s_%d_%d.jpg",prefix.c_str(), _checkpoint_num, scan_size);
jpeg.open(buffer);
TooJpeg::writeJpeg(writeJpegByte, pixels, img_width, img_height);
jpeg.close();
}
void CheckpointWriter::checkpoint(const string prefix, int32_t width, int32_t height, TelemetryPoint scan_data[], int scan_size, int map_size, MapPoint *map, LocalizedOrigin *location){
int scale_factor = 3;
unique_lock<mutex> lock(jpeg_mutex);
int32_t e_width = width/2;
int32_t e_height = height/2;
int32_t img_width = width/scale_factor;
int32_t img_height = height/scale_factor;
unsigned char *pixels = new unsigned char[img_width*img_height*channels];
for(int32_t i = 0; i < img_height*img_width*channels; i= i+3){
pixels[i] = 255;
pixels[i+1] = 255;
pixels[i+2] = 255;
}
for(int i = 0; i < map_size; i++){
MapPoint *cur_point = map+i;
if(cur_point->occupancy > 0) {
int r = 255;
int g = 0;
int b = 0;
if(cur_point->occupancy >=6){
r = 0;
g = 0;
b = 0;
} else if(cur_point->occupancy >= 3){
r = 0;
g = 0;
b = 255;
}
addScanData(pixels, img_width, img_height, (e_width+ cur_point->x)/scale_factor, (e_height - cur_point->y)/scale_factor, r, g ,b , 255, 4);
}
}
for(int i = 0; i < scan_size; i++){
addScanData(pixels, img_width, img_height, (e_width + scan_data[i].x + location->x_offset)/scale_factor, (e_height + (-1 * (scan_data[i].y+ location->y_offset)))/scale_factor
, 0, 0 ,255 , 255, 1);
}
addScanData(pixels, img_width, img_height, (e_width + location->x_offset)/scale_factor, (e_height - location->y_offset)/scale_factor, 64, 128 ,255 , 255, 8);
char buffer [40];
sprintf (buffer, "./maps/map_%s_%d_%d.jpg",prefix.c_str(), _checkpoint_num, scan_size);
jpeg.open(buffer);
TooJpeg::writeJpeg(writeJpegByte, pixels, img_width, img_height);
jpeg.close();
}
void CheckpointWriter::advanceCheckpoint(){
_checkpoint_num++;
}
void CheckpointWriter::addScanData(unsigned char *pixels, int width, int height, int x, int y, int r, int g, int b, int quality,int pad){
for(int yp = -pad; yp < pad; yp++) {
for(int xp = -pad; xp < pad; xp++) {
int pixel_num = (((y+yp)*width) + (x+xp))*channels;
if(y+yp >= height || y+yp < 0 || x+xp >= width || x+xp < 0){
printf("OOB %d %d\n", x, y);
continue;
}
pixels[pixel_num] = r;
pixels[pixel_num+1] = b;
pixels[pixel_num+2] = g;
}
}
}