comparison Sources/OrthancExplorer.js @ 9:8b265e711351

added button "Attach NIfTI 3D model" in Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jul 2023 17:05:23 +0200
parents d1267c6c33e1
children dd0cd39e6259
comparison
equal deleted inserted replaced
8:d1267c6c33e1 9:8b265e711351
151 var seriesId = $.mobile.pageData.uuid; 151 var seriesId = $.mobile.pageData.uuid;
152 152
153 $('#stl-viewer-series').remove(); 153 $('#stl-viewer-series').remove();
154 $('#stl-generate-rtstruct-series').remove(); 154 $('#stl-generate-rtstruct-series').remove();
155 155
156 // Test whether this is a whole-slide image by check the SOP Class
157 // UID of one instance of the series
158 GetResource('/series/' + seriesId, function(series) { 156 GetResource('/series/' + seriesId, function(series) {
159 if (series['Instances'].length == 1) { 157 if (series['Instances'].length == 1) {
160 var instanceId = series['Instances'][0]; 158 var instanceId = series['Instances'][0];
161 159
162 $.ajax({ 160 $.ajax({
182 var instanceId = $.mobile.pageData.uuid; 180 var instanceId = $.mobile.pageData.uuid;
183 181
184 $('#stl-viewer-instance').remove(); 182 $('#stl-viewer-instance').remove();
185 $('#stl-generate-rtstruct-instance').remove(); 183 $('#stl-generate-rtstruct-instance').remove();
186 184
187 // Test whether this is a whole-slide image by check the SOP Class
188 // UID of one instance of the series
189 $.ajax({ 185 $.ajax({
190 url: '/instances/' + instanceId + '/metadata/SopClassUid', 186 url: '/instances/' + instanceId + '/metadata/SopClassUid',
191 success: function(sopClassUid) { 187 success: function(sopClassUid) {
192 188
193 if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_STL) { 189 if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_STL) {
199 } 195 }
200 196
201 } 197 }
202 }); 198 });
203 }); 199 });
200
201
202 $('#study').live('pagebeforeshow', function() {
203 if (${HAS_CREATE_DICOM_STL}) {
204 var studyId = $.mobile.pageData.uuid;
205
206 $('#stl-attach-nifti-study').remove();
207
208 var b = $('<a>')
209 .attr('id', 'stl-attach-nifti-study')
210 .attr('data-role', 'button')
211 .attr('href', '#')
212 .attr('data-icon', 'search')
213 .attr('data-theme', 'e')
214 .text('Attach NIfTI 3D model')
215 .button();
216
217 b.insertAfter($('#study-info'));
218 b.click(function() {
219
220 var options = $('<ul>')
221 .attr('data-divider-theme', 'd')
222 .attr('data-role', 'listview');
223
224 var upload = $('<input>')
225 .attr('type', 'file')
226 .attr('id', 'stl-attach-nifti-study-upload')
227 .attr('data-theme', 'a');
228
229 options.append($('<li>').text('Choose the NIfTI file:'));
230 options.append($('<li>').append(upload));
231 options.append($('<li>').text('Resolution:'));
232 options.append($('<li>').append($('<select>')
233 .attr('id', 'stl-attach-nifti-study-resolution')
234 .attr('data-theme', 'a')
235 .append($('<option>').attr('value', '256').text('256'))
236 .append($('<option>').attr('value', '128').text('128'))
237 .append($('<option>').attr('value', '512').text('512'))));
238 options.append($('<li>')
239 .append($('<input>')
240 .attr('id', 'stl-attach-nifti-study-smooth')
241 .attr('type', 'checkbox')
242 .attr('data-theme', 'a')
243 .attr('checked', ''))
244 .append($('<label>')
245 .attr('for', 'stl-attach-nifti-study-smooth')
246 .text('Smooth volume')));
247
248 options.append($('<li>').append(
249 $('<a>')
250 .attr('href', '#')
251 .attr('rel', 'close').attr('data-theme', 'b')
252 .text('Generate')
253 .click(function(e) {
254 e.preventDefault();
255
256 var fileInput = document.getElementById('stl-attach-nifti-study-upload');
257 var resolution = $('#stl-attach-nifti-study-resolution').val();
258 var smooth = $('#stl-attach-nifti-study-smooth').is(':checked');
259
260 if (fileInput.files.length == 0) {
261 alert('No NIfTI file was selected');
262 return;
263 }
264
265 reader = new FileReader();
266 reader.onload = function() {
267
268 // https://github.com/axios/axios/issues/513
269 var nifti = reader.result;
270 var niftiBase64 = btoa(new Uint8Array(nifti).reduce((data, byte) => data + String.fromCharCode(byte), ''));
271
272 $.ajax({
273 url: '../stl/encode-nifti',
274 type: 'POST',
275 data: JSON.stringify({
276 'Nifti' : 'data:application/octet-stream;base64,' + niftiBase64,
277 'ParentStudy' : studyId,
278 'Smooth' : smooth,
279 'Resolution' : parseInt(resolution, 10)
280 }),
281 dataType: 'json',
282 success: function(s) {
283 $.mobile.changePage('#series?uuid=' + s.ParentSeries, {
284 allowSamePageTransition: true
285 });
286 },
287 error: function() {
288 alert('Error while generating the 3D model');
289 }
290 });
291
292 };
293
294 reader.readAsArrayBuffer(fileInput.files[0]);
295 })));
296
297 // Launch the dialog
298 $('#dialog').simpledialog2({
299 mode: 'blank',
300 animate: false,
301 headerText: 'Generate 3D model',
302 headerClose: true,
303 forceInput: false,
304 width: '100%',
305 blankContent: options
306 });
307
308 });
309 }
310 });