geopro/tests/render/test_scatter.cpp

53 lines
1.7 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <gtest/gtest.h>
#include <vtkPointData.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include "actors/ScatterActor.hpp"
#include "model/ColorScale.hpp"
#include "model/Field.hpp"
using namespace geopro::core;
// buildScatter: 小散点场 -> 非空 actorpolydata 点数=点数、含 verts、按 v 上色(LUT)。
TEST(Scatter, BuildsColoredPointsFromScatterField) {
ScatterField s;
s.x = {0.0, 10.0, 20.0};
s.y = {1.0, 2.0, 3.0}; // 深度,渲染时取负
s.v = {0.0, 2.5, 5.0};
ColorScale cs;
cs.addStop(0.0, Rgba{0, 0, 255, 255});
cs.addStop(5.0, Rgba{255, 0, 0, 255});
auto actor = geopro::render::buildScatter(s, cs);
ASSERT_NE(actor.GetPointer(), nullptr);
auto* mapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper());
ASSERT_NE(mapper, nullptr);
ASSERT_NE(mapper->GetLookupTable(), nullptr);
auto* poly = vtkPolyData::SafeDownCast(mapper->GetInput());
ASSERT_NE(poly, nullptr);
EXPECT_EQ(poly->GetNumberOfPoints(), 3);
EXPECT_EQ(poly->GetNumberOfVerts(), 3); // 每点一个 vtkVertex
ASSERT_NE(poly->GetPointData()->GetScalars(), nullptr);
// y 取负:深度向下(与剖面 #18 一致)。
double p1[3];
poly->GetPoint(1, p1);
EXPECT_DOUBLE_EQ(p1[0], 10.0);
EXPECT_DOUBLE_EQ(p1[1], -2.0);
}
// 退化输入(无值)返回非空 actor 但无 polydata 输入(调用方可安全 add
TEST(Scatter, EmptyFieldYieldsSafeActor) {
ScatterField s; // 空
ColorScale cs;
cs.addStop(0.0, Rgba{0, 0, 255, 255});
auto actor = geopro::render::buildScatter(s, cs);
ASSERT_NE(actor.GetPointer(), nullptr);
EXPECT_EQ(actor->GetMapper(), nullptr); // 未设 mapper
}