Qt&Vtk-026-QScalarsToColors

Posted DreamLife.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt&Vtk-026-QScalarsToColors相关的知识,希望对你有一定的参考价值。

​ 摘要

1 官方示例展示

​ 今天我们又来搬运代码了,今天搬运的是官方实例QScalarsToColors,下面看向官方实例演示

2 代码搬运

2.1 qscalarstocolors.h

#ifndef QSCALARSTOCOLORS_H
#define QSCALARSTOCOLORS_H

#include <QWidget>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"

#include "QVTKOpenGLWidget.h"
#include "vtkChartXY.h"
#include "vtkColorTransferFunction.h"
#include "vtkCompositeTransferFunctionItem.h"
#include "vtkContextScene.h"
#include "vtkContextView.h"
#include "vtkFloatArray.h"
#include "vtkGenericOpenGLRenderWindow.h"
#include "vtkMath.h"
#include "vtkNew.h"
#include "vtkPiecewiseFunction.h"
#include "vtkPlot.h"
#include "vtkQtTableView.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkTimerLog.h"
#include <QResizeEvent>
namespace Ui {
class QScalarsToColors;
}

class QScalarsToColors : public QWidget
{
    Q_OBJECT

public:
    explicit QScalarsToColors(QWidget *parent = 0);
    ~QScalarsToColors();


    void resizeEvent(QResizeEvent *event)override;

private:
    Ui::QScalarsToColors *ui;

    QVTKOpenGLWidget *qvtkWidget = nullptr;

    vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;

    vtkNew<vtkContextView> view;
};

#endif // QSCALARSTOCOLORS_H

2.2 qscalarstocolors.cpp

#include "qscalarstocolors.h"
#include "ui_qscalarstocolors.h"

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


    qvtkWidget = new QVTKOpenGLWidget(ui->widget);


    qvtkWidget->SetRenderWindow(renderWindow);

    view->SetRenderWindow(qvtkWidget->GetRenderWindow());
    view->SetInteractor(qvtkWidget->GetInteractor());


    vtkNew<vtkChartXY> chart;
    chart->SetTitle("Chart");
    view->GetScene()->AddItem(chart);

    vtkNew<vtkColorTransferFunction> colorTransferFunction;
    colorTransferFunction->AddHSVSegment(0.,0.,1.,1.,0.3333,0.3333,1.,1.);
    colorTransferFunction->AddHSVSegment(0.3333,0.3333,1.,1.,0.6666,0.6666,1.,1.);
    colorTransferFunction->AddHSVSegment(0.6666,0.6666,1.,1.,1.,0.,1.,1.);
    colorTransferFunction->Build();

    vtkNew<vtkPiecewiseFunction> opacityFunction;
    opacityFunction->AddPoint(0.,0.);
    opacityFunction->AddPoint(0.5,0.5);
    opacityFunction->AddPoint(1.,1.);

    vtkNew<vtkCompositeTransferFunctionItem> item3;
    item3->SetColorTransferFunction(colorTransferFunction);
    item3->SetOpacityFunction(opacityFunction);
    item3->SetOpacity(0.2);
    item3->SetMaskAboveCurve(true);
    chart->AddPlot(item3);
}

QScalarsToColors::~QScalarsToColors()
{
    delete ui;
}

void QScalarsToColors::resizeEvent(QResizeEvent *event)
{
    qvtkWidget->resize(ui->widget->size());
}

3 运行效果

★ 源码 ★

源码分享一时爽,一直分享一直爽, 链接如下:

自取:https://github.com/DreamLife-Jianwei/Qt-Vtk


以上是关于Qt&Vtk-026-QScalarsToColors的主要内容,如果未能解决你的问题,请参考以下文章

Qt&Vtk-012-CreateTree

Qt&Vtk-010-Cone5

Qt编程基于Qt的词典开发系列&lt;九&gt;--JSON数据解析

Qt & QWT:QwtPlotCurve - 曲线未显示

002-Qt&Vtk-第一个VtkQt程序

Qt & OpenGL:如何尽可能频繁地渲染?