Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/DicomStructureSet.cpp @ 1011:3d4873eccc42
Added tag toa2019092003 for changeset efe1c44628a1
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 20 Sep 2019 12:41:18 +0200 |
parents | 4f28d9459e31 |
children | 53cc787bd7bc |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
439 | 5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 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. | |
0 | 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 | |
47 | 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 | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "DicomStructureSet.h" | |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
23 #include "DicomStructureSetUtils.h" |
0 | 24 |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
25 #include "../Toolbox/GeometryToolbox.h" |
0 | 26 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Core/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
28 #include <Core/OrthancException.h> |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
29 #include <Core/Toolbox.h> |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
30 #include <Plugins/Samples/Common/FullOrthancDataset.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
31 #include <Plugins/Samples/Common/DicomDatasetReader.h> |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
32 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
33 #if defined(_MSC_VER) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
34 #pragma warning(push) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
35 #pragma warning(disable:4244) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
36 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
37 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
38 #include <limits> |
0 | 39 #include <stdio.h> |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
40 #include <boost/geometry.hpp> |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
41 #include <boost/geometry/geometries/point_xy.hpp> |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
42 #include <boost/geometry/geometries/polygon.hpp> |
137 | 43 #include <boost/geometry/multi/geometries/multi_polygon.hpp> |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
44 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
45 #if defined(_MSC_VER) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
46 #pragma warning(pop) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
47 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
48 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
49 typedef boost::geometry::model::d2::point_xy<double> BoostPoint; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
50 typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
51 typedef boost::geometry::model::multi_polygon<BoostPolygon> BoostMultiPolygon; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
52 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
53 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
54 static void Union(BoostMultiPolygon& output, |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
55 std::vector<BoostPolygon>& input) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
56 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
57 for (size_t i = 0; i < input.size(); i++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
58 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
59 boost::geometry::correct(input[i]); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
60 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
61 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
62 if (input.size() == 0) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
63 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
64 output.clear(); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
65 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
66 else if (input.size() == 1) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
67 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
68 output.resize(1); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
69 output[0] = input[0]; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
70 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
71 else |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
72 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
73 boost::geometry::union_(input[0], input[1], output); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
74 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
75 for (size_t i = 0; i < input.size(); i++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
76 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
77 BoostMultiPolygon tmp; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
78 boost::geometry::union_(output, input[i], tmp); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
79 output = tmp; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
80 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
81 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
82 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
83 |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1000
diff
changeset
|
84 #ifdef USE_BOOST_UNION_FOR_POLYGONS |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
85 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
86 static BoostPolygon CreateRectangle(float x1, float y1, |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
87 float x2, float y2) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
88 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
89 BoostPolygon r; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
90 boost::geometry::append(r, BoostPoint(x1, y1)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
91 boost::geometry::append(r, BoostPoint(x1, y2)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
92 boost::geometry::append(r, BoostPoint(x2, y2)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
93 boost::geometry::append(r, BoostPoint(x2, y1)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
94 return r; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
95 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
96 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
97 #else |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
98 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
99 namespace OrthancStone |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
100 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
101 static RtStructRectangleInSlab CreateRectangle(float x1, float y1, |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
102 float x2, float y2) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
103 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
104 RtStructRectangleInSlab rect; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
105 rect.xmin = std::min(x1, x2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
106 rect.xmax = std::max(x1, x2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
107 rect.ymin = std::min(y1, y2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
108 rect.ymax = std::max(y1, y2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
109 return rect; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
110 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
111 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
112 bool CompareRectanglesForProjection(const std::pair<RtStructRectangleInSlab,double>& r1, const std::pair<RtStructRectangleInSlab, double>& r2) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
113 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
114 return r1.second < r2.second; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
115 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
116 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
117 bool CompareSlabsY(const RtStructRectanglesInSlab& r1, const RtStructRectanglesInSlab& r2) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
118 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
119 if ((r1.size() == 0) || (r2.size() == 0)) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
120 return false; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
121 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
122 return r1[0].ymax < r2[0].ymax; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
123 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
124 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
125 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
126 #endif |
0 | 127 |
128 namespace OrthancStone | |
129 { | |
32 | 130 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_GEOMETRIC_TYPE(0x3006, 0x0042); |
131 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_IMAGE_SEQUENCE(0x3006, 0x0016); | |
132 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_SEQUENCE(0x3006, 0x0040); | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
133 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_DATA(0x3006, 0x0050); |
32 | 134 static const OrthancPlugins::DicomTag DICOM_TAG_NUMBER_OF_CONTOUR_POINTS(0x3006, 0x0046); |
135 static const OrthancPlugins::DicomTag DICOM_TAG_REFERENCED_SOP_INSTANCE_UID(0x0008, 0x1155); | |
136 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_CONTOUR_SEQUENCE(0x3006, 0x0039); | |
137 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_DISPLAY_COLOR(0x3006, 0x002a); | |
138 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_NAME(0x3006, 0x0026); | |
139 static const OrthancPlugins::DicomTag DICOM_TAG_RT_ROI_INTERPRETED_TYPE(0x3006, 0x00a4); | |
140 static const OrthancPlugins::DicomTag DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE(0x3006, 0x0080); | |
141 static const OrthancPlugins::DicomTag DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE(0x3006, 0x0020); | |
0 | 142 |
143 | |
144 static uint8_t ConvertColor(double v) | |
145 { | |
146 if (v < 0) | |
147 { | |
148 return 0; | |
149 } | |
150 else if (v >= 255) | |
151 { | |
152 return 255; | |
153 } | |
154 else | |
155 { | |
156 return static_cast<uint8_t>(v); | |
157 } | |
158 } | |
159 | |
160 | |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
161 static bool ParseVector(Vector& target, |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
162 const OrthancPlugins::IDicomDataset& dataset, |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
163 const OrthancPlugins::DicomPath& tag) |
0 | 164 { |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
165 std::string value; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
166 return (dataset.GetStringValue(value, tag) && |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
167 LinearAlgebra::ParseVector(target, value)); |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
168 } |
0 | 169 |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
170 void DicomStructureSet::Polygon::CheckPointIsOnSlice(const Vector& v) const |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
171 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
172 if (hasSlice_) |
0 | 173 { |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
174 double magnitude = |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
175 GeometryToolbox::ProjectAlongNormal(v, geometry_.GetNormal()); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
176 if(!LinearAlgebra::IsNear( |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
177 magnitude, |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
178 projectionAlongNormal_, |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
179 sliceThickness_ / 2.0 /* in mm */ )) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
180 { |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
181 LOG(ERROR) << "This RT-STRUCT contains a point that is off the " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
182 << "slice of its instance | " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
183 << "magnitude = " << magnitude << " | " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
184 << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
185 << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
186 |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
187 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
188 } |
0 | 189 } |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
190 } |
0 | 191 |
988
4c9b4c4de814
Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents:
981
diff
changeset
|
192 bool DicomStructureSet::Polygon::IsPointOnSliceIfAny(const Vector& v) const |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
193 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
194 if (hasSlice_) |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
195 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
196 double magnitude = |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
197 GeometryToolbox::ProjectAlongNormal(v, geometry_.GetNormal()); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
198 bool onSlice = LinearAlgebra::IsNear( |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
199 magnitude, |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
200 projectionAlongNormal_, |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
201 sliceThickness_ / 2.0 /* in mm */); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
202 if (!onSlice) |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
203 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
204 LOG(WARNING) << "This RT-STRUCT contains a point that is off the " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
205 << "slice of its instance | " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
206 << "magnitude = " << magnitude << " | " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
207 << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
208 << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
209 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
210 return onSlice; |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
211 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
212 else |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
213 { |
988
4c9b4c4de814
Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents:
981
diff
changeset
|
214 return true; |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
215 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
216 } |
0 | 217 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
218 void DicomStructureSet::Polygon::AddPoint(const Vector& v) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
219 { |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
220 #if 1 |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
221 // BGO 2019-09-03 |
988
4c9b4c4de814
Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents:
981
diff
changeset
|
222 if (IsPointOnSliceIfAny(v)) |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
223 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
224 points_.push_back(v); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
225 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
226 #else |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
227 CheckPoint(v); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
228 points_.push_back(v); |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
229 #endif |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
230 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
231 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
232 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
233 bool DicomStructureSet::Polygon::UpdateReferencedSlice(const ReferencedSlices& slices) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
234 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
235 if (hasSlice_) |
0 | 236 { |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
237 return true; |
32 | 238 } |
239 else | |
240 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
241 ReferencedSlices::const_iterator it = slices.find(sopInstanceUid_); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
242 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
243 if (it == slices.end()) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
244 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
245 return false; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
246 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
247 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
248 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
249 const CoordinateSystem3D& geometry = it->second.geometry_; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
250 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
251 hasSlice_ = true; |
131 | 252 geometry_ = geometry; |
253 projectionAlongNormal_ = GeometryToolbox::ProjectAlongNormal(geometry.GetOrigin(), geometry.GetNormal()); | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
254 sliceThickness_ = it->second.thickness_; |
0 | 255 |
131 | 256 extent_.Reset(); |
257 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
258 for (Points::const_iterator it = points_.begin(); it != points_.end(); ++it) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
259 { |
988
4c9b4c4de814
Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents:
981
diff
changeset
|
260 if (IsPointOnSliceIfAny(*it)) |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
261 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
262 double x, y; |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
263 geometry.ProjectPoint(x, y, *it); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
264 extent_.AddPoint(x, y); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
265 } |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
266 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
267 return true; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
268 } |
0 | 269 } |
270 } | |
271 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
272 bool DicomStructureSet::Polygon::IsOnSlice(const CoordinateSystem3D& slice) const |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
273 { |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
274 bool isOpposite = false; |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
275 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
276 if (points_.empty() || |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
277 !hasSlice_ || |
131 | 278 !GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), geometry_.GetNormal())) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
279 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
280 return false; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
281 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
282 |
131 | 283 double d = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), geometry_.GetNormal()); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
284 |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
285 return (LinearAlgebra::IsNear(d, projectionAlongNormal_, |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
286 sliceThickness_ / 2.0)); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
287 } |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
288 |
131 | 289 bool DicomStructureSet::Polygon::Project(double& x1, |
290 double& y1, | |
291 double& x2, | |
292 double& y2, | |
293 const CoordinateSystem3D& slice) const | |
294 { | |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
295 // TODO: optimize this method using a sweep-line algorithm for polygons |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
296 |
131 | 297 if (!hasSlice_ || |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
298 points_.size() <= 1) |
131 | 299 { |
300 return false; | |
301 } | |
302 | |
303 double x, y; | |
304 geometry_.ProjectPoint(x, y, slice.GetOrigin()); | |
305 | |
306 bool isOpposite; | |
307 if (GeometryToolbox::IsParallelOrOpposite | |
308 (isOpposite, slice.GetNormal(), geometry_.GetAxisY())) | |
309 { | |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
310 // plane is constant Y |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
311 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
312 if (y < extent_.GetY1() || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
313 y > extent_.GetY2()) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
314 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
315 // The polygon does not intersect the input slice |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
316 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
317 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
318 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
319 bool isFirst = true; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
320 double xmin = std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
321 double xmax = -std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
322 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
323 double prevX, prevY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
324 geometry_.ProjectPoint(prevX, prevY, points_[points_.size() - 1]); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
325 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
326 for (size_t i = 0; i < points_.size(); i++) |
131 | 327 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
328 // Reference: ../../Resources/Computations/IntersectSegmentAndHorizontalLine.py |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
329 double curX, curY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
330 geometry_.ProjectPoint(curX, curY, points_[i]); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
331 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
332 // if prev* and cur* are on opposite sides of y, this means that the |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
333 // segment intersects the plane. |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
334 if ((prevY < y && curY > y) || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
335 (prevY > y && curY < y)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
336 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
337 double p = (curX * prevY - curY * prevX + y * (prevX - curX)) / (prevY - curY); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
338 xmin = std::min(xmin, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
339 xmax = std::max(xmax, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
340 isFirst = false; |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
341 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
342 // xmin and xmax represent the extent of the rectangle along the |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
343 // intersection between the plane and the polygon geometry |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
344 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
345 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
346 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
347 prevX = curX; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
348 prevY = curY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
349 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
350 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
351 // if NO segment intersects the plane |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
352 if (isFirst) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
353 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
354 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
355 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
356 else |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
357 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
358 // y is the plane y coord in the polygon geometry |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
359 // xmin and xmax are ALSO expressed in the polygon geometry |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
360 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
361 // let's convert them to 3D world geometry... |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
362 Vector p1 = (geometry_.MapSliceToWorldCoordinates(xmin, y) + |
131 | 363 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
364 Vector p2 = (geometry_.MapSliceToWorldCoordinates(xmax, y) - |
131 | 365 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
366 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
367 // then to the cutting plane geometry... |
131 | 368 slice.ProjectPoint(x1, y1, p1); |
369 slice.ProjectPoint(x2, y2, p2); | |
370 return true; | |
371 } | |
372 } | |
373 else if (GeometryToolbox::IsParallelOrOpposite | |
374 (isOpposite, slice.GetNormal(), geometry_.GetAxisX())) | |
375 { | |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
376 // plane is constant X |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
377 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
378 /* |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
379 Please read the comments in the section above, by taking into account |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
380 the fact that, in this case, the plane has a constant X, not Y (in |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
381 polygon geometry_ coordinates) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
382 */ |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
383 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
384 if (x < extent_.GetX1() || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
385 x > extent_.GetX2()) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
386 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
387 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
388 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
389 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
390 bool isFirst = true; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
391 double ymin = std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
392 double ymax = -std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
393 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
394 double prevX, prevY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
395 geometry_.ProjectPoint(prevX, prevY, points_[points_.size() - 1]); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
396 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
397 for (size_t i = 0; i < points_.size(); i++) |
131 | 398 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
399 // Reference: ../../Resources/Computations/IntersectSegmentAndVerticalLine.py |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
400 double curX, curY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
401 geometry_.ProjectPoint(curX, curY, points_[i]); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
402 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
403 if ((prevX < x && curX > x) || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
404 (prevX > x && curX < x)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
405 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
406 double p = (curX * prevY - curY * prevX + x * (curY - prevY)) / (curX - prevX); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
407 ymin = std::min(ymin, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
408 ymax = std::max(ymax, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
409 isFirst = false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
410 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
411 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
412 prevX = curX; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
413 prevY = curY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
414 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
415 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
416 if (isFirst) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
417 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
418 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
419 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
420 else |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
421 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
422 Vector p1 = (geometry_.MapSliceToWorldCoordinates(x, ymin) + |
131 | 423 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
424 Vector p2 = (geometry_.MapSliceToWorldCoordinates(x, ymax) - |
131 | 425 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
426 | |
427 slice.ProjectPoint(x1, y1, p1); | |
428 slice.ProjectPoint(x2, y2, p2); | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
429 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
430 // TODO WHY THIS??? |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
431 y1 = -y1; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
432 y2 = -y2; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
433 |
131 | 434 return true; |
435 } | |
436 } | |
437 else | |
438 { | |
439 // Should not happen | |
440 return false; | |
441 } | |
442 } | |
443 | |
444 | |
0 | 445 const DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) const |
446 { | |
447 if (index >= structures_.size()) | |
448 { | |
125 | 449 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
0 | 450 } |
451 | |
452 return structures_[index]; | |
453 } | |
454 | |
455 | |
125 | 456 DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) |
0 | 457 { |
125 | 458 if (index >= structures_.size()) |
459 { | |
460 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
0 | 461 } |
462 | |
463 return structures_[index]; | |
464 } | |
465 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
466 DicomStructureSet::DicomStructureSet(const OrthancPlugins::FullOrthancDataset& tags) |
0 | 467 { |
738
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
468 OrthancPlugins::DicomDatasetReader reader(tags); |
32 | 469 |
470 size_t count, tmp; | |
471 if (!tags.GetSequenceSize(count, DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE) || | |
472 !tags.GetSequenceSize(tmp, DICOM_TAG_ROI_CONTOUR_SEQUENCE) || | |
473 tmp != count || | |
474 !tags.GetSequenceSize(tmp, DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE) || | |
475 tmp != count) | |
0 | 476 { |
477 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
478 } | |
479 | |
32 | 480 structures_.resize(count); |
481 for (size_t i = 0; i < count; i++) | |
482 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
483 structures_[i].interpretation_ = reader.GetStringValue |
738
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
484 (OrthancPlugins::DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE, i, |
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
485 DICOM_TAG_RT_ROI_INTERPRETED_TYPE), |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
486 "No interpretation"); |
0 | 487 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
488 structures_[i].name_ = reader.GetStringValue |
738
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
489 (OrthancPlugins::DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE, i, |
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
490 DICOM_TAG_ROI_NAME), |
949
32eaf4929b08
OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents:
841
diff
changeset
|
491 "No name"); |
0 | 492 |
493 Vector color; | |
738
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
494 if (ParseVector(color, tags, OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
495 DICOM_TAG_ROI_DISPLAY_COLOR)) && |
32 | 496 color.size() == 3) |
0 | 497 { |
32 | 498 structures_[i].red_ = ConvertColor(color[0]); |
499 structures_[i].green_ = ConvertColor(color[1]); | |
500 structures_[i].blue_ = ConvertColor(color[2]); | |
501 } | |
502 else | |
503 { | |
504 structures_[i].red_ = 255; | |
505 structures_[i].green_ = 0; | |
506 structures_[i].blue_ = 0; | |
0 | 507 } |
508 | |
32 | 509 size_t countSlices; |
738
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
510 if (!tags.GetSequenceSize(countSlices, OrthancPlugins::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
8e31b174ab26
removing using namespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
516
diff
changeset
|
511 DICOM_TAG_CONTOUR_SEQUENCE))) |
32 | 512 { |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
513 countSlices = 0; |
32 | 514 } |
0 | 515 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
516 LOG(INFO) << "New RT structure: \"" << structures_[i].name_ |
0 | 517 << "\" with interpretation \"" << structures_[i].interpretation_ |
32 | 518 << "\" containing " << countSlices << " slices (color: " |
0 | 519 << static_cast<int>(structures_[i].red_) << "," |
520 << static_cast<int>(structures_[i].green_) << "," | |
521 << static_cast<int>(structures_[i].blue_) << ")"; | |
522 | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
523 // These temporary variables avoid allocating many vectors in the loop below |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
524 OrthancPlugins::DicomPath countPointsPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
525 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
526 DICOM_TAG_NUMBER_OF_CONTOUR_POINTS); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
527 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
528 OrthancPlugins::DicomPath geometricTypePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
529 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
530 DICOM_TAG_CONTOUR_GEOMETRIC_TYPE); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
531 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
532 OrthancPlugins::DicomPath imageSequencePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
533 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
534 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
535 |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
536 // (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155) |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
537 OrthancPlugins::DicomPath referencedInstancePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
538 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
539 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
540 DICOM_TAG_REFERENCED_SOP_INSTANCE_UID); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
541 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
542 OrthancPlugins::DicomPath contourDataPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
543 DICOM_TAG_CONTOUR_SEQUENCE, 0, |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
544 DICOM_TAG_CONTOUR_DATA); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
545 |
32 | 546 for (size_t j = 0; j < countSlices; j++) |
0 | 547 { |
32 | 548 unsigned int countPoints; |
0 | 549 |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
550 countPointsPath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
551 if (!reader.GetUnsignedIntegerValue(countPoints, countPointsPath)) |
32 | 552 { |
553 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
554 } | |
555 | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
556 //LOG(INFO) << "Parsing slice containing " << countPoints << " vertices"; |
0 | 557 |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
558 geometricTypePath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
559 std::string type = reader.GetMandatoryStringValue(geometricTypePath); |
32 | 560 if (type != "CLOSED_PLANAR") |
0 | 561 { |
173
6b0411ac843a
fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
159
diff
changeset
|
562 LOG(WARNING) << "Ignoring contour with geometry type: " << type; |
6b0411ac843a
fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
159
diff
changeset
|
563 continue; |
0 | 564 } |
565 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
566 size_t size; |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
567 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
568 imageSequencePath.SetPrefixIndex(1, j); |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
569 if (!tags.GetSequenceSize(size, imageSequencePath) || size != 1) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
570 { |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
571 LOG(ERROR) << "The ContourImageSequence sequence (tag 3006,0016) must be present and contain one entry."; |
0 | 572 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
573 } | |
574 | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
575 referencedInstancePath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
576 std::string sopInstanceUid = reader.GetMandatoryStringValue(referencedInstancePath); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
577 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
578 contourDataPath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
579 std::string slicesData = reader.GetMandatoryStringValue(contourDataPath); |
0 | 580 |
581 Vector points; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
582 if (!LinearAlgebra::ParseVector(points, slicesData) || |
32 | 583 points.size() != 3 * countPoints) |
0 | 584 { |
585 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
586 } | |
587 | |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
588 // seen in real world |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
589 if(Orthanc::Toolbox::StripSpaces(sopInstanceUid) == "") |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
590 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
591 LOG(ERROR) << "WARNING. The following Dicom tag (Referenced SOP Instance UID) contains an empty value : // (3006,0039)[" << i << "] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)"; |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
592 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
593 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
594 Polygon polygon(sopInstanceUid); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
595 polygon.Reserve(countPoints); |
0 | 596 |
32 | 597 for (size_t k = 0; k < countPoints; k++) |
0 | 598 { |
599 Vector v(3); | |
600 v[0] = points[3 * k]; | |
601 v[1] = points[3 * k + 1]; | |
602 v[2] = points[3 * k + 2]; | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
603 polygon.AddPoint(v); |
0 | 604 } |
605 | |
606 structures_[i].polygons_.push_back(polygon); | |
607 } | |
608 } | |
609 } | |
610 | |
611 | |
612 Vector DicomStructureSet::GetStructureCenter(size_t index) const | |
613 { | |
614 const Structure& structure = GetStructure(index); | |
615 | |
616 Vector center; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
617 LinearAlgebra::AssignVector(center, 0, 0, 0); |
0 | 618 if (structure.polygons_.empty()) |
619 { | |
620 return center; | |
621 } | |
622 | |
623 double n = static_cast<double>(structure.polygons_.size()); | |
624 | |
625 for (Polygons::const_iterator polygon = structure.polygons_.begin(); | |
626 polygon != structure.polygons_.end(); ++polygon) | |
627 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
628 if (!polygon->GetPoints().empty()) |
0 | 629 { |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
630 center += polygon->GetPoints().front() / n; |
0 | 631 } |
632 } | |
633 | |
634 return center; | |
635 } | |
636 | |
637 | |
638 const std::string& DicomStructureSet::GetStructureName(size_t index) const | |
639 { | |
640 return GetStructure(index).name_; | |
641 } | |
642 | |
643 | |
644 const std::string& DicomStructureSet::GetStructureInterpretation(size_t index) const | |
645 { | |
646 return GetStructure(index).interpretation_; | |
647 } | |
648 | |
649 | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
650 Color DicomStructureSet::GetStructureColor(size_t index) const |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
651 { |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
652 const Structure& s = GetStructure(index); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
653 return Color(s.red_, s.green_, s.blue_); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
654 } |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
655 |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
656 |
0 | 657 void DicomStructureSet::GetStructureColor(uint8_t& red, |
658 uint8_t& green, | |
659 uint8_t& blue, | |
660 size_t index) const | |
661 { | |
662 const Structure& s = GetStructure(index); | |
663 red = s.red_; | |
664 green = s.green_; | |
665 blue = s.blue_; | |
666 } | |
667 | |
668 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
669 void DicomStructureSet::GetReferencedInstances(std::set<std::string>& instances) |
0 | 670 { |
671 for (Structures::const_iterator structure = structures_.begin(); | |
672 structure != structures_.end(); ++structure) | |
673 { | |
674 for (Polygons::const_iterator polygon = structure->polygons_.begin(); | |
675 polygon != structure->polygons_.end(); ++polygon) | |
676 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
677 instances.insert(polygon->GetSopInstanceUid()); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
678 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
679 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
680 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
681 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
682 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
683 void DicomStructureSet::AddReferencedSlice(const std::string& sopInstanceUid, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
684 const std::string& seriesInstanceUid, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
685 const CoordinateSystem3D& geometry, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
686 double thickness) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
687 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
688 if (referencedSlices_.find(sopInstanceUid) != referencedSlices_.end()) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
689 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
690 // This geometry is already known |
956
a7351ad54960
Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents:
949
diff
changeset
|
691 LOG(ERROR) << "DicomStructureSet::AddReferencedSlice(): (referencedSlices_.find(sopInstanceUid) != referencedSlices_.end()). sopInstanceUid = " << sopInstanceUid; |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
692 |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
693 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
694 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
695 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
696 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
697 if (thickness < 0) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
698 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
699 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
700 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
701 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
702 if (!referencedSlices_.empty()) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
703 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
704 const ReferencedSlice& reference = referencedSlices_.begin()->second; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
705 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
706 if (reference.seriesInstanceUid_ != seriesInstanceUid) |
0 | 707 { |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
708 LOG(ERROR) << "This RT-STRUCT refers to several different series"; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
709 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
710 } |
0 | 711 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
712 if (!GeometryToolbox::IsParallel(reference.geometry_.GetNormal(), geometry.GetNormal())) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
713 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
714 LOG(ERROR) << "The slices in this RT-STRUCT are not parallel"; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
715 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
716 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
717 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
718 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
719 referencedSlices_[sopInstanceUid] = ReferencedSlice(seriesInstanceUid, geometry, thickness); |
0 | 720 |
131 | 721 for (Structures::iterator structure = structures_.begin(); |
722 structure != structures_.end(); ++structure) | |
723 { | |
724 for (Polygons::iterator polygon = structure->polygons_.begin(); | |
725 polygon != structure->polygons_.end(); ++polygon) | |
726 { | |
727 polygon->UpdateReferencedSlice(referencedSlices_); | |
728 } | |
729 } | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
730 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
731 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
732 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
733 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
734 void DicomStructureSet::AddReferencedSlice(const Orthanc::DicomMap& dataset) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
735 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
736 CoordinateSystem3D slice(dataset); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
737 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
738 double thickness = 1; // 1 mm by default |
0 | 739 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
740 std::string s; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
741 Vector v; |
994
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
988
diff
changeset
|
742 if (dataset.LookupStringValue(s, Orthanc::DICOM_TAG_SLICE_THICKNESS, false) && |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
743 LinearAlgebra::ParseVector(v, s) && |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
744 v.size() > 0) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
745 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
746 thickness = v[0]; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
747 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
748 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
749 std::string instance, series; |
994
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
988
diff
changeset
|
750 if (dataset.LookupStringValue(instance, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false) && |
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
988
diff
changeset
|
751 dataset.LookupStringValue(series, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false)) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
752 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
753 AddReferencedSlice(instance, series, slice, thickness); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
754 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
755 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
756 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
757 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
758 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
759 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
760 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
761 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
762 void DicomStructureSet::CheckReferencedSlices() |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
763 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
764 for (Structures::iterator structure = structures_.begin(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
765 structure != structures_.end(); ++structure) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
766 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
767 for (Polygons::iterator polygon = structure->polygons_.begin(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
768 polygon != structure->polygons_.end(); ++polygon) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
769 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
770 if (!polygon->UpdateReferencedSlice(referencedSlices_)) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
771 { |
981
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
772 std::string sopInstanceUid = polygon->GetSopInstanceUid(); |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
773 if (Orthanc::Toolbox::StripSpaces(sopInstanceUid) == "") |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
774 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
775 LOG(ERROR) << "DicomStructureSet::CheckReferencedSlices(): " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
776 << " missing information about referenced instance " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
777 << "(sopInstanceUid is empty!)"; |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
778 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
779 else |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
780 { |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
781 LOG(ERROR) << "DicomStructureSet::CheckReferencedSlices(): " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
782 << " missing information about referenced instance " |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
783 << "(sopInstanceUid = " << sopInstanceUid << ")"; |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
784 } |
c20dbaab360c
Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents:
959
diff
changeset
|
785 //throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
0 | 786 } |
787 } | |
788 } | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
789 } |
0 | 790 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
791 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
792 Vector DicomStructureSet::GetNormal() const |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
793 { |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
794 if (referencedSlices_.empty()) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
795 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
796 Vector v; |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
797 LinearAlgebra::AssignVector(v, 0, 0, 1); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
798 return v; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
799 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
800 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
801 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
802 return referencedSlices_.begin()->second.geometry_.GetNormal(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
803 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
804 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
805 |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1000
diff
changeset
|
806 #ifdef USE_BOOST_UNION_FOR_POLYGONS |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
807 bool DicomStructureSet::ProjectStructure(std::vector< std::vector<Point2D> >& polygons, |
794 | 808 const Structure& structure, |
809 const CoordinateSystem3D& slice) const | |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
810 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
811 bool DicomStructureSet::ProjectStructure(std::vector< std::pair<Point2D, Point2D> >& segments, |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
812 const Structure& structure, |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
813 const CoordinateSystem3D& slice) const |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
814 #endif |
125 | 815 { |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1000
diff
changeset
|
816 #ifdef USE_BOOST_UNION_FOR_POLYGONS |
125 | 817 polygons.clear(); |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
818 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
819 segments.clear(); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
820 #endif |
125 | 821 |
822 Vector normal = GetNormal(); | |
823 | |
824 bool isOpposite; | |
825 if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetNormal())) | |
826 { | |
827 // This is an axial projection | |
828 | |
794 | 829 for (Polygons::const_iterator polygon = structure.polygons_.begin(); |
125 | 830 polygon != structure.polygons_.end(); ++polygon) |
831 { | |
832 if (polygon->IsOnSlice(slice)) | |
833 { | |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1000
diff
changeset
|
834 #ifdef USE_BOOST_UNION_FOR_POLYGONS |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
835 polygons.push_back(std::vector<Point2D>()); |
125 | 836 |
837 for (Points::const_iterator p = polygon->GetPoints().begin(); | |
838 p != polygon->GetPoints().end(); ++p) | |
839 { | |
840 double x, y; | |
841 slice.ProjectPoint(x, y, *p); | |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
842 polygons.back().push_back(Point2D(x, y)); |
125 | 843 } |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
844 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
845 // we need to add all the segments corresponding to this polygon |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
846 const std::vector<Vector>& points3D = polygon->GetPoints(); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
847 if (points3D.size() >= 3) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
848 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
849 Point2D prev2D; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
850 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
851 Vector prev = points3D[0]; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
852 double prevX, prevY; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
853 slice.ProjectPoint(prevX, prevY, prev); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
854 prev2D = Point2D(prevX, prevY); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
855 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
856 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
857 size_t pointCount = points3D.size(); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
858 for (size_t ipt = 1; ipt < pointCount; ++ipt) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
859 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
860 Vector next = points3D[ipt]; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
861 double nextX, nextY; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
862 slice.ProjectPoint(nextX, nextY, next); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
863 Point2D next2D(nextX, nextY); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
864 segments.push_back(std::pair<Point2D, Point2D>(prev2D, next2D)); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
865 prev2D = next2D; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
866 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
867 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
868 else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
869 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
870 LOG(ERROR) << "Contour with less than 3 points!"; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
871 // !!! |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
872 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
873 #endif |
125 | 874 } |
875 } | |
876 | |
877 return true; | |
878 } | |
879 else if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisX()) || | |
880 GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisY())) | |
881 { | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
882 #if 1 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
883 // Sagittal or coronal projection |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
884 |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1000
diff
changeset
|
885 #ifdef USE_BOOST_UNION_FOR_POLYGONS |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
886 std::vector<BoostPolygon> projected; |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
887 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
888 // this will contain the intersection of the polygon slab with |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
889 // the cutting plane, projected on the cutting plane coord system |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
890 // (that yields a rectangle) + the Z coordinate of the polygon |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
891 // (this is required to group polygons with the same Z later) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
892 std::vector<std::pair<RtStructRectangleInSlab, double> > projected; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
893 #endif |
794 | 894 for (Polygons::const_iterator polygon = structure.polygons_.begin(); |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
895 polygon != structure.polygons_.end(); ++polygon) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
896 { |
131 | 897 double x1, y1, x2, y2; |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
898 |
131 | 899 if (polygon->Project(x1, y1, x2, y2, slice)) |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
900 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
901 double curZ = polygon->GetGeometryOrigin()[2]; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
902 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
903 // x1,y1 and x2,y2 are in "slice" coordinates (the cutting plane |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
904 // geometry) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
905 projected.push_back(std::make_pair(CreateRectangle( |
516
11fa6f00e33c
Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
906 static_cast<float>(x1), |
11fa6f00e33c
Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
907 static_cast<float>(y1), |
11fa6f00e33c
Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
908 static_cast<float>(x2), |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
909 static_cast<float>(y2)),curZ)); |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
910 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
911 } |
1006
4f28d9459e31
Fixed unit tests and deprecated classes according to last API changes. UT all run ok.
Benjamin Golinvaux <bgo@osimis.io>
parents:
1000
diff
changeset
|
912 #ifndef USE_BOOST_UNION_FOR_POLYGONS |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
913 // projected contains a set of rectangles specified by two opposite |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
914 // corners (x1,y1,x2,y2) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
915 // we need to merge them |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
916 // each slab yields ONE polygon! |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
917 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
918 // we need to sorted all the rectangles that originate from the same Z |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
919 // into lanes. To make sure they are grouped together in the array, we |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
920 // sort it. |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
921 std::sort(projected.begin(), projected.end(), CompareRectanglesForProjection); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
922 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
923 std::vector<RtStructRectanglesInSlab> rectanglesForEachSlab; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
924 rectanglesForEachSlab.reserve(projected.size()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
925 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
926 double curZ = 0; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
927 for (size_t i = 0; i < projected.size(); ++i) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
928 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
929 #if 0 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
930 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
931 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
932 if (i == 0) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
933 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
934 curZ = projected[i].second; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
935 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
936 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
937 else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
938 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
939 // this check is needed to prevent creating a new slab if |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
940 // the new polygon is at the same Z coord than last one |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
941 if (!LinearAlgebra::IsNear(curZ, projected[i].second)) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
942 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
943 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
944 curZ = projected[i].second; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
945 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
946 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
947 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
948 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
949 rectanglesForEachSlab.back().push_back(projected[i].first); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
950 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
951 // as long as they have the same y, we should put them into the same lane |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
952 // BUT in Sebastien's code, there is only one polygon per lane. |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
953 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
954 //std::cout << "rect: xmin = " << rect.xmin << " xmax = " << rect.xmax << " ymin = " << rect.ymin << " ymax = " << rect.ymax << std::endl; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
955 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
956 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
957 // now we need to sort the slabs in increasing Y order (see ConvertListOfSlabsToSegments) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
958 std::sort(rectanglesForEachSlab.begin(), rectanglesForEachSlab.end(), CompareSlabsY); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
959 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
960 ConvertListOfSlabsToSegments(segments, rectanglesForEachSlab, projected.size()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
961 #else |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
962 BoostMultiPolygon merged; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
963 Union(merged, projected); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
964 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
965 polygons.resize(merged.size()); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
966 for (size_t i = 0; i < merged.size(); i++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
967 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
968 const std::vector<BoostPoint>& outer = merged[i].outer(); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
969 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
970 polygons[i].resize(outer.size()); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
971 for (size_t j = 0; j < outer.size(); j++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
972 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
973 polygons[i][j] = Point2D(outer[j].x(), outer[j].y()); |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
974 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
975 } |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
976 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
977 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
978 #else |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
979 for (Polygons::iterator polygon = structure.polygons_.begin(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
980 polygon != structure.polygons_.end(); ++polygon) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
981 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
982 double x1, y1, x2, y2; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
983 if (polygon->Project(x1, y1, x2, y2, slice)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
984 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
985 std::vector<Point2D> p(4); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
986 p[0] = std::make_pair(x1, y1); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
987 p[1] = std::make_pair(x2, y1); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
988 p[2] = std::make_pair(x2, y2); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
989 p[3] = std::make_pair(x1, y2); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
990 polygons.push_back(p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
991 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
992 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
993 #endif |
125 | 994 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
995 return true; |
125 | 996 } |
997 else | |
998 { | |
999 return false; | |
1000 } | |
0 | 1001 } |
1002 } |