Skip to content

Commit bb7df5b

Browse files
committed
Add VRT support
Signed-off-by: Ryan Friedman <[email protected]>
1 parent 92dbada commit bb7df5b

File tree

10 files changed

+192074
-28
lines changed

10 files changed

+192074
-28
lines changed

CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ ament_target_dependencies(${PROJECT_NAME} PUBLIC
5353
tf2_ros
5454
)
5555

56-
add_executable(test_tif_loader
57-
src/test_tif_loader.cpp
56+
add_executable(map_publisher
57+
src/map_publisher.cpp
5858
)
5959

60-
target_link_libraries(test_tif_loader PUBLIC
60+
target_link_libraries(map_publisher PUBLIC
6161
${PROJECT_NAME}
6262
)
6363

64+
add_executable(vsicurl_local_cache
65+
src/gdal_vsicurl_local_cache.cpp
66+
)
67+
6468
# Install
6569
install(
6670
DIRECTORY include/
@@ -81,7 +85,7 @@ ament_export_dependencies(GDAL)
8185

8286
install(
8387
TARGETS
84-
test_tif_loader
88+
map_publisher vsicurl_local_cache
8589
DESTINATION lib/${PROJECT_NAME}
8690
)
8791

@@ -90,6 +94,11 @@ install(DIRECTORY
9094
DESTINATION share/${PROJECT_NAME}/
9195
)
9296

97+
install(DIRECTORY
98+
resources
99+
DESTINATION share/${PROJECT_NAME}/
100+
)
101+
93102
install(DIRECTORY
94103
rviz
95104
DESTINATION share/${PROJECT_NAME}/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Affiliation: [ETH Zurich, Autonomous Systems Lab](https://asl.ethz.ch/)<br />**
1212

1313
## Setup
1414

15-
Install the dependencies. This package depends on gdal, to read georeferenced images and GeoTIFF files.
15+
Install the dependencies. This package depends on GDAL, to read georeferenced images and DEM files.
1616

1717
Pull in dependencies using rosdep
1818
```

include/grid_map_geo/grid_map_geo.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,16 @@ class GridMapGeo {
105105
* @return true Successfully loaded terrain
106106
* @return false Failed to load terrain
107107
*/
108-
bool Load(const std::string& map_path, const std::string& color_map_path);
108+
bool Load(const std::string& map_path, const std::string color_map_path);
109109

110110
/**
111-
* @brief Initialize grid map from a geotiff file
111+
* @brief Initialize grid map from a GDAL dataset
112112
*
113-
* @param path Path to dsm path (Supported formats are *.tif)
113+
* @param path Path to dsm path (Supported formats are https://gdal.org/drivers/raster/index.html)
114114
* @return true Successfully loaded terrain
115115
* @return false Failed to load terrain
116116
*/
117-
bool initializeFromGeotiff(const std::string& path);
117+
bool initializeFromGdalDataset(const std::string& path);
118118

119119
/**
120120
* @brief Load a color layer from a geotiff file (orthomosaic)

launch/load_tif.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def generate_launch_description():
3232
tif_loader = Node(
3333
package="grid_map_geo",
3434
namespace="grid_map_geo",
35-
executable="test_tif_loader",
35+
executable="map_publisher",
3636
name="tif_loader",
3737
parameters=[
3838
{"tif_path": LaunchConfiguration("tif_path")},

launch/load_tif_launch.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<arg name="location" default="sargans"/>
44
<node pkg="tf2_ros" exec="static_transform_publisher" name="world_map" args="--frame-id world --child-frame-id map"/>
55

6-
<node pkg="grid_map_geo" exec="test_tif_loader" name="test_tif_loader" namespace="grid_map_geo" output="screen">
6+
<node pkg="grid_map_geo" exec="map_publisher" name="map_publisher" namespace="grid_map_geo" output="screen">
77
<param name="tif_path" value="$(find-pkg-share grid_map_geo)/resources/sargans.tif"/>
88
<param name="tif_color_path" value="$(find-pkg-share grid_map_geo)/resources/sargans_color.tif"/>
99
</node>

launch/load_vrt_launch.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<launch>
2+
<arg name="rviz" default="false"/>
3+
<node pkg="tf2_ros" exec="static_transform_publisher" name="world_map" args="--frame-id world --child-frame-id map"/>
4+
5+
<node pkg="grid_map_geo" exec="map_publisher" name="map_publisher" output="screen">
6+
<param name="gdal_dataset_path" value="$(find-pkg-share grid_map_geo)/resources/ap_srtm1.vrt"/>
7+
</node>
8+
9+
<group if="$(var rviz)">
10+
<node exec="rviz2" name="rviz2" pkg="rviz2" args="-d $(find-pkg-share grid_map_geo)/launch/config.rviz" />
11+
</group>
12+
</launch>

resources/ap_srtm1.vrt

Lines changed: 191983 additions & 0 deletions
Large diffs are not rendered by default.

src/gdal_vsicurl_local_cache.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
/**
35+
* @brief Support caching VSICURL requests to local storage to reduce network usage
36+
*
37+
* @author Ryan Friedman <[email protected]>
38+
*/
39+
40+
int main() { return 0; }

src/grid_map_geo.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ GridMapGeo::GridMapGeo(const std::string &frame_id) { frame_id_ = frame_id; }
6262

6363
GridMapGeo::~GridMapGeo() {}
6464

65-
bool GridMapGeo::Load(const std::string &map_path, const std::string &color_map_path) {
66-
bool loaded = initializeFromGeotiff(map_path);
65+
bool GridMapGeo::Load(const std::string &map_path, const std::string color_map_path) {
66+
bool loaded = initializeFromGdalDataset(map_path);
6767
if (!color_map_path.empty()) { // Load color layer if the color path is nonempty
6868
bool color_loaded = addColorFromGeotiff(color_map_path);
6969
}
7070
if (!loaded) return false;
7171
return true;
7272
}
7373

74-
bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
74+
bool GridMapGeo::initializeFromGdalDataset(const std::string &path) {
7575
GDALAllRegister();
7676
const auto dataset = GDALDatasetUniquePtr(GDALDataset::FromHandle(GDALOpen(path.c_str(), GA_ReadOnly)));
7777
if (!dataset) {
7878
std::cout << "Failed to open" << std::endl;
7979
return false;
8080
}
81-
std::cout << std::endl << "Loading GeoTIFF file for gridmap" << std::endl;
81+
std::cout << std::endl << "Loading GDAL Dataset for gridmap" << std::endl;
8282

8383
double originX, originY, pixelSizeX, pixelSizeY;
8484
std::array<double, 6> geoTransform;
@@ -104,17 +104,19 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
104104

105105
const OGRSpatialReference *spatial_ref = dataset->GetSpatialRef();
106106
coordinate_name_ = spatial_ref->GetAttrValue("geogcs");
107+
107108
// Get image metadata
108109
unsigned width = dataset->GetRasterXSize();
109110
unsigned height = dataset->GetRasterYSize();
110111
double resolution = pixelSizeX;
111-
std::cout << "Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
112+
std::cout << __LINE__ << "RasterX: " << width << " RasterY: " << height << " pixelSizeX: " << pixelSizeX << std::endl;
112113

113114
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
114115
// Y pixel coordinates go towards the south
115116
const double lengthX = resolution * width;
116117
const double lengthY = resolution * height;
117118
grid_map::Length length(lengthX, lengthY);
119+
std::cout << __LINE__ << "GMLX: " << lengthX << " GMLY: " << lengthY << std::endl;
118120

119121
double mapcenter_e = originX + pixelSizeX * width * 0.5;
120122
double mapcenter_n = originY + pixelSizeY * height * 0.5;
@@ -128,18 +130,18 @@ bool GridMapGeo::initializeFromGeotiff(const std::string &path) {
128130
grid_map_.add("elevation");
129131
GDALRasterBand *elevationBand = dataset->GetRasterBand(1);
130132

131-
std::vector<float> data(width * height, 0.0f);
132-
elevationBand->RasterIO(GF_Read, 0, 0, width, height, &data[0], width, height, GDT_Float32, 0, 0);
133+
// std::vector<float> data(width * height, 0.0f);
134+
// elevationBand->RasterIO(GF_Read, 0, 0, width, height, &data[0], width, height, GDT_Float32, 0, 0);
133135

134-
grid_map::Matrix &layer_elevation = grid_map_["elevation"];
135-
for (grid_map::GridMapIterator iterator(grid_map_); !iterator.isPastEnd(); ++iterator) {
136-
const grid_map::Index gridMapIndex = *iterator;
137-
// TODO: This may be wrong if the pixelSizeY > 0
138-
int x = width - 1 - gridMapIndex(0);
139-
int y = gridMapIndex(1);
136+
// grid_map::Matrix &layer_elevation = grid_map_["elevation"];
137+
// for (grid_map::GridMapIterator iterator(grid_map_); !iterator.isPastEnd(); ++iterator) {
138+
// const grid_map::Index gridMapIndex = *iterator;
139+
// // TODO: This may be wrong if the pixelSizeY > 0
140+
// int x = width - 1 - gridMapIndex(0);
141+
// int y = gridMapIndex(1);
140142

141-
layer_elevation(x, y) = data[gridMapIndex(0) + width * gridMapIndex(1)];
142-
}
143+
// layer_elevation(x, y) = data[gridMapIndex(0) + width * gridMapIndex(1)];
144+
// }
143145

144146
return true;
145147
}
@@ -169,7 +171,7 @@ bool GridMapGeo::addColorFromGeotiff(const std::string &path) {
169171
unsigned width = dataset->GetRasterXSize();
170172
unsigned height = dataset->GetRasterYSize();
171173
double resolution = pixelSizeX;
172-
std::cout << "Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
174+
std::cout << __LINE__ << "Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
173175

174176
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
175177
// Y pixel coordinates go towards the south
@@ -230,7 +232,7 @@ bool GridMapGeo::addLayerFromGeotiff(const std::string &layer_name, const std::s
230232
unsigned width = dataset->GetRasterXSize();
231233
unsigned height = dataset->GetRasterYSize();
232234
double resolution = pixelSizeX;
233-
std::cout << "Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
235+
std::cout << __LINE__ << "Width: " << width << " Height: " << height << " Resolution: " << resolution << std::endl;
234236

235237
// pixelSizeY is negative because the origin of the image is the north-east corner and positive
236238
// Y pixel coordinates go towards the south
File renamed without changes.

0 commit comments

Comments
 (0)