From 74ed86e5158d66aa1797c56503c697a1ac56c259 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Tue, 3 Dec 2024 17:06:26 +0000 Subject: [PATCH 1/6] LIMS-1569: Use dials image viewer to get resolution & ice rings --- api/src/Page/Image.php | 8 +++- client/src/js/modules/dc/views/imageviewer.js | 43 +++---------------- 2 files changed, 11 insertions(+), 40 deletions(-) diff --git a/api/src/Page/Image.php b/api/src/Page/Image.php index 3f461da22..e75918e1d 100644 --- a/api/src/Page/Image.php +++ b/api/src/Page/Image.php @@ -20,11 +20,13 @@ class Image extends Page 'aid' => '\d+', 'visit' => '\w+\d+-\d+', 'thresh' => '\d', + 'res' => '\d', + 'ice' => '\d', ); public static $dispatch = array(array('/id/:id(/n/:n)', 'get', '_xtal_image'), array('/diff/id/:id(/f/:f)(/n/:n)', 'get', '_diffraction_image'), - array('/di/id/:id(/thresh/:thresh)(/n/:n)', 'get', '_diffraction_viewer'), + array('/di/id/:id(/thresh/:thresh)(/res/:res)(/ice/:ice)(/n/:n)', 'get', '_diffraction_viewer'), array('/cam/bl/:bl(/n/:n)', 'get', '_forward_webcam'), array('/oav/bl/:bl(/n/:n)', 'get', '_forward_oav'), array('/fa/fid/:id', 'get', '_fault_attachment'), @@ -192,7 +194,7 @@ function _diffraction_viewer() { } $im = $info['LOC'] . '/' . $info['FT']; - $out = '/tmp/' . $this->arg('id') . '_' . $n . ($this->has_arg('thresh') ? '_th' : '') . '.jpg'; + $out = '/tmp/' . $this->arg('id') . '_' . $n . ($this->has_arg('thresh') ? '_th' : '') . ($this->has_arg('res') ? '_res' : '') . ($this->has_arg('ice') ? '_ice' : '') . '.jpg'; global $dials_rest_url, $dials_rest_jwt; if (!file_exists($out)) { if (!empty($dials_rest_url) && !empty($dials_rest_jwt)) { @@ -212,6 +214,8 @@ function _diffraction_viewer() { 'colour_scheme' => 'greyscale', 'brightness' => $this->has_arg('thresh') ? 1000 : 10, 'format' => 'png', + 'resolution_rings' => array('show' => $this->has_arg('res')), + 'ice_rings' => array('show' => $this->has_arg('ice')), ) )); } else { diff --git a/client/src/js/modules/dc/views/imageviewer.js b/client/src/js/modules/dc/views/imageviewer.js index 4007366f3..f28f488d1 100644 --- a/client/src/js/modules/dc/views/imageviewer.js +++ b/client/src/js/modules/dc/views/imageviewer.js @@ -79,8 +79,8 @@ define(['jquery', 'marionette', 'slidechange @ui.zoom': 'slideChangeZoom', 'keypress @ui.num': 'keyPressNum', - 'click @ui.res': '_dra', - 'click @ui.ice': '_dra', + 'click @ui.res': 'doThreshold', + 'click @ui.ice': 'doThreshold', 'click @ui.invert': 'doInvert', 'click @ui.threshold': 'doThreshold', @@ -285,7 +285,7 @@ define(['jquery', 'marionette', this.n = n this.showProgressBar() this.img.onerror = this._onerror.bind(this,n) - this.img.load(app.apiurl+'/image/'+(this.low ? 'diff' : 'di')+'/id/'+this.model.get('ID')+(this.low ? '/f/1' : '')+(this.ui.threshold.is(':checked') ? '/thresh/1' : '')+('/n/'+n)) + this.img.load(app.apiurl+'/image/'+(this.low ? 'diff' : 'di')+'/id/'+this.model.get('ID')+(this.low ? '/f/1' : '')+(this.ui.threshold.is(':checked') ? '/thresh/1' : '')+(this.ui.res.is(':checked') ? '/res/1' : '')+(this.ui.ice.is(':checked') ? '/ice/1' : '')+('/n/'+n)) }, onImageProgress: function(pc) { @@ -407,9 +407,6 @@ define(['jquery', 'marionette', this.ctx.setTransform(this.scalef,0,0,this.scalef,this.offsetx,this.offsety) var r = this.detectVerticalSquash(this.img) this.ctx.drawImage(this.img, 0, 0, this.width, this.height/r) - - if (this.ui.res.is(':checked')) this._draw_res_rings() - if (this.ui.ice.is(':checked')) this._draw_ice_rings() }, @@ -473,36 +470,7 @@ define(['jquery', 'marionette', this.c.resetOriginalPixelData() }, - - - // Draw ice rings - _draw_ice_rings: function() { - var rings = [3.897, 3.669,3.441,2.671,2.249,2.07,1.95,1.92,1.88,1.72] - - this.ctx.strokeStyle='blue'; - for (var i = 0; i < rings.length; i++) { - this.ctx.beginPath(); - var rad = this._res_to_dist(rings[i])/this.ps*this.imscale - this.ctx.arc(this.model.get('XBEAM')/this.ps*this.imscale,this.model.get('YBEAM')/this.ps*this.imscale,rad,0,2*Math.PI); - this.ctx.stroke(); - } - }, - - // Draw resolution rings - _draw_res_rings: function() { - this.ctx.strokeStyle = 'black'; - this.ctx.font = this.imscale < 1 ? '10px Arial' : '30px Arial'; - - for (var i = 0; i < 5; i++) { - var rad = (((this.height-10)/2)/5)*(i+1) - this.ctx.beginPath(); - this.ctx.arc(this.model.get('XBEAM')/this.ps*this.imscale,this.model.get('YBEAM')/this.ps*this.imscale,rad,0,2*Math.PI); - this.ctx.stroke(); - this.ctx.fillText(this._dist_to_res(rad*this.ps/this.imscale).toFixed(2) + 'A',this.model.get('XBEAM')/this.ps*this.imscale-(this.low ? 10 : 40 ),this.model.get('YBEAM')/this.ps*this.imscale-rad+(this.low ? 10 : 40)); - } - }, - - + // Plot spot profile _plot_profiles: function(xp, yp) { if (xp < 20) xp = 20 @@ -792,7 +760,6 @@ define(['jquery', 'marionette', this._dra() }, - doThreshold: function() { this.load(this.n) } @@ -801,4 +768,4 @@ define(['jquery', 'marionette', })) -}) \ No newline at end of file +}) From 750e1e925fee7144e34f11d082de6849dae3bfa2 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Tue, 3 Dec 2024 17:33:55 +0000 Subject: [PATCH 2/6] LIMS-1569: Use old method to get resolution & ice rings if not using dials --- api/index.php | 4 +- client/src/js/modules/dc/views/imageviewer.js | 56 ++++++++++++++++--- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/api/index.php b/api/index.php index ace25a44c..6d18071ea 100644 --- a/api/index.php +++ b/api/index.php @@ -71,7 +71,8 @@ function setupApplication($mode): Slim $facility_courier_countries, $facility_courier_countries_nde, $facility_courier_countries_link, $dhl_enable, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone, $valid_components, $enabled_container_types, $ifsummary, $synchweb_version, $redirects, - $shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments; + $shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments, + $dials_rest_url; $app->contentType('application/json'); $options = $app->container['options']; $app->response()->body(json_encode(array( @@ -95,6 +96,7 @@ function setupApplication($mode): Slim 'synchweb_version' => $synchweb_version, 'shipping_service_app_url' => $use_shipping_service_redirect || $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null, 'shipping_service_app_url_incoming' => $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null, + 'dials_rest_url' => $dials_rest_url, 'redirects' => $redirects ))); }); diff --git a/client/src/js/modules/dc/views/imageviewer.js b/client/src/js/modules/dc/views/imageviewer.js index f28f488d1..cefd08ec9 100644 --- a/client/src/js/modules/dc/views/imageviewer.js +++ b/client/src/js/modules/dc/views/imageviewer.js @@ -79,10 +79,10 @@ define(['jquery', 'marionette', 'slidechange @ui.zoom': 'slideChangeZoom', 'keypress @ui.num': 'keyPressNum', - 'click @ui.res': 'doThreshold', - 'click @ui.ice': 'doThreshold', + 'click @ui.res': 'doIceOrRes', + 'click @ui.ice': 'doIceOrRes', 'click @ui.invert': 'doInvert', - 'click @ui.threshold': 'doThreshold', + 'click @ui.threshold': 'reloadImage', 'click button[name=next]': 'next', 'click button[name=prev]': 'prev', @@ -407,6 +407,11 @@ define(['jquery', 'marionette', this.ctx.setTransform(this.scalef,0,0,this.scalef,this.offsetx,this.offsety) var r = this.detectVerticalSquash(this.img) this.ctx.drawImage(this.img, 0, 0, this.width, this.height/r) + + if (!app.options.get("dials_rest_url")) { + if (this.ui.res.is(':checked')) this._draw_res_rings() + if (this.ui.ice.is(':checked')) this._draw_ice_rings() + } }, @@ -441,9 +446,9 @@ define(['jquery', 'marionette', // Apply image adjustments adjust: function() { if (this.brightness == 0 && this.contrast == 0 && !(this.invert_change || this.ui.invert.is(':checked'))) return - + this.c.revert() - if (this.ui.invert.is(':checked')) { + if (this.invert_change) { this.c.invert() //_plot_profiles(lastx, lasty) } @@ -469,7 +474,36 @@ define(['jquery', 'marionette', this.c.reloadCanvasData() this.c.resetOriginalPixelData() }, - + + + + // Draw ice rings + _draw_ice_rings: function() { + var rings = [3.897, 3.669,3.441,2.671,2.249,2.07,1.95,1.92,1.88,1.72] + + this.ctx.strokeStyle='blue'; + for (var i = 0; i < rings.length; i++) { + this.ctx.beginPath(); + var rad = this._res_to_dist(rings[i])/this.ps*this.imscale + this.ctx.arc(this.model.get('XBEAM')/this.ps*this.imscale,this.model.get('YBEAM')/this.ps*this.imscale,rad,0,2*Math.PI); + this.ctx.stroke(); + } + }, + + // Draw resolution rings + _draw_res_rings: function() { + this.ctx.strokeStyle = 'black'; + this.ctx.font = this.imscale < 1 ? '10px Arial' : '30px Arial'; + + for (var i = 0; i < 5; i++) { + var rad = (((this.height-10)/2)/5)*(i+1) + this.ctx.beginPath(); + this.ctx.arc(this.model.get('XBEAM')/this.ps*this.imscale,this.model.get('YBEAM')/this.ps*this.imscale,rad,0,2*Math.PI); + this.ctx.stroke(); + this.ctx.fillText(this._dist_to_res(rad*this.ps/this.imscale).toFixed(2) + 'A',this.model.get('XBEAM')/this.ps*this.imscale-(this.low ? 10 : 40 ),this.model.get('YBEAM')/this.ps*this.imscale-rad+(this.low ? 10 : 40)); + } + }, + // Plot spot profile _plot_profiles: function(xp, yp) { @@ -760,7 +794,15 @@ define(['jquery', 'marionette', this._dra() }, - doThreshold: function() { + doIceOrRes: function() { + if (app.options.get("dials_rest_url")) { + this.reloadImage() + } else { + this._dra() + } + }, + + reloadImage: function() { this.load(this.n) } From f884c5a18a10b04c73d3b6d1e3cc9f31caf956bb Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Tue, 10 Dec 2024 15:43:09 +0000 Subject: [PATCH 3/6] LIMS-1569: Use a separate flag for getting rings from dials --- api/config_sample.php | 1 + api/index.php | 4 ++-- client/src/js/modules/dc/views/imageviewer.js | 4 ++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/config_sample.php b/api/config_sample.php index a178d48cd..8ea01cf6f 100644 --- a/api/config_sample.php +++ b/api/config_sample.php @@ -393,4 +393,5 @@ # Dials server values $dials_rest_url = ""; $dials_rest_jwt = ""; + $dials_rest_url_rings = false; ?> diff --git a/api/index.php b/api/index.php index 6d18071ea..6a500f99e 100644 --- a/api/index.php +++ b/api/index.php @@ -72,7 +72,7 @@ function setupApplication($mode): Slim $dhl_enable, $scale_grid, $scale_grid_end_date, $preset_proposal, $timezone, $valid_components, $enabled_container_types, $ifsummary, $synchweb_version, $redirects, $shipping_service_app_url, $use_shipping_service_redirect, $use_shipping_service_redirect_incoming_shipments, - $dials_rest_url; + $dials_rest_url_rings; $app->contentType('application/json'); $options = $app->container['options']; $app->response()->body(json_encode(array( @@ -96,7 +96,7 @@ function setupApplication($mode): Slim 'synchweb_version' => $synchweb_version, 'shipping_service_app_url' => $use_shipping_service_redirect || $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null, 'shipping_service_app_url_incoming' => $use_shipping_service_redirect_incoming_shipments ? $shipping_service_app_url : null, - 'dials_rest_url' => $dials_rest_url, + 'dials_rest_url_rings' => $dials_rest_url_rings, 'redirects' => $redirects ))); }); diff --git a/client/src/js/modules/dc/views/imageviewer.js b/client/src/js/modules/dc/views/imageviewer.js index cefd08ec9..f9f6dd48e 100644 --- a/client/src/js/modules/dc/views/imageviewer.js +++ b/client/src/js/modules/dc/views/imageviewer.js @@ -408,7 +408,7 @@ define(['jquery', 'marionette', var r = this.detectVerticalSquash(this.img) this.ctx.drawImage(this.img, 0, 0, this.width, this.height/r) - if (!app.options.get("dials_rest_url")) { + if (!app.options.get("dials_rest_url_rings")) { if (this.ui.res.is(':checked')) this._draw_res_rings() if (this.ui.ice.is(':checked')) this._draw_ice_rings() } @@ -795,7 +795,7 @@ define(['jquery', 'marionette', }, doIceOrRes: function() { - if (app.options.get("dials_rest_url")) { + if (app.options.get("dials_rest_url_rings")) { this.reloadImage() } else { this._dra() From 9961fe663aff5d07f2da617e33c28d9fb1f21309 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Fri, 13 Dec 2024 10:57:09 +0000 Subject: [PATCH 4/6] LIMS-1569: Improve invert behaviour --- client/src/js/modules/dc/views/imageviewer.js | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/client/src/js/modules/dc/views/imageviewer.js b/client/src/js/modules/dc/views/imageviewer.js index f9f6dd48e..28b326580 100644 --- a/client/src/js/modules/dc/views/imageviewer.js +++ b/client/src/js/modules/dc/views/imageviewer.js @@ -124,7 +124,6 @@ define(['jquery', 'marionette', this.moved = false this.blocks = 0 - this.invert_change = false this.ps = parseFloat(this.model.get('DETECTORPIXELSIZEHORIZONTAL'))/1000 || 0.172 this.diwidth = parseInt(this.model.get('DETECTORNUMBEROFPIXELSX')) || 2527 @@ -445,14 +444,13 @@ define(['jquery', 'marionette', // Apply image adjustments adjust: function() { - if (this.brightness == 0 && this.contrast == 0 && !(this.invert_change || this.ui.invert.is(':checked'))) return + if (this.brightness == 0 && this.contrast == 0 && !(this.ui.invert.is(':checked'))) return this.c.revert() - if (this.invert_change) { + if (this.ui.invert.is(':checked')) { this.c.invert() //_plot_profiles(lastx, lasty) } - this.invert_change = false var self = this this.c.brightness(this.brightness).contrast(this.contrast).render(function() { @@ -678,9 +676,6 @@ define(['jquery', 'marionette', //return false }, - - - // Clamp zoom box _clamp_z_box: function(c) { if (c[0]+20 > this.ui.canvas.width()) c[0] = this.ui.canvas.width()-20 @@ -698,13 +693,6 @@ define(['jquery', 'marionette', if (this.offsetx < this.ui.canvas.width() - this.scalef*this.width) this.offsetx = this.ui.canvas.width() - this.scalef*this.width }, - - - - - - - // Convert distance from centre to resolution and back _dist_to_res: function(dist) { return this.model.get('WAVELENGTH') / (2*Math.sin(Math.atan(dist/this.model.get('DET'))/2)) @@ -742,11 +730,8 @@ define(['jquery', 'marionette', this.ui.resc.text(res.toFixed(2)) }, - - - - - + + // Bind load image on return keyPressNum: function(e) { var n = parseInt(this.ui.num.val()) @@ -790,12 +775,12 @@ define(['jquery', 'marionette', }, doInvert: function() { - this.invert_change = true this._dra() }, doIceOrRes: function() { if (app.options.get("dials_rest_url_rings")) { + this.ui.invert.prop('checked', false) this.reloadImage() } else { this._dra() From 013e819280ba2ada33e90bcc3e14620a7610710c Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Fri, 13 Dec 2024 11:01:33 +0000 Subject: [PATCH 5/6] LIMS-1569: Improve invert behaviour --- client/src/js/modules/dc/views/imageviewer.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/src/js/modules/dc/views/imageviewer.js b/client/src/js/modules/dc/views/imageviewer.js index 28b326580..9adf469e2 100644 --- a/client/src/js/modules/dc/views/imageviewer.js +++ b/client/src/js/modules/dc/views/imageviewer.js @@ -365,6 +365,7 @@ define(['jquery', 'marionette', val-- this.change(val) this.ui.num.val(val) + this.ui.invert.prop('checked', false) } }, @@ -374,6 +375,7 @@ define(['jquery', 'marionette', val++ this.change(val) this.ui.num.val(val) + this.ui.invert.prop('checked', false) } }, @@ -780,7 +782,6 @@ define(['jquery', 'marionette', doIceOrRes: function() { if (app.options.get("dials_rest_url_rings")) { - this.ui.invert.prop('checked', false) this.reloadImage() } else { this._dra() @@ -788,6 +789,7 @@ define(['jquery', 'marionette', }, reloadImage: function() { + this.ui.invert.prop('checked', false) this.load(this.n) } From 2e81c304c190d6f0bb8491f303eb3f62d2261fc4 Mon Sep 17 00:00:00 2001 From: Mark Williams Date: Fri, 13 Dec 2024 11:15:28 +0000 Subject: [PATCH 6/6] LIMS-1569: Improve invert behaviour --- client/src/js/modules/dc/views/imageviewer.js | 1 + 1 file changed, 1 insertion(+) diff --git a/client/src/js/modules/dc/views/imageviewer.js b/client/src/js/modules/dc/views/imageviewer.js index 9adf469e2..a6152470f 100644 --- a/client/src/js/modules/dc/views/imageviewer.js +++ b/client/src/js/modules/dc/views/imageviewer.js @@ -353,6 +353,7 @@ define(['jquery', 'marionette', var self = this this.ui.canvas.fadeOut(100,function() { self.load(n) + self.ui.invert.prop('checked', false) }) },