qt-交通路口仿真

qt-交通路口仿真

  • 一、演示效果
  • 二、核心代码
  • 三、程序链接


一、演示效果

在这里插入图片描述

二、核心代码

#include "generator.h"Generator::Generator(SimulationScene *scene):m_scene(scene),m_mode(VEHICLEMETHOD::GO_THROUGH),m_running_state(false),m_VisionOn(false),m_IsInteraction(true)
{for(int i = 0 ; i < 4 ; ++i){m_timer.append( new QTimer());}this->connect(m_timer.at(0),SIGNAL(timeout()),this,SLOT(makeEastWest()));this->connect(m_timer.at(1),SIGNAL(timeout()),this,SLOT(makeNorthSouth()));this->connect(m_timer.at(2),SIGNAL(timeout()),this,SLOT(makeSouthNorth()));this->connect(m_timer.at(3),SIGNAL(timeout()),this,SLOT(makeWestEast()));//qsrand(static_cast<uint>(QTime(0,0,0).secsTo(QTime::currentTime())));
}Generator::Generator():m_number_N_S(0),m_number_S_N(0),m_number_W_E(0),m_number_E_W(0),m_time_N_S(0),m_time_S_N(0),m_time_W_E(0),m_time_E_W(0),m_mode(VEHICLEMETHOD::GO_THROUGH),m_running_state(false)
{for(int i = 0 ; i < 4 ; ++i){m_timer.append( new QTimer());}//qsrand(static_cast<uint>(QTime(0,0,0).secsTo(QTime::currentTime())));
}Generator::~Generator()
{delete m_timer.at(0);delete m_timer.at(1);delete m_timer.at(2);delete m_timer.at(3);
}void Generator::setMethod(const GENMETHOD& x)
{m_method = x;
}void Generator::startGenerator()
{m_timer.at(0)->start(m_time_E_W);m_timer.at(1)->start(m_time_N_S);m_timer.at(2)->start(m_time_S_N);m_timer.at(3)->start(m_time_W_E);}void Generator::stopGenerator()
{m_timer.at(0)->stop();m_timer.at(1)->stop();m_timer.at(2)->stop();m_timer.at(3)->stop();
}void Generator::startAutoGeneraion()
{setTimer(2500,2000,2600,3000);startGenerator();
}void Generator::setTimer(const int& N_S,const int& S_N,const int& E_W,const int& W_E)
{m_time_N_S = N_S;m_time_S_N = S_N;m_time_E_W = E_W;m_time_W_E = W_E;
}void Generator::makeNorthSouth()
{if(m_scene->getNumber(REGION_N_S) > MAX_N_S){return;}//qDebug()<<"Hello";switch (m_method) {case GEN_3:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_N_S,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_N_S,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;}break;case GEN_5:switch (qrand()%5){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_N_S,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 3:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 4:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_N_S,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;}break;case NO_TURN:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_N_S,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;}break;case ONLY_TURN:switch (qrand()%2) {case 0:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_N_S,m_mode,m_VisionOn,m_IsInteraction));break;case 1:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_N_S,m_mode,m_VisionOn,m_IsInteraction));break;}break;}
}void Generator::makeSouthNorth()
{if(m_scene->getNumber(REGION_S_N) > MAX_S_N){return;}//qDebug()<<"Hello";switch (m_method) {case GEN_3:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_S_N,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_S_N,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;}break;case GEN_5:switch (qrand()%5){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_S_N,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;case 3:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;case 4:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_S_N,m_mode,m_VisionOn,m_IsInteraction));//m_number_S_N++;break;}break;case NO_TURN:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_S_N,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;}break;case ONLY_TURN:switch (qrand()%2) {case 0:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_S_N,m_mode,m_VisionOn,m_IsInteraction));break;case 1:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_S_N,m_mode,m_VisionOn,m_IsInteraction));break;}break;}
}void Generator::makeWestEast()
{if(m_scene->getNumber(REGION_W_E) > MAX_W_E){return;}//qDebug()<<"Hello";switch (m_method) {case GEN_3:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_W_E,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_W_E,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;}break;case GEN_5:switch (qrand()%5){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_W_E,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;case 3:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;case 4:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_W_E,m_mode,m_VisionOn,m_IsInteraction));//m_number_W_E++;break;}break;case NO_TURN:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_W_E,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;}break;case ONLY_TURN:switch (qrand()%2) {case 0:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_W_E,m_mode,m_VisionOn,m_IsInteraction));break;case 1:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_W_E,m_mode,m_VisionOn,m_IsInteraction));break;}break;}
}void Generator::makeEastWest()
{if(m_scene->getNumber(REGION_E_W) > MAX_E_W){return;}//qDebug()<<"Hello";switch (m_method) {case GEN_3:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_E_W,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_E_W,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;}break;case GEN_5:switch (qrand()%5){case 0:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_E_W,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;case 3:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;case 4:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_E_W,m_mode,m_VisionOn,m_IsInteraction));//m_number_E_W++;break;}break;case NO_TURN:switch (qrand()%3){case 0:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,1,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 1:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,2,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;case 2:m_scene->addVehicle(VehiclesGenerator::getThroughVehicle(REGION_E_W,3,m_mode,m_VisionOn,m_IsInteraction));//m_number_N_S++;break;}break;case ONLY_TURN:switch (qrand()%2) {case 0:m_scene->addVehicle(VehiclesGenerator::getLeftTurningVehicle(REGION_E_W,m_mode,m_VisionOn,m_IsInteraction));break;case 1:m_scene->addVehicle(VehiclesGenerator::getRightTurningVehicle(REGION_E_W,m_mode,m_VisionOn,m_IsInteraction));break;}break;}
}void Generator::setMode(const VEHICLEMETHOD &mode)
{m_mode = mode;
}void Generator::setVisionOn(const bool &vision)
{m_VisionOn = vision;
}void Generator::setInteraction(const bool &interact)
{m_IsInteraction = interact;
}void Generator::setScene(SimulationScene *scene)
{m_scene = scene;
}void Generator::turnOn()
{m_running_state = true;
}void Generator::turnOff()
{m_running_state = false;
}

