-
Notifications
You must be signed in to change notification settings - Fork 28
/
System.cc
122 lines (95 loc) · 3.41 KB
/
System.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
// Copyright 2008 Isis Innovation Limited
#include "System.h"
#include "OpenGL.h"
#include <gvars3/instances.h>
#include <stdlib.h>
#include "ATANCamera.h"
#include "MapMaker.h"
#include "Tracker.h"
#include "ARDriver.h"
#include "MapViewer.h"
using namespace CVD;
using namespace std;
using namespace GVars3;
System::System()
: mGLWindow(mVideoSource.Size(), "PTAM")
{
GUI.RegisterCommand("exit", GUICommandCallBack, this);
GUI.RegisterCommand("quit", GUICommandCallBack, this);
mimFrameBW.resize(mVideoSource.Size());
mimFrameRGB.resize(mVideoSource.Size());
// First, check if the camera is calibrated.
// If not, we need to run the calibration widget.
Vector<NUMTRACKERCAMPARAMETERS> vTest;
vTest = GV3::get<Vector<NUMTRACKERCAMPARAMETERS> >("Camera.Parameters", ATANCamera::mvDefaultParams, HIDDEN);
mpCamera = new ATANCamera("Camera");
Vector<2> v2;
if(v2==v2) ;
if(vTest == ATANCamera::mvDefaultParams)
{
cout << endl;
cout << "! Camera.Parameters is not set, need to run the CameraCalibrator tool" << endl;
cout << " and/or put the Camera.Parameters= line into the appropriate .cfg file." << endl;
exit(1);
}
mpMap = new Map;
mpMapMaker = new MapMaker(*mpMap, *mpCamera);
mpTracker = new Tracker(mVideoSource.Size(), *mpCamera, *mpMap, *mpMapMaker);
mpARDriver = new ARDriver(*mpCamera, mVideoSource.Size(), mGLWindow);
mpMapViewer = new MapViewer(*mpMap, mGLWindow);
GUI.ParseLine("GLWindow.AddMenu Menu Menu");
GUI.ParseLine("Menu.ShowMenu Root");
GUI.ParseLine("Menu.AddMenuButton Root Reset Reset Root");
GUI.ParseLine("Menu.AddMenuButton Root Spacebar PokeTracker Root");
GUI.ParseLine("DrawAR=0");
GUI.ParseLine("DrawMap=0");
GUI.ParseLine("Menu.AddMenuToggle Root \"View Map\" DrawMap Root");
GUI.ParseLine("Menu.AddMenuToggle Root \"Draw AR\" DrawAR Root");
mbDone = false;
};
void System::Run()
{
while(!mbDone)
{
// We use two versions of each video frame:
// One black and white (for processing by the tracker etc)
// and one RGB, for drawing.
// Grab new video frame...
mVideoSource.GetAndFillFrameBWandRGB(mimFrameBW, mimFrameRGB);
static bool bFirstFrame = true;
if(bFirstFrame)
{
mpARDriver->Init();
bFirstFrame = false;
}
mGLWindow.SetupViewport();
mGLWindow.SetupVideoOrtho();
mGLWindow.SetupVideoRasterPosAndZoom();
if(!mpMap->IsGood())
mpARDriver->Reset();
static gvar3<int> gvnDrawMap("DrawMap", 0, HIDDEN|SILENT);
static gvar3<int> gvnDrawAR("DrawAR", 0, HIDDEN|SILENT);
bool bDrawMap = mpMap->IsGood() && *gvnDrawMap;
bool bDrawAR = mpMap->IsGood() && *gvnDrawAR;
mpTracker->TrackFrame(mimFrameBW, !bDrawAR && !bDrawMap);
if(bDrawMap)
mpMapViewer->DrawMap(mpTracker->GetCurrentPose());
else if(bDrawAR)
mpARDriver->Render(mimFrameRGB, mpTracker->GetCurrentPose());
// mGLWindow.GetMousePoseUpdate();
string sCaption;
if(bDrawMap)
sCaption = mpMapViewer->GetMessageForUser();
else
sCaption = mpTracker->GetMessageForUser();
mGLWindow.DrawCaption(sCaption);
mGLWindow.DrawMenus();
mGLWindow.swap_buffers();
mGLWindow.HandlePendingEvents();
}
}
void System::GUICommandCallBack(void *ptr, string sCommand, string sParams)
{
if(sCommand=="quit" || sCommand == "exit")
static_cast<System*>(ptr)->mbDone = true;
}