Skip to content

Commit

Permalink
Minor MR Changes (#271)
Browse files Browse the repository at this point in the history
* bug fix, intrinsics

* depth intrinsics too
  • Loading branch information
sandrist authored Jan 4, 2023
1 parent 6210b75 commit 35cb04c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,7 @@ internal static void Export(this IProducer<EncodedImageCameraView> source, strin
videoImageFile.Write(buffer, 0, eicv.ViewedObject.Resource.Size);
timingFile.WriteLine($"{imageCounter}\t{envelope.OriginatingTime.ToText()}");
poseFile.WriteLine($"{envelope.OriginatingTime.ToText()}\t{eicv.CameraPose.ToText()}");

if (imageCounter == 0)
{
intrinsicsFile.WriteLine(eicv.CameraIntrinsics.ToText());
}

intrinsicsFile.WriteLine($"{envelope.OriginatingTime.ToText()}\t{eicv.CameraIntrinsics.ToText()}");
imageCounter++;
});
}
Expand Down Expand Up @@ -272,12 +267,7 @@ internal static void Export(this IProducer<DepthImageCameraView> source, string
depthImageFile.Write(buffer, 0, buffer.Length);
timingFile.WriteLine($"{depthImageCounter}\t{envelope.OriginatingTime.ToText()}");
poseFile.WriteLine($"{envelope.OriginatingTime.ToText()}\t{edicv.CameraPose.ToText()}");

if (depthImageCounter == 0)
{
intrinsicsFile.WriteLine(edicv.CameraIntrinsics.ToText());
}

intrinsicsFile.WriteLine($"{envelope.OriginatingTime.ToText()}\t{edicv.CameraIntrinsics.ToText()}");
depthImageCounter++;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ static SpatialAnchor TryCreateDefaultWorldSpatialAnchor(SpatialStationaryFrameOf
StereoKitTransforms.StereoKitToWorld = StereoKitTransforms.WorldToStereoKit.Invert();

System.Diagnostics.Trace.WriteLine($"StereoKit origin: {StereoKitTransforms.StereoKitToWorld.Origin.X},{StereoKitTransforms.StereoKitToWorld.Origin.Y},{StereoKitTransforms.StereoKitToWorld.Origin.Z}");
SK.AddStepper(new SpatialTransformsUpdater(worldSpatialAnchor, StereoKitTransforms.StereoKitToWorld.TryConvertPsiCoordinateSystemToSpatialCoordinateSystem()));
SK.AddStepper(new SpatialTransformsUpdater(worldSpatialAnchor));

// TODO: It would be nice if we could actually just shift the origin coordinate system in StereoKit
// to the pose currently defined in StereoKitTransforms.WorldPose.
Expand All @@ -159,12 +159,12 @@ static SpatialAnchor TryCreateDefaultWorldSpatialAnchor(SpatialStationaryFrameOf
private class SpatialTransformsUpdater : IStepper
{
private readonly SpatialAnchor worldSpatialAnchor;
private readonly SpatialCoordinateSystem stereoKitSpatialCoordinateSystem;
private SpatialCoordinateSystem stereoKitSpatialCoordinateSystem;

public SpatialTransformsUpdater(SpatialAnchor worldSpatialAnchor, SpatialCoordinateSystem stereoKitSpatialCoordinateSystem)
public SpatialTransformsUpdater(SpatialAnchor worldSpatialAnchor)
{
this.worldSpatialAnchor = worldSpatialAnchor;
this.stereoKitSpatialCoordinateSystem = stereoKitSpatialCoordinateSystem;
this.stereoKitSpatialCoordinateSystem = StereoKitTransforms.StereoKitToWorld.TryConvertPsiCoordinateSystemToSpatialCoordinateSystem();
}

/// <inheritdoc />
Expand All @@ -176,21 +176,26 @@ public SpatialTransformsUpdater(SpatialAnchor worldSpatialAnchor, SpatialCoordin
/// <inheritdoc />
public void Step()
{
if (this.stereoKitSpatialCoordinateSystem.TryConvertSpatialCoordinateSystemToPsiCoordinateSystem() is null)
{
StereoKitTransforms.StereoKitToWorld = null;
StereoKitTransforms.WorldToStereoKit = null;
StereoKitTransforms.WorldHierarchy = null;
}
else
this.stereoKitSpatialCoordinateSystem ??= StereoKitTransforms.StereoKitToWorld.TryConvertPsiCoordinateSystemToSpatialCoordinateSystem();

if (this.stereoKitSpatialCoordinateSystem is not null)
{
// Query the pose of the world anchor. We use this pose for rendering correctly in the world,
// and for transforming from world coordinates to StereoKit coordinates.
StereoKitTransforms.WorldHierarchy = World.FromPerceptionAnchor(this.worldSpatialAnchor).ToMatrix();
StereoKitTransforms.WorldToStereoKit = StereoKitTransforms.WorldHierarchy.Value.ToCoordinateSystem();
if (this.stereoKitSpatialCoordinateSystem.TryConvertSpatialCoordinateSystemToPsiCoordinateSystem() is null)
{
StereoKitTransforms.StereoKitToWorld = null;
StereoKitTransforms.WorldToStereoKit = null;
StereoKitTransforms.WorldHierarchy = null;
}
else
{
// Query the pose of the world anchor. We use this pose for rendering correctly in the world,
// and for transforming from world coordinates to StereoKit coordinates.
StereoKitTransforms.WorldHierarchy = World.FromPerceptionAnchor(this.worldSpatialAnchor).ToMatrix();
StereoKitTransforms.WorldToStereoKit = StereoKitTransforms.WorldHierarchy.Value.ToCoordinateSystem();

// Inverting gives us a coordinate system that can be used for transforming from StereoKit to world coordinates.
StereoKitTransforms.StereoKitToWorld = StereoKitTransforms.WorldToStereoKit.Invert();
// Inverting gives us a coordinate system that can be used for transforming from StereoKit to world coordinates.
StereoKitTransforms.StereoKitToWorld = StereoKitTransforms.WorldToStereoKit.Invert();
}
}
}

Expand Down

0 comments on commit 35cb04c

Please sign in to comment.