Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pymem fileformat #753

Merged
merged 52 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3c04860
Add draft document for file format
RainerKuemmerle Dec 10, 2023
b23ce9d
WIP Graph IO Abstraction
RainerKuemmerle Dec 16, 2023
72f8357
Refine draft of the file format
RainerKuemmerle Dec 17, 2023
56233d3
WIP reading in from g2o format
RainerKuemmerle Dec 17, 2023
ef1f219
Add save function for g2o format
RainerKuemmerle Dec 20, 2023
2c49cd8
Start to add test for save/load in g2o format
RainerKuemmerle Dec 21, 2023
efbc918
Implement save/load of OptimizableGraph with AbstractGraph
RainerKuemmerle Dec 23, 2023
85ce55e
Add JSON by using cereal library
RainerKuemmerle Dec 24, 2023
7aae11a
Add file format to save/load API
RainerKuemmerle Dec 24, 2023
1eabf2a
Extend unit tests
RainerKuemmerle Dec 24, 2023
257a4f1
Update python wrapper API
RainerKuemmerle Dec 25, 2023
9d32a9e
Handle cereal's exception
RainerKuemmerle Dec 25, 2023
72102c1
Add XML and binary IO formats
RainerKuemmerle Dec 25, 2023
6611f5f
Update README and CI to include cereal dependency
RainerKuemmerle Dec 25, 2023
8cde6f1
Try workaround for broken cereal cmake
RainerKuemmerle Dec 25, 2023
90e2d15
Try to fix MSVC
RainerKuemmerle Dec 25, 2023
950bd10
Support renamed types when loading graph
RainerKuemmerle Dec 27, 2023
0f2d579
Simplify IO code with cereal by templated functions
RainerKuemmerle Dec 27, 2023
8847654
Drop read/write API for Vertex and Edges
RainerKuemmerle Dec 27, 2023
99d37de
Fix CMakeLists
RainerKuemmerle Dec 27, 2023
850a371
Fix tests
RainerKuemmerle Dec 27, 2023
c75397b
Simplify AbstractGraph's API
RainerKuemmerle Dec 27, 2023
b8871ef
Add test load/save with data in the graph
RainerKuemmerle Dec 27, 2023
7b65d27
Cleaning up deprecated IO helpers
RainerKuemmerle Dec 28, 2023
c356477
Fix saving of dynamically sized edge
RainerKuemmerle Dec 28, 2023
2cc8139
Cleaning API
RainerKuemmerle Dec 28, 2023
d20506f
Support dynamically sized vertex in G2O format
RainerKuemmerle Dec 29, 2023
eb5a848
Add tests for BaseVertex's methods
RainerKuemmerle Dec 29, 2023
4ed408b
Re-add the IO tests for 2D SLAM
RainerKuemmerle Dec 31, 2023
a3ea2d7
Add IO tests for SBA types
RainerKuemmerle Jan 7, 2024
56a3118
Fix SBA test names
RainerKuemmerle Jan 7, 2024
c0df08c
Rework ParameterCamera in SLAM3D
RainerKuemmerle Jan 20, 2024
5e33a32
Drop aux include files
RainerKuemmerle Jan 21, 2024
ff91c61
Fix writing param IDs in g2o format
RainerKuemmerle Jan 21, 2024
3ababa2
Extend typed IO tests to support optional parameters
RainerKuemmerle Jan 21, 2024
08f3789
Implement type based tests for Jacobian
RainerKuemmerle Jan 28, 2024
6343821
Fix compile error in tests
RainerKuemmerle Jan 28, 2024
4fc6b3d
Use more flexible setInformation
RainerKuemmerle Jan 28, 2024
def728b
Fix linkage of ExtractTupleHead
RainerKuemmerle Jan 28, 2024
70f0b1c
Fix compilation of Python wrapper
RainerKuemmerle Jan 28, 2024
9788518
Use numeric Jacobian for EdgeSE3Expmap as workaround
RainerKuemmerle Jan 28, 2024
8305772
Relax basic Jacobian Epsilon function
RainerKuemmerle Jan 28, 2024
275b54f
Compile own test_main
RainerKuemmerle Jan 28, 2024
c9eaa02
Update python README
RainerKuemmerle Jan 28, 2024
9669511
Disable one getPureFilename test on Windows
RainerKuemmerle Jan 28, 2024
3039bc9
Disable Jacobian tests on MSVC
RainerKuemmerle Jan 28, 2024
4d32225
Fix typed_basic_tests.h on Windows
RainerKuemmerle Jan 29, 2024
9d78f06
Turn edges into fixed size
RainerKuemmerle Jan 30, 2024
c3c61f9
Avoid void* in pointer arithmetic
RainerKuemmerle Feb 1, 2024
4ecec8b
Removed obsolete Makefile
RainerKuemmerle Feb 3, 2024
9d5bd81
Install g2opy to g2o
RainerKuemmerle Feb 3, 2024
06c57fe
Fix registration of types in g2opy
RainerKuemmerle Feb 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ jobs:
sudo apt update
sudo apt install libeigen3-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5 libsuitesparse-dev lcov libspdlog-dev

