namespace mola

Overview

@file VizInterface.cpp @brief Virtual visualization interface (see MolaViz) @author Jose Luis Blanco Claraco @date Feb 15, 2026

namespace mola {

// namespaces

namespace mola::detail;
namespace mola::factors;
namespace mola::gui;
namespace mola::imu;
namespace mola::state_estimation_simple;
namespace mola::state_estimation_smoother;

// typedefs

typedef std::allocator<T> FastAllocator;
typedef std::set<T, Compare, FastAllocator<T>> fast_set;
typedef std::map<Key, T, Compare, FastAllocator<std::pair<const Key, T>>> fast_map;
typedef std::uint64_t id_t;
typedef std::uint64_t fid_t;
typedef mrpt::system::CTimeLogger Profiler;
typedef mrpt::system::CTimeLoggerEntry ProfilerEntry;
typedef mrpt::system::CTimeLoggerSaveAtDtor ProfilerSaverAtDtor;
typedef mrpt::poses::CPose3DInterpolator trajectory_t;
typedef mrpt::obs::CObservation CObservation;
typedef std::size_t timestep_t;
typedef mrpt::containers::yaml Yaml;
typedef std::variant<std::monostate, SensorCamera, SensorIMU> SensorEntry;
typedef uint64_t euroc_timestamp_t;
typedef std::multimap<euroc_timestamp_t, SensorEntry> euroc_dataset_t;

// enums

enum DiagnosticLevel;
enum InitLocalization;
enum InputMode;

// structs

struct AddGNSSFactorParams;
struct AddIMUGravityFactorParams;
struct DiagnosticKeyValue;
struct DiagnosticStatusMsg;
struct FrameGNSS;
struct FrameIMUAcc;
struct GNSSFrames;
struct Georeferencing;
struct IMUAccFrames;
struct NavState;
struct RelocalizationICP_SE2;
struct RelocalizationLikelihood_SE2;
struct SMGeoReferencingOutput;
struct SMGeoReferencingParams;
struct SensorCamera;
struct SensorIMU;
struct YAMLParseOptions;

template <typename cell_coord_t = int32_t>
struct index3d_hash;

template <typename cell_coord_t = int32_t>
struct index3d_t;

template <typename cell_coord_t = int32_t>
struct index_se3_t;

template <typename cell_coord_t = int32_t>
struct index_se3_t_hash;

template <class... Ts>
struct overloaded;

// classes

class BinFileDataset;
class BridgeROS2;
class Dataset_UI;
class DiagnosticsProvider;
class EurocDataset;
class ExecutableBase;
class FilterBase;

template <typename T, size_t SIDE_NUM_BITS, typename inner_coord_t>
class FixedDenseGrid3D;

class FrontEndBase;
class GravityMapAligner;
class HashedSetSE3;
class HashedVoxelPointCloud;
class KeyframeMapCapable;
class KeyframePointCloudMap;
class Kitti360Dataset;
class KittiOdometryDataset;
class LidarOdometry;
class LocalizationSourceBase;
class MapServer;
class MapSourceBase;
class MinimalModuleContainer;
class MockDiagModule;
class MolaLauncherApp;
class MolaViz;
class MolaVizImGui;
class MolaVizImGuiCore;
class MulranDataset;
class NDT;
class NavStateFilter;
class OccGrid;
class OfflineDatasetSource;
class OptionsCapable;
class ParisLucoDataset;
class RawDataConsumer;
class RawDataSourceBase;
class RawlogDataset;
class RegexCache;
class Relocalization;
class Rosbag2Dataset;
class SearchablePoseList;
class SparseTreesPointCloud;
class SparseVoxelPointCloud;
class Synchronizer;
class TrajectoryRebaker;
class VideoDataset;
class VizInterface;

// global variables

constexpr id_t INVALID_ID = std::numeric_limits<id_t>::max();
constexpr fid_t INVALID_FID = std::numeric_limits<fid_t>::max();

// global functions

void pretty_print_exception(
    const std::exception& e,
    const std::string& headerLine,
    const bool use_std_cerr = true
    );

template <class... Ts>
overloaded(Ts...);

template <typename cell_coord_t>
std::ostream& operator << (
    std::ostream& o,
    const index3d_t<cell_coord_t>& idx
    );

void exportLoadableOptionsToIni(
    const mrpt::config::CLoadableOptions& opts,
    mrpt::config::CConfigFileBase& cfg,
    const std::string& section,
    const std::set<std::string>& excludeKeys = {}
    );

bool importLoadableOptionsFromIni(
    mrpt::config::CLoadableOptions& opts,
    const mrpt::config::CConfigFileBase& cfg,
    const std::string& section
    );

bool exportMapLayerOptionsToIni(
    mrpt::maps::CMetricMap& map,
    mrpt::config::CConfigFileBase& cfg,
    const std::string& layerName
    );

bool importMapLayerOptionsFromIni(
    mrpt::maps::CMetricMap& map,
    const mrpt::config::CConfigFileBase& cfg,
    const std::string& layerName,
    std::vector<std::string>* appliedSections = nullptr,
    std::vector<std::string>* rejectedSections = nullptr
    );

template <typename cell_coord_t>
std::ostream& operator << (
    std::ostream& o,
    const index_se3_t<cell_coord_t>& idx
    );

auto find_best_poses_se2(const mrpt::poses::CPosePDFGrid& grid, const double percentile = 0.99);
std::string parse_yaml(const std::string& text, const YAMLParseOptions& opts = YAMLParseOptions());
mrpt::containers::yaml parse_yaml(const mrpt::containers::yaml& input, const YAMLParseOptions& opts = YAMLParseOptions());
mrpt::containers::yaml load_yaml_file(const std::string& fileName, const YAMLParseOptions& opts = YAMLParseOptions());
std::string yaml_to_string(const mrpt::containers::yaml& cfg);

template <std::size_t N, typename T>
constexpr std::array<T, N> create_array(const T& value);

SMGeoReferencingOutput simplemap_georeference(const mrpt::maps::CSimpleMap& sm, const SMGeoReferencingParams& params = {});

GNSSFrames extract_gnss_frames_from_sm(
    const mrpt::maps::CSimpleMap& sm,
    const std::optional<mrpt::topography::TGeodeticCoords>& refCoord = std::nullopt,
    unsigned int minimumFixQuality = 0
    );

IMUAccFrames extract_imu_acc_frames_from_sm(const mrpt::maps::CSimpleMap& sm);

void add_imu_gravity_factors(
    gtsam::NonlinearFactorGraph& fg,
    gtsam::Values& v,
    const IMUAccFrames& imuFrames,
    const std::set<size_t>& existingPoseKeys,
    const AddIMUGravityFactorParams& params
    );

void add_gnss_factors(
    gtsam::NonlinearFactorGraph& fg,
    gtsam::Values& v,
    const GNSSFrames& frames,
    const AddGNSSFactorParams& params
    );

} // namespace mola

