Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/DicomStructureSet2.h @ 998:38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
used yet because of limitations in coordinates computing): DicomStructure2,
DicomStructureSet2, DicomStructurePolygon2, DicomStructureSetSlicer2. Too
many shortcuts have been taken when computing the actual position.
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 20 Sep 2019 11:58:00 +0200 |
parents | 4c9b4c4de814 |
children | 29f5f2031310 |
comparison
equal
deleted
inserted
replaced
995:9893fa8cd7a6 | 998:38b6bb0bdd72 |
---|---|
16 * | 16 * |
17 * You should have received a copy of the GNU Affero General Public License | 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/>. | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | 19 **/ |
20 | 20 |
21 | |
22 #pragma once | 21 #pragma once |
23 | 22 |
23 #include "DicomStructure2.h" | |
24 #include "CoordinateSystem3D.h" | 24 #include "CoordinateSystem3D.h" |
25 #include "Extent2D.h" | 25 #include "Extent2D.h" |
26 #include "../Scene2D/Color.h" | 26 #include "../Scene2D/Color.h" |
27 | 27 |
28 #include <Plugins/Samples/Common/FullOrthancDataset.h> | 28 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
29 | 29 |
30 #include <list> | 30 #include <list> |
31 | 31 |
32 namespace OrthancStone | 32 namespace OrthancStone |
33 { | 33 { |
34 class DicomStructureSet2 : public boost::noncopyable | 34 class DicomStructureSet2 : public boost::noncopyable |
35 { | 35 { |
36 public: | 36 public: |
37 typedef std::pair<double, double> PolygonPoint2D; | 37 DicomStructureSet2(); |
38 | 38 ~DicomStructureSet2(); |
39 private: | 39 |
40 struct ReferencedSlice | 40 void SetContents(const OrthancPlugins::FullOrthancDataset& tags); |
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 IsPointOnSliceIfAny(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 | 41 |
146 size_t GetStructuresCount() const | 42 size_t GetStructuresCount() const |
147 { | 43 { |
148 return structures_.size(); | 44 return structures_.size(); |
149 } | 45 } |
150 | 46 |
151 Vector GetStructureCenter(size_t index) const; | 47 void Clear(); |
152 | 48 |
153 const std::string& GetStructureName(size_t index) const; | 49 const DicomStructure2& GetStructure(size_t i) const |
50 { | |
51 // at() is like []() but with range check | |
52 return structures_.at(i); | |
53 } | |
154 | 54 |
155 const std::string& GetStructureInterpretation(size_t index) const; | 55 /** Internal use only */ |
56 void FillStructuresFromDataset(const OrthancPlugins::FullOrthancDataset& tags); | |
156 | 57 |
157 Color GetStructureColor(size_t index) const; | 58 /** Internal use only */ |
59 void ComputeDependentProperties(); | |
158 | 60 |
159 // TODO - remove | 61 /** Internal use only */ |
160 void GetStructureColor(uint8_t& red, | 62 std::vector<DicomStructure2> structures_; |
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 }; | 63 }; |
185 } | 64 } |