Commit 32ea0562 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Merge branch 'fixes' into 'main'

fixes

See merge request !4
parents 202fb5bd 28454375
Loading
Loading
Loading
Loading
Loading
+30 −5
Original line number Original line Diff line number Diff line
const express = require('express');
const express = require('express');
const bodyParser = require('body-parser');
const bodyParser = require('body-parser');
const mriAddon = require('./build/Release/mriAddon');
const mriAddon = require('./build/Release/mriAddon');
const { Worker } = require('worker_threads');


const app = express();
const app = express();
const port = 8080;
const port = 8080;
@@ -8,7 +9,19 @@ const port = 8080;
app.use(express.static("public"));
app.use(express.static("public"));
app.use(bodyParser.json({limit: '500mb'}));
app.use(bodyParser.json({limit: '500mb'}));


app.post("/segmentation", (req, res) => {
const callWorker = (path, data) => {
    return new Promise((resolve, reject) => {
        const worker = new Worker(path, {workerData: data});
        worker.on('message', resolve);
        worker.on('error', reject);
        worker.on('exit', (code) => {
            if (code !== 0)
                reject(new Error(`stopped with  ${code} exit code`));
        });
    });
};

app.post("/segmentation", async (req, res) => {
    let height = req.body.parameters.height;
    let height = req.body.parameters.height;
    let width = req.body.parameters.width;
    let width = req.body.parameters.width;
    let centerX = req.body.parameters.inputParameters.centerX;
    let centerX = req.body.parameters.inputParameters.centerX;
@@ -22,12 +35,19 @@ app.post("/segmentation", (req, res) => {
    let outerRadius = Math.sqrt(Math.pow(outerX - centerX, 2.0) + Math.pow(outerY - centerY, 2.0));
    let outerRadius = Math.sqrt(Math.pow(outerX - centerX, 2.0) + Math.pow(outerY - centerY, 2.0));
    let innerRadius = Math.sqrt(Math.pow(innerX - centerX, 2.0) + Math.pow(innerY - centerY, 2.0));
    let innerRadius = Math.sqrt(Math.pow(innerX - centerX, 2.0) + Math.pow(innerY - centerY, 2.0));
    let pixelData = new Float64Array(req.body.pixelData);
    let pixelData = new Float64Array(req.body.pixelData);
    let segmented = new Float64Array(mriAddon.levelSet(outerRadius, innerRadius, centerY, centerX, K1, K2,
    let segmented = await callWorker('./workers/levelSet.js', {outerRadius: outerRadius,
                                                        height, width, pixelData.buffer));
                                                                         innerRadius: innerRadius,
                                                                         centerY: centerY,
                                                                         centerX: centerX,
                                                                         K1: K1,
                                                                         K2: K2,
                                                                         height: height,
                                                                         width: width,
                                                                         buffer: pixelData.buffer});
    res.send(Object.values(segmented));
    res.send(Object.values(segmented));
});
});


app.post("/optf", (req, res) => {
app.post("/optf", async (req, res) => {
    let height = req.body.parameters.height;
    let height = req.body.parameters.height;
    let width = req.body.parameters.width;
    let width = req.body.parameters.width;
    let centerX = req.body.parameters.inputParameters.centerX;
    let centerX = req.body.parameters.inputParameters.centerX;
@@ -42,7 +62,12 @@ app.post("/optf", (req, res) => {
    mergedArray.set(targetSegmented);
    mergedArray.set(targetSegmented);
    mergedArray.set(sourceSegmented, width * height);
    mergedArray.set(sourceSegmented, width * height);
    mergedArray.set(sourceOriginal, width * height * 2);
    mergedArray.set(sourceOriginal, width * height * 2);
    let optf = new Float64Array(mriAddon.optf(outerRadius, centerY, centerX, height, width, mergedArray.buffer));
    let optf = await callWorker('./workers/optf.js', {outerRadius: outerRadius,
                                                                centerY: centerY,
                                                                centerX: centerX,
                                                                height: height,
                                                                width: width,
                                                                buffer: mergedArray.buffer});
    res.send(Object.values(optf));
    res.send(Object.values(optf));
});
});


+3 −3
Original line number Original line Diff line number Diff line
@@ -6,8 +6,8 @@
                'AdditionalOptions': ['/MT', '/openmp']
                'AdditionalOptions': ['/MT', '/openmp']
            }
            }
        },
        },
        "cflags!": ["-fno-exceptions -O3 -fopenmp"],
        "cflags!": ["-fno-exceptions"],
        "cflags_cc!": ["-fno-exceptions -O3 -fopenmp"],
        "cflags_cc!": ["-fno-exceptions"],
        "sources": [
        "sources": [
            "addon/mri.cpp",
            "addon/mri.cpp",
            "addon/common.h",
            "addon/common.h",
+237 −72

File changed.

Preview size limit exceeded, changes collapsed.

+221 −45

File changed.

Preview size limit exceeded, changes collapsed.

+171 −20

File changed.

Preview size limit exceeded, changes collapsed.

Loading