Typedefs

typedef mrpt::poses::CPose3DInterpolator trajectory_t

We reuse mrpt::poses::CPose3DInterpolator as a time-indexed map of SE(3) poses

typedef std::size_t timestep_t

0-based indices of observations in a dataset

typedef mrpt::containers::yaml Yaml

Convenient typedef to save typing in the MOLA project.

Global Functions

template <class... Ts>
overloaded(Ts...)

Based on https://en.cppreference.com/w/cpp/utility/variant/visit

void exportLoadableOptionsToIni(
    const mrpt::config::CLoadableOptions& opts,
    mrpt::config::CConfigFileBase& cfg,
    const std::string& section,
    const std::set<std::string>& excludeKeys = {}
    )

Dumps all parameters of opts (via its dumpToTextStream(), which all known CLoadableOptions implement) as key = value entries under section in cfg.

This indirect route (instead of calling saveToConfigFile() directly) is needed because several CLoadableOptions subclasses in this library (and in MRPT itself) only override dumpToTextStream(), not saveToConfigFile(), which would otherwise throw.

Any key listed in excludeKeys is skipped entirely (neither written nor overwritten), which is used to work around individual fields whose dumpToTextStream()/loadFromConfigFile() pair is known to be inconsistent in some MRPT classes (e.g. unit mismatches, or values that get truncated for display and can no longer be parsed back). Importing such a field then simply leaves it at whatever value it already had.

bool importLoadableOptionsFromIni(
    mrpt::config::CLoadableOptions& opts,
    const mrpt::config::CConfigFileBase& cfg,
    const std::string& section
    )

If section exists in cfg, calls opts.loadFromConfigFile() on it and returns true. Otherwise leaves opts untouched and returns false.

bool exportMapLayerOptionsToIni(
    mrpt::maps::CMetricMap& map,
    mrpt::config::CConfigFileBase& cfg,
    const std::string& layerName
    )

Exports all CLoadableOptions structures of map into cfg, one section per structure, named "<layerName>.<structName>". If map implements mola::OptionsCapable, the set of structures (and their names) is obtained generically via OptionsCapable::optionsByName() this covers all classes in this library, present and future, without needing per-class code here. Otherwise, a fallback handles basic mrpt::maps classes (CPointsMap and derivatives, COccupancyGridMap2D) via dynamic_cast.

Also writes a [<layerName>] section with a class key holding the MRPT RTTI class name, used by importMapLayerOptionsFromIni() as a sanity check.

Returns:

false if map is none of the known, supported classes (nothing is written).

bool importMapLayerOptionsFromIni(
    mrpt::maps::CMetricMap& map,
    const mrpt::config::CConfigFileBase& cfg,
    const std::string& layerName,
    std::vector<std::string>* appliedSections = nullptr,
    std::vector<std::string>* rejectedSections = nullptr
    )

The reverse of exportMapLayerOptionsToIni() : for each of map ‘s CLoadableOptions structures whose section is present in cfg, loads it from cfg into map.

Sections absent from cfg are silently skipped, leaving the corresponding options untouched. Names of the sections actually applied are appended to appliedSections, if provided.

The “creationOptions” structure (if present) is handled specially: instead of being overwritten directly, the new values are passed to OptionsCapable::trySetCreationOptions(), which may refuse to apply them (e.g. a voxel size change that would require discarding the map’s current contents). Section names refused this way are appended to rejectedSections, if provided, instead of appliedSections.

Returns:

false if map is none of the known, supported classes (nothing is read).

SMGeoReferencingOutput simplemap_georeference(const mrpt::maps::CSimpleMap& sm, const SMGeoReferencingParams& params = {})

Function to georeferencing a given SimpleMap with GNSS observations. A minimum of 3 (non-colinear) KFs with GNSS data are required to solve for the optimal transformation.

void add_imu_gravity_factors(
    gtsam::NonlinearFactorGraph& fg,
    gtsam::Values& v,
    const IMUAccFrames& imuFrames,
    const std::set<size_t>& existingPoseKeys,
    const AddIMUGravityFactorParams& params
    )

Adds MeasuredGravityFactor factors to the graph. Creates new P(kf_index) variables for keyframes not already present in existingPoseKeys.