comparison OrthancStone/Resources/Graveyard/RTStructTentativeReimplementation-BGO/DicomStructurePolygon2.h @ 1908:affde38b84de

moved tentative bgo reimplementation of rt-struct into graveyard
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 01 Feb 2022 08:38:32 +0100
parents OrthancStone/Sources/Toolbox/DicomStructurePolygon2.h@14c8f339d480
children 07964689cb0b
comparison
equal deleted inserted replaced
1907:0208f99b8bde 1908:affde38b84de
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-2022 Osimis S.A., Belgium
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
7 *
8 * This program is free software: you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>.
21 **/
22
23 #pragma once
24
25 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
26
27 #include "CoordinateSystem3D.h"
28 #include "DicomStructureSetUtils.h"
29 #include "Extent2D.h"
30
31 #include "../Scene2D/Color.h"
32 #include "../StoneException.h"
33
34 #include "OrthancDatasets/FullOrthancDataset.h"
35
36 #include <list>
37 #include <string>
38
39 namespace OrthancStone
40 {
41
42 /**
43 Only polygons that are planar and parallel to either the X,Y or Z plane
44 ("X plane" == plane where X is equal to a constant for each point) are
45 supported.
46 */
47 class DicomStructurePolygon2
48 {
49 public:
50 enum Type
51 {
52 ClosedPlanar,
53 Unsupported
54 };
55
56 DicomStructurePolygon2(std::string referencedSopInstanceUid, const std::string& type)
57 : referencedSopInstanceUid_(referencedSopInstanceUid)
58 , state_(Building)
59 , minX_(std::numeric_limits<double>::max())
60 , maxX_(-std::numeric_limits<double>::max())
61 , minY_(std::numeric_limits<double>::max())
62 , maxY_(-std::numeric_limits<double>::max())
63 , minZ_(std::numeric_limits<double>::max())
64 , maxZ_(-std::numeric_limits<double>::max())
65 , type_(TypeFromString(type))
66 {
67 ORTHANC_ASSERT(type_ == ClosedPlanar);
68 }
69
70 void ComputeDependentProperties();
71
72 size_t GetPointCount() const
73 {
74 ORTHANC_ASSERT(state_ == Valid);
75 return points_.size();
76 }
77
78 const Vector& GetPoint(size_t i) const
79 {
80 ORTHANC_ASSERT(state_ == Valid);
81 return points_.at(i);
82 }
83
84 void AddPoint(const Vector& v)
85 {
86 ORTHANC_ASSERT(state_ == Building);
87 points_.push_back(v);
88 }
89
90 void Reserve(size_t n)
91 {
92 ORTHANC_ASSERT(state_ == Building);
93 points_.reserve(n);
94 }
95
96 /**
97 This method takes a plane+coord system that is parallel to the polygon
98 and adds to polygons a new vector with the ordered set of points projected
99 on the plane, in the plane coordinate system.
100 */
101 void ProjectOnParallelPlane(
102 std::vector< std::pair<ScenePoint2D, ScenePoint2D> >& segments,
103 const CoordinateSystem3D& plane) const;
104
105 /**
106 Returns the coordinates of the intersection of the polygon and a plane
107 that is perpendicular to the polygons (plane has either constant X or
108 constant Y)
109 */
110 void ProjectOnConstantPlane(
111 std::vector<ScenePoint2D>& intersections,
112 const CoordinateSystem3D& plane) const;
113
114 /**
115 This method assumes polygon has a normal equal to 0,0,-1 and 0,0,1 (thus,
116 the polygon is parallel to the XY plane) and returns the Z coordinate of
117 all the polygon points
118 */
119 double GetZ() const;
120
121 /**
122 The normal sign is left undefined for now
123 */
124 Vector GetNormal() const
125 {
126 return normal_;
127 }
128
129 /**
130 This method will compute the intersection between a polygon and
131 a plane where either X, Y or Z is constant.
132 The plane is given with an origin and a normal. If the normal is
133 not parallel to an axis, an error is raised.
134 */
135 void ComputeIntersectionWithPlane(const CoordinateSystem3D& plane);
136
137 private:
138 static Type TypeFromString(const std::string& s)
139 {
140 if (s == "CLOSED_PLANAR")
141 return ClosedPlanar;
142 else
143 return Unsupported;
144 }
145 enum State
146 {
147 Building,
148 Valid
149 };
150 std::string referencedSopInstanceUid_;
151 CoordinateSystem3D geometry_;
152 std::vector<Vector> points_;
153 Vector normal_; // sign is irrelevant for now
154 State state_;
155 double minX_, maxX_, minY_, maxY_, minZ_, maxZ_;
156 Type type_;
157 };
158 }
159
160 #endif
161 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2
162
163