cvpilot-tool/apps/desktop/electron/ipcEvent/alg/index.ts

54 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-09-23 13:02:38 +08:00
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);
});
};