annotate Plugins/Samples/GdcmDecoder/Plugin.cpp @ 2427:715476b5d671

fix
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 10 Oct 2017 13:00:20 +0200
parents a3a65de1840f
children 878b59270859
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
2244
a3a65de1840f shared copyright with osimis
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1900
diff changeset
5 * Copyright (C) 2017 Osimis, 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
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "GdcmDecoderCache.h"
1837
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
23 #include "OrthancImageWrapper.h"
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <orthanc/OrthancCPlugin.h>
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 static OrthancPluginContext* context_ = NULL;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 static OrthancPlugins::GdcmDecoderCache cache_;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31 static OrthancPluginErrorCode DecodeImageCallback(OrthancPluginImage** target,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 const void* dicom,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 const uint32_t size,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 uint32_t frameIndex)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 try
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 {
1837
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
38 std::auto_ptr<OrthancPlugins::OrthancImageWrapper> image;
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
39
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 #if 0
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 // Do not use the cache
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42 OrthancPlugins::GdcmImageDecoder decoder(dicom, size);
1840
859224214616 simplification of the sample plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1837
diff changeset
43 image.reset(new OrthancPlugins::OrthancImageWrapper(context_, decoder.Decode(context_, frameIndex)));
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #else
1837
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
45 image.reset(cache_.Decode(context_, dicom, size, frameIndex));
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #endif
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47
1837
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
48 *target = image->Release();
fbc5522023aa refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1834
diff changeset
49
1834
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 return OrthancPluginErrorCode_Success;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52 catch (std::runtime_error& e)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 *target = NULL;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56 std::string s = "Cannot decode image using GDCM: " + std::string(e.what());
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 OrthancPluginLogError(context_, s.c_str());
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 return OrthancPluginErrorCode_Plugin;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 extern "C"
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 context_ = context;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 OrthancPluginLogWarning(context_, "Initializing the advanced decoder of medical images using GDCM");
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72 /* Check the version of the Orthanc core */
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 if (OrthancPluginCheckVersion(context_) == 0)
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75 char info[1024];
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 context_->orthancVersion,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 OrthancPluginLogError(context_, info);
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82 return -1;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 OrthancPluginSetDescription(context_, "Advanced decoder of medical images using GDCM.");
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86 OrthancPluginRegisterDecodeImageCallback(context_, DecodeImageCallback);
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 return 0;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99 return "gdcm-decoder";
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 {
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 return GDCM_DECODER_VERSION;
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 }
b1a6f49b21dd GDCM decoder sample
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 }