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-025-QChartTable
Qt&Vtk-025-QChartTable
171 0
Qt&Vtk-025-QChartTable
Qt&Vtk-011-Cone6
Qt&Vtk-011-Cone6
153 0
Qt&Vtk-011-Cone6
|
C++
Qt&Vtk-007-Cone2
Qt&Vtk-007-Cone2
136 0
Qt&Vtk-007-Cone2
Qt&Vtk-012-CreateTree
Qt&Vtk-012-CreateTree
155 0
Qt&Vtk-012-CreateTree
Qt&Vtk-006-one
Qt&Vtk-006-one
121 0
Qt&Vtk-006-one
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-016-DiffuseSpheres
129 0
Qt&Vtk-016-DiffuseSpheres
Qt&Vtk-015-Cylinder
Qt&Vtk-015-Cylinder
139 0
Qt&Vtk-015-Cylinder
Qt&Vtk-014-CustomLinkView
Qt&Vtk-014-CustomLinkView
143 0
Qt&Vtk-014-CustomLinkView
Qt&Vtk-022-LabeledMesh
Qt&Vtk-022-LabeledMesh
162 0
Qt&Vtk-022-LabeledMesh
Qt&Vtk-004-AmbientSpheres
Qt&Vtk-004-AmbientSpheres
215 0
Qt&Vtk-004-AmbientSpheres