Skip to content

Commit 9f3c9ee

Browse files
committed
adding flat coordinates when creating circles
1 parent 97a4cc7 commit 9f3c9ee

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

src/api.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,17 @@ function _geometry2Scoord3d(geometry, pyramid) {
6161
});
6262
return new Polyline(coordinates);
6363
} else if (type === 'Circle') {
64-
let center = _geometryCoordinates2scoord3dCoordinates(geometry.getCenter(), pyramid);
65-
// FIXME: radius also needs to be rescaled
66-
let radius = geometry.getRadius();
67-
return new Circle(center, radius);
64+
// chunking the Flat Coordinates into two arrays within 3 elements each
65+
let coordinates = geometry.getFlatCoordinates().reduce((all,one,i) => {
66+
const ch = Math.floor(i/2)
67+
all[ch] = [].concat((all[ch]||[]),one)
68+
return all
69+
}, [])
70+
coordinates = coordinates.map(c => {
71+
c.push(0)
72+
return _geometryCoordinates2scoord3dCoordinates(c, pyramid)
73+
})
74+
return new Circle(coordinates);
6875
} else {
6976
// TODO: Combine multiple points into MULTIPOINT.
7077
console.error(`unknown geometry type "${type}"`)
@@ -88,9 +95,15 @@ function _scoord3d2Geometry(scoord3d, pyramid) {
8895
});
8996
return new PolygonGeometry([coordinates]);
9097
} else if (type === 'CIRCLE') {
91-
let center = _scoord3dCoordinates2geometryCoordinates(data[0], pyramid);
92-
let radius = data[1];
93-
return new CircleGeometry(center, radius);
98+
let coordinates = data.map(d => {
99+
return _scoord3dCoordinates2geometryCoordinates(d, pyramid);
100+
})
101+
// to flat coordinates
102+
coordinates = [...coordinates[0].slice(0,2), ...coordinates[1].slice(0,2)]
103+
104+
// flat coordinates in combination with opt_layout and no opt_radius are also accepted
105+
// and internaly it calculates the Radius
106+
return new CircleGeometry(coordinates, null, "XY");
94107
} else {
95108
console.error(`unsupported graphic type "${type}"`)
96109
}

src/scoord3d.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,15 @@ class Polygon extends Scoord3D {
135135

136136
class Circle extends Scoord3D {
137137

138-
constructor(centerCoordinates, radius) {
138+
constructor(coordinates) {
139139
super()
140-
if (!Array.isArray(centerCoordinates)) {
140+
if (!Array.isArray(coordinates)) {
141141
throw new Error('coordinates of Circle must be an array')
142142
}
143-
if (centerCoordinates.length !== 3) {
144-
throw new Error('center coordinates of Circle must be an array of length 3')
145-
}
146-
if (radius === undefined) {
147-
throw new Error('radius has to be defined')
143+
if(coordinates.find(c => c.length !== 3)!== undefined){
144+
throw new Error('coordinates of Circle must be a list or size two with points of length 3')
148145
}
149-
this[_centerCoordinates] = centerCoordinates
150-
this[_radius] = radius
146+
this[_coordinates] = coordinates
151147
}
152148

153149
get graphicData() {
@@ -156,9 +152,7 @@ class Circle extends Scoord3D {
156152
* The first point is the central pixel.
157153
* The second point is a pixel on the perimeter of the circle.
158154
*/
159-
return [
160-
this[_centerCoordinates],
161-
[this[_centerCoordinates][0], this[_centerCoordinates][1] + this[_radius], 1]]
155+
return this[_coordinates]
162156
}
163157

164158
get graphicType() {

test/api.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ describe('dicomMicroscopyViewer.api.VLWholeSlideMicroscopyImageViewer', ()=> {
1111

1212
let viewer;
1313
const properties = {};
14-
const circle = new dicomMicroscopyViewer.scoord3d.Circle([1000, 1000, 1], 100);
14+
const circle = new dicomMicroscopyViewer.scoord3d.Circle([[8.1036, -9.3211, 1], [8.4463, -9.3211, 1]]);
1515
const point = new dicomMicroscopyViewer.scoord3d.Point([9.0467, -8.7631, 1]);
1616
const box = new dicomMicroscopyViewer.scoord3d.Polyline([
1717
[8.8824, -8.8684, 1],
@@ -77,10 +77,8 @@ describe('dicomMicroscopyViewer.api.VLWholeSlideMicroscopyImageViewer', ()=> {
7777
it('should create a Circle ROI and return it back successfuly', () => {
7878
const roi = new dicomMicroscopyViewer.roi.ROI({scoord3d : circle, properties});
7979
viewer.addROI(roi);
80-
console.log('####')
81-
console.log(viewer.getROI(0).scoord3d.graphicData[0])
82-
console.log('####')
8380
assert.deepEqual(viewer.getROI(0).scoord3d.graphicData[0], circle.graphicData[0]);
81+
assert.deepEqual(viewer.getROI(0).scoord3d.graphicData[1], circle.graphicData[1]);
8482
})
8583

8684
it('should create a Point ROI and return it back successfuly', () => {

0 commit comments

Comments
 (0)