Skip to content

Commit 3fd9206

Browse files
authored
Hide GDAL from public interface, fix export (#59)
* Enforce export in CI * Hide implementation details of GDAL in implementation * Switch to build-scope includes * Install headers per latest ament recommendations to allow package: https://docs.ros.org/en/humble/How-To-Guides/Ament-CMake-Documentation.html#adding-targets * This is crucial before realeasing as a library * Remove unused yaml dependency * Add all missing libraries in ament_export_dependencies * Fix a few typos in comments * Add badges for all jobs but point them to the default ros2 branch rather than any branch * Fix style check not running on ros2 branch Signed-off-by: Ryan Friedman <[email protected]>
1 parent 92dbada commit 3fd9206

File tree

14 files changed

+133
-67
lines changed

14 files changed

+133
-67
lines changed

.github/workflows/build_test.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,18 @@ jobs:
2828
rosdep install --from-paths src --ignore-src -y
2929
shell: bash
3030
- name: Colcon Build (Release)
31-
working-directory:
3231
run: |
3332
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash
3433
colcon build --cmake-args -DCMAKE_BUILD_TYPE=Release --packages-up-to grid_map_geo
3534
shell: bash
35+
- name: Verify Export
36+
run: |
37+
source /opt/ros/${{matrix.config.rosdistro}}/setup.bash
38+
source install/setup.bash
39+
cd src/grid_map_geo/test/export
40+
colcon build
41+
./build/grid_map_export_test/main
42+
shell: bash
3643
# - name: unit_tests
3744
# working-directory:
3845
# run: |

.github/workflows/check_style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Style Checks
33
on:
44
push:
55
branches:
6-
- master
6+
- ros2
77
pull_request:
88
branches:
99
- '*'

CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ find_package(rclcpp REQUIRED)
2525
find_package(Eigen3 REQUIRED)
2626
find_package(GDAL 3 REQUIRED)
2727

28-
find_package(yaml_cpp_vendor REQUIRED)
29-
link_directories(${yaml_cpp_vendor_LIBRARY_DIRS})
3028

3129
# Reverse compatability for GDAL<3.5
3230
# https://gdal.org/development/cmake.html
@@ -37,13 +35,13 @@ endif()
3735
# Build
3836
add_library(${PROJECT_NAME}
3937
src/grid_map_geo.cpp
38+
src/transform.cpp
4039
)
4140

4241
target_include_directories(${PROJECT_NAME}
4342
PUBLIC
44-
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
45-
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
46-
)
43+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
44+
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>")
4745

4846
target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen PRIVATE GDAL::GDAL)
4947

@@ -77,7 +75,9 @@ install(
7775
)
7876

7977
ament_export_targets(export_${PROJECT_NAME} HAS_LIBRARY_TARGET)
80-
ament_export_dependencies(GDAL)
78+
79+
# Everything in find_package goes here too, ordered alphabetically.
80+
ament_export_dependencies(Eigen3 GDAL grid_map_core grid_map_msgs grid_map_ros tf2_ros rclcpp)
8181

