-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphview.cpp
131 lines (108 loc) · 4.41 KB
/
graphview.cpp
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
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
/*
Copyright 2019 Balázs Ludmány
This file is part of contours-viewer.
contours-viewer is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
contours-viewer is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with contours-viewer. If not, see <https://www.gnu.org/licenses/>.
*/
#include "graphview.hpp"
#include <boost/container/flat_set.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/range/algorithm/copy.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include <boost/range/algorithm/max_element.hpp>
#include <boost/range/algorithm/sort.hpp>
#include <functional>
#include <vtkAOSDataArrayTemplate.h>
#include <vtkActor.h>
#include <vtkDataSetAttributes.h>
#include <vtkFast2DLayoutStrategy.h>
#include <vtkGenericOpenGLRenderWindow.h>
#include <vtkGenericRenderWindowInteractor.h>
#include <vtkGlyph2D.h>
#include <vtkGlyphSource2D.h>
#include <vtkGraphLayout.h>
#include <vtkGraphLayoutView.h>
#include <vtkGraphToGlyphs.h>
#include <vtkGraphToPolyData.h>
#include <vtkInteractorStyleRubberBand2D.h>
#include <vtkMutableDirectedGraph.h>
#include <vtkNew.h>
#include <vtkPassThroughLayoutStrategy.h>
#include <vtkPoints.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkVariant.h>
#include <vtkViewTheme.h>
void GraphView::Initialize() {
vtkNew<vtkFast2DLayoutStrategy> strategy;
vtkNew<vtkGraphLayout> layout;
layout->SetInputData(m_displayedGraph.GetPointer());
layout->SetLayoutStrategy(strategy.GetPointer());
m_view->AddRepresentationFromInputConnection(layout->GetOutputPort());
m_view->SetLayoutStrategyToPassThrough();
m_view->SetEdgeLayoutStrategyToPassThrough();
m_view->SetGlyphType(vtkGraphToGlyphs::CIRCLE);
vtkNew<vtkViewTheme> theme;
theme->SetBackgroundColor(1.0, 1.0, 1.0);
theme->SetBackgroundColor2(1.0, 1.0, 1.0);
theme->SetPointColor(0.0, 0.0, 0.0);
theme->SetCellColor(0.0, 0.0, 0.0);
theme->SetOutlineColor(0.0, 0.0, 0.0);
theme->SetSelectedPointColor(1.0, 1.0, 0.0);
theme->SetSelectedCellColor(1.0, 1.0, 0.0);
m_view->ApplyViewTheme(theme.GetPointer());
vtkNew<vtkGraphToPolyData> polydata;
polydata->SetInputConnection(layout->GetOutputPort());
polydata->EdgeGlyphOutputOn();
polydata->SetEdgeGlyphPosition(0.99);
vtkNew<vtkGlyphSource2D> source;
source->SetGlyphTypeToEdgeArrow();
source->SetScale(0.2);
source->Update();
vtkNew<vtkGlyph2D> glyph;
glyph->SetInputConnection(0, polydata->GetOutputPort(1));
glyph->SetInputConnection(1, source->GetOutputPort(0));
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(glyph->GetOutputPort());
vtkNew<vtkActor> actor;
actor->SetMapper(mapper.GetPointer());
actor->GetProperty()->SetColor(0.0, 0.0, 0.0);
m_view->GetRenderer()->AddActor(actor.GetPointer());
vtkNew<vtkGenericOpenGLRenderWindow> window;
m_view->SetRenderWindow(window.GetPointer());
m_view->ResetCamera();
vtkNew<vtkGenericRenderWindowInteractor> interactor;
interactor->SetRenderWindow(window.GetPointer());
vtkNew<vtkInteractorStyleRubberBand2D> style;
style->SetPickColor(1.0, 1.0, 0.0);
interactor->SetInteractorStyle(style.GetPointer());
SetRenderWindowInteractor(interactor.GetPointer());
interactor->Enable();
}
void GraphView::UpdateGraph(const Graph &reeb) {
wxCriticalSectionLocker lock(m_critical_section);
vtkNew<vtkMutableDirectedGraph> graph;
vtkNew<vtkIntArray> pedigree;
for (const auto &vertex : boost::make_iterator_range(boost::vertices(reeb)))
pedigree->InsertValue(graph->AddVertex(), reeb[vertex].id);
graph->GetVertexData()->SetPedigreeIds(pedigree.GetPointer());
for (const auto &edge : boost::make_iterator_range(boost::edges(reeb)))
graph->AddEdge(vtkVariant(reeb[boost::source(edge, reeb)].id),
vtkVariant(reeb[boost::target(edge, reeb)].id));
m_preparedGraph->ShallowCopy(graph.GetPointer());
}
void GraphView::Swap() {
wxCriticalSectionLocker lock(m_critical_section);
m_displayedGraph->ShallowCopy(m_preparedGraph.GetPointer());
m_view->ResetCamera();
Refresh();
}