feat(vtk): 渲染策略接口+字符串键注册表+3骨架策略(volume/curtain/plane2d)
This commit is contained in:
parent
8f7da3657a
commit
72b5f6f25f
|
|
@ -3,6 +3,7 @@ add_library(geopro_controller STATIC
|
||||||
WorkbenchNavController.cpp
|
WorkbenchNavController.cpp
|
||||||
DatasetDetailController.cpp
|
DatasetDetailController.cpp
|
||||||
DatasetViewState.cpp
|
DatasetViewState.cpp
|
||||||
|
DatasetRenderStrategy.cpp
|
||||||
VtkSceneController.cpp)
|
VtkSceneController.cpp)
|
||||||
target_include_directories(geopro_controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(geopro_controller PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
target_link_libraries(geopro_controller PUBLIC geopro_data Qt6::Core)
|
target_link_libraries(geopro_controller PUBLIC geopro_data Qt6::Core)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#include "controller/DatasetRenderStrategy.hpp"
|
||||||
|
|
||||||
|
namespace geopro::controller {
|
||||||
|
|
||||||
|
// 骨架实现:渲染体由后续阶段填充(Phase B / E / F)。当前为空实现,仅保证链接。
|
||||||
|
void VolumeRenderStrategy::add(const std::string& /*typeId*/, const std::string& /*dsId*/) {}
|
||||||
|
void VolumeRenderStrategy::remove(const std::string& /*dsId*/) {}
|
||||||
|
|
||||||
|
void CurtainRenderStrategy::add(const std::string& /*typeId*/, const std::string& /*dsId*/) {}
|
||||||
|
void CurtainRenderStrategy::remove(const std::string& /*dsId*/) {}
|
||||||
|
|
||||||
|
void Plane2DRenderStrategy::add(const std::string& /*typeId*/, const std::string& /*dsId*/) {}
|
||||||
|
void Plane2DRenderStrategy::remove(const std::string& /*dsId*/) {}
|
||||||
|
|
||||||
|
} // namespace geopro::controller
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
#pragma once
|
||||||
|
#include <map>
|
||||||
|
#include <memory>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace geopro::controller {
|
||||||
|
|
||||||
|
class IDatasetRenderStrategy {
|
||||||
|
public:
|
||||||
|
virtual ~IDatasetRenderStrategy() = default;
|
||||||
|
virtual void add(const std::string& typeId, const std::string& dsId) = 0;
|
||||||
|
virtual void remove(const std::string& dsId) = 0;
|
||||||
|
virtual void onTypeActivated(const std::string& /*typeId*/) {}
|
||||||
|
virtual void onTypeDeactivated(const std::string& /*typeId*/) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
class RenderStrategyRegistry {
|
||||||
|
public:
|
||||||
|
void registerStrategy(std::string id, std::unique_ptr<IDatasetRenderStrategy> s) {
|
||||||
|
strategies_[std::move(id)] = std::move(s);
|
||||||
|
}
|
||||||
|
IDatasetRenderStrategy* get(const std::string& id) const {
|
||||||
|
auto it = strategies_.find(id);
|
||||||
|
return it == strategies_.end() ? nullptr : it->second.get();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::map<std::string, std::unique_ptr<IDatasetRenderStrategy>> strategies_;
|
||||||
|
};
|
||||||
|
|
||||||
|
// 3 骨架策略:本任务仅建类与注册。add/remove 的真实渲染实现由后续阶段填充——
|
||||||
|
// Phase B(VolumeRenderStrategy/CurtainRenderStrategy 包现有 3D 分支)与
|
||||||
|
// Phase E/F(Plane2DRenderStrategy 平面 z + 底图)。届时各自接所需的
|
||||||
|
// VtkSceneController& / View / Repo 引用。当前 .cpp 给空实现使链接通过。
|
||||||
|
class VolumeRenderStrategy : public IDatasetRenderStrategy {
|
||||||
|
public:
|
||||||
|
void add(const std::string& typeId, const std::string& dsId) override;
|
||||||
|
void remove(const std::string& dsId) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CurtainRenderStrategy : public IDatasetRenderStrategy {
|
||||||
|
public:
|
||||||
|
void add(const std::string& typeId, const std::string& dsId) override;
|
||||||
|
void remove(const std::string& dsId) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
class Plane2DRenderStrategy : public IDatasetRenderStrategy {
|
||||||
|
public:
|
||||||
|
void add(const std::string& typeId, const std::string& dsId) override;
|
||||||
|
void remove(const std::string& dsId) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace geopro::controller
|
||||||
|
|
@ -218,6 +218,8 @@ target_sources(geopro_tests PRIVATE controller/test_dataset_detail_controller.cp
|
||||||
target_sources(geopro_tests PRIVATE controller/test_workbench_nav_controller.cpp)
|
target_sources(geopro_tests PRIVATE controller/test_workbench_nav_controller.cpp)
|
||||||
# VtkSceneController 编排:注入 fake repo + fake view,断言 视图模式×图层 组合下 add 的图元类型/数量;取消勾选清空。
|
# VtkSceneController 编排:注入 fake repo + fake view,断言 视图模式×图层 组合下 add 的图元类型/数量;取消勾选清空。
|
||||||
target_sources(geopro_tests PRIVATE controller/test_vtk_scene_controller.cpp)
|
target_sources(geopro_tests PRIVATE controller/test_vtk_scene_controller.cpp)
|
||||||
|
# RenderStrategyRegistry:字符串键策略注册表解析(register/get,纯逻辑,FakeStrategy)。
|
||||||
|
target_sources(geopro_tests PRIVATE controller/test_render_strategy_registry.cpp)
|
||||||
target_link_libraries(geopro_tests PRIVATE geopro_controller Qt6::Test)
|
target_link_libraries(geopro_tests PRIVATE geopro_controller Qt6::Test)
|
||||||
|
|
||||||
# io/gpr 层:.iprh 头解析 + .iprb B-scan 读取(纯 C++17,零 Qt/VTK)。
|
# io/gpr 层:.iprh 头解析 + .iprb B-scan 读取(纯 C++17,零 Qt/VTK)。
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "controller/DatasetRenderStrategy.hpp"
|
||||||
|
|
||||||
|
using namespace geopro::controller;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct FakeStrategy : IDatasetRenderStrategy {
|
||||||
|
int added = 0;
|
||||||
|
void add(const std::string&, const std::string&) override { ++added; }
|
||||||
|
void remove(const std::string&) override {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(RenderStrategyRegistry, ResolvesById) {
|
||||||
|
RenderStrategyRegistry reg;
|
||||||
|
reg.registerStrategy("fake", std::make_unique<FakeStrategy>());
|
||||||
|
auto* s = reg.get("fake");
|
||||||
|
ASSERT_NE(s, nullptr);
|
||||||
|
s->add("trajectory", "d1");
|
||||||
|
EXPECT_EQ(static_cast<FakeStrategy*>(s)->added, 1);
|
||||||
|
EXPECT_EQ(reg.get("missing"), nullptr);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue