forked from swayfreeda/ImageBasedModellingEduV1.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_debug_embeddings.cpp
executable file
·106 lines (89 loc) · 3.79 KB
/
generate_debug_embeddings.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
/*
* Copyright (C) 2015, Nils Moehrle
* TU Darmstadt - Graphics, Capture and Massively Parallel Computing
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD 3-Clause license. See the LICENSE.txt file for details.
*/
#include <math/vector.h>
#include "debug.h"
const bool font[] = {
0,1,0, 0,1,0, 1,1,0, 1,1,0, 1,0,0, 1,1,1, 0,1,0, 1,1,1, 0,1,0 ,0,1,0,
1,0,1, 1,1,0, 0,0,1, 0,0,1, 1,0,1, 1,0,0, 1,0,0, 0,0,1, 1,0,1, 1,0,1,
1,0,1, 0,1,0, 0,1,0, 0,1,0, 1,1,1, 1,1,0, 1,1,0, 0,0,1, 0,1,0, 0,1,1,
1,0,1, 0,1,0, 1,0,0, 0,0,1, 0,0,1, 0,0,1, 1,0,1, 0,1,0, 1,0,1, 0,0,1,
0,1,0, 1,1,1, 1,1,1, 1,1,0, 0,0,1, 1,1,0, 0,1,0, 0,1,0, 0,1,0, 0,1,0
};
void print_number(core::ByteImage::Ptr image, int x, int y, int digit, math::Vec3uc color) {
assert(0 <= x && x < image->width() - 3);
assert(0 <= y && y < image->height() - 5);
assert(0 <= digit && digit <= 9);
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < 5; ++j) {
if(font[30 * j + digit * 3 + i]) {
for(int c = 0; c < image->channels(); ++c) {
image->at(x+i, y+j, c) = color[c];
}
}
}
}
}
void
generate_debug_colors(std::vector<math::Vec4f> & colors) {
for (float s = 1.0f; s > 0.0f; s -= 0.4) {
for (float v = 1.0f; v > 0.0f; v -= 0.3) {
for (float h = 0.0f; h < 360.0f; h += 30.0f) {
float c = v * s;
float x = c * (1.0f - fabs(fmod(h / 60.0f, 2.0f) - 1.0f));
float m = v - c;
math::Vec4f color;
if (0 <= h && h < 60)
color = math::Vec4f(c, x, 0.0f, 1.0f);
if (60 <= h && h < 120)
color = math::Vec4f(x, c, 0.0f, 1.0f);
if (120 <= h && h < 180)
color = math::Vec4f(0.0f, c, x, 1.0f);
if (180 <= h && h < 240)
color = math::Vec4f(0.0f, x, c, 1.0f);
if (240 <= h && h < 300)
color = math::Vec4f(x, 0.0f, c, 1.0f);
if (300 <= h && h < 360)
color = math::Vec4f(c, 0.0f, x, 1.0f);
color = color + math::Vec4f(m, m, m, 0.0f);
colors.push_back(color);
}
}
}
}
void
generate_debug_embeddings(std::vector<TextureView> * texture_views) {
std::vector<math::Vec4f> colors;
generate_debug_colors(colors);
#pragma omp parallel for
for (std::size_t i = 0; i < texture_views->size(); ++i) {
math::Vec4f float_color = colors[i % colors.size()];
TextureView * texture_view = &(texture_views->at(i));
/* Determine font color depending on luminance of background. */
float luminance = math::interpolate(float_color[0], float_color[1], float_color[2], 0.30f, 0.59f, 0.11f);
math::Vec3uc font_color = luminance > 0.5f ? math::Vec3uc(0,0,0) : math::Vec3uc(255,255,255);
math::Vec3uc color;
color[0] = float_color[0] * 255.0f;
color[1] = float_color[1] * 255.0f;
color[2] = float_color[2] * 255.0f;
core::ByteImage::Ptr image = core::ByteImage::create(texture_view->get_width(), texture_view->get_height(), 3);
image->fill_color(*color);
for(int ox=0; ox < image->width() - 13; ox += 13) {
for(int oy=0; oy < image->height() - 6; oy += 6) {
std::size_t id = texture_view->get_id();
int d0 = id / 100;
int d1 = (id % 100) / 10;
int d2 = id % 10;
print_number(image, ox, oy, d0, font_color);
print_number(image, ox + 4, oy, d1, font_color);
print_number(image, ox + 8, oy, d2, font_color);
}
}
texture_view->bind_image(image);
}
}