CARLA
FloatColor.h
Go to the documentation of this file.
1 // Copyright (c) 2021 Computer Vision Center (CVC) at the Universitat Autonoma
2 // de Barcelona (UAB).
3 //
4 // This work is licensed under the terms of the MIT license.
5 // For a copy, see <https://opensource.org/licenses/MIT>.
6 
7 #pragma once
8 
9 #include "carla/MsgPack.h"
10 
11 #include <cstdint>
12 
13 #ifdef LIBCARLA_INCLUDED_FROM_UE4
14 # include "Math/Color.h"
15 #endif // LIBCARLA_INCLUDED_FROM_UE4
16 
17 namespace carla {
18 namespace rpc {
19 
20 #pragma pack(push, 1)
21  struct FloatColor {
22  public:
23 
24  float r = 0.f;
25  float g = 0.f;
26  float b = 0.f;
27  float a = 1.f;
28 
29  FloatColor() = default;
30  FloatColor(const FloatColor &) = default;
31 
32  FloatColor(float r, float g, float b, float a = 1.f)
33  : r(r), g(g), b(b), a(a) {}
34 
35  FloatColor &operator=(const FloatColor &) = default;
36 
37  bool operator==(const FloatColor &rhs) const {
38  return (r == rhs.r) && (g == rhs.g) && (b == rhs.b) && (a == rhs.a);
39  }
40 
41  bool operator!=(const FloatColor &rhs) const {
42  return !(*this == rhs);
43  }
44 
45 #ifdef LIBCARLA_INCLUDED_FROM_UE4
46 
47  FloatColor(const FColor &color)
48  : FloatColor(color.R / 255.f, color.G / 255.f, color.B / 255.f, color.A / 255.f) {}
49 
50  FloatColor(const FLinearColor &color)
51  : FloatColor(color.R, color.G, color.B, color.A) {}
52 
53  FColor ToFColor() const {
54  return FColor{
55  static_cast<uint8>(r * 255),
56  static_cast<uint8>(g * 255),
57  static_cast<uint8>(b * 255),
58  static_cast<uint8>(a * 255)};
59  }
60 
61  operator FLinearColor() const {
62  return FLinearColor{ r, g, b, a };
63  }
64 
65 #endif // LIBCARLA_INCLUDED_FROM_UE4
66 
67  MSGPACK_DEFINE_ARRAY(r, g, b, a);
68  };
69 #pragma pack(pop)
70 
71 } // namespace rpc
72 } // namespace carla
FloatColor(float r, float g, float b, float a=1.f)
Definition: FloatColor.h:32
bool operator!=(const FloatColor &rhs) const
Definition: FloatColor.h:41
MSGPACK_DEFINE_ARRAY(r, g, b, a)
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
FloatColor & operator=(const FloatColor &)=default
bool operator==(const FloatColor &rhs) const
Definition: FloatColor.h:37