Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/DicomStructureSet2.h @ 987:d225bccd4d4a
Scaffolding for A/B tests with DicomStructureSet[Loader] (A/B testing)
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Mon, 09 Sep 2019 15:18:24 +0200 |
parents | |
children | 4c9b4c4de814 |
comparison
equal
deleted
inserted
replaced
986:4e2de6b8a70b | 987:d225bccd4d4a |
---|---|
1 /** | |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU Affero General Public License | |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 **/ | |
20 | |
21 | |
22 #pragma once | |
23 | |
24 #include "CoordinateSystem3D.h" | |
25 #include "Extent2D.h" | |
26 #include "../Scene2D/Color.h" | |
27 | |
28 #include <Plugins/Samples/Common/FullOrthancDataset.h> | |
29 | |
30 #include <list> | |
31 | |
32 namespace OrthancStone | |
33 { | |
34 class DicomStructureSet2 : public boost::noncopyable | |
35 { | |
36 public: | |
37 typedef std::pair<double, double> PolygonPoint2D; | |
38 | |
39 private: | |
40 struct ReferencedSlice | |
41 { | |
42 std::string seriesInstanceUid_; | |
43 CoordinateSystem3D geometry_; | |
44 double thickness_; | |
45 | |
46 ReferencedSlice() | |
47 { | |
48 } | |
49 | |
50 ReferencedSlice(const std::string& seriesInstanceUid, | |
51 const CoordinateSystem3D& geometry, | |
52 double thickness) : | |
53 seriesInstanceUid_(seriesInstanceUid), | |
54 geometry_(geometry), | |
55 thickness_(thickness) | |
56 { | |
57 } | |
58 }; | |
59 | |
60 typedef std::map<std::string, ReferencedSlice> ReferencedSlices; | |
61 | |
62 typedef std::vector<Vector> Points; | |
63 | |
64 class Polygon | |
65 { | |
66 private: | |
67 std::string sopInstanceUid_; | |
68 bool hasSlice_; | |
69 CoordinateSystem3D geometry_; | |
70 double projectionAlongNormal_; | |
71 double sliceThickness_; // In millimeters | |
72 Points points_; | |
73 Extent2D extent_; | |
74 | |
75 void CheckPointIsOnSlice(const Vector& v) const; | |
76 bool IsPointOnSlice(const Vector& v) const; | |
77 | |
78 public: | |
79 Polygon(const std::string& sopInstanceUid) : | |
80 sopInstanceUid_(sopInstanceUid), | |
81 hasSlice_(false) | |
82 { | |
83 } | |
84 | |
85 void Reserve(size_t n) | |
86 { | |
87 points_.reserve(n); | |
88 } | |
89 | |
90 void AddPoint(const Vector& v); | |
91 | |
92 bool UpdateReferencedSlice(const ReferencedSlices& slices); | |
93 | |
94 bool IsOnSlice(const CoordinateSystem3D& geometry) const; | |
95 | |
96 const std::string& GetSopInstanceUid() const | |
97 { | |
98 return sopInstanceUid_; | |
99 } | |
100 | |
101 const Points& GetPoints() const | |
102 { | |
103 return points_; | |
104 } | |
105 | |
106 double GetSliceThickness() const | |
107 { | |
108 return sliceThickness_; | |
109 } | |
110 | |
111 bool Project(double& x1, | |
112 double& y1, | |
113 double& x2, | |
114 double& y2, | |
115 const CoordinateSystem3D& slice) const; | |
116 }; | |
117 | |
118 typedef std::list<Polygon> Polygons; | |
119 | |
120 struct Structure | |
121 { | |
122 std::string name_; | |
123 std::string interpretation_; | |
124 Polygons polygons_; | |
125 uint8_t red_; | |
126 uint8_t green_; | |
127 uint8_t blue_; | |
128 }; | |
129 | |
130 typedef std::vector<Structure> Structures; | |
131 | |
132 Structures structures_; | |
133 ReferencedSlices referencedSlices_; | |
134 | |
135 const Structure& GetStructure(size_t index) const; | |
136 | |
137 Structure& GetStructure(size_t index); | |
138 | |
139 bool ProjectStructure(std::vector< std::vector<PolygonPoint2D> >& polygons, | |
140 const Structure& structure, | |
141 const CoordinateSystem3D& slice) const; | |
142 | |
143 public: | |
144 DicomStructureSet2(const OrthancPlugins::FullOrthancDataset& instance); | |
145 | |
146 size_t GetStructuresCount() const | |
147 { | |
148 return structures_.size(); | |
149 } | |
150 | |
151 Vector GetStructureCenter(size_t index) const; | |
152 | |
153 const std::string& GetStructureName(size_t index) const; | |
154 | |
155 const std::string& GetStructureInterpretation(size_t index) const; | |
156 | |
157 Color GetStructureColor(size_t index) const; | |
158 | |
159 // TODO - remove | |
160 void GetStructureColor(uint8_t& red, | |
161 uint8_t& green, | |
162 uint8_t& blue, | |
163 size_t index) const; | |
164 | |
165 void GetReferencedInstances(std::set<std::string>& instances); | |
166 | |
167 void AddReferencedSlice(const std::string& sopInstanceUid, | |
168 const std::string& seriesInstanceUid, | |
169 const CoordinateSystem3D& geometry, | |
170 double thickness); | |
171 | |
172 void AddReferencedSlice(const Orthanc::DicomMap& dataset); | |
173 | |
174 void CheckReferencedSlices(); | |
175 | |
176 Vector GetNormal() const; | |
177 | |
178 bool ProjectStructure(std::vector< std::vector<PolygonPoint2D> >& polygons, | |
179 size_t index, | |
180 const CoordinateSystem3D& slice) const | |
181 { | |
182 return ProjectStructure(polygons, GetStructure(index), slice); | |
183 } | |
184 }; | |
185 } |