InfoVis 2013  1.0
Information Visualisation project - "Mapping Text with Phrase Nets"
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
NodeGraphManager.h
Go to the documentation of this file.
1 #ifndef NODE_GRAPH_MANAGER_H
2 #define NODE_GRAPH_MANAGER_H
3 
4 #include <map>
5 #include <set>
6 #include <vector>
7 
8 class Application;
9 class GraphNode;
10 class UIManager;
11 class Arrow;
12 class RegexPhraseMatcher;
13 
14 namespace CEGUI
15 {
16  class Window;
17  class Colour;
18 }
19 
20 typedef std::map<std::string, GraphNode*> WordGraphMap;
21 typedef std::set<std::string> StopWordSet;
22 
23 
25 {
26 public:
29  bool operator< (const GraphNodeListEntry& compareNode);
30 
32  CEGUI::Window* m_graphNodeWindow;
33 
35 };
36 
37 struct float2
38 {
40  : x(0.f)
41  , y(0.f)
42  {
43  }
44 
45  float x;
46  float y;
47 };
48 
50 {
51  bool operator< (const GraphNodePair& otherPair) const;
52 
55 
58 };
59 
60 
61 typedef std::vector<GraphNodeListEntry> GraphNodeList;
62 typedef std::set<const GraphNodeListEntry*> GraphNodeSet;
63 typedef std::map<const GraphNode*, const GraphNodeListEntry*> GraphNodeListEntryMap;
64  /* NodeGraphManager takes care of the creation of nodes during the processing of the documents. Documents are received from application as strings and nodes are built from them using the RegexPhraseMatcher class to split them into word connections.
65  RegexPhraseMatcher offers the functionality for matching of regular expessions and is owned by this class. Furthermore NodeGraphmanager positions the nodes without overlap using several class methods. */
67 {
68 public:
69  NodeGraphManager(Application* application);
71 
72  static void addNodeConnection(GraphNode* first, GraphNode* second);
73 
75 
77 
78  void addHighestNeighbourEdgeWeights(GraphNodeList &graphNodeList);
79 
80  void createGraphWindows(GraphNodeList& mostFrequentGraphNodes, GraphNodeSet& graphNodeSet, UIManager* uiManager);
81 
82 
83 
84  void positionGraphNodes(GraphNodeList &graphNodes, const GraphNodeSet& graphNodeSet, const GraphNodeListEntryMap& graphNodeListEntryMap);
85 
86  void positionRelatedWindows(const GraphNodeListEntry* curListEntry, const GraphNodeListEntryMap& graphNodeListEntryMap, std::set<CEGUI::Window*>& positionedWindows, const GraphNodeSet& graphNodeSet, std::set<const CEGUI::Window*>& connectedWindows);
87 
88  void positionSubsequentWindows(const GraphNodeListEntry* curListEntry, const GraphNodeListEntryMap &graphNodeListEntryMap, std::set<CEGUI::Window*> &positionedWindows,
89  const GraphNodeSet &graphNodeSet, float2 windowCenter, std::set<const CEGUI::Window*>& connectedWindows);
90  void positionPreviousWindows(const GraphNodeListEntry* curListEntry, const GraphNodeListEntryMap &graphNodeListEntryMap, std::set<CEGUI::Window*> &positionedWindows,
91  const GraphNodeSet &graphNodeSet, float2 windowCenter, std::set<const CEGUI::Window*>& connectedWindows);
92 
93  void findAndSetFreePosition(std::set<CEGUI::Window*> &positionedWindows, CEGUI::Window* currentWindow, std::set<const CEGUI::Window*>& connectedWindows,
94  bool isInitialWindow, float2 startPos = float2(), CEGUI::Window* placeAroundWindow = 0);
95 
96  void createGraphNodeSetFromList(const GraphNodeList &mostFrequentGraphNodes, GraphNodeSet& graphNodeSet);
97 
98  void setMaxReturnedNodes(int maxReturnedNodes);
99  int getMaxReturnedNodes() const;
100 
101  void createGraphNodeConnectionPairs(const GraphNodeList &mostFrequentGraphNodes, const GraphNodeListEntryMap& graphNodeListEntryMap, std::set<GraphNodePair>& graphNodePairs);
102  void fillGraphNodeListEntryMap(const GraphNodeList &graphNodeListEntries, GraphNodeListEntryMap& graphNodeListEntryMap);
103 
104  void createNodeGraphArrows(const std::set<GraphNodePair>& graphNodePairs, std::vector<Arrow>& arrows);
105  void setIsUsingStopWords(bool isUsingStopWords);
106 
107  GraphNode* getGraphNodeByWord(const std::string& word);
108 
109 private:
110  void destroyWordGraph();
111 
112 
113 
114  void retrieveWeightedGraphNodes(GraphNodeList& graphNodeList);
115  void addWeightedGraphnodeToList(GraphNode* node, GraphNodeList& graphNodeList);
116 
117  void initStopWords();
118  void addStopWord(const std::string& stopWord);
119  bool isStopWord(const std::string& stopWord);
120 
121  void normaliseGraphNodeListIndicators(GraphNodeList &sortedGraphNodeList);
122  bool areNodeWindowsOverlapping(const CEGUI::Window* window, const CEGUI::Window* otherWindow, const std::set<const CEGUI::Window*>& connectedWindows, bool windowIsInitialOne) const;
123  bool areNodeWindowsOverlapping(const CEGUI::Window* window, const std::set<CEGUI::Window*>& otherWindows, const std::set<const CEGUI::Window*>& connectedWindows, bool windowIsInitialOne) const;
124 
125  float calculateOutgoingToTotalConnRatio(const GraphNodeListEntry& currentNode);
126 
127  void removeLowestTopNodesWithoutConnections(GraphNodeList &graphNodeList);
128 
129  float2 getRandomVector();
130 
131  Application* m_application;
132  WordGraphMap m_wordToGraphNodeMap;
133 
134  unsigned int m_maxReturnedNodes;
135 
136  StopWordSet m_stopWords;
137 
138  float m_randomPosMarginX;
139  float m_randomPosMarginY;
140 
141  bool m_usingStopWords;
142 
143  RegexPhraseMatcher* m_regexPhraseMatcher;
144 };
145 
146 #endif