annotate Plugins/Samples/GdcmDecoder/Plugin.cpp @ 3933:f67b48833a4f transcoding

new option "Throttling" to the GDCM plugin
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 15 May 2020 12:25:36 +0200
parents b99acc213937
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Orthanc - A Lightweight, RESTful DICOM Store
1900
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1840
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
3640
94f4a18a79cc upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3060
diff changeset
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * modify it under the terms of the GNU General Public License as
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9 * published by the Free Software Foundation, either version 3 of the
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 * License, or (at your option) any later version.
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 * General Public License for more details.
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 *
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
3768
6110a4995ace replacing std::auto_ptr by std::unique_ptr in GDCM sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3640
diff changeset
22 #include "../../../Core/Compatibility.h"
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
23 #include "../../../Core/DicomFormat/DicomMap.h"
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
24 #include "../../../Core/MultiThreading/Semaphore.h"
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
25 #include "../../../Core/Toolbox.h"
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include "GdcmDecoderCache.h"
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
27
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
28 #include <gdcmImageChangeTransferSyntax.h>
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
29 #include <gdcmImageReader.h>
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
30 #include <gdcmImageWriter.h>
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
31 #include <gdcmUIDGenerator.h>
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
32 #include <gdcmAttribute.h>
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
33
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
34
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
35 static OrthancPlugins::GdcmDecoderCache cache_;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
36 static bool restrictTransferSyntaxes_ = false;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
37 static std::set<std::string> enabledTransferSyntaxes_;
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
38 static bool hasThrottling_ = false;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
39 static std::unique_ptr<Orthanc::Semaphore> throttlingSemaphore_;
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
40
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
41 static bool ExtractTransferSyntax(std::string& transferSyntax,
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
42 const void* dicom,
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
43 const uint32_t size)
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
44 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
45 Orthanc::DicomMap header;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
46 if (!Orthanc::DicomMap::ParseDicomMetaInformation(header, reinterpret_cast<const char*>(dicom), size))
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
47 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
48 return false;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
49 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
50
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
51 const Orthanc::DicomValue* tag = header.TestAndGetValue(0x0002, 0x0010);
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
52 if (tag == NULL ||
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
53 tag->IsNull() ||
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
54 tag->IsBinary())
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
55 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
56 return false;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
57 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
58 else
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
59 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
60 // Stripping spaces should not be required, as this is a UI value
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
61 // representation whose stripping is supported by the Orthanc
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
62 // core, but let's be careful...
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
63 transferSyntax = Orthanc::Toolbox::StripSpaces(tag->GetContent());
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
64 return true;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
65 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
66 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
67
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
69 static bool IsTransferSyntaxEnabled(const void* dicom,
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
70 const uint32_t size)
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
71 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
72 std::string formattedSize;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
73
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
74 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
75 char tmp[16];
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
76 sprintf(tmp, "%0.1fMB", static_cast<float>(size) / (1024.0f * 1024.0f));
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
77 formattedSize.assign(tmp);
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
78 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
79
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
80 if (!restrictTransferSyntaxes_)
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
81 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
82 LOG(INFO) << "Decoding one DICOM instance of " << formattedSize << " using GDCM";
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
83 return true;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
84 }
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
86 std::string transferSyntax;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
87 if (!ExtractTransferSyntax(transferSyntax, dicom, size))
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
88 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
89 LOG(INFO) << "Cannot extract the transfer syntax of this instance of "
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
90 << formattedSize << ", will use GDCM to decode it";
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
91 return true;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
92 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
93 else if (enabledTransferSyntaxes_.find(transferSyntax) != enabledTransferSyntaxes_.end())
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
94 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
95 // Decoding for this transfer syntax is enabled
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
96 LOG(INFO) << "Using GDCM to decode this instance of " << formattedSize
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
97 << " with transfer syntax " << transferSyntax;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
98 return true;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
99 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
100 else
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
101 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
102 LOG(INFO) << "Won't use GDCM to decode this instance of " << formattedSize
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
103 << ", as its transfer syntax " << transferSyntax << " is disabled";
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
104 return false;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
105 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
106 }
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 static OrthancPluginErrorCode DecodeImageCallback(OrthancPluginImage** target,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 const void* dicom,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 const uint32_t size,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 uint32_t frameIndex)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 try
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
116 std::unique_ptr<Orthanc::Semaphore::Locker> locker;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
117
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
118 if (hasThrottling_)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
119 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
120 if (throttlingSemaphore_.get() == NULL)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
121 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
122 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
123 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
124 else
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
125 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
126 locker.reset(new Orthanc::Semaphore::Locker(*throttlingSemaphore_));
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
127 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
128 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
129
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
130 if (!IsTransferSyntaxEnabled(dicom, size))
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
131 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
132 *target = NULL;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
133 return OrthancPluginErrorCode_Success;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
134 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
135
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
136 std::unique_ptr<OrthancPlugins::OrthancImage> image;
1837
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
137
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 #if 0
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139 // Do not use the cache
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 OrthancPlugins::GdcmImageDecoder decoder(dicom, size);
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
141 image.reset(new OrthancPlugins::OrthancImage(decoder.Decode(frameIndex)));
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 #else
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
143 image.reset(cache_.Decode(dicom, size, frameIndex));
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 #endif
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
1837
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
146 *target = image->Release();
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
147
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 return OrthancPluginErrorCode_Success;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 }
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
150 catch (Orthanc::OrthancException& e)
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
151 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
152 *target = NULL;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
153
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
154 LOG(WARNING) << "Cannot decode image using GDCM: " << e.What();
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
155 return OrthancPluginErrorCode_Plugin;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
156 }
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 catch (std::runtime_error& e)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 *target = NULL;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
161 LOG(WARNING) << "Cannot decode image using GDCM: " << e.what();
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
162 return OrthancPluginErrorCode_Plugin;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
163 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
164 catch (...)
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
165 {
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
166 *target = NULL;
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
167
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
168 LOG(WARNING) << "Native exception while decoding image using GDCM";
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 return OrthancPluginErrorCode_Plugin;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
174 OrthancPluginErrorCode TranscoderCallback(
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
175 OrthancPluginMemoryBuffer* transcoded /* out */,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
176 uint8_t* hasSopInstanceUidChanged /* out */,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
177 const void* buffer,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
178 uint64_t size,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
179 const char* const* allowedSyntaxes,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
180 uint32_t countSyntaxes,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
181 uint8_t allowNewSopInstanceUid)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
182 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
183 try
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
184 {
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
185 std::unique_ptr<Orthanc::Semaphore::Locker> locker;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
186
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
187 if (hasThrottling_)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
188 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
189 if (throttlingSemaphore_.get() == NULL)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
190 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
191 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
192 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
193 else
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
194 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
195 locker.reset(new Orthanc::Semaphore::Locker(*throttlingSemaphore_));
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
196 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
197 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
198
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
199 std::string dicom(reinterpret_cast<const char*>(buffer), size);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
200 std::stringstream stream(dicom);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
201
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
202 gdcm::ImageReader reader;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
203 reader.SetStream(stream);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
204 if (!reader.Read())
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
205 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
206 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
207 "GDCM cannot decode the image");
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
208 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
209
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
210 // First check that transcoding is mandatory
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
211 for (uint32_t i = 0; i < countSyntaxes; i++)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
212 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
213 gdcm::TransferSyntax syntax(gdcm::TransferSyntax::GetTSType(allowedSyntaxes[i]));
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
214 if (syntax.IsValid() &&
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
215 reader.GetImage().GetTransferSyntax() == syntax)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
216 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
217 // Same transfer syntax as in the source, return a copy of the
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
218 // source buffer
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
219 OrthancPlugins::MemoryBuffer orthancBuffer(buffer, size);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
220 *transcoded = orthancBuffer.Release();
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
221 *hasSopInstanceUidChanged = false;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
222 return OrthancPluginErrorCode_Success;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
223 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
224 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
225
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
226 for (uint32_t i = 0; i < countSyntaxes; i++)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
227 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
228 gdcm::TransferSyntax syntax(gdcm::TransferSyntax::GetTSType(allowedSyntaxes[i]));
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
229 if (syntax.IsValid())
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
230 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
231 gdcm::ImageChangeTransferSyntax change;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
232 change.SetTransferSyntax(syntax);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
233 change.SetInput(reader.GetImage());
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
234
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
235 if (change.Change())
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
236 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
237 if (syntax == gdcm::TransferSyntax::JPEGBaselineProcess1 ||
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
238 syntax == gdcm::TransferSyntax::JPEGExtendedProcess2_4 ||
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
239 syntax == gdcm::TransferSyntax::JPEGLSNearLossless ||
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
240 syntax == gdcm::TransferSyntax::JPEG2000 ||
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
241 syntax == gdcm::TransferSyntax::JPEG2000Part2)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
242 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
243 // In the case of a lossy compression, generate new SOP instance UID
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
244 gdcm::UIDGenerator generator;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
245 std::string uid = generator.Generate();
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
246 if (uid.size() == 0)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
247 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
248 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
249 "GDCM cannot generate a UID");
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
250 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
251
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
252 gdcm::Attribute<0x0008,0x0018> sopInstanceUid;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
253 sopInstanceUid.SetValue(uid);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
254 reader.GetFile().GetDataSet().Replace(sopInstanceUid.GetAsDataElement());
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
255 *hasSopInstanceUidChanged = 1;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
256 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
257 else
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
258 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
259 *hasSopInstanceUidChanged = 0;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
260 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
261
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
262 // GDCM was able to change the transfer syntax, serialize it
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
263 // to the output buffer
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
264 gdcm::ImageWriter writer;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
265 writer.SetImage(change.GetOutput());
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
266 writer.SetFile(reader.GetFile());
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
267
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
268 std::stringstream ss;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
269 writer.SetStream(ss);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
270 if (writer.Write())
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
271 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
272 std::string s = ss.str();
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
273 OrthancPlugins::MemoryBuffer orthancBuffer(s.empty() ? NULL : s.c_str(), s.size());
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
274 *transcoded = orthancBuffer.Release();
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
275
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
276 return OrthancPluginErrorCode_Success;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
277 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
278 else
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
279 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
280 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError,
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
281 "GDCM cannot serialize the image");
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
282 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
283 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
284 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
285 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
286
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
287 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
288 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
289 catch (Orthanc::OrthancException& e)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
290 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
291 LOG(INFO) << "Cannot transcode image using GDCM: " << e.What();
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
292 return OrthancPluginErrorCode_Plugin;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
293 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
294 catch (std::runtime_error& e)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
295 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
296 LOG(INFO) << "Cannot transcode image using GDCM: " << e.what();
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
297 return OrthancPluginErrorCode_Plugin;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
298 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
299 catch (...)
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
300 {
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
301 LOG(INFO) << "Native exception while decoding image using GDCM";
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
302 return OrthancPluginErrorCode_Plugin;
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
303 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
304 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
305
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
307 /**
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
308 * We force the redefinition of the "ORTHANC_PLUGINS_API" macro, that
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
309 * was left empty with gcc until Orthanc SDK 1.5.7 (no "default"
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
310 * visibility). This causes the version script, if run from "Holy
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
311 * Build Box", to make private the 4 global functions of the plugin.
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
312 **/
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
313
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
314 #undef ORTHANC_PLUGINS_API
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
315
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
316 #ifdef WIN32
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
317 # define ORTHANC_PLUGINS_API __declspec(dllexport)
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
318 #elif __GNUC__ >= 4
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
319 # define ORTHANC_PLUGINS_API __attribute__ ((visibility ("default")))
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
320 #else
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
321 # define ORTHANC_PLUGINS_API
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
322 #endif
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
323
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
324
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 extern "C"
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328 {
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
329 static const char* const KEY_GDCM = "Gdcm";
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
330 static const char* const KEY_ENABLE_GDCM = "Enable";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
331 static const char* const KEY_THROTTLING = "Throttling";
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
332 static const char* const KEY_RESTRICT_TRANSFER_SYNTAXES = "RestrictTransferSyntaxes";
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
333
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
334 try
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 {
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
336 OrthancPlugins::SetGlobalContext(context);
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
337 Orthanc::Logging::Initialize(context);
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
338 LOG(INFO) << "Initializing the decoder/transcoder of medical images using GDCM";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
339
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
340 /* Check the version of the Orthanc core */
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
341 if (!OrthancPlugins::CheckMinimalOrthancVersion(0, 9, 5))
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
342 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
343 LOG(ERROR) << "Your version of Orthanc (" << std::string(context->orthancVersion)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
344 << ") must be above 0.9.5 to run this plugin";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
345 return -1;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
346 }
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
348 OrthancPluginSetDescription(context, "Decoder/transcoder of medical images using GDCM.");
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
349
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
350 OrthancPlugins::OrthancConfiguration global;
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
351
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
352 bool enabled = true;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
353 hasThrottling_ = false;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
354
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
355 if (global.IsSection(KEY_GDCM))
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
356 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
357 OrthancPlugins::OrthancConfiguration config;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
358 global.GetSection(config, KEY_GDCM);
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
359
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
360 enabled = config.GetBooleanValue(KEY_ENABLE_GDCM, true);
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
361
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
362 if (enabled &&
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
363 config.LookupSetOfStrings(enabledTransferSyntaxes_, KEY_RESTRICT_TRANSFER_SYNTAXES, false))
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
364 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
365 restrictTransferSyntaxes_ = true;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
366
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
367 for (std::set<std::string>::const_iterator it = enabledTransferSyntaxes_.begin();
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
368 it != enabledTransferSyntaxes_.end(); ++it)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
369 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
370 LOG(WARNING) << "Orthanc will use GDCM to decode transfer syntax: " << *it;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
371 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
372 }
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
374 unsigned int throttling;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
375 if (enabled &&
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
376 config.LookupUnsignedIntegerValue(throttling, KEY_THROTTLING))
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
377 {
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
378 if (throttling == 0)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
379 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
380 LOG(ERROR) << "Bad value for option \"" << KEY_THROTTLING
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
381 << "\": Must be a strictly positive integer";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
382 return -1;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
383 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
384 else
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
385 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
386 LOG(WARNING) << "Throttling GDCM to " << throttling << " concurrent thread(s)";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
387 hasThrottling_ = true;
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
388 throttlingSemaphore_.reset(new Orthanc::Semaphore(throttling));
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
389 }
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
390 }
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
391 }
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
392
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
393 if (enabled)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
394 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
395 if (!hasThrottling_)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
396 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
397 LOG(WARNING) << "GDCM throttling is disabled";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
398 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
399
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
400 OrthancPluginRegisterDecodeImageCallback(context, DecodeImageCallback);
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
401
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
402 if (OrthancPlugins::CheckMinimalOrthancVersion(1, 7, 0))
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
403 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
404 OrthancPluginRegisterTranscoderCallback(context, TranscoderCallback);
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
405 }
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
406 else
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
407 {
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
408 LOG(WARNING) << "Your version of Orthanc (" << std::string(context->orthancVersion)
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
409 << ") must be above 1.7.0 to benefit from transcoding";
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
410 }
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
411 }
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
412 else
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
413 {
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
414 LOG(WARNING) << "The decoder/transcoder of medical images using GDCM is disabled";
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
415 }
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
416
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
417 return 0;
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
418 }
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
419 catch (Orthanc::OrthancException& e)
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
420 {
3933
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
421 LOG(ERROR) << "Exception while initializing the GDCM plugin: " << e.What();
f67b48833a4f new option "Throttling" to the GDCM plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3930
diff changeset
422 return -1;
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
423 }
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 {
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
429 LOG(INFO) << "Finalizing the decoder/transcoder of medical images using GDCM";
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434 {
3930
b99acc213937 transcoder plugins and GDCM transcoding are working
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3915
diff changeset
435 return "gdcm";
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 {
3915
7e33516965f8 merging sample GDCM decoder and Orthanc Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 3768
diff changeset
441 return PLUGIN_VERSION;
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 }