feat(core): 领域模型 ScalarVolume/Grid/ScatterField(点序 i 最快)
This commit is contained in:
parent
29987191d0
commit
fb0586b6e0
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
#include <vector>
|
||||
#include <cstddef>
|
||||
namespace geopro::core {
|
||||
|
||||
// 规则三维标量场(IInterpolator 输出;render 层转 vtkImageData)。
|
||||
// 点序:i 最快、j 次之、k 最慢(匹配 vtkImageData)。
|
||||
class ScalarVolume {
|
||||
public:
|
||||
ScalarVolume(int nx, int ny, int nz)
|
||||
: nx_(nx), ny_(ny), nz_(nz), data_(static_cast<size_t>(nx) * ny * nz, 0.0) {}
|
||||
int nx() const { return nx_; } int ny() const { return ny_; } int nz() const { return nz_; }
|
||||
double& at(int i, int j, int k) { return data_[idx(i, j, k)]; }
|
||||
double at(int i, int j, int k) const { return data_[idx(i, j, k)]; }
|
||||
const std::vector<double>& data() const { return data_; }
|
||||
std::vector<double>& data() { return data_; }
|
||||
private:
|
||||
// i 最快、j 次之、k 最慢 ⇒ ((k*ny + j)*nx + i)。
|
||||
size_t idx(int i, int j, int k) const {
|
||||
return (static_cast<size_t>(k) * ny_ + j) * nx_ + i;
|
||||
}
|
||||
int nx_, ny_, nz_;
|
||||
std::vector<double> data_;
|
||||
};
|
||||
|
||||
// 规则二维网格剖面(x=距离 i, y=深度 j)。values 存 [j*nx + i],i 最快。
|
||||
class Grid {
|
||||
public:
|
||||
Grid(int nx, int ny) : nx_(nx), ny_(ny), values_(static_cast<size_t>(nx) * ny, 0.0) {}
|
||||
int nx() const { return nx_; } int ny() const { return ny_; }
|
||||
double& valueAt(int i, int j) { return values_[static_cast<size_t>(j) * nx_ + i]; }
|
||||
double valueAt(int i, int j) const { return values_[static_cast<size_t>(j) * nx_ + i]; }
|
||||
const std::vector<double>& values() const { return values_; }
|
||||
std::vector<double>& values() { return values_; }
|
||||
std::vector<double> x, y; // 轴坐标(规则)
|
||||
private:
|
||||
int nx_, ny_;
|
||||
std::vector<double> values_;
|
||||
};
|
||||
|
||||
// 散点场(剖面原数据):局部坐标 + 值。
|
||||
struct ScatterField {
|
||||
std::vector<double> x, y, z, v; // 对应样本 xlist/ylist/(hlist)/vlist
|
||||
};
|
||||
|
||||
} // namespace geopro::core
|
||||
|
|
@ -10,6 +10,7 @@ include(GoogleTest)
|
|||
gtest_discover_tests(geopro_tests)
|
||||
|
||||
target_sources(geopro_tests PRIVATE core/test_local_frame.cpp)
|
||||
target_sources(geopro_tests PRIVATE core/test_model.cpp)
|
||||
target_link_libraries(geopro_tests PRIVATE geopro_core)
|
||||
|
||||
add_subdirectory(spike) # spike S3: banded contour 渲染验证
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
#include <gtest/gtest.h>
|
||||
#include "model/Field.hpp"
|
||||
using namespace geopro::core;
|
||||
|
||||
TEST(Model, ScalarVolumeIndexing) {
|
||||
ScalarVolume v(/*nx=*/2, /*ny=*/3, /*nz=*/4);
|
||||
v.at(1, 2, 3) = 42.0;
|
||||
EXPECT_EQ(v.nx(), 2); EXPECT_EQ(v.ny(), 3); EXPECT_EQ(v.nz(), 4);
|
||||
EXPECT_EQ(v.data().size(), 2u * 3u * 4u);
|
||||
EXPECT_DOUBLE_EQ(v.at(1, 2, 3), 42.0);
|
||||
}
|
||||
|
||||
TEST(Model, GridStoresRegularSpec) {
|
||||
Grid g(/*nx=*/100, /*ny=*/22);
|
||||
EXPECT_EQ(g.values().size(), 100u * 22u);
|
||||
g.valueAt(/*i=*/3, /*j=*/5) = 7.5; // i=x(0..99), j=y(0..21)
|
||||
EXPECT_DOUBLE_EQ(g.valueAt(3, 5), 7.5);
|
||||
}
|
||||
Loading…
Reference in New Issue