comparison Sources/OrthancExplorer.js @ 5:1cc024bb662a

added generate model button in Orthanc Explorer
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Jul 2023 12:39:50 +0200
parents 2bdb9acb7dcf
children d1267c6c33e1
comparison
equal deleted inserted replaced
4:5ee4448a8ff8 5:1cc024bb662a
20 * You should have received a copy of the GNU General Public License 20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **/ 22 **/
23 23
24 24
25 const SOP_CLASS_UID_STL = '1.2.840.10008.5.1.4.1.1.104.3'; 25 const STL_PLUGIN_SOP_CLASS_UID_STL = '1.2.840.10008.5.1.4.1.1.104.3';
26 const STL_PLUGIN_SOP_CLASS_UID_RT_STRUCT = '1.2.840.10008.5.1.4.1.1.481.3';
26 27
27 function AddOpenStlViewerButton(instanceId, id, parent) { 28 function AddOpenStlViewerButton(instanceId, id, parent) {
28 var b = $('<a>') 29 var b = $('<a>')
29 .attr('id', id) 30 .attr('id', id)
30 .attr('data-role', 'button') 31 .attr('data-role', 'button')
41 } 42 }
42 }); 43 });
43 } 44 }
44 45
45 46
47 function AddGenerateFromRtStructButton(instanceId, id, parent) {
48 if (${HAS_CREATE_DICOM_STL}) {
49
50 var b = $('<a>')
51 .attr('id', id)
52 .attr('data-role', 'button')
53 .attr('href', '#')
54 .attr('data-icon', 'search')
55 .attr('data-theme', 'e')
56 .text('Generate 3D model')
57 .button();
58
59 b.insertAfter($('#' + parent));
60 b.click(function() {
61
62 $.ajax({
63 url: '../stl/rt-struct/' + instanceId,
64 dataType: 'json',
65 success: function(s) {
66
67 var options = $('<ul>')
68 .attr('data-divider-theme', 'd')
69 .attr('data-role', 'listview');
70
71 var select = $('<select>')
72 .attr('id', id + '-structure')
73 .attr('data-theme', 'a');
74
75 for (i = 0; i < s.length; i++) {
76 select.append($('<option>').attr('value', s[i]).text(s[i]));
77 }
78
79 options.append($('<li>').text('Choose the structure:'));
80 options.append($('<li>').append(select));
81 options.append($('<li>').text('Resolution:'));
82 options.append($('<li>').append($('<select>')
83 .attr('id', id + '-resolution')
84 .attr('data-theme', 'a')
85 .append($('<option>').attr('value', '256').text('256'))
86 .append($('<option>').attr('value', '128').text('128'))
87 .append($('<option>').attr('value', '512').text('512'))));
88 options.append($('<li>')
89 .append($('<input>')
90 .attr('id', id + '-smooth')
91 .attr('type', 'checkbox')
92 .attr('data-theme', 'a')
93 .attr('checked', ''))
94 .append($('<label>')
95 .attr('for', id + '-smooth')
96 .text('Smooth volume')));
97
98 options.append($('<li>').append(
99 $('<a>')
100 .attr('href', '#')
101 .attr('rel', 'close').attr('data-theme', 'b')
102 .text('Generate')
103 .click(function(e) {
104 e.preventDefault();
105
106 var structure = $('#' + id + '-structure').val();
107 var resolution = $('#' + id + '-resolution').val();
108 var smooth = $('#' + id + '-smooth').is(':checked');
109
110 $.ajax({
111 url: '../stl/encode',
112 type: 'POST',
113 data: JSON.stringify({
114 'Instance' : instanceId,
115 'RoiNames' : [ structure ],
116 'Smooth' : smooth,
117 'Resolution' : parseInt(resolution, 10)
118 }),
119 dataType: 'json',
120 success: function(s) {
121 $.mobile.changePage('#series?uuid=' + s.ParentSeries, {
122 allowSamePageTransition: true
123 });
124 },
125 error: function() {
126 alert('Error while generating the 3D model');
127 }
128 });
129
130 })));
131
132 // Launch the dialog
133 $('#dialog').simpledialog2({
134 mode: 'blank',
135 animate: false,
136 headerText: 'Generate 3D model',
137 headerClose: true,
138 forceInput: false,
139 width: '100%',
140 blankContent: options
141 });
142
143 }
144 });
145 });
146 }
147 }
148
149
46 $('#series').live('pagebeforeshow', function() { 150 $('#series').live('pagebeforeshow', function() {
47 var seriesId = $.mobile.pageData.uuid; 151 var seriesId = $.mobile.pageData.uuid;
48 152
49 $('#stl-button-series').remove(); 153 $('#stl-viewer-series').remove();
154 $('#stl-generate-rtstruct-series').remove();
50 155
51 // Test whether this is a whole-slide image by check the SOP Class 156 // Test whether this is a whole-slide image by check the SOP Class
52 // UID of one instance of the series 157 // UID of one instance of the series
53 GetResource('/series/' + seriesId, function(series) { 158 GetResource('/series/' + seriesId, function(series) {
54 if (series['Instances'].length == 1) { 159 if (series['Instances'].length == 1) {
55 var instanceId = series['Instances'][0]; 160 var instanceId = series['Instances'][0];
56 161
57 $.ajax({ 162 $.ajax({
58 url: '/instances/' + instanceId + '/metadata/SopClassUid', 163 url: '/instances/' + instanceId + '/metadata/SopClassUid',
59 success: function(sopClassUid) { 164 success: function(sopClassUid) {
60 if (sopClassUid == SOP_CLASS_UID_STL) { 165
166 if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_STL) {
61 // This is an "Encapsulated STL Storage" IOD, register the button 167 // This is an "Encapsulated STL Storage" IOD, register the button
62 AddOpenStlViewerButton(instanceId, 'stl-button-series', 'series-info'); 168 AddOpenStlViewerButton(instanceId, 'stl-viewer-series', 'series-info');
63 } 169 }
170 else if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_RT_STRUCT) {
171 AddGenerateFromRtStructButton(instanceId, 'stl-generate-rtstruct-series', 'series-info');
172 }
173
64 } 174 }
65 }); 175 });
66 } 176 }
67 }); 177 });
68 }); 178 });
69 179
70 180
71 $('#instance').live('pagebeforeshow', function() { 181 $('#instance').live('pagebeforeshow', function() {
72 var instanceId = $.mobile.pageData.uuid; 182 var instanceId = $.mobile.pageData.uuid;
73 183
74 $('#stl-button-instance').remove(); 184 $('#stl-viewer-instance').remove();
185 $('#stl-generate-rtstruct-instance').remove();
75 186
76 // Test whether this is a whole-slide image by check the SOP Class 187 // Test whether this is a whole-slide image by check the SOP Class
77 // UID of one instance of the series 188 // UID of one instance of the series
78 $.ajax({ 189 $.ajax({
79 url: '/instances/' + instanceId + '/metadata/SopClassUid', 190 url: '/instances/' + instanceId + '/metadata/SopClassUid',
80 success: function(sopClassUid) { 191 success: function(sopClassUid) {
81 if (sopClassUid == SOP_CLASS_UID_STL) { 192
193 if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_STL) {
82 // This is an "Encapsulated STL Storage" IOD, register the button 194 // This is an "Encapsulated STL Storage" IOD, register the button
83 AddOpenStlViewerButton(instanceId, 'stl-button-instance', 'instance-info'); 195 AddOpenStlViewerButton(instanceId, 'stl-viewer-instance', 'instance-info');
84 } 196 }
197 else if (sopClassUid == STL_PLUGIN_SOP_CLASS_UID_RT_STRUCT) {
198 AddGenerateFromRtStructButton(instanceId, 'stl-generate-rtstruct-instance', 'instance-info');
199 }
200
85 } 201 }
86 }); 202 });
87 }); 203 });