color.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_IO_COLOR_H_
18 #define CARTOGRAPHER_IO_COLOR_H_
19 
20 #include <array>
21 
24 
25 namespace cartographer {
26 namespace io {
27 
28 using Uint8Color = std::array<uint8, 3>;
29 using FloatColor = std::array<float, 3>;
30 
31 // A function for on-demand generation of a color palette, with every two
32 // direct successors having large contrast.
33 FloatColor GetColor(int id);
34 
35 inline uint8 FloatComponentToUint8(float c) {
36  return static_cast<uint8>(cartographer::common::RoundToInt(
37  cartographer::common::Clamp(c, 0.f, 1.f) * 255));
38 }
39 
40 inline float Uint8ComponentToFloat(uint8 c) { return c / 255.f; }
41 
42 inline Uint8Color ToUint8Color(const FloatColor& color) {
43  return {{FloatComponentToUint8(color[0]), FloatComponentToUint8(color[1]),
44  FloatComponentToUint8(color[2])}};
45 }
46 
47 inline FloatColor ToFloatColor(const Uint8Color& color) {
48  return {{Uint8ComponentToFloat(color[0]), Uint8ComponentToFloat(color[1]),
49  Uint8ComponentToFloat(color[2])}};
50 }
51 
52 } // namespace io
53 } // namespace cartographer
54 
55 #endif // CARTOGRAPHER_IO_COLOR_H_
int RoundToInt(const float x)
Definition: port.h:41
FloatColor ToFloatColor(const Uint8Color &color)
Definition: color.h:47
float Uint8ComponentToFloat(uint8 c)
Definition: color.h:40
Uint8Color ToUint8Color(const FloatColor &color)
Definition: color.h:42
FloatColor GetColor(int id)
Definition: color.cc:61
std::array< uint8, 3 > Uint8Color
Definition: color.h:28
std::array< float, 3 > FloatColor
Definition: color.h:29
uint8 FloatComponentToUint8(float c)
Definition: color.h:35
T Clamp(const T value, const T min, const T max)
Definition: math.h:32
uint8_t uint8
Definition: port.h:34


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58