feat: temp
This commit is contained in:
parent
72aae0c40f
commit
db8ba53589
53
apps/desktop/electron/ipcEvent/alg/index.ts
Normal file
53
apps/desktop/electron/ipcEvent/alg/index.ts
Normal file
|
@ -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);
|
||||
});
|
||||
};
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -1,3 +1,21 @@
|
|||
export const Model3DViewer = () => {
|
||||
return <div>3d model</div>;
|
||||
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 (
|
||||
<div>{SeriesInstanceUID ? <div>3d</div> : <div>启动AI分析该数据</div>}</div>
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user