jfxmap_python.h 2.16 KB
Newer Older
oscar's avatar
oscar committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#ifndef _JFXMAP_PYTHON_H_
#define _JFXMAP_PYTHON_H_

#include <pybind11/pybind11.h>
#include <pybind11/stl_bind.h>
#include <pybind11/stl.h>
#include <string>

namespace py = pybind11;

struct MapInfo
{
    int isInMap;
    long lOutRaodId;
    std::vector<long> vctlOutPreRoadId;
    std::vector<long> vctlOutNxtRoadId;
    int nLaneCnt;
    int nOutLaneNum;
    int nOutLaneType;
    int nOutLeftEdgeCrossType;
    int nOutRightEdgeCrossType;
    int nOutSpeedLimit;
    double dOutLaneAngle;
    double ptOutFoot_lat;
    double ptOutFoot_lon;
};

int add(int i, int j);

bool InitMap(std::string strPrjPath, std::string strCfgPath);

MapInfo* GetMapData(double lat,double lon,double carAngle);

PYBIND11_MODULE(libjfxmap_python, m)
{
    // optional module docstring
    m.doc() = "pybind11 example plugin";

    py::class_<MapInfo>(m, "MapInfo")
        .def_readwrite("isInMap", &MapInfo::isInMap)
        .def_readwrite("lOutRaodId", &MapInfo::lOutRaodId)
        .def_readwrite("vctlOutPreRoadId", &MapInfo::vctlOutPreRoadId)
        .def_readwrite("vctlOutNxtRoadId", &MapInfo::vctlOutNxtRoadId)
        .def_readwrite("nLaneCnt", &MapInfo::nLaneCnt)
        .def_readwrite("nOutLaneNum", &MapInfo::nOutLaneNum)
        .def_readwrite("nOutLaneType", &MapInfo::nOutLaneType)
        .def_readwrite("nOutLeftEdgeCrossType", &MapInfo::nOutLeftEdgeCrossType)
        .def_readwrite("nOutRightEdgeCrossType", &MapInfo::nOutRightEdgeCrossType)
        .def_readwrite("nOutSpeedLimit", &MapInfo::nOutSpeedLimit)
        .def_readwrite("dOutLaneAngle", &MapInfo::dOutLaneAngle)
        .def_readwrite("ptOutFoot_lat", &MapInfo::ptOutFoot_lat)
        .def_readwrite("ptOutFoot_lon", &MapInfo::ptOutFoot_lon);
    // expose add function, and add keyword arguments and default arguments
    m.def("add", &add, "A function which adds two numbers", py::arg("i") = 1, py::arg("j") = 2);
    m.def("InitMap", &InitMap, "A function which init map", py::return_value_policy::copy);
    m.def("GetMapData", &GetMapData, "A function which GetInfo", py::return_value_policy::reference);

    // exporting variables
    m.attr("the_answer") = 42;
    py::object world = py::cast("World");
    m.attr("what") = world;
}

#endif