-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
add7a02
commit 2ef770a
Showing
4 changed files
with
97 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
// openpiv | ||
#include "core/grid.h" | ||
#include "core/rect.h" | ||
#include "core/size.h" | ||
|
||
using namespace openpiv; | ||
using namespace openpiv::core; | ||
|
||
// pybind | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
using namespace pybind11::literals; | ||
|
||
// std | ||
#include <sstream> | ||
|
||
namespace py = pybind11; | ||
|
||
void add_grid(py::module& m) | ||
{ | ||
m.def("generate_cartesian_grid_with_relative_offset", | ||
static_cast<std::vector<rect>(*)(const size&, const core::size&, double)>(&generate_cartesian_grid), | ||
"image_size"_a, | ||
"interrogation_size"_a, | ||
"percentage_offset"_a); | ||
m.def("generate_cartesian_grid_with_fixed_offset", | ||
static_cast<std::vector<rect>(*)(const size&, const core::size&, std::array< uint32_t, 2 >)>(&generate_cartesian_grid), | ||
"image_size"_a, | ||
"interrogation_size"_a, | ||
"offsets"_a); | ||
} |
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,55 @@ | ||
|
||
// openpiv | ||
#include "core/log.h" | ||
|
||
using namespace openpiv; | ||
using namespace openpiv::core; | ||
using namespace openpiv::core::logger; | ||
|
||
// pybind | ||
#include <pybind11/pybind11.h> | ||
#include <pybind11/functional.h> | ||
#include <pybind11/stl.h> | ||
|
||
// std | ||
#include <functional> | ||
#include <sstream> | ||
#include <string> | ||
|
||
namespace py = pybind11; | ||
|
||
Logger::sink_id_t add_sink_(Logger::sink_t sink) | ||
{ | ||
// wrap the passed function in a GIL lock as the sink is called | ||
// from a logging thread in C++ | ||
auto gil_sink = [sink](Level level, const std::string& str) -> bool { | ||
pybind11::gil_scoped_acquire lock{}; | ||
return sink(level, str); | ||
}; | ||
|
||
auto result = Logger::instance().add_sink(gil_sink); | ||
warn("python logging sink added: ensure this is removed before this module is unloaded by calling remove_sink"); | ||
|
||
return result; | ||
} | ||
|
||
void add_log(py::module& m) | ||
{ | ||
py::enum_<Level>(m, "Level") | ||
.value("NONE", Level::NONE) | ||
.value("FATAL", Level::FATAL) | ||
.value("ERROR", Level::ERROR) | ||
.value("WARN", Level::WARN) | ||
.value("INFO", Level::INFO) | ||
.value("DEBUG", Level::DEBUG) | ||
.value("TEST", Level::TEST) | ||
.export_values(); | ||
|
||
m.def("add_sink", &add_sink_); | ||
m.def("remove_sink", | ||
[](Logger::sink_id_t id) -> bool | ||
{ | ||
return Logger::instance().remove_sink(id); | ||
}); | ||
m.def("test_log", [](){ debug("hello, world! {}", 3.141); }); | ||
} |
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