diff --git a/tools/gpr_poc/main.cpp b/tools/gpr_poc/main.cpp index 11800a3..3a91b46 100644 --- a/tools/gpr_poc/main.cpp +++ b/tools/gpr_poc/main.cpp @@ -3167,8 +3167,13 @@ int cmdView(int argc, char** argv) { // gallery 同一 mapper 类型,保证交互画面 == 预览画面、fps 同档。 vtkNew mapper; mapper->SetRequestedRenderMode(vtkSmartVolumeMapper::GPURenderMode); - mapper->SetAutoAdjustSampleDistances(0); - mapper->SetInteractiveAdjustSampleDistances(0); + // C3-5:交互式采样距离自适应(修长板填屏 ray-march 慢的关键)。POC 当初为离屏 + // 基准把这两个关掉(0/0)以求恒定全质量,但交互场景必须【开启】:拖动时按渲染窗口的 + // DesiredUpdateRate 拉大 SampleDistance(降采样→快)、停下恢复小步长(全质量→可慢)。 + // 长板填屏慢的根因是每像素沿超长轴海量采样,LOD/异步都不缩短 ray-march 长度,只有 + // 拖动期降采样才把交互态降到可跟手帧率。 + mapper->SetAutoAdjustSampleDistances(1); + mapper->SetInteractiveAdjustSampleDistances(1); auto volume = vtkSmartPointer::New(); volume->SetMapper(mapper); @@ -3246,15 +3251,34 @@ int cmdView(int argc, char** argv) { }; const vtkIdType defStruct = countStructPixels(); - // 旋相机 N 帧测真实 fps(非首帧:首帧含纹理上传/shader 编译已在预热完成)。 - rw->Render(); // 再预热一帧,确保管线热 - Stopwatch sw; + // C3-5:两态 fps 对照。AutoAdjustSampleDistances 据渲染窗口的 DesiredUpdateRate + // 决定 SampleDistance——高 DesiredUpdateRate=拖动态(大步长/降采样/快),低=静止态 + // (小步长/全质量/可慢)。离屏无真交互,故显式设 DesiredUpdateRate 模拟两态,旋相机 + // 测真实 Render() 帧率,量化拖动降采样提速。 + // + // ① 全质量静态:StillUpdateRate(慢档),mapper 用最小 SampleDistance。 + rw->SetDesiredUpdateRate(0.5); // 静止目标帧率(慢)→全质量 + rw->Render(); // 预热一帧(管线热 + 采样距离按此档生效) + Stopwatch swStill; for (int f = 0; f < frames; ++f) { st.cam->Azimuth(360.0 / frames); rw->Render(); } - const double ms = sw.elapsedMs(); - const double fps = ms > 0 ? frames * 1000.0 / ms : 0.0; + const double msStill = swStill.elapsedMs(); + const double fps = msStill > 0 ? frames * 1000.0 / msStill : 0.0; + + // ② 交互态(降采样):高 DesiredUpdateRate(拖动目标 15fps)→ mapper 拉大 SampleDistance。 + rw->SetDesiredUpdateRate(15.0); // 拖动目标帧率→降采样 + rw->Render(); // 预热一帧让降采样步长生效 + Stopwatch swInteract; + for (int f = 0; f < frames; ++f) { + st.cam->Azimuth(360.0 / frames); + rw->Render(); + } + const double msInteract = swInteract.elapsedMs(); + const double fpsInteract = + msInteract > 0 ? frames * 1000.0 / msInteract : 0.0; + rw->SetDesiredUpdateRate(0.5); // 复位 const bool texErr2 = capWin->textureError(); vtkOutputWindow::SetInstance(nullptr); @@ -3268,8 +3292,18 @@ int cmdView(int argc, char** argv) { << " (" << (100.0 * defStruct / (winW * winH)) << "%, 已排除深蓝灰背景)\n"; std::cout << "纹理维度错误 : " << (texErr2 ? "是(!!)" : "否") << "\n"; - std::cout << "真实渲染 fps : " << (ok ? std::to_string(fps) : "INVALID") - << " (" << frames << " 帧旋相机, 非首帧)\n"; + const double speedup = fps > 0 ? fpsInteract / fps : 0.0; + std::cout << "全质量静态 fps : " << (ok ? std::to_string(fps) : "INVALID") + << " (" << frames << " 帧旋相机, DesiredUpdateRate=0.5)\n"; + std::cout << "交互态降采样 fps: " + << (ok ? std::to_string(fpsInteract) : "INVALID") << " (" << frames + << " 帧旋相机, DesiredUpdateRate=15)\n"; + std::cout << "拖动态提速 : " << (ok ? std::to_string(speedup) : "INVALID") + << "x (交互态/全质量)\n"; + std::cout << "交互级(≥15fps) : " + << (ok ? (fpsInteract >= 15.0 ? "是 ✔" : "否(未达拖动目标)") + : "INVALID") + << "\n"; std::cout << "preview 结果 : " << (ok ? "OK ✔ 默认视角有结构" : "FAIL ✘") << "\n"; @@ -3278,7 +3312,9 @@ int cmdView(int argc, char** argv) { ",opacity=" + std::to_string(opacity) + ",localBricks=" + std::to_string(kViewDefaultLocalBricks) + ",structPixels=" + std::to_string(defStruct) + - ",fps=" + (ok ? std::to_string(fps) : "INVALID") + + ",fpsStill=" + (ok ? std::to_string(fps) : "INVALID") + + ",fpsInteract=" + (ok ? std::to_string(fpsInteract) : "INVALID") + + ",speedup=" + (ok ? std::to_string(speedup) : "INVALID") + ",textureErr=" + std::to_string(texErr2 ? 1 : 0) + ",ok=" + std::to_string(ok ? 1 : 0) + ",png=" + pngPath); @@ -3327,6 +3363,12 @@ int cmdView(int argc, char** argv) { vtkNew style; iren->SetInteractorStyle(style); + // C3-5:交互/静止目标帧率。interactor 在交互(拖动)中把渲染窗口 DesiredUpdateRate + // 拉到 DesiredUpdateRate(15)→mapper 自适应降采样(快、跟手);松手后落回 StillUpdateRate + // (0.5)→恢复小步长全质量。配合上面 mapper 的 AutoAdjust/InteractiveAdjust 才生效。 + iren->SetDesiredUpdateRate(15.0); + iren->SetStillUpdateRate(0.5); + vtkNew cb; cb->SetCallback(viewOnInteract); cb->SetClientData(&st);