@@ -287,6 +287,10 @@ def __init__(self, args=VisualizerArgs()):
287
287
# Recording
288
288
self .recorder = None
289
289
290
+ def __resetAfterLost (self ):
291
+ self .map .reset ()
292
+ self .poseTrail .reset ()
293
+
290
294
def __initDisplay (self ):
291
295
from pygame .locals import DOUBLEBUF , OPENGL , FULLSCREEN , GL_MULTISAMPLEBUFFERS , GL_MULTISAMPLESAMPLES
292
296
@@ -430,29 +434,26 @@ def __processUserInput(self):
430
434
if self .cameraMode is CameraMode .THIRD_PERSON : self .cameraControls3D .update (event )
431
435
if self .cameraMode is CameraMode .TOP_VIEW : self .cameraControls2D .update (event )
432
436
433
- def onVioOutput (self , cameraPose , image = None , width = None , height = None , colorFormat = None ):
437
+ def onVioOutput (self , cameraPose , image = None , width = None , height = None , colorFormat = None , status = None ):
434
438
if self .shouldQuit : return
439
+ import spectacularAI
435
440
436
- if image is None :
437
- output = {
438
- "type " : "vio" ,
439
- "cameraPose" : cameraPose ,
440
- "image" : None ,
441
- "width" : self .targetResolution [0 ],
442
- "height" : self .targetResolution [1 ],
443
- "colorFormat" : None
444
- }
445
- else :
441
+ output = {
442
+ "type" : "vio" ,
443
+ "isTracking " : status == spectacularAI . TrackingStatus . TRACKING ,
444
+ "cameraPose" : cameraPose ,
445
+ "image" : None ,
446
+ "width" : self .targetResolution [0 ],
447
+ "height" : self .targetResolution [1 ],
448
+ "colorFormat" : None
449
+ }
450
+ if image is not None :
446
451
# Flip the image upside down for OpenGL.
447
452
if not self .args .flip : image = np .ascontiguousarray (np .flipud (image ))
448
- output = {
449
- "type" : "vio" ,
450
- "cameraPose" : cameraPose ,
451
- "image" : image ,
452
- "width" : width ,
453
- "height" : height ,
454
- "colorFormat" : colorFormat
455
- }
453
+ output ['width' ] = width
454
+ output ['height' ] = height
455
+ output ['colorFormat' ] = colorFormat
456
+
456
457
457
458
if self .outputQueueMutex :
458
459
self .outputQueue .append (output )
@@ -475,24 +476,37 @@ def onMappingOutput(self, mapperOutput):
475
476
476
477
def run (self ):
477
478
vioOutput = None
479
+ wasTracking = False
478
480
479
481
while not self .shouldQuit :
480
482
self .__processUserInput ()
481
483
482
484
# Process VIO & Mapping API outputs
483
- while self . outputQueueMutex and len ( self . outputQueue ) > 0 :
485
+ while True :
484
486
if self .shouldPause : break
485
487
486
- output = self .outputQueue .pop (0 )
488
+ if self .outputQueueMutex and len (self .outputQueue ) > 0 :
489
+ output = self .outputQueue .pop (0 )
490
+ else :
491
+ break
492
+
487
493
if output ["type" ] == "vio" :
488
494
vioOutput = output
489
- cameraPose = vioOutput ["cameraPose" ]
490
- self .poseTrail .append (cameraPose .getPosition ())
495
+ if vioOutput ['isTracking' ]:
496
+ wasTracking = True
497
+ cameraPose = vioOutput ["cameraPose" ]
498
+ self .poseTrail .append (cameraPose .getPosition ())
499
+ else :
500
+ vioOutput = None
501
+ if wasTracking :
502
+ self .__resetAfterLost ()
503
+ wasTracking = False
491
504
# Drop vio outputs if target fps is too low
492
505
if self .args .targetFps == 0 : break
493
506
elif output ["type" ] == "slam" :
494
507
mapperOutput = output ["mapperOutput" ]
495
- self .map .onMappingOutput (mapperOutput )
508
+ if wasTracking : # Don't render if not tracking. Messes up this visualization easily
509
+ self .map .onMappingOutput (mapperOutput )
496
510
if mapperOutput .finalMap and not self .args .keepOpenAfterFinalMap :
497
511
self .shouldQuit = True
498
512
else :
0 commit comments