mirror of
https://github.com/leaders-of-digital-9-task/dicom-viewer.git
synced 2024-11-22 02:16:32 +03:00
some changes from firesieht
This commit is contained in:
commit
3c9a0462c9
170
index.js
170
index.js
|
@ -4,12 +4,13 @@ var app = new dwv.App();
|
||||||
|
|
||||||
var circleFactory = new dwv.tool.draw.CircleFactory();
|
var circleFactory = new dwv.tool.draw.CircleFactory();
|
||||||
var roiFactory = new dwv.tool.draw.RoiFactory();
|
var roiFactory = new dwv.tool.draw.RoiFactory();
|
||||||
|
schema = []
|
||||||
|
|
||||||
|
|
||||||
var tools = {
|
var tools = {
|
||||||
Scroll: {},
|
Scroll: {},
|
||||||
Draw: {
|
Draw: {
|
||||||
options: ['Circle', 'Roi'],
|
options: ['Circle', 'Roi', 'Ruler', 'FreeHand'],
|
||||||
type: 'factory'
|
type: 'factory'
|
||||||
},
|
},
|
||||||
ZoomAndPan: {},
|
ZoomAndPan: {},
|
||||||
|
@ -29,6 +30,18 @@ app.addEventListener('load', function () {
|
||||||
app.setDrawShape('Circle')
|
app.setDrawShape('Circle')
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function loadSchema(schema) {
|
||||||
|
console.log(schema, schema.length)
|
||||||
|
urls = []
|
||||||
|
picSchema = new Map()
|
||||||
|
for (var i = 0; i < schema.length; ++i) {
|
||||||
|
console.log(i)
|
||||||
|
picSchema.set(schema[i].url, schema[i].figures)
|
||||||
|
urls.push(schema[i].url)
|
||||||
|
}
|
||||||
|
return [urls, picSchema]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
function createCircle(circleData) {
|
function createCircle(circleData) {
|
||||||
var point1 = new dwv.math.Point2D(circleData.center.x, circleData.center.y)
|
var point1 = new dwv.math.Point2D(circleData.center.x, circleData.center.y)
|
||||||
|
@ -53,6 +66,7 @@ function createCircle(circleData) {
|
||||||
})
|
})
|
||||||
//drawCommand = new dwv.tool.DrawGroupCommand(draw, 'circle-group', app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer()['.position-group'][0], false)
|
//drawCommand = new dwv.tool.DrawGroupCommand(draw, 'circle-group', app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer()['.position-group'][0], false)
|
||||||
posGroup = app.getActiveLayerGroup().getActiveDrawLayer().getDrawController().getCurrentPosGroup()
|
posGroup = app.getActiveLayerGroup().getActiveDrawLayer().getDrawController().getCurrentPosGroup()
|
||||||
|
console.log(app.getActiveLayerGroup().getActiveDrawLayer().getDrawController())
|
||||||
posGroup.add(draw)
|
posGroup.add(draw)
|
||||||
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().listening(true)
|
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().listening(true)
|
||||||
//drawCommand.execute()
|
//drawCommand.execute()
|
||||||
|
@ -100,61 +114,60 @@ function createDraws(drawsData) {
|
||||||
|
|
||||||
|
|
||||||
function postCircles() {
|
function postCircles() {
|
||||||
circlesAttrs = app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().getChildren().filter(e => e.attrs.name == 'circle-group').map(
|
|
||||||
(e) => {
|
setTimeout(() => {
|
||||||
return e.children.filter(
|
console.log(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0].children)
|
||||||
(ee) => {
|
}, 100)
|
||||||
return ee.attrs.name == 'shape'
|
// circlesAttrs = app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().getChildren().filter(e => e.attrs.name == 'circle-group').map(
|
||||||
}
|
// (e) => {
|
||||||
).map(e => e.attrs)
|
// //console.log(e)
|
||||||
}
|
// return e.children.filter(
|
||||||
)
|
// (ee) => {
|
||||||
|
// return ee.attrs.name == 'shape'
|
||||||
|
// }
|
||||||
|
// ).map(eee => {return {attrs: eee.attrs, parent: e.attrs}})
|
||||||
|
// }
|
||||||
|
// )
|
||||||
|
circlesAttrs = []
|
||||||
circlesAttrs = circlesAttrs.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0].children.filter(e => e.attrs.name == 'circle-group').map((e) => {
|
circlesAttrs = circlesAttrs.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0].children.filter(e => e.attrs.name == 'circle-group').map((e) => {
|
||||||
return e.children.filter((e) => e.attrs.name == 'shape').map(e => e.attrs)
|
return e.children.filter((eee) => eee.attrs.name == 'shape').map(ee => {return {attrs: ee.attrs, parent: e.attrs}})
|
||||||
}))
|
}))
|
||||||
//circleAttrs.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0])
|
//circleAttrs.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0])
|
||||||
return circlesAttrs.flat().map((e) => {
|
return circlesAttrs.flat().map((e) => {
|
||||||
return {
|
return {
|
||||||
type: 'Circle',
|
type: 'Circle',
|
||||||
center: {
|
center: {
|
||||||
x: e.x,
|
x: e.attrs.x,
|
||||||
y: e.y
|
y: e.attrs.y
|
||||||
},
|
},
|
||||||
radius: e.radius,
|
radius: e.attrs.radius,
|
||||||
id: e.id
|
id: e.parent.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function postRois() {
|
function postRois() {
|
||||||
roisAttrs = app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().getChildren().filter(e => e.attrs.name == 'roi-group').map(
|
roisAttrs = []
|
||||||
(e) => {
|
|
||||||
return e.children.filter(
|
|
||||||
(ee) => {
|
|
||||||
return ee.attrs.name == 'shape'
|
|
||||||
}
|
|
||||||
).map(e => e.attrs)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
roisAttrs = roisAttrs.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0].children.filter(e => e.attrs.name == 'roi-group').map((e) => {
|
roisAttrs = roisAttrs.concat(app.getActiveLayerGroup().getActiveDrawLayer().getKonvaLayer().children[0].children.filter(e => e.attrs.name == 'roi-group').map((e) => {
|
||||||
return e.children.filter((e) => e.attrs.name == 'shape').map(e => e.attrs)
|
return e.children.filter((e) => e.attrs.name == 'shape').map(e => {return {attrs: e.attrs, parent: e.parent.attrs}})
|
||||||
}))
|
}))
|
||||||
return roisAttrs.flat().map((e) => {
|
return roisAttrs.flat().map((e) => {
|
||||||
|
console.log(e)
|
||||||
var points = [];
|
var points = [];
|
||||||
for (var i = 0; i < e.points.length; i+=2) {
|
for (var i = 0; i < e.attrs.points.length; i+=2) {
|
||||||
points.push({x: e.points[i], y: e.points[i+1]})
|
points.push({x: e.attrs.points[i], y: e.attrs.points[i+1]})
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
type: 'Roi',
|
type: 'Roi',
|
||||||
points: points,
|
points: points,
|
||||||
id: e.id
|
id: e.parent.id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function postDraws() {
|
function postDraws() {
|
||||||
return postCircles().concat(postRois())
|
console.log(postRois())
|
||||||
|
return JSON.parse(JSON.stringify(postCircles().concat(postRois())))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -172,15 +185,15 @@ function receiveMessage(event)
|
||||||
} else if(data.type == "setTool"){
|
} else if(data.type == "setTool"){
|
||||||
if (data.data == "null"){
|
if (data.data == "null"){
|
||||||
app.setTool('Scroll');
|
app.setTool('Scroll');
|
||||||
} else if (data.data == 'Roi' || data.data == 'Circle'){
|
|
||||||
app.setTool('Draw');
|
|
||||||
app.setDrawShape(data.data);
|
|
||||||
}
|
}
|
||||||
else if (data.data == 'ZoomAndPan') {
|
else if (data.data == 'ZoomAndPan') {
|
||||||
app.setTool('ZoomAndPan');
|
app.setTool('ZoomAndPan');
|
||||||
}
|
}
|
||||||
else if (data.data == 'WindowLevel') {
|
else if (data.data == 'WindowLevel') {
|
||||||
app.setTool('WindowLevel')
|
app.setTool('WindowLevel')
|
||||||
|
}else {
|
||||||
|
app.setTool('Draw');
|
||||||
|
app.setDrawShape(data.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (data.type == 'setDraws') {
|
else if (data.type == 'setDraws') {
|
||||||
|
@ -200,6 +213,9 @@ function receiveMessage(event)
|
||||||
else if (data.type == 'deleteById') {
|
else if (data.type == 'deleteById') {
|
||||||
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().find("#"+data.data)[0].destroy()
|
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().find("#"+data.data)[0].destroy()
|
||||||
}
|
}
|
||||||
|
else if (data.type == 'loadSchema') {
|
||||||
|
schema = loadSchema(data.data)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
window.addEventListener("message", receiveMessage, false);
|
window.addEventListener("message", receiveMessage, false);
|
||||||
|
|
||||||
|
@ -209,7 +225,6 @@ function findActive() {
|
||||||
(e) => {
|
(e) => {
|
||||||
return e.children.filter(
|
return e.children.filter(
|
||||||
(ee) => {
|
(ee) => {
|
||||||
console.log(e)
|
|
||||||
return ee.attrs.name == 'anchor'
|
return ee.attrs.name == 'anchor'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -227,12 +242,91 @@ app.addEventListener('loadend', function () {
|
||||||
//range.max = app.getImage(0).getGeometry().getSize().get(2) - 1;
|
//range.max = app.getImage(0).getGeometry().getSize().get(2) - 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
//app.loadURLs(['https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm'])
|
|
||||||
|
// schema = [
|
||||||
|
// {
|
||||||
|
// 'url': 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm',
|
||||||
|
// 'figures': [
|
||||||
|
// {type: 'Circle', center: {x: 10, y: 100}, radius: 10},
|
||||||
|
// {type: 'Roi', points: [{x: 10, y: 20}, {x: 100, y: 50}]}
|
||||||
|
// ]
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// 'url': 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323707.dcm',
|
||||||
|
// 'figures': [
|
||||||
|
// {type: 'Circle', center: {x: 10, y: 200}, radius: 10},
|
||||||
|
// {type: 'Roi', points: [{x: 10, y: 30}, {x: 100, y: 50}]}
|
||||||
|
// ]
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
|
|
||||||
|
// schema = loadSchema(schema)
|
||||||
|
|
||||||
|
// console.log(schema[0], "0")
|
||||||
|
|
||||||
|
|
||||||
|
// app.loadURLs(schema[0])
|
||||||
|
|
||||||
|
|
||||||
|
// app.loadURLs([
|
||||||
|
// 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323851.dcm',
|
||||||
|
// 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323707.dcm',
|
||||||
|
// 'https://raw.githubusercontent.com/ivmartel/dwv/master/tests/data/bbmri-53323563.dcm'
|
||||||
|
// ])
|
||||||
|
|
||||||
|
function setFrame(frameNumber) {
|
||||||
|
var lg = app.getLayerGroupById(0);
|
||||||
|
var vc = lg.getActiveViewLayer().getViewController();
|
||||||
|
var index = vc.getCurrentIndex();
|
||||||
|
var values = index.getValues();
|
||||||
|
values[2] = frameNumber;
|
||||||
|
vc.setCurrentIndex(new dwv.math.Index(values));
|
||||||
|
loadPictures(
|
||||||
|
schema[1].get(schema[0][frameNumber])
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadPictures(pictures) {
|
||||||
|
// app.deleteDraws()
|
||||||
|
deleteDraws()
|
||||||
|
app.setTool('Draw')
|
||||||
|
pictures.map((e) => {
|
||||||
|
if (e.type == 'Circle') {
|
||||||
|
createCircle(e)
|
||||||
|
}
|
||||||
|
else if (e.type == 'Roi') {
|
||||||
|
createRoi(e)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteDraws() {
|
||||||
|
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().find('.circle-group').map((e) => e.destroy())
|
||||||
|
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().find('.roi-group').map((e) => e.destroy())
|
||||||
|
}
|
||||||
|
|
||||||
app.addEventListener('load', () => {
|
app.addEventListener('load', () => {
|
||||||
// app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().addEventListener('mouseup', () => {
|
|
||||||
// parent.postMessage({'type': 'returnDraws', data: postDraws()}, "*")
|
// app.setDrawShape('Roi')
|
||||||
// })
|
app.setTool("Scroll")
|
||||||
|
setFrame(0)
|
||||||
|
// loadPictures([
|
||||||
|
// {type: 'Circle', center: {x: 10, y: 100}, radius: 10},
|
||||||
|
// {type: 'Roi', points: [{x: 10, y: 20}, {x: 100, y: 50}]}
|
||||||
|
// ])
|
||||||
|
setTimeout(() => {
|
||||||
|
setFrame(1)
|
||||||
|
}, 1000)
|
||||||
|
var lg = app.getLayerGroupById(0);
|
||||||
|
var vc = lg.getActiveViewLayer().getViewController();
|
||||||
|
console.log(vc.getCurrentScrollIndexValue())
|
||||||
|
//app.getActiveLayerGroup().getActiveViewLayer().getViewController().setCurrentIndex(new dwv.math.Index(1))
|
||||||
|
app.getActiveLayerGroup().getActiveDrawLayer().getKonvaStage().addEventListener('mouseup', () => {
|
||||||
|
setTimeout(() => {
|
||||||
|
parent.postMessage({'type': 'returnDraws', data: postDraws()}, "*")
|
||||||
|
//console.log({'type': 'returnDraws', data: postDraws()})
|
||||||
|
}, 100)
|
||||||
|
})
|
||||||
// createCircle({
|
// createCircle({
|
||||||
// type: 'Circle',
|
// type: 'Circle',
|
||||||
// center: {
|
// center: {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user