Skip to content

Commit

Permalink
Move annotation and layer creation to app
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jul 19, 2024
1 parent b78c47c commit ca19ae8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 24 deletions.
45 changes: 45 additions & 0 deletions src/app/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {toolList, defaultToolList, toolOptions} from '../tools';
import {binderList} from '../gui/stage';
import {WindowLevel} from '../image/windowLevel';
import {PlaneHelper} from '../image/planeHelper';
import {AnnotationGroup} from '../image/annotation';

// doc imports
/* eslint-disable no-unused-vars */
Expand Down Expand Up @@ -1447,6 +1448,50 @@ export class App {
}
}

/**
* Create new annotation data based on the data of
* the active view layer.
*
* @param {LayerGroup} layerGroup The layerGroup with the data to associate
* to the annotation.
* @returns {DicomData} The new data.
*/
createAnnotationData(layerGroup) {
const viewLayer = layerGroup.getActiveViewLayer();
const refData = this.getData(viewLayer.getDataId());
const refMeta = refData.image.getMeta();

const data = new DicomData({});
data.annotationGroup = new AnnotationGroup();
data.annotationGroup.setMetaValue('Modality', 'SR');
data.annotationGroup.setMetaValue(
'PatientID', refMeta.PatientID);
data.annotationGroup.setMetaValue(
'StudyInstanceUID', refMeta.StudyInstanceUID);
data.annotationGroup.setMetaValue(
'ReferencedSeriesSequence', {
value: [{
SeriesInstanceUID: refMeta.SeriesInstanceUID
}]
});
return data;
}

/**
* Add new data and render it with a simple new data view config.
*
* @param {DicomData} data The data to add.
* @param {string} divId The div where to draw.
*/
addAndRenderAnnotationData(data, divId) {
// add new data
const dataId = this.addData(data);
// add simple data view config
this.addDataViewConfig(dataId, new ViewConfig(divId));
// render (will create draw layer)
this.render(dataId);
}

// Private Methods -----------------------------------------------------------

/**
Expand Down
30 changes: 6 additions & 24 deletions src/tools/draw.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {getLayerDetailsFromEvent} from '../gui/layerGroup';
import {DicomData} from '../app/dataController';
import {ViewConfig} from '../app/application';
import {
getMousePoint,
getTouchPoints
Expand All @@ -14,7 +12,7 @@ import {
import {
isNodeNameShape,
} from './drawBounds';
import {Annotation, AnnotationGroup} from '../image/annotation';
import {Annotation} from '../image/annotation';
import {ScrollWheel} from './scrollWheel';

// external
Expand Down Expand Up @@ -177,6 +175,7 @@ export class Draw {
this.#style = app.getStyle();
}


/**
* Start tool interaction.
*
Expand All @@ -189,30 +188,13 @@ export class Draw {

if (typeof drawLayer === 'undefined') {
// create new data
const viewLayer = layerGroup.getActiveViewLayer();
const refData = this.#app.getData(viewLayer.getDataId());
const refMeta = refData.image.getMeta();
const data = new DicomData({});
data.annotationGroup = new AnnotationGroup();
data.annotationGroup.setMetaValue('Modality', 'SR');
data.annotationGroup.setMetaValue(
'PatientID', refMeta.PatientID);
data.annotationGroup.setMetaValue(
'StudyInstanceUID', refMeta.StudyInstanceUID);
data.annotationGroup.setMetaValue(
'ReferencedSeriesSequence', {
value: [{
SeriesInstanceUID: refMeta.SeriesInstanceUID
}]
});
const dataId = this.#app.addData(data);
const data = this.#app.createAnnotationData(layerGroup);
// render (will create draw layer)
this.#app.addDataViewConfig(dataId, new ViewConfig(divId));
this.#app.render(dataId);

this.#app.addAndRenderAnnotationData(data, divId);
// get draw layer
drawLayer = layerGroup.getActiveDrawLayer();
// set active to bind to toolboxController
layerGroup.setActiveDrawLayerByDataId(dataId);
layerGroup.setActiveDrawLayerByDataId(drawLayer.getDataId());
}

// set the layer shape handler
Expand Down

0 comments on commit ca19ae8

Please sign in to comment.