Qt&Vtk-026-QScalarsToColors

简介: Qt&Vtk-026-QScalarsToColors

image.png 摘要


文章目录


1 官方示例展示

2 代码搬运

2.1 qscalarstocolors.h

2.2 qscalarstocolors.cpp

3 运行效果

★ 源码 ★

1 官方示例展示

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

image.png

#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());
}

image.pngimage.png

目录
相关文章
Qt&Vtk-011-Cone6
Qt&Vtk-011-Cone6
153 0
Qt&Vtk-011-Cone6
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-016-DiffuseSpheres
129 0
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-028-SGrid
Qt&Vtk-028-SGrid
158 0
Qt&Vtk-028-SGrid
Qt&Vtk-027-RGrid
Qt&Vtk-027-RGrid
153 0
Qt&Vtk-027-RGrid
Qt&Vtk-012-CreateTree
Qt&Vtk-012-CreateTree
155 0
Qt&Vtk-012-CreateTree
Qt&Vtk-022-LabeledMesh
Qt&Vtk-022-LabeledMesh
162 0
Qt&Vtk-022-LabeledMesh
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-019-GPURenderDemo
160 0
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-004-AmbientSpheres
215 0
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-014-CustomLinkView
Qt&Vtk-014-CustomLinkView
143 0
Qt&Vtk-014-CustomLinkView
Qt&Vtk-009-Cone4
Qt&Vtk-009-Cone4
122 0
Qt&Vtk-009-Cone4