Skip to content

Commit

Permalink
progressing on config files, adding some tests for specific cases (tu…
Browse files Browse the repository at this point in the history
…ple returns etc)
  • Loading branch information
SamFlt committed Nov 23, 2023
1 parent f698fe8 commit c58147b
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 1 deletion.
34 changes: 34 additions & 0 deletions modules/python/bindings/include/blob.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef VISP_PYTHON_BLOB_HPP
#define VISP_PYTHON_BLOB_HPP
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/numpy.h>

#include <visp3/blob/vpDot2.h>
#include <optional>

namespace py = pybind11;

void bindings_vpDot2(py::class_<vpDot2, vpTracker> &pyDot2)
{
pyDot2.def_static("defineDots", [](std::vector<vpDot2> &dots,
const std::string &dotFile,
vpImage<unsigned char> &I,
vpColor col = vpColor::blue,
bool trackDot = true) {
return vpDot2::defineDots(&dots[0], dots.size(), dotFile, I, col, trackDot);
}, R"doc(
Wrapper for the defineDots method, see the C++ ViSP documentation.
)doc", py::arg("dots"), py::arg("dotFile"), py::arg("I"), py::arg("color"), py::arg("trackDot") = true);
pyDot2.def_static("trackAndDisplay", [](std::vector<vpDot2> &dots,
vpImage<unsigned char> &I,
std::vector<vpImagePoint> &cogs,
std::optional<std::vector<vpImagePoint>> cogStar) {
vpImagePoint *desireds = cogStar ? &((*cogStar)[0]) : nullptr;
vpDot2::trackAndDisplay(&dots[0], dots.size(), I, cogs, desireds);
}, R"doc(
Wrapper for the trackAndDisplay method, see the C++ ViSP documentation.
)doc", py::arg("dots"), py::arg("I"), py::arg("cogs"), py::arg("desiredCogs"));
}

#endif
74 changes: 73 additions & 1 deletion modules/python/config/core.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@
}
]
},
"vpMath" :{
"methods": [
{
"static": true,
"signature": "double lineFitting(const std::vector<vpImagePoint>&, double&, double&, double&)",
"use_default_param_policy": false,
"param_is_input": [
true,
false,
false,
false
],
"param_is_output": [
false,
true,
true,
true
]
}
]
},
"vpImage": {
"additional_bindings": "bindings_vpImage",
"use_buffer_protocol": true,
Expand Down Expand Up @@ -190,7 +211,42 @@
},
"vpHomogeneousMatrix": {
"additional_bindings": "bindings_vpHomogeneousMatrix",
"use_buffer_protocol": true
"use_buffer_protocol": true,
"methods": [
{
"static": false,
"signature": "void convert(std::vector<double>&)",
"use_default_param_policy": false,
"param_is_input": [
false
],
"param_is_output": [
true
]
},
{
"static": false,
"signature": "void convert(std::vector<float>&)",
"ignore": true
}
]
},
"vpThetaUVector": {
"methods": [
{
"static": false,
"signature": "void extract(double&, vpColVector&)",
"use_default_param_policy": false,
"param_is_input": [
false,
false
],
"param_is_output": [
true,
true
]
}
]
},
"vpPolygon": {
"methods":
Expand All @@ -202,6 +258,22 @@
}
]
},
"vpPoint": {
"methods":
[
{
"static": false,
"ignore": true,
"signature": "void getWorldCoordinates(std::vector<double>&)"
},
{
"static": false,
"ignore": true,
"signature": "void getWorldCoordinates(double&, double&, double&)"
}

]
},
"vpBSpline": {
"methods":
[
Expand Down
43 changes: 43 additions & 0 deletions modules/python/test/test_specific_cases.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from pytest import approx
from visp.core import Math, ImagePoint, ColVector, ThetaUVector, Point
def test_tuple_return_basic_values_only_output():
'''
Test that a function that was with signature
double lineFitting(const std::vector<...>& imPts, double& a, double& b, double& c)
is now (with custom configuration) with a signature lineFitting(imPts) -> tuple[double * 4]
all the reference parameters are used as outputs but not as inputs
'''
a = 45.0
b = 52.0
points = [
ImagePoint(a*i+b, i) for i in range(3)
]
res = Math.lineFitting(points)
print(res)
values = (res[0], -res[1] / res[2], res[3] / res[2])
expected = (0, a, b)
for i, (val, exp) in enumerate(zip(values, expected)):
print(i)
assert val == approx(exp, 0.0001)

def test_tuple_return_basic_values_only_output_2():
theta = 3.14
vec = [0.0, 0.0, 1.0]
thetau = ThetaUVector(*[v * theta for v in vec])
theta_out, vec_out = thetau.extract()
assert theta_out == theta
assert vec_out == ColVector(vec)


def test_pass_by_ref():
values = [0, 1, 2]
p = Point(values)
vec_ref = ColVector()
p.getWorldCoordinates(vec_ref)
assert vec_ref == p.getWorldCoordinates()


def test_tuple_return_basic_values_mixed():
pass

0 comments on commit c58147b

Please sign in to comment.