QtVtk-014-CustomLinkView

2024-02-01 07:59
文章标签 014 qtvtk customlinkview

本文主要是介绍QtVtk-014-CustomLinkView,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

头图

​ 这个Demo已经拖了好久好久了,今天整理文章的时候,发现躲不过了呀,前面的几篇都发出了。

文章目录

  • 1 官方示例展示
  • 2 官方源码
    • 2.1CustomLinkView.h
    • 2.2 CustomLinkView.cpp
  • ★ 源码 ★

1 官方示例展示

​ 啊呀,今天终于更新到这里了,一直拖延症到现在,还是没有弄明白这个项目是干啥的。仅仅展示官方代码,在项目中建了对应的文件。不要给我寄刀片哈。

在这里插入图片描述

​ 点击打开按钮,显示让我打开一个XML文档,实在搞不懂这个项目是干啥的。

在这里插入图片描述

2 官方源码

2.1CustomLinkView.h

#ifndef CustomLinkView_H
#define CustomLinkView_H#include "vtkSmartPointer.h"    // Required for smart pointer internal ivars.#include <QMainWindow>// Forward Qt class declarations
class Ui_CustomLinkView;// Forward VTK class declarations
class vtkCommand;
class vtkEventQtSlotConnect;
class vtkGraphLayoutView;
class vtkObject;
class vtkQtTableView;
class vtkQtTreeView;
class vtkXMLTreeReader;class CustomLinkView : public QMainWindow
{Q_OBJECTpublic:// Constructor/DestructorCustomLinkView();~CustomLinkView() override;public slots:virtual void slotOpenXMLFile();virtual void slotExit();protected:protected slots:public slots:// Qt signal (produced by vtkEventQtSlotConnect) will be connected to// this slot.// Full signature of the slot could be:// MySlot(vtkObject* caller, unsigned long vtk_event,//         void* clientData, void* callData, vtkCommand*)void selectionChanged(vtkObject*, unsigned long, void*, void* callData);private:// Methodsvoid SetupCustomLink();// MembersvtkSmartPointer<vtkXMLTreeReader>       XMLReader;vtkSmartPointer<vtkGraphLayoutView>     GraphView;vtkSmartPointer<vtkQtTreeView>          TreeView;vtkSmartPointer<vtkQtTableView>         TableView;vtkSmartPointer<vtkQtTreeView>          ColumnView;// This class converts a vtkEvent to QT signal.vtkSmartPointer<vtkEventQtSlotConnect>  Connections;// Designer formUi_CustomLinkView *ui;
};#endif // CustomLinkView_H

2.2 CustomLinkView.cpp

