feat/vtk-3d-view #7

Merged
gaozheng merged 301 commits from feat/vtk-3d-view into main 2026-06-27 18:43:52 +08:00
1 changed files with 21 additions and 5 deletions
Showing only changes of commit eb8cb9e7ee - Show all commits

View File

@ -131,12 +131,28 @@ int InteractionManager::nearestSlice(const Vec3& worldPoint) const {
}
void InteractionManager::onPicked(const Vec3& worldPoint) {
// 单击 = 仅选中命中的切片(不动相机 → 绝不跳;拖动旋转交给默认 TrackballCamera
// 原"把焦点移到命中点以绕其旋转"实测会让视图跳变,去掉。选中切片高亮 + 供滚轮推进/关闭。
const int idx = nearestSlice(worldPoint);
if (idx >= 0) {
selected_ = idx;
updateSelectionVisual();
if (idx < 0) {
safeRender(); // 未命中切片:不动相机(拖动绕当前中心旋转,不甩)
return;
}
selected_ = idx;
updateSelectionVisual();
// 旋转中心 = 切片中心spec C38 "以切片为中心旋转"**不是点击点**
// 实测点击点常远离体中心,绕它拖动旋转会大幅摆动(=用户看到的"跳");切片中心≈体中心 → 居中、不甩。
// 焦点与相机位置同步平移同一 delta → 视向/距离不变、点击瞬间画面不动;之后 TrackballCamera 绕切片中心旋转。
if (renderer_) {
if (auto* cam = renderer_->GetActiveCamera()) {
const Vec3 c = slices_[static_cast<std::size_t>(idx)]->center();
double f[3], p[3];
cam->GetFocalPoint(f);
cam->GetPosition(p);
const double d[3] = {c[0] - f[0], c[1] - f[1], c[2] - f[2]};
cam->SetFocalPoint(c[0], c[1], c[2]);
cam->SetPosition(p[0] + d[0], p[1] + d[1], p[2] + d[2]);
renderer_->ResetCameraClippingRange();
}
}
safeRender();
}