三、程序链接

https://download.csdn.net/download/u013083044/88850953

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/692374.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

HTML元素和属性快速参考指南

​ 以下是几个与HTML元素和属性相关的参考资料网站链接&#xff1a; HTML Reference - 提供所有HTML元素和属性的免费指南。W3Schools HTML Reference - W3Schools 提供一个广泛的HTML标签和属性参考。freeCodeCamp HTML Cheat Sheet - freeCodeCamp 提供了一个HTML元素列表参…

【Label Studio运行报错】ModuleNotFoundError: No module named ‘google.rpc‘

报错截图&#xff1a; 解决方法&#xff1a; 新建虚拟环境&#xff0c;安装google相关包 pip install google-cloud-core google-cloud-storage把虚拟环境中site-packages下google文件夹拷贝到当前环境的对应位置下。去官网下载最新的sqlite3&#xff0c;复制到AppData\Loca…

Android挖取原图中心区域RectF(并框线标记)放大到ImageView宽高,Kotlin

Android挖取原图中心区域RectF(并框线标记)放大到ImageView宽高&#xff0c;Kotlin 红色线框区域即为选中的原图中心区域&#xff0c;放大后放到等宽高的ImageView里面。 import android.content.Context import android.graphics.Bitmap import android.graphics.BitmapFactor…

163邮箱发邮件

1、Jenkins安装Email Extension Plugin 2、网易邮箱里获取授权码:qa_jenkins_robot@163.com 开启POP3/SMTP 我已经配置过了,所以这里会有一个使用设备 3、配置Jenkins邮箱通知 Manage Jnekins-Configuration System Jenkins Location: Extended E-mail Notification: …

【MySQL】如何处理DB读写分离数据不一致问题?

文章内容 1、前言读写库数据不一致问题我们如何解决&#xff1f;方案一&#xff1a;利用数据库自身特性方案二&#xff1a;不解决方案三&#xff1a;客户端保存法方案四&#xff1a;缓存标记法方案五&#xff1a;本地缓存标记 那DB读写分离情况下&#xff0c;如何解决缓存和数据…

【最新Dubbo3深入理解】Dubbo特性、工作原理以及负载均衡策略

欢迎关注公众号&#xff08;通过文章导读关注&#xff1a;【11来了】&#xff09;&#xff0c;及时收到 AI 前沿项目工具及新技术的推送&#xff01; 在我后台回复 「资料」 可领取编程高频电子书&#xff01; 在我后台回复「面试」可领取硬核面试笔记&#xff01; 文章导读地址…

代码随想录算法训练营第56天 | 300.最长递增子序列 674.最长连续递增序列 718.最长重复子数组

最长递增子序列 这里dp数组的定义比较难想。dp[i] 表示 i 之前的序列中以 nums[i] 结尾的最长递增子序列长度&#xff0c;只有这样才能实现状态递推。对于dp数组初始化&#xff0c;所有下标位置都应该初始化为1。 class Solution{ public:int lengthOfLIS(vector<int>&a…

课后延时服务选课报名管理系统功能清单

课后延时服务选课报名管理系统分为学校端&#xff0c;培训机构端&#xff0c;家长端。 学校端提供学生管理&#xff0c;课程管理&#xff0c;班级管理&#xff0c;班级排课&#xff0c;班级课表&#xff0c;可直接安排学生入班上课&#xff0c;查看学生考勤情况&#xff0c;查…