#include "ui_CustomLinkView.h"
#include "CustomLinkView.h"#include <vtkAnnotationLink.h>
#include <vtkCommand.h>
#include <vtkDataObjectToTable.h>
#include <vtkDataRepresentation.h>
#include <vtkEventQtSlotConnect.h>
#include "vtkGenericOpenGLRenderWindow.h"
#include <vtkGraphLayoutView.h>
#include <vtkQtTableView.h>
#include <vtkQtTreeView.h>
#include <vtkRenderer.h>
#include <vtkSelection.h>
#include <vtkSelectionNode.h>
#include <vtkTable.h>
#include <vtkTableToGraph.h>
#include <vtkTreeLayoutStrategy.h>
#include <vtkViewTheme.h>
#include <vtkViewUpdater.h>
#include <vtkXMLTreeReader.h>#include <QDir>
#include <QFileDialog>
#include <QTreeView>#include "vtkSmartPointer.h"
#define VTK_CREATE(type, name) \vtkSmartPointer<type> name = vtkSmartPointer<type>::New()// Constructor
CustomLinkView::CustomLinkView()
{this->ui = new Ui_CustomLinkView;this->ui->setupUi(this);vtkNew<vtkGenericOpenGLRenderWindow> renderWindow;this->ui->vtkGraphViewWidget->SetRenderWindow(renderWindow);this->XMLReader    = vtkSmartPointer<vtkXMLTreeReader>::New();this->GraphView    = vtkSmartPointer<vtkGraphLayoutView>::New();this->TreeView     = vtkSmartPointer<vtkQtTreeView>::New();this->TableView    = vtkSmartPointer<vtkQtTableView>::New();this->ColumnView   = vtkSmartPointer<vtkQtTreeView>::New();this->ColumnView->SetUseColumnView(1);// Tell the table view to sort selections that it receives (but does// not initiate) to the topthis->TableView->SetSortSelectionToTop(true);// Set widgets for the tree and table viewsthis->ui->treeFrame->layout()->addWidget(this->TreeView->GetWidget());this->ui->tableFrame->layout()->addWidget(this->TableView->GetWidget());this->ui->columnFrame->layout()->addWidget(this->ColumnView->GetWidget());// Graph View needs to get my render windowthis->GraphView->SetInteractor(this->ui->vtkGraphViewWidget->GetInteractor());this->GraphView->SetRenderWindow(this->ui->vtkGraphViewWidget->GetRenderWindow());// Set up the theme on the graph view :)vtkViewTheme* theme = vtkViewTheme::CreateNeonTheme();this->GraphView->ApplyViewTheme(theme);theme->Delete();// Set up action signals and slotsconnect(this->ui->actionOpenXMLFile, SIGNAL(triggered()), this,SLOT(slotOpenXMLFile()));connect(this->ui->actionExit, SIGNAL(triggered()), this,SLOT(slotExit()));// Apply application stylesheetQString css ="* { font: bold italic 18px \"Calibri\"; color: midnightblue }";css +="QTreeView { font: bold italic 16px \"Calibri\"; color: midnightblue }";//qApp->setStyleSheet(css); // Seems to cause a bug on some systems// But at least it's here as an examplethis->GraphView->Render();
};// Set up the annotation between the vtk and qt views
void CustomLinkView::SetupCustomLink()
{this->TreeView->GetRepresentation()->SetSelectionType(vtkSelectionNode::PEDIGREEIDS);this->TableView->GetRepresentation()->SetSelectionType(vtkSelectionNode::PEDIGREEIDS);this->ColumnView->GetRepresentation()->SetSelectionType(vtkSelectionNode::PEDIGREEIDS);this->GraphView->GetRepresentation()->SetSelectionType(vtkSelectionNode::PEDIGREEIDS);// Set up the theme on the graph view :)vtkViewTheme* theme = vtkViewTheme::CreateNeonTheme();this->GraphView->ApplyViewTheme(theme);this->GraphView->Update();theme->Delete();// Create vtkEventQtSlotConnect and make the connections.Connections = vtkEventQtSlotConnect::New();// Make the connection here.// Requires vtkObject which generates the event of type// vtkCommand::SelectionChangedEvent, pointer to object// which has the given slot. vtkEvent of type SelectionChangedEvent// from reach representation should invoke selectionChanged.Connections->Connect(this->GraphView->GetRepresentation(),vtkCommand::SelectionChangedEvent,this,SLOT(selectionChanged(vtkObject*, unsigned long, void*, void*)));Connections->Connect(this->TreeView->GetRepresentation(),vtkCommand::SelectionChangedEvent,this,SLOT(selectionChanged(vtkObject*, unsigned long, void*, void*)));Connections->Connect(this->TableView->GetRepresentation(),vtkCommand::SelectionChangedEvent,this,SLOT(selectionChanged(vtkObject*, unsigned long, void*, void*)));Connections->Connect(this->ColumnView->GetRepresentation(),vtkCommand::SelectionChangedEvent,this,SLOT(selectionChanged(vtkObject*, unsigned long, void*, void*)));}CustomLinkView::~CustomLinkView()
{}// Action to be taken upon graph file open
void CustomLinkView::slotOpenXMLFile()
{// Browse for and open the fileQDir dir;// Open the text data fileQString fileName = QFileDialog::getOpenFileName(this,"Select the text data file",QDir::homePath(),"XML Files (*.xml);;All Files (*.*)");if (fileName.isNull()){cerr << "Could not open file" << endl;return;}// Create XML readerthis->XMLReader->SetFileName( fileName.toLatin1() );this->XMLReader->ReadTagNameOff();this->XMLReader->Update();// Set up some hard coded parameters for the graph viewthis->GraphView->SetVertexLabelArrayName("id");this->GraphView->VertexLabelVisibilityOn();this->GraphView->SetVertexColorArrayName("VertexDegree");this->GraphView->ColorVerticesOn();this->GraphView->SetEdgeColorArrayName("edge id");this->GraphView->ColorEdgesOn();// Create a tree layout strategyVTK_CREATE(vtkTreeLayoutStrategy, treeStrat);treeStrat->RadialOn();treeStrat->SetAngle(360);treeStrat->SetLogSpacingValue(1);this->GraphView->SetLayoutStrategy(treeStrat);// Set the input to the graph viewthis->GraphView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort());// Okay now do an explicit reset camera so that// the user doesn't have to move the mouse// in the window to see the resulting graphthis->GraphView->ResetCamera();// Now hand off tree to the tree viewthis->TreeView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort());this->ColumnView->SetRepresentationFromInputConnection(this->XMLReader->GetOutputPort());// Extract a table and give to table viewVTK_CREATE(vtkDataObjectToTable, toTable);toTable->SetInputConnection(this->XMLReader->GetOutputPort());toTable->SetFieldType(vtkDataObjectToTable::VERTEX_DATA);this->TableView->SetRepresentationFromInputConnection(toTable->GetOutputPort());this->SetupCustomLink();// Hide an unwanted column in the tree view.this->TreeView->HideColumn(2);// Turn on some colors.this->TreeView->SetColorArrayName("vertex id");this->TreeView->ColorByArrayOn();// Update all the viewsthis->TreeView->Update();this->TableView->Update();this->ColumnView->Update();// Force a render on the graph viewthis->GraphView->Render();
}void CustomLinkView::slotExit()
{qApp->exit();
}// This defines the QT slot. They way it works is first get the vtkSelection,
// push it to the default vtkAnnotationLink associated with each
// vtkDataRepresentation of each view type and then call Update or
// Render (if it is a vtkRenderView) on each view.
void CustomLinkView::selectionChanged(vtkObject*,unsigned long,void* vtkNotUsed(clientData),void* callData)
{vtkSelection* selection = reinterpret_cast<vtkSelection*>(callData);if(selection){this->GraphView->GetRepresentation()->GetAnnotationLink()->SetCurrentSelection(selection);this->TreeView->GetRepresentation()->GetAnnotationLink()->SetCurrentSelection(selection);this->TableView->GetRepresentation()->GetAnnotationLink()->SetCurrentSelection(selection);this->ColumnView->GetRepresentation()->GetAnnotationLink()->SetCurrentSelection(selection);this->TreeView->Update();this->TableView->Update();this->ColumnView->Update();this->GraphView->Render();}
}

★ 源码 ★

源码分享一时爽,一直分享一直爽, 链接如下:

自取:https://github.com/DreamLife-Jianwei/Qt-Vtk

在这里插入图片描述


博客签名2021

这篇关于QtVtk-014-CustomLinkView的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/666602

相关文章

014.Python爬虫系列_解析练习

我 的 个 人 主 页:👉👉 失心疯的个人主页 👈👈 入 门 教 程 推 荐 :👉👉 Python零基础入门教程合集 👈👈 虚 拟 环 境 搭 建 :👉👉 Python项目虚拟环境(超详细讲解) 👈👈 PyQt5 系 列 教 程:👉👉 Python GUI(PyQt5)文章合集 👈👈 Oracle数据库教程:👉👉 Oracle数据库文章合集 👈👈 优

【安当产品应用案例100集】014-使用安当TDE实现达梦数据库实例文件的透明加密存储

随着数据安全重要性的不断提升,数据库文件的落盘加密已成为数据保护的一项基本要求。达梦数据库作为一款高性能的国产数据库管理系统,为用户提供了一种高效、安全的数据存储解决方案。本文将详细介绍如何利用安当KSP密钥管理平台及TDE透明加密组件来实现达梦数据库文件的透明加密,从而进一步提高数据的安全性。 一、安当产品简介 1. KSP密钥管理平台 KSP作为数据保护系统的核心模块,提供密钥全生命

算法学习014 0-1背包问题 c++动态规划算法实现 中小学算法思维学习 信奥算法解析

目录 C++0-1背包 一、题目要求 1、编程实现 2、输入输出 二、算法分析 三、程序编写 四、运行结果 五、考点分析 六、推荐资料 C++0-1背包 一、题目要求 1、编程实现 有 N 件物品和一个容量为 M的背包,每件物品有各自的价值且只能被选择一次,要求在有限的背包容量下,装入的物品总价值最大。 2、输入输出 输入描述:第一行输入两个整数,分别表示

014.修改chromium源码-修改webGL指纹(二)

修改chromium源码-修改webGL指纹(二) 一、webGL指纹是什么 之前介绍过webGL指纹和常见网站绕过webGL指纹,插眼传送 二、为啥有的webGL指纹-二期 上期我们通过修改gl的参数,getSupportedExtensions()函数返回值列表的顺序,绕过部分网站的指纹检测。但还有些网站通过webGL生成图形来获取指纹,我们就需要再出一期了。还有就是:上期指纹检测未通

014基于SSM+Jsp的网络视频播放器

开发语言:Java框架:ssm技术:JSPJDK版本:JDK1.8服务器:tomcat7数据库:mysql 5.7(一定要5.7版本)数据库工具:Navicat11开发软件:eclipse/myeclipse/ideaMaven包:Maven3.3.9 系统展示 前台首页 用户登录 视频信息 系统公告 管理员登录 用户管理 视频信息管理 系统公告管理

[deeplearning-014] 深度学习的模型结构历史

[0] 参考文献 http://www.cnblogs.com/skyfsm/p/8451834.html https://www.cnblogs.com/52machinelearning/p/5821591.html [1]Q:什么是深度学习?  A:隐层数量多的神经网络,隐层从5~1000不等。 [2]Q:深度学习的网络模型有哪些种类? A:图像处理的卷积神经网络CNN; 自然语言处理的

[rust-014]关于形如T的borrowing借用

参考文献:https://doc.rust-lang.org/rust-by-example/scope/borrow.html borrow,借用,借用不改变ownership,不会产生ownership的move。所以可以多次借用。 T是值,&T是reference引用。赋值使用引用,或者函数调用传参为引用,即形成“借用”。 借用,总是处于一个scope。只要这个scope没有运行结束,

【面试题-014】Mysql数据库有哪些索引类型?

文章目录 B 树和 B+ 树区别B 树B+ 树 mysql聚簇索引和非聚簇索引聚簇索引(Clustered Index)非聚簇索引(Non-Clustered Index)总结 MyISAM和InnoDB两种常见的存储引擎区别MySQL的主从同步原理如何确保主从同步的数据一致性? 在数据库中,索引的类型取决于数据库管理系统(DBMS)的实现,但大多数数据库系统都支持以下几种基本类

Debug-014-nginx代理路径的一条规则

直接上图: 今天看禹神的前端视频,讲到在nginx中代理路径的时候,有一个规则: 如果/dev和下面的proxy_pass路径最后都带‘/’,那么就是匹配到dev之后要删除dev,然后再带着后面的路径;如果/dev和下面的proxy_pass路径最后都不带‘/’,那么就是匹配到dev之后不会删除dev字段。因为我们项目也需要走nginx配置,就比较感兴趣 而我也看到有一篇文章才知道准确来讲

3D 生成重建014-Bidiff使用二维和三维先验的双向扩散

3D 生成重建014-Bidiff使用二维和三维先验的双向扩散 文章目录 0 论文工作1 论文方法2 效果 0 论文工作 大多数三维生成研究集中在将二维基础模型向上投影到三维空间中,要么通过最小化二维评分蒸馏采样(SDS)损失,要么通过对多视图数据集进行微调。由于缺乏显式的三维先验,这些方法经常导致几何异常和多视图不一致。近来研究人员试图通过直接在三维数据集上