Mercurial > hg > orthanc-stl
annotate Sources/Plugin.cpp @ 0:4e889a8e8be2
initial commit of the viewer plugin
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 04 Jul 2023 19:15:27 +0200 |
parents | |
children | 0f03a8a0bd6f |
rev | line source |
---|---|
0
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * SPDX-License-Identifier: GPL-3.0-or-later |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 */ |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
5 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
6 /** |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * STL plugin for Orthanc |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * This program is free software: you can redistribute it and/or |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * modify it under the terms of the GNU General Public License as |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * published by the Free Software Foundation, either version 3 of the |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * License, or (at your option) any later version. |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, but |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * WITHOUT ANY WARRANTY; without even the implied warranty of |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * General Public License for more details. |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 **/ |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
23 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
26 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
27 #include <Logging.h> |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
28 #include <SystemToolbox.h> |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
29 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
30 #include <EmbeddedResources.h> |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
31 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
32 #include <boost/thread/shared_mutex.hpp> |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
33 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 // Forward declaration |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
35 void ReadStaticAsset(std::string& target, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
36 const std::string& path); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
38 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
39 /** |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
40 * As the Three.js static assets are gzipped by the |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
41 * "EmbedStaticAssets.py" script, we use a cache to maintain the |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
42 * uncompressed assets in order to avoid multiple gzip decodings. |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
43 **/ |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
44 class ResourcesCache : public boost::noncopyable |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
45 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
46 private: |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
47 typedef std::map<std::string, std::string*> Content; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
48 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
49 boost::shared_mutex mutex_; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
50 Content content_; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
51 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
52 public: |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
53 ~ResourcesCache() |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
54 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
55 for (Content::iterator it = content_.begin(); it != content_.end(); ++it) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
56 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
57 assert(it->second != NULL); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
58 delete it->second; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
59 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
60 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
61 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
62 void Answer(OrthancPluginRestOutput* output, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
63 const std::string& path) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
64 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
65 const std::string mime = Orthanc::EnumerationToString(Orthanc::SystemToolbox::AutodetectMimeType(path)); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
66 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
67 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
68 // Check whether the cache already contains the resource |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
69 boost::shared_lock<boost::shared_mutex> lock(mutex_); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
70 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
71 Content::const_iterator found = content_.find(path); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
72 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
73 if (found != content_.end()) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
74 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
75 assert(found->second != NULL); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
76 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, found->second->c_str(), found->second->size(), mime.c_str()); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
77 return; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
78 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
79 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
80 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
81 // This resource has not been cached yet |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
82 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
83 std::unique_ptr<std::string> item(new std::string); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
84 ReadStaticAsset(*item, path); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
85 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, item->c_str(), item->size(), mime.c_str()); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
86 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
87 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
88 // Store the resource into the cache |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
89 boost::unique_lock<boost::shared_mutex> lock(mutex_); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
90 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
91 if (content_.find(path) == content_.end()) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
92 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
93 content_[path] = item.release(); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
94 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
95 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
96 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
97 }; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
98 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
99 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
100 static ResourcesCache cache_; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
101 static bool hasCreateDicomStl_; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
102 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
103 void ServeFile(OrthancPluginRestOutput* output, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
104 const char* url, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
105 const OrthancPluginHttpRequest* request) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
106 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
107 std::string file = request->groups[0]; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
108 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
109 if (file == "viewer.html") |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
110 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
111 std::string s; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
112 Orthanc::EmbeddedResources::GetFileResource(s, Orthanc::EmbeddedResources::VIEWER_HTML); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
113 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), Orthanc::EnumerationToString(Orthanc::MimeType_Html)); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
114 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
115 else if (file == "viewer.js") |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
116 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
117 std::string s; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
118 Orthanc::EmbeddedResources::GetFileResource(s, Orthanc::EmbeddedResources::VIEWER_JS); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
119 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), Orthanc::EnumerationToString(Orthanc::MimeType_JavaScript)); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
120 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
121 else |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
122 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
123 cache_.Answer(output, file); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
124 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
125 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
126 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
127 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
128 extern "C" |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
129 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
130 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
131 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
132 OrthancPlugins::SetGlobalContext(context); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
133 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
134 /* Check the version of the Orthanc core */ |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
135 if (OrthancPluginCheckVersion(OrthancPlugins::GetGlobalContext()) == 0) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
136 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
137 char info[1024]; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
138 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
139 OrthancPlugins::GetGlobalContext()->orthancVersion, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
140 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
141 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
142 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
143 OrthancPluginLogError(OrthancPlugins::GetGlobalContext(), info); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
144 return -1; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
145 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
146 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
147 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
148 Orthanc::Logging::InitializePluginContext(context); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
149 #else |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
150 Orthanc::Logging::Initialize(context); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
151 #endif |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
152 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
153 hasCreateDicomStl_ = OrthancPlugins::CheckMinimalOrthancVersion(1, 12, 1); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
154 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
155 if (!hasCreateDicomStl_) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
156 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
157 LOG(WARNING) << "Your version of Orthanc (" << std::string(context->orthancVersion) |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
158 << ") is insufficient to create DICOM STL, it should be above 1.12.1"; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
159 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
160 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
161 OrthancPluginSetDescription(context, "STL plugin for Orthanc."); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
162 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
163 OrthancPlugins::RegisterRestCallback<ServeFile>("/stl/(.*)", true); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
164 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
165 // Extend the default Orthanc Explorer with custom JavaScript for STL |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
166 std::string explorer; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
167 Orthanc::EmbeddedResources::GetFileResource(explorer, Orthanc::EmbeddedResources::ORTHANC_EXPLORER); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
168 OrthancPluginExtendOrthancExplorer(OrthancPlugins::GetGlobalContext(), explorer.c_str()); |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
169 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
170 return 0; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
171 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
172 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
173 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
174 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
175 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
176 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
177 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
178 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
179 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
180 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
181 return "stl"; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
182 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
183 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
184 |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
185 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
186 { |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
187 return ORTHANC_STL_VERSION; |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
188 } |
4e889a8e8be2
initial commit of the viewer plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
189 } |