geopro/tests/render/test_voxel_i16_smoke.cpp

41 lines
1.2 KiB
C++
Raw Permalink 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 <vtkImageData.h>
#include "actors/VoxelActor.hpp"
#include "model/ColorScale.hpp"
#include "model/ScalarVolumeI16.hpp"
using namespace geopro;
// buildVoxelI16 无窗冒烟int16 量化体 → vtkImageData(vtkShortArray)。
// 仅验 image 构造/类型(VTK_SHORT)/dims/逐体素值/blank 原样保留;不实际 GPU 渲染。
TEST(VoxelActorI16, BuildsShortImageWithBlank) {
core::ScalarVolumeI16 v(2, 2, 2);
for (auto& x : v.data()) x = 10;
v.at(0, 0, 0) = core::ScalarVolumeI16::kBlank;
core::Quant q{1.0, 0.0};
core::ColorScale cs;
cs.addStop(0.0, core::Rgba{0, 0, 255, 255});
cs.addStop(20.0, core::Rgba{255, 0, 0, 255});
vtkSmartPointer<vtkImageData> img;
auto vol = render::buildVoxelI16(v, q, cs, 0, 0, 0, 1, 1, 1, 0.0, 20.0, img);
ASSERT_NE(vol.Get(), nullptr);
ASSERT_NE(img.Get(), nullptr);
EXPECT_EQ(img->GetScalarType(), VTK_SHORT);
int dims[3];
img->GetDimensions(dims);
EXPECT_EQ(dims[0], 2);
EXPECT_EQ(dims[1], 2);
EXPECT_EQ(dims[2], 2);
EXPECT_EQ(*static_cast<short*>(img->GetScalarPointer(1, 1, 1)), 10);
EXPECT_EQ(*static_cast<short*>(img->GetScalarPointer(0, 0, 0)),
core::ScalarVolumeI16::kBlank);
}