Qt&Vtk-009-Cone4

简介: Qt&Vtk-009-Cone4

image.png

文章目录


Qt&Vtk-Cone4


又双叕来搬运代码了,这次我们还是搬运Cone。先看看官方的效果吧image.png

1 代码搬运


1.1 cone4.h


#ifndef CONE4_H
#define CONE4_H
#include <QWidget>
#include <QTimer>
#include "QVTKOpenGLWidget.h"               //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderWindow.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkRenderer.h"
#include "vtkProperty.h"
namespace Ui {
class Cone4;
}
class Cone4 : public QWidget
{
    Q_OBJECT
public:
    explicit Cone4(QWidget *parent = 0);
    ~Cone4();
private:
    Ui::Cone4 *ui;
    vtkConeSource *cone = nullptr;
    vtkPolyDataMapper *mapper = nullptr;
    vtkActor *actor1 = nullptr,*actor2 = nullptr;
    vtkProperty *property = nullptr;
    vtkRenderer *render = nullptr;
    QTimer *rotateTimer = nullptr;
};
#endif // CONE4_H

1.2 cone4.cpp


#include "cone4.h"
#include "ui_cone4.h"
Cone4::Cone4(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Cone4)
{
    ui->setupUi(this);
    cone = vtkConeSource::New();
    cone->SetRadius(1);
    cone->SetResolution(300);
    cone->SetHeight(4.0);
    mapper = vtkPolyDataMapper::New();
    mapper->SetInputConnection(cone->GetOutputPort());
    actor1 = vtkActor::New();
    actor1->SetMapper(mapper);
    actor1->GetProperty()->SetColor(1.0,0.0,0.0);
    actor1->GetProperty()->SetDiffuse(0.7);     //漫反射
    actor1->GetProperty()->SetSpecular(0.4);    //高光,镜面光
    actor1->GetProperty()->SetSpecularPower(20);//高光强度
    property = vtkProperty::New();
    property->SetColor(0.0,0.0,1.0);
    property->SetDiffuse(0.5);
    property->SetSpecular(0.6);
    property->SetSpecularPower(30);
    actor2 = vtkActor::New();
    actor2->SetMapper(mapper);
    actor2->GetProperty()->SetColor(0.0,1.0,0.0);
    actor2->SetProperty(property);
    actor2->SetPosition(0,2,0);
    render = vtkRenderer::New();
    render->AddActor(actor1);
    render->AddActor(actor2);
    render->SetBackground(0,0,0);
    ui->widget->GetRenderWindow()->AddRenderer(render);
    rotateTimer = new QTimer;
    connect(rotateTimer,&QTimer::timeout,this,[=](){
        render->GetActiveCamera()->Azimuth(1);
        ui->widget->GetRenderWindow()->Render();
    });
    rotateTimer->start(10);
}
Cone4::~Cone4()
{
    rotateTimer->stop();
    delete ui;
}

image.pngimage.pngimage.pngimage.png

目录
相关文章
Qt&Vtk-012-CreateTree
Qt&Vtk-012-CreateTree
159 0
Qt&Vtk-012-CreateTree
|
C++
Qt&Vtk-007-Cone2
Qt&Vtk-007-Cone2
140 0
Qt&Vtk-007-Cone2
Qt&Vtk-025-QChartTable
Qt&Vtk-025-QChartTable
177 0
Qt&Vtk-025-QChartTable
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-019-GPURenderDemo
165 0
Qt&Vtk-019-GPURenderDemo
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-004-AmbientSpheres
228 0
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-008-Cone3
Qt&Vtk-008-Cone3
138 0
Qt&Vtk-008-Cone3
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-016-DiffuseSpheres
135 0
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-010-Cone5
Qt&Vtk-010-Cone5
174 0
Qt&Vtk-010-Cone5
Qt&Vtk-017-EasyView
Qt&Vtk-017-EasyView
199 0
Qt&Vtk-017-EasyView
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT
162 0
Qt&Vtk-018-FixedPointVolumeRayCastMapperCT