comparison OrthancStone/Sources/Toolbox/DicomStructureSet.h @ 1512:244ad1e4e76a

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 07 Jul 2020 16:21:02 +0200
parents Framework/Toolbox/DicomStructureSet.h@d8af188ab545
children 94750ef63ad5
comparison
equal deleted inserted replaced
1511:9dfeee74c1e6 1512:244ad1e4e76a
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-2020 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 "../OrthancStone.h"
25
26 #if !defined(ORTHANC_ENABLE_DCMTK)
27 # error The macro ORTHANC_ENABLE_DCMTK must be defined
28 #endif
29
30 #include "DicomStructureSetUtils.h"
31 #include "CoordinateSystem3D.h"
32 #include "Extent2D.h"
33 #include "OrthancDatasets/FullOrthancDataset.h"
34 #include "../Scene2D/Color.h"
35 #include "../Scene2D/PolylineSceneLayer.h"
36
37 #if ORTHANC_ENABLE_DCMTK == 1
38 # include <DicomParsing/ParsedDicomFile.h>
39 #endif
40
41 //#define USE_BOOST_UNION_FOR_POLYGONS 1
42
43
44 #include <list>
45
46 namespace OrthancStone
47 {
48 class DicomStructureSet : public boost::noncopyable
49 {
50 private:
51 struct ReferencedSlice
52 {
53 std::string seriesInstanceUid_;
54 CoordinateSystem3D geometry_;
55 double thickness_;
56
57 ReferencedSlice()
58 {
59 }
60
61 ReferencedSlice(const std::string& seriesInstanceUid,
62 const CoordinateSystem3D& geometry,
63 double thickness) :
64 seriesInstanceUid_(seriesInstanceUid),
65 geometry_(geometry),
66 thickness_(thickness)
67 {
68 }
69 };
70
71 typedef std::map<std::string, ReferencedSlice> ReferencedSlices;
72
73 typedef std::vector<Vector> Points;
74
75 class Polygon
76 {
77 private:
78 std::string sopInstanceUid_;
79 bool hasSlice_;
80 CoordinateSystem3D geometry_;
81 double projectionAlongNormal_;
82 double sliceThickness_; // In millimeters
83 Points points_;
84 Extent2D extent_;
85
86 void CheckPointIsOnSlice(const Vector& v) const;
87 bool IsPointOnSliceIfAny(const Vector& v) const;
88
89 public:
90 Polygon(const std::string& sopInstanceUid) :
91 sopInstanceUid_(sopInstanceUid),
92 hasSlice_(false)
93 {
94 }
95
96 void Reserve(size_t n)
97 {
98 points_.reserve(n);
99 }
100
101 void AddPoint(const Vector& v);
102
103 bool UpdateReferencedSlice(const ReferencedSlices& slices);
104
105 bool IsOnSlice(const CoordinateSystem3D& geometry) const;
106
107 const Vector& GetGeometryOrigin() const
108 {
109 return geometry_.GetOrigin();
110 }
111
112 const std::string& GetSopInstanceUid() const
113 {
114 return sopInstanceUid_;
115 }
116
117 const Points& GetPoints() const
118 {
119 return points_;
120 }
121
122 double GetSliceThickness() const
123 {
124 return sliceThickness_;
125 }
126
127 bool Project(double& x1,
128 double& y1,
129 double& x2,
130 double& y2,
131 const CoordinateSystem3D& slice) const;
132 };
133
134 typedef std::list<Polygon> Polygons;
135
136 struct Structure
137 {
138 std::string name_;
139 std::string interpretation_;
140 Polygons polygons_;
141 uint8_t red_;
142 uint8_t green_;
143 uint8_t blue_;
144 };
145
146 typedef std::vector<Structure> Structures;
147
148 Structures structures_;
149 ReferencedSlices referencedSlices_;
150
151 void Setup(const IDicomDataset& dataset);
152
153 const Structure& GetStructure(size_t index) const;
154
155 Structure& GetStructure(size_t index);
156
157 bool ProjectStructure(
158 #if USE_BOOST_UNION_FOR_POLYGONS == 1
159 std::vector< std::vector<Point2D> >& polygons,
160 #else
161 std::vector< std::pair<Point2D, Point2D> >& segments,
162 #endif
163 const Structure& structure,
164 const CoordinateSystem3D& slice) const;
165
166 public:
167 DicomStructureSet(const FullOrthancDataset& instance)
168 {
169 Setup(instance);
170 }
171
172 #if ORTHANC_ENABLE_DCMTK == 1
173 DicomStructureSet(Orthanc::ParsedDicomFile& instance);
174 #endif
175
176 size_t GetStructuresCount() const
177 {
178 return structures_.size();
179 }
180
181 Vector GetStructureCenter(size_t index) const;
182
183 const std::string& GetStructureName(size_t index) const;
184
185 const std::string& GetStructureInterpretation(size_t index) const;
186
187 Color GetStructureColor(size_t index) const;
188
189 // TODO - remove
190 void GetStructureColor(uint8_t& red,
191 uint8_t& green,
192 uint8_t& blue,
193 size_t index) const;
194
195 void GetReferencedInstances(std::set<std::string>& instances);
196
197 void AddReferencedSlice(const std::string& sopInstanceUid,
198 const std::string& seriesInstanceUid,
199 const CoordinateSystem3D& geometry,
200 double thickness);
201
202 void AddReferencedSlice(const Orthanc::DicomMap& dataset);
203
204 void CheckReferencedSlices();
205
206 Vector GetNormal() const;
207
208 #if USE_BOOST_UNION_FOR_POLYGONS == 1
209 bool ProjectStructure(std::vector< std::vector<Point2D> >& polygons,
210 size_t index,
211 const CoordinateSystem3D& slice) const
212 {
213 return ProjectStructure(polygons, GetStructure(index), slice);
214 }
215 #else
216 bool ProjectStructure(std::vector< std::pair<Point2D, Point2D> >& segments,
217 size_t index,
218 const CoordinateSystem3D& slice) const
219 {
220 return ProjectStructure(segments, GetStructure(index), slice);
221 }
222 #endif
223
224 void ProjectOntoLayer(PolylineSceneLayer& layer,
225 const CoordinateSystem3D& plane,
226 size_t structureIndex,
227 const Color& color) const;
228
229 void ProjectOntoLayer(PolylineSceneLayer& layer,
230 const CoordinateSystem3D& plane,
231 size_t structureIndex) const
232 {
233 ProjectOntoLayer(layer, plane, structureIndex, GetStructureColor(structureIndex));
234 }
235 };
236 }