annotate Sources/OrthancExplorer.js @ 37:2cc9950018ab

replaced folder ./Three by ./JavaScriptLibraries
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Apr 2024 07:52:43 +0200
parents 13698d34e059
children b6910092bcca
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
24
dd0cd39e6259 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 9
diff changeset
2 * SPDX-FileCopyrightText: 2023-2024 Sebastien Jodogne, UCLouvain, Belgium
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * SPDX-License-Identifier: GPL-3.0-or-later
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 */
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 /**
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * STL plugin for Orthanc
24
dd0cd39e6259 update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 9
diff changeset
8 * Copyright (C) 2023-2024 Sebastien Jodogne, UCLouvain, Belgium
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 *
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * This program is free software: you can redistribute it and/or
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 * modify it under the terms of the GNU General Public License as
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * published by the Free Software Foundation, either version 3 of the
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * License, or (at your option) any later version.
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 *
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful, but
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * General Public License for more details.
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 *
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 **/
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
25 const STL_PLUGIN_SOP_CLASS_UID_STL = '1.2.840.10008.5.1.4.1.1.104.3';
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
26 const STL_PLUGIN_SOP_CLASS_UID_RT_STRUCT = '1.2.840.10008.5.1.4.1.1.481.3';
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
27
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
28 function AddOpenStlViewerButton(instanceId, id, parent) {
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
29 var b = $('<a>')
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
30 .attr('id', id)
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
31 .attr('data-role', 'button')
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
32 .attr('href', '#')
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
33 .attr('data-icon', 'search')
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
34 .attr('data-theme', 'e')
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
35 .text('STL viewer')
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
36 .button();
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
37
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
38 b.insertAfter($('#' + parent));
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
39 b.click(function() {
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
40 if ($.mobile.pageData) {
36
13698d34e059 preparing to include O3DV
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
41 window.open('../stl/app/three.html?instance=' + instanceId);
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
42 }
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
43 });
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
44 }
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
45
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
46
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
47 function AddGenerateFromRtStructButton(instanceId, id, parent) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
48 if (${HAS_CREATE_DICOM_STL}) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
49
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
50 var b = $('<a>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
51 .attr('id', id)
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
52 .attr('data-role', 'button')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
53 .attr('href', '#')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
54 .attr('data-icon', 'search')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
55 .attr('data-theme', 'e')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
56 .text('Generate 3D model')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
57 .button();
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
58
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
59 b.insertAfter($('#' + parent));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
60 b.click(function() {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
61
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
62 $.ajax({
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
63 url: '../stl/rt-struct/' + instanceId,
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
64 dataType: 'json',
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
65 success: function(s) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
66
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
67 var options = $('<ul>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
68 .attr('data-divider-theme', 'd')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
69 .attr('data-role', 'listview');
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
70
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
71 var select = $('<select>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
72 .attr('id', id + '-structure')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
73 .attr('data-theme', 'a');
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
74
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
75 for (i = 0; i < s.length; i++) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
76 select.append($('<option>').attr('value', s[i]).text(s[i]));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
77 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
78
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
79 options.append($('<li>').text('Choose the structure:'));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
80 options.append($('<li>').append(select));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
81 options.append($('<li>').text('Resolution:'));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
82 options.append($('<li>').append($('<select>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
83 .attr('id', id + '-resolution')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
84 .attr('data-theme', 'a')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
85 .append($('<option>').attr('value', '256').text('256'))
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
86 .append($('<option>').attr('value', '128').text('128'))
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
87 .append($('<option>').attr('value', '512').text('512'))));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
88 options.append($('<li>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
89 .append($('<input>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
90 .attr('id', id + '-smooth')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
91 .attr('type', 'checkbox')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
92 .attr('data-theme', 'a')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
93 .attr('checked', ''))
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
94 .append($('<label>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
95 .attr('for', id + '-smooth')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
96 .text('Smooth volume')));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
97
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
98 options.append($('<li>').append(
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
99 $('<a>')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
100 .attr('href', '#')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
101 .attr('rel', 'close').attr('data-theme', 'b')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
102 .text('Generate')
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
103 .click(function(e) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
104 e.preventDefault();
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
105
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
106 var structure = $('#' + id + '-structure').val();
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
107 var resolution = $('#' + id + '-resolution').val();
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
108 var smooth = $('#' + id + '-smooth').is(':checked');
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
109
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
110 $.ajax({
8
d1267c6c33e1 added route /stl/encode-nifti
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 5
diff changeset
111 url: '../stl/encode-rtstruct',
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
112 type: 'POST',
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
113 data: JSON.stringify({
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
114 'Instance' : instanceId,
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
115 'RoiNames' : [ structure ],
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
116 'Smooth' : smooth,
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
117 'Resolution' : parseInt(resolution, 10)
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
118 }),
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
119 dataType: 'json',
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
120 success: function(s) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
121 $.mobile.changePage('#series?uuid=' + s.ParentSeries, {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
122 allowSamePageTransition: true
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
123 });
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
124 },
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
125 error: function() {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
126 alert('Error while generating the 3D model');
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
127 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
128 });
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
129
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
130 })));
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
131
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
132 // Launch the dialog
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
133 $('#dialog').simpledialog2({
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
134 mode: 'blank',
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
135 animate: false,
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
136 headerText: 'Generate 3D model',
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
137 headerClose: true,
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
138 forceInput: false,
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
139 width: '100%',
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
140 blankContent: options
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
141 });
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
142
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
143 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
144 });
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
145 });
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
146 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
147 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
148
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
149
31
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
150 function AddGenerateFromNIfTIButton(studyId) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
151 if (${HAS_CREATE_DICOM_STL} &&
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
152 ${SHOW_NIFTI_BUTTON}) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
153 $('#stl-attach-nifti').remove();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
154
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
155 var nifti = $('<a>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
156 .attr('id', 'stl-attach-nifti')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
157 .attr('data-role', 'button')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
158 .attr('href', '#')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
159 .attr('data-icon', 'search')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
160 .attr('data-theme', 'e')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
161 .text('Attach NIfTI 3D model')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
162 .button();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
163
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
164 nifti.insertAfter($('#study-info'));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
165 nifti.click(function() {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
166
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
167 var options = $('<ul>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
168 .attr('data-divider-theme', 'd')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
169 .attr('data-role', 'listview');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
170
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
171 var upload = $('<input>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
172 .attr('type', 'file')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
173 .attr('id', 'stl-attach-nifti-upload')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
174 .attr('data-theme', 'a');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
175
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
176 options.append($('<li>').text('Choose the NIfTI file:'));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
177 options.append($('<li>').append(upload));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
178 options.append($('<li>').text('Resolution:'));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
179 options.append($('<li>').append($('<select>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
180 .attr('id', 'stl-attach-nifti-resolution')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
181 .attr('data-theme', 'a')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
182 .append($('<option>').attr('value', '256').text('256'))
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
183 .append($('<option>').attr('value', '128').text('128'))
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
184 .append($('<option>').attr('value', '512').text('512'))));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
185 options.append($('<li>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
186 .append($('<input>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
187 .attr('id', 'stl-attach-nifti-smooth')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
188 .attr('type', 'checkbox')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
189 .attr('data-theme', 'a')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
190 .attr('checked', ''))
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
191 .append($('<label>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
192 .attr('for', 'stl-attach-nifti-smooth')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
193 .text('Smooth volume')));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
194
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
195 options.append($('<li>').append(
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
196 $('<a>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
197 .attr('href', '#')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
198 .attr('rel', 'close').attr('data-theme', 'b')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
199 .text('Generate')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
200 .click(function(e) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
201 e.preventDefault();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
202
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
203 var fileInput = document.getElementById('stl-attach-nifti-upload');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
204 var resolution = $('#stl-attach-nifti-resolution').val();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
205 var smooth = $('#stl-attach-nifti-smooth').is(':checked');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
206
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
207 if (fileInput.files.length == 0) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
208 alert('No NIfTI file was selected');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
209 return;
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
210 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
211
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
212 reader = new FileReader();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
213 reader.onload = function() {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
214
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
215 // https://github.com/axios/axios/issues/513
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
216 var nifti = reader.result;
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
217 var niftiBase64 = btoa(new Uint8Array(nifti).reduce((data, byte) => data + String.fromCharCode(byte), ''));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
218
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
219 $.ajax({
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
220 url: '../stl/encode-nifti',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
221 type: 'POST',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
222 data: JSON.stringify({
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
223 'Nifti' : 'data:application/octet-stream;base64,' + niftiBase64,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
224 'ParentStudy' : studyId,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
225 'Smooth' : smooth,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
226 'Resolution' : parseInt(resolution, 10)
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
227 }),
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
228 dataType: 'json',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
229 success: function(s) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
230 $.mobile.changePage('#series?uuid=' + s.ParentSeries, {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
231 allowSamePageTransition: true
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
232 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
233 },
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
234 error: function() {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
235 alert('Error while generating the 3D model');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
236 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
237 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
238
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
239 };
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
240
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
241 reader.readAsArrayBuffer(fileInput.files[0]);
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
242 })));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
243
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
244 // Launch the dialog
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
245 $('#dialog').simpledialog2({
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
246 mode: 'blank',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
247 animate: false,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
248 headerText: 'Generate 3D model',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
249 headerClose: true,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
250 forceInput: false,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
251 width: '100%',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
252 blankContent: options
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
253 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
254 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
255 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
256 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
257
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
258
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
259 function AddImportSTLButton(studyId) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
260 if (${HAS_CREATE_DICOM_STL}) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
261 $('#stl-attach-instance').remove();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
262
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
263 var instance = $('<a>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
264 .attr('id', 'stl-attach-instance')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
265 .attr('data-role', 'button')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
266 .attr('href', '#')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
267 .attr('data-icon', 'search')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
268 .attr('data-theme', 'e')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
269 .text('Attach STL model')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
270 .button();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
271
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
272 instance.insertAfter($('#study-info'));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
273 instance.click(function() {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
274
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
275 var options = $('<ul>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
276 .attr('data-divider-theme', 'd')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
277 .attr('data-role', 'listview');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
278
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
279 var upload = $('<input>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
280 .attr('type', 'file')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
281 .attr('id', 'stl-attach-instance-upload')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
282 .attr('data-theme', 'a');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
283
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
284 options.append($('<li>').text('Choose the STL file:'));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
285 options.append($('<li>').append(upload));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
286
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
287 options.append($('<li>').text('Series description:'));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
288 options.append($('<li>').append($('<input>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
289 .attr('type', 'text')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
290 .attr('id', 'stl-attach-instance-description')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
291 .attr('data-theme', 'b')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
292 .val('Imported STL')));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
293
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
294 options.append($('<li>').append(
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
295 $('<a>')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
296 .attr('href', '#')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
297 .attr('rel', 'close').attr('data-theme', 'b')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
298 .text('Import')
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
299 .click(function(e) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
300 e.preventDefault();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
301
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
302 var fileInput = document.getElementById('stl-attach-instance-upload');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
303 var description = $('#stl-attach-instance-description').val();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
304
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
305 if (fileInput.files.length == 0) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
306 alert('No Instance file was selected');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
307 return;
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
308 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
309
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
310 reader = new FileReader();
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
311 reader.onload = function() {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
312
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
313 // https://github.com/axios/axios/issues/513
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
314 var stl = reader.result;
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
315 var stlBase64 = btoa(new Uint8Array(stl).reduce((data, byte) => data + String.fromCharCode(byte), ''));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
316
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
317 $.ajax({
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
318 url: '../tools/create-dicom',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
319 type: 'POST',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
320 data: JSON.stringify({
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
321 'Content' : 'data:model/stl;base64,' + stlBase64,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
322 'Parent' : studyId,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
323 'Tags' : {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
324 'SeriesDescription' : description
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
325 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
326 }),
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
327 dataType: 'json',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
328 success: function(s) {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
329 $.mobile.changePage('#series?uuid=' + s.ParentSeries, {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
330 allowSamePageTransition: true
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
331 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
332 },
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
333 error: function() {
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
334 alert('Error while generating the 3D model');
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
335 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
336 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
337
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
338 };
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
339
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
340 reader.readAsArrayBuffer(fileInput.files[0]);
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
341 })));
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
342
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
343 // Launch the dialog
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
344 $('#dialog').simpledialog2({
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
345 mode: 'blank',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
346 animate: false,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
347 headerText: 'Attach STL',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
348 headerClose: true,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
349 forceInput: false,
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
350 width: '100%',
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
351 blankContent: options
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
352 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
353 });
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
354 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
355 }
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
356
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
357
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
358
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 $('#series').live('pagebeforeshow', function() {
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 var seriesId = $.mobile.pageData.uuid;
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
362 $('#stl-viewer-series').remove();
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
363 $('#stl-generate-rtstruct-series').remove();
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 GetResource('/series/' + seriesId, function(series) {
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
366 if (series['Instances'].length == 1) {
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
367 var instanceId = series['Instances'][0];
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
369 $.ajax({
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
370 url: '/instances/' + instanceId + '/metadata/SopClassUid',
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
371 success: function(sopClassUid) {
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
372
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
373 if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_STL) {
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
374 // This is an "Encapsulated STL Storage" IOD, register the button
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
375 AddOpenStlViewerButton(instanceId, 'stl-viewer-series', 'series-info');
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
376 }
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
377 else if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_RT_STRUCT) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
378 AddGenerateFromRtStructButton(instanceId, 'stl-generate-rtstruct-series', 'series-info');
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
379 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
380
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 }
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
382 });
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
383 }
0
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 });
4e889a8e8be2 initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385 });
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
386
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
387
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
388 $('#instance').live('pagebeforeshow', function() {
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
389 var instanceId = $.mobile.pageData.uuid;
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
390
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
391 $('#stl-viewer-instance').remove();
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
392 $('#stl-generate-rtstruct-instance').remove();
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
393
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
394 $.ajax({
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
395 url: '/instances/' + instanceId + '/metadata/SopClassUid',
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
396 success: function(sopClassUid) {
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
397
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
398 if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_STL) {
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
399 // This is an "Encapsulated STL Storage" IOD, register the button
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
400 AddOpenStlViewerButton(instanceId, 'stl-viewer-instance', 'instance-info');
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
401 }
5
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
402 else if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_RT_STRUCT) {
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
403 AddGenerateFromRtStructButton(instanceId, 'stl-generate-rtstruct-instance', 'instance-info');
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
404 }
1cc024bb662a added generate model button in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 2
diff changeset
405
2
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
406 }
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
407 });
2bdb9acb7dcf added STL viewer button at instance level too
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1
diff changeset
408 });
9
8b265e711351 added button "Attach NIfTI 3D model" in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
409
8b265e711351 added button "Attach NIfTI 3D model" in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
410
8b265e711351 added button "Attach NIfTI 3D model" in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
411 $('#study').live('pagebeforeshow', function() {
31
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
412 var studyId = $.mobile.pageData.uuid;
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
413 AddImportSTLButton(studyId);
ab231760799d added button to import STL
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 24
diff changeset
414 AddGenerateFromNIfTIButton(studyId);
9
8b265e711351 added button "Attach NIfTI 3D model" in Orthanc Explorer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 8
diff changeset
415 });