/*
* 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.Mapping;
using CartographerSharp.Transform;
namespace CartographerSharp.Mapping;
///
/// This interface is used for both library and RPC implementations.
/// Implementations wire up the complete SLAM stack.
///
public interface IMapBuilder : IDisposable
{
///
/// Creates a new trajectory builder and returns its index.
///
int AddTrajectoryBuilder(
HashSet expectedSensorIds,
TrajectoryBuilderOptions trajectoryOptions);
///
/// Creates a new trajectory and returns its index. Querying the trajectory
/// builder for it will return 'null'.
///
int AddTrajectoryForDeserialization(
TrajectoryBuilderOptionsWithSensorIds optionsWithSensorIdsProto);
///
/// Returns the 'ITrajectoryBuilder' corresponding to the specified
/// 'trajectory_id' or 'null' if the trajectory has no corresponding builder.
///
ITrajectoryBuilder? GetTrajectoryBuilder(int trajectoryId);
///
/// Marks the TrajectoryBuilder corresponding to 'trajectory_id' as finished,
/// i.e. no further sensor data is expected.
///
void FinishTrajectory(int trajectoryId);
///
/// Fills the SubmapQuery::Response corresponding to 'submap_id'. Returns an
/// error string on failure, or an empty string on success.
///
string SubmapToProto(SubmapId submapId, out Models.Mapping.SubmapQuery.Response response);
///
/// Serializes the current state to a proto stream. If
/// 'include_unfinished_submaps' is set to true, unfinished submaps, i.e.
/// submaps that have not yet received all rangefinder data insertions, will
/// be included in the serialized state.
///
void SerializeState(bool includeUnfinishedSubmaps, IO.IProtoStreamWriter writer);
///
/// Serializes the current state to a proto stream file on the host system.
/// Returns true if the file was successfully written.
///
bool SerializeStateToFile(bool includeUnfinishedSubmaps, string filename);
///
/// Loads the SLAM state from a proto stream. Returns the remapping of new trajectory_ids.
///
Dictionary LoadState(IO.IProtoStreamReader reader, bool loadFrozenState);
///
/// Loads the SLAM state from a pbstream file. Returns the remapping of new trajectory_ids.
///
Dictionary LoadStateFromFile(string filename, bool loadFrozenState);
///
/// Starts relocalization (match C++ MapBuilder::StartRelocalization).
/// Sets pose graph localization callback and initial poses so constraint builder
/// uses them when finding constraints (MaybeAddLocalizationConstraint).
/// Call after AddTrajectoryBuilder when starting localization (e.g. xloc calls
/// StartRelocalization(initial_poses, callback) after AddTrajectory).
///
/// Initial poses in global frame (e.g. from MCL).
/// Invoked when relocalization succeeds or when max nodes searched without success (trajectoryId=-1).
void StartRelocalization(IReadOnlyList initialPoses, Action? callback);
int NumTrajectoryBuilders { get; }
IPoseGraph PoseGraph { get; }
List GetAllTrajectoryBuilderOptions();
}