조성현

add node type property

1 #include "stdafx.h" 1 #include "stdafx.h"
2 #include "GraphItem.h" 2 #include "GraphItem.h"
3 3
4 -GraphItem::GraphItem(ifstream& fin) 4 +GraphItem::GraphItem(ifstream& fin, int numOfLines)
5 { 5 {
6 + //numOfLines == ifstream에서 읽을 라인의 수
7 +
6 if (!fin) 8 if (!fin)
7 throw std::exception("graph file input is invalid"); 9 throw std::exception("graph file input is invalid");
10 + else if (numOfLines < 1)
11 + throw std::exception("invalid numOfLines");
8 12
9 /** 13 /**
10 * Parse Paper dataset 14 * Parse Paper dataset
...@@ -24,6 +28,7 @@ GraphItem::GraphItem(ifstream& fin) ...@@ -24,6 +28,7 @@ GraphItem::GraphItem(ifstream& fin)
24 vector<simple_edge> edges_indexes; //int로 변환된 edge 28 vector<simple_edge> edges_indexes; //int로 변환된 edge
25 29
26 int node_cnt = 0; 30 int node_cnt = 0;
31 + int line_cnt = 0;
27 qDebug() << "* graph reading start"; 32 qDebug() << "* graph reading start";
28 33
29 //한 줄씩 읽어서 Parse 34 //한 줄씩 읽어서 Parse
...@@ -48,9 +53,11 @@ GraphItem::GraphItem(ifstream& fin) ...@@ -48,9 +53,11 @@ GraphItem::GraphItem(ifstream& fin)
48 } 53 }
49 54
50 //debug 55 //debug
51 - if (node_cnt > NODE_LIMIT) break; 56 + ++line_cnt;
57 + if (line_cnt >= numOfLines) break;
52 } 58 }
53 qDebug() << "* graph reading complete"; 59 qDebug() << "* graph reading complete";
60 + qDebug() << "* # of read line: " << line_cnt;
54 qDebug() << "* # of nodes: " << node_cnt; 61 qDebug() << "* # of nodes: " << node_cnt;
55 qDebug() << "* # of edges: " << edges.size(); 62 qDebug() << "* # of edges: " << edges.size();
56 63
...@@ -85,10 +92,10 @@ GraphItem::GraphItem(ifstream& fin) ...@@ -85,10 +92,10 @@ GraphItem::GraphItem(ifstream& fin)
85 //node type 설정 92 //node type 설정
86 if (boost::regex_match(node_label, paper_reg)) { 93 if (boost::regex_match(node_label, paper_reg)) {
87 //Paper 94 //Paper
88 - boost::put(vertex_type, *graph, *vi, NODE_PAPER); 95 + boost::put(vertex_type, *graph, *vi, NODE_TYPE::NODE_PAPER);
89 } else { 96 } else {
90 //Author 97 //Author
91 - boost::put(vertex_type, *graph, *vi, NODE_AUTHOR); 98 + boost::put(vertex_type, *graph, *vi, NODE_TYPE::NODE_AUTHOR);
92 } 99 }
93 100
94 ++i; 101 ++i;
...@@ -173,6 +180,7 @@ GraphItem::GraphItem(ifstream& fin) ...@@ -173,6 +180,7 @@ GraphItem::GraphItem(ifstream& fin)
173 typedef typename Topology::point_type Point; 180 typedef typename Topology::point_type Point;
174 auto position = get(vertex_position, *graph); 181 auto position = get(vertex_position, *graph);
175 auto label = get(vertex_name, *graph); 182 auto label = get(vertex_name, *graph);
183 + auto nodeType = get(vertex_type, *graph);
176 184
177 typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor; 185 typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
178 typename graph_traits<Graph>::edge_iterator ei, ei_end; 186 typename graph_traits<Graph>::edge_iterator ei, ei_end;
...@@ -186,15 +194,6 @@ GraphItem::GraphItem(ifstream& fin) ...@@ -186,15 +194,6 @@ GraphItem::GraphItem(ifstream& fin)
186 //make edge item and push it to list 194 //make edge item and push it to list
187 EdgeItem *edge; 195 EdgeItem *edge;
188 196
189 - //if (label[u] == "conf/sbrn/GomesPSRC10" ||
190 - // label[u] == "conf/iastedCSN/KeimS06" ||
191 - // label[v] == "conf/sbrn/GomesPSRC10" ||
192 - // label[v] == "conf/iastedCSN/KeimS06") {
193 - // //highlight
194 - // edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::blue), 3);
195 - //} else {
196 - // edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::black), 0);
197 - //}
198 edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::black), 0); 197 edge = new EdgeItem(p1[0], p1[1], p2[0], p2[1], QColor(Qt::black), 0);
199 edge->setPos(p1[0], p1[1]); 198 edge->setPos(p1[0], p1[1]);
200 edgeList << edge; 199 edgeList << edge;
...@@ -203,18 +202,16 @@ GraphItem::GraphItem(ifstream& fin) ...@@ -203,18 +202,16 @@ GraphItem::GraphItem(ifstream& fin)
203 //add nodes 202 //add nodes
204 for (boost::tie(vi, vi_end)=vertices(*graph); vi!=vi_end; ++vi) { 203 for (boost::tie(vi, vi_end)=vertices(*graph); vi!=vi_end; ++vi) {
205 Point p = position[*vi]; 204 Point p = position[*vi];
205 + auto nt = nodeType[*vi];
206 std::string name = label[*vi]; 206 std::string name = label[*vi];
207 207
208 //make node item and push it to list 208 //make node item and push it to list
209 NodeItem *node; 209 NodeItem *node;
210 - //if (name == "conf/sbrn/GomesPSRC10" || 210 + if (nt == NODE_TYPE::NODE_PAPER) {
211 - // name == "conf/iastedCSN/KeimS06") { 211 + node = new NodeItem(p[0], p[1], QColor(Qt::darkGreen), QString(name.c_str()), nt);
212 - // //highlight 212 + } else {
213 - // node = new NodeItem(p[0], p[1], QColor(Qt::blue), QString(name.c_str())); 213 + node = new NodeItem(p[0], p[1], QColor(Qt::green), QString(name.c_str()), nt);
214 - //} else { 214 + }
215 - // node = new NodeItem(p[0], p[1], QColor(Qt::green), QString(name.c_str()));
216 - //}
217 - node = new NodeItem(p[0], p[1], QColor(Qt::green), QString(name.c_str()));
218 node->setPos(QPointF(p[0], p[1])); 215 node->setPos(QPointF(p[0], p[1]));
219 nodeList << node; 216 nodeList << node;
220 } 217 }
...@@ -263,7 +260,11 @@ void GraphItem::path_highlighting(std::string start, std::string end) ...@@ -263,7 +260,11 @@ void GraphItem::path_highlighting(std::string start, std::string end)
263 void GraphItem::reset_color() 260 void GraphItem::reset_color()
264 { 261 {
265 for (auto& n: nodeList) { 262 for (auto& n: nodeList) {
266 - n->setColor(QColor(Qt::green)); 263 + if (n->getType() == NODE_PAPER) {
264 + n->setColor(QColor(Qt::darkGreen));
265 + } else {
266 + n->setColor(QColor(Qt::green));
267 + }
267 } 268 }
268 } 269 }
269 270
......
...@@ -9,21 +9,6 @@ using namespace std; ...@@ -9,21 +9,6 @@ using namespace std;
9 using namespace boost; 9 using namespace boost;
10 10
11 11
12 -//enum GRAPH_LAYOUT {
13 -// RANDOM_LAYOUT,
14 -// CIRCLE_LAYOUT,
15 -// //KAMADA_KAWAI_LAYOUT,
16 -// FRUCHTERMAN_REINGOLD_LAYOUT //slow
17 -//};
18 -
19 -/**
20 - * Constants
21 - */
22 -//const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT;
23 -//const int SCREEN_SIZE = 300;
24 -//const int NODE_LIMIT = 100;
25 -//const boost::regex paper_reg("(conf|journals).*");
26 -
27 enum vertex_position_t { vertex_position }; 12 enum vertex_position_t { vertex_position };
28 enum vertex_type_t { vertex_type }; 13 enum vertex_type_t { vertex_type };
29 namespace boost { 14 namespace boost {
...@@ -55,7 +40,7 @@ class GraphItem ...@@ -55,7 +40,7 @@ class GraphItem
55 : public QGraphicsItem 40 : public QGraphicsItem
56 { 41 {
57 public: 42 public:
58 - GraphItem(ifstream& fin); 43 + GraphItem(ifstream& fin, int numOfLines);
59 44
60 //overrides 45 //overrides
61 QRectF boundingRect() const override; 46 QRectF boundingRect() const override;
......
...@@ -39,7 +39,7 @@ void MainWindow::createActions() ...@@ -39,7 +39,7 @@ void MainWindow::createActions()
39 testHighlightAct->setStatusTip(tr("Highlighting node")); 39 testHighlightAct->setStatusTip(tr("Highlighting node"));
40 connect(testHighlightAct, &QAction::triggered, this, &MainWindow::test_highlighting); 40 connect(testHighlightAct, &QAction::triggered, this, &MainWindow::test_highlighting);
41 41
42 - resetColorAct = new QAction(tr("&Reset"), this); 42 + resetColorAct = new QAction(tr("&Reset colors"), this);
43 resetColorAct->setStatusTip(tr("Reset all node's color")); 43 resetColorAct->setStatusTip(tr("Reset all node's color"));
44 connect(resetColorAct, &QAction::triggered, this, &MainWindow::reset_color); 44 connect(resetColorAct, &QAction::triggered, this, &MainWindow::reset_color);
45 } 45 }
......
...@@ -22,13 +22,14 @@ void NodeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) ...@@ -22,13 +22,14 @@ void NodeItem::mouseReleaseEvent(QGraphicsSceneMouseEvent * event)
22 { 22 {
23 } 23 }
24 24
25 -NodeItem::NodeItem(double x, double y, QColor color, QString label) 25 +NodeItem::NodeItem(double x, double y, QColor color, QString label, int type)
26 { 26 {
27 //node constructor 27 //node constructor
28 this->x = x; 28 this->x = x;
29 this->y = y; 29 this->y = y;
30 this->color = color; 30 this->color = color;
31 this->label = label; 31 this->label = label;
32 + this->type = type;
32 setZValue(1); 33 setZValue(1);
33 34
34 //setFlags(ItemIsSelectable | ItemIsMovable); 35 //setFlags(ItemIsSelectable | ItemIsMovable);
......
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
3 3
4 #include "stdafx.h" 4 #include "stdafx.h"
5 5
6 -const int NODE_SIZE = 4;
7 -
8 class NodeItem 6 class NodeItem
9 : public QGraphicsItem 7 : public QGraphicsItem
10 { 8 {
...@@ -13,6 +11,7 @@ private: ...@@ -13,6 +11,7 @@ private:
13 double y; 11 double y;
14 QColor color; 12 QColor color;
15 QString label; 13 QString label;
14 + int type;
16 15
17 protected: 16 protected:
18 void mousePressEvent(QGraphicsSceneMouseEvent *event) override; 17 void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
...@@ -20,10 +19,11 @@ protected: ...@@ -20,10 +19,11 @@ protected:
20 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; 19 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
21 20
22 public: 21 public:
23 - NodeItem(double x, double y, QColor color, QString label); 22 + NodeItem(double x, double y, QColor color, QString label, int type);
24 23
25 //getter setter 24 //getter setter
26 QString getLabel() {return label;} 25 QString getLabel() {return label;}
26 + int getType() { return type; }
27 void setColor(QColor color) {this->color=color;} 27 void setColor(QColor color) {this->color=color;}
28 28
29 QRectF boundingRect() const override; 29 QRectF boundingRect() const override;
......
...@@ -12,14 +12,13 @@ PaperGraphWidget::PaperGraphWidget(QWidget *parent) ...@@ -12,14 +12,13 @@ PaperGraphWidget::PaperGraphWidget(QWidget *parent)
12 view->view()->setScene(scene); 12 view->view()->setScene(scene);
13 13
14 QVBoxLayout *layout = new QVBoxLayout; 14 QVBoxLayout *layout = new QVBoxLayout;
15 - QComboBox *combo = new QComboBox; 15 + //QComboBox *combo = new QComboBox;
16 - combo->addItem("conf/iastedCSN/KeimS06"); 16 + //combo->addItem("conf/iastedCSN/KeimS06");
17 - combo->addItem("conf/iastedCSN/Mojumdar06"); 17 + //combo->addItem("conf/iastedCSN/Mojumdar06");
18 - combo->addItem("conf/iastedCSN/PourKKI06"); 18 + //combo->addItem("conf/iastedCSN/PourKKI06");
19 - connect(combo, SIGNAL(currentIndexChanged(int)), 19 + //connect(combo, SIGNAL(currentIndexChanged(int)),
20 - this, SLOT(handleSelectionChanged(int))); 20 + // this, SLOT(handleSelectionChanged(int)));
21 - 21 + //layout->addWidget(combo);
22 - layout->addWidget(combo);
23 layout->addWidget(view); 22 layout->addWidget(view);
24 setLayout(layout); 23 setLayout(layout);
25 24
...@@ -32,7 +31,7 @@ void PaperGraphWidget::print_graph(ifstream& fin) ...@@ -32,7 +31,7 @@ void PaperGraphWidget::print_graph(ifstream& fin)
32 if (graphItem) 31 if (graphItem)
33 throw std::exception("already have graph item"); 32 throw std::exception("already have graph item");
34 33
35 - graphItem = new GraphItem(fin); 34 + graphItem = new GraphItem(fin, READ_LINE_UNIT);
36 graphItem->setPos(0, 0); 35 graphItem->setPos(0, 0);
37 scene->addItem(graphItem); 36 scene->addItem(graphItem);
38 } 37 }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
2 #include "PaperGraphWidget.h" 2 #include "PaperGraphWidget.h"
3 #include "MainWindow.h" 3 #include "MainWindow.h"
4 4
5 -//const char* PAPER_FILENAME = "dblp-paper.txt";
6 -
7 int main(int argc, char *argv[]) 5 int main(int argc, char *argv[])
8 { 6 {
9 QApplication app(argc, argv); 7 QApplication app(argc, argv);
......
...@@ -40,10 +40,14 @@ ...@@ -40,10 +40,14 @@
40 using namespace boost; 40 using namespace boost;
41 using namespace std; 41 using namespace std;
42 42
43 -#define NODE_PAPER 1 43 +/* constants */
44 -#define NODE_AUTHOR 2
45 -
46 namespace { 44 namespace {
45 + /* enums */
46 + enum NODE_TYPE {
47 + NODE_PAPER,
48 + NODE_AUTHOR
49 + };
50 +
47 enum GRAPH_LAYOUT { 51 enum GRAPH_LAYOUT {
48 RANDOM_LAYOUT, 52 RANDOM_LAYOUT,
49 CIRCLE_LAYOUT, 53 CIRCLE_LAYOUT,
...@@ -51,13 +55,20 @@ namespace { ...@@ -51,13 +55,20 @@ namespace {
51 FRUCHTERMAN_REINGOLD_LAYOUT //slow 55 FRUCHTERMAN_REINGOLD_LAYOUT //slow
52 }; 56 };
53 57
54 - const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT; 58 + /* file io */
55 - const int SCREEN_SIZE = 300;
56 - const int NODE_LIMIT = 100;
57 -
58 const char* PAPER_FILENAME = "dblp-paper.txt"; 59 const char* PAPER_FILENAME = "dblp-paper.txt";
60 +
61 + /* visualization */
62 + const int NODE_SIZE = 4;
63 + const int LAYOUT_MODE = GRAPH_LAYOUT::RANDOM_LAYOUT;
64 + const int SCREEN_SIZE = 1000;
65 + const int READ_LINE_UNIT = 100; //한 번에 몇 라인을 읽을지
66 +
67 + /* topK */
68 + const int topK = 10; //상위 몇 개 아이템에 대해
69 +
59 } 70 }
60 71
61 namespace boost { 72 namespace boost {
62 - const regex paper_reg("(conf|journals).*"); 73 + const boost::regex paper_reg("(conf|journals).*");
63 } 74 }
...\ No newline at end of file ...\ No newline at end of file
......