| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // This file is part of INSTINCT, the INS Toolkit for Integrated | ||
| 2 | // Navigation Concepts and Training by the Institute of Navigation of | ||
| 3 | // the University of Stuttgart, Germany. | ||
| 4 | // | ||
| 5 | // This Source Code Form is subject to the terms of the Mozilla Public | ||
| 6 | // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| 7 | // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
| 8 | |||
| 9 | /// @file PositionInput.hpp | ||
| 10 | /// @brief Position Input GUI widgets | ||
| 11 | /// @author T. Topp (topp@ins.uni-stuttgart.de) | ||
| 12 | /// @date 2023-08-14 | ||
| 13 | |||
| 14 | #pragma once | ||
| 15 | |||
| 16 | #include <cstdint> | ||
| 17 | #include <Eigen/Core> | ||
| 18 | #include <nlohmann/json.hpp> | ||
| 19 | using json = nlohmann::json; ///< json namespace | ||
| 20 | |||
| 21 | #include "Navigation/Transformations/Units.hpp" | ||
| 22 | #include "Navigation/Transformations/CoordinateFrames.hpp" | ||
| 23 | |||
| 24 | namespace NAV | ||
| 25 | { | ||
| 26 | namespace gui::widgets | ||
| 27 | { | ||
| 28 | |||
| 29 | /// Position with Reference frame, used for GUI input | ||
| 30 | struct PositionWithFrame | ||
| 31 | { | ||
| 32 | /// Reference frames | ||
| 33 | enum class ReferenceFrame : uint8_t | ||
| 34 | { | ||
| 35 | ECEF, ///< Earth-centered Earth-fixed | ||
| 36 | LLA, ///< Latitude, Longitude, Altitude | ||
| 37 | COUNT, ///< Amount of items in the enum | ||
| 38 | }; | ||
| 39 | |||
| 40 | /// Reference frame used for the input, not for the storage of values | ||
| 41 | ReferenceFrame frame = ReferenceFrame::LLA; | ||
| 42 | /// Position in ECEF coordinates in [m] | ||
| 43 | Eigen::Vector3d e_position = trafo::lla2ecef_WGS84(Eigen::Vector3d::Zero()); | ||
| 44 | |||
| 45 | /// Latitude in [rad] | ||
| 46 |
2/4✓ Branch 1 taken 273008 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273008 times.
✗ Branch 5 not taken.
|
273008 | [[nodiscard]] double latitude() const { return trafo::ecef2lla_WGS84(e_position)(0); } |
| 47 | /// Longitude in [rad] | ||
| 48 |
2/4✓ Branch 1 taken 273008 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 273008 times.
✗ Branch 5 not taken.
|
273008 | [[nodiscard]] double longitude() const { return trafo::ecef2lla_WGS84(e_position)(1); } |
| 49 | /// Altitude in [m] | ||
| 50 | ✗ | [[nodiscard]] double altitude() const { return trafo::ecef2lla_WGS84(e_position)(2); } | |
| 51 | /// Latitude in [deg] | ||
| 52 | [[nodiscard]] double latitude_deg() const { return trafo::ecef2lla_WGS84(e_position)(0); } | ||
| 53 | /// Longitude in [deg] | ||
| 54 | [[nodiscard]] double longitude_deg() const { return trafo::ecef2lla_WGS84(e_position)(1); } | ||
| 55 | |||
| 56 | /// Latitude in [rad, rad, m] | ||
| 57 | 6718756 | [[nodiscard]] Eigen::Vector3d latLonAlt() const { return trafo::ecef2lla_WGS84(e_position); } | |
| 58 | /// Latitude in [deg, deg, m] | ||
| 59 | [[nodiscard]] Eigen::Vector3d latLonAlt_deg() const | ||
| 60 | { | ||
| 61 | auto lla = trafo::ecef2lla_WGS84(e_position); | ||
| 62 | return { rad2deg(lla(0)), rad2deg(lla(1)), lla(2) }; | ||
| 63 | } | ||
| 64 | }; | ||
| 65 | |||
| 66 | /// @brief Converts the provided Object into a json object | ||
| 67 | /// @param[out] j Return Json object | ||
| 68 | /// @param[in] refFrame Object to convert | ||
| 69 | void to_json(json& j, const PositionWithFrame::ReferenceFrame& refFrame); | ||
| 70 | /// @brief Converts the provided json object | ||
| 71 | /// @param[in] j Json object with the time system | ||
| 72 | /// @param[out] refFrame Object to return | ||
| 73 | void from_json(const json& j, PositionWithFrame::ReferenceFrame& refFrame); | ||
| 74 | /// @brief Converts the provided Object into a json object | ||
| 75 | /// @param[out] j Return Json object | ||
| 76 | /// @param[in] position Object to convert | ||
| 77 | void to_json(json& j, const PositionWithFrame& position); | ||
| 78 | /// @brief Converts the provided json object | ||
| 79 | /// @param[in] j Json object with the time system | ||
| 80 | /// @param[out] position Object to return | ||
| 81 | void from_json(const json& j, PositionWithFrame& position); | ||
| 82 | |||
| 83 | /// Layout options for the Position input | ||
| 84 | enum class PositionInputLayout : uint8_t | ||
| 85 | { | ||
| 86 | SINGLE_COLUMN, ///< All elements in a single column | ||
| 87 | SINGLE_ROW, ///< All elements in a single row | ||
| 88 | TWO_ROWS, ///< 2 rows | ||
| 89 | }; | ||
| 90 | |||
| 91 | /// @brief Inputs to edit an Position object | ||
| 92 | /// @param[in] str Text to display near the Frame selection (Unique id for the ImGui elements) | ||
| 93 | /// @param[in, out] position Position and reference frame object to modify | ||
| 94 | /// @param[in] layout Layout to use | ||
| 95 | /// @param[in] itemWidth Width of the widget items | ||
| 96 | /// @return True if changes were made to the object | ||
| 97 | bool PositionInput(const char* str, PositionWithFrame& position, PositionInputLayout layout = PositionInputLayout::SINGLE_COLUMN, float itemWidth = 140.0F); | ||
| 98 | |||
| 99 | } // namespace gui::widgets | ||
| 100 | |||
| 101 | /// @brief Converts the enum to a string | ||
| 102 | /// @param[in] refFrame Enum value to convert into text | ||
| 103 | /// @return String representation of the enum | ||
| 104 | const char* to_string(gui::widgets::PositionWithFrame::ReferenceFrame refFrame); | ||
| 105 | |||
| 106 | } // namespace NAV | ||
| 107 |