CARLA
sensor/data/Color.h
Go to the documentation of this file.
1 // Copyright (c) 2017 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/rpc/Color.h"
10 #include "carla/rpc/FloatColor.h"
11 
12 #include <cstdint>
13 
14 namespace carla {
15 namespace sensor {
16 namespace data {
17 
18 #pragma pack(push, 1)
19  /// A 32-bit BGRA color.
20  struct Color {
21  Color() = default;
22  Color(const Color &) = default;
23 
24  Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a = 255u)
25  : b(b), g(g), r(r), a(a) {}
26 
27  Color &operator=(const Color &) = default;
28 
29  bool operator==(const Color &rhs) const {
30  return (r == rhs.r) && (g == rhs.g) && (b == rhs.b);
31  }
32 
33  bool operator!=(const Color &rhs) const {
34  return !(*this == rhs);
35  }
36 
37  operator rpc::Color() const {
38  return {r, g, b};
39  }
40  operator rpc::FloatColor() const {
41  return {r/255.f, g/255.f, b/255.f, a/255.f};
42  }
43 
44  uint8_t b = 0u;
45  uint8_t g = 0u;
46  uint8_t r = 0u;
47  uint8_t a = 0u;
48  MSGPACK_DEFINE_ARRAY(r, g, b, a);
49  };
50 #pragma pack(pop)
51 
52 static_assert(sizeof(Color) == sizeof(uint32_t), "Invalid color size!");
53 
54 #pragma pack(push, 1)
55  /// Optical flow pixel format. 2 channel float data.
57  OpticalFlowPixel() = default;
58  OpticalFlowPixel(const OpticalFlowPixel &) = default;
59 
60  OpticalFlowPixel(float x, float y)
61  : x(x), y(y) {}
62 
63  OpticalFlowPixel &operator=(const OpticalFlowPixel &) = default;
64 
65  bool operator==(const OpticalFlowPixel &rhs) const {
66  return (x == rhs.x) && (y == rhs.y);
67  }
68 
69  bool operator!=(const OpticalFlowPixel &rhs) const {
70  return !(*this == rhs);
71  }
72 
73  float x = 0;
74  float y = 0;
76  };
77 #pragma pack(pop)
78 
79 } // namespace data
80 } // namespace sensor
81 } // namespace carla
bool operator==(const OpticalFlowPixel &rhs) const
sensor::data::Color Color
A 32-bit BGRA color.
bool operator!=(const Color &rhs) const
This file contains definitions of common data structures used in traffic manager. ...
Definition: Carla.cpp:133
bool operator!=(const OpticalFlowPixel &rhs) const
Color & operator=(const Color &)=default
Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a=255u)
bool operator==(const Color &rhs) const
Optical flow pixel format. 2 channel float data.
MSGPACK_DEFINE_ARRAY(r, g, b, a)