Skip to content

Commit

Permalink
Merge branch 'fix/grid_map_core_remove_compiler_warnings' into 'master'
Browse files Browse the repository at this point in the history
[grid_map_core] Remove compiler warnings

GitOrigin-RevId: 593af35e98d1d24b28f8aaedbc18d96e99f861cf
  • Loading branch information
Emilk Roy Sempertegui Aveiga authored and CI committed Apr 7, 2021
1 parent 1cbbf46 commit 6ddff74
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 51 deletions.
25 changes: 6 additions & 19 deletions grid_map_core/include/grid_map_core/GridMapMath.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@

namespace grid_map {

union Color
{
unsigned long longColor;
float floatColor;
};

/*!
* Gets the position of a cell specified by its index in the map frame.
* @param[out] position the position of the center of the cell in the map frame.
Expand Down Expand Up @@ -289,25 +295,6 @@ size_t getLinearIndexFromIndex(const Index& index, const Size& bufferSize, const
*/
Index getIndexFromLinearIndex(const size_t linearIndex, const Size& bufferSize, const bool rowMajor = false);

/*!
* Generates a list of indices for a region in the map.
* @param regionIndex the region top-left index.
* @param regionSize the region size.
* @param indices the list of indices of the region.
*/
void getIndicesForRegion(const Index& regionIndex, const Size& regionSize,
std::vector<Index> indices);

/*!
* Generates a list of indices for multiple regions in the map.
* This method makes sure every index is only once contained in the list.
* @param regionIndeces the regions' top-left index.
* @param regionSizes the regions' sizes.
* @param indices the list of indices of the regions.
*/
void getIndicesForRegions(const std::vector<Index>& regionIndeces, const Size& regionSizes,
std::vector<Index> indices);

/*!
* Transforms an int color value (concatenated RGB values) to an int color vector (RGB from 0-255).
* @param [in] colorValue the concatenated RGB color value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class GridMapIterator
*/
GridMapIterator(const GridMapIterator* other);

/*!
* Copy constructor.
* @param other the object to copy.
*/
GridMapIterator(const GridMapIterator &other) = default;

/*!
* Assignment operator.
* @param iterator the iterator to copy data from.
Expand Down
2 changes: 1 addition & 1 deletion grid_map_core/src/CubicInterpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ unsigned int bindIndexToRange(int idReq, unsigned int nElem)
if (idReq < 0) {
return 0;
}
if (idReq >= nElem) {
if (static_cast<unsigned int>(idReq) >= nElem) {
return static_cast<unsigned int>(nElem - 1);
}
return static_cast<unsigned int>(idReq);
Expand Down
10 changes: 7 additions & 3 deletions grid_map_core/src/GridMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ float GridMap::atPosition(const std::string& layer, const Position& position, In
interpolationMethod = InterpolationMethods::INTER_LINEAR;
skipNextSwitchCase = true;
}
[[fallthrough]];
}
case InterpolationMethods::INTER_CUBIC: {
if (!skipNextSwitchCase) {
Expand All @@ -187,13 +188,16 @@ float GridMap::atPosition(const std::string& layer, const Position& position, In
interpolationMethod = InterpolationMethods::INTER_LINEAR;
}
}
[[fallthrough]];
}
case InterpolationMethods::INTER_LINEAR: {
float value;
if (atPositionLinearInterpolated(layer, position, value))
return value;
else
else {
interpolationMethod = InterpolationMethods::INTER_NEAREST;
}
[[fallthrough]];
}
case InterpolationMethods::INTER_NEAREST: {
Index index;
Expand Down Expand Up @@ -289,7 +293,7 @@ GridMap GridMap::getSubmap(const Position& position, const Length& length, bool&
return getSubmap(position, length, index, isSuccess);
}

GridMap GridMap::getSubmap(const Position& position, const Length& length, Index& indexInSubmap, bool& isSuccess) const {
GridMap GridMap::getSubmap(const Position& position, const Length& length, Index& /*indexInSubmap*/, bool& isSuccess) const {
// Submap the generate.
GridMap submap(layers_);
submap.setBasicLayers(basicLayers_);
Expand Down Expand Up @@ -696,7 +700,7 @@ void GridMap::convertToDefaultStartIndex() {
}

Position GridMap::getClosestPositionInMap(const Position& position) const {
if (getSize().x() < 1u || getSize().y() < 1u) {
if (getSize().x() < 1 || getSize().y() < 1) {
return position_;
}

Expand Down
21 changes: 3 additions & 18 deletions grid_map_core/src/GridMapMath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,21 +517,6 @@ Index getIndexFromLinearIndex(const size_t linearIndex, const Size& bufferSize,
return Index((int)linearIndex / bufferSize(1), (int)linearIndex % bufferSize(1));
}

void getIndicesForRegion(const Index& regionIndex, const Size& regionSize,
std::vector<Index> indices)
{
// for (int i = line.index_; col < line.endIndex(); col++) {
// for (int i = 0; i < getSize()(0); i++) {
//
// }
// }
}

void getIndicesForRegions(const std::vector<Index>& regionIndeces, const Size& regionSizes,
std::vector<Index> indices)
{
}

bool colorValueToVector(const unsigned long& colorValue, Eigen::Vector3i& colorVector)
{
colorVector(0) = (colorValue >> 16) & 0x0000ff;
Expand Down Expand Up @@ -564,9 +549,9 @@ bool colorVectorToValue(const Eigen::Vector3i& colorVector, unsigned long& color

void colorVectorToValue(const Eigen::Vector3i& colorVector, float& colorValue)
{
unsigned long color = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
// cppcheck-suppress invalidPointerCast
colorValue = *reinterpret_cast<float*>(&color);
Color colors;
colors.longColor = (colorVector(0) << 16) + (colorVector(1) << 8) + colorVector(2);
colorValue = colors.floatColor;
}

void colorVectorToValue(const Eigen::Vector3f& colorVector, float& colorValue)
Expand Down
10 changes: 5 additions & 5 deletions grid_map_core/src/Polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Polygon::~Polygon() {}
bool Polygon::isInside(const Position& point) const
{
int cross = 0;
for (int i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
for (size_t i = 0, j = vertices_.size() - 1; i < vertices_.size(); j = i++) {
if ( ((vertices_[i].y() > point.y()) != (vertices_[j].y() > point.y()))
&& (point.x() < (vertices_[j].x() - vertices_[i].x()) * (point.y() - vertices_[i].y()) /
(vertices_[j].y() - vertices_[i].y()) + vertices_[i].x()) )
Expand Down Expand Up @@ -102,7 +102,7 @@ double Polygon::getArea() const
{
double area = 0.0;
int j = vertices_.size() - 1;
for (int i = 0; i < vertices_.size(); i++) {
for (size_t i = 0; i < vertices_.size(); i++) {
area += (vertices_.at(j).x() + vertices_.at(i).x())
* (vertices_.at(j).y() - vertices_.at(i).y());
j = i;
Expand All @@ -116,7 +116,7 @@ Position Polygon::getCentroid() const
std::vector<Position> vertices = getVertices();
vertices.push_back(vertices.at(0));
double area = 0.0;
for (int i = 0; i < vertices.size() - 1; i++) {
for (size_t i = 0; i < vertices.size() - 1; i++) {
const double a = vertices[i].x() * vertices[i+1].y() - vertices[i+1].x() * vertices[i].y();
area += a;
centroid.x() += a * (vertices[i].x() + vertices[i+1].x());
Expand Down Expand Up @@ -220,7 +220,7 @@ bool Polygon::offsetInward(const double margin)
return true;
}

std::vector<Polygon> Polygon::triangulate(const TriangulationMethods& method) const
std::vector<Polygon> Polygon::triangulate(const TriangulationMethods& /*method*/) const
{
// TODO Add more triangulation methods.
// https://en.wikipedia.org/wiki/Polygon_triangulation
Expand Down Expand Up @@ -311,7 +311,7 @@ Polygon Polygon::monotoneChainConvexHullOfPoints(const std::vector<Position>& po

int k = 0;
// Build lower hull
for (int i = 0; i < sortedPoints.size(); ++i) {
for (size_t i = 0; i < sortedPoints.size(); ++i) {
while (k >= 2 && vectorsMakeClockwiseTurn(pointsConvexHull.at(k - 2), pointsConvexHull.at(k - 1), sortedPoints.at(i))) {
k--;
}
Expand Down
2 changes: 1 addition & 1 deletion grid_map_core/src/iterators/PolygonIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool PolygonIterator::isInside() const
return polygon_.isInside(position);
}

void PolygonIterator::findSubmapParameters(const grid_map::Polygon& polygon, Index& startIndex, Size& bufferSize) const
void PolygonIterator::findSubmapParameters(const grid_map::Polygon& /*polygon*/, Index& startIndex, Size& bufferSize) const
{
Position topLeft = polygon_.getVertices()[0];
Position bottomRight = topLeft;
Expand Down
8 changes: 4 additions & 4 deletions grid_map_core/src/iterators/SpiralIterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ SpiralIterator& SpiralIterator::operator =(const SpiralIterator& other)
return *this;
}

bool SpiralIterator::operator !=(const SpiralIterator& other) const
bool SpiralIterator::operator !=(const SpiralIterator& /*other*/) const
{
return (pointsRing_.back() != pointsRing_.back()).any();
}
Expand Down Expand Up @@ -101,16 +101,16 @@ void SpiralIterator::generateRing()
normal.x() = -signum(point.y());
normal.y() = signum(point.x());
if (normal.x() != 0
&& (int) Vector(point.x() + normal.x(), point.y()).norm() == distance_)
&& static_cast<unsigned int>(Vector(point.x() + normal.x(), point.y()).norm()) == distance_)
point.x() += normal.x();
else if (normal.y() != 0
&& (int) Vector(point.x(), point.y() + normal.y()).norm() == distance_)
&& static_cast<unsigned int>(Vector(point.x(), point.y() + normal.y()).norm()) == distance_)
point.y() += normal.y();
else {
point.x() += normal.x();
point.y() += normal.y();
}
} while (point.x() != distance_ || point.y() != 0);
} while (static_cast<unsigned int>(point.x()) != distance_ || point.y() != 0);
}

double SpiralIterator::getCurrentRadius() const
Expand Down

0 comments on commit 6ddff74

Please # to comment.