Initial commit
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2017 The Cartographer Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
using CartographerSharp.Models.Transform;
|
||||
using CartographerSharp.Transform;
|
||||
|
||||
namespace CartographerSharp.Sensor;
|
||||
|
||||
/// <summary>
|
||||
/// Landmark observation structure.
|
||||
/// </summary>
|
||||
public struct LandmarkObservation(string id, Rigid3d landmarkToTrackingTransform, double translationWeight, double rotationWeight)
|
||||
{
|
||||
public string Id { get; set; } = id;
|
||||
public Rigid3d LandmarkToTrackingTransform { get; set; } = landmarkToTrackingTransform;
|
||||
public double TranslationWeight { get; set; } = translationWeight;
|
||||
public double RotationWeight { get; set; } = rotationWeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Landmark data structure.
|
||||
/// </summary>
|
||||
public struct LandmarkData(long time, List<LandmarkObservation>? landmarkObservations = null)
|
||||
{
|
||||
public long Time { get; set; } = time;
|
||||
public List<LandmarkObservation> LandmarkObservations { get; set; } = landmarkObservations ?? [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Operations on LandmarkData.
|
||||
/// </summary>
|
||||
public static class LandmarkDataOperations
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts 'landmark_data' to a proto::LandmarkData.
|
||||
/// </summary>
|
||||
public static Models.Sensor.LandmarkData ToProto(LandmarkData landmarkData)
|
||||
{
|
||||
var proto = new Models.Sensor.LandmarkData(landmarkData.Time, []);
|
||||
|
||||
foreach (var observation in landmarkData.LandmarkObservations)
|
||||
{
|
||||
proto.LandmarkObservations.Add(new Models.Sensor.LandmarkData.LandmarkObservation(
|
||||
System.Text.Encoding.UTF8.GetBytes(observation.Id),
|
||||
(Rigid3dProto)observation.LandmarkToTrackingTransform,
|
||||
observation.TranslationWeight,
|
||||
observation.RotationWeight
|
||||
));
|
||||
}
|
||||
|
||||
return proto;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts 'proto' to an LandmarkData.
|
||||
/// </summary>
|
||||
public static LandmarkData FromProto(Models.Sensor.LandmarkData proto)
|
||||
{
|
||||
var observations = new List<LandmarkObservation>();
|
||||
foreach (var protoObservation in proto.LandmarkObservations)
|
||||
{
|
||||
observations.Add(new LandmarkObservation(
|
||||
System.Text.Encoding.UTF8.GetString(protoObservation.Id),
|
||||
(Rigid3d)protoObservation.LandmarkToTrackingTransform,
|
||||
protoObservation.TranslationWeight,
|
||||
protoObservation.RotationWeight
|
||||
));
|
||||
}
|
||||
|
||||
return new LandmarkData(proto.Timestamp, observations);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user