-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.cpp
152 lines (124 loc) · 5.04 KB
/
main.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// TODO: create ComboBox for selecting the graphs to be processed
#include <osg/Image>
#include <osg/Notify>
#include <osgViewer/CompositeViewer>
#include <osgEarth/ElevationQuery>
#include <osgEarth/StringUtils>
#include <osgEarth/TerrainEngineNode>
#include <osgEarthUtil/AnnotationEvents>
#include <osgEarthUtil/ExampleResources>
#include <osgEarthUtil/EarthManipulator>
#include <osgEarthUtil/LinearLineOfSight>
#include <osgEarthUtil/Controls>
#include <osgEarthAnnotation/PlaceNode>
#include <osgEarthAnnotation/RectangleNode>
#include <osgEarthAnnotation/HighlightDecoration>
#include <osgEarthQt/ViewerWidget>
// to draw polygons
#include <osgEarthSymbology/GeometryFactory>
#include <osgEarthAnnotation/FeatureNode>
// private headers
#include "gui.h"
#include "graph.h"
#include "graph_io.h"
#include "geometry.h"
#include "polygon.h"
// STL
#include <map>
#include <fstream>
#include <string>
#ifdef Q_WS_X11
#include <X11/Xlib.h>
#endif
//--------------------------------------------------------------
/** Main function for hacking */
int main()
{
kdtree tree;
tree.add(GeoNode(50, 30));
// set different pin colors
pin_img_path[0] = "red";
pin_img_path[1] = "orange";
pin_img_path[2] = "green";
// load graph and its nodes's coordinates
load_dimacs_coordinates(target_graph);
// LoadDimacsGraph(target_graph);
// set earth file path with map configurations
int argc = 2;
char* argv[2] = {"Geo-Graph Tool for WGS84 geocoordinates", "openstreetmap.earth"};
// initialize osgearth objects
arguments = new osg::ArgumentParser(&argc, argv);
if(arguments != NULL)
{
map_node = MapNode::load(*arguments);
if (map_node != NULL)
{
viewer = new osgViewer::Viewer(*arguments);
pin_group = new osg::Group();
box_group = new osg::Group();
polygon_group = new osg::Group();
edge_group = new osg::Group();
selected_point_group = new osg::Group();
#ifdef Q_WS_X11
// required for multi-threaded viewer on linux:
XInitThreads();
#endif
// configure layer of pins
Decluttering::setEnabled(pin_group->getOrCreateStateSet(), true);
Decluttering::setEnabled(selected_point_group->getOrCreateStateSet(), true);
// configure viewer, control for the map
if(viewer != NULL)
{
viewer->setRunFrameScheme(viewer->ON_DEMAND);
map_controller = new EarthManipulator();
if(map_controller != NULL)
{
viewer->setCameraManipulator(map_controller);
// put each layer of GUI elements onto central group of GUI elements
root = new osg::Group();
// let the annotations be highlighted
DecorationInstaller highlightInstaller("hover", new HighlightDecoration());
box_group->accept(highlightInstaller);
// install an event handler for picking and hovering.
AnnotationEventCallback* cb = new AnnotationEventCallback();
cb->addHandler(new SelectEventHandler());
box_group->addEventCallback(cb);
polygon_group->addEventCallback(cb);
edge_group->addEventCallback(cb);
// create GUI elements and configure them
if(root != NULL)
{
root->addChild(map_node);
root->addChild(pin_group);
root->addChild(box_group);
root->addChild(polygon_group);
root->addChild(edge_group);
root->addChild(selected_point_group);
// connect GUI elements to the viewer and create an user event handler
viewer->setSceneData(root);
viewer->addEventHandler(new UserEventHandler());
// create Qt GUI elements
QApplication app(argc, argv);
win = new QMainWindow;
if(win != NULL)
{
viewerWidget = new ViewerWidget(viewer);
if(viewerWidget != NULL)
{
win->setCentralWidget(viewerWidget);
win->setGeometry(500, 500, 600, 600);
win->show();
// DrawConvexHull();
app.exec();
}
}
}
}
}
} else {
OE_WARN << "Unable to load earth file." << std::endl;
return -1;
}
}
return 0;
}