-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
189 lines (160 loc) · 4.57 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
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
/*
* File: main.cpp
* Author: gabe
*
* Created on 26 March 2012, 4:16 PM
*/
/*
#include <stdio.h>
#include "io.hpp"
#include "grid_features.hpp"
#include "ukf.hpp"
int main (int argc, const char * argv[])
{
ukf* filter = new ukf();
std::vector<std::string> test;
ImageReader* imgReader = new ImageReader("/home/gabe/sequences/grid sequence/frames/");
std::string imgWindowName = "Frame";
GridFeatures* featureFinder = new GridFeatures(8,6);
for (int i=0; i<imgReader->numImages; i++)
{
cv::Mat img = imgReader->getNextImage();
std::vector<cv::Point2f> corners = featureFinder->getFeatures(img);
cv::imshow(imgWindowName, img);
cv::waitKey(0);
}
}
*/
//#include "ukf.hpp"
#include "GL/freeglut.h"
#include "GL/gl.h"
#include "simCamera.hpp"
#include "simScene.hpp"
#include "ukf.hpp"
#include <stdio.h>
void drawCamera(Eigen::Vector3d position, double r, double g, double b);
void drawAxes();
void drawLandmarks();
void drawLandmark(double x, double y, double sideLength, double r, double g, double b);
namespace
{
double areaWidth = 200;
double areaHeight = 100;
SimScene simScene;
SimCamera simCamera(simScene);
ukf filter(simCamera);
}
void renderFunction()
{
float grey = 241.0;
glClearColor(grey/255.0, grey/255.0, grey/255.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glOrtho(-20.0, areaWidth+25.0, -20.0, areaHeight+25.0, -1.0, 1.0);
drawAxes();
drawCamera(simCamera.position(), 1.0, 0.0, 0.0);
drawCamera(filter.position(), 0.0, 0.0, 1.0);
printf("\n");
drawLandmarks();
glutSwapBuffers();
glFlush();
}
void drawLandmarks()
{
for (int i=0; i<simScene.landmarks.size(); i++)
{
Eigen::Vector3d landmark = simScene.landmarks.at(i);
drawLandmark(landmark(0,0), landmark(1,0), 2.0, 0.0, 1.0, 0.0);
}
std::vector<Eigen::Vector2d, Eigen::aligned_allocator<Eigen::Vector2d> > lms = filter.landmarks();
for (int i=0; i<lms.size(); i++)
{
drawLandmark(lms.at(i)(0,0), lms.at(i)(1,0), 2.0, 0.0, 0.0, 1.0);
}
}
void drawCamera(Eigen::Vector3d position, double r, double g, double b)
{
//Eigen::Vector3d position = simCamera.position();
glColor3f(r, g, b);
glPushMatrix();
glBegin(GL_POLYGON);
glVertex2d(position(0,0), position(1,0));
glVertex2d(position(0,0)+1.0, position(1,0)+1.0);
glVertex2d(position(0,0)+1.0, position(1,0)-1.0);
glEnd();
glPopMatrix();
}
void drawAxes()
{
glColor3f(0.0, 0.0, 0.0);
glBegin(GL_LINES); //x
glVertex2d(0.0, 0.0);
glVertex2d(areaWidth, 0.0);
glEnd();
glBegin(GL_LINES); //y
glVertex2d(0.0, 0.0);
glVertex2d(0.0, areaHeight);
glEnd();
double hashSpace = 10.0;
double hashLength = 3.0;
for (int i=0; i<areaWidth; i+=hashSpace)
{
glBegin(GL_LINES); // x axis hashes
glVertex2d(i, -1.0 * hashLength / 2.0);
glVertex2d(i, hashLength / 2.0);
glEnd();
}
for (int i=0; i<areaHeight; i+=hashSpace)
{
glBegin(GL_LINES); // y axis hashes
glVertex2d(-1.0 * hashLength / 2.0, i);
glVertex2d( hashLength / 2.0, i);
glEnd();
}
}
void drawLandmark(double x, double y, double sideLength, double r, double g, double b)
{
glColor3f(r, g, b);
glPushMatrix();
glTranslated(x, y, 0.0);
glRotated(45.0, 0.0, 0.0, 1.0);
glBegin(GL_QUADS);
glVertex2d(-1.0 * sideLength/2.0, -1.0 * sideLength/2.0);
glVertex2d(-1.0 * sideLength/2.0, sideLength/2.0);
glVertex2d( sideLength/2.0, sideLength/2.0);
glVertex2d( sideLength/2.0, -1.0 * sideLength/2.0);
glEnd();
glPopMatrix();
}
void keyboardListener(unsigned char key, int x, int y)
{
switch (key)
{
case 27: // Esc
exit(0);
break;
case 32: // Space
simCamera.timeStep();
filter.step(simCamera.defaultTimeStep, simCamera.measure(simScene));
break;
case 82: //R
case 114://r
simCamera.reset();
filter.reset(simCamera);
break;
}
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(1000,500);
glutInitWindowPosition(100,100);
glutCreateWindow("OpenGL - First window demo");
glutDisplayFunc(renderFunction);
// glutIdleFunc(renderFunction);
glutKeyboardFunc(keyboardListener);
glutMainLoop();
return 0;
}