forked from dkogan/horizonator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
render_terrain_show.cc
198 lines (160 loc) · 5.06 KB
/
render_terrain_show.cc
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#include <string.h>
#include <stdio.h>
#include <getopt.h>
#include <opencv2/highgui/highgui_c.h>
#include <FL/Fl.H>
#include <FL/fl_ask.H>
#include <FL/Fl_Double_Window.H>
#include "Fl_Scroll_Draggable.hh"
#include "fltk_annotated_image.hh"
#include "orb_osmlayer.hpp"
#include "orb_renderviewlayer.hh"
#include "orb_mapctrl.hpp"
#include "render_terrain.h"
// window geometry
#define WINDOW_W 800
#define WINDOW_H 600
static Fl_Scroll_Draggable* render_scroll;
static CvFltkWidget_annotated* widgetImage;
static void cb_slippymap( Fl_Widget* widget, void* cookie );
static void redraw_slippymap( void* mapctrl );
int main(int argc, char** argv)
{
Fl::lock();
int doGlonly = 0;
float glonly_view_lat, glonly_view_lon;
const char* usage =
"%s [--glonly lat,lon] [--help]\n"
" --glonly renders to a OpenGL window. No annotations\n"
" otherwise the full FLTK app is launched; annotations and all\n";
struct option long_options[] =
{
{"glonly", required_argument, NULL, 'g' },
{"help", no_argument, NULL, 'h' },
{}
};
int getopt_res;
do
{
char* lat;
char* lon;
getopt_res = getopt_long(argc, argv, "", long_options, NULL);
switch( getopt_res )
{
case '?':
fprintf(stderr, "Unknown cmdline option encountered\nUsage: ");
fprintf(stderr, usage, argv[0]);
return 1;
case 'h':
fprintf(stdout, usage, argv[0]);
return 0;
case 'g':
doGlonly = 1;
lat = strtok( optarg, "," );
if( lat == NULL )
{
fprintf(stderr, "Couldn't parse lat,lon;\n" );
fprintf(stderr, usage, argv[0]);
return 1;
}
glonly_view_lat = atof( lat );
lon = strtok( NULL, "," );
if( lon == NULL )
{
fprintf(stderr, "Couldn't parse lat,lon;\n" );
fprintf(stderr, usage, argv[0]);
return 1;
}
glonly_view_lon = atof( lon );
break;
default: ;
}
} while(getopt_res != -1);
if( doGlonly )
{
render_terrain_to_window( glonly_view_lat, glonly_view_lon );
return 0;
}
std::vector<orb_layer*> layers;
orb_mapctrl* mapctrl;
orb_renderviewlayer* renderviewlayer;
Fl_Double_Window* window = new Fl_Double_Window( WINDOW_W, WINDOW_H, "Horizonator" );
const int map_h = window->h()/2;
{
mapctrl = new orb_mapctrl( 0, 0, window->w(), map_h, "Slippy Map" );
mapctrl->box(FL_NO_BOX);
mapctrl->color(FL_BACKGROUND_COLOR);
mapctrl->selection_color(FL_BACKGROUND_COLOR);
mapctrl->labeltype(FL_NORMAL_LABEL);
mapctrl->labelfont(0);
mapctrl->labelsize(14);
mapctrl->labelcolor(FL_FOREGROUND_COLOR);
mapctrl->align(Fl_Align(FL_ALIGN_CENTER));
renderviewlayer = new orb_renderviewlayer;
orb_osmlayer* osmlayer = new orb_osmlayer;
osmlayer->callback( &redraw_slippymap, mapctrl );
layers.push_back(osmlayer);
layers.push_back(renderviewlayer);
mapctrl->layers(layers);
// callback for the right mouse button
mapctrl->callback( &cb_slippymap, renderviewlayer );
}
{
render_scroll = new Fl_Scroll_Draggable( 0, map_h, window->w(), window->h() - map_h,
renderviewlayer, mapctrl );
render_scroll->end();
}
window->resizable(window);
window->end();
window->show();
Fl::run();
return 0;
}
static void redraw_slippymap( void* mapctrl )
{
reinterpret_cast<orb_mapctrl*>(mapctrl)->redraw();
}
static void cb_slippymap(Fl_Widget* widget,
void* cookie )
{
if( Fl::event() == FL_PUSH &&
Fl::event_button() == FL_RIGHT_MOUSE )
{
orb_point<double> gps;
if( reinterpret_cast<orb_mapctrl*>(widget)->mousegps( gps ) != 0 )
{
fprintf( stderr, "couldn't get mouse click latlon position for some reason...\n" );
return;
}
float view_lat = (float)gps.get_y();
float view_lon = (float)gps.get_x();
orb_renderviewlayer* renderviewlayer = reinterpret_cast<orb_renderviewlayer*>(cookie);
renderviewlayer->setlatlon( view_lat, view_lon );
float elevation;
IplImage* img = render_terrain( view_lat, view_lon, &elevation,
false /* BGR is we're writing to a file;
cvSaveImage() expects */
);
if( img == NULL )
{
fl_alert( "Error rendering the terrain....\n");
return;
}
if( !widgetImage )
{
render_scroll->begin();
widgetImage = new CvFltkWidget_annotated(render_scroll->x(), render_scroll->y(), img->width, img->height,
WIDGET_COLOR);
render_scroll->end();
}
cvCopy( img, (IplImage*)*widgetImage, NULL );
cvReleaseImage( &img );
// set up the labels
widgetImage->setTransformation( view_lat * M_PI / 180.0,
view_lon * M_PI / 180.0,
elevation,
mercator,
0,0,0,0 );
widgetImage->redrawNewFrame();
}
}