#include "source/WholeVolumeSource.hpp" #include "data/store/ChunkedVolumeStore.hpp" #include "core/algo/GprVolumeBuilder.hpp" #include #include #include using namespace geopro; TEST(WholeVolumeSource, ReassemblesFullVolumeFromStore) { auto dir = (std::filesystem::temp_directory_path() / "gpr_wvs_test").string(); std::filesystem::remove_all(dir); // 造一个可识别的体:值 = 全局 i+j+k(便于校验重组位置) core::BuiltI16 b; b.vol = core::ScalarVolumeI16(100,40,30); for (int k=0;k<30;k++)for(int j=0;j<40;j++)for(int i=0;i<100;i++) b.vol.at(i,j,k)=(short)((i+j+k)%1000); b.quant={1.0,0.0}; b.origin={{1,2,3}}; b.spacing={{0.5,0.5,0.2}}; b.vminPhys=0; b.vmaxPhys=1000; data::ChunkedVolumeStore::write(dir, b, 64); // 100/40/30 均非 64 整除→含边缘块 render::WholeVolumeSource src(dir); EXPECT_EQ(src.meta().nx, 100); auto imgs = src.currentImages(); ASSERT_EQ(imgs.size(), 1u); auto* img = imgs[0].Get(); EXPECT_EQ(img->GetScalarType(), VTK_SHORT); int dims[3]; img->GetDimensions(dims); EXPECT_EQ(dims[0],100); EXPECT_EQ(dims[1],40); EXPECT_EQ(dims[2],30); // 关键:重组位置正确(边缘块也对) EXPECT_EQ(*static_cast(img->GetScalarPointer(99,39,29)), (short)((99+39+29)%1000)); EXPECT_EQ(*static_cast(img->GetScalarPointer(70,10,5)), (short)((70+10+5)%1000)); EXPECT_EQ(src.sliceSource(), img); src.update(nullptr); // no-op 安全 std::filesystem::remove_all(dir); }