From 8e68cbdd8a6cab6f6b7067b048fd6523eaca55bb Mon Sep 17 00:00:00 2001 From: Daniel Santos-Olivan Date: Tue, 7 Jul 2020 17:25:05 +0200 Subject: [PATCH] Fix error in the serializer of LidarMeasurament. --- .../source/carla/pointcloud/PointCloudIO.cpp | 1 + .../source/carla/pointcloud/PointCloudIO.h | 2 +- .../carla/sensor/data/LidarMeasurement.h | 6 ++--- .../carla/sensor/s11n/LidarMeasurement.h | 11 ++++----- .../carla/source/libcarla/SensorData.cpp | 12 +++++++--- PythonAPI/docs/sensor_data.yml | 24 +++++++++++++++++-- 6 files changed, 40 insertions(+), 16 deletions(-) diff --git a/LibCarla/source/carla/pointcloud/PointCloudIO.cpp b/LibCarla/source/carla/pointcloud/PointCloudIO.cpp index 6b9930bdf..4a5cf78d3 100644 --- a/LibCarla/source/carla/pointcloud/PointCloudIO.cpp +++ b/LibCarla/source/carla/pointcloud/PointCloudIO.cpp @@ -18,6 +18,7 @@ namespace pointcloud { "property float32 x\n" "property float32 y\n" "property float32 z\n" + "property float32 I\n" // "property uchar diffuse_red\n" // "property uchar diffuse_green\n" // "property uchar diffuse_blue\n" diff --git a/LibCarla/source/carla/pointcloud/PointCloudIO.h b/LibCarla/source/carla/pointcloud/PointCloudIO.h index b3ff50eff..fab4a63c5 100644 --- a/LibCarla/source/carla/pointcloud/PointCloudIO.h +++ b/LibCarla/source/carla/pointcloud/PointCloudIO.h @@ -22,7 +22,7 @@ namespace pointcloud { DEBUG_ASSERT(std::distance(begin, end) >= 0); WriteHeader(out, static_cast(std::distance(begin, end))); for (; begin != end; ++begin) { - out << begin->x << ' ' << begin->y << ' ' << begin->z << '\n'; + out << begin->Point.x << ' ' << begin->Point.y << ' ' << begin->Point.z << ' ' << begin->intensity << '\n'; } } diff --git a/LibCarla/source/carla/sensor/data/LidarMeasurement.h b/LibCarla/source/carla/sensor/data/LidarMeasurement.h index 7fb0ecfa4..e031b8fda 100644 --- a/LibCarla/source/carla/sensor/data/LidarMeasurement.h +++ b/LibCarla/source/carla/sensor/data/LidarMeasurement.h @@ -17,9 +17,9 @@ namespace data { /// Measurement produced by a Lidar. Consists of an array of 3D points plus /// some extra meta-information about the Lidar. - class LidarMeasurement : public Array { - static_assert(sizeof(rpc::Location) == 3u * sizeof(float), "Location size missmatch"); - using Super = Array; + class LidarMeasurement : public Array { + static_assert(sizeof(s11n::LidarDetection) == 4u * sizeof(float), "Location size missmatch"); + using Super = Array; protected: diff --git a/LibCarla/source/carla/sensor/s11n/LidarMeasurement.h b/LibCarla/source/carla/sensor/s11n/LidarMeasurement.h index 32d7395f6..99856999b 100644 --- a/LibCarla/source/carla/sensor/s11n/LidarMeasurement.h +++ b/LibCarla/source/carla/sensor/s11n/LidarMeasurement.h @@ -42,19 +42,18 @@ namespace s11n { class LidarDetection { public: - rpc::Location Point; + geom::Location Point; float intensity; - static const int SIZE = 4; LidarDetection(float x, float y, float z, float intensity) : Point(x, y, z), intensity{intensity} { } - LidarDetection(rpc::Location p, float intensity) : + LidarDetection(geom::Location p, float intensity) : Point(p), intensity{intensity} { } }; - class LidarMeasurement { static_assert(sizeof(float) == sizeof(uint32_t), "Invalid float size"); + static const int SizeLidarDetection = 4; friend class LidarSerializer; friend class LidarHeaderView; @@ -89,7 +88,7 @@ namespace s11n { void Reset(uint32_t channels, uint32_t channel_point_count) { std::memset(_header.data() + Index::SIZE, 0, sizeof(uint32_t) * GetChannelCount()); _points.clear(); - _points.reserve(LidarDetection::SIZE * channels * channel_point_count); + _points.reserve(SizeLidarDetection * channels * channel_point_count); _aux_points.resize(channels); @@ -116,11 +115,9 @@ namespace s11n { _points.emplace_back(pt.intensity); } } - } private: - std::vector _header; std::vector> _aux_points; diff --git a/PythonAPI/carla/source/libcarla/SensorData.cpp b/PythonAPI/carla/source/libcarla/SensorData.cpp index c74e38e8c..af34eadc8 100644 --- a/PythonAPI/carla/source/libcarla/SensorData.cpp +++ b/PythonAPI/carla/source/libcarla/SensorData.cpp @@ -254,11 +254,11 @@ void export_sensor_data() { .def("save_to_disk", &SavePointCloudToDisk, (arg("path"))) .def("__len__", &csd::LidarMeasurement::size) .def("__iter__", iterator()) - .def("__getitem__", +[](const csd::LidarMeasurement &self, size_t pos) -> cr::Location { + .def("__getitem__", +[](const csd::LidarMeasurement &self, size_t pos) -> css::LidarDetection { return self.at(pos); }) - .def("__setitem__", +[](csd::LidarMeasurement &self, size_t pos, const cr::Location &point) { - self.at(pos) = point; + .def("__setitem__", +[](csd::LidarMeasurement &self, size_t pos, const css::LidarDetection &detection) { + self.at(pos) = detection; }) .def(self_ns::str(self_ns::self)) ; @@ -319,6 +319,12 @@ void export_sensor_data() { .def(self_ns::str(self_ns::self)) ; + class_("LidarDetection") + .def_readwrite("point", &css::LidarDetection::Point) + .def_readwrite("intensity", &css::LidarDetection::intensity) + .def(self_ns::str(self_ns::self)) + ; + class_("DVSEvent") .add_property("x", &csd::DVSEvent::x) .add_property("y", &csd::DVSEvent::y) diff --git a/PythonAPI/docs/sensor_data.yml b/PythonAPI/docs/sensor_data.yml index 80bd28e3d..3f43e8c84 100644 --- a/PythonAPI/docs/sensor_data.yml +++ b/PythonAPI/docs/sensor_data.yml @@ -161,12 +161,32 @@ params: - param_name: pos type: int - - param_name: location - type: carla.Location + - param_name: detection + type: carla.LidarDetection # -------------------------------------- - def_name: __str__ # -------------------------------------- + - class_name: LidarDetection + # - DESCRIPTION ------------------------ + doc: > + Data contained inside a carla.LidarMeasurement. Each of these represents one of the points in the cloud with its location and its asociated intensity. + # - PROPERTIES ------------------------- + instance_variables: + - var_name: point + type: carla.Location + doc: > + Point in xyz coordinates. + # -------------------------------------- + - var_name: intensity + type: float + doc: > + Computed intensity for this point. + # - METHODS ---------------------------- + methods: + - def_name: __str__ + # -------------------------------------- + - class_name: CollisionEvent parent: carla.SensorData # - DESCRIPTION ------------------------