Toggle navigation
Toggle navigation
This project
Loading...
Sign in
조성현
/
graph-visualization
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
조성현
2017-04-17 19:54:15 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e619f46f743bb884995f8501abc4bedc0384697d
e619f46f
1 parent
5ccb1e3d
add node type property
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
55 additions
and
60 deletions
PaperGraph/GraphItem.cpp
PaperGraph/GraphItem.h
PaperGraph/MainWindow.cpp
PaperGraph/NodeItem.cpp
PaperGraph/NodeItem.h
PaperGraph/PaperGraphWidget.cpp
PaperGraph/main.cpp
PaperGraph/stdafx.h
PaperGraph/GraphItem.cpp
View file @
e619f46
#include "stdafx.h"
#include "GraphItem.h"
GraphItem
::
GraphItem
(
ifstream
&
fin
)
GraphItem
::
GraphItem
(
ifstream
&
fin
,
int
numOfLines
)
{
//numOfLines == ifstream에서 읽을 라인의 수
if
(
!
fin
)
throw
std
::
exception
(
"graph file input is invalid"
);
else
if
(
numOfLines
<
1
)
throw
std
::
exception
(
"invalid numOfLines"
);
/**
* Parse Paper dataset
...
...
@@ -24,6 +28,7 @@ GraphItem::GraphItem(ifstream& fin)
vector
<
simple_edge
>
edges_indexes
;
//int로 변환된 edge
int
node_cnt
=
0
;
int
line_cnt
=
0
;
qDebug
()
<<
"* graph reading start"
;
//한 줄씩 읽어서 Parse
...
...
@@ -48,9 +53,11 @@ GraphItem::GraphItem(ifstream& fin)
}
//debug
if
(
node_cnt
>
NODE_LIMIT
)
break
;
++
line_cnt
;
if
(
line_cnt
>=
numOfLines
)
break
;
}
qDebug
()
<<
"* graph reading complete"
;
qDebug
()
<<
"* # of read line: "
<<
line_cnt
;
qDebug
()
<<
"* # of nodes: "
<<
node_cnt
;
qDebug
()
<<
"* # of edges: "
<<
edges
.
size
();
...
...
@@ -85,10 +92,10 @@ GraphItem::GraphItem(ifstream& fin)
//node type 설정
if
(
boost
::
regex_match
(
node_label
,
paper_reg
))
{
//Paper
boost
::
put
(
vertex_type
,
*
graph
,
*
vi
,
NODE_PAPER
);
boost
::
put
(
vertex_type
,
*
graph
,
*
vi
,
NODE_
TYPE
::
NODE_
PAPER
);
}
else
{
//Author
boost
::
put
(
vertex_type
,
*
graph
,
*
vi
,
NODE_AUTHOR
);
boost
::
put
(
vertex_type
,
*
graph
,
*
vi
,
NODE_
TYPE
::
NODE_
AUTHOR
);
}
++
i
;
...
...
@@ -173,6 +180,7 @@ GraphItem::GraphItem(ifstream& fin)
typedef
typename
Topology
::
point_type
Point
;
auto
position
=
get
(
vertex_position
,
*
graph
);
auto
label
=
get
(
vertex_name
,
*
graph
);
auto
nodeType
=
get
(
vertex_type
,
*
graph
);
typedef
boost
::
graph_traits
<
Graph
>::
vertex_descriptor
vertex_descriptor
;
typename
graph_traits
<
Graph
>::
edge_iterator
ei
,
ei_end
;
...
...
@@ -186,15 +194,6 @@ GraphItem::GraphItem(ifstream& fin)
//make edge item and push it to list
EdgeItem
*
edge
;
//if (label[u] == "conf/sbrn/GomesPSRC10" ||
// label[u] == "conf/iastedCSN/KeimS06" ||
// label[v] == "conf/sbrn/GomesPSRC10" ||
// label[v] == "conf/iastedCSN/KeimS06") {
// //highlight
// edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::blue), 3);
//} else {
// edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::black), 0);
//}
edge
=
new
EdgeItem
(
p1
[
0
],
p1
[
1
],
p2
[
0
],
p2
[
1
],
QColor
(
Qt
::
black
),
0
);
edge
->
setPos
(
p1
[
0
],
p1
[
1
]);
edgeList
<<
edge
;
...
...
@@ -203,18 +202,16 @@ GraphItem::GraphItem(ifstream& fin)
//add nodes
for
(
boost
::
tie
(
vi
,
vi_end
)
=
vertices
(
*
graph
);
vi
!=
vi_end
;
++
vi
)
{
Point
p
=
position
[
*
vi
];
auto
nt
=
nodeType
[
*
vi
];
std
::
string
name
=
label
[
*
vi
];
//make node item and push it to list
NodeItem
*
node
;
//if (name == "conf/sbrn/GomesPSRC10" ||
// name == "conf/iastedCSN/KeimS06") {
// //highlight
// node = new NodeItem(p[0], p[1], QColor(Qt::blue), QString(name.c_str()));
//} else {
// node = new NodeItem(p[0], p[1], QColor(Qt::green), QString(name.c_str()));
//}
node
=
new
NodeItem
(
p
[
0
],
p
[
1
],
QColor
(
Qt
::
green
),
QString
(
name
.
c_str
()));
if
(
nt
==
NODE_TYPE
::
NODE_PAPER
)
{
node
=
new
NodeItem
(
p
[
0
],
p
[
1
],
QColor
(
Qt
::
darkGreen
),
QString
(
name
.
c_str
()),
nt
);
}
else
{
node
=
new
NodeItem
(
p
[
0
],
p
[
1
],
QColor
(
Qt
::
green
),
QString
(
name
.
c_str
()),
nt
);
}
node
->
setPos
(
QPointF
(
p
[
0
],
p
[
1
]));
nodeList
<<
node
;
}
...
...
@@ -263,8 +260,12 @@ void GraphItem::path_highlighting(std::string start, std::string end)
void
GraphItem
::
reset_color
()
{
for
(
auto
&
n
:
nodeList
)
{
if
(
n
->
getType
()
==
NODE_PAPER
)
{
n
->
setColor
(
QColor
(
Qt
::
darkGreen
));
}
else
{
n
->
setColor
(
QColor
(
Qt
::
green
));
}
}
}
//event handler
...
...
PaperGraph/GraphItem.h
View file @
e619f46
...
...
@@ -9,21 +9,6 @@ using namespace std;
using
namespace
boost
;
//enum GRAPH_LAYOUT {
// RANDOM_LAYOUT,
// CIRCLE_LAYOUT,
// //KAMADA_KAWAI_LAYOUT,
// FRUCHTERMAN_REINGOLD_LAYOUT //slow
//};
/**
* Constants
*/
//const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT;
//const int SCREEN_SIZE = 300;
//const int NODE_LIMIT = 100;
//const boost::regex paper_reg("(conf|journals).*");
enum
vertex_position_t
{
vertex_position
};
enum
vertex_type_t
{
vertex_type
};
namespace
boost
{
...
...
@@ -55,7 +40,7 @@ class GraphItem
:
public
QGraphicsItem
{
public
:
GraphItem
(
ifstream
&
fin
);
GraphItem
(
ifstream
&
fin
,
int
numOfLines
);
//overrides
QRectF
boundingRect
()
const
override
;
...
...
PaperGraph/MainWindow.cpp
View file @
e619f46
...
...
@@ -39,7 +39,7 @@ void MainWindow::createActions()
testHighlightAct
->
setStatusTip
(
tr
(
"Highlighting node"
));
connect
(
testHighlightAct
,
&
QAction
::
triggered
,
this
,
&
MainWindow
::
test_highlighting
);
resetColorAct
=
new
QAction
(
tr
(
"&Reset"
),
this
);
resetColorAct
=
new
QAction
(
tr
(
"&Reset
colors
"
),
this
);
resetColorAct
->
setStatusTip
(
tr
(
"Reset all node's color"
));
connect
(
resetColorAct
,
&
QAction
::
triggered
,
this
,
&
MainWindow
::
reset_color
);
}
...
...
PaperGraph/NodeItem.cpp
View file @
e619f46
...
...
@@ -22,13 +22,14 @@ void NodeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
{
}
NodeItem
::
NodeItem
(
double
x
,
double
y
,
QColor
color
,
QString
label
)
NodeItem
::
NodeItem
(
double
x
,
double
y
,
QColor
color
,
QString
label
,
int
type
)
{
//node constructor
this
->
x
=
x
;
this
->
y
=
y
;
this
->
color
=
color
;
this
->
label
=
label
;
this
->
type
=
type
;
setZValue
(
1
);
//setFlags(ItemIsSelectable | ItemIsMovable);
...
...
PaperGraph/NodeItem.h
View file @
e619f46
...
...
@@ -3,8 +3,6 @@
#include "stdafx.h"
const
int
NODE_SIZE
=
4
;
class
NodeItem
:
public
QGraphicsItem
{
...
...
@@ -13,6 +11,7 @@ private:
double
y
;
QColor
color
;
QString
label
;
int
type
;
protected
:
void
mousePressEvent
(
QGraphicsSceneMouseEvent
*
event
)
override
;
...
...
@@ -20,10 +19,11 @@ protected:
void
mouseReleaseEvent
(
QGraphicsSceneMouseEvent
*
event
)
override
;
public
:
NodeItem
(
double
x
,
double
y
,
QColor
color
,
QString
label
);
NodeItem
(
double
x
,
double
y
,
QColor
color
,
QString
label
,
int
type
);
//getter setter
QString
getLabel
()
{
return
label
;}
int
getType
()
{
return
type
;
}
void
setColor
(
QColor
color
)
{
this
->
color
=
color
;}
QRectF
boundingRect
()
const
override
;
...
...
PaperGraph/PaperGraphWidget.cpp
View file @
e619f46
...
...
@@ -12,14 +12,13 @@ PaperGraphWidget::PaperGraphWidget(QWidget *parent)
view
->
view
()
->
setScene
(
scene
);
QVBoxLayout
*
layout
=
new
QVBoxLayout
;
QComboBox
*
combo
=
new
QComboBox
;
combo
->
addItem
(
"conf/iastedCSN/KeimS06"
);
combo
->
addItem
(
"conf/iastedCSN/Mojumdar06"
);
combo
->
addItem
(
"conf/iastedCSN/PourKKI06"
);
connect
(
combo
,
SIGNAL
(
currentIndexChanged
(
int
)),
this
,
SLOT
(
handleSelectionChanged
(
int
)));
layout
->
addWidget
(
combo
);
//QComboBox *combo = new QComboBox;
//combo->addItem("conf/iastedCSN/KeimS06");
//combo->addItem("conf/iastedCSN/Mojumdar06");
//combo->addItem("conf/iastedCSN/PourKKI06");
//connect(combo, SIGNAL(currentIndexChanged(int)),
// this, SLOT(handleSelectionChanged(int)));
//layout->addWidget(combo);
layout
->
addWidget
(
view
);
setLayout
(
layout
);
...
...
@@ -32,7 +31,7 @@ void PaperGraphWidget::print_graph(ifstream& fin)
if
(
graphItem
)
throw
std
::
exception
(
"already have graph item"
);
graphItem
=
new
GraphItem
(
fin
);
graphItem
=
new
GraphItem
(
fin
,
READ_LINE_UNIT
);
graphItem
->
setPos
(
0
,
0
);
scene
->
addItem
(
graphItem
);
}
...
...
PaperGraph/main.cpp
View file @
e619f46
...
...
@@ -2,8 +2,6 @@
#include "PaperGraphWidget.h"
#include "MainWindow.h"
//const char* PAPER_FILENAME = "dblp-paper.txt";
int
main
(
int
argc
,
char
*
argv
[])
{
QApplication
app
(
argc
,
argv
);
...
...
PaperGraph/stdafx.h
View file @
e619f46
...
...
@@ -40,10 +40,14 @@
using
namespace
boost
;
using
namespace
std
;
#define NODE_PAPER 1
#define NODE_AUTHOR 2
/* constants */
namespace
{
/* enums */
enum
NODE_TYPE
{
NODE_PAPER
,
NODE_AUTHOR
};
enum
GRAPH_LAYOUT
{
RANDOM_LAYOUT
,
CIRCLE_LAYOUT
,
...
...
@@ -51,13 +55,20 @@ namespace {
FRUCHTERMAN_REINGOLD_LAYOUT
//slow
};
/* file io */
const
char
*
PAPER_FILENAME
=
"dblp-paper.txt"
;
/* visualization */
const
int
NODE_SIZE
=
4
;
const
int
LAYOUT_MODE
=
GRAPH_LAYOUT
::
RANDOM_LAYOUT
;
const
int
SCREEN_SIZE
=
300
;
const
int
NODE_LIMIT
=
100
;
const
int
SCREEN_SIZE
=
1000
;
const
int
READ_LINE_UNIT
=
100
;
//한 번에 몇 라인을 읽을지
/* topK */
const
int
topK
=
10
;
//상위 몇 개 아이템에 대해
const
char
*
PAPER_FILENAME
=
"dblp-paper.txt"
;
}
namespace
boost
{
const
regex
paper_reg
(
"(conf|journals).*"
);
const
boost
::
regex
paper_reg
(
"(conf|journals).*"
);
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment