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