Skip to content

Commit

Permalink
Add referencePoints to annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmartel committed Jul 17, 2024
1 parent 67770f4 commit 1035e39
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 15 deletions.
10 changes: 10 additions & 0 deletions src/dicom/dicomCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ const DcmCodes = {
121055: 'Path',
121322: 'Source image for image processing operation',
121324: 'Source Image',
122438: 'Reference Points',
125007: 'Measurement Group',
125309: 'Short label'
};
Expand Down Expand Up @@ -248,3 +249,12 @@ export function getSourceImageForProcessingCode() {
export function getShortLabelCode() {
return getDicomCode('125309');
}

/**
* Get a reference points DICOM code.
*
* @returns {DicomCode} The code.
*/
export function getReferencePointsCode() {
return getDicomCode('122438');
}
2 changes: 1 addition & 1 deletion src/dicom/dicomSpatialCoordinate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const TagKeys = {
/**
* DICOM graphic types.
*/
const GraphicTypes = {
export const GraphicTypes = {
point: 'POINT',
multipoint: 'MULTIPOINT',
polyline: 'POLYLINE',
Expand Down
7 changes: 7 additions & 0 deletions src/image/annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ export class Annotation {
*/
mathShape;

/**
* Additional points used to define the annotation.
*
* @type {Point2D[]}
*/
referencePoints;

/**
* The color: for example 'green', '#00ff00' or 'rgb(0,255,0)'.
*
Expand Down
70 changes: 56 additions & 14 deletions src/image/annotationFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@ import {
DicomSRContent
} from '../dicom/dicomSRContent';
import {
isEqualCode,
getPathCode,
getMeasurementGroupCode,
getImageRegionCode,
getSourceImageCode,
getTrackingIdentifierCode,
getShortLabelCode
getShortLabelCode,
getReferencePointsCode
} from '../dicom/dicomCode';
import {getElementsFromJSONTags} from '../dicom/dicomWriter';
import {ImageReference} from '../dicom/dicomImageReference';
import {SopInstanceReference} from '../dicom/dicomSopInstanceReference';
import {
GraphicTypes,
getScoordFromShape,
getShapeFromScoord
getShapeFromScoord,
SpatialCoordinate
} from '../dicom/dicomSpatialCoordinate';
import {guid} from '../math/stats';
import {logger} from '../utils/logger';
import {Annotation, AnnotationGroup} from './annotation';
import {Line} from '../math/line';
import {Point2D} from '../math/point';

// doc imports
/* eslint-disable no-unused-vars */
import {DataElement} from '../dicom/dataElement';
import {ViewController} from '../app/viewController';
/* eslint-enable no-unused-vars */

/**
Expand Down Expand Up @@ -118,18 +122,34 @@ export class AnnotationFactory {

for (const subItem of item.contentSequence) {
if (subItem.valueType === ValueTypes.image &&
subItem.relationshipType === RelationshipTypes.selectedFrom) {
subItem.relationshipType === RelationshipTypes.selectedFrom &&
isEqualCode(subItem.conceptNameCode, getSourceImageCode())) {
annotation.referenceSopUID =
subItem.value.referencedSOPSequence.referencedSOPInstanceUID;
}
if (subItem.valueType === ValueTypes.uidref &&
subItem.relationshipType === RelationshipTypes.hasProperties) {
subItem.relationshipType === RelationshipTypes.hasProperties &&
isEqualCode(subItem.conceptNameCode, getTrackingIdentifierCode())) {
annotation.id = subItem.value;
}
if (subItem.valueType === ValueTypes.text &&
subItem.relationshipType === RelationshipTypes.hasProperties) {
subItem.relationshipType === RelationshipTypes.hasProperties &&
isEqualCode(subItem.conceptNameCode, getShortLabelCode())) {
annotation.textExpr = subItem.value;
}
if (subItem.valueType === ValueTypes.scoord &&
subItem.relationshipType === RelationshipTypes.hasProperties &&
isEqualCode(subItem.conceptNameCode, getReferencePointsCode()) &&
subItem.value.graphicType === GraphicTypes.multipoint) {
const points = [];
for (let i = 0; i < subItem.value.graphicData.length; i += 2) {
points.push(new Point2D(
subItem.value.graphicData[i],
subItem.value.graphicData[i + 1]
));
}
annotation.referencePoints = points;
}
}

annotations.push(annotation);
Expand Down Expand Up @@ -200,6 +220,17 @@ export class AnnotationFactory {
const contentSequence = [];

for (const annotation of annotationGroup.getList()) {
const srScoord = new DicomSRContent(ValueTypes.scoord);
srScoord.relationshipType = RelationshipTypes.contains;
if (annotation.mathShape instanceof Line) {
srScoord.conceptNameCode = getPathCode();
} else {
srScoord.conceptNameCode = getImageRegionCode();
}
srScoord.value = getScoordFromShape(annotation.mathShape);

const itemContentSequence = [];

const srImage = new DicomSRContent(ValueTypes.image);
srImage.relationshipType = RelationshipTypes.selectedFrom;
srImage.conceptNameCode = getSourceImageCode();
Expand All @@ -209,27 +240,38 @@ export class AnnotationFactory {
const imageRef = new ImageReference();
imageRef.referencedSOPSequence = sopRef;
srImage.value = imageRef;
itemContentSequence.push(srImage);

const srUid = new DicomSRContent(ValueTypes.uidref);
srUid.relationshipType = RelationshipTypes.hasProperties;
srUid.conceptNameCode = getTrackingIdentifierCode();
srUid.value = annotation.id;
itemContentSequence.push(srUid);

const shortLabel = new DicomSRContent(ValueTypes.text);
shortLabel.relationshipType = RelationshipTypes.hasProperties;
shortLabel.conceptNameCode = getShortLabelCode();
shortLabel.value = annotation.textExpr;
itemContentSequence.push(shortLabel);

if (typeof annotation.referencePoints !== 'undefined') {
const referencePoints = new DicomSRContent(ValueTypes.scoord);
referencePoints.relationshipType = RelationshipTypes.hasProperties;
referencePoints.conceptNameCode = getReferencePointsCode();
const refPointsScoord = new SpatialCoordinate();
refPointsScoord.graphicType = GraphicTypes.multipoint;
const graphicData = [];
for (const point of annotation.referencePoints) {
graphicData.push(point.getX().toString());
graphicData.push(point.getY().toString());
}
refPointsScoord.graphicData = graphicData;

const srScoord = new DicomSRContent(ValueTypes.scoord);
srScoord.relationshipType = RelationshipTypes.contains;
if (annotation.mathShape instanceof Line) {
srScoord.conceptNameCode = getPathCode();
} else {
srScoord.conceptNameCode = getImageRegionCode();
referencePoints.value = refPointsScoord;
itemContentSequence.push(referencePoints);
}
srScoord.value = getScoordFromShape(annotation.mathShape);
srScoord.contentSequence = [srImage, srUid, shortLabel];

srScoord.contentSequence = itemContentSequence;
contentSequence.push(srScoord);
}

Expand Down

0 comments on commit 1035e39

Please sign in to comment.