qt-交通路口仿真

news2024/11/26 2:36:40

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.coloradmin.cn/o/1456955.html

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

相关文章

AI时代教师如何修炼内功

AI时代教师如何修炼内功 How Teachers Can Cultivate Their Inner Strength in the Age of AI 在AI时代&#xff0c;教师的角色和职责正在经历前所未有的变革。随着人工智能技术的不断进步&#xff0c;教育领域出现了许多新的工具和方法&#xff0c;这些新发展要求教师提升自身…

MySQL系列之索引入门(下)

前言 通过上文&#xff0c;我想各位盆友已熟悉MySQL的索引分类及其含义&#xff0c;那么如何合理的使用呢&#xff1f; 请继续围观此文&#xff0c;一探究竟&#xff01; 一、创建索引 首先&#xff0c;我们一起学习索引是如何创建的&#xff0c;又有哪些方式。 1. create t…

IO线程进程

代码练习 使用fread和fwrite完成两个文件的拷贝 #include<myhead.h>int main(int argc, const char *argv[]) {FILE *fp NULL;//重新以只读的形式打开文件if((fp fopen("./OIP-C.bmp", "r")) NULL){perror("fopen error");return -1;…

stm32--笔记

一、引脚与变量 ​​​​​​​​​​​​​​ 二、STM32时钟 [STM32-时钟系统详解_stm32时钟_KevinFlyn的博客-CSDN博客] 三、定时器中断实验 1、定时器中断实验 ​ stm32关于通用定时器的周期、频率计算公式_stm32tim频率计算_胶囊咖啡的博客-CSDN博客 ​ 【STM32】通用…

阿里云服务器CPU内存配置怎么选择够用?

阿里云服务器配置怎么选择&#xff1f;根据实际使用场景选择&#xff0c;个人搭建网站可选2核2G配置&#xff0c;访问量大的话可以选择2核4G配置&#xff0c;企业部署Java、Python等开发环境可以选择2核8G配置&#xff0c;企业数据库、Web应用或APP可以选择4核8G配置或4核16G配…

【已解决】引发的异常: 0xC0000005: 读取位置 0xFFFFFFFFFFFFFFFF 时发生访问冲突。

这种问题产生一般都会手足无措&#xff0c;包括笔者&#xff0c;但是不要慌&#xff0c;这种问题一般都是内存泄漏引起的。例如读者要访问一个已经被析构或者释放的变量&#xff0c;当然访问不了&#xff0c;导致存在问题。这时候读者应该从哪里产生内存泄漏这方面进行考虑&…

【C深剖】数组名的细节

本系列博客为个人刷题思路分享&#xff0c;有需要借鉴即可。 引言&#xff1a;我想我说的这个数组名细节可能很多人并没有留意&#xff0c;现在先来C设计者这样设计也很合理。 就是数组名本质上是一个指针&#xff0c;但是这个指针的内容也就是说指向的空间是固定的&#xff0c…

IO 作业 24/2/19

1> 使用fread和fwrite完成两个文件的拷贝 #include <myhead.h> int main(int argc, const char *argv[]) {//定义被复制文件指针FILE *fp1NULL;if((fp1fopen("./111.bmp","r"))NULL){perror("error open");return -1;}//定义目标文件指…

OpenAI划时代大模型——文本生成视频模型Sora作品欣赏(三)

Sora介绍 Sora是一个能以文本描述生成视频的人工智能模型&#xff0c;由美国人工智能研究机构OpenAI开发。 Sora这一名称源于日文“空”&#xff08;そら sora&#xff09;&#xff0c;即天空之意&#xff0c;以示其无限的创造潜力。其背后的技术是在OpenAI的文本到图像生成模…

【数据结构与算法】手搓JDK底层ArrayList底层 - 动态数组

数组 在介绍数组之前&#xff0c;我们先来看一段chatGPT给出的对于数组描述&#xff1a; 数组&#xff08;Array&#xff09;是一种线性数据结构&#xff0c;它由一组连续的内存空间组成&#xff0c;用来存储相同类型的数据元素。数组具有固定的大小&#xff0c;一旦创建后&a…

Gitlab中CICD提交代码后,运行报错:Preparation failed: Cannot connect to the Docker daemon

目录 1.1、错误描述 1.2、解决方案 1.1、错误描述 今天工作中&#xff0c;合并到了几个Git分支上的代码到dev环境&#xff0c;触发Gitlab流水线进行打包构建的时候&#xff0c;突然报错了&#xff0c;结果如下&#xff1a; 点进去查看具体的报错日志&#xff0c;报错信息见下…

【每周AI简讯】OpenAI推出王炸文生视频模型Sora

ChatGPT中文版https://ai7.pro OpenAI推出王炸文生视频模型Sora OpenAI 宣布推出名为 Sora 的新型文本到视频模型。Sora 能根据用户的文本提示&#xff0c;生成长达一分钟的逼真视频。它可以创造出细节丰富的场景、复杂的摄影机运动以及表情丰富的多个角色。Sora 是一种扩散模…

PyCharm 主题和字体 (Scheme Editor Font)

PyCharm 主题和字体 [Scheme & Editor Font] References Scheme & Editor Font File -> Settings -> Editor -> Colors & Fonts -> Font Show only monospaced fonts&#xff1a; 只显示等宽字体。编程时使用等宽字体效果较好。 References [1] Yon…

前端win10如何设置固定ip(简单明了)

1、右击这个 2、点击属性 3、双击协议版本4设置成以下就ok

基于Springboot+Vue的超市管理系统源码

✌全网粉丝20W,csdn特邀作者、博客专家、CSDN新星计划导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取项目下载方式&#x1f345; 一、项目背景介绍&#xff1a; 随着社会经济的发展和…

第三百五十五回

文章目录 1. 概念介绍2. 获取方法3. 示例代码4. 对比与总结4.1 横向对比4.2 内容总结 我们在上一章回中介绍了"如何获取当前系统语言"相关的内容&#xff0c;本章回中将介绍如何获取当前时区.闲话休提&#xff0c;让我们一起Talk Flutter吧。 1. 概念介绍 我们使用的…

探索与实践:深度解读禅道项目管理工具的高效运用

【引言】 在日益复杂的现代项目管理领域中&#xff0c;一款优秀的项目管理工具能够极大地提升团队协作效率&#xff0c;降低项目风险&#xff0c;而禅道正是这样一款深受开发者和项目经理喜爱的产品。它是一款基于敏捷开发理念设计的开源项目管理软件&#xff0c;涵盖了产品管…

One API初体验

前言 忘了在微信公众号是先看到了FastGPT还是One API了&#xff0c;反正对于自己来说知识库或One API都是个新东西&#xff0c;都有很强大的活力。One API在我看来&#xff0c;可能更基础、部署更简单一些&#xff0c;于是打算先搞个One API部署来看看。 One API是开源的&…

使用openai-whisper实现语音转文字

使用openai-whisper实现语音转文字 1 安装依赖 1.1 Windows下安装ffmpeg FFmpeg是一套可以用来记录、转换数字音频、视频&#xff0c;并能将其转化为流的开源计算机程序。采用LGPL或GPL许可证。它提供了录制、转换以及流化音视频的完整解决方案。 # ffmpeg官网 https://ffm…

业务型 长时间组件封装(复制即可使用)

{/*disabledAfter 日期限制 例如传入5 则只能选择今天日期5天内的时间 */} import React from react; import { DatePicker } from antd; import moment from moment;const { RangePicker } DatePicker;const CustomRangePicker ({ value, onChange, disabledAfter, ...restP…