Loading apps/MRI/app.js +30 −5 Original line number Diff line number Diff line const express = require('express'); const bodyParser = require('body-parser'); const mriAddon = require('./build/Release/mriAddon'); const { Worker } = require('worker_threads'); const app = express(); const port = 8080; Loading @@ -8,7 +9,19 @@ const port = 8080; app.use(express.static("public")); 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 width = req.body.parameters.width; let centerX = req.body.parameters.inputParameters.centerX; Loading @@ -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 innerRadius = Math.sqrt(Math.pow(innerX - centerX, 2.0) + Math.pow(innerY - centerY, 2.0)); let pixelData = new Float64Array(req.body.pixelData); let segmented = new Float64Array(mriAddon.levelSet(outerRadius, innerRadius, centerY, centerX, K1, K2, height, width, pixelData.buffer)); let segmented = await callWorker('./workers/levelSet.js', {outerRadius: outerRadius, innerRadius: innerRadius, centerY: centerY, centerX: centerX, K1: K1, K2: K2, height: height, width: width, buffer: pixelData.buffer}); res.send(Object.values(segmented)); }); app.post("/optf", (req, res) => { app.post("/optf", async (req, res) => { let height = req.body.parameters.height; let width = req.body.parameters.width; let centerX = req.body.parameters.inputParameters.centerX; Loading @@ -42,7 +62,12 @@ app.post("/optf", (req, res) => { mergedArray.set(targetSegmented); mergedArray.set(sourceSegmented, width * height); 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)); }); Loading apps/MRI/binding.gyp +3 −3 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ 'AdditionalOptions': ['/MT', '/openmp'] } }, "cflags!": ["-fno-exceptions -O3 -fopenmp"], "cflags_cc!": ["-fno-exceptions -O3 -fopenmp"], "cflags!": ["-fno-exceptions"], "cflags_cc!": ["-fno-exceptions"], "sources": [ "addon/mri.cpp", "addon/common.h", Loading Loading
apps/MRI/app.js +30 −5 Original line number Diff line number Diff line const express = require('express'); const bodyParser = require('body-parser'); const mriAddon = require('./build/Release/mriAddon'); const { Worker } = require('worker_threads'); const app = express(); const port = 8080; Loading @@ -8,7 +9,19 @@ const port = 8080; app.use(express.static("public")); 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 width = req.body.parameters.width; let centerX = req.body.parameters.inputParameters.centerX; Loading @@ -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 innerRadius = Math.sqrt(Math.pow(innerX - centerX, 2.0) + Math.pow(innerY - centerY, 2.0)); let pixelData = new Float64Array(req.body.pixelData); let segmented = new Float64Array(mriAddon.levelSet(outerRadius, innerRadius, centerY, centerX, K1, K2, height, width, pixelData.buffer)); let segmented = await callWorker('./workers/levelSet.js', {outerRadius: outerRadius, innerRadius: innerRadius, centerY: centerY, centerX: centerX, K1: K1, K2: K2, height: height, width: width, buffer: pixelData.buffer}); res.send(Object.values(segmented)); }); app.post("/optf", (req, res) => { app.post("/optf", async (req, res) => { let height = req.body.parameters.height; let width = req.body.parameters.width; let centerX = req.body.parameters.inputParameters.centerX; Loading @@ -42,7 +62,12 @@ app.post("/optf", (req, res) => { mergedArray.set(targetSegmented); mergedArray.set(sourceSegmented, width * height); 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)); }); Loading
apps/MRI/binding.gyp +3 −3 Original line number Diff line number Diff line Loading @@ -6,8 +6,8 @@ 'AdditionalOptions': ['/MT', '/openmp'] } }, "cflags!": ["-fno-exceptions -O3 -fopenmp"], "cflags_cc!": ["-fno-exceptions -O3 -fopenmp"], "cflags!": ["-fno-exceptions"], "cflags_cc!": ["-fno-exceptions"], "sources": [ "addon/mri.cpp", "addon/common.h", Loading