Qt&Vtk-011-Cone6
Posted DreamLife.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt&Vtk-011-Cone6相关的知识,希望对你有一定的参考价值。
Qt&Vtk-Cone6
今天我们又来搬运代码了,今天还是搞Cone,哈哈哈,已经是第六个Cone,不过这是最后一个了,还有点意思,先看看官方的例子。
1 代码搬运
1.1 cone6.h
#ifndef CONE6_H
#define CONE6_H
#include <QWidget>
#include <QTimer>
#include <QDebug>
#include <QString>
#include <QTextBrowser>
#include "QVTKOpenGLWidget.h" //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkConeSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkCamera.h"
#include "vtkActor.h"
#include "vtkCommand.h"
#include "vtkBoxWidget.h"
#include "vtkTransform.h"
#include "vtkInteractorStyleTrackballCamera.h"
namespace Ui {
class Cone6;
}
class vtkMyCallBack : public vtkCommand
{
public:
static vtkMyCallBack *New()
{
return new vtkMyCallBack;
}
void Execute(vtkObject *caller, unsigned long eventId, void *callData) override;
};
class Cone6 : public QWidget
{
Q_OBJECT
public:
explicit Cone6(QWidget *parent = 0);
~Cone6();
void startInteractor();
private:
Ui::Cone6 *ui;
vtkConeSource *cone = nullptr;
vtkPolyDataMapper *mapper = nullptr;
vtkActor *actor = nullptr;
vtkRenderer *render = nullptr;
vtkRenderWindowInteractor *iren = nullptr;
vtkInteractorStyleTrackballCamera * style = nullptr;
vtkBoxWidget *boxWidget = nullptr;
vtkMyCallBack *callback = nullptr;
};
#endif // CONE6_H
1.2 cone6.cpp
#include "cone6.h"
#include "ui_cone6.h"
Cone6::Cone6(QWidget *parent) :
QWidget(parent),
ui(new Ui::Cone6)
{
ui->setupUi(this);
cone = vtkConeSource::New();
cone->SetRadius(1);
cone->SetResolution(20);
cone->SetHeight(3);
mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(cone->GetOutputPort());
actor = vtkActor::New();
actor->SetMapper(mapper);
render = vtkRenderer::New();
render->AddActor(actor);
render->SetBackground(0,0,1);
ui->widget->GetRenderWindow()->AddRenderer(render);
iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(ui->widget->GetRenderWindow());
style = vtkInteractorStyleTrackballCamera::New();
iren->SetInteractorStyle(style);
boxWidget = vtkBoxWidget::New();
boxWidget->SetInteractor(iren);
boxWidget->SetPlaceFactor(1.25);
boxWidget->SetProp3D(actor);
boxWidget->PlaceWidget();
callback = vtkMyCallBack::New();
boxWidget->AddObserver(vtkCommand::InteractionEvent,callback);
boxWidget->On();
iren->Initialize();
}
Cone6::~Cone6()
{
delete ui;
}
void Cone6::startInteractor()
{
iren->Start();
}
void vtkMyCallBack::Execute(vtkObject *caller, unsigned long eventId, void *callData)
{
vtkTransform *t = vtkTransform::New();
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
widget->GetTransform(t);
widget->GetProp3D()->SetUserTransform(t);
t->Delete();
}
2 运行效果
3 知识点
3.1 vtkBoxWidget
参考:https://blog.csdn.net/minmindianzi/article/details/89403606
https://vtk.org/doc/nightly/html/classvtkBoxWidget.html
这个Cone更新完了,暂时就不用和Cone玩了。
★ 源码 ★
这里就要有人问了呀,这么优秀的代码,能不能分享下呀,当然可以呀,我不生产代码,我只是代码的搬运工,链接如下:
以上是关于Qt&Vtk-011-Cone6的主要内容,如果未能解决你的问题,请参考以下文章
26.Qt Quick QML-RotationAnimationPathAnimationSmoothedAnimationBehaviorPauseAnimationSequential(代码片段
如何在 Javadoc 中使用 @ 和 符号格式化代码片段?