网关服务gateway注册Consul时报错Consul service ids must not be empty

网关服务gateway启动时&#xff0c;初始化Consul相关配置时报错。 Consul service ids must not be empty, must start with a letter, end with a letter or digit, and have as interior characters only letters, digits, and hyphen: cbda-server-gateway:10.111.236.142:…

stm32学习笔记-STLINK使用

stm32学习笔记-STLINK使用 使用ST-LINK调试程序进度表格 使用ST-LINK调试程序 说明 组成 总结 记录使用STLINK进行项目的烧写和调试&#xff0c;旨在高效的进行代码调试学习工具包括笔记本、keil5MDK、stm32f030c8t6电表主机、STLINK V2、导线、电表代码总的来说&#xff0…

深度学习图像算法工程师--面试准备(1)

1 请问人工神经网络中为什么 ReLU 要好过于 tanh 和 Sigmoid function&#xff1f; 采⽤Sigmoid 等函数&#xff0c;算激活函数时&#xff08;指数运算&#xff09;&#xff0c;计算量⼤&#xff0c;反向传播求误差梯度时&#xff0c;求导涉及除法和指数运算&#xff0c;计算量…

企业级 文件传输加密应用,干货分享

企业级 文件传输加密应用 简历一直在投&#xff0c;一直无音讯&#xff0c;今天我又从硬盘里翻出一个 好玩的加密软件&#xff0c;这个是 2017年的时候和荷兰某世界500强公司合作的小项目。 今天分享给大家 。 文章目录 企业级 文件传输加密应用1.目的2.软件介绍3.下载好 安装…

Discuz! X3.4上次访问时间显示1970积分不增加问题

您好&#xff0c;我discuz论坛的【注册用户注册信息的运行】存在问题&#xff0c;您看能调试吗&#xff1f; 这个论坛的“注册用户信息是”从其它discuz论坛【迁移过来的】&#xff0c; 所以&#xff0c;目前&#xff1a; 全部用户 新注册用户 迁移过来的用户 故障现象是…

我的NPI项目之Android USB 系列(一) - 遥望和USB的相识

和USB应该是老朋友了&#xff0c;从2011年接触Android开发开始&#xff0c;就天天和USB打交道了。那时候还有不 对称扁头的usb/方口的usb&#xff0c;直到如今使用广泛的防反插USB3.0 type-C。 但是&#xff0c;一直有一个不是很清楚的问题萦绕在心头&#xff0c;那就是。先有…

Java基于SpringBoot+Vue的图书管理系统

博主介绍&#xff1a;✌程序员徐师兄、7年大厂程序员经历。全网粉丝12w、csdn博客专家、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精彩专栏推荐订阅&#x1f447;…

Spring相关注解

文章目录 Spring注解Bean1、Bean 概述2、Bean 的声明1&#xff09;搭配 Configuration2&#xff09;搭配 Component3&#xff09;搭配 ApplicationContext 3、Bean 的注入1&#xff09;NO&#xff08;主要关注这个&#xff09;【1】同一配置类【2】不同配置类 2&#xff09;BY_…

软件测试进阶自动化测试流程

如果想让测试在公司的项目中发挥出它最大的价值&#xff0c;并不是招两个测试技术高手&#xff0c;或引入几个测试技术&#xff0c;而是测试技术对项目流程的渗透&#xff0c;以及测试流程的改进与完善。虽然&#xff0c;当然测试行业前景乐观&#xff0c;许多中小企业也都在引…

C++11---(3)

目录 一、可变参数模板 1.1、可变参数模板的概念 1.2、可变参数模板的定义方式 1.3、如何获取可变参数 二、lambda表达式 2.1、Lamabda表达式定义 2.2、为什么有Lambda 2.3、Lambda表达式的用法 2.4、函数对象与lambda表达式 三、包装器 3.1、function 3.2、bind …

Spring源码:手写SpringIOC

文章目录 一、分析二、实现1、版本1&#xff1a;实现Bean注入IOC容器&#xff0c;并从容器中获取1&#xff09;定义BeanDefinition2&#xff09;定义BeanDefinition实现类3&#xff09;定义BeanDefinitionRegistry4&#xff09;定义Beanfactory5&#xff09;定义默认Beanfactor…

GC调优学习

一.常见工具P62P63 1.jstat 2.visualvm插件 3.Prometheus Grafana 4.GC日志 5.GC Viewer 6.GCeasy&#xff08;强推&#xff09; 二.常见的GC模式P64 三.GC调优 1.优化基础JVM参数P65 2.减少对象产生 看以前视频&#xff0c;内存泄露相关 3.垃圾回收器的选择P66 4.优化垃圾回…