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.rhkb.cn/news/260130.html

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

相关文章

第四篇【传奇开心果系列】Python文本和语音相互转换库技术点案例示例:pyttsx3自动化脚本经典案例

传奇开心果短博文系列 系列短博文目录Python文本和语音相互转换库技术点案例示例系列 短博文目录前言一、雏形示例代码二、扩展思路介绍三、批量处理文本示例代码四、自定义语音设置示例代码五、结合其他库和API示例代码六、语音交互系统示例代码七、多语言支持示例代码八、添加…

java 宠物医院系统Myeclipse开发mysql数据库web结构jsp编程计算机网页项目

一、源码特点 java 宠物医院系统是一套完善的java web信息管理系统&#xff0c;对理解JSP java编程开发语言有帮助&#xff0c;系统具有完整的源代码和数据库&#xff0c;系统主要采用B/S模式开发。开发环境为TOMCAT7.0,Myeclipse8.5开发&#xff0c;数据库为Mysql5.0&…

HarmonyOS4.0系列——08、整合UI常用组件

HarmonyOS4.0 系列——08、UI 组件 Blank Blank 组件在横竖屏占满空余空间效果 // xxx.ets Entry Component struct BlankExample {build() {Column() {Row() {Text(Button).fontSize(18)Blank()Toggle({type: ToggleType.Switch}).margin({top: 14,bottom: 14,left: 6,righ…

CMNet:Contrastive Magnification Network for Micro-Expression Recognition 阅读笔记

AAAI 2023的一篇文章&#xff0c;东南大学几位老师的工作&#xff0c;用于做微表情识别中的运动增强工作&#xff0c; 以下是阅读时记录的笔记。 摘要&#xff1a; However,existing magnification strategies tend to use the features offacial images that include not onl…

AI提示工程实战:从零开始利用提示工程学习应用大语言模型【文末送书-19】

文章目录 背景什么是提示工程&#xff1f;从零开始&#xff1a;准备工作设计提示调用大语言模型 实际应用示例文字创作助手代码生成持续优化与迭代数据隐私与安全性可解释性与透明度总结 AI提示工程实战&#xff1a;从零开始利用提示工程学习应用大语言模型【文末送书-19】⛳粉…

2023年全球软件开发大会(QCon北京站2023)2月:核心内容与学习收获(附大会核心PPT下载)

本次峰会是一个汇集了最新技术趋势、最佳实践和创新思维的盛会。对于从事软件开发和相关领域的专业人士来说&#xff0c;参加这样的大会将有助于他们了解行业动态、提升技能水平、拓展职业视野&#xff0c;并与同行建立联系和合作。 本次峰会包含&#xff1a;AI基础架构、DevO…

从 AGP 4.1.2 到 7.5.1——XmlParser、GPathResult、QName 过时

新年首发&#xff0c; 去年的问题&#xff0c;今年解决~ 问题 & 排查 1: Task failed with an exception. ----------- * What went wrong: Execution failed for task :app:processCommonReleaseManifest. > org.xml.sax.SAXParseException; lineNumber: 1; columnNu…

【求职】搜狗2016 C++笔试题

1.关于重载和多态正确的是&#xff1f; A.如果父类和子类都有相同的方法,参数个数不同,将子类对象赋给父类后,由于子类继承于父类,所以使用父类指针调用父类方法时,实际调用的是子类的方法; B.选项全部都不正确 C.重载和多态在C面向对象编程中经常用到的方法,都只在实现子类…

【C/C++】2024春晚刘谦春晚魔术步骤模拟+暴力破解

在这个特别的除夕夜&#xff0c;我们不仅享受了与家人的温馨团聚&#xff0c;还被电视机前的春节联欢晚会深深吸引。特别是&#xff0c;魔术师刘谦的精彩表演&#xff0c;为我们带来了一场视觉和心灵的盛宴。在我的博客“【C/C】2024春晚刘谦春晚魔术步骤模拟暴力破解”中&…

WPF中样式

WPF中样式&#xff1a;类似于winform中控件的属性 <Grid><!-- Button属性 字体大小 字体颜色 内容 控件宽 高 --><Button FontSize"20" Foreground"Blue" Content"Hello" Width"100" Height"40"/></G…

