comparison Plugins/Samples/GdcmDecoder/Plugin.cpp @ 1834:b1a6f49b21dd

GDCM decoder sample
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 27 Nov 2015 12:53:32 +0100
parents
children fbc5522023aa
comparison
equal deleted inserted replaced
1833:47d032c48818 1834:b1a6f49b21dd
1 /**
2 * Orthanc - A Lightweight, RESTful DICOM Store
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 *
6 * This program is free software: you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 **/
19
20
21 #include "GdcmDecoderCache.h"
22
23 #include <orthanc/OrthancCPlugin.h>
24
25 static OrthancPluginContext* context_ = NULL;
26 static OrthancPlugins::GdcmDecoderCache cache_;
27
28
29 static OrthancPluginErrorCode DecodeImageCallback(OrthancPluginImage** target,
30 const void* dicom,
31 const uint32_t size,
32 uint32_t frameIndex)
33 {
34 try
35 {
36 #if 0
37 // Do not use the cache
38 OrthancPlugins::GdcmImageDecoder decoder(dicom, size);
39 *target = decoder.Decode(context_, frameIndex);
40 #else
41 *target = cache_.Decode(context_, dicom, size, frameIndex);
42 #endif
43
44 return OrthancPluginErrorCode_Success;
45 }
46 catch (std::runtime_error& e)
47 {
48 *target = NULL;
49
50 std::string s = "Cannot decode image using GDCM: " + std::string(e.what());
51 OrthancPluginLogError(context_, s.c_str());
52 return OrthancPluginErrorCode_Plugin;
53 }
54 }
55
56
57
58 extern "C"
59 {
60 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context)
61 {
62 context_ = context;
63 OrthancPluginLogWarning(context_, "Initializing the advanced decoder of medical images using GDCM");
64
65
66 /* Check the version of the Orthanc core */
67 if (OrthancPluginCheckVersion(context_) == 0)
68 {
69 char info[1024];
70 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin",
71 context_->orthancVersion,
72 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER,
73 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER,
74 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER);
75 OrthancPluginLogError(context_, info);
76 return -1;
77 }
78
79 OrthancPluginSetDescription(context_, "Advanced decoder of medical images using GDCM.");
80 OrthancPluginRegisterDecodeImageCallback(context_, DecodeImageCallback);
81
82 return 0;
83 }
84
85
86 ORTHANC_PLUGINS_API void OrthancPluginFinalize()
87 {
88 }
89
90
91 ORTHANC_PLUGINS_API const char* OrthancPluginGetName()
92 {
93 return "gdcm-decoder";
94 }
95
96
97 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion()
98 {
99 return GDCM_DECODER_VERSION;
100 }
101 }