/* * 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; /// /// Landmark observation structure. /// 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; } /// /// Landmark data structure. /// public struct LandmarkData(long time, List? landmarkObservations = null) { public long Time { get; set; } = time; public List LandmarkObservations { get; set; } = landmarkObservations ?? []; } /// /// Operations on LandmarkData. /// public static class LandmarkDataOperations { /// /// Converts 'landmark_data' to a proto::LandmarkData. /// 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; } /// /// Converts 'proto' to an LandmarkData. /// public static LandmarkData FromProto(Models.Sensor.LandmarkData proto) { var observations = new List(); 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); } }