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

63 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-09-20 15:55:17 +08:00
import { app, 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";
2024-09-20 15:55:17 +08:00
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 () => {
await db.read();
const optPath = db.data.setting.outputPath;
const resolvedPath = path.resolve(optPath);
try {
// 检查路径是否存在
const stats = await stat(resolvedPath);
if (stats.isDirectory()) shell.openPath(resolvedPath);
} catch (error) {
log.error(error);
await mkdir(resolvedPath, { recursive: true });
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: `操作失败` };
}
});
2024-09-20 15:55:17 +08:00
2024-09-22 22:11:12 +08:00
ipcMain.on("model:infer", async (event, SeriesInstanceUIDs) => {
console.log('SeriesInstanceUIDs', SeriesInstanceUIDs)
2024-09-20 15:55:17 +08:00
// 构造推理任务参数列表
const pu = InferDeviceEnum.GPU;
2024-09-20 16:48:32 +08:00
const module = InferStructuralEnum.AORTA;
2024-09-20 15:55:17 +08:00
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
);
2024-09-20 15:55:17 +08:00
const task = { save_path, pu, module, turbo, seg_schedule, img_path };
2024-09-22 22:11:12 +08:00
console.log('infer task: ', task);
2024-09-20 15:55:17 +08:00
const result = await executeInferTask(task, (data) => {
2024-09-22 22:11:12 +08:00
console.log(data)
event.reply('infer:progress', data)
2024-09-20 15:55:17 +08:00
});
console.log("end: ", result);
}
});
};