From d46f320a748e48014425686a7cbd87fcbac5167f Mon Sep 17 00:00:00 2001 From: admin <572701190@qq.com> Date: Sun, 3 May 2026 02:29:17 +0800 Subject: [PATCH] preserve cutoff line color in rotated preview --- WebSite/src/App.tsx | 7 +++++++ head_extension_app.py | 10 +++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/WebSite/src/App.tsx b/WebSite/src/App.tsx index 2a3c119..422ca3d 100644 --- a/WebSite/src/App.tsx +++ b/WebSite/src/App.tsx @@ -86,9 +86,11 @@ type LibraryInfo = { type StoredDeformationJob = { job: BackendJob; progress: number; + renderVersion?: string; }; const DEFORMATION_JOB_STORAGE_KEY = 'head_ct_morph_deformation_job'; +const DEFORMATION_RESULT_RENDER_VERSION = 'quick-preview-cutoff-only-v1'; const API_BASE = typeof window === 'undefined' ? 'http://127.0.0.1:8787' @@ -109,6 +111,10 @@ function readStoredDeformationJob(): StoredDeformationJob | null { if (!rawValue) return null; const parsed = JSON.parse(rawValue) as StoredDeformationJob; if (!parsed?.job?.id) return null; + if (parsed.renderVersion !== DEFORMATION_RESULT_RENDER_VERSION) { + window.localStorage.removeItem(DEFORMATION_JOB_STORAGE_KEY); + return null; + } return { job: parsed.job, progress: Math.max(0, Math.min(100, parsed.progress || 0)), @@ -417,6 +423,7 @@ export default function App() { JSON.stringify({ job: deformationJob, progress: deformationJob.status === 'completed' ? 100 : progress, + renderVersion: DEFORMATION_RESULT_RENDER_VERSION, }) ); }, [deformationJob, progress]); diff --git a/head_extension_app.py b/head_extension_app.py index 5a127f7..6f6a6ae 100644 --- a/head_extension_app.py +++ b/head_extension_app.py @@ -159,8 +159,8 @@ def preview_deform_2d(image, angle_degrees): except Exception: return image - arr = np.asarray(image.convert("L")).astype(np.float32) - h, w = arr.shape + arr = np.asarray(image.convert("RGB")).astype(np.float32) + h, w, _ = arr.shape yy, xx = np.mgrid[0:h, 0:w] pivot_x = int(w * 0.55) @@ -183,7 +183,11 @@ def preview_deform_2d(image, angle_degrees): src_x = pivot_x + cos_t * dx + sin_t * dy src_y = pivot_y - sin_t * dx + cos_t * dy - warped = map_coordinates(arr, [src_y, src_x], order=1, mode="constant", cval=0) + warped_channels = [ + map_coordinates(arr[..., channel], [src_y, src_x], order=1, mode="constant", cval=0) + for channel in range(arr.shape[2]) + ] + warped = np.stack(warped_channels, axis=2) return Image.fromarray(np.clip(warped, 0, 255).astype(np.uint8)).convert("RGB")