@@ -31,34 +31,34 @@ import {
3131 Polyline ,
3232 Circle ,
3333 Ellipse
34- } from './scoord .js' ;
34+ } from './scoord3d .js' ;
3535
3636import DICOMwebClient from 'dicomweb-client/build/dicomweb-client.js'
3737
3838
39- function _geometry2Scoord ( geometry ) {
39+ function _geometry2Scoord3d ( geometry ) {
4040 const type = geometry . getType ( ) ;
4141 if ( type === 'Point' ) {
4242 let coordinates = geometry . getCoordinates ( ) ;
43- coordinates = _geometryCoordinates2scoordCoordinates ( coordinates ) ;
43+ coordinates = _geometryCoordinates2scoord3dCoordinates ( coordinates ) ;
4444 return new Point ( coordinates ) ;
4545 } else if ( type === 'Polygon' ) {
4646 /*
4747 * The first linear ring of the array defines the outer-boundary (surface).
4848 * Each subsequent linear ring defines a hole in the surface.
4949 */
5050 let coordinates = geometry . getCoordinates ( ) [ 0 ] . map ( c => {
51- return _geometryCoordinates2scoordCoordinates ( c ) ;
51+ return _geometryCoordinates2scoord3dCoordinates ( c ) ;
5252 } ) ;
5353 return new Polyline ( coordinates ) ;
5454 } else if ( type === 'LineString' ) {
5555 let coordinates = geometry . getCoordinates ( ) . map ( c => {
56- return _geometryCoordinates2scoordCoordinates ( c ) ;
56+ return _geometryCoordinates2scoord3dCoordinates ( c ) ;
5757 } ) ;
5858 return new Polyline ( coordinates ) ;
5959 } else if ( type === 'Circle' ) {
6060 // TODO: Circle may actually represent a Polyline
61- let center = _geometryCoordinates2scoordCoordinates ( geometry . getCenter ( ) ) ;
61+ let center = _geometryCoordinates2scoord3dCoordinates ( geometry . getCenter ( ) ) ;
6262 let radius = geometry . getRadius ( ) ;
6363 return new Circle ( center , radius ) ;
6464 } else {
@@ -68,41 +68,38 @@ function _geometry2Scoord(geometry) {
6868}
6969
7070
71- function _scoord2Geometry ( scoord ) {
72- const type = scoord . graphicType ;
73- const data = scoord . graphicData ;
71+ function _scoord3d2Geometry ( scoord3d ) {
72+ const type = scoord3d . graphicType ;
73+ const data = scoord3d . graphicData ;
74+ console . log ( data )
7475 if ( type === 'POINT' ) {
75- let coordinates = _scoordCoordinates2geometryCoordinates ( data ) ;
76+ let coordinates = _scoord3dCoordinates2geometryCoordinates ( data ) ;
7677 return new PointGeometry ( coordinates ) ;
7778 } else if ( type === 'POLYLINE' ) {
7879 const coordinates = data . map ( d => {
79- return _scoordCoordinates2geometryCoordinates ( d ) ;
80+ return _scoord3dCoordinates2geometryCoordinates ( d ) ;
8081 } ) ;
81- let isClosed = (
82- data [ 0 ] [ 0 ] === data [ data . length - 1 ] [ 0 ] &&
83- data [ 0 ] [ 1 ] === data [ data . length - 1 ] [ 1 ]
84- ) ;
85- if ( isClosed ) {
86- // Polygon requires inner linear ring and an outer ring.
87- return new PolygonGeometry ( [ coordinates ] ) ;
88- } else {
89- return new LineStringGeometry ( coordinates ) ;
90- }
82+ return new LineStringGeometry ( coordinates ) ;
83+ } else if ( type === 'POLYGON' ) {
84+ const coordinates = data . map ( d => {
85+ return _scoord3dCoordinates2geometryCoordinates ( d ) ;
86+ } ) ;
87+ return new PolygonGeometry ( [ coordinates ] ) ;
9188 } else if ( type === 'CIRCLE' ) {
92- let center = _scoordCoordinates2geometryCoordinates ( scoord . centerCoordinates ) ;
93- let radius = scoord . radius ;
89+ let center = _scoord3dCoordinates2geometryCoordinates ( scoord3d . centerCoordinates ) ;
90+ let radius = scoord3d . radius ;
9491 return new CircleGeometry ( center , radius ) ;
9592 } else {
9693 console . error ( `unsupported graphic type "${ type } "` )
9794 }
9895}
9996
10097
101- function _geometryCoordinates2scoordCoordinates ( coordinates ) {
98+ function _geometryCoordinates2scoord3dCoordinates ( coordinates ) {
10299 return [ coordinates [ 0 ] + 1 , - coordinates [ 1 ] ]
103100}
104101
105- function _scoordCoordinates2geometryCoordinates ( coordinates ) {
102+ function _scoord3dCoordinates2geometryCoordinates ( coordinates ) {
106103 return [ coordinates [ 0 ] - 1 , - coordinates [ 1 ] ]
107104}
108105
@@ -120,17 +117,6 @@ function coordinateFormatFunction(coordinates, pyramid) {
120117 return ( coordinates ) ;
121118}
122119
123- function _getROIByFeature ( feature , pyramid , coordinateSystem ) {
124- const geometry = feature . getGeometry ( ) ;
125- let scoord = _geometry2Scoord ( geometry ) ;
126- if ( pyramid !== undefined && coordinateSystem === 'mm' ) {
127- scoord = coordinateFormatFunction ( scoord . coordinates , pyramid ) ;
128- }
129- const properties = feature . getProperties ( ) ;
130- delete properties [ "geometry" ] ;
131- return new ROI ( { scoord, properties, coordinateSystem } ) ;
132- }
133-
134120const _usewebgl = Symbol ( 'usewebgl' ) ;
135121const _map = Symbol ( 'map' ) ;
136122const _features = Symbol ( 'features' ) ;
@@ -723,13 +709,12 @@ class VLWholeSlideMicroscopyImageViewer {
723709 return this [ _interaction ] . modify !== undefined ;
724710 }
725711
726- getAllROIs ( coordinateSystem = 'totalPixelMatrix' ) {
727- const features = this [ _features ] ;
712+ getAllROIs ( ) {
728713 let rois = [ ] ;
729- if ( features !== undefined ) {
730- features . forEach ( feature => {
731- rois . push ( _getROIByFeature ( feature , this . pyramid , coordinateSystem ) ) ;
732- } ) ;
714+ if ( this . numberOfROIs > 0 ) {
715+ for ( let index = 0 ; index < this . numberOfROIs ; index ++ ) {
716+ rois . push ( this . getROI ( index ) ) ;
717+ }
733718 }
734719 return rois ;
735720 }
@@ -738,33 +723,43 @@ class VLWholeSlideMicroscopyImageViewer {
738723 return this [ _features ] . getLength ( ) ;
739724 }
740725
741- getROI ( index , coordinateSystem = 'totalPixelMatrix' ) {
726+ getROI ( index ) {
742727 const feature = this [ _features ] . item ( index ) ;
743728 let roi = { } ;
744- if ( feature !== undefined ) {
745- roi = _getROIByFeature ( feature , this . pyramid , coordinateSystem ) ;
729+ if ( feature !== undefined ) {
730+ const geometry = feature . getGeometry ( ) ;
731+ let scoord3d = _geometry2Scoord3d ( geometry ) ;
732+ // This is to uniform the ROI format in an array of arrays. When it is a point the representation
733+ // is a single array with x and y coords
734+ if ( scoord3d . coordinates . length === 2 ) {
735+ scoord3d . coordinates = [ scoord3d . coordinates ]
736+ }
737+ scoord3d . coordinates . map ( coord => { return coordinateFormatFunction ( coord , this . pyramid ) } ) ;
738+ const properties = feature . getProperties ( ) ;
739+ delete properties [ 'geometry' ] ;
740+ return new ROI ( { scoord3d, properties} ) ;
746741 }
747742 return roi ;
748743 }
749744
750745 popROI ( ) {
751746 const feature = this [ _features ] . pop ( ) ;
752747 const geometry = feature . getGeometry ( )
753- const scoord = _geometry2Scoord ( geometry ) ;
748+ const scoord3d = _geometry2Scoord3d ( geometry ) ;
754749 const properties = feature . getProperties ( ) ;
755750 delete properties [ 'geometry' ] ;
756- return new ROI ( { scoord , properties} ) ;
751+ return new ROI ( { scoord3d , properties} ) ;
757752 }
758753
759754 addROI ( item ) {
760- const geometry = _scoord2Geometry ( item . scoord ) ;
755+ const geometry = _scoord3d2Geometry ( item . scoord3d ) ;
761756 const feature = new Feature ( geometry ) ;
762757 feature . setProperties ( item . properties , true ) ;
763758 this [ _features ] . push ( feature ) ;
764759 }
765760
766761 updateROI ( index , item ) {
767- const geometry = _scoord2Geometry ( item . scoord ) ;
762+ const geometry = _scoord3d2Geometry ( item . scoord3d ) ;
768763 const feature = new Feature ( geometry ) ;
769764 feature . setProperties ( item . properties , true ) ;
770765 this [ _features ] . setAt ( index , feature ) ;
0 commit comments