Qt&Vtk-023-MultiView
Posted DreamLife.
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Qt&Vtk-023-MultiView相关的知识,希望对你有一定的参考价值。
今天又来搬运代码了,这周是入职的第三周了,领导给安排的任务,后面要开始搞任务了。今天搬运的代码为官方实例MuliView。
1 官方示例展示
从运行界面来看,和我们之前搬运的CreateTree没有啥区别呀。官方的描述也很简单呀,设个描述是不是很迷呀。
2 代码搬运
2.1 multiview.h
#ifndef MULTIVIEW_H
#define MULTIVIEW_H
#include <QWidget>
#include "QVTKOpenGLWidget.h" //新版本,旧版QVTKWidget
#include "vtkAutoInit.h"
#include "vtkAnnotationLink.h"
#include "vtkCommand.h"
#include "vtkDataRepresentation.h"
#include "vtkDataSetAttributes.h"
#include "vtkGraphLayoutView.h"
#include "vtkMutableDirectedGraph.h"
#include "vtkRandomGraphSource.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkStringArray.h"
#include "vtkTree.h"
#include "vtkViewTheme.h"
#include "vector"
class ViewUpdater :public vtkCommand
{
public:
static ViewUpdater* New()
{
return new ViewUpdater;
}
void AddView(vtkView *view)
{
this->Views.push_back(view);
view->AddObserver(vtkCommand::SelectionChangedEvent,this);
}
void Execute(vtkObject*,unsigned long,void*)override
{
for(unsigned int i = 0;i<this->Views.size();i++)
{
this->Views[i]->Update();
}
}
private:
ViewUpdater() = default;
~ViewUpdater() override = default;
std::vector<vtkView*> Views;
};
namespace Ui {
class MultiView;
}
class MultiView : public QWidget
{
Q_OBJECT
public:
explicit MultiView(QWidget *parent = 0);
~MultiView();
private:
Ui::MultiView *ui;
vtkMutableDirectedGraph *graph = nullptr;
vtkStringArray* labels = nullptr;
vtkTree* tree = nullptr;
vtkGraphLayoutView* view = nullptr;
vtkGraphLayoutView* view2 = nullptr;
vtkAnnotationLink* link = nullptr;
ViewUpdater* update = nullptr;
};
#endif // MULTIVIEW_H
2.2 multiview.cpp
#include "multiview.h"
#include "ui_multiview.h"
MultiView::MultiView(QWidget *parent) :
QWidget(parent),
ui(new Ui::MultiView)
{
ui->setupUi(this);
graph = vtkMutableDirectedGraph::New();
vtkIdType a = graph->AddVertex();
vtkIdType b = graph->AddChild(a);
vtkIdType c = graph->AddChild(a);
vtkIdType d = graph->AddChild(b);
vtkIdType e = graph->AddChild(c);
vtkIdType f = graph->AddChild(c);
labels = vtkStringArray::New();
labels->SetName("Label");
labels->InsertValue(a, "a");
labels->InsertValue(b, "b");
labels->InsertValue(c, "c");
labels->InsertValue(d, "d");
labels->InsertValue(e, "e");
labels->InsertValue(f, "f");
graph->GetVertexData()->AddArray(labels);
tree = vtkTree::New();
bool validTree = tree->CheckedShallowCopy(graph);
if (!validTree)
{
std::cout << "ERROR: Invalid tree" << std::endl;
graph->Delete();
labels->Delete();
tree->Delete();
}
view = vtkGraphLayoutView::New();
view->SetRenderWindow(ui->widget->GetRenderWindow());
vtkDataRepresentation* rep =view->SetRepresentationFromInput(tree);
vtkViewTheme* theme = vtkViewTheme::CreateMellowTheme();
view->ApplyViewTheme(theme);
view->SetVertexColorArrayName("VertexDegree");
view->SetColorVertices(true);
view->SetVertexLabelArrayName("Label");
view->SetVertexLabelVisibility(true);
view2 = vtkGraphLayoutView::New();
vtkDataRepresentation* rep2 =view2->SetRepresentationFromInput(tree);
view2->SetVertexLabelArrayName("Label");
view2->SetVertexLabelVisibility(true);
link = vtkAnnotationLink::New();
rep->SetAnnotationLink(link);
rep2->SetAnnotationLink(link);
update = ViewUpdater::New();
update->AddView(view);
update->AddView(view2);
}
MultiView::~MultiView()
{
delete ui;
}
3 运行效果
这个是我的运行效果了,但是呢不知道为什么这些代码跑到Qt里面,点就成了圆点了。
★ 源码 ★
源码分享一时爽,一直分享一直爽, 链接如下:
以上是关于Qt&Vtk-023-MultiView的主要内容,如果未能解决你的问题,请参考以下文章
Leetcode: LFU Cache && Summary of various Sets: HashSet, TreeSet, LinkedHashSet(示例代
JUC并发编程 -- 共享代来的问题(操作统一资源) & 临界区 Critical Section & 竞态条件 Race Condition
POJ 3177--Redundant Paths无向图添加最少的边成为边双连通图 && tarjan求ebc && 缩点构造缩点树(代
佩特来项目经验小集合___组合查询存储过程,报错 "varchar JBID='' 转换成数据类型 int 时失败"(示例代(代码
2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!字符串,贪心+排序(示例代码(代