Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMUII-8068: lungs brain segmentation improvements #199

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/store/ActionTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ const StoreActionType = {
SET_SHOW_MODAL_SELECT_FILES: 43,
SET_SELECTED_COLOR: 44,
SET_DEFAULT_3D_POSITION: 45,
SET_LUNGS_SEED_STATUS: 46,
};
export default StoreActionType;
4 changes: 4 additions & 0 deletions src/store/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const initialState = {
showModalSelectFiles: false,
selectedColor: '#ffff00',
isDefault3dPosition: false,
lungsSeedStatus: false,
};
//
// App reducer
Expand Down Expand Up @@ -150,6 +151,9 @@ const medReducer = (state = initialState, action) => {
return Object.assign({}, state, { selectedColor: action.selectedColor });
case StoreActionType.SET_DEFAULT_3D_POSITION:
return Object.assign({}, state, { isDefault3dPosition: action.isDefault3dPosition });
case StoreActionType.SET_LUNGS_SEED_STATUS:
return Object.assign({}, state, { lungsSeedStatus: action.lungsSeedStatus });

default:
return state;
}
Expand Down
24 changes: 21 additions & 3 deletions src/ui/Main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ import PositionTool3D from './Toolbars/PositionTool3D';

export const Main = () => {
const dispatch = useDispatch();
const { isLoaded, progress, spinner, viewMode, showModalText, showModalAlert, showModalWindowCW, showModalConfirmation } = useSelector(
(state) => state
);
const {
isLoaded,
progress,
spinner,
viewMode,
showModalText,
showModalAlert,
showModalWindowCW,
showModalConfirmation,
lungsSeedStatus,
} = useSelector((state) => state);

const [m_fileNameOnLoad, setM_fileNameOnLoad] = useState(false);
const [isWebGl20supported, setIsWebGl20supported] = useState(true);
Expand Down Expand Up @@ -188,6 +196,16 @@ export const Main = () => {

useOnEvent(mriEventsService.FILE_READ_SUCCESS, onHide);

//Alret message does not catch all cases then loaded image, which does not contain lungs
useEffect(() => {
if (lungsSeedStatus) {
setStrAlertTitle('Attention!');
setStrAlertText(' Please note, the uploaded image may not contain lungs!');
onShowModalAlert();
dispatch({ type: StoreActionType.SET_LUNGS_SEED_STATUS, lungsSeedStatus: false });
}
});

return (
<AppContextProvider>
<div ref={appRef} style={{ height: '100%' }}>
Expand Down
12 changes: 7 additions & 5 deletions src/ui/TopToolbar/Filter/Jobs/lungsFillJob.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,25 @@
import SeedPoints from '../../../../engine/actvolume/lungsfill/seedPoints';
import FloodFillTool from '../../../../engine/actvolume/lungsfill/floodfill';

const getSeedPointOnCentralSlice = (volTexSrc, xDim, yDim, zDim) => {
const getSeedPointOnCentralSlice = (volTexSrc, xDim, yDim, zDim, setSeed) => {
let vSeed = { x: 0, y: 0, z: 0 };
const seedPoints = new SeedPoints(volTexSrc, xDim, yDim, zDim);
const resFind = seedPoints.findSeedPointOnCentralSlice(vSeed);
if (resFind) {
console.log('Lungs Central fill run: seed point not found');
setSeed(true);
return false;
}
return vSeed;
};

const getSeedPointOnFirstSlice = (volTexSrc, xDim, yDim, zDim) => {
const getSeedPointOnFirstSlice = (volTexSrc, xDim, yDim, zDim, setSeed) => {
let vSeed = { x: 0, y: 0, z: 0 };
const seedPoints = new SeedPoints(volTexSrc, xDim, yDim, zDim);
const resFind = seedPoints.findSeedPointOnFirstSlice(vSeed);
if (resFind) {
console.log('Airway fill run: seed point not found');
setSeed(true);
return false;
}
return vSeed;
Expand Down Expand Up @@ -111,7 +113,7 @@ const detectNonEmptyBox = (xDim, yDim, zDim, volTexMask) => {
return { xBorderMin, xBorderMax, yBorderMin, yBorderMax };
};

export const lungsFillJob = (volume) => {
export const lungsFillJob = (volume, setSeed) => {
let xDim = volume.m_xDim;
let yDim = volume.m_yDim;
let zDim = volume.m_zDim;
Expand Down Expand Up @@ -197,7 +199,7 @@ export const lungsFillJob = (volume) => {

const run = () => {
if (getProgress() === 0) {
seedOnCentralSlice = getSeedPointOnCentralSlice(volTexSrc, xDim, yDim, zDim);
seedOnCentralSlice = getSeedPointOnCentralSlice(volTexSrc, xDim, yDim, zDim, setSeed);
if (!seedOnCentralSlice) {
setProgress(0);
return true;
Expand Down Expand Up @@ -231,7 +233,7 @@ export const lungsFillJob = (volume) => {
volTexMask1[i] = volTexSrc[i];
}

seedOnFirstSlice = getSeedPointOnFirstSlice(volTexSrc, xDim, yDim, zDim);
seedOnFirstSlice = getSeedPointOnFirstSlice(volTexSrc, xDim, yDim, zDim, setSeed);
if (!seedOnFirstSlice) {
setProgress(0);
return true;
Expand Down
21 changes: 17 additions & 4 deletions src/ui/TopToolbar/Filter/LungsTool.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,42 @@
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { useSelector } from 'react-redux';
import React, { useState, useEffect } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import StoreActionType from '../../../store/ActionTypes';
import { ToolButton } from '../ToolButton';
import { checkVolume } from './checkVolume';
import { useAppContext } from '../../App/AppContext';
import { lungsFillJob } from './Jobs/lungsFillJob';

export const LungsTool = () => {
const { startJob } = useAppContext();
const dispatch = useDispatch();
const { volumeSet, volumeIndex, graphics2d } = useSelector((state) => state);

const volume = volumeSet.getVolume(volumeIndex);
const [isSeed, setSeed] = useState(false);

const handleChange = () => {
if (!checkVolume(volume)) {
return;
}

startJob(lungsFillJob(volume), () => {
startJob(lungsFillJob(volume, setSeed), () => {
// update render
graphics2d.forceUpdate();
});
};

return <ToolButton content="Lungs segmentation" onChange={handleChange} icon="lungs" />;
useEffect(() => {
if (isSeed) {
dispatch({ type: StoreActionType.SET_LUNGS_SEED_STATUS, lungsSeedStatus: true });
setSeed(false);
}
}, [isSeed]);
return (
<>
<ToolButton content="Lungs segmentation" onChange={handleChange} icon="lungs" />
</>
);
};
Loading