/* * Copyright 2018 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 System.Text.Json; namespace CartographerSharp.Models.Mapping; /// /// Protocol buffer representation of a 2D grid. /// public struct Grid2D { /// /// Cell box for known cells. /// public struct CellBox { [JsonPropertyName("max_x")] public int MaxX { get; set; } [JsonPropertyName("max_y")] public int MaxY { get; set; } [JsonPropertyName("min_x")] public int MinX { get; set; } [JsonPropertyName("min_y")] public int MinY { get; set; } public CellBox(int maxX, int maxY, int minX, int minY) { MaxX = maxX; MaxY = maxY; MinX = minX; MinY = minY; } } [JsonPropertyName("limits")] public MapLimits Limits { get; set; } /// /// These values are actually int16s, but protos don't have a native int16 type. /// [JsonPropertyName("cells")] public List Cells { get; set; } [JsonPropertyName("known_cells_box")] public CellBox KnownCellsBox { get; set; } /// /// Grid type - oneof probability_grid_2d or tsdf_2d. /// Using JsonPolymorphic for oneof support in System.Text.Json. /// [JsonPropertyName("probability_grid_2d")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public ProbabilityGrid? ProbabilityGrid2D { get; set; } [JsonPropertyName("tsdf_2d")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public TSDF2D? Tsdf2D { get; set; } [JsonPropertyName("min_correspondence_cost")] public double MinCorrespondenceCost { get; set; } [JsonPropertyName("max_correspondence_cost")] public double MaxCorrespondenceCost { get; set; } public Grid2D( MapLimits limits, List? cells = null, CellBox knownCellsBox = default, ProbabilityGrid? probabilityGrid2D = null, TSDF2D? tsdf2D = null, double minCorrespondenceCost = 0.0, double maxCorrespondenceCost = 0.0) { Limits = limits; Cells = cells ?? new List(); KnownCellsBox = knownCellsBox; ProbabilityGrid2D = probabilityGrid2D; Tsdf2D = tsdf2D; MinCorrespondenceCost = minCorrespondenceCost; MaxCorrespondenceCost = maxCorrespondenceCost; } }