/* * Copyright 2016 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 System.Collections.Generic; using System.Text.Json.Serialization; using CartographerSharp.Models.Transform; namespace CartographerSharp.Models.Mapping; /// /// Protocol buffer representation of a pose graph. /// public struct PoseGraph { /// /// Submap ID. /// public struct SubmapId { [JsonPropertyName("trajectory_id")] public int TrajectoryId { get; set; } /// /// Submap index in the given trajectory. /// [JsonPropertyName("submap_index")] public int SubmapIndex { get; set; } public SubmapId(int trajectoryId, int submapIndex) { TrajectoryId = trajectoryId; SubmapIndex = submapIndex; } } /// /// Node ID. /// public struct NodeId { [JsonPropertyName("trajectory_id")] public int TrajectoryId { get; set; } /// /// Node index in the given trajectory. /// [JsonPropertyName("node_index")] public int NodeIndex { get; set; } public NodeId(int trajectoryId, int nodeIndex) { TrajectoryId = trajectoryId; NodeIndex = nodeIndex; } } /// /// Constraint in the pose graph. /// public struct Constraint { /// /// Differentiates between intra-submap (where the range data was inserted /// into the submap) and inter-submap constraints (where the range data was /// not inserted into the submap). /// public enum Tag { IntraSubmap = 0, InterSubmap = 1 } /// /// Differentiates between enable state (condition to add to optimization) /// and disable state (do not use to optimize). /// public enum State { Enabled = 0, Disabled = 1 } /// /// Submap ID. /// [JsonPropertyName("submap_id")] public SubmapId SubmapId { get; set; } /// /// Node ID. /// [JsonPropertyName("node_id")] public NodeId NodeId { get; set; } /// /// Pose of the node relative to submap, i.e. taking data from the node frame /// into the submap frame. /// [JsonPropertyName("relative_pose")] public Rigid3dProto RelativePose { get; set; } /// /// Weight of the translational part of the constraint. /// [JsonPropertyName("translation_weight")] public double TranslationWeight { get; set; } /// /// Weight of the rotational part of the constraint. /// [JsonPropertyName("rotation_weight")] public double RotationWeight { get; set; } /// /// Tag indicating constraint type. /// [JsonPropertyName("tag")] public Tag ConstraintTag { get; set; } /// /// Score of the constraint. /// [JsonPropertyName("score")] public double Score { get; set; } /// /// State of the constraint (enabled or disabled). /// [JsonPropertyName("state")] public State ConstraintState { get; set; } public Constraint( SubmapId submapId, NodeId nodeId, Rigid3dProto relativePose, double translationWeight, double rotationWeight, Tag constraintTag, double score = 0.0, State constraintState = State.Enabled) { SubmapId = submapId; NodeId = nodeId; RelativePose = relativePose; TranslationWeight = translationWeight; RotationWeight = rotationWeight; ConstraintTag = constraintTag; Score = score; ConstraintState = constraintState; } } /// /// Landmark pose in the pose graph. /// public struct LandmarkPose { [JsonPropertyName("landmark_id")] public string LandmarkId { get; set; } [JsonPropertyName("global_pose")] public Rigid3dProto GlobalPose { get; set; } public LandmarkPose(string landmarkId, Rigid3dProto globalPose) { LandmarkId = landmarkId; GlobalPose = globalPose; } } /// /// Accurate submap in the pose graph. /// public struct AccurateSubmap { [JsonPropertyName("submap_id")] public SubmapId SubmapId { get; set; } [JsonPropertyName("parent_id")] public SubmapId ParentId { get; set; } [JsonPropertyName("pose")] public Rigid2dProto Pose { get; set; } [JsonPropertyName("parent_relative_pose")] public Rigid2dProto ParentRelativePose { get; set; } /// /// Stop station in the accurate submap. /// public struct StopStation { public enum StopStationType { StartPoint = 0, StopPoint = 1 } [JsonPropertyName("pose")] public Rigid2dProto Pose { get; set; } [JsonPropertyName("type")] public StopStationType Type { get; set; } public StopStation(Rigid2dProto pose, StopStationType type) { Pose = pose; Type = type; } } [JsonPropertyName("stop_stations")] public List StopStations { get; set; } [JsonPropertyName("is_shelf")] public bool IsShelf { get; set; } public AccurateSubmap( SubmapId submapId, SubmapId parentId, Rigid2dProto pose, Rigid2dProto parentRelativePose, List? stopStations = null, bool isShelf = false) { SubmapId = submapId; ParentId = parentId; Pose = pose; ParentRelativePose = parentRelativePose; StopStations = stopStations ?? new List(); IsShelf = isShelf; } } [JsonPropertyName("constraint")] public List Constraints { get; set; } [JsonPropertyName("trajectory")] public List Trajectories { get; set; } [JsonPropertyName("landmark_poses")] public List LandmarkPoses { get; set; } [JsonPropertyName("accurate_submaps")] public List AccurateSubmaps { get; set; } [JsonPropertyName("transform_to_map")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public Rigid3dProto? TransformToMap { get; set; } public PoseGraph( List? constraints = null, List? trajectories = null, List? landmarkPoses = null, List? accurateSubmaps = null, Rigid3dProto? transformToMap = null) { Constraints = constraints ?? new List(); Trajectories = trajectories ?? new List(); LandmarkPoses = landmarkPoses ?? new List(); AccurateSubmaps = accurateSubmaps ?? new List(); TransformToMap = transformToMap; } }