QCustomplot基本使用

QCustomPlot系列2—绘制折线图(X轴为时间) 【代码】QCustomPlot系列2—绘制折线图(X轴为时间) 阅读详情

QCustomplot基本使用

安装

  • 进入官网下载最新版本下载QCustomplot,解压后可直接引用源码,也可编译链接动态库。此例中实现基本折线图绘制、十字线、标记marker功能。

画折线图

  • 打开Qt创建新工程,引用QCustomplot源码到工程中
  • 工程.pro文件:
QT       += core gui opengl printsupport

DEFINES += QCUSTOMPLOT_USE_OPENGL

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    CMainPlot.cpp \
    TestWidget.cpp \
    main.cpp \
    qcustomplot.cpp

HEADERS += \
    CMainPlot.h \
    TestWidget.h \
    qcustomplot.h

FORMS += \
    TestWidget.ui

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

  • main.cpp
#include "TestWidget.h"

#include <QApplication>

int main(int argc, char *argv[]) {
  QApplication a(argc, argv);
  TestWidget w;
  w.show();

  return a.exec();
}
  • TestWidget.h
#ifndef TEST_WIDGET_H
#define TEST_WIDGET_H

#include "CMainPlot.h"
#include <QTimer>
#include <QVector>
#include <QWidget>

QT_BEGIN_NAMESPACE
namespace Ui {
class TestWidget;
}
QT_END_NAMESPACE

class TestWidget : public QWidget {
  Q_OBJECT

public:
  TestWidget(QWidget *parent = nullptr);
  ~TestWidget();

private:
  Ui::TestWidget *ui;

  CMainPlot *plot_main_;
};
#endif // TEST_WIDGET_H

  • TestWidget.cpp
#include "TestWidget.h"
#include "ui_TestWidget.h"

TestWidget::TestWidget(QWidget *parent)
    : QWidget(parent), ui(new Ui::TestWidget) {
  ui->setupUi(this);

  plot_main_ = new CMainPlot();
  ui->horizontalLayout->addWidget(plot_main_);
}

TestWidget::~TestWidget() { delete ui; }
  • TestWidget.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>TestWidget</class>
 <widget class="QWidget" name="TestWidget">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>800</width>
    <height>600</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Test Widget</string>
  </property>
  <layout class="QHBoxLayout" name="horizontalLayout"/>
 </widget>
 <resources/>
 <connections/>
</ui>

  • CMainPlot.h
#ifndef MAIN_PLOT_DEF_H
#define MAIN_PLOT_DEF_H

#include "qcustomplot.h"
#include <QTimer>
#include <array>
#include <random>

#define X_DATA_COUNT 1000
#define Y_DATA_MAX_LIMIT 100

class CrossLine; // 十字线
class DrawTriangle; // 绘制倒三角形
class MarkerManager; // 绘制marker

class CMainPlot : public QWidget {
  Q_OBJECT
public:
  explicit CMainPlot(QWidget *parent = nullptr);

private:
  void Init();

  void SetXRange(double min, double max, const QString &name = "");
  void SetYRange(double min, double max, const QString &name = "");

  void CreateX(int size);
  void CreateY(int size, QVector<double> *ret);

private:
  QCustomPlot *plot_; // 作用类似画板
  QCPGraph *graph_selected_;  // marker依附的曲线标记
  CrossLine *cross_line_; // 十字线

  MarkerManager *draw_marker_; // marker

  QVector<double> vec_data_x_; // 模拟x轴数据
  QTimer update_data_timer_; // 模拟曲线数据定时器
};

class CrossLine : public QObject {
  Q_OBJECT
public:
  CrossLine(QCustomPlot *plot);

  void SetVisible(bool v);
  void CrossLineDraw(double x, double y);

private:
  void SetXLineCoords(double lx, double ly, double rx, double ry);
  void SetYLineCoords(double tx, double ty, double bx, double by);
  void SetTextCoords(double x, double y);
  void SetTextPixel(int x, int y);
  void SetText(const QString &xText, const QString &yText);

private:
  QCustomPlot *plot_;
  QCPItemLine *x_line_;  // 横线
  QCPItemLine *y_line_;  // 竖线
  QCPItemText *text_;    // 文本显示

  QPointF mouse_coords_;  // 记录鼠标坐标
};

class DrawMarker : public QObject {
  Q_OBJECT
public:
  DrawMarker(QCustomPlot *plot);

  void MarkerDraw(double x, double y);
  void SetVisible(bool v);
  void SetPixelPosition(double x, double y);
  bool IsVisible() const;

private:
  bool visible_;  // 是否可见
  QCustomPlot *plot_;
  QCPItemText *text_;  // mark文本

  DrawTriangle *triangle_; // 倒三角形
};

class MarkerManager : public QObject {
  Q_OBJECT
public:
  MarkerManager(QCustomPlot *plot);
  void ClearMarker();
  void MarkerDraw(double xpos, double ypos, QCPGraph *graph);
  void UpdateMarker();

private:
  QCustomPlot *plot_;
  std::array<DrawMarker *, 5> array_marker_; // marker数组,最多绘制5个
  std::array<QCPItemTracer *, 5> array_tracer_; // marker依附曲线数组,数据寻峰
  std::array<QPointF, 5> array_mouse_pos_;   // 记录鼠标位置

  int marker_count_;  // 绘制marker的索引
};

class DrawTriangle : public QCPAbstractItem {
  Q_OBJECT
public:
  DrawTriangle(QCustomPlot *plot);

  void TriangleDraw(double x, double y);
  void SetVisible(bool v);

private:
  void SetMouseCoords(double x, double y);

  // reimplemented virtual methods:
  virtual double selectTest(const QPointF &pos, bool onlySelectable, QVariant *details = nullptr) const Q_DECL_OVERRIDE;

  virtual void draw(QCPPainter *painter) Q_DECL_OVERRIDE;

private:
  QCustomPlot *plot_;
  QPointF mouse_coords_;  // 记录鼠标坐标
};

#endif // MAIN_PLOT_DEF_H

  • CMainPlot.cpp
#include "CMainPlot.h"
#include <QHBoxLayout>

CMainPlot::CMainPlot(QWidget *parent) : QWidget(parent) {
  Init();
  update_data_timer_.setInterval(40);

  CreateX(X_DATA_COUNT);
  connect(&update_data_timer_, &QTimer::timeout, [this] {
    static QVector<double> vec_data_y;
    CreateY(X_DATA_COUNT, &vec_data_y);
    plot_->graph(0)->setData(vec_data_x_, vec_data_y);
    CreateY(X_DATA_COUNT, &vec_data_y);
    plot_->graph(1)->setData(vec_data_x_, vec_data_y);
    draw_marker_->UpdateMarker();
    plot_->replot();
  });
  update_data_timer_.start();
  this->resize(800, 600);

  QHBoxLayout *hbox = new QHBoxLayout;
  hbox->addWidget(plot_);
  this->setLayout(hbox);

  draw_marker_ = new MarkerManager(plot_);
}

void CMainPlot::SetXRange(double min, double max, const QString &name) {
  plot_->xAxis->setRange(min, max);
  plot_->xAxis->setLabel(name);
}

void CMainPlot::SetYRange(double min, double max, const QString &name) {
  plot_->yAxis->setRange(min, max);
  plot_->yAxis->setLabel(name);
}

void CMainPlot::CreateX(int size) {
  for (int i = 0; i < size; ++i) {
    vec_data_x_.push_back(i);
  }
}

void CMainPlot::CreateY(int size, QVector<double> *ret) {
  ret->resize(size);
  std::random_device rd;
  std::default_random_engine e(rd());
  std::uniform_int_distribution<int> uniform_dist(1, Y_DATA_MAX_LIMIT);

  for (int i = 0; i < size; ++i) {
    (*ret)[i] = uniform_dist(e);
  }
}

void CMainPlot::Init() {
  plot_ = new QCustomPlot(this);
  plot_->setInteractions(QCP::iRangeZoom | QCP::iSelectPlottables);

  SetXRange(0, X_DATA_COUNT, "X");
  SetYRange(0, Y_DATA_MAX_LIMIT + 10, "Y");

  //  plot_->legend->setVisible(true);
  //  plot_->legend->setTextColor(Qt::blue);
  plot_->setOpenGl(true);

  plot_->addGraph();
  plot_->graph(0)->setPen(QPen(Qt::red));
  plot_->graph(0)->setName("red color");

  plot_->addGraph();
  plot_->graph(1)->setPen(QPen(Qt::green));
  plot_->graph(1)->setName("green color");
  plot_->replot();

  cross_line_ = new CrossLine(plot_);
  cross_line_->SetVisible(true);

  graph_selected_ = nullptr;

  connect(plot_, &QCustomPlot::selectionChangedByUser, [this] {
    for (int i = 0; i < plot_->graphCount(); ++i) {
      if (!plot_->graph(i)->selected())
        continue;

      graph_selected_ = plot_->graph(i);
      break;
    }
  });

  connect(plot_, &QCustomPlot::mouseMove, [this](QMouseEvent *event) {
    double x = plot_->xAxis->pixelToCoord(event->pos().x());
    double y = plot_->yAxis->pixelToCoord(event->pos().y());
    cross_line_->CrossLineDraw(x, y);
    plot_->replot();
  });

  connect(plot_, &QCustomPlot::mouseDoubleClick, [this](QMouseEvent *event) {
    if (graph_selected_ == nullptr)
      return;
    draw_marker_->MarkerDraw(event->pos().x(), event->pos().y(),
                             graph_selected_);
    plot_->replot();
  });
}

CrossLine::CrossLine(QCustomPlot *plot) : QObject(nullptr), plot_(plot) {
  assert(plot != nullptr);

  QPen pen;
  pen.setWidthF(1.3);
  pen.setColor(Qt::blue);

  x_line_ = new QCPItemLine(plot_);
  x_line_->setPen(pen);
  x_line_->setSelectable(false);

  y_line_ = new QCPItemLine(plot_);
  y_line_->setPen(pen);
  y_line_->setSelectable(false);

  text_ = new QCPItemText(plot_);
  text_->setPen(pen);
  text_->setColor(Qt::blue);
  text_->setSelectable(false);
  SetVisible(false);
}

void CrossLine::SetVisible(bool v) {
  x_line_->setVisible(v);
  y_line_->setVisible(v);
  text_->setVisible(v);
}

void CrossLine::CrossLineDraw(double x, double y) {
  mouse_coords_.setX(x);
  mouse_coords_.setY(y);

  double l = plot_->xAxis->pixelToCoord(plot_->rect().topLeft().x());
  double r = plot_->xAxis->pixelToCoord(plot_->rect().topRight().x());
  SetXLineCoords(l, y, r, y);

  l = plot_->yAxis->pixelToCoord(plot_->rect().topLeft().y());
  r = plot_->yAxis->pixelToCoord(plot_->rect().bottomRight().y());
  SetYLineCoords(x, l, x, r);

  l = plot_->xAxis->coordToPixel(x);
  r = plot_->yAxis->coordToPixel(y);
  SetTextPixel(l + 40, r - 20);
  SetText(QString("X: %1").arg(x), QString("Y: %1").arg(y));
}

void CrossLine::SetXLineCoords(double lx, double ly, double rx, double ry) {
  x_line_->start->setCoords(lx, ly);
  x_line_->end->setCoords(rx, ry);
}

void CrossLine::SetYLineCoords(double tx, double ty, double bx, double by) {
  y_line_->start->setCoords(tx, ty);
  y_line_->end->setCoords(bx, by);
}

void CrossLine::SetTextCoords(double x, double y) {
  text_->position->setCoords(x, y);
}

void CrossLine::SetTextPixel(int x, int y) {
  text_->position->setPixelPosition(QPointF(x, y));
}

void CrossLine::SetText(const QString &xText, const QString &yText) {
  text_->setText(QString("%1\n%2").arg(xText).arg(yText));
}

DrawMarker::DrawMarker(QCustomPlot *plot) : QObject(nullptr), plot_(plot) {
  assert(plot != nullptr);

  text_ = new QCPItemText(plot_);
  text_->setTextAlignment(Qt::AlignmentFlag::AlignLeft);
  //  text_->setColor(QColor(Qt::green));
  triangle_ = new DrawTriangle(plot_);
}

void DrawMarker::SetPixelPosition(double x, double y) {
  text_->position->setPixelPosition(QPointF(x, y));
}

bool DrawMarker::IsVisible() const { return visible_; }

void DrawMarker::MarkerDraw(double x, double y) {
  triangle_->TriangleDraw(x, y);
  text_->setText(QString("X: %1, Y: %2").arg(x).arg(y));
}

void DrawMarker::SetVisible(bool v) {
  visible_ = v;
  triangle_->SetVisible(v);
  text_->setVisible(v);
}

DrawTriangle::DrawTriangle(QCustomPlot *plot)
    : QCPAbstractItem(plot), plot_(plot) {

  assert(plot != nullptr);
  SetVisible(false);
}

void DrawTriangle::TriangleDraw(double x, double y) {
  SetVisible(true);
  SetMouseCoords(x, y);
}

void DrawTriangle::SetVisible(bool v) { this->setVisible(v); }

void DrawTriangle::SetMouseCoords(double x, double y) {
  mouse_coords_.setX(x);
  mouse_coords_.setY(y);
}

double DrawTriangle::selectTest(const QPointF &pos, bool onlySelectable,
                                QVariant *details) const {
  Q_UNUSED(details)
  Q_UNUSED(pos)
  if (onlySelectable && !mSelectable)
    return -1;
  return -1;
}

/* inherits documentation from base class */
void DrawTriangle::draw(QCPPainter *painter) {

  painter->save();
  painter->setPen(Qt::red); //画笔
  painter->setBrush(Qt::red);

  double x = plot_->xAxis->coordToPixel(mouse_coords_.x());
  double y = plot_->yAxis->coordToPixel(mouse_coords_.y());

  QPainterPath path;
  // Set pen to this point.
  path.moveTo(x - 10, y - 10);
  // Draw line from pen point to this point.
  path.lineTo(x + 10, y - 10);

  path.moveTo(x + 10, y - 10);
  path.lineTo(x, y);

  path.moveTo(x, y);
  path.lineTo(x - 10, y - 10);

  painter->fillPath(path, QBrush(Qt::red));
  painter->drawPath(path);
  painter->restore();
}

MarkerManager::MarkerManager(QCustomPlot *plot)
    : QObject(nullptr), plot_(plot) {
  assert(plot != nullptr);
  for (size_t i = 0; i < array_marker_.size(); ++i) {
    array_marker_[i] = new DrawMarker(plot_);
    array_marker_[i]->SetVisible(false);
    array_tracer_[i] = new QCPItemTracer(plot_);
    array_tracer_[i]->setVisible(false);
    array_tracer_[i]->setInterpolating(true);
  }

  marker_count_ = 0;
}

void MarkerManager::ClearMarker() {
  marker_count_ = 0;

  for (size_t i = 0; i < array_marker_.size(); ++i) {
    array_marker_[i]->SetVisible(false);
  }
}

void MarkerManager::MarkerDraw(double xpos, double ypos, QCPGraph *graph) {
  double x = plot_->xAxis->pixelToCoord(xpos);
  double y = plot_->yAxis->pixelToCoord(ypos);
  array_marker_[marker_count_]->SetVisible(true);
  array_mouse_pos_[marker_count_] = QPointF(xpos, ypos);

  QPoint pt = plot_->rect().topRight();
  array_marker_[marker_count_]->SetPixelPosition(
      pt.x() - 110, pt.y() + 20 * (marker_count_ + 1));

  array_marker_[marker_count_]->MarkerDraw(x, y);

  if (graph) {
    array_tracer_[marker_count_]->setGraph(graph);
    array_tracer_[marker_count_]->setGraphKey(x);
    array_tracer_[marker_count_]->updatePosition();
  }

  marker_count_ = (++marker_count_) % array_marker_.size();
}

void MarkerManager::UpdateMarker() {

  double low = plot_->xAxis->range().lower;
  double up = plot_->xAxis->range().upper;
  int start = 0;
  int end = 0;
  double offset = 0.0;

  double x = 0.0;
  double y = 0.0;
  double pos = 0.0;
  for (size_t i = 0; i < array_mouse_pos_.size(); ++i) {
    if (!array_marker_[i]->IsVisible())
      continue;

    x = plot_->xAxis->pixelToCoord(array_mouse_pos_[i].x());
    y = plot_->yAxis->pixelToCoord(array_mouse_pos_[i].y());

    if (array_tracer_[i]->graph() == nullptr)
      continue;

    pos = array_tracer_[i]->graph()->dataCount() * ((x - low) / (up - low));

    offset = array_tracer_[i]->graph()->dataCount() * 0.005;

    start = pos - offset > 0 ? pos - offset : 0;
    end = pos + offset > array_tracer_[i]->graph()->dataCount()
              ? array_tracer_[i]->graph()->dataCount()
              : pos + offset;

    double max = array_tracer_[i]->graph()->dataMainValue(start);
    int index = start;
    for (int n = start + 1; n < end; ++n) {
      if (array_tracer_[i]->graph()->dataMainValue(n) < max)
        continue;

      index = n;
      max = array_tracer_[i]->graph()->dataMainValue(n);
    }

    array_tracer_[marker_count_]->setGraphKey(
        array_tracer_[i]->graph()->dataMainKey(index));
    array_tracer_[marker_count_]->updatePosition();
    array_marker_[i]->MarkerDraw(array_tracer_[i]->graph()->dataMainKey(index),  max);
  }
}

图例

![运行图例](https://img-blog.csdnimg.cn/0f79e39759494909aa78adb16901fa3a.png#pic_center) 运行图例

起始

QT——如何使用QCustomPlot绘制折线图 需求:做一个折线图,y轴为温度,x轴为时间,点数据从数据库中获取,鼠标在折线图中悬浮时显示对应点的数据。 我是在Node1_Temperature文件里写折线图。 1、下载安装第三方库QCustomPlot 官方下载地址: https://www.qcustomplot.com/index.php/download 需要注意的地方是2.0.1和1.3.2版本有些内置函数有很大变化,甚至是直接取消了。比如当你x轴显示的字太长放不下,想要旋转字体的时候,1.3.2版本里有一个... 阅读详情

相关推荐

QCustomPlot使用

一、官网下载 QCustomPlot官网下载 从官网下载 qcustomplot.h 和 qcustomplot.cpp 二、加入工程 通过添加现有文件将 qcustomplot.h、qcustomplot.cpp加入工程,并在pro文件中加入printsupport 三、使用

pzs0221的专栏 2万+

Qt框架绘图高级编程、仪表盘、折线图、饼图、柱状图、K线图

Qt是由Qt Company开发的主流跨平台C++图形用户界面应用程序开发框架。Qt是面向对象的框架、容易扩展,并且允许真正地组件编程,既可以开发GUI程序,也可用于控制台工具和服务器。其跨平台集成开发环境Qt Creator 全面支持Windows ,mac、Linux、iOS、Android、WP等。 本课程主要帮助学员熟练掌握Qt 5框架下的C++开发,通过核心内容的详细讲解演示,迅速帮助学员达到企业级Qt开发工程师的能力!课程包括以下内容:Qt QPainter绘图常用操作(画图、线、文字、矩形、扇形等)项目实战一、Qt 绘制汽车仪表盘项目实战二、Qt 绘制漂亮预警仪表项目实战三、Qt 实现自绘折线图Qt 框架之 图表模块QtChart、折线图、柱状图、饼图等Qt 高性能轻量级图表QCustomPlot、折线图、金融图等Qt 工业图表库QWT的使用、图表、指南针、温度计、旋钮等

QCustomPlot 曲线各种属性详细介绍

图表曲线作为一种直观分析的工具,在软件的应用中非常广泛,我在Qt的应用软件中一直使用QCustomPlot第三方类库,最近因为肺炎疫情一直在家办公,正好抽个时间整理一下QCustomPlot经常使用的属性,省得自己花精力去查阅。 1. legend 设置图例字体、大小、是否显示: QFont font; font.setPixelSize(12);//文字像素大小 font....

luanl的博客 1万+

采用Qt快速绘制多条曲线(折线),跟随鼠标动态显示线上点的值(基于Qt的开源绘图控件QCustomPlot进行二次开发)

采用Qt快速绘制多条曲线(折线),跟随鼠标动态显示线上点的值(基于Qt的开源绘图控件QCustomPlot进行二次开发)

u014613270的博客 3593

QCustomPlot使用之绘制散点图

一、简单概述:QCustomPlot是基于Qt封装的一个图形绘制库、可以绘制散点图、曲线图、柱状图等各种图形,并可以把各种图形导出为png、jpg等各种格式的图片,使用很方便,只有两个文件qcustomplot.h和qcustomplot.cpp,这两个文件直接加到工程中即可。需要说明的是这个库依赖Qt中的Qt5PrintSupport模块,使用时添加上该模块即可。二、下载地址: QCustomP

ISmileLi的博客 1万+

QML使用QCustomPlot笔记

在QML中使用QCustomPlot,QML使用QT的Widget控件,QML使用QWidget控件,QCustomPlot的设置与使用,QCustomPlot设置时间轴

wangshenqiang的博客 2044

Qwt、QChart、QCustomPlot使用

Qwt、QChart、QCustomPlot使用文档 文章目录Qwt、QChart、QCustomPlot使用文档@[toc]效果图比较Qwt1、下载源码2、将Qwt编译成共享库3、添加Qwt4、使用Qwt5、添加帮助文档6、示例QCustomPlot1、下载源码2、使用源码3、将QCustomPlot编译成共享库4、示例QChart1、安装2、示例 效果图 Qwt Qcustomplot QChart 比较 美观方面: Qcustomplot≈Qchart > Qwt Q

mahuifa的博客 1万+

QCustomPlot通过CMake启用OpenGL

讲解QCustomPlot如何通过CMake启用OpenGL

Solititude的博客 1433

Qt:QCustomPlot使用教程

Qt:QCustomPlot使用教程

m0_73443478的博客 2851

qcustomplot使用教程--基本绘图

需要注意的是,QCustomPlot处理的时间/日期坐标系,都是以时间戳0起始坐标点的,,单位是s。目前为止,我们只应用了Graph,因为Graph是我们使用QCustomPlot的主要内容,QCustomPlot为我们使用Graph提供了专门的接口,我们也一直在使用它们,比如。中的字符串,需要符合ISO8601时间格式,除了时间格式之外的其他字符都会原封不动的保留,而时间格式的字符会被正确填充。x、y是大小相等的一组数据,其中x中存储的是横坐标,y中存储的是纵坐标。本例介绍如何绘制时间、日期相关的数。

wanglu22006281的博客 9534

QCustomPlot 使用

包含内容:导入工程;参数设置;graph绘图;curve绘图;设置标题;设置图例;游标;

Renjiankun的博客 1233

QCustomPlot的基本使用

QCustomPlot是QT下一个方便易用的绘图工具,只有两个文件qcustomplot.h和qcustomplot.cpp组成。源文件和使用文档可从官方网站下载。 官方网站:http://www.qcustomplot.com/ 下面介绍下基本使用: 1、将qcustomplot.cpp和qcustomplot.h拷贝到工程目录下,并在工程中添加文件。 并在工程的pro文

shanghaojia_的博客 1万+

dummy机械臂代码学习(六)

CLI-Tool文件夹下又包含四个子文件夹,以及一个gitignore文件、一个run_shell.py的python文件、一个run.bat文件和一个zadig exe文件。库解析命令行参数,并根据不同的命令执行相应的操作。Zadig是一个用于Windows操作系统的开源工具,它的主要功能是安装和配置USB驱动程序。的目的呢就是确保在版本控制过程中,不必要的或自动生成的文件被忽略掉,来保持代码仓库的干净和整洁。,DummyStudio的软件作者已放在GitHub,我们主要看CLI-Tool文件夹就行。

jumaohhh的博客 1432

深入浅出之QCustomPlot

QCustomPlot是一个基于Qt C++的开源绘图库,广泛用于绘制和数据可视化,如制作漂亮的2D图、曲线图、趋势图、坐标图、柱状图等,并为实时可视化应用程序提供高性能服务。

浩瀚之水的专栏 2248

【芯片验证随心记】1.SystemVerilog中,rand和randc的区别?如何用constraint实现randc?

在SystemVerilog里,randc 的“不重复循环”特性是用一个 周期性排列器(permutation engine) 实现的,而这个引擎在 LRM 里并没有公开。我们只能在 “用户空间” 用 rand + constraint 去模仿它的行为。每次随机化只取 queue.pop_front(),用完再洗。在4次随机化内,y会依次出现0,1,2,3各一次(顺序随机)每次随机化,x可能是0-3中的任意值,可能连续多次相同。每次随机化时,在未使用的值里随机挑一个;第5次随机化时,重新生成新的排列周期。

qq_43172512的博客 342

【人工智能】AI算法系统设计与算法建模的详细阐述

AI算法系统设计与算法建模是人工智能领域中的核心任务之一,它涉及从问题定义、数据收集、算法选择、模型构建到系统部署的全过程。以下是对AI算法系统设计与算法建模的详细阐述

weixin_51306394的博客 4355

QCustomPlot开发笔记(一):QCustomPlot简介、下载以及基础绘图

QCustomPlot开发笔记系列整理集合,这是目前使用最为广泛的Qt图表类(Qt的QWidget代码方向只有QtCharts,Qwt,QCustomPlot),使用多年,系统性的整理,过目并整理了原有文档,本系列旨在系统解说并逐步更新其各种Demo示例。

长沙红胖子 Qt・西安|省级科研团队从业背景,深耕双一流体系高精尖技术配套研发|剥离高精尖机理,沉淀高端特种行业领域 Qt 工程化落地经验|博文仅分享通用技术总结,输出公开普适工程思路。 6万+

Mit6.S081-实验1-Xv6 and Unix utilities

Mit6.S081-实验1-Xv6 and Unix utilities前言一、Boot xv61,实验目的2,操作流程1)切换到xv6-labs-2020代码库的lab1分支2)启动xv63)测试xv64)过程分析5)其他操作二、在xv6中添加一个自己编写的程序1,源码准备2,编译配置3,测试添加程序4,过程分析三、xv6中shell简析 前言 一、Boot xv6 1,实验目的 利用qemu启动xv6 2,操作流程 1)切换到xv6-labs-2020代码库的lab1分支 git checkout ut

code a better life~ 36万+

Qt--QCustomPlot

一、基础知识 1、QT绘图有QWT和QCustomPlot,QWT比较麻烦一些,相比来说QCustomPlot简单易用。    二、QCustomPlot介绍 1、QCustomPlot是一个用于绘图和数据可视化的Qt C++构件。 它没有进一步的依赖关系,并有很好的文档记录。 该绘图库专注于制作美观,出版品质的2D图表,图表和图表,以及为实时可视化应用程序提供高性能。 查看“设置”和“基...

天道酬勤 1万+

OpenCV图像拼接实战:用SIFT+透视变换打造无缝全景图(附完整代码)

本文详细介绍了使用OpenCV和SIFT算法实现图像拼接的全过程,包括特征匹配、透视变换和高级融合技术。通过实战代码演示,帮助开发者掌握无缝全景图生成的核心技术,适用于旅行摄影、无人机航拍等多种场景。

eee77的博客 998

告别复杂配置!用GuidosToolbox 3.0做MSPA景观格局分析,从安装到出图全记录

本文详细介绍了如何使用GuidosToolbox 3.0进行MSPA景观格局分析,从安装配置到出图全流程。涵盖环境准备、数据预处理、参数设置、结果解读及可视化技巧,帮助用户快速掌握这一生态安全评估工具。特别针对安装教程中的常见问题提供解决方案,提升分析效率。

weixin_29248313的博客 489

QCustomPlot使用(一)

一,介绍 QCustomPlot是Qt的一个小型第三方图表库,支持静态/动态曲线、柱状图、蜡烛图、频谱图等。使用方便,仅需在项目中加入头文件qcustomplot.h和qcustomplot.cpp源文件即可,或者把它当做一个库来添加到项目当中,需要在pro文件加入 DEFINES += QCUSTOMPLOT_COMPILE_LIBRARY 下载地址:下载链接https://www.qcustomplot.com/index.php/download 二、简单介绍QCustomPlot的几个重要类.

guojunjunjun2006的专栏 1420

红火蚁巢穴AI智能识别,提供方案与思路!

🏆本文收录于 《全栈 Bug 调优(实战版)》 专栏。专栏聚焦真实项目中的各类疑难 Bug,从成因剖析 → 排查路径 → 解决方案 → 预防优化全链路拆解,形成一套可复用、可沉淀的实战知识体系。无论你是初入职场的开发者,还是负责复杂项目的资深工程师,都可以在这里构建一套属于自己的「问题诊断与性能调优」方法论,助你稳步进阶、放大技术价值 。

**My Coding Family** 1042

QcustomPlot的安装和使用

然后在提升类的名称中输入QcustomPlot,然后点击【添加】将QcustomPlot加入到提升类列表中,最后点击【提升】设置坐标轴刻度字体颜色。设置坐标轴标题字体颜色。设置座标售颜色和线宽。设置主刻度颜色及线宽。设置子刻度颜色及线宽。

x_xinghua的博客 675

华为OD机试2025A卷 - BOSS的收入(Java & Python& JS & C++ & C )

华为OD机试2025A卷 - BOSS的收入(Jav一个XX产品行销总公司,只有一个boss,其有若干一级分销,一级分销又有若干二级分销,每个分销只有唯一的上级分销。规定,每个月,下级分销需要将自己的总收入(自己的+下级上交的)每满100元上交15元给自己的上级。现给出一组分销的关系,和每个分销的收入,请找出boss并计算出这个boss的收入。输入:分销关系和收入:[[分销id 上级分销id 收入], [分销id 上级分销id 收入], [分销id 上级分销id 收入]]输出:[boss的ID, 总收入]

算法大师! 1172

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Qt之QCustomPlot

在学完各种dll的调用方式和QAbstractItemModel之后,终于到了这一步,之前用过CustomPlot来实现简单图的绘制,但是这次我需要从头开始,理解内涵 文章目录1 Main Page1.1 QCustomPlot 2.0.1 Documentation1.2 Plottables 绘图板1.3 Controlling the Axes 坐标轴的操控1.4 Plot Legend 绘...

赵树成的博客 6706

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

上一篇: std::unordered_multiset
下一篇: std::stack
无夜_
博客等级 码龄7年 2916粉丝 51原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值