Mercurial > hg > orthanc-stone
comparison Framework/Toolbox/DicomStructurePolygon2.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 | |
children | 29f5f2031310 |
comparison
equal
deleted
inserted
replaced
995:9893fa8cd7a6 | 998:38b6bb0bdd72 |
---|---|
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 #pragma once | |
22 | |
23 #include "CoordinateSystem3D.h" | |
24 #include "DicomStructureSetUtils.h" | |
25 #include "Extent2D.h" | |
26 | |
27 #include "../Scene2D/Color.h" | |
28 #include "../StoneException.h" | |
29 | |
30 #include <Plugins/Samples/Common/FullOrthancDataset.h> | |
31 | |
32 #include <list> | |
33 #include <string> | |
34 | |
35 namespace OrthancStone | |
36 { | |
37 | |
38 /** | |
39 Only polygons that are planar and parallel to either the X,Y or Z plane | |
40 ("X plane" == plane where X is equal to a constant for each point) are | |
41 supported. | |
42 */ | |
43 class DicomStructurePolygon2 | |
44 { | |
45 public: | |
46 enum Type | |
47 { | |
48 ClosedPlanar, | |
49 Unsupported | |
50 }; | |
51 | |
52 DicomStructurePolygon2(std::string referencedSopInstanceUid, const std::string& type) | |
53 : referencedSopInstanceUid_(referencedSopInstanceUid) | |
54 , state_(Building) | |
55 , minX_(std::numeric_limits<double>::max()) | |
56 , maxX_(-std::numeric_limits<double>::max()) | |
57 , minY_(std::numeric_limits<double>::max()) | |
58 , maxY_(-std::numeric_limits<double>::max()) | |
59 , minZ_(std::numeric_limits<double>::max()) | |
60 , maxZ_(-std::numeric_limits<double>::max()) | |
61 , type_(TypeFromString(type)) | |
62 { | |
63 ORTHANC_ASSERT(type_ == ClosedPlanar); | |
64 } | |
65 | |
66 void ComputeDependentProperties(); | |
67 | |
68 size_t GetPointCount() const | |
69 { | |
70 ORTHANC_ASSERT(state_ == Valid); | |
71 return points_.size(); | |
72 } | |
73 | |
74 const Point3D& GetPoint(size_t i) const | |
75 { | |
76 ORTHANC_ASSERT(state_ == Valid); | |
77 return points_.at(i); | |
78 } | |
79 | |
80 void AddPoint(const Point3D& v) | |
81 { | |
82 ORTHANC_ASSERT(state_ == Building); | |
83 points_.push_back(v); | |
84 } | |
85 | |
86 void Reserve(size_t n) | |
87 { | |
88 ORTHANC_ASSERT(state_ == Building); | |
89 points_.reserve(n); | |
90 } | |
91 | |
92 /** | |
93 This method takes a plane+coord system that is parallel to the polygon | |
94 and adds to polygons a new vector with the ordered set of points projected | |
95 on the plane, in the plane coordinate system. | |
96 */ | |
97 void ProjectOnParallelPlane( | |
98 std::vector< std::pair<Point2D,Point2D> >& segments, | |
99 const CoordinateSystem3D& plane) const; | |
100 | |
101 /** | |
102 Returns the coordinates of the intersection of the polygon and a plane | |
103 that is perpendicular to the polygons (plane has either constant X or | |
104 constant Y) | |
105 */ | |
106 void ProjectOnConstantPlane( | |
107 std::vector<Point2D>& intersections, | |
108 const CoordinateSystem3D& plane) const; | |
109 | |
110 /** | |
111 This method assumes polygon has a normal equal to 0,0,-1 and 0,0,1 (thus, | |
112 the polygon is parallel to the XY plane) and returns the Z coordinate of | |
113 all the polygon points | |
114 */ | |
115 double GetZ() const; | |
116 | |
117 /** | |
118 The normal sign is left undefined for now | |
119 */ | |
120 Vector3D GetNormal() const | |
121 { | |
122 return normal_; | |
123 } | |
124 | |
125 /** | |
126 This method will compute the intersection between a polygon and | |
127 a plane where either X, Y or Z is constant. | |
128 The plane is given with an origin and a normal. If the normal is | |
129 not parallel to an axis, an error is raised. | |
130 */ | |
131 void ComputeIntersectionWithPlane(const CoordinateSystem3D& plane); | |
132 | |
133 private: | |
134 static Type TypeFromString(const std::string& s) | |
135 { | |
136 if (s == "CLOSED_PLANAR") | |
137 return ClosedPlanar; | |
138 else | |
139 return Unsupported; | |
140 } | |
141 enum State | |
142 { | |
143 Building, | |
144 Valid | |
145 }; | |
146 std::string referencedSopInstanceUid_; | |
147 CoordinateSystem3D geometry_; | |
148 std::vector<Point3D> points_; | |
149 Vector3D normal_; // sign is irrelevant for now | |
150 State state_; | |
151 double minX_, maxX_, minY_, maxY_, minZ_, maxZ_; | |
152 Type type_; | |
153 }; | |
154 } | |
155 |