Mercurial > hg > orthanc-stone
annotate RenderingPlugin/Sources/Plugin.cpp @ 2146:743fa9c74443 dicom-sr tip
integration mainline->dicom-sr
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 16 Aug 2024 18:09:53 +0200 |
parents | 16c01cc201e7 |
children |
rev | line source |
---|---|
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1 /** |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
2 * Stone of Orthanc |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
2124
16c01cc201e7
updated copyright, as Osimis is not active on Orthanc anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2114
diff
changeset
|
5 * Copyright (C) 2017-2023 Osimis S.A., Belgium |
2114
c23eef785569
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
2077
diff
changeset
|
6 * Copyright (C) 2021-2024 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
7 * |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
8 * This program is free software: you can redistribute it and/or |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
9 * modify it under the terms of the GNU General Public License as |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
10 * published by the Free Software Foundation, either version 3 of the |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
11 * License, or (at your option) any later version. |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
12 * |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
13 * This program is distributed in the hope that it will be useful, but |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
14 * WITHOUT ANY WARRANTY; without even the implied warranty of |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
16 * General Public License for more details. |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
17 * |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
18 * You should have received a copy of the GNU General Public License |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
20 **/ |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
21 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
22 |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
23 #include "OrthancPluginConnection.h" |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
24 #include "../Resources/Orthanc/Plugins/OrthancPluginCppWrapper.h" |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
25 |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
26 #include "../../OrthancStone/Sources/Toolbox/AffineTransform2D.h" |
1883
fba6e550e0ee
apply rescale slope/intercept in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1882
diff
changeset
|
27 #include "../../OrthancStone/Sources/Toolbox/DicomInstanceParameters.h" |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
28 #include "../../OrthancStone/Sources/Toolbox/DicomStructureSet.h" |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
29 |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
30 #include <Cache/MemoryObjectCache.h> |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
31 #include <Images/Image.h> |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
32 #include <Images/ImageProcessing.h> |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
33 #include <Images/NumpyWriter.h> |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
34 #include <Logging.h> |
1884
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
35 #include <SerializationToolbox.h> |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
36 #include <Toolbox.h> |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
37 |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
38 #include <boost/math/constants/constants.hpp> |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
39 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
40 |
1916 | 41 static const char* const INSTANCES = "Instances"; |
42 static const char* const RT_STRUCT_IOD = "1.2.840.10008.5.1.4.1.1.481.3"; | |
43 static const char* const SOP_CLASS_UID = "0008,0016"; | |
44 static const char* const STRUCTURES = "Structures"; | |
45 | |
46 | |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
47 class DicomStructureCache : public boost::noncopyable |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
48 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
49 private: |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
50 class Item : public Orthanc::ICacheable |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
51 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
52 private: |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
53 std::unique_ptr<OrthancStone::DicomStructureSet> rtstruct_; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
54 |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
55 public: |
1957 | 56 explicit Item(OrthancStone::DicomStructureSet* rtstruct) : |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
57 rtstruct_(rtstruct) |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
58 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
59 if (rtstruct == NULL) |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
60 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
61 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
62 } |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
63 } |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
64 |
1957 | 65 virtual size_t GetMemoryUsage() const ORTHANC_OVERRIDE |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
66 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
67 return 1; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
68 } |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
69 |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
70 OrthancStone::DicomStructureSet& GetRtStruct() const |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
71 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
72 return *rtstruct_; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
73 } |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
74 }; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
75 |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
76 Orthanc::MemoryObjectCache cache_; |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
77 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
78 DicomStructureCache() // Singleton design pattern |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
79 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
80 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
81 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
82 public: |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
83 void Invalidate(const std::string& instanceId) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
84 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
85 cache_.Invalidate(instanceId); |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
86 } |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
87 |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
88 void SetMaximumNumberOfItems(size_t items) |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
89 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
90 cache_.SetMaximumSize(items); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
91 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
92 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
93 static DicomStructureCache& GetSingleton() |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
94 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
95 static DicomStructureCache instance; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
96 return instance; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
97 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
98 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
99 class Accessor : public boost::noncopyable |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
100 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
101 private: |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
102 DicomStructureCache& that_; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
103 std::string instanceId_; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
104 Orthanc::MemoryObjectCache::Accessor lock_; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
105 std::unique_ptr<OrthancStone::DicomStructureSet> notCached_; |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
106 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
107 public: |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
108 Accessor(DicomStructureCache& that, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
109 const std::string& instanceId) : |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
110 that_(that), |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
111 instanceId_(instanceId), |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
112 lock_(that.cache_, instanceId, true /* unique, as "GetRtStruct()" is mutable */) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
113 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
114 if (!lock_.IsValid()) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
115 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
116 OrthancStone::OrthancPluginConnection connection; |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
117 OrthancStone::FullOrthancDataset dataset(connection, "/instances/" + instanceId + "/tags?ignore-length=3006-0050"); |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
118 notCached_.reset(new OrthancStone::DicomStructureSet(dataset)); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
119 } |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
120 } |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
121 |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
122 ~Accessor() |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
123 { |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
124 if (!lock_.IsValid()) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
125 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
126 assert(notCached_.get() != NULL); |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
127 |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
128 try |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
129 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
130 that_.cache_.Acquire(instanceId_, new Item(notCached_.release())); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
131 } |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
132 catch (Orthanc::OrthancException& e) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
133 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
134 LOG(ERROR) << "Cannot insert RT-STRUCT into cache: " << e.What(); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
135 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
136 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
137 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
138 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
139 const std::string& GetInstanceId() const |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
140 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
141 return instanceId_; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
142 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
143 |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
144 OrthancStone::DicomStructureSet& GetRtStruct() const |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
145 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
146 if (lock_.IsValid()) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
147 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
148 return dynamic_cast<Item&>(lock_.GetValue()).GetRtStruct(); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
149 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
150 else |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
151 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
152 assert(notCached_.get() != NULL); |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
153 return *notCached_; |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
154 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
155 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
156 }; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
157 }; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
158 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
159 |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
160 static Orthanc::PixelFormat Convert(OrthancPluginPixelFormat format) |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
161 { |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
162 switch (format) |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
163 { |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
164 case OrthancPluginPixelFormat_RGB24: |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
165 return Orthanc::PixelFormat_RGB24; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
166 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
167 case OrthancPluginPixelFormat_Grayscale8: |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
168 return Orthanc::PixelFormat_Grayscale8; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
169 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
170 case OrthancPluginPixelFormat_Grayscale16: |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
171 return Orthanc::PixelFormat_Grayscale16; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
172 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
173 case OrthancPluginPixelFormat_SignedGrayscale16: |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
174 return Orthanc::PixelFormat_SignedGrayscale16; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
175 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
176 default: |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
177 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
178 } |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
179 } |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
180 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
181 |
1884
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
182 static bool ParseBoolean(const std::string& key, |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
183 const std::string& value) |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
184 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
185 bool result; |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
186 |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
187 if (Orthanc::SerializationToolbox::ParseBoolean(result, value)) |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
188 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
189 return result; |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
190 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
191 else |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
192 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
193 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
194 "Bad value for " + key + ": " + value); |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
195 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
196 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
197 |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
198 |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
199 static double ParseDouble(const std::string& key, |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
200 const std::string& value) |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
201 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
202 double result; |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
203 |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
204 if (Orthanc::SerializationToolbox::ParseDouble(result, value)) |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
205 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
206 return result; |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
207 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
208 else |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
209 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
210 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
211 "Bad value for " + key + ": " + value); |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
212 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
213 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
214 |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
215 |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
216 static unsigned int ParseUnsignedInteger(const std::string& key, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
217 const std::string& value) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
218 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
219 uint32_t result; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
220 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
221 if (Orthanc::SerializationToolbox::ParseUnsignedInteger32(result, value)) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
222 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
223 return result; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
224 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
225 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
226 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
227 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
228 "Bad value for " + key + ": " + value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
229 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
230 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
231 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
232 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
233 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
234 class DataAugmentationParameters : public boost::noncopyable |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
235 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
236 private: |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
237 double angleRadians_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
238 double scaling_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
239 double offsetX_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
240 double offsetY_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
241 bool flipX_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
242 bool flipY_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
243 bool hasResize_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
244 unsigned int targetWidth_; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
245 unsigned int targetHeight_; |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
246 bool hasInterpolation_; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
247 OrthancStone::ImageInterpolation interpolation_; |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
248 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
249 void ApplyInternal(Orthanc::ImageAccessor& target, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
250 const Orthanc::ImageAccessor& source) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
251 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
252 if (source.GetWidth() == 0 || |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
253 source.GetHeight() == 0) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
254 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
255 Orthanc::ImageProcessing::Set(target, 0); // Clear the image |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
256 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
257 else if (target.GetWidth() == 0 || |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
258 target.GetHeight() == 0) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
259 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
260 // Nothing to do |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
261 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
262 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
263 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
264 OrthancStone::AffineTransform2D transform = ComputeTransform(source.GetWidth(), source.GetHeight()); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
265 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
266 OrthancStone::ImageInterpolation interpolation; |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
267 |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
268 if (hasInterpolation_) |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
269 { |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
270 interpolation = interpolation_; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
271 } |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
272 else if (source.GetFormat() == Orthanc::PixelFormat_RGB24) |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
273 { |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
274 // Bilinear interpolation for color images is not implemented yet |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
275 interpolation = OrthancStone::ImageInterpolation_Nearest; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
276 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
277 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
278 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
279 interpolation = OrthancStone::ImageInterpolation_Bilinear; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
280 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
281 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
282 transform.Apply(target, source, interpolation, true /* clear */); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
283 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
284 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
285 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
286 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
287 Orthanc::ImageAccessor* ApplyUnchecked(const Orthanc::ImageAccessor& source) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
288 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
289 std::unique_ptr<Orthanc::ImageAccessor> target; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
290 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
291 if (hasResize_) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
292 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
293 target.reset(new Orthanc::Image(source.GetFormat(), targetWidth_, targetHeight_, false)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
294 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
295 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
296 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
297 target.reset(new Orthanc::Image(source.GetFormat(), source.GetWidth(), source.GetHeight(), false)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
298 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
299 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
300 ApplyInternal(*target, source); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
301 return target.release(); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
302 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
303 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
304 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
305 public: |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
306 DataAugmentationParameters() |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
307 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
308 Clear(); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
309 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
310 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
311 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
312 void Clear() |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
313 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
314 angleRadians_ = 0; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
315 scaling_ = 1; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
316 offsetX_ = 0; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
317 offsetY_ = 0; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
318 flipX_ = false; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
319 flipY_ = false; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
320 hasResize_ = false; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
321 targetWidth_ = 0; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
322 targetHeight_ = 0; |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
323 hasInterpolation_ = false; |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
324 interpolation_ = OrthancStone::ImageInterpolation_Nearest; |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
325 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
326 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
327 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
328 OrthancStone::AffineTransform2D ComputeTransform(unsigned int sourceWidth, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
329 unsigned int sourceHeight) const |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
330 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
331 unsigned int w = (hasResize_ ? targetWidth_ : sourceWidth); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
332 unsigned int h = (hasResize_ ? targetHeight_ : sourceHeight); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
333 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
334 if (w == 0 || |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
335 h == 0 || |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
336 sourceWidth == 0 || |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
337 sourceHeight == 0) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
338 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
339 // Division by zero |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
340 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
341 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
342 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
343 double r = std::min(static_cast<double>(w) / static_cast<double>(sourceWidth), |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
344 static_cast<double>(h) / static_cast<double>(sourceHeight)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
345 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
346 OrthancStone::AffineTransform2D resize = OrthancStone::AffineTransform2D::Combine( |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
347 OrthancStone::AffineTransform2D::CreateOffset(static_cast<double>(w) / 2.0, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
348 static_cast<double>(h) / 2.0), |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
349 OrthancStone::AffineTransform2D::CreateScaling(r, r)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
350 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
351 OrthancStone::AffineTransform2D dataAugmentation = OrthancStone::AffineTransform2D::Combine( |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
352 OrthancStone::AffineTransform2D::CreateScaling(scaling_, scaling_), |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
353 OrthancStone::AffineTransform2D::CreateOffset(offsetX_, offsetY_), |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
354 OrthancStone::AffineTransform2D::CreateRotation(angleRadians_), |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
355 OrthancStone::AffineTransform2D::CreateOffset(-static_cast<double>(sourceWidth) / 2.0, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
356 -static_cast<double>(sourceHeight) / 2.0), |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
357 OrthancStone::AffineTransform2D::CreateFlip(flipX_, flipY_, sourceWidth, sourceHeight)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
358 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
359 return OrthancStone::AffineTransform2D::Combine(resize, dataAugmentation); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
360 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
361 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
362 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
363 bool ParseParameter(const std::string& key, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
364 const std::string& value) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
365 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
366 if (key == "angle") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
367 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
368 double angle = ParseDouble(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
369 angleRadians_ = angle / 180.0 * boost::math::constants::pi<double>(); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
370 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
371 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
372 else if (key == "scaling") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
373 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
374 scaling_ = ParseDouble(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
375 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
376 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
377 else if (key == "offset-x") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
378 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
379 offsetX_ = ParseDouble(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
380 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
381 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
382 else if (key == "offset-y") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
383 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
384 offsetY_ = ParseDouble(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
385 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
386 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
387 else if (key == "flip-x") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
388 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
389 flipX_ = ParseBoolean(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
390 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
391 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
392 else if (key == "flip-y") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
393 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
394 flipY_ = ParseBoolean(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
395 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
396 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
397 else if (key == "resize") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
398 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
399 std::vector<std::string> tokens; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
400 Orthanc::Toolbox::TokenizeString(tokens, value, ','); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
401 if (tokens.size() != 2) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
402 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
403 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
404 "Must provide two integers separated by commas in " + key + ": " + value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
405 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
406 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
407 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
408 targetWidth_ = ParseUnsignedInteger(key, tokens[0]); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
409 targetHeight_ = ParseUnsignedInteger(key, tokens[1]); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
410 hasResize_ = true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
411 return true; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
412 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
413 } |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
414 else if (key == "interpolation") |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
415 { |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
416 if (value == "nearest") |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
417 { |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
418 interpolation_ = OrthancStone::ImageInterpolation_Nearest; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
419 } |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
420 else if (value == "bilinear") |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
421 { |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
422 interpolation_ = OrthancStone::ImageInterpolation_Bilinear; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
423 } |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
424 else |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
425 { |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
426 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange, |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
427 "Unknown interpolation (must be \"nearest\" or \"bilinear\"): " + value); |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
428 } |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
429 |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
430 hasInterpolation_ = true; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
431 return true; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
432 } |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
433 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
434 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
435 return false; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
436 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
437 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
438 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
439 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
440 Orthanc::ImageAccessor* Apply(const Orthanc::ImageAccessor& source) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
441 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
442 if (source.GetFormat() != Orthanc::PixelFormat_RGB24 && |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
443 source.GetFormat() != Orthanc::PixelFormat_Float32) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
444 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
445 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
446 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
447 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
448 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
449 return ApplyUnchecked(source); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
450 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
451 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
452 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
453 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
454 Orthanc::ImageAccessor* ApplyBinaryMask(const Orthanc::ImageAccessor& source) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
455 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
456 if (source.GetFormat() != Orthanc::PixelFormat_Grayscale8) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
457 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
458 throw Orthanc::OrthancException(Orthanc::ErrorCode_IncompatibleImageFormat, |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
459 "A segmentation mask should be a grayscale image"); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
460 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
461 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
462 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
463 std::unique_ptr<Orthanc::ImageAccessor> target(ApplyUnchecked(source)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
464 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
465 const unsigned int h = target->GetHeight(); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
466 const unsigned int w = target->GetWidth(); |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
467 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
468 // Apply thresholding to get back a binary image |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
469 for (unsigned int y = 0; y < h; y++) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
470 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
471 uint8_t* p = reinterpret_cast<uint8_t*>(target->GetRow(y)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
472 for (unsigned int x = 0; x < w; x++, p++) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
473 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
474 if (*p < 128) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
475 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
476 *p = 0; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
477 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
478 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
479 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
480 *p = 255; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
481 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
482 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
483 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
484 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
485 return target.release(); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
486 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
487 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
488 }; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
489 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
490 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
491 static OrthancStone::DicomInstanceParameters* GetInstanceParameters(const std::string& orthancId) |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
492 { |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
493 OrthancPlugins::MemoryBuffer tags; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
494 if (!tags.RestApiGet("/instances/" + orthancId + "/tags", false)) |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
495 { |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
496 throw Orthanc::OrthancException(Orthanc::ErrorCode_InexistentItem); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
497 } |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
498 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
499 Json::Value json; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
500 tags.ToJson(json); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
501 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
502 Orthanc::DicomMap m; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
503 m.FromDicomAsJson(json); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
504 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
505 return new OrthancStone::DicomInstanceParameters(m); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
506 } |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
507 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
508 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
509 static void AnswerNumpyImage(OrthancPluginRestOutput* output, |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
510 const Orthanc::ImageAccessor& image, |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
511 bool compress) |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
512 { |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
513 std::string answer; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
514 Orthanc::NumpyWriter writer; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
515 writer.SetCompressed(compress); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
516 Orthanc::IImageWriter::WriteToMemory(writer, answer, image); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
517 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
518 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
519 answer.c_str(), answer.size(), "application/octet-stream"); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
520 } |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
521 |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
522 |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
523 static void RenderNumpyFrame(OrthancPluginRestOutput* output, |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
524 const char* url, |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
525 const OrthancPluginHttpRequest* request) |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
526 { |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
527 DataAugmentationParameters dataAugmentation; |
1884
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
528 bool compress = false; |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
529 |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
530 for (uint32_t i = 0; i < request->getCount; i++) |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
531 { |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
532 std::string key(request->getKeys[i]); |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
533 std::string value(request->getValues[i]); |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
534 |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
535 if (!dataAugmentation.ParseParameter(key, value)) |
1884
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
536 { |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
537 if (key == "compress") |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
538 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
539 compress = ParseBoolean(key, value); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
540 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
541 else |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
542 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
543 LOG(WARNING) << "Unsupported option for data augmentation: " << key; |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
544 } |
1884
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
545 } |
0c6923982fdd
rendering options from GET args
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1883
diff
changeset
|
546 } |
1883
fba6e550e0ee
apply rescale slope/intercept in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1882
diff
changeset
|
547 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
548 std::unique_ptr<OrthancStone::DicomInstanceParameters> parameters(GetInstanceParameters(request->groups[0])); |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
549 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
550 OrthancPlugins::MemoryBuffer dicom; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
551 dicom.GetDicomInstance(request->groups[0]); |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
552 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
553 unsigned int frame = boost::lexical_cast<unsigned int>(request->groups[1]); |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
554 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
555 OrthancPlugins::OrthancImage image; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
556 image.DecodeDicomImage(dicom.GetData(), dicom.GetSize(), frame); |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
557 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
558 Orthanc::ImageAccessor source; |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
559 source.AssignReadOnly(Convert(image.GetPixelFormat()), image.GetWidth(), image.GetHeight(), |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
560 image.GetPitch(), image.GetBuffer()); |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
561 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
562 std::unique_ptr<Orthanc::ImageAccessor> modified; |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
563 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
564 if (parameters->GetSopClassUid() == OrthancStone::SopClassUid_DicomSeg) |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
565 { |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
566 modified.reset(dataAugmentation.ApplyBinaryMask(source)); |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
567 } |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
568 else if (source.GetFormat() == Orthanc::PixelFormat_RGB24) |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
569 { |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
570 modified.reset(dataAugmentation.Apply(source)); |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
571 } |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
572 else |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
573 { |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
574 std::unique_ptr<Orthanc::ImageAccessor> converted(parameters->ConvertToFloat(source)); |
1883
fba6e550e0ee
apply rescale slope/intercept in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1882
diff
changeset
|
575 assert(converted.get() != NULL); |
1887
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
576 |
aa4ed1cf4e8d
refactoring using DataAugmentationParameters
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1886
diff
changeset
|
577 modified.reset(dataAugmentation.Apply(*converted)); |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
578 } |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
579 |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
580 assert(modified.get() != NULL); |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
581 AnswerNumpyImage(output, *modified, compress); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
582 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
583 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
584 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
585 static bool IsRtStruct(const std::string& instanceId) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
586 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
587 std::string s; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
588 if (OrthancPlugins::RestApiGetString(s, "/instances/" + instanceId + "/content/" + SOP_CLASS_UID, false) && |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
589 !s.empty()) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
590 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
591 if (s[s.size() - 1] == '\0') // Deal with DICOM padding |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
592 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
593 s.resize(s.size() - 1); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
594 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
595 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
596 return s == RT_STRUCT_IOD; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
597 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
598 else |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
599 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
600 return false; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
601 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
602 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
603 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
604 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
605 static void ListRtStruct(OrthancPluginRestOutput* output, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
606 const char* url, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
607 const OrthancPluginHttpRequest* request) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
608 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
609 // This is a quick version of "/tools/find" on "SOPClassUID" (the |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
610 // latter would load all the DICOM files from disk) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
611 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
612 Json::Value series; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
613 OrthancPlugins::RestApiGet(series, "/series?expand", false); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
614 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
615 if (series.type() != Json::arrayValue) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
616 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
617 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
618 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
619 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
620 Json::Value answer = Json::arrayValue; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
621 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
622 for (Json::Value::ArrayIndex i = 0; i < series.size(); i++) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
623 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
624 if (series[i].type() != Json::objectValue || |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
625 !series[i].isMember(INSTANCES) || |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
626 series[i][INSTANCES].type() != Json::arrayValue) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
627 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
628 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
629 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
630 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
631 const Json::Value& instances = series[i][INSTANCES]; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
632 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
633 for (Json::Value::ArrayIndex j = 0; j < instances.size(); j++) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
634 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
635 if (instances[j].type() != Json::stringValue) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
636 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
637 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
638 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
639 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
640 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
641 if (instances.size() > 0 && |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
642 IsRtStruct(instances[0].asString())) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
643 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
644 for (Json::Value::ArrayIndex j = 0; j < instances.size(); j++) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
645 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
646 answer.append(instances[j].asString()); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
647 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
648 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
649 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
650 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
651 std::string s = answer.toStyledString(); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
652 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json"); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
653 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
654 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
655 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
656 static void GetRtStruct(OrthancPluginRestOutput* output, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
657 const char* url, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
658 const OrthancPluginHttpRequest* request) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
659 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
660 DicomStructureCache::Accessor accessor(DicomStructureCache::GetSingleton(), request->groups[0]); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
661 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
662 Json::Value answer; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
663 answer[STRUCTURES] = Json::arrayValue; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
664 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
665 for (size_t i = 0; i < accessor.GetRtStruct().GetStructuresCount(); i++) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
666 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
667 Json::Value color = Json::arrayValue; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
668 color.append(accessor.GetRtStruct().GetStructureColor(i).GetRed()); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
669 color.append(accessor.GetRtStruct().GetStructureColor(i).GetGreen()); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
670 color.append(accessor.GetRtStruct().GetStructureColor(i).GetBlue()); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
671 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
672 Json::Value structure; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
673 structure["Name"] = accessor.GetRtStruct().GetStructureName(i); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
674 structure["Interpretation"] = accessor.GetRtStruct().GetStructureInterpretation(i); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
675 structure["Color"] = color; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
676 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
677 answer[STRUCTURES].append(structure); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
678 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
679 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
680 std::set<std::string> sopInstanceUids; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
681 accessor.GetRtStruct().GetReferencedInstances(sopInstanceUids); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
682 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
683 answer[INSTANCES] = Json::arrayValue; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
684 for (std::set<std::string>::const_iterator it = sopInstanceUids.begin(); it != sopInstanceUids.end(); ++it) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
685 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
686 OrthancPlugins::OrthancString s; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
687 s.Assign(OrthancPluginLookupInstance(OrthancPlugins::GetGlobalContext(), it->c_str())); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
688 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
689 std::string t; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
690 s.ToString(t); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
691 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
692 answer[INSTANCES].append(t); |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
693 } |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
694 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
695 std::string s = answer.toStyledString(); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
696 OrthancPluginAnswerBuffer(OrthancPlugins::GetGlobalContext(), output, s.c_str(), s.size(), "application/json"); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
697 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
698 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
699 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
700 |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
701 static void RenderRtStruct(OrthancPluginRestOutput* output, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
702 const char* url, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
703 const OrthancPluginHttpRequest* request) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
704 { |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
705 class XorFiller : public Orthanc::ImageProcessing::IPolygonFiller |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
706 { |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
707 private: |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
708 Orthanc::Image image_; |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
709 |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
710 public: |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
711 XorFiller(unsigned int width, |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
712 unsigned int height) : |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
713 image_(Orthanc::PixelFormat_Grayscale8, width, height, false) |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
714 { |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
715 Orthanc::ImageProcessing::Set(image_, 0); |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
716 } |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
717 |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
718 Orthanc::ImageAccessor& GetImage() |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
719 { |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
720 return image_; |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
721 } |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
722 |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
723 virtual void Fill(int y, |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
724 int x1, |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
725 int x2) ORTHANC_OVERRIDE |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
726 { |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
727 assert(x1 <= x2); |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
728 |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
729 if (y >= 0 && |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
730 y < static_cast<int>(image_.GetHeight())) |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
731 { |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
732 x1 = std::max(x1, 0); |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
733 x2 = std::min(x2, static_cast<int>(image_.GetWidth()) - 1); |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
734 |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
735 uint8_t* p = reinterpret_cast<uint8_t*>(image_.GetRow(y)) + x1; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
736 |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
737 for (int i = x1; i <= x2; i++, p++) |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
738 { |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
739 *p = (*p ^ 0xff); |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
740 } |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
741 } |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
742 } |
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
743 }; |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
744 |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
745 |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
746 class HorizontalSegment |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
747 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
748 private: |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
749 int y_; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
750 int x1_; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
751 int x2_; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
752 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
753 public: |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
754 HorizontalSegment(int y, |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
755 int x1, |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
756 int x2) : |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
757 y_(y), |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
758 x1_(std::min(x1, x2)), |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
759 x2_(std::max(x1, x2)) |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
760 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
761 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
762 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
763 int GetY() const |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
764 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
765 return y_; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
766 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
767 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
768 int GetX1() const |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
769 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
770 return x1_; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
771 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
772 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
773 int GetX2() const |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
774 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
775 return x2_; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
776 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
777 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
778 void Fill(Orthanc::ImageAccessor& image) const |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
779 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
780 assert(x1_ <= x2_); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
781 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
782 if (y_ >= 0 && |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
783 y_ < static_cast<int>(image.GetHeight())) |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
784 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
785 int a = std::max(x1_, 0); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
786 int b = std::min(x2_, static_cast<int>(image.GetWidth()) - 1); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
787 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
788 uint8_t* p = reinterpret_cast<uint8_t*>(image.GetRow(y_)) + a; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
789 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
790 for (int i = a; i <= b; i++, p++) |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
791 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
792 *p = 0xff; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
793 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
794 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
795 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
796 }; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
797 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
798 |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
799 DataAugmentationParameters dataAugmentation; |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
800 std::vector<std::string> structureNames; |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
801 std::string instanceId; |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
802 bool compress = false; |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
803 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
804 for (uint32_t i = 0; i < request->getCount; i++) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
805 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
806 std::string key(request->getKeys[i]); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
807 std::string value(request->getValues[i]); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
808 |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
809 if (!dataAugmentation.ParseParameter(key, value)) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
810 { |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
811 if (key == "structure") |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
812 { |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
813 Orthanc::Toolbox::TokenizeString(structureNames, value, ','); |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
814 } |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
815 else if (key == "instance") |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
816 { |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
817 instanceId = value; |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
818 } |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
819 else if (key == "compress") |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
820 { |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
821 compress = ParseBoolean(key, value); |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
822 } |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
823 else |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
824 { |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
825 LOG(WARNING) << "Unsupported option: " << key; |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
826 } |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
827 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
828 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
829 |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
830 if (structureNames.empty()) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
831 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
832 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
833 "Missing option \"structure\" to provide the names of the structures of interest"); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
834 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
835 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
836 if (instanceId.empty()) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
837 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
838 throw Orthanc::OrthancException(Orthanc::ErrorCode_NetworkProtocol, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
839 "Missing option \"instance\" to provide the Orthanc identifier of the instance of interest"); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
840 } |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
841 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
842 std::unique_ptr<OrthancStone::DicomInstanceParameters> parameters(GetInstanceParameters(instanceId)); |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
843 |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
844 typedef std::list< std::vector<OrthancStone::Vector> > Polygons; |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
845 |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
846 Polygons polygons; |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
847 |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
848 { |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
849 DicomStructureCache::Accessor accessor(DicomStructureCache::GetSingleton(), request->groups[0]); |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
850 |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
851 for (size_t i = 0; i < structureNames.size(); i++) |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
852 { |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
853 size_t structureIndex; |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
854 if (accessor.GetRtStruct().LookupStructureName(structureIndex, structureNames[i])) |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
855 { |
1945
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
856 Polygons p; |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
857 accessor.GetRtStruct().GetStructurePoints(p, structureIndex, parameters->GetSopInstanceUid()); |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
858 polygons.splice(polygons.begin(), p); |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
859 } |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
860 else |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
861 { |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
862 LOG(WARNING) << "Missing structure name \"" << structureNames[i] |
98952be6fb97
rendering plugin: rendering of multiple structures
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1944
diff
changeset
|
863 << "\" in RT-STRUCT: " << parameters->GetSopInstanceUid(); |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
864 } |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
865 } |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
866 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
867 |
1895
14c8f339d480
removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1894
diff
changeset
|
868 // We use a "XOR" filler for the polygons in order to deal with holes in the RT-STRUCT |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
869 XorFiller filler(parameters->GetWidth(), parameters->GetHeight()); |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
870 OrthancStone::AffineTransform2D transform = dataAugmentation.ComputeTransform(parameters->GetWidth(), parameters->GetHeight()); |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
871 |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
872 std::list<HorizontalSegment> horizontalSegments; |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
873 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
874 for (std::list< std::vector<OrthancStone::Vector> >::const_iterator |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
875 it = polygons.begin(); it != polygons.end(); ++it) |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
876 { |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
877 std::vector<Orthanc::ImageProcessing::ImagePoint> points; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
878 points.reserve(it->size()); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
879 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
880 for (size_t i = 0; i < it->size(); i++) |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
881 { |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
882 // The (0.5, 0.5) offset is due to the fact that DICOM |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
883 // coordinates are expressed wrt. the CENTER of the voxels |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
884 |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
885 double x, y; |
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
886 parameters->GetGeometry().ProjectPoint(x, y, (*it) [i]); |
1943
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
887 x = x / parameters->GetPixelSpacingX() + 0.5; |
a601b8abc1cb
rendering plugin: subpixel accuracy in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1916
diff
changeset
|
888 y = y / parameters->GetPixelSpacingY() + 0.5; |
1889
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
889 |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
890 transform.Apply(x, y); |
fe4befc9c2b0
rendering of rt-struct in plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1888
diff
changeset
|
891 |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
892 points.push_back(Orthanc::ImageProcessing::ImagePoint(std::floor(x), std::floor(y))); |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
893 } |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
894 |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
895 Orthanc::ImageProcessing::FillPolygon(filler, points); |
1888
9bdce2c91620
start rendering rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1887
diff
changeset
|
896 |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
897 for (size_t i = 0; i < points.size(); i++) |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
898 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
899 size_t next = (i + 1) % points.size(); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
900 if (points[i].GetY() == points[next].GetY()) |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
901 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
902 horizontalSegments.push_back(HorizontalSegment(points[i].GetY(), points[i].GetX(), points[next].GetX())); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
903 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
904 } |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
905 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
906 |
1946
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
907 /** |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
908 * We repeat the filling of the horizontal segments. This is |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
909 * important to deal with horizontal edges that are seen in one |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
910 * direction, then in the reverse direction within the same polygon, |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
911 * which can typically be seen in RT-STRUCT with holes. If this step |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
912 * is not done, only the starting point and the ending point of the |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
913 * segments are drawn. |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
914 **/ |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
915 for (std::list<HorizontalSegment>::const_iterator it = horizontalSegments.begin(); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
916 it != horizontalSegments.end(); ++it) |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
917 { |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
918 it->Fill(filler.GetImage()); |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
919 } |
3c68cdfbdcab
rendering plugin: deal with special case of holes in structs
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1945
diff
changeset
|
920 |
1894
438071a29f77
xor polygon filler for holes in rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1892
diff
changeset
|
921 AnswerNumpyImage(output, filler.GetImage(), compress); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
922 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
923 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
924 |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
925 |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
926 OrthancPluginErrorCode OnChangeCallback(OrthancPluginChangeType changeType, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
927 OrthancPluginResourceType resourceType, |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
928 const char* resourceId) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
929 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
930 switch (changeType) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
931 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
932 case OrthancPluginChangeType_Deleted: |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
933 if (resourceType == OrthancPluginResourceType_Instance) |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
934 { |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
935 DicomStructureCache::GetSingleton().Invalidate(resourceId); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
936 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
937 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
938 break; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
939 |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
940 case OrthancPluginChangeType_OrthancStarted: |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
941 { |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
942 DicomStructureCache::Accessor accessor(DicomStructureCache::GetSingleton(), "54460695-ba3885ee-ddf61ac0-f028e31d-a6e474d9"); |
1892
cdf91ad891a5
estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1890
diff
changeset
|
943 OrthancStone::LinearAlgebra::Print(accessor.GetRtStruct().GetEstimatedNormal()); |
cdf91ad891a5
estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1890
diff
changeset
|
944 printf("Slice thickness: %f\n", accessor.GetRtStruct().GetEstimatedSliceThickness()); |
1890
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
945 break; |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
946 } |
6ce81914f7e4
added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1889
diff
changeset
|
947 |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
948 default: |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
949 break; |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
950 } |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
951 |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
952 return OrthancPluginErrorCode_Success; |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
953 } |
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
954 |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
955 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
956 extern "C" |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
957 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
958 ORTHANC_PLUGINS_API int32_t OrthancPluginInitialize(OrthancPluginContext* context) |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
959 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
960 OrthancPlugins::SetGlobalContext(context); |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
961 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
962 #if ORTHANC_FRAMEWORK_VERSION_IS_ABOVE(1, 7, 2) |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
963 Orthanc::Logging::InitializePluginContext(context); |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
964 #else |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
965 Orthanc::Logging::Initialize(context); |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
966 #endif |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
967 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
968 /* Check the version of the Orthanc core */ |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
969 if (OrthancPluginCheckVersion(context) == 0) |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
970 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
971 char info[1024]; |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
972 sprintf(info, "Your version of Orthanc (%s) must be above %d.%d.%d to run this plugin", |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
973 context->orthancVersion, |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
974 ORTHANC_PLUGINS_MINIMAL_MAJOR_NUMBER, |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
975 ORTHANC_PLUGINS_MINIMAL_MINOR_NUMBER, |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
976 ORTHANC_PLUGINS_MINIMAL_REVISION_NUMBER); |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
977 OrthancPluginLogError(context, info); |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
978 return -1; |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
979 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
980 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
981 try |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
982 { |
1944
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
983 DicomStructureCache::GetSingleton().SetMaximumNumberOfItems(1024); // Cache up to 1024 RT-STRUCT instances |
3daecfa5791c
rendering plugin: caching multiple rt-struct in memory
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1943
diff
changeset
|
984 |
1882
4e80b8afd0da
numpy in rendering plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1877
diff
changeset
|
985 OrthancPlugins::RegisterRestCallback<RenderNumpyFrame>("/stone/instances/([^/]+)/frames/([0-9]+)/numpy", true); |
1885
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
986 OrthancPlugins::RegisterRestCallback<ListRtStruct>("/stone/rt-struct", true); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
987 OrthancPlugins::RegisterRestCallback<GetRtStruct>("/stone/rt-struct/([^/]+)/info", true); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
988 OrthancPlugins::RegisterRestCallback<RenderRtStruct>("/stone/rt-struct/([^/]+)/numpy", true); |
ddaee6b96501
retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1884
diff
changeset
|
989 OrthancPluginRegisterOnChangeCallback(context, OnChangeCallback); |
1877
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
990 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
991 catch (...) |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
992 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
993 OrthancPlugins::LogError("Exception while initializing the Stone Web viewer plugin"); |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
994 return -1; |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
995 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
996 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
997 return 0; |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
998 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
999 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1000 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1001 ORTHANC_PLUGINS_API void OrthancPluginFinalize() |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1002 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1003 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1004 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1005 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1006 ORTHANC_PLUGINS_API const char* OrthancPluginGetName() |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1007 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1008 return PLUGIN_NAME; |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1009 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1010 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1011 |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1012 ORTHANC_PLUGINS_API const char* OrthancPluginGetVersion() |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1013 { |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1014 return PLUGIN_VERSION; |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1015 } |
a2955abe4c2e
skeleton for the RenderingPlugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff
changeset
|
1016 } |