Skip to content

Commit 7febb54

Browse files
committed
Visualizer tweaks: handle lost tracking status
1 parent f6b3eba commit 7febb54

File tree

2 files changed

+51
-30
lines changed

2 files changed

+51
-30
lines changed

python/cli/visualization/visualizer.py

Lines changed: 38 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,10 @@ def __init__(self, args=VisualizerArgs()):
287287
# Recording
288288
self.recorder = None
289289

290+
def __resetAfterLost(self):
291+
self.map.reset()
292+
self.poseTrail.reset()
293+
290294
def __initDisplay(self):
291295
from pygame.locals import DOUBLEBUF, OPENGL, FULLSCREEN, GL_MULTISAMPLEBUFFERS, GL_MULTISAMPLESAMPLES
292296

@@ -430,29 +434,26 @@ def __processUserInput(self):
430434
if self.cameraMode is CameraMode.THIRD_PERSON: self.cameraControls3D.update(event)
431435
if self.cameraMode is CameraMode.TOP_VIEW: self.cameraControls2D.update(event)
432436

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):
434438
if self.shouldQuit: return
439+
import spectacularAI
435440

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:
446451
# Flip the image upside down for OpenGL.
447452
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+
456457

457458
if self.outputQueueMutex:
458459
self.outputQueue.append(output)
@@ -475,24 +476,37 @@ def onMappingOutput(self, mapperOutput):
475476

476477
def run(self):
477478
vioOutput = None
479+
wasTracking = False
478480

479481
while not self.shouldQuit:
480482
self.__processUserInput()
481483

482484
# Process VIO & Mapping API outputs
483-
while self.outputQueueMutex and len(self.outputQueue) > 0:
485+
while True:
484486
if self.shouldPause: break
485487

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+
487493
if output["type"] == "vio":
488494
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
491504
# Drop vio outputs if target fps is too low
492505
if self.args.targetFps == 0: break
493506
elif output["type"] == "slam":
494507
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)
496510
if mapperOutput.finalMap and not self.args.keepOpenAfterFinalMap:
497511
self.shouldQuit = True
498512
else:

python/cli/visualization/visualizer_renderers/renderers.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,7 @@ def __init__(
7777
renderSparsePointCloud='auto',
7878
renderKeyFrames=True,
7979
renderMesh=False):
80-
self.keyFrameCameraToWorldMatrices = {}
81-
self.pointCloudRenderers = {}
82-
self.sparsePointCloudRenderer = None
8380
self.renderSparsePointCloud = renderSparsePointCloud
84-
self.keyFrameRenderer = KeyFrameRenderer()
85-
# self.meshRenderer = MeshRenderer() # TODO: fix
8681

8782
# constant for entire visualization
8883
self.voxelSize = 0 if voxelSize is None else voxelSize
@@ -99,6 +94,8 @@ def __init__(
9994
self.maxRenderKeyFrames = keyFrameCount
10095
self.colorMode = colorMode
10196

97+
self.reset()
98+
10299
def onMappingOutput(self, mapperOutput):
103100
for kfId in mapperOutput.updatedKeyFrames:
104101
keyFrame = mapperOutput.map.keyFrames.get(kfId)
@@ -177,6 +174,13 @@ def setColorMode(self, mode):
177174
def setMaxRenderKeyFrames(self, n):
178175
self.maxRenderKeyFrames = n
179176

177+
def reset(self):
178+
self.keyFrameCameraToWorldMatrices = {}
179+
self.pointCloudRenderers = {}
180+
self.sparsePointCloudRenderer = None
181+
self.keyFrameRenderer = KeyFrameRenderer()
182+
# self.meshRenderer = MeshRenderer() # TODO: fix
183+
180184
def render(self, cameraPositionWorld, viewMatrix, projectionMatrix):
181185
n = len(self.pointCloudRenderers) if self.maxRenderKeyFrames is None else self.maxRenderKeyFrames
182186

@@ -203,10 +207,13 @@ def renderPointCloud():
203207

204208
class PoseTrailRenderer:
205209
def __init__(self, maxLength=None, color=np.array(DEFAULT_POSE_TRAIL_RGBA), lineWidth=2.0):
206-
self.poseTrail = []
207210
self.color = color
208211
self.maxLength = maxLength
209212
self.lineWidth = lineWidth
213+
self.reset()
214+
215+
def reset(self):
216+
self.poseTrail = []
210217

211218
def append(self, position):
212219
position = np.array([position.x, position.y, position.z])

0 commit comments

Comments
 (0)