Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Loaders/OrthancMultiframeVolumeLoader.cpp @ 2041:85a20cbfcc04 deep-learning
check glUseProgram()
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 01 Feb 2023 08:23:26 +0100 |
parents | 7053b8a0aaec |
children | 990f396484b1 |
rev | line source |
---|---|
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
9 * modify it under the terms of the GNU Lesser General Public License |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * as published by the Free Software Foundation, either version 3 of |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * the License, or (at your option) any later version. |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
16 * Lesser General Public License for more details. |
1596
4fb8fdf03314
removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1571
diff
changeset
|
17 * |
1598
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
18 * You should have received a copy of the GNU Lesser General Public |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
19 * License along with this program. If not, see |
8563ea5d8ae4
relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1596
diff
changeset
|
20 * <http://www.gnu.org/licenses/>. |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
21 **/ |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
22 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
23 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
24 #include "OrthancMultiframeVolumeLoader.h" |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
25 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1381
diff
changeset
|
26 #include <Endianness.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1381
diff
changeset
|
27 #include <Toolbox.h> |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
28 |
1751
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
29 #if STONE_TIME_BLOCKING_OPS |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
30 # include <boost/date_time/posix_time/posix_time.hpp> |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
31 #endif |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
32 |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 namespace OrthancStone |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
35 class OrthancMultiframeVolumeLoader::LoadRTDoseGeometry : public LoaderStateMachine::State |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
37 private: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 std::unique_ptr<Orthanc::DicomMap> dicom_; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
39 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
40 public: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
41 LoadRTDoseGeometry(OrthancMultiframeVolumeLoader& that, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
42 Orthanc::DicomMap* dicom) : |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
43 State(that), |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
44 dicom_(dicom) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
45 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
46 if (dicom == NULL) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
50 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
51 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
52 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
53 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) ORTHANC_OVERRIDE |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
54 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
55 // Complete the DICOM tags with just-received "Grid Frame Offset Vector" |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
56 std::string s = Orthanc::Toolbox::StripSpaces(message.GetAnswer()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
57 dicom_->SetValue(Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR, s, false); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
58 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
59 GetLoader<OrthancMultiframeVolumeLoader>().SetGeometry(*dicom_); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
60 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
61 }; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
62 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
63 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
64 static std::string GetSopClassUid(const Orthanc::DicomMap& dicom) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
65 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
66 std::string s; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
67 if (!dicom.LookupStringValue(s, Orthanc::DICOM_TAG_SOP_CLASS_UID, false)) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
68 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
69 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 "DICOM file without SOP class UID"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
72 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
73 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
74 return s; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
75 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
76 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
77 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
78 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
79 class OrthancMultiframeVolumeLoader::LoadGeometry : public State |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
80 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
81 public: |
1571 | 82 explicit LoadGeometry(OrthancMultiframeVolumeLoader& that) : |
83 State(that) | |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
84 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
85 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
86 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
87 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
88 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
89 OrthancMultiframeVolumeLoader& loader = GetLoader<OrthancMultiframeVolumeLoader>(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
91 Json::Value body; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 message.ParseJsonBody(body); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
93 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
94 if (body.type() != Json::objectValue) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
95 { |
1758
4ee11b8773e2
Better error description in case of network json payload errors
Benjamin Golinvaux <bgo@osimis.io>
parents:
1757
diff
changeset
|
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadJson, "JSON body should be an object value"); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
97 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
98 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
99 std::unique_ptr<Orthanc::DicomMap> dicom(new Orthanc::DicomMap); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
100 dicom->FromDicomAsJson(body); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
102 if (StringToSopClassUid(GetSopClassUid(*dicom)) == SopClassUid_RTDose) |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
104 // Download the "Grid Frame Offset Vector" DICOM tag, that is |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
105 // mandatory for RT-DOSE, but is too long to be returned by default |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
106 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
107 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
1831
a03260db8835
Added SetCallerName to IOracleCommand to ease debugging
Benjamin Golinvaux <bgo@osimis.io>
parents:
1758
diff
changeset
|
108 command->SetCallerName("OrthancMultiframeVolumeLoader::LoadGeometry"); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
109 command->SetUri("/instances/" + loader.GetInstanceId() + "/content/" + |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
110 Orthanc::DICOM_TAG_GRID_FRAME_OFFSET_VECTOR.Format()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
111 command->AcquirePayload(new LoadRTDoseGeometry(loader, dicom.release())); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
112 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
113 Schedule(command.release()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
114 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
115 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
116 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
117 loader.SetGeometry(*dicom); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
118 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
119 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
120 }; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
121 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
122 class OrthancMultiframeVolumeLoader::LoadTransferSyntax : public State |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
123 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
124 public: |
1571 | 125 explicit LoadTransferSyntax(OrthancMultiframeVolumeLoader& that) : |
126 State(that) | |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
127 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
128 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
129 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
130 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
131 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
132 GetLoader<OrthancMultiframeVolumeLoader>().SetTransferSyntax(message.GetAnswer()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
133 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
134 }; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
135 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
136 class OrthancMultiframeVolumeLoader::LoadUncompressedPixelData : public State |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
137 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
138 public: |
1571 | 139 explicit LoadUncompressedPixelData(OrthancMultiframeVolumeLoader& that) : |
140 State(that) | |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
141 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
142 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
143 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
144 virtual void Handle(const OrthancRestApiCommand::SuccessMessage& message) |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
145 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
146 GetLoader<OrthancMultiframeVolumeLoader>().SetUncompressedPixelData(message.GetAnswer()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
147 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
148 }; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
149 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
150 const std::string& OrthancMultiframeVolumeLoader::GetInstanceId() const |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
151 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
152 if (IsActive()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
153 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
154 return instanceId_; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
155 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
156 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
157 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
158 LOG(ERROR) << "OrthancMultiframeVolumeLoader::GetInstanceId(): (!IsActive())"; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
160 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
161 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
162 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
163 void OrthancMultiframeVolumeLoader::ScheduleFrameDownloads() |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
164 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
165 if (transferSyntaxUid_.empty() || |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
166 !volume_->HasGeometry()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
167 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
168 return; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
169 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
170 /* |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
171 1.2.840.10008.1.2 Implicit VR Endian: Default Transfer Syntax for DICOM |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
172 1.2.840.10008.1.2.1 Explicit VR Little Endian |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
173 1.2.840.10008.1.2.2 Explicit VR Big Endian |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
174 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
175 See https://www.dicomlibrary.com/dicom/transfer-syntax/ |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
176 */ |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
177 if (transferSyntaxUid_ == "1.2.840.10008.1.2" || |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
178 transferSyntaxUid_ == "1.2.840.10008.1.2.1" || |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
179 transferSyntaxUid_ == "1.2.840.10008.1.2.2") |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
180 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
181 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
1831
a03260db8835
Added SetCallerName to IOracleCommand to ease debugging
Benjamin Golinvaux <bgo@osimis.io>
parents:
1758
diff
changeset
|
182 command->SetCallerName("OrthancMultiframeVolumeLoader::ScheduleFrameDownloads"); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
183 command->SetHttpHeader("Accept-Encoding", "gzip"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
184 command->SetUri("/instances/" + instanceId_ + "/content/" + |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
185 Orthanc::DICOM_TAG_PIXEL_DATA.Format() + "/0"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
186 command->AcquirePayload(new LoadUncompressedPixelData(*this)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
187 Schedule(command.release()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
188 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
189 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
190 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
191 throw Orthanc::OrthancException( |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
192 Orthanc::ErrorCode_NotImplemented, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
193 "No support for multiframe instances with transfer syntax: " + transferSyntaxUid_); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
194 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
195 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
196 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
197 void OrthancMultiframeVolumeLoader::SetTransferSyntax(const std::string& transferSyntax) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
198 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
199 transferSyntaxUid_ = Orthanc::Toolbox::StripSpaces(transferSyntax); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
200 ScheduleFrameDownloads(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
201 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
202 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
203 void OrthancMultiframeVolumeLoader::SetGeometry(const Orthanc::DicomMap& dicom) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
204 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
205 DicomInstanceParameters parameters(dicom); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
206 volume_->SetDicomParameters(parameters); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
207 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
208 Orthanc::PixelFormat format; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
209 if (!parameters.GetImageInformation().ExtractPixelFormat(format, true)) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
210 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
211 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
212 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
213 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
214 double spacingZ; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
215 switch (parameters.GetSopClassUid()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
216 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
217 case SopClassUid_RTDose: |
1634
a4418a489e86
improving robustness of DicomInstanceParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1598
diff
changeset
|
218 spacingZ = parameters.GetSliceThickness(); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
219 break; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
220 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
221 default: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
222 throw Orthanc::OrthancException( |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
223 Orthanc::ErrorCode_NotImplemented, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
224 "No support for multiframe instances with SOP class UID: " + GetSopClassUid(dicom)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
225 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
226 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
227 const unsigned int width = parameters.GetImageInformation().GetWidth(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
228 const unsigned int height = parameters.GetImageInformation().GetHeight(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
229 const unsigned int depth = parameters.GetImageInformation().GetNumberOfFrames(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
230 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
231 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
232 VolumeImageGeometry geometry; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
233 geometry.SetSizeInVoxels(width, height, depth); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
234 geometry.SetAxialGeometry(parameters.GetGeometry()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
235 geometry.SetVoxelDimensions(parameters.GetPixelSpacingX(), |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
236 parameters.GetPixelSpacingY(), spacingZ); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
237 volume_->Initialize(geometry, format, true /* Do compute range */); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
238 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
239 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
240 volume_->GetPixelData().Clear(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
241 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
242 ScheduleFrameDownloads(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
243 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
244 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
245 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
246 BroadcastMessage(DicomVolumeImage::GeometryReadyMessage(*volume_)); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
247 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
248 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
249 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
250 ORTHANC_FORCE_INLINE |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
251 static void CopyPixel(uint32_t& target, const void* source) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
252 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
253 // TODO - check alignement? |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
254 target = le32toh(*reinterpret_cast<const uint32_t*>(source)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
255 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
256 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
257 ORTHANC_FORCE_INLINE |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
258 static void CopyPixel(uint16_t& target, const void* source) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
259 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
260 // TODO - check alignement? |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
261 target = le16toh(*reinterpret_cast<const uint16_t*>(source)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
262 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
263 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
264 ORTHANC_FORCE_INLINE |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
265 static void CopyPixel(int16_t& target, const void* source) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
266 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
267 // byte swapping is the same for unsigned and signed integers |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
268 // (the sign bit is always stored with the MSByte) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
269 uint16_t* targetUp = reinterpret_cast<uint16_t*>(&target); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
270 CopyPixel(*targetUp, source); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
271 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
272 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
273 template <typename T> |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
274 void OrthancMultiframeVolumeLoader::CopyPixelDataAndComputeDistribution( |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
275 const std::string& pixelData, std::map<T, PixelCount>& distribution) |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
276 { |
1751
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
277 #if STONE_TIME_BLOCKING_OPS |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
278 boost::posix_time::ptime timerStart = boost::posix_time::microsec_clock::universal_time(); |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
279 #endif |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
280 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
281 ImageBuffer3D& target = volume_->GetPixelData(); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
282 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
283 const unsigned int bpp = target.GetBytesPerPixel(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
284 const unsigned int width = target.GetWidth(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
285 const unsigned int height = target.GetHeight(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
286 const unsigned int depth = target.GetDepth(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
287 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
288 if (pixelData.size() != bpp * width * height * depth) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
289 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
290 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
291 "The pixel data has not the proper size"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
292 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
293 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
294 if (pixelData.empty()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
295 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
296 return; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
297 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
298 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
299 // first pass to initialize map |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
300 #if 0 |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
301 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
302 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData.c_str()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
303 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
304 for (unsigned int z = 0; z < depth; z++) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
305 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
306 for (unsigned int y = 0; y < height; y++) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
307 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
308 for (unsigned int x = 0; x < width; x++) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
309 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
310 T value; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
311 CopyPixel(value, source); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
312 distribution[value] = 0; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
313 source += bpp; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
314 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
315 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
316 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
317 } |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
318 #endif |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
319 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
320 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
321 const uint8_t* source = reinterpret_cast<const uint8_t*>(pixelData.c_str()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
322 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
323 for (unsigned int z = 0; z < depth; z++) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
324 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
325 ImageBuffer3D::SliceWriter writer(target, VolumeProjection_Axial, z); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
326 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
327 assert(writer.GetAccessor().GetWidth() == width && |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
328 writer.GetAccessor().GetHeight() == height); |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
329 #if 0 |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
330 for (unsigned int y = 0; y < height; y++) |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
331 { |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
332 assert(sizeof(T) == Orthanc::GetBytesPerPixel(target.GetFormat())); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
333 |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
334 T* target = reinterpret_cast<T*>(writer.GetAccessor().GetRow(y)); |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
335 |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
336 for (unsigned int x = 0; x < width; x++) |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
337 { |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
338 CopyPixel(*target, source); |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
339 |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
340 distribution[*target] += 1; |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
341 |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
342 target++; |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
343 source += bpp; |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
344 } |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
345 } |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
346 #else |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
347 // optimized version (fixed) as of 2020-04-15 |
1349
b1e6bef86955
Tentative loop optimization in CopyPixelDataAndComputeDistribution
Benjamin Golinvaux <bgo@osimis.io>
parents:
1337
diff
changeset
|
348 unsigned int pitch = writer.GetAccessor().GetPitch(); |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
349 T* targetAddrLine = reinterpret_cast<T*>(writer.GetAccessor().GetRow(0)); |
1349
b1e6bef86955
Tentative loop optimization in CopyPixelDataAndComputeDistribution
Benjamin Golinvaux <bgo@osimis.io>
parents:
1337
diff
changeset
|
350 assert(sizeof(T) == Orthanc::GetBytesPerPixel(target.GetFormat())); |
b1e6bef86955
Tentative loop optimization in CopyPixelDataAndComputeDistribution
Benjamin Golinvaux <bgo@osimis.io>
parents:
1337
diff
changeset
|
351 |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
352 for (unsigned int y = 0; y < height; y++) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
353 { |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
354 T* targetAddrPix = targetAddrLine; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
355 for (unsigned int x = 0; x < width; x++) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
356 { |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
357 CopyPixel(*targetAddrPix, source); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
358 |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
359 distribution[*targetAddrPix].count_ += 1; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
360 |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
361 targetAddrPix++; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
362 source += bpp; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
363 } |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
364 uint8_t* targetAddrLineBytes = reinterpret_cast<uint8_t*>(targetAddrLine) + pitch; |
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
365 targetAddrLine = reinterpret_cast<T*>(targetAddrLineBytes); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
366 } |
1362
104e0b0f2316
Fixed the broken function, and left the unoptimized
Benjamin Golinvaux <bgo@osimis.io>
parents:
1349
diff
changeset
|
367 #endif |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
368 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
369 } |
1751
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
370 #if STONE_TIME_BLOCKING_OPS |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
371 boost::posix_time::ptime timerEnd = boost::posix_time::microsec_clock::universal_time(); |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
372 boost::posix_time::time_duration duration = timerEnd - timerStart; |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
373 int64_t durationMs = duration.total_milliseconds(); |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
374 LOG(WARNING) << "OrthancMultiframeVolumeLoader::CopyPixelDataAndComputeDistribution took " << durationMs << " ms"; |
946eb7200b82
FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents:
1739
diff
changeset
|
375 #endif |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
376 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
377 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
378 template <typename T> |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
379 void OrthancMultiframeVolumeLoader::ComputeMinMaxWithOutlierRejection( |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
380 const std::map<T, PixelCount>& distribution) |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
381 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
382 if (distribution.size() == 0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
383 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
384 LOG(ERROR) << "ComputeMinMaxWithOutlierRejection -- Volume image empty."; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
385 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
386 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
387 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
388 ImageBuffer3D& target = volume_->GetPixelData(); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
389 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
390 const uint64_t width = target.GetWidth(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
391 const uint64_t height = target.GetHeight(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
392 const uint64_t depth = target.GetDepth(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
393 const uint64_t voxelCount = width * height * depth; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
394 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
395 // now that we have distribution[pixelValue] == numberOfPixelsWithValue |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
396 // compute number of values and check (assertion) that it is equal to |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
397 // width * height * depth |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
398 { |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
399 typename std::map<T, PixelCount>::const_iterator it = distribution.begin(); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
400 uint64_t totalCount = 0; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
401 distributionRawMin_ = static_cast<float>(it->first); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
402 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
403 while (it != distribution.end()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
404 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
405 T pixelValue = it->first; |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
406 totalCount += it->second.count_; |
1571 | 407 ++it; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
408 if (it == distribution.end()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
409 distributionRawMax_ = static_cast<float>(pixelValue); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
410 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
411 LOG(INFO) << "Volume image. First distribution value = " |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
412 << static_cast<float>(distributionRawMin_) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
413 << " | Last distribution value = " |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
414 << static_cast<float>(distributionRawMax_); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
415 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
416 if (totalCount != voxelCount) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
417 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
418 LOG(ERROR) << "Internal error in dose distribution computation. TC (" |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
419 << totalCount << ") != VoxC (" << voxelCount; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
420 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
421 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
422 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
423 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
424 // compute the number of voxels to reject at each end of the distribution |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
425 uint64_t endRejectionCount = static_cast<uint64_t>( |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
426 outliersHalfRejectionRate_ * voxelCount); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
427 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
428 if (endRejectionCount > voxelCount) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
429 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
430 LOG(ERROR) << "Internal error in dose distribution computation." |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
431 << " endRejectionCount = " << endRejectionCount |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
432 << " | voxelCount = " << voxelCount; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
433 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
434 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
435 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
436 // this will contain the actual distribution minimum after outlier |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
437 // rejection |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
438 T resultMin = 0; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
439 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
440 // then start from start and remove pixel values up to |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
441 // endRejectionCount voxels rejected |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
442 { |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
443 typename std::map<T, PixelCount>::const_iterator it = distribution.begin(); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
444 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
445 uint64_t currentCount = 0; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
446 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
447 while (it != distribution.end()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
448 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
449 T pixelValue = it->first; |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
450 uint64_t count = it->second.count_; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
451 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
452 // if this pixelValue crosses the rejection threshold, let's set it |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
453 // and exit the loop |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
454 if ((currentCount <= endRejectionCount) && |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
455 (currentCount + count > endRejectionCount)) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
456 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
457 resultMin = pixelValue; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
458 break; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
459 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
460 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
461 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
462 currentCount += count; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
463 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
464 // and continue walking along the distribution |
1571 | 465 ++it; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
466 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
467 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
468 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
469 // this will contain the actual distribution maximum after outlier |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
470 // rejection |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
471 T resultMax = 0; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
472 // now start from END and remove pixel values up to |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
473 // endRejectionCount voxels rejected |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
474 { |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
475 typename std::map<T, PixelCount>::const_reverse_iterator it = distribution.rbegin(); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
476 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
477 uint64_t currentCount = 0; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
478 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
479 while (it != distribution.rend()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
480 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
481 T pixelValue = it->first; |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
482 uint64_t count = it->second.count_; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
483 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
484 if ((currentCount <= endRejectionCount) && |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
485 (currentCount + count > endRejectionCount)) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
486 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
487 resultMax = pixelValue; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
488 break; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
489 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
490 else |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
491 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
492 currentCount += count; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
493 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
494 // and continue walking along the distribution |
1571 | 495 ++it; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
496 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
497 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
498 if (resultMin > resultMax) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
499 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
500 LOG(ERROR) << "Internal error in dose distribution computation! " << |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
501 "resultMin (" << resultMin << ") > resultMax (" << resultMax << ")"; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
502 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
503 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
504 computedDistributionMin_ = static_cast<float>(resultMin); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
505 computedDistributionMax_ = static_cast<float>(resultMax); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
506 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
507 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
508 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
509 template <typename T> |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
510 void OrthancMultiframeVolumeLoader::CopyPixelDataAndComputeMinMax( |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
511 const std::string& pixelData) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
512 { |
1757
28979b77ce90
Suppressed one pass on the dose distribution computation
bgo@SHARKNADO.localdomain
parents:
1751
diff
changeset
|
513 std::map<T, PixelCount> distribution; |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
514 CopyPixelDataAndComputeDistribution(pixelData, distribution); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
515 ComputeMinMaxWithOutlierRejection(distribution); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
516 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
517 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
518 void OrthancMultiframeVolumeLoader::SetUncompressedPixelData(const std::string& pixelData) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
519 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
520 switch (volume_->GetPixelData().GetFormat()) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
521 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
522 case Orthanc::PixelFormat_Grayscale32: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
523 CopyPixelDataAndComputeMinMax<uint32_t>(pixelData); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
524 break; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
525 case Orthanc::PixelFormat_Grayscale16: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
526 CopyPixelDataAndComputeMinMax<uint16_t>(pixelData); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
527 break; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
528 case Orthanc::PixelFormat_SignedGrayscale16: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
529 CopyPixelDataAndComputeMinMax<int16_t>(pixelData); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
530 break; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
531 default: |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
532 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
533 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
534 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
535 volume_->IncrementRevision(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
536 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
537 pixelDataLoaded_ = true; |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
538 BroadcastMessage(DicomVolumeImage::ContentUpdatedMessage(*volume_)); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
539 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
540 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
541 bool OrthancMultiframeVolumeLoader::HasGeometry() const |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
542 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
543 return volume_->HasGeometry(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
544 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
545 |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
546 const VolumeImageGeometry& OrthancMultiframeVolumeLoader::GetImageGeometry() const |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
547 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
548 return volume_->GetGeometry(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
549 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
550 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
551 OrthancMultiframeVolumeLoader::OrthancMultiframeVolumeLoader( |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
552 ILoadersContext& loadersContext, |
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
553 boost::shared_ptr<DicomVolumeImage> volume, |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
554 float outliersHalfRejectionRate) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
555 : LoaderStateMachine(loadersContext) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
556 , volume_(volume) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
557 , pixelDataLoaded_(false) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
558 , outliersHalfRejectionRate_(outliersHalfRejectionRate) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
559 , distributionRawMin_(0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
560 , distributionRawMax_(0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
561 , computedDistributionMin_(0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
562 , computedDistributionMax_(0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
563 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
564 if (volume.get() == NULL) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
565 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
566 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
567 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
568 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
569 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
570 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
571 boost::shared_ptr<OrthancMultiframeVolumeLoader> |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
572 OrthancMultiframeVolumeLoader::Create( |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
573 ILoadersContext& loadersContext, |
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
574 boost::shared_ptr<DicomVolumeImage> volume, |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
575 float outliersHalfRejectionRate /*= 0.0005*/) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
576 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
577 boost::shared_ptr<OrthancMultiframeVolumeLoader> obj( |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
578 new OrthancMultiframeVolumeLoader( |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
579 loadersContext, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
580 volume, |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
581 outliersHalfRejectionRate)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
582 obj->LoaderStateMachine::PostConstructor(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
583 return obj; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
584 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
585 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
586 OrthancMultiframeVolumeLoader::~OrthancMultiframeVolumeLoader() |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
587 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
588 LOG(TRACE) << "OrthancMultiframeVolumeLoader::~OrthancMultiframeVolumeLoader()"; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
589 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
590 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
591 void OrthancMultiframeVolumeLoader::GetDistributionMinMax |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
592 (float& minValue, float& maxValue) const |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
593 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
594 if (distributionRawMin_ == 0 && distributionRawMax_ == 0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
595 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
596 LOG(WARNING) << "GetDistributionMinMaxWithOutliersRejection called before computation!"; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
597 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
598 minValue = distributionRawMin_; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
599 maxValue = distributionRawMax_; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
600 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
601 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
602 void OrthancMultiframeVolumeLoader::GetDistributionMinMaxWithOutliersRejection |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
603 (float& minValue, float& maxValue) const |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
604 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
605 if (computedDistributionMin_ == 0 && computedDistributionMax_ == 0) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
606 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
607 LOG(WARNING) << "GetDistributionMinMaxWithOutliersRejection called before computation!"; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
608 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
609 minValue = computedDistributionMin_; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
610 maxValue = computedDistributionMax_; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
611 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
612 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
613 void OrthancMultiframeVolumeLoader::LoadInstance(const std::string& instanceId) |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
614 { |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
615 Start(); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
616 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
617 instanceId_ = instanceId; |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
618 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
619 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
620 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
1831
a03260db8835
Added SetCallerName to IOracleCommand to ease debugging
Benjamin Golinvaux <bgo@osimis.io>
parents:
1758
diff
changeset
|
621 command->SetCallerName("OrthancMultiframeVolumeLoader::LoadInstance"); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
622 command->SetHttpHeader("Accept-Encoding", "gzip"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
623 command->SetUri("/instances/" + instanceId + "/tags"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
624 command->AcquirePayload(new LoadGeometry(*this)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
625 Schedule(command.release()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
626 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
627 |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
628 { |
1640
52b8b96cb55f
cleaning namespaces
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1634
diff
changeset
|
629 std::unique_ptr<OrthancRestApiCommand> command(new OrthancRestApiCommand); |
1831
a03260db8835
Added SetCallerName to IOracleCommand to ease debugging
Benjamin Golinvaux <bgo@osimis.io>
parents:
1758
diff
changeset
|
630 command->SetCallerName("OrthancMultiframeVolumeLoader::LoadInstance"); |
1337
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
631 command->SetUri("/instances/" + instanceId + "/metadata/TransferSyntax"); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
632 command->AcquirePayload(new LoadTransferSyntax(*this)); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
633 Schedule(command.release()); |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
634 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
635 } |
b1396be5aa27
Moved the fixed loaders back from the dead
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
636 } |