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-020-GraphItem
Qt&Vtk-020-GraphItem
181 0
Qt&Vtk-020-GraphItem
Qt&Vtk-025-QChartTable
Qt&Vtk-025-QChartTable
174 0
Qt&Vtk-025-QChartTable
Qt&Vtk-010-Cone5
Qt&Vtk-010-Cone5
169 0
Qt&Vtk-010-Cone5
Qt&Vtk-027-RGrid
Qt&Vtk-027-RGrid
153 0
Qt&Vtk-027-RGrid
|
C++
Qt&Vtk-007-Cone2
Qt&Vtk-007-Cone2
136 0
Qt&Vtk-007-Cone2
Qt&Vtk-026-QScalarsToColors
Qt&Vtk-026-QScalarsToColors
214 0
Qt&Vtk-026-QScalarsToColors
Qt&Vtk-014-CustomLinkView
Qt&Vtk-014-CustomLinkView
144 0
Qt&Vtk-014-CustomLinkView
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-004-AmbientSpheres
216 0
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-028-SGrid
Qt&Vtk-028-SGrid
159 0
Qt&Vtk-028-SGrid
Qt&Vtk-012-CreateTree
Qt&Vtk-012-CreateTree
155 0
Qt&Vtk-012-CreateTree