Skip to content

Commit 6aa3892

Browse files
committed
Change type signature
Signed-off-by: Arjo Chakravarty <arjoc@intrinsic.ai>
1 parent a8d171a commit 6aa3892

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

include/gz/math/OccupancyGrid.hh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef GZ_MATH_OCCUPANCY_GRID_HH_
1818
#define GZ_MATH_OCCUPANCY_GRID_HH_
1919

20+
#include <cstdint>
2021
#include <memory>
2122
#include <vector>
2223

@@ -123,11 +124,11 @@ inline namespace GZ_MATH_VERSION_NAMESPACE {
123124

124125
/// \brief Export the occupancy grid to a RGB image buffer.
125126
/// \param[out] _pixels The output buffer to store the RGB image data.
126-
public: void ExportToRGBImage(std::vector<unsigned char> &_pixels) const;
127+
public: void ExportToRGBImage(std::vector<uint8_t> &_pixels) const;
127128

128129
/// \brief Export the occupancy grid to a raw buffer.
129130
/// \param[out] _data The output buffer to store the raw occupancy data.
130-
public: void GetRawOccupancy(std::vector<char> &_data) const;
131+
public: void GetRawOccupancy(std::vector<int8_t> &_data) const;
131132

132133
/// \brief Get the resolution of the occupancy grid.
133134
/// \return The resolution in meters per cell.

src/OccupancyGrid.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*
1616
*/
1717
#include <cmath>
18+
#include <cstdint>
1819
#include <memory>
1920
#include <utility>
2021
#include <vector>
@@ -246,15 +247,15 @@ void OccupancyGrid::MarkFree(double worldX0, double worldY0, double worldX1,
246247
}
247248

248249
/////////////////////////////////////////////////
249-
void OccupancyGrid::ExportToRGBImage(std::vector<unsigned char>& _pixels) const
250+
void OccupancyGrid::ExportToRGBImage(std::vector<uint8_t>& _pixels) const
250251
{
251252
_pixels.assign(this->pImpl->widthCells * this->pImpl->heightCells * 3, 0);
252253

253254
for (int gridY = 0; gridY < this->pImpl->heightCells; ++gridY)
254255
{
255256
for (int gridX = 0; gridX < this->pImpl->widthCells; ++gridX)
256257
{
257-
unsigned char r = 0, g = 0, b = 0;
258+
uint8_t r = 0, g = 0, b = 0;
258259
auto res = this->pImpl->GetCellStateImpl(gridX, gridY);
259260
switch (res)
260261
{
@@ -283,15 +284,15 @@ void OccupancyGrid::ExportToRGBImage(std::vector<unsigned char>& _pixels) const
283284
}
284285

285286
/////////////////////////////////////////////////
286-
void OccupancyGrid::GetRawOccupancy(std::vector<char>& _data) const
287+
void OccupancyGrid::GetRawOccupancy(std::vector<int8_t>& _data) const
287288
{
288289
_data.assign(this->pImpl->widthCells * this->pImpl->heightCells, 0);
289290

290291
for (int gridY = 0; gridY < this->pImpl->heightCells; ++gridY)
291292
{
292293
for (int gridX = 0; gridX < this->pImpl->widthCells; ++gridX)
293294
{
294-
char val = -1;
295+
int8_t val = -1;
295296
auto res = this->pImpl->GetCellStateImpl(gridX, gridY);
296297
switch (res)
297298
{

src/OccupancyGrid_TEST.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ TEST(OccupancyGridTest, ExportToRGBImage)
195195
grid.SetCellState(1, 0, CellState::Unknown);
196196
// (1, 1) is implicitly Unknown
197197

198-
std::vector<unsigned char> pixels;
198+
std::vector<uint8_t> pixels;
199199
grid.ExportToRGBImage(pixels);
200200

201201
// Expected size: 2x2 grid * 3 channels (RGB)
@@ -231,7 +231,7 @@ TEST(OccupancyGridTest, GetRawOccupancy)
231231
grid.SetCellState(1, 1, CellState::Free);
232232
grid.SetCellState(2, 1, CellState::Unknown);
233233

234-
std::vector<char> data;
234+
std::vector<int8_t> data;
235235
grid.GetRawOccupancy(data);
236236

237237
ASSERT_EQ(data.size(), 6);

src/python_pybind11/src/OccupancyGrid.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <pybind11/stl.h>
2020
#include <pybind11/numpy.h>
2121

22+
#include <cstdint>
2223
#include <memory>
2324
#include <string>
2425
#include <tuple>
@@ -73,15 +74,15 @@ void defineMathOccupancyGrid(py::module &m, const std::string &typestr)
7374
.def("mark_free", &Class::MarkFree,
7475
"Mark a path as free.")
7576
.def("export_to_rgb_image", [](const Class &self) {
76-
std::vector<unsigned char> pixels;
77+
std::vector<uint8_t> pixels;
7778
self.ExportToRGBImage(pixels);
7879
return py::bytes(reinterpret_cast<const char*>(pixels.data()),
7980
pixels.size());
8081
}, "Export the occupancy grid to a RGB image buffer.")
8182
.def("get_raw_occupancy", [](const Class &self) {
82-
std::vector<char> data;
83+
std::vector<int8_t> data;
8384
self.GetRawOccupancy(data);
84-
return py::bytes(data.data(), data.size());
85+
return py::bytes(reinterpret_cast<const char*>(data.data()), data.size());
8586
}, "Export the occupancy grid to a raw buffer.")
8687
.def("get_resolution", &Class::GetResolution,
8788
"Get the resolution of the occupancy grid.")

0 commit comments

Comments
 (0)