- name: Install cereal on Ubuntu
if: runner.os == 'Linux'
run: |
cd /tmp
wget https://github.com/USCiLab/cereal/archive/refs/tags/v1.3.2.tar.gz
tar xaf v1.3.2.tar.gz
cd cereal-1.3.2
mkdir build; cd build
cmake -DJUST_INSTALL_CEREAL:=On ..
sudo make install

- name: Install dependencies on macOS
if: runner.os == 'macOS'
run: brew install cmake eigen
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,17 @@ else()
include_directories(${EIGEN3_INCLUDE_DIR})
endif ()

find_package(cereal)

# Generate config.h
set(G2O_OPENGL_FOUND ${OPENGL_FOUND})
set(G2O_HAVE_CHOLMOD ${CHOLMOD_FOUND})
set(G2O_HAVE_CSPARSE ${G2O_USE_CSPARSE})
if (TARGET cereal::cereal)
set(G2O_HAVE_CEREAL 1)
else()
set(G2O_HAVE_CEREAL 0)
endif()
set(G2O_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(G2O_LGPL_SHARED_LIBS ${BUILD_LGPL_SHARED_LIBS})
set(G2O_CXX_COMPILER "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER}")
Expand Down
22 changes: 0 additions & 22 deletions Makefile

This file was deleted.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ following packages.

- spdlog <https://github.com/gabime/spdlog>
- suitesparse <http://faculty.cse.tamu.edu/davis/suitesparse.html>
- cereal <https://uscilab.github.io/cereal/index.html>
- Qt5 <http://qt-project.org>
- libQGLViewer <http://www.libqglviewer.com>

Expand All @@ -104,6 +105,7 @@ following packages.

- libspdlog-dev
- libsuitesparse-dev
- libcereal-dev
- qtdeclarative5-dev
- qt5-qmake
- libqglviewer-dev-qt5
Expand Down
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#cmakedefine G2O_SHARED_LIBS 1
#cmakedefine G2O_LGPL_SHARED_LIBS 1

#cmakedefine G2O_HAVE_CEREAL 1

// available sparse matrix libraries
#cmakedefine G2O_HAVE_CHOLMOD 1
#cmakedefine G2O_HAVE_CSPARSE 1
Expand Down
73 changes: 73 additions & 0 deletions doc/file-format.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Content to be saved
- Parameters
- Vertex / Dynamic
- Data
- Edge / Dynamic Edge
- Data

The above list gives an overview about the data to be saved.
Each kind of element has a set of data which is agnostic to the concrete instance and we have data specific to the instance.

The agnostic data contains, for example, a single ID or a list of IDs. For a vertex and a parameter we will have an ID followed by the specific payload.

# Types

We have the following trivially copyable types which we need to handle.

- String: A string without spaces
- Int: An integer number
- Float: A floating point

## Paramater
- String, the tag of the parameter
- Int, the unique ID of the parameter
- [Float], the value of the parameter

## Data
- String, the tag of the data
- [String], the data in serialized form

## Vertex / Dynamic Vertex
- String, the tag of the vertex
- Int, the unique ID of the vertex
- [Float], the estimate of the vertex
- [Data], the data associated to the vertex

## Edge / Dynamic Edge
- String, the tag of the vertex
- [Int], the unique IDs of the edge's vertices
- [Int], the unique IDs of the edge's parameters
- [Float], the measurement of the edge
- [Float], the information matrix of the edge
- [Data], the data associated to the edge

A Data element belongs to a vertex or an edge in a parent/child relation.

## Fixed vertices
- [Int], the vertex IDs which are fixed

# A graph

A graph comprises above information. And we will save it in a specific order.

- "Fixed"
- [Int]
- "Parameters"
- [Parameter]
- "Vertices"
- [Vertex]
- "Edges"
- [Edge]

# File formats to support

We want to save the original g2o file format but also support potentially new file formats like JSON or a binary format.

## Challenges

To support the original g2o file format, we need to handle the special case of a dynamic edge. However, we can assume that not many files with dynamically sized edges in the g2o format exist.
To support the original g2o format, we need anyhow to implement a custom reader for the data. Hence, we can handle in there the special format to separate IDs, estimate and information matrix.

As we assume only a very limited number of files have been written with dynamically sized edges, we will break compatibility for reading those. This allows as a smooth path forward.

Currently, g2o can only implicitly differentiate if a edge is dynamic. To this end, an edge with zero vertices upon construction is assumed to be a dynamic edge. The same holds for a vertex.
4 changes: 2 additions & 2 deletions g2o/apps/g2o_simulator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_library(g2o_simulator_library ${G2O_LIB_TYPE}
simulator.cpp simulator.h
pointsensorparameters.cpp pointsensorparameters.h
simulator2d_base.h simulator2d.h
simulator2d_base.h
sensor_odometry2d.cpp sensor_odometry2d.h
sensor_pose2d.cpp sensor_pose2d.h
sensor_pointxy.cpp sensor_pointxy.h
Expand All @@ -12,7 +12,7 @@ add_library(g2o_simulator_library ${G2O_LIB_TYPE}
sensor_segment2d_line.cpp sensor_segment2d_line.h
sensor_segment2d_pointline.cpp sensor_segment2d_pointline.h

simulator3d_base.h simulator3d.h
simulator3d_base.h
sensor_odometry3d.cpp sensor_odometry3d.h
sensor_pose3d.cpp sensor_pose3d.h
sensor_pose3d_offset.cpp sensor_pose3d_offset.h
Expand Down
10 changes: 6 additions & 4 deletions g2o/apps/g2o_simulator/pointsensorparameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ namespace g2o {
class G2O_SIMULATOR_API PointSensorParameters {
public:
PointSensorParameters() = default;
double maxRange() const { return sqrt(maxRange2_); }
[[nodiscard]] double maxRange() const { return sqrt(maxRange2_); }
void setMaxRange(double maxRange);
double minRange() const { return sqrt(minRange2_); }
[[nodiscard]] double minRange() const { return sqrt(minRange2_); }
void setMinRange(double minRange);
double fov() const { return fov_; }
[[nodiscard]] double fov() const { return fov_; }
void setFov(double fov);
double maxAngularDifference() const { return maxAngularDifference_; }
[[nodiscard]] double maxAngularDifference() const {
return maxAngularDifference_;
}
void setMaxAngularDifference(double angularDifference);

protected:
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_odometry2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef G2O_SENSOR_ODOMETRY2D_H_
#define G2O_SENSOR_ODOMETRY2D_H_

#include "g2o/types/slam2d/edge_se2.h"
#include "g2o_simulator_api.h"
#include "simulator2d_base.h"

Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_odometry3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef G2O_SENSOR_ODOMETRY3D_H_
#define G2O_SENSOR_ODOMETRY3D_H_

#include "g2o/types/slam3d/edge_se3.h"
#include "g2o_simulator_api.h"
#include "simulator3d_base.h"

Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_pointxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef G2O_SENSOR_POINTXY_H_
#define G2O_SENSOR_POINTXY_H_

#include "g2o/types/slam2d/edge_se2_pointxy.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator2d_base.h"
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_pointxy_bearing.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef G2O_SENSOR_POINTXY_BEARING_H_
#define G2O_SENSOR_POINTXY_BEARING_H_

#include "g2o/types/slam2d/edge_se2_pointxy_bearing.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator2d_base.h"
Expand Down
4 changes: 1 addition & 3 deletions g2o/apps/g2o_simulator/sensor_pointxy_offset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

#include <cassert>

#include "g2o/core/factory.h"

namespace g2o {

// SensorPointXYOffset
Expand Down Expand Up @@ -82,7 +80,7 @@ void SensorPointXYOffset::sense() {
count++;
}
if (!robotPoseObject_) return;
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->offset();
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->param();
for (auto* it : world()->objects()) {
auto* o = dynamic_cast<WorldObjectType*>(it);
if (o && isVisible(o)) {
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_pointxy_offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef G2O_SENSOR_POINTXY_OFFSET_H_
#define G2O_SENSOR_POINTXY_OFFSET_H_

#include "g2o/types/slam2d/edge_se2_pointxy_offset.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator2d_base.h"
Expand Down
2 changes: 1 addition & 1 deletion g2o/apps/g2o_simulator/sensor_pointxyz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void SensorPointXYZ::sense() {
count++;
}
if (!robotPoseObject_) return;
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->offset();
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->param();
for (auto* it : world()->objects()) {
auto* o = dynamic_cast<WorldObjectType*>(it);
if (o && isVisible(o)) {
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_pointxyz.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#ifndef G2O_SENSOR_POINTXYZ_H_
#define G2O_SENSOR_POINTXYZ_H_
#include "g2o/types/slam3d/edge_se3_pointxyz.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator3d_base.h"
Expand Down
3 changes: 2 additions & 1 deletion g2o/apps/g2o_simulator/sensor_pointxyz_depth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void SensorPointXYZDepth::sense() {
count++;
}
if (!robotPoseObject_) return;
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->offset();
sensorPose_ =
robotPoseObject_->vertex()->estimate() * offsetParam_->param().offset();
for (auto* it : world()->objects()) {
auto* o = dynamic_cast<WorldObjectType*>(it);
if (o && isVisible(o)) {
Expand Down
6 changes: 4 additions & 2 deletions g2o/apps/g2o_simulator/sensor_pointxyz_depth.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#ifndef G2O_SENSOR_POINTXYZ_DEPTH_H_
#define G2O_SENSOR_POINTXYZ_DEPTH_H_
#include "g2o/types/slam3d/edge_se3_pointxyz_depth.h"
#include "g2o/types/slam3d/parameter_camera.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator3d_base.h"
Expand All @@ -40,13 +42,13 @@ class G2O_SIMULATOR_API SensorPointXYZDepth
explicit SensorPointXYZDepth(const std::string& name);
void sense() override;
void addParameters() override;
std::shared_ptr<ParameterSE3Offset> offsetParam() { return offsetParam_; };
std::shared_ptr<ParameterCamera> offsetParam() { return offsetParam_; };
void addNoise(EdgeType* e) override;

protected:
bool isVisible(WorldObjectType* to);
RobotPoseType sensorPose_;
std::shared_ptr<ParameterSE3Offset> offsetParam_;
std::shared_ptr<ParameterCamera> offsetParam_;
};
} // namespace g2o

Expand Down
3 changes: 2 additions & 1 deletion g2o/apps/g2o_simulator/sensor_pointxyz_disparity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ void SensorPointXYZDisparity::sense() {
count++;
}
if (!robotPoseObject_) return;
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->offset();
sensorPose_ =
robotPoseObject_->vertex()->estimate() * offsetParam_->param().offset();
for (auto* it : world()->objects()) {
auto* o = dynamic_cast<WorldObjectType*>(it);
if (o && isVisible(o)) {
Expand Down
6 changes: 4 additions & 2 deletions g2o/apps/g2o_simulator/sensor_pointxyz_disparity.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#ifndef G2O_SENSOR_POINTXYZ_DISPARITY_H_
#define G2O_SENSOR_POINTXYZ_DISPARITY_H_
#include "g2o/types/slam3d/edge_se3_pointxyz_disparity.h"
#include "g2o/types/slam3d/parameter_camera.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator3d_base.h"
Expand All @@ -41,13 +43,13 @@ class G2O_SIMULATOR_API SensorPointXYZDisparity
explicit SensorPointXYZDisparity(const std::string& name);
void sense() override;
void addParameters() override;
std::shared_ptr<ParameterSE3Offset> offsetParam() { return offsetParam_; };
std::shared_ptr<ParameterCamera> offsetParam() { return offsetParam_; };
void addNoise(EdgeType* e) override;

protected:
bool isVisible(WorldObjectType* to);
RobotPoseType sensorPose_;
std::shared_ptr<ParameterSE3Offset> offsetParam_;
std::shared_ptr<ParameterCamera> offsetParam_;
};

} // namespace g2o
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_pose2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#ifndef G2O_SENSOR_POSE2D_H_
#define G2O_SENSOR_POSE2D_H_

#include "g2o/types/slam2d/edge_se2.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator2d_base.h"
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_pose3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#ifndef G2O_SENSOR_POSE3D_H_
#define G2O_SENSOR_POSE3D_H_
#include "g2o/types/slam3d/edge_se3.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator3d_base.h"
Expand Down
4 changes: 3 additions & 1 deletion g2o/apps/g2o_simulator/sensor_pose3d_offset.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#ifndef G2O_SENSOR_POSE3D_OFFSET_H_
#define G2O_SENSOR_POSE3D_OFFSET_H_

#include "g2o/types/slam3d/edge_se3_offset.h"
#include "g2o/types/slam3d/parameter_se3_offset.h"
#include "pointsensorparameters.h"
#include "simulator3d_base.h"

Expand All @@ -38,7 +40,7 @@ class SensorPose3DOffset
public:
explicit SensorPose3DOffset(const std::string& name);
void sense() override;
int stepsToIgnore() const { return stepsToIgnore_; }
[[nodiscard]] int stepsToIgnore() const { return stepsToIgnore_; }
void setStepsToIgnore(int stepsToIgnore) { stepsToIgnore_ = stepsToIgnore; }
void addNoise(EdgeType* e) override;
void addParameters() override;
Expand Down
2 changes: 1 addition & 1 deletion g2o/apps/g2o_simulator/sensor_se3_prior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void SensorSE3Prior::sense() {
count++;
}
if (!robotPoseObject_) return;
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->offset();
sensorPose_ = robotPoseObject_->vertex()->estimate() * offsetParam_->param();
auto e = mkEdge();
if (e && graph()) {
e->setParameterId(0, offsetParam_->id());
Expand Down
1 change: 1 addition & 0 deletions g2o/apps/g2o_simulator/sensor_se3_prior.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#ifndef G2O_SENSOR_SE3_PRIOR_H_
#define G2O_SENSOR_SE3_PRIOR_H_
#include "g2o/types/slam3d/edge_se3_prior.h"
#include "g2o_simulator_api.h"
#include "pointsensorparameters.h"
#include "simulator3d_base.h"
Expand Down
Loading
Loading