annotate OrthancStone/Resources/Graveyard/RTStructTentativeReimplementation-BGO/DicomStructurePolygon2.cpp @ 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.cpp@14c8f339d480
children 07964689cb0b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
1 /**
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
2 * Stone of Orthanc
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
7 *
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
11 * the License, or (at your option) any later version.
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
12 *
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
16 * Lesser General Public License for more details.
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
20 * <http://www.gnu.org/licenses/>.
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
21 **/
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
22
1019
29f5f2031310 Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents: 1018
diff changeset
23 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2
29f5f2031310 Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents: 1018
diff changeset
24
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
25 #include "DicomStructurePolygon2.h"
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
26
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
27 #include "../Toolbox/LinearAlgebra.h"
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
28
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
29 #include <Logging.h>
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1739
diff changeset
30
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
31 namespace OrthancStone
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
32 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
33 void DicomStructurePolygon2::ComputeDependentProperties()
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
34 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
35 ORTHANC_ASSERT(state_ == Building);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
36
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
37 for (size_t j = 0; j < points_.size(); ++j)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
38 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
39 // TODO: move to AddPoint!
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
40 const Vector& p = points_[j];
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
41 if (p[0] < minX_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
42 minX_ = p[0];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
43 if (p[0] > maxX_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
44 maxX_ = p[0];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
45
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
46 if (p[1] < minY_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
47 minY_ = p[1];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
48 if (p[1] > maxY_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
49 maxY_ = p[1];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
50
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
51 if (p[2] < minZ_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
52 minZ_ = p[2];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
53 if (p[2] > maxZ_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
54 maxZ_ = p[2];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
55 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
56
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
57 if (LinearAlgebra::IsNear(minX_, maxX_))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
58 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
59 LinearAlgebra::AssignVector(normal_, 1, 0, 0);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
60 //ORTHANC_ASSERT(!LinearAlgebra::IsNear(minX, maxX));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
61 ORTHANC_ASSERT(!LinearAlgebra::IsNear(minY_, maxY_));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
62 ORTHANC_ASSERT(!LinearAlgebra::IsNear(minZ_, maxZ_));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
63 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
64 else if (LinearAlgebra::IsNear(minY_, maxY_))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
65 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
66 LinearAlgebra::AssignVector(normal_, 0, 1, 0);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
67 ORTHANC_ASSERT(!LinearAlgebra::IsNear(minX_, maxX_));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
68 ORTHANC_ASSERT(!LinearAlgebra::IsNear(minZ_, maxZ_));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
69 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
70 else if (LinearAlgebra::IsNear(minZ_, maxZ_))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
71 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
72 LinearAlgebra::AssignVector(normal_, 0, 0, 1);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
73 ORTHANC_ASSERT(!LinearAlgebra::IsNear(minX_, maxX_));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
74 ORTHANC_ASSERT(!LinearAlgebra::IsNear(minY_, maxY_));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
75 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
76 else
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
77 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
78 LOG(ERROR) << "The contour is not coplanar and not parallel to any axis.";
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
80 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
81 state_ = Valid;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
82 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
83
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
84
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
85 void DicomStructurePolygon2::ProjectOnConstantPlane(
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
86 std::vector<ScenePoint2D>& intersections, const CoordinateSystem3D& plane) const
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
87 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
88 // the plane can either have constant X, or constant Y.
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
89 // - for constant Z planes, use the ProjectOnParallelPlane method
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
90 // - other type of planes are not supported
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
91
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
92 // V is the coordinate that is constant in the plane
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
93 double planeV = 0.0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
94
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
95 // if true, then "u" in the code is "x" and "v" is "y".
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
96 // (v is constant in the plane)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
97 bool uvxy = false;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
98
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
99 size_t uindex = static_cast<size_t>(-1);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
100 size_t vindex = static_cast<size_t>(-1);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
101
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
102 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[2], 0.0));
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
103
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
104 if (LinearAlgebra::IsNear(plane.GetNormal()[1], 0.0))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
105 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
106 // normal is 1,0,0 (or -1,0,0).
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
107 // plane is constant X
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
108 uindex = 1;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
109 vindex = 0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
110
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
111 uvxy = false;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
112 planeV = plane.GetOrigin()[0];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
113 if (planeV < minX_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
114 return;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
115 if (planeV > maxX_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
116 return;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
117 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
118 else if (LinearAlgebra::IsNear(plane.GetNormal()[0], 0.0))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
119 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
120 // normal is 0,1,0 (or 0,-1,0).
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
121 // plane is constant Y
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
122 uindex = 0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
123 vindex = 1;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
124
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
125 uvxy = true;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
126 planeV = plane.GetOrigin()[1];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
127 if (planeV < minY_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
128 return;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
129 if (planeV > maxY_)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
130 return;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
131 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
132 else
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
133 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
134 // if the following assertion(s) fail(s), it means the plane is NOT a constant-X or constant-Y plane
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
135 LOG(ERROR) << "Plane normal must be (a,0,0) or (0,a,0), with a == -1 or a == 1";
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
136 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
137 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
138
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
139 size_t pointCount = GetPointCount();
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
140 if (pointCount >= 3)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
141 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
142 // this vector will contain the coordinates of the intersection points
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
143 // between the plane and the polygon.
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
144 // these are expressed in the U coordinate, that is either X or Y,
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
145 // depending upon the plane orientation
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
146 std::vector<double> uIntersections;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
147
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
148 // we loop on the segments of the polygon (TODO: optimize)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
149 // and we compute the intersection between each segment and the cut
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
150 // cutting plane (slice) has a constant X
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
151
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
152 for (size_t iPoint = 0; iPoint < pointCount; ++iPoint)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
153 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
154 double u1 = points_[iPoint][uindex];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
155 double v1 = points_[iPoint][vindex];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
156
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
157 double u2 = 0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
158 double v2 = 0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
159
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
160 if (iPoint < pointCount - 1)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
161 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
162 u2 = points_[iPoint + 1][uindex];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
163 v2 = points_[iPoint + 1][vindex];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
164 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
165 else
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
166 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
167 u2 = points_[0][uindex];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
168 v2 = points_[0][vindex];
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
169 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
170
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
171 // Check if the segment intersects the plane
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
172 if ((std::min(v1, v2) <= planeV) && (std::max(v1, v2) >= planeV))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
173 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
174 // special case: the segment is parallel to the plane but close to it
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
175 if (LinearAlgebra::IsNear(v1, v2))
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
176 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
177 // in that case, we choose to label both points as an intersection
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
178 double x, y;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
179 plane.ProjectPoint(x, y, points_[iPoint]);
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
180 intersections.push_back(ScenePoint2D(x, y));
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
181
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
182 plane.ProjectPoint(x, y, points_[iPoint + 1]);
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
183 intersections.push_back(ScenePoint2D(x, y));
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
184 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
185 else
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
186 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
187 // we are looking for u so that (u,planeV) belongs to the segment
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
188 // let's define alpha = (u-u2)/(u1-u2) --> u = alpha*(u1-u2) + u2
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
189 // alpha = (v2-planeV)/(v2-v1)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
190 // because the following two triangles are similar
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
191 // [ (planeY,x) , (y2,x2), (planeY,x2) ] or
1463
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
192 // [ (planeX,y) , (x2,y2), (planeX,y2) ]
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
193 // and
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
194 // [ (y1 ,x1) , (y2,x2), (y1 ,x2) ] or
1463
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
195 // [ (x1 ,y1) , (x2,y2), (x1 ,y2) ]
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
196
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
197 /*
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
198 void CoordinateSystem3D::ProjectPoint(double& offsetX,
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
199 double& offsetY,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
200 const Vector& point) const
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
201 */
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
202 double alpha = (v2 - planeV) / (v2 - v1);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
203
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
204 // get rid of numerical oddities
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
205 if (alpha < 0.0)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
206 alpha = 0.0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
207 if (alpha > 1.0)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
208 alpha = 1.0;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
209 double u = alpha * (u1 - u2) + u2;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
210
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
211 // here is the intersection in world coordinates
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
212 Vector intersection;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
213 if(uvxy)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
214 LinearAlgebra::AssignVector(intersection, u, planeV, minZ_);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
215 else
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
216 LinearAlgebra::AssignVector(intersection, planeV, u, minZ_);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
217
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
218 // and we convert it to plane coordinates
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
219 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
220 double xi, yi;
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
221 plane.ProjectPoint(xi, yi, intersection);
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
222
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
223 // we consider that the x axis is always parallel to the polygons
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
224 // TODO: is this hypothesis safe??????
1463
182bf3106ee2 dos2unix
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1270
diff changeset
225 uIntersections.insert(std::lower_bound(uIntersections.begin(), uIntersections.end(), xi), xi);
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
226 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
227 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
228 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
229 } // end of for (size_t iPoint = 0; iPoint < pointCount; ++iPoint)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
230
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
231 // now we convert the intersections to plane points
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
232 // we consider that the x axis is always parallel to the polygons
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
233 // TODO: same hypothesis as above: plane is perpendicular to polygons,
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
234 // plane is parallel to the XZ (constant Y) or YZ (constant X) 3D planes
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
235 for (size_t i = 0; i < uIntersections.size(); ++i)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
236 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
237 double x = uIntersections[i];
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
238 intersections.push_back(ScenePoint2D(x, minZ_));
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
239 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
240 } // end of if (pointCount >= 3)
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
241 else
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
242 {
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
243 LOG(ERROR) << "This polygon has " << pointCount << " vertices, which is less than 3 --> skipping";
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
244 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
245 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
246
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
247 void DicomStructurePolygon2::ProjectOnParallelPlane(
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
248 std::vector< std::pair<ScenePoint2D, ScenePoint2D> >& segments,
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
249 const CoordinateSystem3D& plane) const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
250 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
251 if (points_.size() < 3)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
252 return;
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
253
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
254 // the plane is horizontal
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
255 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[0], 0.0));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
256 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[1], 0.0));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
257
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
258 segments.clear();
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
259 segments.reserve(points_.size());
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
260 // since the returned values need to be expressed in the supplied coordinate
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
261 // system, we need to subtract origin_ from the returned points
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
262
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
263 double planeOriginX = plane.GetOrigin()[0];
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
264 double planeOriginY = plane.GetOrigin()[1];
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
265
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
266 // precondition: points_.size() >= 3
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
267 for (size_t j = 0; j < points_.size()-1; ++j)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
268 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
269 // segment between point j and j+1
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
270
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
271 const Vector& point0 = GetPoint(j);
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
272 // subtract plane origin x and y
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
273 ScenePoint2D p0(point0[0] - planeOriginX, point0[1] - planeOriginY);
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
274
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
275 const Vector& point1 = GetPoint(j+1);
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
276 // subtract plane origin x and y
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
277 ScenePoint2D p1(point1[0] - planeOriginX, point1[1] - planeOriginY);
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
278
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
279 segments.push_back(std::pair<ScenePoint2D, ScenePoint2D>(p0,p1));
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
280 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
281
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
282
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
283 // final segment
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
284
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
285 const Vector& point0 = GetPoint(points_.size() - 1);
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
286 // subtract plane origin x and y
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
287 ScenePoint2D p0(point0[0] - planeOriginX, point0[1] - planeOriginY);
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
288
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
289 const Vector& point1 = GetPoint(0);
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
290 // subtract plane origin x and y
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
291 ScenePoint2D p1(point1[0] - planeOriginX, point1[1] - planeOriginY);
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
292
1895
14c8f339d480 removed redundant definitions Point2D, Point3D and Vector3D from DicomStructureSetUtils.h
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
293 segments.push_back(std::pair<ScenePoint2D, ScenePoint2D>(p0, p1));
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
294 }
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
295
1641
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
296 double DicomStructurePolygon2::GetZ() const
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
297 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
298 ORTHANC_ASSERT(LinearAlgebra::IsNear(normal_[0], 0.0));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
299 ORTHANC_ASSERT(LinearAlgebra::IsNear(normal_[1], 0.0));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
300 ORTHANC_ASSERT(LinearAlgebra::IsNear(minZ_, maxZ_));
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
301 return minZ_;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
302 }
998
38b6bb0bdd72 added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff changeset
303 }
1019
29f5f2031310 Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents: 1018
diff changeset
304
29f5f2031310 Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents: 1018
diff changeset
305 #endif
29f5f2031310 Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents: 1018
diff changeset
306 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2
29f5f2031310 Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents: 1018
diff changeset
307