From db8ba53589dfbf17d66d52738679302b81b3e0ad Mon Sep 17 00:00:00 2001 From: mozzie Date: Mon, 23 Sep 2024 13:02:38 +0800 Subject: [PATCH] feat: temp --- apps/desktop/electron/ipcEvent/alg/index.ts | 53 +++++++++++++++++++ .../desktop/electron/ipcEvent/common/index.ts | 42 +-------------- apps/desktop/electron/ipcEvent/index.ts | 2 + apps/desktop/electron/main.ts | 2 +- .../src/pages/Viewer/ModelViewer/index.tsx | 22 +++++++- 5 files changed, 77 insertions(+), 44 deletions(-) create mode 100644 apps/desktop/electron/ipcEvent/alg/index.ts diff --git a/apps/desktop/electron/ipcEvent/alg/index.ts b/apps/desktop/electron/ipcEvent/alg/index.ts new file mode 100644 index 0000000..ffed176 --- /dev/null +++ b/apps/desktop/electron/ipcEvent/alg/index.ts @@ -0,0 +1,53 @@ +import { downloadSeriesDicomFiles } from "../../core/pacs"; +import { executeInferTask } from "../../core/alg"; +import { InferDeviceEnum, InferStructuralEnum } from "../../core/alg.type"; +import { db } from "../../core/db"; +import log from "electron-log"; +import path from "node:path"; +import { app, ipcMain } from "electron"; + +export const registerAlgHandler = () => { + ipcMain.handle("device:infer:set", async (_event, inferDevice) => { + try { + await db.update(({ setting }) => ({ ...setting, inferDevice })); + return { success: true, msg: `推理硬件修改为${inferDevice}` }; + } catch (error) { + await db.update(({ setting }) => ({ ...setting, inferDevice })); + log.error(error); + return { success: false, msg: `操作失败` }; + } + }); + + ipcMain.on("model:infer", async (event, SeriesInstanceUIDs) => { + // 构造推理任务参数列表 + const pu = InferDeviceEnum.GPU; + const module = InferStructuralEnum.AORTA; + const turbo = true; + const seg_schedule = true; + for (let i = 0; i < SeriesInstanceUIDs.length; i++) { + const SeriesInstanceUID = SeriesInstanceUIDs[i]; + // 下载dicom到本地,获取文件夹路径 + const img_path = await downloadSeriesDicomFiles(SeriesInstanceUID); + const save_path = path.join( + app.getPath("userData"), + "output", + SeriesInstanceUID + ); + const task = { save_path, pu, module, turbo, seg_schedule, img_path }; + console.log("infer task: ", task); + await executeInferTask(task, (data) => { + console.log(data); + event.reply("infer:progress", data); + }); + } + }); + + ipcMain.handle("alg:assets", (_event, SeriesInstanceUID) => { + const assetsPath = path.join( + app.getPath("userData"), + "output", + SeriesInstanceUID + ); + console.log("assetsPath", assetsPath); + }); +}; diff --git a/apps/desktop/electron/ipcEvent/common/index.ts b/apps/desktop/electron/ipcEvent/common/index.ts index 5ea22a5..6300db4 100644 --- a/apps/desktop/electron/ipcEvent/common/index.ts +++ b/apps/desktop/electron/ipcEvent/common/index.ts @@ -1,11 +1,8 @@ -import { app, ipcMain, shell } from "electron"; +import { ipcMain, shell } from "electron"; import { mkdir, stat } from "fs/promises"; import { db } from "../../core/db"; import log from "electron-log"; import path from "node:path"; -import { downloadSeriesDicomFiles } from "../../core/pacs"; -import { executeInferTask } from "../../core/alg"; -import { InferDeviceEnum, InferStructuralEnum } from "../../core/alg.type"; export const registerCommonHandler = () => { ipcMain.handle("output:open", async () => { @@ -22,41 +19,4 @@ export const registerCommonHandler = () => { shell.openPath(resolvedPath); } }); - - ipcMain.handle("device:infer:set", async (_event, inferDevice) => { - try { - await db.update(({ setting }) => ({ ...setting, inferDevice })); - return { success: true, msg: `推理硬件修改为${inferDevice}` }; - } catch (error) { - await db.update(({ setting }) => ({ ...setting, inferDevice })); - log.error(error); - return { success: false, msg: `操作失败` }; - } - }); - - ipcMain.on("model:infer", async (event, SeriesInstanceUIDs) => { - console.log('SeriesInstanceUIDs', SeriesInstanceUIDs) - // 构造推理任务参数列表 - const pu = InferDeviceEnum.GPU; - const module = InferStructuralEnum.AORTA; - const turbo = true; - const seg_schedule = true; - for (let i = 0; i < SeriesInstanceUIDs.length; i++) { - const SeriesInstanceUID = SeriesInstanceUIDs[i]; - // 下载dicom到本地,获取文件夹路径 - const img_path = await downloadSeriesDicomFiles(SeriesInstanceUID); - const save_path = path.join( - app.getPath("userData"), - "output", - SeriesInstanceUID - ); - const task = { save_path, pu, module, turbo, seg_schedule, img_path }; - console.log('infer task: ', task); - const result = await executeInferTask(task, (data) => { - console.log(data) - event.reply('infer:progress', data) - }); - console.log("end: ", result); - } - }); }; diff --git a/apps/desktop/electron/ipcEvent/index.ts b/apps/desktop/electron/ipcEvent/index.ts index bffe811..03053f1 100644 --- a/apps/desktop/electron/ipcEvent/index.ts +++ b/apps/desktop/electron/ipcEvent/index.ts @@ -1,6 +1,7 @@ import { ipcMain } from "electron"; import { registerDicomHandler } from "./dicom/handler"; import { registerCommonHandler } from "./common"; +import { registerAlgHandler } from "./alg"; export const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow) => { ipcMain.removeAllListeners(); @@ -12,4 +13,5 @@ export const registerIpcMainHandlers = (mainWindow: Electron.BrowserWindow) => { registerCommonHandler(); registerDicomHandler(); + registerAlgHandler(); }; diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts index a5d1c15..21a1b60 100644 --- a/apps/desktop/electron/main.ts +++ b/apps/desktop/electron/main.ts @@ -74,7 +74,7 @@ function createWindow() { win.loadURL(VITE_DEV_SERVER_URL); registerIpcMainHandlers(win); runOrthancServer(getPacsPath(platform, true)); - startALGServer(); + if (platform !== "macos") startALGServer(); } else { // if (platform !== "macos") { // python_process = spawn(path.join(process.env.VITE_PUBLIC!, "main.exe")); diff --git a/apps/desktop/src/pages/Viewer/ModelViewer/index.tsx b/apps/desktop/src/pages/Viewer/ModelViewer/index.tsx index 9c9e16c..e628b0e 100644 --- a/apps/desktop/src/pages/Viewer/ModelViewer/index.tsx +++ b/apps/desktop/src/pages/Viewer/ModelViewer/index.tsx @@ -1,3 +1,21 @@ -export const Model3DViewer = () => { - return
3d model
; +import { useEffect, useState } from "react"; +import { useLocation } from "react-router-dom"; + +interface Model3DViewerProps {} + +export const Model3DViewer = (props: Model3DViewerProps) => { + const [assets, setAssets] = useState(); + const location = useLocation(); + const queryParams = new URLSearchParams(location.search); + const SeriesInstanceUID = queryParams.get("SeriesInstanceUID"); + + useEffect(() => { + window.ipcRenderer.invoke("alg:assets", SeriesInstanceUID).then((res) => { + console.log(res); + }); + }); + + return ( +
{SeriesInstanceUID ?
3d
:
启动AI分析该数据
}
+ ); };