annotate OrthancStone/UnitTestsSources/SortedFramesCreateTest.py @ 2056:66c130af0d3c deep-learning

OpenGLTexture::SetClampingToZero() is not available in wasm
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 18 Apr 2023 15:18:36 +0200
parents a2955abe4c2e
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1477
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
3 # Stone of Orthanc
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
4 # Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
5 # Department, University Hospital of Liege, Belgium
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 # Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
7 # Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
8 #
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
9 # This program is free software: you can redistribute it and/or
1877
a2955abe4c2e skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
10 # modify it under the terms of the GNU Lesser General Public License
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
11 # as published by the Free Software Foundation, either version 3 of
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
12 # the License, or (at your option) any later version.
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
13 #
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
14 # This program is distributed in the hope that it will be useful, but
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
15 # WITHOUT ANY WARRANTY; without even the implied warranty of
1877
a2955abe4c2e skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a2955abe4c2e skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
17 # Lesser General Public License for more details.
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
18 #
1877
a2955abe4c2e skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
19 # You should have received a copy of the GNU Lesser General Public
a2955abe4c2e skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
20 # License along with this program. If not, see
a2955abe4c2e skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
21 # <http://www.gnu.org/licenses/>.
1589
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
22
8c5f9864545f adding missing headers
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1587
diff changeset
23
1477
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 import pprint
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 import requests
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 import sys
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 if len(sys.argv) != 2:
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 print('Usage: %s [Orthanc series ID]' % sys.argv[0])
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 print('Example: %s 4d04593b-953ced51-87e93f11-ae4cf03c-25defdcd | xclip -selection c -t text/plain' % sys.argv[0])
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 exit(-1)
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 SERIES = sys.argv[1]
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 r = requests.get('http://localhost:8042/series/%s/study' % SERIES)
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 r.raise_for_status()
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 print(' // From patient %s' % r.json() ['PatientMainDicomTags']['PatientName'])
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 r = requests.get('http://localhost:8042/series/%s' % SERIES)
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 r.raise_for_status()
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 first = True
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 for instance in r.json() ['Instances']:
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 tags = requests.get('http://localhost:8042/instances/%s/tags?short' % instance)
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 tags.raise_for_status()
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 if first:
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 print('''
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 Orthanc::DicomMap tags;
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 tags.SetValue(Orthanc::DICOM_TAG_STUDY_INSTANCE_UID, "%s", false);
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 tags.SetValue(Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, "%s", false);
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 OrthancStone::SortedFrames f;
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 ''' % (tags.json() ['0020,000d'], tags.json() ['0020,000e']))
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 first = False
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 print(' tags.SetValue(Orthanc::DICOM_TAG_SOP_INSTANCE_UID, "%s", false);' % instance)
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 if '0020,0032' in tags.json():
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_POSITION_PATIENT, "%s", false);' %
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 tags.json() ['0020,0032'].replace('\\', '\\\\'))
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 if '0020,0037' in tags.json():
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_ORIENTATION_PATIENT, "%s", false);' %
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 tags.json() ['0020,0037'].replace('\\', '\\\\'))
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 if '0020,0013' in tags.json():
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 print(' tags.SetValue(Orthanc::DICOM_TAG_INSTANCE_NUMBER, "%s", false);' %
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 tags.json() ['0020,0013'].replace('\\', '\\\\'))
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 if '0054,1330' in tags.json():
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 print(' tags.SetValue(Orthanc::DICOM_TAG_IMAGE_INDEX, "%s", false);' %
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 tags.json() ['0054,1330'].replace('\\', '\\\\'))
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 print(' f.AddInstance(tags);')
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 print(' f.Sort();')
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 r = requests.get('http://localhost:8042/series/%s/ordered-slices' % SERIES)
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 r.raise_for_status()
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 slices = r.json() ['SlicesShort']
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 print(' ASSERT_EQ(%du, f.GetFramesCount());' % len(slices))
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 for i in range(len(slices)):
1644
4796fb60999e removing methods from SortedFrames to simplify api
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1589
diff changeset
86 print(' ASSERT_EQ(f.GetInstanceOfFrame(%d).GetSopInstanceUid(), "%s");' % (i, slices[i][0]))
1477
5732edec7cbd sorting frames in 3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87