Qt&Vtk-024-PiecewiseItem

简介: Qt&Vtk-024-PiecewiseItem

image.png 摘要

文章目录


1 官方示例展示


今天搬运的代码是官方实例PiecewiseItem,先看先官方代码跑起来的样子。image.png

2 代码搬运


2.1 piecewiseitem.h


#ifndef PIECEWISEITEM_H
#define PIECEWISEITEM_H
#include <QWidget>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkSmartPointer.h"
#include "vtkContextView.h"
#include "vtkContextScene.h"
#include "vtkPiecewiseFunction.h"
#include "vtkPiecewiseFunctionItem.h"
#include "vtkPiecewiseControlPointsItem.h"
namespace Ui {
class PiecewiseItem;
}
class PiecewiseItem : public QWidget
{
    Q_OBJECT
public:
    explicit PiecewiseItem(QWidget *parent = 0);
    ~PiecewiseItem();
private:
    Ui::PiecewiseItem *ui;
    vtkSmartPointer<vtkContextView> view = nullptr;
    vtkSmartPointer<vtkPiecewiseFunction> source = nullptr;
    vtkSmartPointer<vtkPiecewiseControlPointsItem> item = nullptr;
};
#endif // PIECEWISEITEM_H

2.2 piecewiseitem.cpp


#include "piecewiseitem.h"
#include "ui_piecewiseitem.h"
PiecewiseItem::PiecewiseItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::PiecewiseItem)
{
    ui->setupUi(this);
    view = vtkSmartPointer<vtkContextView>::New();
    view->SetRenderWindow(ui->widget->GetRenderWindow());
    view->GetRenderer()->SetBackground(0,0,1);
    source = vtkSmartPointer<vtkPiecewiseFunction>::New();
    source->AddPoint(0,0);
    source->AddPoint(200,200);
    source->AddPoint(400,600);
    source->AddPoint(700,500);
    item = vtkSmartPointer<vtkPiecewiseControlPointsItem>::New();
    item->SetPiecewiseFunction(source);
    view->GetScene()->AddItem(item);
}
PiecewiseItem::~PiecewiseItem()
{
    delete ui;
}

image.pngimage.png

目录
相关文章
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
160 0
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
Qt&Vtk-022-LabeledMesh
Qt&Vtk-022-LabeledMesh
165 0
Qt&Vtk-022-LabeledMesh
Qt&Vtk-027-RGrid
Qt&Vtk-027-RGrid
158 0
Qt&Vtk-027-RGrid
Qt&Vtk-011-Cone6
Qt&Vtk-011-Cone6
160 0
Qt&Vtk-011-Cone6
Qt&Vtk-028-SGrid
Qt&Vtk-028-SGrid
164 0
Qt&Vtk-028-SGrid
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-016-DiffuseSpheres
132 0
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-012-CreateTree
Qt&Vtk-012-CreateTree
157 0
Qt&Vtk-012-CreateTree
Qt&Vtk-010-Cone5
Qt&Vtk-010-Cone5
173 0
Qt&Vtk-010-Cone5
Qt&Vtk-025-QChartTable
Qt&Vtk-025-QChartTable
176 0
Qt&Vtk-025-QChartTable
Qt&Vtk-017-EasyView
Qt&Vtk-017-EasyView
198 0
Qt&Vtk-017-EasyView