
#include <stdio.h>
//#include "OdrManager.h"
#include <vector>
#include "MapInterface.hpp"


int main(int argc, char* argv[])
{
    printf("hello world\n");

    std::string dir = "/home/oscar/ros/git/catkin_ws_xishan/src/jfx_traffic_events/";
    std::string cfg = "/thirdparty_map/maps/dqSample12091.xodr";
    jf::MapInterface mapInstance(dir, cfg);

    int nLaneCnt = 0/*所在道路的车道总数*/, nOutLaneNum = 0;//当前所在位置的车道序号，从左至右，从1开始
    jf::LaneType nOutLaneType = jf::LaneType::NotInvestigated;//车道类型，看头文件枚举
    jf::EdgeCrossType nOutLeftEdgeCrossType;//左车道边缘线的跨越属性，具体看头文件枚举
    jf::EdgeCrossType nOutRightEdgeCrossType;//右车道边缘线的跨越属性，具体看头文件枚举
    int nOutSpeedLimit = 0;//车道最高限速值，单位是千米每小时
    double dOutLaneAngle = 0.0;//所在车道，车应该的朝向角度，北为0，顺时针旋转360，0-360

    const jf::Point ptInLoc = { 3926.381879, 11180.870534, 0.0 };
    jf::Point ptOutFoot;//车道中心线做垂线的点
    double dCarAngle = 30.0f;
    long lOutRaodId;
    std::vector<long> vctlOutPreRoadId;
    std::vector<long> vctlOutNxtRoadId;

    //ROS_INFO("begin call jfxmap");
    bool result = mapInstance.GetMapData(ptInLoc, dCarAngle, lOutRaodId, vctlOutPreRoadId, vctlOutNxtRoadId,
        nLaneCnt, nOutLaneNum, nOutLaneType,
        nOutLeftEdgeCrossType, nOutRightEdgeCrossType,
        nOutSpeedLimit, dOutLaneAngle, ptOutFoot);

    //string filename = "/home/oscar/ros/maps/2022307.xodr";
    //string filename = "/home/oscar/ros/maps/dqSample12091.xodr";
    //OpenDrive::OdrManager myManager;
    //bool bRtn = myManager.LoadFile(filename.c_str());
    //printf("return bRtn = %d\n",bRtn);



    // const double longitude = 106.474419689;
    // const double latitude = 29.67213045;
    // std::vector<OdrInfo> odr = myManager.GetOdrInfo(longitude,latitude);
    // printf("odr size = %d\n",odr.size());
    // for(auto iter: odr)
    // {
    //     printf("roadID = %s,sectionID = %s,laneID = %s, _s = %f. _t = %f \n", iter._roadID,iter._sectionID,iter._laneID,iter._s,iter._t);
    // }

    //vector<OdrInfo> odr2 = myManager.GetOdrInfoByXY (3926.381879, 11180.870534);
    //printf("odr2 size = %d\n",odr2.size());
    //for(auto iter: odr2)
    //{
    //    printf("roadID = %s,sectionID = %s,laneID = %s, _s = %f. _t = %f \n", iter._roadID,iter._sectionID,iter._laneID,iter._s,iter._t);

    //    char** sucId = nullptr;
    //    int sucSize = 0;
    //    bool ret0 = myManager.GetSucRoadID(iter._roadID,sucId,sucSize);
    //    if(ret0)
    //    {
    //        printf("GetSucRoadID ret size = %d\n",sucSize);
    //        for(int i = 0; i < sucSize; i++)
    //        {
    //            printf("GetSucRoadID i = %d, roadID = %s\n",i,sucId[i]);
    //        }            
    //    }
    //    else
    //    {
    //        printf("GetSucRoadID ret = false\n");
    //    }
    //    char** preId = nullptr;
    //    int preSize = 0;
    //    bool ret1 = myManager.GetPreRoadID(iter._roadID,preId,preSize);
    //    if(ret1)
    //    {
    //        printf("GetPreRoadID ret size = %d\n",preSize);
    //        for(int i = 0; i < preSize; i++)
    //        {
    //            printf("GetPreRoadID i = %d, roadID = %s\n",i,preId[i]);
    //        }            
    //    }
    //    else
    //    {
    //        printf("GetPreRoadID ret = false\n");
    //    }
    //    char** preLId = nullptr;
    //    int preLSize = 0;
    //    bool ret2 = myManager.GetPreLaneID(iter._roadID,iter._sectionID,iter._laneID,preLId,preLSize);
    //    if(ret2)
    //    {
    //        printf("GetPreLaneID ret size = %d\n",preLSize);
    //        for(int i = 0; i < preLSize; i++)
    //        {
    //            printf("GetPreLaneID i = %d, laneID = %s\n",i,preLId[i]);
    //        }            
    //    }
    //    else
    //    {
    //        printf("GetPreLaneID ret = false\n");
    //    }                

    //    OpenDrive::LaneRelation* vecLaneRelation = nullptr;
    //    int size = 0;
    //    bool ret = myManager.GetPreLaneRelationID(iter._roadID,iter._sectionID,iter._laneID,vecLaneRelation,size);
    //    if(ret)
    //    {
    //        printf("LaneRelation ret size = %d\n",size);
    //        for(int i = 0; i < size; i++)
    //        {
    //            printf("LaneRelation i = %d, roadID = %s,sectionID = %s,laneID = %s\n", i,(vecLaneRelation+i)->_roadID,(vecLaneRelation+i)->_sectionID,(vecLaneRelation+i)->_laneID);
    //        }
    //    }
    //    else
    //    {
    //        printf("GetPreLaneRelationID ret = false\n");
    //    }

    //    char** vecLane = nullptr;
    //    int vecLSize = 0;
    //    bool ret3 = myManager.GetAllDrivingLaneIDS(iter._roadID,iter._sectionID,vecLane,vecLSize);
    //    if(ret3)
    //    {
    //        printf("GetAllDrivingLaneIDS ret size = %d\n",vecLSize);
    //        for(int i = 0; i < vecLSize; i++)
    //        {
    //            printf("GetAllDrivingLaneIDS i = %d, laneID = %s\n",i,vecLane[i]);
    //        }
    //    }
    //    else
    //    {
    //        printf("GetAllDrivingLaneIDS ret = false\n");
    //    }

    //}

    return 0;
}