x86使用内敛汇编实现简单的临界段保护

临界资源保护 实现方法 禁用中断 __attribute__((used)) static inline uint32_t read_eflags (void){uint32_t eflags;ASM_V("pushf\n\tpop %%eax":"a"(eflags));return eflags; } __attribute__((used)) static inline void write_eflags (uint32_t e…

安全架构设计理论与实践

一、考点分布 安全架构概述&#xff08;※※&#xff09;安全模型&#xff08;※※※&#xff09;信息安全整体架构设计网络安全体系架构设计区块链技术&#xff08;※※&#xff09; 二、安全架构概述 被动攻击&#xff1a;收集信息为主&#xff0c;破坏保密性 主动攻击&#…

Quantitative Analysis: PIM Chip Demands for LLAMA-7B inference

1 Architecture 如果将LLAMA-7B模型参数量化为4bit&#xff0c;则存储模型参数需要3.3GB。那么&#xff0c;至少PIM chip 的存储至少要4GB。 AiM单个bank为32MB&#xff0c;单个die 512MB&#xff0c;至少需要8个die的芯片。8个die集成在一个芯片上。 提供816bank级别的访存带…

计算机视觉的应用23-OpenAI发布的文本生成视频大模型Sora的原理解密

大家好&#xff0c;我是微学AI&#xff0c;今天给大家介绍一下计算机视觉的应用23-OpenAI发布的文本生成视频大模型Sora的原理解密。本文概况性地将Sora模型生成视频主要分为三个步骤&#xff1a;视频压缩网络、空间时间潜在补丁提取以及视频生成的Transformer模型。 文章目录…

「年后复工主题」app用户运营拉新,接入引爆用户增长的活动

随着春节假期的结束&#xff0c;人们重返工作岗位&#xff0c;各行各业也迎来了年后复工的高峰期。在这个时间节点&#xff0c;APP运营团队面临着一个绝佳的机遇——利用节日余温和复工活力&#xff0c;通过策划一系列相关主题的趣味活动来吸引新用户&#xff0c;实现用户增长的…

消息队列(Message Queue)

目录 一、概念 二、消息队列使用场景 三、消息队列的两种模式 1.点对点模式 2.发布/订阅模式 四、常用消息队列介绍 1.RabbitMQ 1) 主要特性 2&#xff09;安装需要 3&#xff09;优点 4&#xff09;缺点 2.ActiveMQ 1&#xff09;主要特性 2) 安装需要 3&#xff09;优…

uniapp富文本文字长按选中(用于复制,兼容H5、APP、小程序三端)

方案&#xff1a;使用u-parse的selectable属性 <u-parse :selectable"true" :html"content"></u-parse> 注意&#xff1a;u-parse直接使用是不兼容小程序的&#xff0c;需要对u-parse进行改造&#xff1a; 1. 查看u-parse源码发现小程序走到以…

Panalog大数据日志审计系统libres_syn_delete.php存在命令执行漏洞

文章目录 前言声明一、Panalog大数据日志审计系统简介二、漏洞描述三、影响版本四、漏洞复现五、整改意见 前言 Panalog大数据日志审计系统定位于将大数据产品应用于高校、 公安、 政企、 医疗、 金融、 能源等行业之中&#xff0c;针对网络流量的信息进行日志留存&#xff0c…

K8s进阶之路-命名空间级-服务发现 :

服务发现&#xff1a; Service&#xff08;东西流量&#xff09;&#xff1a;集群内网络通信、负载均衡&#xff08;四层负载&#xff09;内部跨节点&#xff0c;节点与节点之间的通信&#xff0c;以及pod与pod之间的通信&#xff0c;用Service暴露端口即可实现 Ingress&#…

MySQL命令行输入密码后闪退解决方案

使用MySQL8.0的Command&#xff0c;输入密码后闪退&#xff0c;但是如果不输入密码直接回车&#xff0c;却能直接进入MySQL环境&#xff1b;另外&#xff0c;在IDEA中也无法通过密码连接到root。在网上有如下常见的解决方案&#xff1a;(1)移动my.ini、(2)启动MySQL服务等。但是…