Commit 068af276 authored by oscar's avatar oscar

提交jfxmap源代码

parent 62ce34fc
Pipeline #875 canceled with stages
cmake_minimum_required(VERSION 2.8.3)
project(jfxmap)
option(TARGET_CORE_LIB "Core lib" ON)
option(TARGET_MAP_PRE_EXE "map pre exe" OFF)
option(TARGET_MAPPER_LIB "mapper lib" OFF)
option(TARGET_MAPPER_EXE "mapper exe" OFF)
set(CMAKE_DEBUG_POSTFIX _d)
if("${BUILD_PLATFORM}" STREQUAL "")
set(BUILD_PLATFORM "BUILD_ON_LINUX" CACHE STRING "Build on target platform")
endif()
message(STATUS "============= ${PROJECT_NAME} : ${BUILD_PLATFORM} ===========")
if("${BUILD_PLATFORM}" STREQUAL "BUILD_ON_LINUX")
set(CMAKE_C_STANDARD 99)
set(CMAKE_CXX_STANDARD 11)
endif()
if(TARGET_CORE_LIB )
file(GLOB SRC_LIST
"offline/Core/*.cpp"
"submodules/xxtea-c/*.c"
)
add_library(core_lib_dynamic SHARED ${SRC_LIST})
set_target_properties(core_lib_dynamic PROPERTIES OUTPUT_NAME "core_lib")
if("${BUILD_PLATFORM}" STREQUAL "BUILD_ON_ANDROID")
target_link_libraries(core_lib_dynamic log)
else()
target_link_libraries(core_lib_dynamic pthread)
endif()
set(local_include_directories
${local_include_directories}
${PROJECT_SOURCE_DIR}/offline/Core
${PROJECT_SOURCE_DIR}/offline/Public
${PROJECT_SOURCE_DIR}/submodules/ajson
${PROJECT_SOURCE_DIR}/submodules/spdlog/include
)
endif()
if(TARGET_MAP_PRE_EXE)
# file(GLOB SRC_LIST
# "offline/MapPre/*.cpp"
# "submodules/tinyxml/src/*.cpp"
# )
# add_executable(map_pre_exe ${SRC_LIST})
# # add_dependencies(map_pre_exe core_lib_dynamic)
# add_definitions(-DSTANDALONE)
# link_directories(${PROJECT_SOURCE_DIR}/build)
# link_directories(${PROJECT_SOURCE_DIR}/submodules/shapelib/build)
# link_directories(/usr/local/lib)
# target_link_libraries(map_pre_exe core_lib_dynamic)
# target_link_libraries(map_pre_exe shp)
# set(local_include_directories
# ${local_include_directories}
# ${PROJECT_SOURCE_DIR}/offline/core
# ${PROJECT_SOURCE_DIR}/offline/mapPre
# ${PROJECT_SOURCE_DIR}/submodules/shapelib
# )
endif()
if(TARGET_UNIT_TEST_EXE)
# file(GLOB SRC_LIST
# "offline/Core/*.cpp"
# "offline/Projects/qichecheng/*.cpp"
# "offline/UnitTest/*.cpp"
# "submodules/xxtea-c/*.c"
# )
# add_executable(unit_test_exe ${SRC_LIST})
# add_definitions(-DSTANDALONE)
# add_dependencies(unit_test_exe core_lib_dynamic)
# link_directories(${PROJECT_SOURCE_DIR}/build/devel/lib)
# message(STATUS "dir = ${PROJECT_SOURCE_DIR}/build/devel/lib")
# link_directories(/usr/local/lib)
# # target_link_libraries(unit_test_exe core_lib_dynamic)
# # target_link_libraries(unit_test_exe ${PROJECT_SOURCE_DIR}/build/devel/lib/libcore_lib_d.so)
# target_link_libraries(unit_test_exe pthread)
# set(local_include_directories
# ${local_include_directories}
# ${PROJECT_SOURCE_DIR}/offline/Core
# ${PROJECT_SOURCE_DIR}/offline/UnitTest
# ${PROJECT_SOURCE_DIR}/offline/UnitTest/fusion_localization/include
# ${PROJECT_SOURCE_DIR}/offline/UnitTest/hd_map/hd_map_common/include
# ${PROJECT_SOURCE_DIR}/offline/UnitTest/utils/common/include
# ${PROJECT_SOURCE_DIR}/offline/Projects
# )
endif()
set(local_include_directories
${local_include_directories}
${PROJECT_SOURCE_DIR}/submodules/ajson
${PROJECT_SOURCE_DIR}/submodules/tinyxml/include
${PROJECT_SOURCE_DIR}/submodules/boolinq/include/boolinq
${PROJECT_SOURCE_DIR}/submodules/jfxthread/include
${PROJECT_SOURCE_DIR}/submodules/queue-thread-safe
${PROJECT_SOURCE_DIR}/submodules/spdlog/include
${PROJECT_SOURCE_DIR}/submodules/xxtea-c
)
include_directories(${local_include_directories})
get_directory_property(hasParent PARENT_DIRECTORY)
if(hasParent)
set(jfxoffline_include_directories ${local_include_directories} PARENT_SCOPE)
endif()
执行方法:
1.编译代码,在catkin_ws下执行catkin_make命令
节点间交互的接口,单独定义成了一个包。另外,所需功能单独打包到libmap.so中,并单独提供调用接口。
编译后,会生成devel/lib/jfxmap/mapper的可知性文件。
偶尔会有如下错误信息:请再执行一次catkin_make
/root/catkin_ws/devel/include/hd_map_msgs/MapDataMsgs.h:19:30: fatal error: hd_map_msgs/Road.h: No such file or directory
2.启动节点,在catkin_ws下执行roslaunch jfxmap mapper.launch
节点执行需要指定地图的位置,所以单独执行mapper会有问题。
如果需要,请按照如下方式启动:
./mapper /root/catkin_ws/src/jfxmap/ ./maps/bosch/mapconfig.json
其中,中间的jfxmap的地址需要按照实际情况修改。
{
"tag": "",
"node_interpolate": 3,
"gps_rect_lat_metres_half": 1,
"gps_rect_lon_metres_half": 1,
"route_rect_lon": 10,
"route_rect_lat": 10,
"qt_max_level": 5,
"algorithm_path_len": 50,
"algorithm_condidate_max": 30,
"algorithm_change_road_punish_div": 4,
"algorithm_change_direction_punish_range_max": 0.5,
"profiler_interval": 5,
"tile_lat_interval": 0.02,
"tile_lon_interval": 0.02,
"map_file_dir": "./resources/HeFei_008_HD_SHP_1117/",
"map_use_type": "hd",
"sd_config": {
"save_dir_json": "./maps/hefei/sd_json/",
"save_dir_binary": "./maps/hefei/sd_binary/"
},
"hd_config": {
"save_dir_json": "./maps/hefei/hd_json/",
"save_dir_binary": "./maps/hefei/hd_binary/"
},
"gps_file_path": "./resources/node1x.csv",
"logDir": "./logs/",
"tile_encrypt": true,
"serialize_type_json1_binary2": 2,
"road_plan_file_dir": "./maps/hefei/",
"road_plan_min_waypoint_dis": 10.0,
"road_plan_max_links": 5000,
"road_plan_max_failes": 100,
"sdid2hdid_path": "./maps/hefei/SdId2HdId"
}
\ No newline at end of file
{
"daemon":false,
"edge_addr": "",
"devNo": "JFQCC0007001",
"mecNo": "JFQCC0007001",
"server_ip": "10.51.49.43",
"server_port": 9000,
"pro_dir":"/home/nvidia/catkin_ws/src/jfxrosperceiver/jfx_events/thirdparty/jfxmap/",
"map_cfg":"./maps/qichecheng/mapconfig.json"
}
{
"tag": "",
"node_interpolate": 3,
"gps_rect_lat_metres_half": 1,
"gps_rect_lon_metres_half": 1,
"route_rect_lon": 1,
"route_rect_lat": 1,
"qt_max_level": 5,
"algorithm_path_len": 50,
"algorithm_condidate_max": 30,
"algorithm_change_road_punish_div": 4,
"algorithm_change_direction_punish_range_max": 0.5,
"profiler_interval": 5,
"tile_lat_interval": 0.02,
"tile_lon_interval": 0.02,
"map_file_dir": "./resources/JiaDing12Connection_HD_SHP_0728/QX_HD_SHP_0728/",
"map_use_type": "hd",
"sd_config": {
"save_dir_json": "./maps/qichecheng/sd_json/",
"save_dir_binary": "./maps/qichecheng/sd_binary/"
},
"hd_config": {
"save_dir_json": "./maps/qichecheng/hd_json/",
"save_dir_binary": "./maps/qichecheng/hd_binary/"
},
"gps_file_path": "./resources/JiaDing12Connection_HD_SHP_0728/node1x.csv",
"logDir": "./logs/",
"tile_encrypt": true,
"serialize_type_json1_binary2": 2,
"road_plan_file_dir": "./maps/qichecheng/",
"road_plan_min_waypoint_dis": 10.0,
"road_plan_max_links": 5000,
"road_plan_max_failes": 100,
"sdid2hdid_path": "./maps/qichecheng/SdId2HdId"
}
\ No newline at end of file
{
"algorithm_change_direction_punish_range_max": 0.5,
"algorithm_change_road_punish_div": 4,
"algorithm_condidate_max": 30,
"algorithm_path_len": 50,
"gps_file_path": "./resources/JiaDing12Connection_HD_SHP_0728/node1x.csv",
"gps_rect_lat_metres_half": 1,
"gps_rect_lon_metres_half": 1,
"hd_config": {
"save_dir_binary": "./maps/qichecheng/hd_binary/",
"save_dir_json": "./maps/qichecheng/hd_json/"
},
"logDir": "./logs/",
"map_file_dir": "./resources/JiaDing12Connection_HD_SHP_0728/QX_HD_SHP_0728/",
"map_use_type": "hd",
"node_interpolate": 3,
"profiler_interval": 5,
"qt_max_level": 5,
"road_plan_file_dir": "./maps/qichecheng/",
"road_plan_max_failes": 100,
"road_plan_max_links": 5000,
"road_plan_min_waypoint_dis": 10.0,
"route_rect_lat": 1,
"route_rect_lon": 1,
"sd_config": {
"save_dir_binary": "./maps/qichecheng/sd_binary/",
"save_dir_json": "./maps/qichecheng/sd_json/"
},
"sdid2hdid_path": "./maps/qichecheng/SdId2HdId",
"serialize_type_json1_binary2": 2,
"tag": "",
"tile_encrypt": true,
"tile_lat_interval": 0.02,
"tile_lon_interval": 0.02
}
{
"tag": "",
"node_interpolate": 3,
"gps_rect_lat_metres_half": 1,
"gps_rect_lon_metres_half": 1,
"": 1,
"route_rect_lat": 1,
"qt_max_level": 5,
"algorithm_path_len": 50,
"algorithm_condidate_max": 30,
"algorithm_change_road_punish_div": 4,
"algorithm_change_direction_punish_range_max": 0.5,
"profiler_interval": 5,
"tile_lat_interval": 0.02,
"tile_lon_interval": 0.02,
"map_file_dir": "./resources/003_WX_HD_SHP_0907/",
"map_use_type": "hd",
"sd_config": {
"save_dir_json": "./maps/xishan/sd_json/",
"save_dir_binary": "./maps/xishan/sd_binary/"
},
"hd_config": {
"save_dir_json": "./maps/xishan/hd_json/",
"save_dir_binary": "./maps/xishan/hd_binary/"
},
"gps_file_path": "./resources/node1x.csv",
"logDir": "./logs/",
"tile_encrypt": true,
"serialize_type_json1_binary2": 2,
"road_plan_file_dir": "./maps/xishan/",
"road_plan_min_waypoint_dis": 10.0,
"road_plan_max_links": 5000,
"road_plan_max_failes": 100,
"sdid2hdid_path": "./maps/xishan/SdId2HdId"
}
\ No newline at end of file
This diff is collapsed.
#ifndef algorithm_h
#define algorithm_h
#include <iostream>
#include <vector>
#include "CoordSys.h"
#include "FileSys.h"
#include "MapConfig.h"
#include "SdTypes.h"
namespace jf {
class BindRoad;
typedef std::shared_ptr<BindRoad> ShPtr_BindRoad;
/**
* @brief 绑路算法
*
*/
class BindRoad {
public:
static ShPtr_BindRoad GetInstance();
BindRoad();
/**
* @brief 算法需要的data
*
*/
struct AlgoNodeData {
/**
* @brief 节点
*
*/
const SdNode* n = nullptr;
/**
* @brief 观察概率
*
*/
double obsProb = 0.0;
/**
* @brief 转移概率
*
*/
double transProb = 0.0;
/**
* @brief 累计概率
*
*/
double accProb = 0.0;
AlgoNodeData() : n(nullptr), obsProb(0), transProb(0), accProb(0) {}
AlgoNodeData(const SdNode* inn) : n(inn), obsProb(1), transProb(1), accProb(1) {}
// algoNodeData(const algoNodeData other) : n(other.n), obsProb(other.obsProb), transProb(other.transProb), accProb(other.accProb) {}
AlgoNodeData(const AlgoNodeData& other) : n(other.n), obsProb(other.obsProb), transProb(other.transProb), accProb(other.accProb) {}
AlgoNodeData& operator=(const AlgoNodeData& other) {
n = other.n;
obsProb = other.obsProb;
transProb = other.transProb;
accProb = other.accProb;
return *this;
}
inline bool operator==(const AlgoNodeData& o) const { return (*n) == (*o.n); }
inline bool operator!=(const AlgoNodeData& o) const { return !((*n) == (*o.n)); }
};
/**
* @brief 临时绑到最近点
*
* @param p gps点位置
* @param w 世界指针
* @return std::pair<nodeId, nodeData>
*/
void BindRoadLnn(const BindRoadInput& in, const SdNode* out);
/**
* @brief 算法
*
* @param p 本次gps点
* @param w 世界指针
* @return std::pair<nodeId, nodeData>
*/
void BindRoadHmm(const BindRoadInput& in, BindRoadOutput& out);
private:
static ShPtr_BindRoad m_spInstance;
int execNum;
/**
* @brief 第一次执行算法
*
*/
bool first;
bool pending;
// std::vector<Point> gpses;
// std::vector<algoNodeData> candidates_;
int condidateNum;
bool CalcTransformProb(std::vector<AlgoNodeData>& punishCandidates, bool first);
bool InitLastBest();
void GetNextNNodes(int n, const SdNode* from, std::set<AlgoNodeData>& ret);
double GetTransProb(const SdNode* n, const BindRoadInput& in);
uint64_t GetRid(const SdNode* nd);
// 地图有个特点,在路口会把很多点捏成一个点,所有很多点的经纬度完全相同,会导致在这些点之前跳跃
// 为了防止这种事情发生,设置这个变量,如果上一个点和当前点的经纬度相同,则用上一次输出
AlgoNodeData last_best;
};
inline bool operator<(const BindRoad::AlgoNodeData& l, const BindRoad::AlgoNodeData& r) { return l.n < r.n; }
// 降低观察概率的权重
inline double CalcObsProb(double in) { return 1 / pow(in, 1.0 / 3); }
} // namespace jf
#endif
\ No newline at end of file
#include "CoordSys.h"
#include <string>
#include <vector>
#include "Gaussian.h"
#include "Wgs84.h"
namespace jf {
double GetValidZoneWidth(const Point &l, const Point &r) { return GetValidZoneWidth_impl(l, r); }
// Point::Point() : dLon(0), dLat(0), dAlt(0) {}
Point::Point(double inlon, double inlat, double inalt) {
dLon = inlon;
dLat = inlat;
dAlt = inalt;
}
Point::Point(const Point &o) {
dLon = o.dLon;
dLat = o.dLat;
dAlt = o.dAlt;
}
Point::Point(const std::vector<double> &d) {
assert(d.size() >= 2);
dLon = d[0];
dLat = d[1];
if (d.size() >= 3) {
dAlt = d[2];
}
}
Point::Point(const std::map<std::string, double> &m) {
assert(Utils::MapValue(m, std::string("lon"), dLon));
assert(Utils::MapValue(m, std::string("lat"), dLat));
Utils::MapValue(m, std::string("height"), dAlt);
}
Point &Point::operator=(const Point &o) {
dLon = o.dLon;
dLat = o.dLat;
dAlt = o.dAlt;
return *this;
}
bool operator<(const Point &l, const Point &r) {
if (l.dLon < r.dLon) return true;
if (l.dLon == r.dLon && l.dLat < r.dLat) return true;
if (l.dLon == r.dLon && l.dLat == r.dLat && l.dAlt < r.dAlt) return true;
return false;
}
bool operator==(const Point &l, const Point &r) {
if ((l.dLon == r.dLon) && (l.dLat == r.dLat) && (l.dAlt == r.dAlt)) return true;
return false;
}
bool operator!=(const Point &l, const Point &r) {
if ((l.dLon != r.dLon) || (l.dLat != r.dLat) || (l.dAlt != r.dAlt)) return true;
return false;
}
bool Rect2D::intersect(const Rect2D &inr) {
// 完全闭区间
bool lonIntersect = (std::max(inr.rt.dLon, rt.dLon) - std::min(inr.lb.dLon, lb.dLon)) <= ((inr.rt.dLon - inr.lb.dLon) + (rt.dLon - lb.dLon));
bool latIntersect = (std::max(inr.rt.dLat, rt.dLat) - std::min(inr.lb.dLat, lb.dLat)) <= ((inr.rt.dLat - inr.lb.dLat) + (rt.dLat - lb.dLat));
return lonIntersect && latIntersect;
}
bool Rect2D::Contains(const Point &p) const {
// 左下闭区间,右上开区间
return p.dLon < rt.dLon && p.dLat < rt.dLat && p.dLon >= lb.dLon && p.dLat >= lb.dLat;
}
Rect2D Rect2D::getLt() const { return Rect2D(Point(lb.dLon, (lb.dLat + rt.dLat) / 2, 0), Point((lb.dLon + rt.dLon) / 2, rt.dLat, 0)); }
Rect2D Rect2D::getLb() const { return Rect2D(lb, Point((lb.dLon + rt.dLon) / 2, (lb.dLat + rt.dLat) / 2, 0)); }
Rect2D Rect2D::getRt() const { return Rect2D(Point(((lb.dLon + rt.dLon) / 2), (lb.dLat + rt.dLat) / 2, 0), rt); }
Rect2D Rect2D::getRb() const { return Rect2D(Point((lb.dLon + rt.dLon) / 2, lb.dLat, 0), Point(rt.dLon, (lb.dLat + rt.dLat) / 2, 0)); }
Rect2D::Rect2D(const Point &inlb, const Point &inrt) : lb(inlb), rt(inrt) {}
Rect2D::Rect2D(const Rect2D &o) : lb(o.lb), rt(o.rt) {}
Rect2D::Rect2D(const Point &p, float lon_interval_half, float lat_interval_half) {
XYZ xyp = P2XYZ(p);
XYZ xylb = XYZ(xyp.x - lon_interval_half, xyp.y - lat_interval_half, 0);
XYZ xyrt = XYZ(xyp.x + lon_interval_half, xyp.y + lat_interval_half, 0);
lb = XYZ2P(xylb);
rt = XYZ2P(xyrt);
}
TileId::TileId(int inlonId, int inlatId) {
nLonId = inlonId;
nLatId = inlatId;
}
bool operator<(const TileId &l, const TileId &r) {
if (l.nLonId < r.nLonId) return true;
if (l.nLonId == r.nLonId && l.nLatId < r.nLatId) return true;
return false;
}
double D2_84(const Point &l, const Point &r) { return pow((l.dLon - r.dLon), 2) + pow((l.dLat - r.dLat), 2); }
double D_84(const Point &l, const Point &r) { return sqrt(D2_84(l, r)); }
double D2XYZ(const XYZ &l, const XYZ &r, bool consider_alt) {
if (consider_alt)
return pow((l.x - r.x), 2) + pow((l.y - r.y), 2) + pow((l.z - r.z), 2);
else
return pow((l.x - r.x), 2) + pow((l.y - r.y), 2);
}
double D2XYZ(const Point &l, const Point &r, bool consider_alt) {
XYZ ll = P2XYZ(l);
XYZ rr = P2XYZ(r);
return D2XYZ(ll, rr, consider_alt);
}
double DXYZ(const XYZ &l, const XYZ &r, bool consider_alt) { return sqrt(D2XYZ(l, r, consider_alt)); }
double DXYZ(const Point &l, const Point &r, bool consider_alt) { return sqrt(D2XYZ(l, r, consider_alt)); }
XYZ P2XYZ(const Point &p) {
XYZ ret = Convert(p);
return ret;
}
Point XYZ2P(const XYZ &in) {
Point ret = Inverse(in);
return ret;
}
XYZ P2XYZ(const Point &p, double zone_width) { return Convert(p, zone_width); }
Point XYZ2P(const XYZ &in, double zone_width) { return Inverse(in, zone_width); }
} // namespace jf
\ No newline at end of file
#ifndef _JFXMAP_COORDSYS_H_
#define _JFXMAP_COORDSYS_H_
#include <cmath>
#include <iostream>
#include <istream>
#include <map>
#include <ostream>
#include <set>
#include <vector>
#include "MapConfig.h"
#include "MapTypes.hpp"
#include "Serialize.h"
#include "Utils.h"
#include "ajson.hpp"
namespace jf {
static const double PI = 3.1415926535897932384626;
double Rad2Degree(double rad);
inline double Dot(const XYZ &from, const XYZ &to) { return from.x * to.x + from.y * to.y; }
inline double Cross(const XYZ &from, const XYZ &to) { return from.x * to.y - from.y * to.x; }
// 右手坐标系
struct Rot {
Rot() : angle(0) {}
Rot(double in_angle) : angle(in_angle) {}
Rot(const XYZ &from, const XYZ &to) : angle(0) {
if (from == to) {
angle = 0;
} else {
XYZ toward = to - from;
XYZ norm_toward = norm(toward);
XYZ x0(0, 1, 0);
double cos = Dot(x0, norm_toward);
angle = acos(cos) * 180 / PI;
if (Cross(x0, norm_toward) < 0) {
angle = -angle;
}
}
}
double angle;
// 右手坐标系逆时针正,顺时针负
Rot operator+(const Rot &o) const {
Rot ret;
ret.angle = angle + o.angle;
return ret;
}
// 新方向 - 旧方向 : 旧方向到新方向要至少旋转多少? 两个旋转方向取angle值小的
Rot operator-(const Rot &o) const {
Rot ret;
Rot new_rot = *this;
Rot old_rot = o;
if (new_rot.angle < 0) {
new_rot.angle = new_rot.angle + 360.0;
}
if (old_rot.angle < 0) {
old_rot.angle = old_rot.angle + 360.0;
}
ret.angle = new_rot.angle - old_rot.angle;
return ret;
}
};
inline Rect2D TId2Rect(const TileId &tid) {
double lonlb = tid.nLonId * MapConfig::tile_lon_interval;
double latlb = tid.nLatId * MapConfig::tile_lat_interval;
double lonrt = (tid.nLonId + 1) * MapConfig::tile_lon_interval;
double latrt = (tid.nLatId + 1) * MapConfig::tile_lat_interval;
return Rect2D(Point(lonlb, latlb, 0), Point(lonrt, latrt, 0));
}
// point到tile左下角点
inline Point P2TLBP(const Point &p) {
double lon = int(p.dLon / MapConfig::tile_lon_interval) * MapConfig::tile_lon_interval;
double lat = int(p.dLat / MapConfig::tile_lat_interval) * MapConfig::tile_lat_interval;
return Point(lon, lat, p.dAlt);
}
inline Point P2TRTP(const Point &p) {
double lon = int(p.dLon / MapConfig::tile_lon_interval) * MapConfig::tile_lon_interval + MapConfig::tile_lon_interval;
double lat = int(p.dLat / MapConfig::tile_lat_interval) * MapConfig::tile_lat_interval + MapConfig::tile_lat_interval;
return Point(lon, lat, p.dAlt);
}
inline Rect2D P2TRect(const Point &p) {
Point tlbp = P2TLBP(p);
Point trtp = P2TRTP(p);
return Rect2D(tlbp, trtp);
}
inline TileId String2TId(const std::string &s) {
std::vector<int> tid;
jf::Utils::SplitToArray(s, ',', tid);
if (tid.size() >= 2)
return TileId(tid[0], tid[1]);
else
return TileId(0, 0);
}
inline TileId P2TId(const Point &p, float tile_lon_interval, float tile_lat_interval) {
int lonId = Utils::DoubleToInt(p.dLon / tile_lon_interval);
int latId = Utils::DoubleToInt(p.dLat / tile_lat_interval);
return TileId(lonId, latId);
}
inline std::set<TileId> R2TIds(const Rect2D &r) {
Point fromlb = P2TLBP(r.lb);
Point tort = P2TRTP(r.rt);
std::vector<double> lons;
std::vector<double> lats;
std::set<TileId> ret;
for (double lon = fromlb.dLon; lon < tort.dLon; lon += MapConfig::tile_lon_interval) {
lons.push_back(lon);
}
for (double lat = fromlb.dLat; lat < tort.dLat; lat += MapConfig::tile_lat_interval) {
lats.push_back(lat);
}
for (auto lon : lons)
for (auto lat : lats) ret.insert(P2TId(Point(lon, lat, 0)));
return ret;
}
Point TId2PointLB(const TileId &tid);
void GaussProjCal(double longitude, double latitude, double &X, double &Y);
void GaussProjInvCal(double X, double Y, double &longitude, double &latitude);
inline std::vector<Point> InterP(const Point &p1, const Point &p2, float interval) {
XYZ xyz1 = P2XYZ(p1);
XYZ xyz2 = P2XYZ(p2);
XYZ dir = xyz2 - xyz1;
float len = dir.length();
XYZ unit = dir / len;
std::vector<Point> ret;
ret.push_back(p1);
for (float l = interval; l < len; l += interval) {
XYZ now = xyz1 + unit * l;
ret.push_back(XYZ2P(now));
}
ret.push_back(p2);
return ret;
}
/**
* @brief 笛卡尔坐标系下距离平方
*
* @param l
* @param r
* @return double
*/
double D2XYZ(const XYZ &l, const XYZ &r, bool consider_alt = false);
double D2XYZ(const Point &l, const Point &r, bool consider_alt = false);
/**
* @brief 笛卡尔坐标系下距离
*
* @param l
* @param r
* @return double
*/
double DXYZ(const XYZ &l, const XYZ &r, bool consider_alt = false);
double DXYZ(const Point &l, const Point &r, bool consider_alt = false);
/**
* @brief 84坐标系距离平方
*
* @param l 点a
* @param r 点b
* @return double
*/
double D2_84(const Point &l, const Point &r);
/**
* @brief 84坐标系距离
*
* @param l 点a
* @param r 点b
* @return double
*/
double D_84(const Point &l, const Point &r);
inline bool test_near(const Point &p1, const Point &p2) {
if (std::abs(p1.dLon - p2.dLon) < 0.001 && std::abs(p1.dLat - p2.dLat) < 0.001) {
return true;
}
return false;
}
} // namespace jf
#ifndef jfxmap_serialize_override_tileId
jfxmap_serialize(jf::TileId, nLonId, nLatId);
#endif
#ifndef jfxmap_serialize_override_point
jfxmap_serialize(jf::Point, dLon, dLat, dAlt);
#endif
#ifndef jfxmap_serialize_override_rot
jfxmap_serialize(jf::Rot, angle);
#endif
#ifndef jfxmap_serialize_override_rect2d
jfxmap_serialize(jf::Rect2D, lb, rt);
#endif
#endif
\ No newline at end of file
#include "FileSys.h"
#include "Log.h"
#include "MapConfig.h"
#include "Utils.h"
extern "C" {
#include "xxtea.h"
}
#include <dirent.h> //windows开发工具没有这个头文件
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <cstdlib>
#include <iostream>
#include <ostream>
#include <string>
#include <vector>
#include <memory>
using namespace std;
using namespace jf;
std::string FileSys::key = "jfx2020!";
std::vector<string> FileSys::GetAllFiles(const string& indir) {
std::vector<string> ret;
DIR* dir;
struct dirent* ptr;
int i = 0;
dir = opendir(indir.c_str());
if (!dir) {
// jf_log_error("cannot find dir {}", indir.c_str());
return {};
}
while ((ptr = readdir(dir)) != NULL) {
printf("d_name : %s\n", ptr->d_name);
ret.push_back(ptr->d_name);
}
// delete ptr;
return ret;
}
bool FileSys::Read(const std::string& f, std::string& is, bool encrypt) {
// jf_log_info("[FileSys::Read] load file {0}", f);
if (!Exist(f)) {
// jf_log_error("[FileSys::Read] file {0} cannot found", f);
return false;
}
std::ifstream in(f.c_str(), ios::binary);
string str((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
if (encrypt) {
size_t outlen;
void* outdata = xxtea_decrypt(str.data(), str.length(), key.data(), &outlen);
std::stringstream ss;
ss.write((char*)outdata, outlen);
is = ss.str();
free(outdata);
} else {
is = str;
}
return in.good();
}
void FileSys::AppendSlow(const std::string& f, const std::string& content) {
#ifndef ANDROID
std::string p = MapConfig::GetProjectDir() + f;
// jf_log_info("[FileSys::Save] Save file {}", p);
std::ofstream of;
of.open(f.c_str(), iostream::app);
of << content;
of.close();
#endif
}
void FileSys::Save(const std::string& f, const std::string& content, bool encrypt) {
// jf_log_info("[FileSys::Save] Save file {}", f);
std::ofstream of;
of.open(f.c_str(), ios::binary);
if (encrypt) {
size_t outlen;
void* outdata = xxtea_encrypt(content.data(), content.length(), key.data(), &outlen);
std::stringstream outss;
outss.write((char*)outdata, outlen);
of << outss.rdbuf();
free(outdata);
} else {
of << content;
}
of.close();
return;
}
void FileSys::CleanDir(const std::string& dir) {
DIR* theFolder = opendir(dir.c_str());
if (!theFolder) {
return;
}
struct dirent* next_file;
char filepath[1024];
while ((next_file = readdir(theFolder)) != NULL) {
sprintf(filepath, "%s/%s", dir.c_str(), next_file->d_name);
remove(filepath);
}
closedir(theFolder);
}
void FileSys::MkDir(const std::string& dir) {
std::string command = std::string("mkdir ") + dir;
const int dir_err = system(command.c_str());
}
void FileSys::Remove(const std::string& path) {
std::string command = std::string("rm -rf ") + path;
const int dir_err = system(command.c_str());
if (-1 == dir_err) {
printf("Error creating directory!n");
}
}
bool FileSys::FileNameEndWith(const std::string& fileName, const std::string& ext) { return jf::Utils::EndsWith(fileName, ext); }
std::string FileSys::ChoosePath(const std::vector<std::string>& dirs, const std::string& subPath) {
for (auto& dir : dirs) {
std::string fullPath = dir + subPath;
if (Exist(fullPath)) {
return fullPath;
}
}
// jf_log_error("assert false : cannot find file in any dirs: {}", subPath);
return "";
}
bool FileSys::Exist(const std::string& fullPath) {
struct stat buffer;
return (stat(fullPath.c_str(), &buffer) == 0);
}
\ No newline at end of file
#ifndef _JFXMAP_FILESYS_H_
#define _JFXMAP_FILESYS_H_
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
// #include "log.h"
namespace jf {
class FileSys {
public:
template <typename LineFuncType>
static void ReadByLine(const std::string& f, LineFuncType lf) {
// jf_log_info("[FileSys::Read] load file {}", f);
std::ifstream fin(f.c_str());
std::string l;
int lineNum = 0;
while (std::getline(fin, l)) {
std::istringstream iss(l);
lf(iss, ++lineNum);
}
}
static bool Exist(const std::string& fullPath);
static bool Read(const std::string& f, std::string& is, bool encrypt = false);
static std::vector<std::string> GetAllFiles(const std::string& dir);
static void Save(const std::string& f, const std::string& content, bool encrypt = false);
static void AppendSlow(const std::string& f, const std::string& content);
static void CleanDir(const std::string& dir);
static void MkDir(const std::string& dir);
static void Remove(const std::string& path);
static bool FileNameEndWith(const std::string& fileName, const std::string& ext);
static std::string ChoosePath(const std::vector<std::string>& dirs, const std::string& subPath);
static std::string key;
};
} // namespace jf
#endif //_JFXMAP_FILESYS_H_
\ No newline at end of file
#include "Gaussian.h"
#include "CoordSys.h"
#include "Wgs84.h"
namespace jf {
const double ZoneOffset = 1e6;
// const int ZoneWidth = 2.7;
const double EastOffset = 500000.0;
#define use_gaussian_convert_deprecated
#define pi 3.1415926535897
double GetValidZoneWidth_impl(const Point& left, const Point& right) {
for (double d = 2; d < 4; d += 0.1) {
if (int((left.dLon + 1.5) / d) == int((right.dLon + 1.5) / d)) {
return d;
}
}
assert(false);
return 0.0;
}
XYZ gaussian_convert_deprecated(const Point& inp, double ZoneWidth) {
int Zone = int((inp.dLon + 1.5) / ZoneWidth);
double L0 = Zone * ZoneWidth;
double dL = inp.dLon - L0 * 1.0;
double dLRadian = Degree2Rad(dL);
double latRadian = Degree2Rad(inp.dLat);
double X = GetX(latRadian);
double N = GetN(latRadian);
double t = tan(latRadian);
double t2 = t * t;
double sinB = sin(latRadian);
double cosB = cos(latRadian);
double ita2 = ep2 * cosB * cosB;
double temp = dLRadian * cosB;
double temp2 = temp * temp;
double yPart1 = 0.5 * N * temp * temp * t;
double yPart2 = N * t * (5.0 - t2 + 9.0 * ita2 + 4.0 * ita2 * ita2) * temp2 * temp2 / 24.0;
double yPart3 = temp2 * temp2 * temp2 * N * t * (61.0 - 58.0 * t2 + t2 * t2) / 720.0;
double y = X + yPart1 + yPart2 + yPart3;
double xPart1 = N * temp;
double xPart2 = (1.0 - t2 + ita2) * N * temp * temp2 / 6.0;
double xPart3 = (5.0 - 18.0 * t2 + t2 * t2 + 14.0 * ita2 - 58.0 * ita2 * t2) * N * temp * temp2 * temp2 / 120.0;
double x = Zone * 1.0 * ZoneOffset * 1.0 + EastOffset + xPart1 + xPart2 + xPart3;
// double h = inLonLat[2];
return XYZ{x, y, inp.dAlt};
}
XYZ Convert(const Point& inp, double ZoneWidth) {
#ifdef use_gaussian_convert_deprecated
return gaussian_convert_deprecated(inp, ZoneWidth);
#else
return cartesian_convert(inp);
#endif
}
Point gaussian_inverse_deprecated(const XYZ& inxyz, double ZoneWidth) {
int Zone = int(inxyz.x / ZoneOffset);
double L0 = Zone * ZoneWidth;
double L0_radian = Degree2Rad(L0);
double X0 = Zone * ZoneOffset + EastOffset;
double Y0 = 0;
double x = inxyz.x - X0;
double y = inxyz.y - Y0;
double Br = GetLatByX(y);
double cosB = cos(Br);
double secB = 1.0 / cosB;
double ita2 = ep2 * cosB * cosB;
double t = tan(Br);
double t2 = t * t;
double V = GetV(Br);
double V2 = V * V;
double N = c / V;
double M = N / V / V;
double D = x / N;
double tmp3 = (1.0 + 2.0 * t2 + ita2) * D * D * D / 6.0;
double tmp5 = (5.0 + 28.0 * t2 + 24.0 * t2 * t2 + 6.0 * ita2 + 8.0 * ita2 * t2) * D * D * D * D * D / 120.0;
double l = secB * (D - tmp3 + tmp5);
double L_radian = L0_radian + l;
double tmp2 = D * D / 2.0;
double tmp4 = (5.0 + 3.0 * t2 + ita2 - 9.0 * ita2 * t2) * D * D * D * D / 24.0;
double tmp6 = (61.0 + 90.0 * t2 + 45.0 * t2 * t2) * D * D * D * D * D * D / 720.0;
double B_radian = Br - t * V2 * (tmp2 - tmp4 + tmp6);
double B = Rad2Degree(B_radian);
double L = Rad2Degree(L_radian);
return Point{L, B, inxyz.z};
}
Point Inverse(const XYZ& inxyz, double ZoneWidth) {
#ifdef use_gaussian_convert_deprecated
return gaussian_inverse_deprecated(inxyz, ZoneWidth);
#else
return cartesian_inverse(inxyz);
#endif
}
} // namespace jf
#ifndef _JFXMAP_GAUSSIAN_H_
#define _JFXMAP_GAUSSIAN_H_
#include "CoordSys.h"
#include "Wgs84.h"
static const double ZoneWidth = 3.0;
namespace jf {
double GetValidZoneWidth_impl(const Point& left, const Point& right);
XYZ Convert(const Point& inLonLat, double inZoneWidth = ZoneWidth);
Point Inverse(const XYZ& inxyz, double inZoneWidth = ZoneWidth);
} // namespace jf
#endif // jf
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#ifndef SRC_HDLIBMATH_H
#define SRC_HDLIBMATH_H
#include "MapTypes.hpp"
namespace jf{
class HdLibMath {
public:
static bool IsInRecArea(const Point &cptPoint, const std::vector<std::vector<double>> &cvctvdLeftEdgeGeo, const std::vector<std::vector<double>> &cvctvdRightEdgeGeo, bool isReverseFlag);
static bool GetPerpendicularFoot(const Point &ptPoint, const std::vector<std::vector<double>> &vctvdGeoLink, Point &ptOutPoint, double &dOutDistance, int &nOutNxtIndex);
static bool GetPerpendicularFoot(const Point &ptPoint, const std::vector<std::vector<double>> &vctvdGeoLink,Point &ptOutPoint, double &dOutDistance);
static bool GetNearestPointFromArray(const Point &ptPoint, const std::vector<std::vector<double>> &vctvdGeoLink, Point &ptOutPoint, double &dOutDistance, int &nOutIndex);
private:
static bool IsInTriangle(const Point &cptPoint, const Point &cptA, const Point &cptB, const Point &cptC);
static bool IsInTriangle(const XYZ &cxyz1, const XYZ &cxyz2, const XYZ &cxyz3, const XYZ &cxyz0);
};
}
#endif //SRC_HDLIBMATH_H
This diff is collapsed.
// #include "log.h"
// #include "FileSys.h"
// #if ANDROID
// #include "spdlog/sinks/android_sink.h"
// #else
// #include <chrono>
// // #include "spdlog/async_logger.h"
// // #include "spdlog/sinks/base_sink.h"
// // #include "spdlog/sinks/file_sinks.h"
// // #include "spdlog/sinks/stdout_sinks.h"
// #endif
// #include "MapConfig.h"
// using namespace jf;
// bool logger::inited = false;
// void logger::init() {
// // auto exist = spdlog::get("file_log") || spdlog::get("file_error") || spdlog::get("log");
// // if (exist) return;
// // FileSys::Remove(MapConfig::logDir + "log.txt");
// // FileSys::Remove(MapConfig::logDir + "Profiler.txt");
// // FileSys::Remove(MapConfig::logDir + "error.txt");
// // FileSys::MkDir(MapConfig::logDir);
// #if ANDROID
// std::string tag = "spdlog-android";
// spdlog::android_logger_mt("android", tag);
// #else
// // spdlog::basic_logger_mt("file_log", MapConfig::logDir + "log.txt");
// // spdlog::basic_logger_mt("file_profiler", MapConfig::logDir + "Profiler.txt");
// // spdlog::basic_logger_mt("file_error", MapConfig::logDir + "error.txt");
// // spdlog::stdout_logger_mt("console_log");
// // spdlog::flush_every(std::chrono::seconds(1));
// #endif
// inited = true;
// }
\ No newline at end of file
#ifndef jfxoffline_log_h
#define jfxoffline_log_h
// #include "spdlog/spdlog.h"
#include <memory>
#include <string>
#define jf_log_init(...) jf::logger::init(__VA_ARGS__)
#define jf_log_info(...) jf::logger::log_info(__VA_ARGS__)
#define jf_log_profiler(...) jf::logger::log_profiler(__VA_ARGS__)
#define jf_log_error(...) jf::logger::log_error(__VA_ARGS__)
#define jf_log_flush(...) jf::logger::flush()
// #define jf_log_init(...)
// #define jf_log_info(...)
// #define jf_log_profiler(...)
// #define jf_log_error(...)
// #define jf_log_flush(...)
namespace jf {
class logger {
public:
template <typename... Args>
static void log_info(Args &&... args) {
if (!inited) init();
#if ANDROID
spdlog::get("android")->info(std::forward<Args>(args)...);
#else
// spdlog::get("file_log")->info(std::forward<Args>(args)...);
// spdlog::get("console_log")->info(std::forward<Args>(args)...);
#endif
}
template <typename... Args>
static void log_profiler(Args &&... args) {
if (!inited) init();
#if ANDROID
spdlog::get("android")->info(std::forward<Args>(args)...);
#else
// spdlog::get("file_profiler")->info(std::forward<Args>(args)...);
// spdlog::get("console_log")->info(std::forward<Args>(args)...);
#endif
}
template <typename... Args>
static void log_error(Args &&... args) {
if (!inited) init();
#if ANDROID
spdlog::get("android")->error(std::forward<Args>(args)...);
#else
// spdlog::get("file_log")->error(std::forward<Args>(args)...);
// spdlog::get("file_error")->error(std::forward<Args>(args)...);
// spdlog::get("console_log")->error(std::forward<Args>(args)...);
#endif
}
static void flush() {
if (!inited) init();
#if ANDROID
spdlog::get("android")->flush();
#else
// spdlog::get("file_log")->flush();
// spdlog::get("file_error")->flush();
// spdlog::get("file_profiler")->flush();
// spdlog::get("console_log")->flush();
#endif
}
private:
static void init();
static bool inited;
};
} // namespace jf
#endif
\ No newline at end of file
#include "MapConfig.h"
#include <assert.h>
#include <fstream>
#include "FileSys.h"
#include "ajson.hpp"
using namespace jf;
std::string MapConfig::map_file_dir;
std::string MapConfig::map_use_type;
std::string MapConfig::tag;
double MapConfig::tile_lon_interval;
double MapConfig::tile_lat_interval;
double MapConfig::node_interpolate;
double MapConfig::gps_rect_lon_metres_half;
double MapConfig::gps_rect_lat_metres_half;
double MapConfig::route_rect_lon;
double MapConfig::route_rect_lat;
int MapConfig::qt_max_level;
int MapConfig::algorithm_path_len;
int MapConfig::algorithm_condidate_max;
float MapConfig::algorithm_change_road_punish_div;
double MapConfig::algorithm_change_direction_punish_range_max;
std::string MapConfig::gps_file_path;
int MapConfig::profiler_interval;
std::string MapConfig::logDir;
int MapConfig::serialize_type_json1_binary2 = 1;
bool MapConfig::tile_encrypt;
MapConfig::sdConfig MapConfig::sd_config;
MapConfig::hdConfig MapConfig::hd_config;
std::string MapConfig::sdConfig::save_dir_json;
std::string MapConfig::sdConfig::save_dir_binary;
std::string MapConfig::hdConfig::save_dir_json;
std::string MapConfig::hdConfig::save_dir_binary;
std::string MapConfig::road_plan_file_dir;
// double MapConfig::road_plan_min_waypoint_dis;
// int MapConfig::road_plan_max_links;
// int MapConfig::road_plan_max_failes;
std::string MapConfig::projectDir;
std::string MapConfig::sdid2hdid_path;
std::string MapConfig::map_road_filer_logic;
AJSON(MapConfig::sdConfig, save_dir_json, save_dir_binary);
AJSON(MapConfig::hdConfig, save_dir_json, save_dir_binary);
AJSON(MapConfig, map_file_dir, map_use_type, tag, tile_lon_interval, tile_lat_interval, node_interpolate, gps_rect_lon_metres_half, gps_rect_lat_metres_half, route_rect_lon, route_rect_lat, qt_max_level, algorithm_path_len, algorithm_condidate_max,
algorithm_change_road_punish_div, algorithm_change_direction_punish_range_max, sd_config, hd_config, gps_file_path, profiler_interval, logDir, serialize_type_json1_binary2, tile_encrypt, road_plan_file_dir, /*road_plan_min_waypoint_dis,
road_plan_max_links, road_plan_max_failes,*/
sdid2hdid_path, map_road_filer_logic);
void MapConfig::Init(const std::string &inProjectDir, const std::string &configJsonPath) {
std::ifstream in = {};
in.open((inProjectDir + configJsonPath).c_str());
std::string s((std::istreambuf_iterator<char>(in)), std::istreambuf_iterator<char>());
assert(in.good());
MapConfig c;
std::cout << s;
ajson::load_from_buff(c, s.c_str());
map_file_dir = inProjectDir + c.map_file_dir;
sdConfig::save_dir_json = inProjectDir + c.sd_config.save_dir_json;
sdConfig::save_dir_binary = inProjectDir + c.sd_config.save_dir_binary;
hdConfig::save_dir_json = inProjectDir + c.hd_config.save_dir_json;
hdConfig::save_dir_binary = inProjectDir + c.hd_config.save_dir_binary;
gps_file_path = inProjectDir + c.gps_file_path;
// road_plan_file_dir = inProjectDir + c.road_plan_file_dir;
sdid2hdid_path = inProjectDir + c.sdid2hdid_path;
projectDir = inProjectDir;
tag = "MapConfig";
// jf_log_info("--------");
// jf_log_info("{}", MapConfig::sdConfig::save_dir_json);
// jf_log_info("{}", MapConfig::sdConfig::save_dir_binary);
// jf_log_info("{}", MapConfig::hdConfig::save_dir_json);
// jf_log_info("{}", MapConfig::hdConfig::save_dir_binary);
// jf_log_info("--------");
return;
}
\ No newline at end of file
#ifndef mapConfig_h
#define mapConfig_h
#include <string>
// #include "log.h"
namespace jf {
struct MapConfig {
/**
* @brief map文件路径
*
*/
static std::string map_file_dir;
/**
* @brief map应用类型
*
*/
static std::string map_use_type;
/**
* @brief tag
*
*/
static std::string tag;
/**
* @brief 区块lat跨度
*
*/
static double tile_lat_interval;
/**
* @brief 区块lon跨度
*
*/
static double tile_lon_interval;
/**
* @brief 地图点间插值距离
*
*/
static double node_interpolate;
/**
* @brief 算法取附近rect区域时lon方向半轴长
*
*/
static double gps_rect_lon_metres_half;
/**
* @brief 算法取附近rect区域时lat方向半轴长
*
*/
static double gps_rect_lat_metres_half;
/**
* @brief 算法取附近rect区域时lon方向半轴长(寻路用)
*
*/
static double route_rect_lon;
/**
* @brief 算法取附近rect区域时lat方向半轴长(寻路用)
*
*/
static double route_rect_lat;
/**
* @brief 四叉树最大深度
*
*/
static int qt_max_level;
/**
* @brief 算法从一点开始往下缕几个node
*
*/
static int algorithm_path_len;
/**
* @brief 候选节点数量
*
*/
static int algorithm_condidate_max;
/**
* @brief 换路惩罚除数
*
*/
static float algorithm_change_road_punish_div;
/**
* @brief 掉头惩罚系数
*
*/
static double algorithm_change_direction_punish_range_max;
/**
* @brief 过滤road逻辑表达式
*
*/
static std::string map_road_filer_logic;
/**
* @brief gps文件路径
*
*/
static std::string gps_file_path;
/**
* @brief 序列化格式
*
*/
static int serialize_type_json1_binary2;
/**
* @brief tile是否加密
*
*/
static bool tile_encrypt;
/**
* @brief profiler时间间隔
*
*/
static int profiler_interval;
/**
* @brief log目录
*
*/
static std::string logDir;
/**
* @brief 寻路结果保存地址
*
*/
static std::string road_plan_file_dir;
/**
* @brief 途径点之间的最小距离(超过该值,途径点会被抛弃)
*
*/
// static double road_plan_min_waypoint_dis;
/**
* @brief 寻路结果所包含的最大link数(超过该值,寻路会失败)
*
*/
// static int road_plan_max_links;
/**
* @brief 寻路失败最大次数(超过该值,将会退到上一段途径点之间的寻路结果)
*
*/
// static int road_plan_max_failes;
/**
* @brief 切地图选项
*
*/
struct map_pre_option_st {
// road表只保存rank在min max范围内的
static int road_rank_min;
static int road_rank_max;
};
static map_pre_option_st map_pre_option;
struct hdConfig {
static std::string save_dir_json;
static std::string save_dir_binary;
};
static hdConfig hd_config;
struct sdConfig {
static std::string save_dir_json;
static std::string save_dir_binary;
};
static sdConfig sd_config;
static void Init(const std::string &projectDir, const std::string &configJsonPath);
static std::string GetProjectDir() { return projectDir; }
static std::string sdid2hdid_path;
private:
static std::string projectDir;
};
} // namespace jf
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#include "MapTypes.hpp"
const double EARTH_RADIUS = 6378137.0;
const double PI = 3.1415926535897932384626;
namespace jf {
double PointsDis(const Point &p1, const Point &p2, bool consider_alt) { return PointsDis(p1.dLon, p1.dLat, p2.dLon, p2.dLat); }
double PointsDis(double lng1, double lat1, double lng2, double lat2) {
double radLat1 = Degree2Rad(lat1);
double radLng1 = Degree2Rad(lng1);
double radLat2 = Degree2Rad(lat2);
double radLng2 = Degree2Rad(lng2);
double a = radLat2 - radLat1;
double b = radLng2 - radLng1;
double result = 2 * asin(sqrt(pow(sin(a / 2), 2) + cos(radLat1) * cos(radLat2) * pow(sin(b / 2), 2))) * EARTH_RADIUS;
return result;
}
void PointDis2NewPoint(const Point &ptInPoint, double dLonDis, double dLatDis, Point &ptOutPoint) {
double dLonAngle = (dLonDis * 180) / (PI * EARTH_RADIUS);
double dLatAngle = (dLatDis * 180) / (PI * EARTH_RADIUS);
ptOutPoint = Point(ptInPoint.dLon + dLonAngle, ptInPoint.dLat + dLatAngle, ptInPoint.dAlt);
return;
}
double Degree2Rad(double angle) { return angle * PI / 180.0; }
double Rad2Degree(double rad) { return rad * 180.0 / PI; }
/**
* 计算有向线段s->e
* @param s
* @param e
* @return
*/
double PointsAngle(const Point &s, const Point &e) {
XYZ xyzS = P2XYZ(s);
XYZ xyzE = P2XYZ(e);
double dAngle = atan2((xyzE.x - xyzS.x), (xyzE.y - xyzS.y));
dAngle = dAngle * (180 / PI);
if (dAngle < 0) {
dAngle = dAngle + 360;
}
return dAngle;
// return abs(atan(xyzS.y / xyzS.x) - atan(xyzE.y / xyzE.x));
// double dAngle = 0.0;
// double dXX = xyzE.x - xyzS.x;
// double dYY = xyzE.y - xyzS.y;
// if (dXX == 0.0)
// dAngle = PI / 2.0;
// else
// dAngle = atan(fabs(dYY / dXX));
// if ((dXX < 0.0) && (dYY >= 0.0))
// dAngle = PI - dAngle;
// else if ((dXX < 0.0) && (dYY < 0.0))
// dAngle = PI + dAngle;
// else if ((dXX >= 0.0) && (dYY < 0.0))
// dAngle = PI * 2.0 - dAngle;
// return dAngle;
}
double AngleSub(double dAngle1, double dAngle2) {
if (std::abs(dAngle1 - dAngle2) > 360.0 - std::abs(dAngle1 - dAngle2)) {
return 360.0 - std::abs(dAngle1 - dAngle2);
} else {
return std::abs(dAngle1 - dAngle2);
}
}
} // namespace jf
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#include "Profiler.h"
using namespace jf;
std::map<std::string, Profiler::Record> Profiler::records;
double Profiler::accTime = 0.0;
double Profiler::lastStatTime = 0;
bool Profiler::inited = false;
int Profiler::interval = 1;
\ No newline at end of file
This diff is collapsed.
#include "Save.h"
\ No newline at end of file
This diff is collapsed.
#ifndef _JFXMAP_SDID2HDID_H_
#define _JFXMAP_SDID2HDID_H_
#include <map>
#include "HdTypes.h"
#include "MapConfig.h"
#include "SdTypes.h"
#include "Serialize.h"
#include "Singleton.h"
#include "Utils.h"
#include "World.h"
namespace jf {
struct sdid2hdid_serialize_data {
std::vector<RoadId> rids;
std::vector<HdLinkId> hdlkids;
};
class SdId2HdId {
public:
static void Deserialize() {
sdid2hdid_serialize_data d;
for (const auto& [k, v] : convert_map) {
d.rids.push_back(k);
d.hdlkids.push_back(v);
}
std::string content = DoSerialize(d, MapConfig::serialize_type_json1_binary2);
FileSys::Save(MapConfig::sdid2hdid_path, content, MapConfig::tile_encrypt);
}
static void Init() {
std::string content;
if (!FileSys::Read(MapConfig::sdid2hdid_path, content, MapConfig::tile_encrypt)) {
return;
}
sdid2hdid_serialize_data d;
DoSeserialize(content, d, MapConfig::serialize_type_json1_binary2);
if (d.rids.size() != d.hdlkids.size()) // jf_log_error("[SdId2HdId::init]");
for (int i = 0; i < d.rids.size(); ++i) {
convert_map.insert(std::make_pair(d.rids[i], d.hdlkids[i]));
}
}
static bool Convert(const RoadId& in, HdLinkId& hdid) { return jf::Utils::MapValue(convert_map, in, hdid); }
static void Put(const RoadId& r, const HdLinkId& id) { convert_map.insert(std::make_pair(r, id)); }
inline static std::map<RoadId, HdLinkId> convert_map;
};
} // namespace jf
jfxmap_serialize(jf::sdid2hdid_serialize_data, rids, hdlkids);
#endif
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#include "Tile.h"
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#include "Timer.h"
using namespace jf;
std::map<int, std::function<void(double)>> Timer::loopFuncs;
bool Timer::m_bLooping = false;
int Timer::m_nHandleIndex = 0;
timeDuration Timer::m_tdLastDuration;
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment