Windows Qt C++ VTK 绘制三维曲线

Qt 自带数据可视化从文档上看,只能实现三维曲面。

QwtPlot3D在Qt6.6.0上没编译通过。

QCustomPlot 只能搞二维。

VTK~搞起。抄官网demo。

后续需求:

1、对数轴

2、Y轴逆序

3、Z轴值给色带,类似等高线图的色带

期待各位大佬多多指导。

cpp 复制代码
 vtkNew<vtkNamedColors> colors;

    // Create the data.
    vtkNew<vtkTable> table;
    vtkNew<vtkTable> table1;

    vtkNew<vtkFloatArray> arrX0;
    arrX0->SetName("X");
    table->AddColumn(arrX0);

    vtkNew<vtkFloatArray> arrX1;
    arrX1->SetName("Y");
    table->AddColumn(arrX1);

    vtkNew<vtkFloatArray> arrX2;
    arrX2->SetName("Z");
    table->AddColumn(arrX2);

    vtkNew<vtkFloatArray> arrX3;
    arrX3->SetName("-Z");
    table->AddColumn(arrX3);

    vtkNew<vtkFloatArray> arrX4;
    arrX4->SetName("-Y");
    table->AddColumn(arrX4);

    const unsigned int numberOfTimePoints = 128;

    table->SetNumberOfRows(numberOfTimePoints);

    for (unsigned int ii = 0; ii < numberOfTimePoints; ++ii)
    {
        double value = ii;
        double value1 = rand() % 100;

        table->SetValue(ii, 0, ii);
        table->SetValue(ii, 1, ii);
        table->SetValue(ii, 2, sin(value));
        table->SetValue(ii, 3, sin(value) + 10);
        table->SetValue(ii, 4, sin(value) + 20);
    }

    // Set up a 3D scene and add an XYZ chart to it.
    vtkNew<vtkContextView> contextView;
    contextView->GetRenderWindow()->SetSize(1024, 1024);
    contextView->GetRenderWindow()->SetWindowName("PlotLine3D");

    vtkNew<vtkChartXYZ> chartXYZ;
    chartXYZ->SetGeometry(vtkRectf(5.0, 5.0, 635.0, 475.0));
    contextView->GetScene()->AddItem(chartXYZ);


    // Add a line plot.
    vtkNew<vtkPlotLine3D> plotLine3D;
    plotLine3D->SetInputData(table, 0, 1, 2);

    contextView->GetRenderWindow()->SetMultiSamples(0);

    plotLine3D->GetPen()->SetWidth(1.0);

    chartXYZ->AddPlot(plotLine3D);


    // Add a line plot.
    vtkNew<vtkPlotLine3D> plotLine3D1;
    plotLine3D1->SetInputData(table, 0, 1, 3);

    plotLine3D1->GetPen()->SetWidth(2.0);

    chartXYZ->AddPlot(plotLine3D1);


    // Add a line plot.
    vtkNew<vtkPlotLine3D> plotLine3D2;
    plotLine3D2->SetInputData(table, 0, 1, 4);

    plotLine3D2->GetPen()->SetWidth(3.0);

    chartXYZ->AddPlot(plotLine3D2);


    chartXYZ->SetXAxisLabel("振幅");
    chartXYZ->SetVisible(true);

    // Finally render the scene.
    contextView->GetRenderer()->SetBackground(colors->GetColor3d("DarkOliveGreen").GetData());
    contextView->GetRenderWindow()->Render();
    contextView->GetInteractor()->Initialize();
    contextView->GetInteractor()->Start();
相关推荐
wbs_scy4 分钟前
C++:unordered_map/unordered_set 使用指南(差异、性能与场景选择)
开发语言·c++·哈希算法
余衫马8 分钟前
突破语言边界:Python 与 C/C++ 集成方案年度深度总结
c++·python·性能优化·年度技术总结
小此方17 分钟前
Re: ゼロから学ぶ C++ 入門(八)类和对象·第五篇:時間计算器
开发语言·c++
无限进步_18 分钟前
C++ Vector 全解析:从使用到深入理解
开发语言·c++·ide·windows·git·github·visual studio
Dream it possible!21 分钟前
LeetCode 面试经典 150_分治_将有序数组转换为二叉搜索树(105_108_C++_简单)(递归)
c++·leetcode·面试
Q741_14721 分钟前
C++ 栈 模拟 力扣 227. 基本计算器 II 题解 每日一题
c++·算法·leetcode·模拟
徐新帅24 分钟前
CSP 二进制与小数进制转换专题及答案解析
c++·算法
im_AMBER30 分钟前
Leetcode 88 K 和数对的最大数目
数据结构·c++·笔记·学习·算法·leetcode
兵哥工控31 分钟前
MFC分组平均法数据平滑曲线实例
c++·mfc
wangnaisheng1 小时前
Intel IPP 图像处理相关函数
c++·c#·图像