forked from ScanNet/ScanNet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.h
More file actions
330 lines (240 loc) · 9.59 KB
/
ViewController.h
File metadata and controls
330 lines (240 loc) · 9.59 KB
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/*
This file is part of the Structure SDK.
Copyright © 2015 Occipital, Inc. All rights reserved.
http://structure.io
*/
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreMotion/CoreMotion.h>
#define HAS_LIBCXX
#import <Structure/Structure.h>
#import "GPUImage.h"
#include <string>
#include <vector>
#import "Config.h"
struct Options //TODO get rid of mesh view/tracking params
{
// Whether we should use depth aligned to the color viewpoint when Structure Sensor was calibrated.
// This setting may get overwritten to false if no color camera can be used.
bool useHardwareRegisteredDepth = false;
// Focus position for the color camera (between 0 and 1). Must remain fixed one depth streaming
// has started when using hardware registered depth.
const float lensPosition = 0.75f;
unsigned int colorEncodeBitrate = 5000;
//meta-data (res, intrinsics)
unsigned int colorWidth = 640;
unsigned int colorHeight = 480;
unsigned int depthWidth = 640;
unsigned int depthHeight = 480;
float colorFocalX = 578.0f; float colorFocalY = 578.0f; float colorCenterX = 320.0f; float colorCenterY = 240.0f; //default for VGA
float depthFocalX = 570.5f; float depthFocalY = 570.5f; float depthCenterX = 320.0f; float depthCenterY = 240.0f; //default for VGA
bool useHalfResColor = false;
float colorToDepthExtrinsics[16];
std::string sceneLabel = "";
std::string deviceId = "";
std::string deviceName = "";
std::string specifiedSceneType = "";
std::string userName = "";
};
enum ScannerState
{
// scene label - wait for label (can't can until have one)
ScannerStateSceneLabelling = 0,
// before scanning (let user toggle awb, find good first frame)
ScannerStateCubePlacement,
// Scanning (scan!)
ScannerStateScanning,
// View all uploads
ScannerStateViewing,
NumStates
};
// SLAM-related members.
struct SlamData
{
SlamData ()
: initialized (false)
, scannerState (ScannerStateCubePlacement)
{}
BOOL initialized;
BOOL showingMemoryWarning = false;
NSTimeInterval prevFrameTimeStamp = -1.0;
ScannerState scannerState;
};
struct AppStatus
{
NSString* const pleaseConnectSensorMessage = @"Please connect Structure Sensor.";
NSString* const pleaseChargeSensorMessage = @"Please charge Structure Sensor.";
NSString* const needColorCameraAccessMessage = @"This app requires camera access to capture color.\nAllow access by going to Settings → Privacy → Camera.";
NSString* const needIntrinsicsMessage = @"No intrinsics received. Please restart the app.";
enum SensorStatus
{
SensorStatusOk,
SensorStatusNeedsUserToConnect,
SensorStatusNeedsUserToCharge,
SensorStatusNeedsIntrinsics,
};
// Structure Sensor status.
SensorStatus sensorStatus = SensorStatusOk;
// Whether iOS camera access was granted by the user.
bool colorCameraIsAuthorized = true;
// Whether there is currently a message to show.
bool needsDisplayOfStatusMessage = false;
// Flag to disable entirely status message display.
bool statusMessageDisabled = false;
};
// Display related members.
struct DisplayData
{
DisplayData ()
{
}
~DisplayData ()
{
if (lumaTexture)
{
CFRelease (lumaTexture);
lumaTexture = NULL;
}
if (chromaTexture)
{
CFRelease (chromaTexture);
lumaTexture = NULL;
}
if (videoTextureCache)
{
CFRelease(videoTextureCache);
videoTextureCache = NULL;
}
/*
if (corners)
{
corners = NULL;
}*/
}
// OpenGL context.
EAGLContext *context;
// OpenGL Texture reference for y images.
CVOpenGLESTextureRef lumaTexture;
// OpenGL Texture reference for color images.
CVOpenGLESTextureRef chromaTexture;
// OpenGL Texture cache for the color camera.
CVOpenGLESTextureCacheRef videoTextureCache;
// Shader to render a GL texture as a simple quad.
STGLTextureShaderYCbCr *yCbCrTextureShader;
STGLTextureShaderRGBA *rgbaTextureShader;
STGLTextureShaderGray *grayTextureShader;
GLuint depthAsRgbaTexture;
GLuint grayTexture;
//uint8_t* cornerBuffer;
// Renders the volume boundaries as a cube.
//STCubeRenderer *cubeRenderer;
// OpenGL viewport.
GLfloat viewport[4];
// OpenGL projection matrix for the color camera.
GLKMatrix4 colorCameraGLProjectionMatrix = GLKMatrix4Identity;
// OpenGL projection matrix for the depth camera.
GLKMatrix4 depthCameraGLProjectionMatrix = GLKMatrix4Identity;
};
@interface ViewController : UIViewController <STBackgroundTaskDelegate, //MeshViewDelegate,
UIPopoverControllerDelegate, UIGestureRecognizerDelegate, NSURLSessionTaskDelegate, UITableViewDelegate, UITableViewDataSource, UIPickerViewDataSource, UIPickerViewDelegate>
{
// Structure Sensor controller.
STSensorController *_sensorController;
STStreamConfig _structureStreamConfig;
SlamData _slamState;
Options _options;
// Manages the app status messages.
AppStatus _appStatus;
DisplayData _display;
// Most recent gravity vector from IMU.
GLKVector3 _lastGravity;
// Scale of the scanning volume.
//PinchScaleState _volumeScale;
// IMU handling.
CMMotionManager *_motionManager;
NSOperationQueue *_imuQueue;
NSOperationQueue *_uploadQueue;
NSOperationQueue *_verifyQueue;
STDepthToRgba *_depthAsRgbaVisualizer;
bool _useColorCamera;
bool _renderDepthOverlay;
FILE *g_imuFile;
NSLock* g_imuLock;
unsigned int g_numIMUmeasurements;
FILE *g_cameraFile;
NSLock* g_cameraLock;
std::vector<NSTimeInterval> _colorTimestamps; // NSTimeInterval : double
std::vector<NSTimeInterval> _depthTimestamps; // NSTimeInterval : double
NSTimer *uploadErrorTimer;
NSUInteger blinkCounter;
NSMutableArray *myScanData;
NSMutableArray *sceneTypes;
NSString* specifiedSceneType;
NSMutableArray *corners;
//For Upload Task
NSURLSession *defaultSession;
int numPreviousCorners[12];
int numPrevFramesTracked;
NSArray *exposureLevels;
NSString* exposureValue;
}
@property (weak, nonatomic) IBOutlet UIButton *toggleDepthButton;
@property (weak, nonatomic) IBOutlet UIButton *uploadButton;
@property (weak, nonatomic) IBOutlet UITextField *sceneLabelField;
@property (weak, nonatomic) IBOutlet UIView *sceneLabelFieldView;
@property (weak, nonatomic) IBOutlet UIProgressView *memProgressView;
@property (weak, nonatomic) IBOutlet UIView *memProgressFieldView;
@property (weak, nonatomic) IBOutlet UITextField *userNameField;
@property (weak, nonatomic) IBOutlet UIView *optionsView;
@property (weak, nonatomic) IBOutlet UISegmentedControl *colorResControl;
@property (nonatomic, retain) AVCaptureSession *avCaptureSession;
@property (nonatomic, retain) AVCaptureDevice *videoDevice;
@property (weak, nonatomic) IBOutlet UILabel *appStatusMessageLabel;
@property (weak, nonatomic) IBOutlet UIButton *scanButton;
@property (weak, nonatomic) IBOutlet UIButton *resetButton;
@property (weak, nonatomic) IBOutlet UIButton *doneButton;
@property (weak, nonatomic) IBOutlet UILabel *trackingLostLabel;
@property (weak, nonatomic) IBOutlet UIProgressView *progressView;
@property (weak, nonatomic) IBOutlet UILabel *uploadErrorIndicator;
@property (weak, nonatomic) IBOutlet UIButton *viewScans;
@property (weak, nonatomic) IBOutlet UITableView *exposureTable;
@property (nonatomic, retain) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UILabel *tooCloseLabel;
@property (weak, nonatomic) IBOutlet UIProgressView *numCornersProgressView;
@property (weak, nonatomic) IBOutlet UIButton *changeExposure;
@property (weak, nonatomic) IBOutlet UILabel *AWBLabel;
//@property (weak, nonatomic) IBOutlet UILabel *percentTooClose;
@property (weak, nonatomic) IBOutlet UILabel *losingTrackingLabel;
@property (weak, nonatomic) IBOutlet UIPickerView *pickSceneType;
@property (weak, nonatomic) IBOutlet UILabel *uploadErrorDescription;
@property (weak, nonatomic) IBOutlet UISwitch *AWBSwitch;
- (IBAction)awbSwitchChanged:(id)sender;
- (IBAction)indexChanged:(UISegmentedControl *)sender;
//- (IBAction)enableNewTrackerSwitchChanged:(id)sender;
- (IBAction)scanButtonPressed:(id)sender;
- (IBAction)resetButtonPressed:(id)sender;
- (IBAction)doneButtonPressed:(id)sender;
- (IBAction)uploadButtonPressed:(id)sender;
- (IBAction)sceneLabelFieldEdited:(id)sender;
- (IBAction)toggleDepthButtonPressed:(id)sender;
- (IBAction)viewScansPressed:(id)sender;
- (IBAction)userNameFieldEdited:(id)sender;
- (IBAction)changeExposurePressed:(id)sender;
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
//- (UITableView *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
- (BOOL)isConnectedToWIFI;
- (void)enterSceneLabellingState;
- (void)enterCubePlacementState;
- (void)enterScanningState;
- (void)enterViewingState;
- (void)updateAppStatusMessage;
- (BOOL)currentStateNeedsSensor;
- (void)updateIdleTimer;
- (void)showTrackingMessage:(NSString*)message;
- (void)hideTrackingErrorMessage;
- (void)updateColorRes:(NSInteger)index;
- (void)loadOptions;
- (void)loadSceneLabel;
- (void)cleanUpAndReset;
- (void)blinkUploadErrorIndicator;
@end