123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- /**
- * 文件 tunnel.cpp
- * 简述 巷道类的实现
- * 详细信息
- * 作者 曾敏果; 邮箱:57862207@qq.com
- * 日期 2022-7-14
- */
- #include "tunnel.h"
- tunnel_cell::tunnel_cell(double x, double y, double z)
- {
- this->x = x;
- this->y = y;
- this->z = z;
- }
- tunnel_cell::~tunnel_cell()
- {
- }
- tunnel::tunnel()
- {
- }
- //初始化格子列表,由一系列线段按顺序构成巷道的所有路径。
- //自第一条线段的顶点开始,每隔一米为一个格子。
- bool tunnel::init_cells()
- {
- bool bRet = true;
- read_lines_from_db();
- transform_lines_to_cells();
- return bRet;
- }
- //初始化巷道
- bool tunnel::init_tunnel()
- {
- init_cells();
- }
- //通过格子索引号获取格子的具体坐标
- bool tunnel::get_position_by_cell_index(int index, point& pos)
- {
- bool bRet = true;
- if (index < 0 || index >= m_vec_cells.size())
- {
- bRet = false;
- return bRet;
- }
- pos = point(m_vec_cells[index].x, m_vec_cells[index].y, m_vec_cells[index].z);
- return bRet;
- }
- int tunnel::get_cells_count()
- {
- return m_vec_cells.size();
- }
- //用于将基站坐标映射到对应的格子索引,这样就能通过基站索引加距离来确定当前车辆所在的格子
- int tunnel::get_cell_index_by_position(const point& pos)
- {
- //取巷道格子中离基站最近的点作为基站的格子号
- int index = 0;
- double dist_min = 1000;//
- for (int i = 0; i < m_vec_cells.size(); i++)
- {
- double dist = pos.dist(point(m_vec_cells[i].x, m_vec_cells[i].y, m_vec_cells[i].z));
- if (dist < dist_min)
- {
- dist_min = dist;
- index = i;
- }
- }
- return index;
- }
- tunnel::~tunnel()
- {
- }
- //从数据库中读取构成整个巷道的所有线段
- bool tunnel::read_lines_from_db()
- {
- bool ret = true;
- m_queue_lines.clear();
- std::string sql = "SELECT id, b_x, b_y, b_z, e_x, e_y, e_z FROM dat_tunnel_path_v ORDER BY id ASC;";
- std::string Error;
- YADB::CDBResultSet DBRes;
- sDBConnPool.Query(sql.c_str(), DBRes, Error);
- int nCount = DBRes.GetRecordCount(Error);
- if (nCount < 1)
- {
- log_error("初始化巷道格子集失败");
- ret = false;
- return ret;
- }
- log_info("init_cells. The record count=%ld\n", nCount);
- while (DBRes.GetNextRecod(Error))
- {
- double b_x = 0.0;
- double b_y = 0.0;
- double b_z = 0.0;
- double e_x = 0.0;
- double e_y = 0.0;
- double e_z = 0.0;
- DBRes.GetField("b_x", b_x, Error);
- DBRes.GetField("b_y", b_y, Error);
- DBRes.GetField("b_z", b_z, Error);
- DBRes.GetField("e_x", e_x, Error);
- DBRes.GetField("e_y", e_y, Error);
- DBRes.GetField("e_z", e_z, Error);
- line_v tunnel_line(point(b_x, b_y, b_z), point(e_x, e_y, e_z));
- m_queue_lines.push_back(tunnel_line);
- }
- return ret;
- }
- //将线段队列转换成巷道格子队列
- bool tunnel::transform_lines_to_cells()
- {
- bool bRet = true;
- for (auto iter_line = m_queue_lines.begin(); iter_line != m_queue_lines.end(); iter_line++)
- {
- std::deque<point> deque_points;
- iter_line->calc_point_list(deque_points);
- for (auto iter_point = deque_points.begin(); iter_point != deque_points.end(); iter_point++)
- {
- m_vec_cells.push_back(tunnel_cell(iter_point->x, iter_point->y, iter_point->z));
- }
- }
- return bRet;
- }
|