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
15 #include "Math/Color.h"
17 #endif // LIBCARLA_INCLUDED_FROM_UE4
18 
19 namespace carla {
20 namespace rpc {
21 
22 #pragma pack(push, 1)
23  struct FloatColor {
24  public:
25 
26  float r = 0.f;
27  float g = 0.f;
28  float b = 0.f;
29  float a = 1.f;
30 
31  FloatColor() = default;
32  FloatColor(const FloatColor &) = default;
33 
34  FloatColor(float r, float g, float b, float a = 1.f)
35  : r(r), g(g), b(b), a(a) {}
36 
37  FloatColor &operator=(const FloatColor &) = default;
38 
39  bool operator==(const FloatColor &rhs) const {
40  return (r == rhs.r) && (g == rhs.g) && (b == rhs.b) && (a == rhs.a);
41  }
42 
43  bool operator!=(const FloatColor &rhs) const {
44  return !(*this == rhs);
45  }
46 
47 #ifdef LIBCARLA_INCLUDED_FROM_UE4
48 
49  FloatColor(const FColor &color)
50  : FloatColor(color.R / 255.f, color.G / 255.f, color.B / 255.f, color.A / 255.f) {}
51 
52  FloatColor(const FLinearColor &color)
53  : FloatColor(color.R, color.G, color.B, color.A) {}
54 
55  FColor ToFColor() const {
56  return FColor{
57  static_cast<uint8>(r * 255),
58  static_cast<uint8>(g * 255),
59  static_cast<uint8>(b * 255),
60  static_cast<uint8>(a * 255)};
61  }
62 
63  operator FLinearColor() const {
64  return FLinearColor{ r, g, b, a };
65  }
66 
67 #endif // LIBCARLA_INCLUDED_FROM_UE4
68 
69  MSGPACK_DEFINE_ARRAY(r, g, b, a);
70  };
71 #pragma pack(pop)
72 
73 } // namespace rpc
74 } // namespace carla
FloatColor(float r, float g, float b, float a=1.f)
Definition: FloatColor.h:34
bool operator!=(const FloatColor &rhs) const
Definition: FloatColor.h:43
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:39