-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add_kimera_spectacular_data_provider
- Loading branch information
Showing
12 changed files
with
361 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
|
||
#include "common/matplotlib.hh" | ||
|
||
#include <cstdlib> | ||
#include <limits> | ||
|
||
#include "pybind11/embed.h" | ||
#include "pybind11/stl.h" | ||
|
||
namespace py = pybind11; | ||
using namespace pybind11::literals; | ||
|
||
namespace robot { | ||
namespace { | ||
wchar_t *to_wchar(const char *str) { | ||
const size_t num_chars = std::mbstowcs(nullptr, str, 0) + 1; | ||
if (num_chars == std::numeric_limits<size_t>::max()) { | ||
return nullptr; | ||
} | ||
wchar_t *out = static_cast<wchar_t *>(malloc(num_chars * sizeof(wchar_t))); | ||
|
||
std::mbstowcs(out, str, num_chars); | ||
|
||
return out; | ||
} | ||
} // namespace | ||
|
||
void plot(const std::vector<PlotSignal> &signals, const bool block) { | ||
PyConfig config; | ||
PyConfig_InitPythonConfig(&config); | ||
config.home = to_wchar(CPP_PYTHON_HOME); | ||
config.pathconfig_warnings = 1; | ||
config.program_name = to_wchar(CPP_PYVENV_LAUNCHER); | ||
config.pythonpath_env = to_wchar(CPP_PYTHON_PATH); | ||
config.user_site_directory = 0; | ||
py::scoped_interpreter guard{&config}; | ||
|
||
py::module_ mpl = py::module_::import("matplotlib"); | ||
mpl.attr("use")("GTK3Agg"); | ||
py::module_ plt = py::module_::import("matplotlib.pyplot"); | ||
|
||
plt.attr("figure")(); | ||
for (const auto &signal : signals) { | ||
plt.attr("plot")(signal.x, signal.y, signal.marker, "label"_a = signal.label); | ||
} | ||
plt.attr("legend")(); | ||
plt.attr("show")("block"_a = block); | ||
} | ||
} // namespace robot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
#pragma once | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace robot { | ||
struct PlotSignal { | ||
std::vector<double> x; | ||
std::vector<double> y; | ||
std::string label = ""; | ||
std::string marker = "-"; | ||
}; | ||
|
||
void plot(const std::vector<PlotSignal> &signals, const bool block = true); | ||
|
||
} // namespace robot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
#include "common/matplotlib.hh" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace robot { | ||
|
||
TEST(MatplotlibTest, simple_plot) { | ||
EXPECT_NO_THROW(plot( | ||
{{.x = std::vector{0.0, 1.0, 2.0}, .y = std::vector{10.0, 20.0, 15.0}, .label = "label"}}, | ||
false)); | ||
} | ||
} // namespace robot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
cc_test( | ||
name = "openstreetmap_test", | ||
srcs = ["openstreetmap_test.cc"], | ||
data = ["@openstreetmap_snippet//:files"], | ||
deps = [ | ||
"@fmt", | ||
"@libosmium", | ||
"@com_google_googletest//:gtest_main", | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
#include <fmt/core.h> | ||
|
||
#include <filesystem> | ||
#include <limits> | ||
|
||
#include "fmt/format.h" | ||
#include "gtest/gtest.h" | ||
#include "osmium/handler.hpp" | ||
#include "osmium/handler/dump.hpp" | ||
#include "osmium/io/pbf_input.hpp" | ||
#include "osmium/visitor.hpp" | ||
|
||
namespace robot::openstreetmap { | ||
TEST(OpenstreetmapTest, can_open_pbf_file) { | ||
// Setup | ||
struct TestHandler : public osmium::handler::Handler { | ||
int node_counter = 0; | ||
int way_counter = 0; | ||
int relation_counter = 0; | ||
|
||
void node(const osmium::Node &node) { node_counter++; } | ||
|
||
void way(const osmium::Way &way) { way_counter++; } | ||
|
||
void relation(const osmium::Relation &relation) { relation_counter++; } | ||
}; | ||
const std::filesystem::path osm_pbf_path( | ||
"external/openstreetmap_snippet/us-virgin-islands-latest.osm.pbf"); | ||
osmium::io::Reader reader(osm_pbf_path, osmium::osm_entity_bits::node | | ||
osmium::osm_entity_bits::way | | ||
osmium::osm_entity_bits::relation); | ||
|
||
// Action | ||
auto handler = TestHandler(); | ||
osmium::apply(reader, handler); | ||
|
||
// Verification | ||
EXPECT_GT(handler.node_counter, 0); | ||
EXPECT_GT(handler.way_counter, 0); | ||
EXPECT_GT(handler.relation_counter, 0); | ||
} | ||
|
||
} // namespace robot::openstreetmap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
def _cc_py_runtime_impl(ctx): | ||
toolchain = ctx.toolchains["@bazel_tools//tools/python:toolchain_type"] | ||
py3_runtime = toolchain.py3_runtime | ||
imports = [] | ||
for dep in ctx.attr.deps: | ||
imports.append(dep[PyInfo].imports) | ||
python_path = "" | ||
for path in depset(transitive = imports).to_list(): | ||
# print("Printing python path: " + str(path)) | ||
python_path += "external/" + path + ":" | ||
|
||
py3_runfiles = ctx.runfiles(files = py3_runtime.files.to_list()) | ||
runfiles = [py3_runfiles] | ||
for dep in ctx.attr.deps: | ||
dep_runfiles = ctx.runfiles(files = dep[PyInfo].transitive_sources.to_list()) | ||
runfiles.append(dep_runfiles) | ||
runfiles.append(dep[DefaultInfo].default_runfiles) | ||
|
||
runfiles = ctx.runfiles().merge_all(runfiles) | ||
|
||
# print("Printing interpreter path: " + str(py3_runtime.interpreter.path)) | ||
# print("Printing interpreter home: " + str(py3_runtime.interpreter.dirname.rstrip("bin"))) | ||
|
||
return [ | ||
DefaultInfo(runfiles = runfiles), | ||
platform_common.TemplateVariableInfo({ | ||
"PYTHON3": str(py3_runtime.interpreter.path), | ||
"PYTHONPATH": python_path, | ||
"PYTHONHOME": str(py3_runtime.interpreter.dirname.rstrip("bin")), | ||
}), | ||
] | ||
|
||
_cc_py_runtime = rule( | ||
implementation = _cc_py_runtime_impl, | ||
attrs = { | ||
"deps": attr.label_list(providers = [PyInfo]), | ||
}, | ||
toolchains = [ | ||
str(Label("@bazel_tools//tools/python:toolchain_type")), | ||
], | ||
) | ||
|
||
def cc_py_test(name, py_deps = [], **kwargs): | ||
py_runtime_target = name + "_py_runtime" | ||
_cc_py_runtime( | ||
name = py_runtime_target, | ||
deps = py_deps, | ||
) | ||
|
||
kwargs.update({ | ||
"data": kwargs.get("data", []) + [":" + py_runtime_target], | ||
"env": {"__PYVENV_LAUNCHER__": "$(PYTHON3)", "PYTHONPATH": "$(PYTHONPATH)", "PYTHONHOME": "$(PYTHONHOME)", "PYTHONNOUSERSITE": "1"}, | ||
"toolchains": kwargs.get("toolchains", []) + [":" + py_runtime_target], | ||
}) | ||
|
||
native.cc_test( | ||
name = name, | ||
**kwargs | ||
) | ||
|
||
def cc_py_binary(name, py_deps = [], **kwargs): | ||
py_runtime_target = name + "_py_runtime" | ||
_cc_py_runtime( | ||
name = py_runtime_target, | ||
deps = py_deps, | ||
) | ||
|
||
kwargs.update({ | ||
"data": kwargs.get("data", []) + [":" + py_runtime_target], | ||
"env": {"__PYVENV_LAUNCHER__": "$(PYTHON3)", "PYTHONPATH": "$(PYTHONPATH)", "PYTHONHOME": "$(PYTHONHOME)", "PYTHONNOUSERSITE": "1"}, | ||
"toolchains": kwargs.get("toolchains", []) + [":" + py_runtime_target], | ||
}) | ||
|
||
native.cc_binary( | ||
name = name, | ||
**kwargs | ||
) | ||
|
||
def cc_py_library(name, py_deps = [], **kwargs): | ||
py_runtime_target = name + "_py_runtime" | ||
_cc_py_runtime( | ||
name = py_runtime_target, | ||
deps = py_deps, | ||
) | ||
|
||
kwargs.update({ | ||
"data": kwargs.get("data", []) + [":" + py_runtime_target], | ||
"defines": [ | ||
"CPP_PYVENV_LAUNCHER=\\\"$(PYTHON3)\\\"", | ||
"CPP_PYTHON_PATH=\\\"$(PYTHONPATH)\\\"", | ||
"CPP_PYTHON_HOME=\\\"$(PYTHONHOME)\\\"", | ||
"PYTHONNOUSERSITE=\\\"1\\\"", | ||
], | ||
"toolchains": kwargs.get("toolchains", []) + [":" + py_runtime_target], | ||
}) | ||
|
||
native.cc_library( | ||
name = name, | ||
**kwargs | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
cc_library( | ||
name = "libosmium", | ||
visibility = ["//visibility:public"], | ||
hdrs = glob(["include/**/*.hpp"], | ||
exclude = [ | ||
"include/io/any_input.hpp", | ||
"include/io/any_output.hpp", | ||
"include/io/xml_input.hpp", | ||
"include/io/xml_output.hpp" | ||
] | ||
), | ||
strip_include_prefix="include", | ||
deps = [ | ||
"@protozero", | ||
"@org_bzip_bzip2//:bz2lib", | ||
"@zlib", | ||
] | ||
) |
Oops, something went wrong.