#include #include #include #include "actors/ElectrodeActor.hpp" #include "model/Field.hpp" using namespace geopro::core; // buildElectrodes: nx 列 → nx 个朝下三角(各 3 点);顶点 y = -min(深度)(剖面顶边)。 TEST(Electrode, BuildsDownTrianglesAtSectionTop) { Grid g(3, 2); g.x = {0.0, 10.0, 20.0}; g.y = {2.0, 8.0}; // 深度;min=2 → 顶边 y_screen = -2 auto actor = geopro::render::buildElectrodes(g, /*markerW*/ 0.5, /*markerH*/ 1.0); ASSERT_NE(actor.GetPointer(), nullptr); auto* mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper()); ASSERT_NE(mapper, nullptr); auto* poly = vtkPolyData::SafeDownCast(mapper->GetInput()); ASSERT_NE(poly, nullptr); EXPECT_EQ(poly->GetNumberOfCells(), 3); // 3 电极 → 3 三角 EXPECT_EQ(poly->GetNumberOfPoints(), 3 * 3); // 每三角 3 点 // 第一个三角的 apex(点 0) 在 (x=0, y=-2)(顶边),底边两点在其上方 y=-1。 double apex[3]; poly->GetPoint(0, apex); EXPECT_DOUBLE_EQ(apex[0], 0.0); EXPECT_DOUBLE_EQ(apex[1], -2.0); double base[3]; poly->GetPoint(1, base); EXPECT_DOUBLE_EQ(base[1], -1.0); // -2 + markerH(1) } // 退化网格(无 x)返回空 actor。 TEST(Electrode, EmptyGridYieldsSafeActor) { Grid g(0, 0); auto actor = geopro::render::buildElectrodes(g); ASSERT_NE(actor.GetPointer(), nullptr); EXPECT_EQ(actor->GetMapper(), nullptr); }