Skip to content

Commit

Permalink
LIMS-1569: Get image viewer rings from dials if possible (#875)
Browse files Browse the repository at this point in the history
* LIMS-1569: Use dials image viewer to get resolution & ice rings

* LIMS-1569: Use old method to get resolution & ice rings if not using dials

* LIMS-1569: Use a separate flag for getting rings from dials

* LIMS-1569: Improve invert behaviour

* LIMS-1569: Improve invert behaviour

* LIMS-1569: Improve invert behaviour

---------

Co-authored-by: Mark Williams <[email protected]>
  • Loading branch information
ndg63276 and Mark Williams authored Dec 16, 2024
1 parent 7eb2aab commit 4b57ba2
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 40 deletions.
1 change: 1 addition & 0 deletions api/config_sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,4 +393,5 @@
# Dials server values
$dials_rest_url = "";
$dials_rest_jwt = "";
$dials_rest_url_rings = false;
?>
4 changes: 3 additions & 1 deletion api/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_rings;
$app->contentType('application/json');
$options = $app->container['options'];
$app->response()->body(json_encode(array(
Expand All @@ -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_rings' => $dials_rest_url_rings,
'redirects' => $redirects
)));
});
Expand Down
8 changes: 6 additions & 2 deletions api/src/Page/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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)) {
Expand All @@ -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 {
Expand Down
71 changes: 34 additions & 37 deletions client/src/js/modules/dc/views/imageviewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ define(['jquery', 'marionette',
'slidechange @ui.zoom': 'slideChangeZoom',
'keypress @ui.num': 'keyPressNum',

'click @ui.res': '_dra',
'click @ui.ice': '_dra',
'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',
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -285,7 +284,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) {
Expand Down Expand Up @@ -354,6 +353,7 @@ define(['jquery', 'marionette',
var self = this
this.ui.canvas.fadeOut(100,function() {
self.load(n)
self.ui.invert.prop('checked', false)
})
},

Expand All @@ -366,6 +366,7 @@ define(['jquery', 'marionette',
val--
this.change(val)
this.ui.num.val(val)
this.ui.invert.prop('checked', false)
}
},

Expand All @@ -375,6 +376,7 @@ define(['jquery', 'marionette',
val++
this.change(val)
this.ui.num.val(val)
this.ui.invert.prop('checked', false)
}
},

Expand Down Expand Up @@ -407,9 +409,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 (this.ui.res.is(':checked')) this._draw_res_rings()
if (this.ui.ice.is(':checked')) this._draw_ice_rings()

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()
}
},


Expand Down Expand Up @@ -443,14 +447,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.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() {
Expand All @@ -472,13 +475,13 @@ 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();
Expand All @@ -487,12 +490,12 @@ define(['jquery', 'marionette',
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();
Expand All @@ -501,8 +504,8 @@ define(['jquery', 'marionette',
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
Expand Down Expand Up @@ -676,9 +679,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
Expand All @@ -696,13 +696,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))
Expand Down Expand Up @@ -740,11 +733,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())
Expand Down Expand Up @@ -788,17 +778,24 @@ define(['jquery', 'marionette',
},

doInvert: function() {
this.invert_change = true
this._dra()
},

doIceOrRes: function() {
if (app.options.get("dials_rest_url_rings")) {
this.reloadImage()
} else {
this._dra()
}
},

doThreshold: function() {
reloadImage: function() {
this.ui.invert.prop('checked', false)
this.load(this.n)
}



}))

})
})

0 comments on commit 4b57ba2

Please sign in to comment.