8282
install(
8383
TARGETS
@@ -103,7 +103,7 @@ install(DIRECTORY
103103
# Test
104104
include(CTest)
105105
if(BUILD_TESTING)
106-
add_subdirectory(test)
106+
add_subdirectory(test/unit)
107107
endif()
108108

109109
ament_package()

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# grid_map_geo
22

3-
[![Build Test](https://github.com/ethz-asl/grid_map_geo/actions/workflows/build_test.yml/badge.svg)](https://github.com/ethz-asl/grid_map_geo/actions/workflows/build_test.yml)
3+
[![Build Test](https://github.com/ethz-asl/grid_map_geo/actions/workflows/build_test.yml/badge.svg?branch=ros2)](https://github.com/ethz-asl/grid_map_geo/actions/workflows/build_test.yml)
4+
[![Doxygen Build](https://github.com/ethz-asl/grid_map_geo/actions/workflows/doxygen_build.yml/badge.svg?branch=ros2)](https://github.com/ethz-asl/grid_map_geo/actions/workflows/doxygen_build.yml)
5+
[![Style Checks](https://github.com/ethz-asl/grid_map_geo/actions/workflows/check_style.yml/badge.svg?branch=ros2)](https://github.com/ethz-asl/grid_map_geo/actions/workflows/check_style.yml)
46

57
This package provides a georeferenced extension to the elevation map [grid_map](https://github.com/ANYbotics/grid_map) using [GDAL](https://gdal.org/), library for raster and vector geospatial data formats
68

include/grid_map_geo/grid_map_geo.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,13 @@
3434
#ifndef GRID_MAP_GEO_H
3535
#define GRID_MAP_GEO_H
3636

37+
#include <tf2_ros/transform_broadcaster.h>
38+
3739
#include <grid_map_core/GridMap.hpp>
3840
#include <grid_map_core/iterators/GridMapIterator.hpp>
3941
#include <iostream>
4042

41-
#include "grid_map_geo/transform.hpp"
42-
#include "tf2_ros/transform_broadcaster.h"
43+
#include "transform.hpp"
4344
struct Location {
4445
ESPG espg{ESPG::WGS84};
4546
Eigen::Vector3d position{Eigen::Vector3d::Zero()};
@@ -95,7 +96,7 @@ class GridMapGeo {
9596
*
9697
* @param map_path Path to dsm path (Supported formats are *.tif)
9798
*/
98-
bool Load(const std::string& map_path) { Load(map_path, ""); }
99+
bool Load(const std::string& map_path) { return Load(map_path, ""); }
99100

100101
/**
101102
* @brief Helper function for loading terrain from path
@@ -184,4 +185,4 @@ class GridMapGeo {
184185
std::string frame_id_{""};
185186
std::string coordinate_name_{""};
186187
};
187-
#endif
188+
#endif // GRID_MAP_GEO_H

include/grid_map_geo/transform.hpp

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@
3434
#ifndef GRID_MAP_GEO_TRANSFORM_H
3535
#define GRID_MAP_GEO_TRANSFORM_H
3636

37-
#if __APPLE__
38-
#include <gdal.h>
39-
#include <gdal_priv.h>
40-
#include <ogr_p.h>
41-
#include <ogr_spatialref.h>
42-
#else
43-
#include <gdal/gdal.h>
44-
#include <gdal/gdal_priv.h>
45-
#include <gdal/ogr_p.h>
46-
#include <gdal/ogr_spatialref.h>
47-
#endif
48-
4937
#include <Eigen/Dense>
5038

5139
enum class ESPG { ECEF = 4978, WGS84 = 4326, WGS84_32N = 32632, CH1903_LV03 = 21781 };
@@ -58,21 +46,7 @@ enum class ESPG { ECEF = 4978, WGS84 = 4326, WGS84_32N = 32632, CH1903_LV03 = 21
5846
* @param source_coordinates
5947
* @return Eigen::Vector3d
6048
*/
61-
inline Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen::Vector3d source_coordinates) {
62-
OGRSpatialReference source, target;
63-
source.importFromEPSG(static_cast<int>(src_coord));
64-
target.importFromEPSG(static_cast<int>(tgt_coord));
65-
66-
OGRPoint p;
67-
p.setX(source_coordinates(0));
68-
p.setY(source_coordinates(1));
69-
p.setZ(source_coordinates(2));
70-
p.assignSpatialReference(&source);
71-
72-
p.transformTo(&target);
73-
Eigen::Vector3d target_coordinates(p.getX(), p.getY(), p.getZ());
74-
return target_coordinates;
75-
}
49+
Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen::Vector3d source_coordinates);
7650

7751
/**
7852
* @brief Helper function for transforming using gdal
@@ -82,22 +56,6 @@ inline Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, cons
8256
* @param source_coordinates
8357
* @return Eigen::Vector3d
8458
*/
85-
inline Eigen::Vector3d transformCoordinates(ESPG src_coord, const std::string wkt,
86-
const Eigen::Vector3d source_coordinates) {
87-
OGRSpatialReference source, target;
88-
char* wkt_string = const_cast<char*>(wkt.c_str());
89-
source.importFromEPSG(static_cast<int>(src_coord));
90-
target.importFromWkt(&wkt_string);
91-
92-
OGRPoint p;
93-
p.setX(source_coordinates(0));
94-
p.setY(source_coordinates(1));
95-
p.setZ(source_coordinates(2));
96-
p.assignSpatialReference(&source);
97-
98-
p.transformTo(&target);
99-
Eigen::Vector3d target_coordinates(p.getX(), p.getY(), p.getZ());
100-
return target_coordinates;
101-
}
59+
Eigen::Vector3d transformCoordinates(ESPG src_coord, const std::string wkt, const Eigen::Vector3d source_coordinates);
10260

103-
#endif
61+
#endif // GRID_MAP_GEO_TRANSFORM_H

src/grid_map_geo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
****************************************************************************/
3333

3434
/**
35-
* @brief Terain map representation
35+
* @brief Terrain map representation
3636
*
3737
* @author Jaeyoung Lim <[email protected]>
3838
*/

src/test_tif_loader.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,21 @@
3131
*
3232
****************************************************************************/
3333
/**
34-
* @brief Node to test planner in the view utiltiy map
34+
* @brief Node to test planner in the view utility map
3535
*
3636
*
3737
* @author Jaeyoung Lim <[email protected]>
3838
*/
3939

40-
#include "geometry_msgs/msg/transform_stamped.hpp"
40+
#include <grid_map_msgs/msg/grid_map.h>
41+
#include <tf2_ros/static_transform_broadcaster.h>
42+
43+
#include <geometry_msgs/msg/transform_stamped.hpp>
44+
#include <grid_map_ros/GridMapRosConverter.hpp>
45+
#include <rclcpp/rclcpp.hpp>
46+
#include <std_msgs/msg/string.hpp>
47+
4148
#include "grid_map_geo/grid_map_geo.hpp"
42-
#include "grid_map_msgs/msg/grid_map.h"
43-
#include "grid_map_ros/GridMapRosConverter.hpp"
44-
#include "rclcpp/rclcpp.hpp"
45-
#include "std_msgs/msg/string.hpp"
46-
#include "tf2_ros/static_transform_broadcaster.h"
4749

4850
using namespace std::chrono_literals;
4951

src/transform.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/****************************************************************************
2+
*
3+
* Copyright (c) 2022 Jaeyoung Lim, ASL, ETH Zurich, Switzerland
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* 2. Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in
13+
* the documentation and/or other materials provided with the
14+
* distribution.
15+
* 3. Neither the name terrain-navigation nor the names of its contributors may be
16+
* used to endorse or promote products derived from this software
17+
* without specific prior written permission.
18+
*
19+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
22+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
****************************************************************************/
33+
34+
#include "grid_map_geo/transform.hpp"
35+
36+
#if __APPLE__
37+
#include <gdal.h>
38+
#include <gdal_priv.h>
39+
#include <ogr_p.h>
40+
#include <ogr_spatialref.h>
41+
#else
42+
#include <gdal/gdal.h>
43+
#include <gdal/gdal_priv.h>
44+
#include <gdal/ogr_p.h>
45+
#include <gdal/ogr_spatialref.h>
46+
#endif
47+
48+
Eigen::Vector3d transformCoordinates(ESPG src_coord, ESPG tgt_coord, const Eigen::Vector3d source_coordinates) {
49+
OGRSpatialReference source, target;
50+
source.importFromEPSG(static_cast<int>(src_coord));
51+
target.importFromEPSG(static_cast<int>(tgt_coord));
52+
53+
OGRPoint p;
54+
p.setX(source_coordinates(0));
55+
p.setY(source_coordinates(1));
56+
p.setZ(source_coordinates(2));
57+
p.assignSpatialReference(&source);
58+
59+
p.transformTo(&target);
60+
Eigen::Vector3d target_coordinates(p.getX(), p.getY(), p.getZ());
61+
return target_coordinates;
62+
}
63+
64+
Eigen::Vector3d transformCoordinates(ESPG src_coord, const std::string wkt, const Eigen::Vector3d source_coordinates) {
65+
OGRSpatialReference source, target;
66+
char* wkt_string = const_cast<char*>(wkt.c_str());
67+
source.importFromEPSG(static_cast<int>(src_coord));
68+
target.importFromWkt(&wkt_string);
69+
70+
OGRPoint p;
71+
p.setX(source_coordinates(0));
72+
p.setY(source_coordinates(1));
73+
p.setZ(source_coordinates(2));
74+
p.assignSpatialReference(&source);
75+
76+
p.transformTo(&target);
77+
Eigen::Vector3d target_coordinates(p.getX(), p.getY(), p.getZ());
78+
return target_coordinates;
79+
}

test/export/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Add gtest based cpp test target and link libraries
2+
cmake_minimum_required(VERSION 3.14)
3+
project(grid_map_export_test)
4+
find_package(grid_map_geo REQUIRED)
5+
add_executable(main main.cpp)
6+
target_link_libraries(main PRIVATE grid_map_geo::grid_map_geo)
7+

0 commit comments

Comments
 (0)