72 lines
2.6 KiB
C++
72 lines
2.6 KiB
C++
#include <gtest/gtest.h>
|
||
|
||
#include <vtkImageData.h>
|
||
|
||
#include "VoxelFromScatters.hpp"
|
||
#include "geo/CrsTransform.hpp"
|
||
#include "geo/GeoLocalFrame.hpp"
|
||
#include "model/ColorScale.hpp"
|
||
#include "model/Field.hpp"
|
||
|
||
using namespace geopro::core;
|
||
|
||
// buildVoxelFromScatters: 两条剖面散点(项目 CRS EPSG:4547) 配准到 GeoLocalFrame 世界系
|
||
// + IDW 成体素。验证:valid、image dims/spacing 合理、原点附近格被充填。
|
||
// (需 PROJ_DATA:tests CMake 已注入环境变量。)
|
||
TEST(VoxelRegister, BuildsRegisteredVoxelFromTwoProfiles) {
|
||
// 香港测区附近(EPSG:4547 CM114E)的两组点,构造交叉两臂。
|
||
// profile1 沿 East 方向、profile2 沿 North 方向,深度 0..-10。
|
||
const double px0 = 516870.0, py0 = 2494270.0;
|
||
ScatterField p1, p2;
|
||
for (int i = 0; i < 11; ++i) {
|
||
const double t = i; // 0..10 米
|
||
// p1:projX 递增(East 向)
|
||
p1.projX.push_back(px0 + t);
|
||
p1.projY.push_back(py0);
|
||
p1.y.push_back(t); // ylist=深度
|
||
p1.v.push_back(100.0 + t);
|
||
// p2:projY 递增(North 向)
|
||
p2.projX.push_back(px0);
|
||
p2.projY.push_back(py0 + t);
|
||
p2.y.push_back(t);
|
||
p2.v.push_back(200.0 + t);
|
||
}
|
||
|
||
ColorScale cs;
|
||
cs.addStop(100.0, Rgba{0, 0, 255, 255});
|
||
cs.addStop(210.0, Rgba{255, 0, 0, 255});
|
||
|
||
CrsTransform crs("EPSG:4547", "EPSG:4326");
|
||
// 世界系原点取测区附近经纬(由 px0/py0 反算)。
|
||
const auto ll0 = crs.forward(px0, py0); // (lon, lat)
|
||
GeoLocalFrame frame(ll0.y, ll0.x);
|
||
|
||
auto vr = geopro::render::buildVoxelFromScatters({p1, p2}, cs, crs, frame,
|
||
/*cellXY*/ 1.0, /*cellZ*/ 1.0,
|
||
/*power*/ 2.0, /*maxDist*/ 3.0);
|
||
ASSERT_TRUE(vr.valid());
|
||
|
||
int dims[3];
|
||
vr.image->GetDimensions(dims);
|
||
// 两臂各 ~10m → 水平 ~10x10,深度 0..-10 → ~11。合理上界检查。
|
||
EXPECT_GE(dims[0], 5);
|
||
EXPECT_GE(dims[1], 5);
|
||
EXPECT_GE(dims[2], 5);
|
||
EXPECT_LT(dims[0], 50);
|
||
EXPECT_LT(dims[1], 50);
|
||
EXPECT_LT(dims[2], 50);
|
||
|
||
double sp[3];
|
||
vr.image->GetSpacing(sp);
|
||
EXPECT_DOUBLE_EQ(sp[0], 1.0);
|
||
EXPECT_DOUBLE_EQ(sp[2], 1.0);
|
||
|
||
// 体内应有被充填(非哨兵)的格:哨兵 = vmin-1 = 99。统计 > 99.5 的格数 > 0。
|
||
int filled = 0;
|
||
for (int k = 0; k < dims[2]; ++k)
|
||
for (int j = 0; j < dims[1]; ++j)
|
||
for (int i = 0; i < dims[0]; ++i)
|
||
if (vr.image->GetScalarComponentAsDouble(i, j, k, 0) > 99.5) ++filled;
|
||
EXPECT_GT(filled, 0);
|
||
}
|