forked from alicevision/AliceVision
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjetColorMap.cpp
More file actions
59 lines (50 loc) · 3.1 KB
/
jetColorMap.cpp
File metadata and controls
59 lines (50 loc) · 3.1 KB
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
// This file is part of the AliceVision project.
// Copyright (c) 2017 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.
#include "jetColorMap.hpp"
namespace aliceVision {
static float jetr[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0.0625, 0.1250, 0.1875, 0.2500, 0.3125, 0.3750, 0.4375, 0.5000, 0.5625,
0.6250, 0.6875, 0.7500, 0.8125, 0.8750, 0.9375, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 0.9375, 0.8750, 0.8125, 0.7500, 0.6875, 0.6250, 0.5625, 0.5000};
static float jetg[64] = {0, 0, 0, 0, 0, 0, 0, 0, 0.0625, 0.1250, 0.1875,
0.2500, 0.3125, 0.3750, 0.4375, 0.5000, 0.5625, 0.6250, 0.6875, 0.7500, 0.8125, 0.8750,
0.9375, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 0.9375, 0.8750, 0.8125, 0.7500,
0.6875, 0.6250, 0.5625, 0.5000, 0.4375, 0.3750, 0.3125, 0.2500, 0.1875, 0.1250, 0.0625,
0, 0, 0, 0, 0, 0, 0, 0, 0};
static float jetb[64] = {0.5625, 0.6250, 0.6875, 0.7500, 0.8125, 0.8750, 0.9375, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, 1.0000,
1.0000, 1.0000, 0.9375, 0.8750, 0.8125, 0.7500, 0.6875, 0.6250, 0.5625, 0.5000, 0.4375,
0.3750, 0.3125, 0.2500, 0.1875, 0.1250, 0.0625, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0};
Color getColorFromJetColorMap(float value)
{
if(value <= 0.0f)
return Color(0, 0, 0);
if(value >= 1.0f)
return Color(1.0f, 1.0f, 1.0f);
const float idx_f = value * 63.0f;
float integral;
const float fractB = std::modf(idx_f, &integral);
const float fractA = 1.0f - fractB;
const int idx = static_cast<int>(integral);
Color c;
c.r = jetr[idx] * fractA + jetr[idx + 1] * fractB;
c.g = jetg[idx] * fractA + jetg[idx + 1] * fractB;
c.b = jetb[idx] * fractA + jetb[idx + 1] * fractB;
return c;
}
rgb getRGBFromJetColorMap(float value)
{
const Color color = getColorFromJetColorMap(value);
return {static_cast<unsigned char>(color.r * 255.0f),
static_cast<unsigned char>(color.g * 255.0f),
static_cast<unsigned char>(color.b * 255.0f)};
}
} // namespace aliceVision