Qt&Vtk-014-CustomLinkView

      網(wǎng)友投稿 763 2025-04-04

      這個(gè)Demo已經(jīng)拖了好久好久了,今天整理文章的時(shí)候,發(fā)現(xiàn)躲不過(guò)了呀,前面的幾篇都發(fā)出了。

      文章目錄

      1 官方示例展示

      2 官方源碼

      2.1CustomLinkView.h

      2.2 CustomLinkView.cpp

      ★ 源碼 ★

      1 官方示例展示

      啊呀,今天終于更新到這里了,一直拖延癥到現(xiàn)在,還是沒(méi)有弄明白這個(gè)項(xiàng)目是干啥的。僅僅展示官方代碼,在項(xiàng)目中建了對(duì)應(yīng)的文件。不要給我寄刀片哈。

      點(diǎn)擊打開(kāi)按鈕,顯示讓我打開(kāi)一個(gè)XML文檔,實(shí)在搞不懂這個(gè)項(xiàng)目是干啥的。

      2 官方源碼

      2.1CustomLinkView.h

      #ifndef CustomLinkView_H #define CustomLinkView_H #include "vtkSmartPointer.h" // Required for smart pointer internal ivars. #include // 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_OBJECT public: // Constructor/Destructor CustomLinkView(); ~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: // Methods void SetupCustomLink(); // Members vtkSmartPointer XMLReader; vtkSmartPointer GraphView; vtkSmartPointer TreeView; vtkSmartPointer TableView; vtkSmartPointer ColumnView; // This class converts a vtkEvent to QT signal. vtkSmartPointer Connections; // Designer form Ui_CustomLinkView *ui; }; #endif // CustomLinkView_H

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      44

      45

      46

      47

      48

      49

      50

      51

      52

      53

      54

      55

      56

      57

      58

      59

      60

      61

      62

      63

      64

      65

      66

      67

      2.2 CustomLinkView.cpp

      #include "ui_CustomLinkView.h" #include "CustomLinkView.h" #include #include #include #include #include #include "vtkGenericOpenGLRenderWindow.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "vtkSmartPointer.h" #define VTK_CREATE(type, name) \ vtkSmartPointer name = vtkSmartPointer::New() // Constructor CustomLinkView::CustomLinkView() { this->ui = new Ui_CustomLinkView; this->ui->setupUi(this); vtkNew renderWindow; this->ui->vtkGraphViewWidget->SetRenderWindow(renderWindow); this->XMLReader = vtkSmartPointer::New(); this->GraphView = vtkSmartPointer::New(); this->TreeView = vtkSmartPointer::New(); this->TableView = vtkSmartPointer::New(); this->ColumnView = vtkSmartPointer::New(); this->ColumnView->SetUseColumnView(1); // Tell the table view to sort selections that it receives (but does // not initiate) to the top this->TableView->SetSortSelectionToTop(true); // Set widgets for the tree and table views this->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 window this->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 slots connect(this->ui->actionOpenXMLFile, SIGNAL(triggered()), this, SLOT(slotOpenXMLFile())); connect(this->ui->actionExit, SIGNAL(triggered()), this, SLOT(slotExit())); // Apply application stylesheet QString 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 example this->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 file QDir dir; // Open the text data file QString 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 reader this->XMLReader->SetFileName( fileName.toLatin1() ); this->XMLReader->ReadTagNameOff(); this->XMLReader->Update(); // Set up some hard coded parameters for the graph view this->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 strategy VTK_CREATE(vtkTreeLayoutStrategy, treeStrat); treeStrat->RadialOn(); treeStrat->SetAngle(360); treeStrat->SetLogSpacingValue(1); this->GraphView->SetLayoutStrategy(treeStrat); // Set the input to the graph view this->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 graph this->GraphView->ResetCamera(); // Now hand off tree to the tree view this->TreeView->SetRepresentationFromInputConnection( this->XMLReader->GetOutputPort()); this->ColumnView->SetRepresentationFromInputConnection( this->XMLReader->GetOutputPort()); // Extract a table and give to table view VTK_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 views this->TreeView->Update(); this->TableView->Update(); this->ColumnView->Update(); // Force a render on the graph view this->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(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(); } }

      1

      2

      3

      4

      5

      6

      7

      8

      9

      10

      11

      12

      13

      14

      15

      16

      17

      18

      19

      20

      21

      22

      23

      24

      25

      26

      27

      28

      29

      30

      31

      32

      33

      34

      35

      36

      37

      38

      39

      40

      41

      42

      43

      44

      45

      46

      47

      48

      Qt&amp;Vtk-014-CustomLinkView

      49

      50

      51

      52

      53

      54

      55

      56

      57

      58

      59

      60

      61

      62

      63

      64

      65

      66

      67

      68

      69

      70

      71

      72

      73

      74

      75

      76

      77

      78

      79

      80

      81

      82

      83

      84

      85

      86

      87

      88

      89

      90

      91

      92

      93

      94

      95

      96

      97

      98

      99

      100

      101

      102

      103

      104

      105

      106

      107

      108

      109

      110

      111

      112

      113

      114

      115

      116

      117

      118

      119

      120

      121

      122

      123

      124

      125

      126

      127

      128

      129

      130

      131

      132

      133

      134

      135

      136

      137

      138

      139

      140

      141

      142

      143

      144

      145

      146

      147

      148

      149

      150

      151

      152

      153

      154

      155

      156

      157

      158

      159

      160

      161

      162

      163

      164

      165

      166

      167

      168

      169

      170

      171

      172

      173

      174

      175

      176

      177

      178

      179

      180

      181

      182

      183

      184

      185

      186

      187

      188

      189

      190

      191

      192

      193

      194

      195

      196

      197

      198

      199

      200

      201

      202

      203

      204

      205

      206

      207

      208

      209

      210

      211

      212

      213

      214

      215

      216

      217

      218

      219

      220

      221

      222

      223

      224

      225

      226

      227

      228

      229

      230

      231

      232

      233

      234

      235

      236

      237

      238

      239

      240

      241

      242

      243

      244

      245

      246

      247

      248

      249

      250

      251

      252

      253

      254

      255

      256

      257

      ★ 源碼 ★

      源碼分享一時(shí)爽,一直分享一直爽, 鏈接如下:

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

      Qt

      版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。

      版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。

      上一篇:javascript基礎(chǔ)修煉(11)——DOM-DIFF的實(shí)現(xiàn)
      下一篇:excel2003行列互換的教程
      相關(guān)文章
      亚洲AV无码专区国产乱码电影| 亚洲午夜激情视频| 亚洲中文字幕无码不卡电影| 亚洲国产AV无码一区二区三区 | 久久精品国产亚洲av麻| 亚洲乱码无码永久不卡在线 | 国产av无码专区亚洲国产精品| 欧洲亚洲综合一区二区三区| 亚洲AV无码AV日韩AV网站| 亚洲精品无码人妻无码| 亚洲AV成人精品日韩一区| 激情无码亚洲一区二区三区| 男人的天堂av亚洲一区2区| 亚洲AV无码AV吞精久久| 国产精品亚洲一区二区三区| 亚洲AV无码成人精品区大在线| 亚洲成a人片在线观看老师| 精品国产香蕉伊思人在线在线亚洲一区二区| 亚洲а∨天堂久久精品| 久久亚洲色一区二区三区| 亚洲精品午夜无码电影网| 亚洲AV无码国产精品麻豆天美 | 亚洲精品国产suv一区88 | 亚洲精品亚洲人成在线| 国产午夜亚洲精品不卡| 亚洲中文字幕视频国产| 亚洲日韩aⅴ在线视频| 亚洲国产精品无码久久久蜜芽| 久久亚洲精品无码| 亚洲精品**中文毛片| 自拍日韩亚洲一区在线| 亚洲色大成网站WWW国产| 蜜臀亚洲AV无码精品国产午夜.| 人人狠狠综合久久亚洲高清| 国产精品亚洲高清一区二区| 亚洲国产精品无码成人片久久| 亚洲美女视频一区| 一本色道久久88—综合亚洲精品| 色综合久久精品亚洲国产| 亚洲一区二区三区在线播放| 日本亚洲视频在线|