feat(core): LocalFrame 坐标系(原点偏移+东北轴向+Z基准)

This commit is contained in:
gaozheng 2026-06-07 19:40:23 +08:00
parent 9337340848
commit 238faff56e
7 changed files with 72 additions and 0 deletions

View File

@ -8,4 +8,5 @@
# add_subdirectory(view) # QtWidgets # add_subdirectory(view) # QtWidgets
# add_subdirectory(controller) # # add_subdirectory(controller) #
# #
add_subdirectory(core)
add_subdirectory(app) add_subdirectory(app)

11
src/core/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
find_package(Eigen3 CONFIG REQUIRED)
add_library(geopro_core STATIC
geo/LocalFrame.cpp
)
target_include_directories(geopro_core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(geopro_core PUBLIC Eigen3::Eigen)
target_compile_features(geopro_core PUBLIC cxx_std_17)
# core Qt / VTK

View File

@ -0,0 +1,15 @@
#include "geo/LocalFrame.hpp"
namespace geopro::core {
LocalFrame::LocalFrame(double originEast, double originNorth, double zDatum)
: originEast_(originEast), originNorth_(originNorth), zDatum_(zDatum) {}
WorldPoint LocalFrame::gisToWorld(double east, double north, double elevation) const {
return WorldPoint{east - originEast_, north - originNorth_, elevation - zDatum_};
}
GisPoint LocalFrame::worldToGis(const WorldPoint& w) const {
return GisPoint{w.x + originEast_, w.y + originNorth_, w.z + zDatum_};
}
} // namespace geopro::core

View File

@ -0,0 +1,21 @@
#pragma once
namespace geopro::core {
struct WorldPoint { double x, y, z; }; // 局部米x=East偏移, y=North偏移, z=相对Z基准
struct GisPoint { double east, north, elevation; };
// 唯一权威「项目世界系」:双精度 GIS 原点平移到局部米,规避 VTK float 大坐标抖动。
// 轴向钉死world.x = Easting(projectX)world.y = Northing(projectY)world.z 向上为正。
class LocalFrame {
public:
LocalFrame(double originEast, double originNorth, double zDatum);
WorldPoint gisToWorld(double east, double north, double elevation) const;
GisPoint worldToGis(const WorldPoint& w) const;
double originEast() const { return originEast_; }
double originNorth() const { return originNorth_; }
double zDatum() const { return zDatum_; }
private:
double originEast_, originNorth_, zDatum_;
};
} // namespace geopro::core

View File

@ -9,4 +9,7 @@ target_link_libraries(geopro_tests PRIVATE GTest::gtest GTest::gtest_main)
include(GoogleTest) include(GoogleTest)
gtest_discover_tests(geopro_tests) gtest_discover_tests(geopro_tests)
target_sources(geopro_tests PRIVATE core/test_local_frame.cpp)
target_link_libraries(geopro_tests PRIVATE geopro_core)
add_subdirectory(spike) # spike S3: banded contour add_subdirectory(spike) # spike S3: banded contour

View File

@ -0,0 +1,20 @@
#include <gtest/gtest.h>
#include "geo/LocalFrame.hpp"
using geopro::core::LocalFrame;
TEST(LocalFrame, GisToWorldSubtractsOriginEastNorth) {
LocalFrame f(/*originEast=*/516000.0, /*originNorth=*/2494000.0, /*zDatum=*/0.0);
auto w = f.gisToWorld(516863.6350992983, 2494259.56246985, 21.0);
EXPECT_NEAR(w.x, 863.6350992983, 1e-6);
EXPECT_NEAR(w.y, 259.56246985, 1e-6);
EXPECT_NEAR(w.z, 21.0, 1e-6);
}
TEST(LocalFrame, RoundTripWorldGis) {
LocalFrame f(516000.0, 2494000.0, 5.0);
auto w = f.gisToWorld(516500.0, 2494500.0, 30.0);
auto g = f.worldToGis(w);
EXPECT_NEAR(g.east, 516500.0, 1e-6);
EXPECT_NEAR(g.north, 2494500.0, 1e-6);
EXPECT_NEAR(g.elevation, 30.0, 1e-6);
}

View File

@ -3,6 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"description": "Geopro 3.0 desktop client (Qt6 + VTK9) - M1. 方案②-修订: Qt/VTK/ADS/QtKeychain 对接官方 MSVC Qt(不走 vcpkg); 仅非 Qt 依赖走 vcpkg, 按层递增。", "description": "Geopro 3.0 desktop client (Qt6 + VTK9) - M1. 方案②-修订: Qt/VTK/ADS/QtKeychain 对接官方 MSVC Qt(不走 vcpkg); 仅非 Qt 依赖走 vcpkg, 按层递增。",
"dependencies": [ "dependencies": [
"eigen3",
"gtest", "gtest",
"nlohmann-json" "nlohmann-json"
] ]