Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Toolbox/DicomStructureSet.cpp @ 1592:0d4b11ba86df
fix
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 23 Oct 2020 15:15:32 +0200 |
parents | 85e117739eca |
children | 4fb8fdf03314 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
5 * Copyright (C) 2017-2020 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" |
1504 | 26 #include "OrthancDatasets/DicomDatasetReader.h" |
0 | 27 |
1455
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
28 #include <Logging.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
29 #include <OrthancException.h> |
30deba7bc8e2
simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1279
diff
changeset
|
30 #include <Toolbox.h> |
113
2eca030792aa
using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
110
diff
changeset
|
31 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
32 #if defined(_MSC_VER) |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
33 # pragma warning(push) |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
34 # pragma warning(disable:4244) |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
35 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
36 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
37 #include <limits> |
0 | 38 #include <stdio.h> |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
39 #include <boost/geometry.hpp> |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
40 #include <boost/geometry/geometries/point_xy.hpp> |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
41 #include <boost/geometry/geometries/polygon.hpp> |
137 | 42 #include <boost/geometry/multi/geometries/multi_polygon.hpp> |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
43 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
44 #if defined(_MSC_VER) |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
45 # pragma warning(pop) |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
46 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
47 |
1180
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
48 #if ORTHANC_ENABLE_DCMTK == 1 |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
49 # include "ParsedDicomDataset.h" |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
50 #endif |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
51 |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
52 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
53 typedef boost::geometry::model::d2::point_xy<double> BoostPoint; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
54 typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
55 typedef boost::geometry::model::multi_polygon<BoostPolygon> BoostMultiPolygon; |
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 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
58 static void Union(BoostMultiPolygon& output, |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
59 std::vector<BoostPolygon>& input) |
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 for (size_t i = 0; i < input.size(); i++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
62 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
63 boost::geometry::correct(input[i]); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
64 } |
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 if (input.size() == 0) |
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.clear(); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
69 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
70 else if (input.size() == 1) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
71 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
72 output.resize(1); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
73 output[0] = input[0]; |
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 else |
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 boost::geometry::union_(input[0], input[1], output); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
78 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
79 for (size_t i = 0; i < input.size(); i++) |
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 BoostMultiPolygon tmp; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
82 boost::geometry::union_(output, input[i], tmp); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
83 output = tmp; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
84 } |
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 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
87 |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
88 #if USE_BOOST_UNION_FOR_POLYGONS == 1 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
89 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
90 static BoostPolygon CreateRectangle(float x1, float y1, |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
91 float x2, float y2) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
92 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
93 BoostPolygon r; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
94 boost::geometry::append(r, BoostPoint(x1, y1)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
95 boost::geometry::append(r, BoostPoint(x1, y2)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
96 boost::geometry::append(r, BoostPoint(x2, y2)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
97 boost::geometry::append(r, BoostPoint(x2, y1)); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
98 return r; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
99 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
100 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
101 #else |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
102 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
103 namespace OrthancStone |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
104 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
105 static RtStructRectangleInSlab CreateRectangle(float x1, float y1, |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
106 float x2, float y2) |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
107 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
108 RtStructRectangleInSlab rect; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
109 rect.xmin = std::min(x1, x2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
110 rect.xmax = std::max(x1, x2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
111 rect.ymin = std::min(y1, y2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
112 rect.ymax = std::max(y1, y2); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
113 return rect; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
114 } |
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 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
|
117 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
118 return r1.second < r2.second; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
119 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
120 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
121 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
|
122 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
123 if ((r1.size() == 0) || (r2.size() == 0)) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
124 return false; |
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 return r1[0].ymax < r2[0].ymax; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
127 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
128 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
129 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
130 #endif |
0 | 131 |
132 namespace OrthancStone | |
133 { | |
1504 | 134 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_GEOMETRIC_TYPE(0x3006, 0x0042); |
135 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_IMAGE_SEQUENCE(0x3006, 0x0016); | |
136 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_SEQUENCE(0x3006, 0x0040); | |
137 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_DATA(0x3006, 0x0050); | |
138 static const Orthanc::DicomTag DICOM_TAG_NUMBER_OF_CONTOUR_POINTS(0x3006, 0x0046); | |
139 static const Orthanc::DicomTag DICOM_TAG_REFERENCED_SOP_INSTANCE_UID(0x0008, 0x1155); | |
140 static const Orthanc::DicomTag DICOM_TAG_ROI_CONTOUR_SEQUENCE(0x3006, 0x0039); | |
141 static const Orthanc::DicomTag DICOM_TAG_ROI_DISPLAY_COLOR(0x3006, 0x002a); | |
142 static const Orthanc::DicomTag DICOM_TAG_ROI_NAME(0x3006, 0x0026); | |
143 static const Orthanc::DicomTag DICOM_TAG_RT_ROI_INTERPRETED_TYPE(0x3006, 0x00a4); | |
144 static const Orthanc::DicomTag DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE(0x3006, 0x0080); | |
145 static const Orthanc::DicomTag DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE(0x3006, 0x0020); | |
0 | 146 |
147 | |
148 static uint8_t ConvertColor(double v) | |
149 { | |
150 if (v < 0) | |
151 { | |
152 return 0; | |
153 } | |
154 else if (v >= 255) | |
155 { | |
156 return 255; | |
157 } | |
158 else | |
159 { | |
160 return static_cast<uint8_t>(v); | |
161 } | |
162 } | |
163 | |
164 | |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
165 static bool ParseVector(Vector& target, |
1504 | 166 const IDicomDataset& dataset, |
167 const DicomPath& tag) | |
0 | 168 { |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
169 std::string value; |
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
170 return (dataset.GetStringValue(value, tag) && |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
171 LinearAlgebra::ParseVector(target, value)); |
118
a4d0b6c82b29
using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
113
diff
changeset
|
172 } |
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 void DicomStructureSet::Polygon::CheckPointIsOnSlice(const Vector& v) const |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
175 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
176 if (hasSlice_) |
0 | 177 { |
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
|
178 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
|
179 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
|
180 if(!LinearAlgebra::IsNear( |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
181 magnitude, |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
182 projectionAlongNormal_, |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
183 sliceThickness_ / 2.0 /* in mm */ )) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
184 { |
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
|
185 LOG(ERROR) << "This RT-STRUCT contains a point that is off the " |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
186 << "slice of its instance | " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
187 << "magnitude = " << magnitude << " | " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
188 << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
189 << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0); |
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
|
190 |
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
|
191 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
192 } |
0 | 193 } |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
194 } |
0 | 195 |
988
4c9b4c4de814
Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents:
981
diff
changeset
|
196 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
|
197 { |
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 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
|
199 { |
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 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 { |
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 LOG(WARNING) << "This RT-STRUCT contains a point that is off the " |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
209 << "slice of its instance | " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
210 << "magnitude = " << magnitude << " | " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
211 << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
212 << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0); |
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
|
213 } |
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
|
214 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
|
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 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
|
217 { |
988
4c9b4c4de814
Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents:
981
diff
changeset
|
218 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
|
219 } |
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 } |
0 | 221 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
222 void DicomStructureSet::Polygon::AddPoint(const Vector& v) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
223 { |
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
|
224 #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
|
225 // 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
|
226 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
|
227 { |
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
|
228 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
|
229 } |
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
|
230 #else |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
231 CheckPoint(v); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
232 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
|
233 #endif |
122
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 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
236 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
237 bool DicomStructureSet::Polygon::UpdateReferencedSlice(const ReferencedSlices& slices) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
238 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
239 if (hasSlice_) |
0 | 240 { |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
241 return true; |
32 | 242 } |
243 else | |
244 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
245 ReferencedSlices::const_iterator it = slices.find(sopInstanceUid_); |
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 if (it == slices.end()) |
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 return false; |
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 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
252 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
253 const CoordinateSystem3D& geometry = it->second.geometry_; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
254 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
255 hasSlice_ = true; |
131 | 256 geometry_ = geometry; |
257 projectionAlongNormal_ = GeometryToolbox::ProjectAlongNormal(geometry.GetOrigin(), geometry.GetNormal()); | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
258 sliceThickness_ = it->second.thickness_; |
0 | 259 |
131 | 260 extent_.Reset(); |
261 | |
1571 | 262 for (Points::const_iterator it2 = points_.begin(); it2 != points_.end(); ++it2) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
263 { |
1571 | 264 if (IsPointOnSliceIfAny(*it2)) |
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
|
265 { |
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
|
266 double x, y; |
1571 | 267 geometry.ProjectPoint2(x, y, *it2); |
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
|
268 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
|
269 } |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
270 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
271 return true; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
272 } |
0 | 273 } |
274 } | |
275 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
276 bool DicomStructureSet::Polygon::IsOnSlice(const CoordinateSystem3D& slice) const |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
277 { |
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
|
278 bool isOpposite = false; |
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 if (points_.empty() || |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
281 !hasSlice_ || |
131 | 282 !GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), geometry_.GetNormal())) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
283 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
284 return false; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
285 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
286 |
131 | 287 double d = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), geometry_.GetNormal()); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
288 |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
289 return (LinearAlgebra::IsNear(d, projectionAlongNormal_, |
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
290 sliceThickness_ / 2.0)); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
291 } |
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
|
292 |
131 | 293 bool DicomStructureSet::Polygon::Project(double& x1, |
294 double& y1, | |
295 double& x2, | |
296 double& y2, | |
297 const CoordinateSystem3D& slice) const | |
298 { | |
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
|
299 // 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
|
300 |
131 | 301 if (!hasSlice_ || |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
302 points_.size() <= 1) |
131 | 303 { |
304 return false; | |
305 } | |
306 | |
307 double x, y; | |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
308 geometry_.ProjectPoint2(x, y, slice.GetOrigin()); |
131 | 309 |
310 bool isOpposite; | |
311 if (GeometryToolbox::IsParallelOrOpposite | |
312 (isOpposite, slice.GetNormal(), geometry_.GetAxisY())) | |
313 { | |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
314 // plane is constant Y |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
315 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
316 if (y < extent_.GetY1() || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
317 y > extent_.GetY2()) |
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 // The polygon does not intersect the input slice |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
320 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
321 } |
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 bool isFirst = true; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
324 double xmin = std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
325 double xmax = -std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
326 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
327 double prevX, prevY; |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
328 geometry_.ProjectPoint2(prevX, prevY, points_[points_.size() - 1]); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
329 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
330 for (size_t i = 0; i < points_.size(); i++) |
131 | 331 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
332 // Reference: ../../Resources/Computations/IntersectSegmentAndHorizontalLine.py |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
333 double curX, curY; |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
334 geometry_.ProjectPoint2(curX, curY, points_[i]); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
335 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
336 // 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
|
337 // segment intersects the plane. |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
338 if ((prevY < y && curY > y) || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
339 (prevY > y && curY < y)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
340 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
341 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
|
342 xmin = std::min(xmin, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
343 xmax = std::max(xmax, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
344 isFirst = false; |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
345 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
346 // 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
|
347 // 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
|
348 |
132
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 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
351 prevX = curX; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
352 prevY = curY; |
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 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
355 // if NO segment intersects the plane |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
356 if (isFirst) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
357 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
358 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
359 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
360 else |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
361 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
362 // 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
|
363 // 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
|
364 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
365 // let's convert them to 3D world geometry... |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
366 Vector p1 = (geometry_.MapSliceToWorldCoordinates(xmin, y) + |
131 | 367 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
368 Vector p2 = (geometry_.MapSliceToWorldCoordinates(xmax, y) - |
131 | 369 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
370 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
371 // then to the cutting plane geometry... |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
372 slice.ProjectPoint2(x1, y1, p1); |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
373 slice.ProjectPoint2(x2, y2, p2); |
131 | 374 return true; |
375 } | |
376 } | |
377 else if (GeometryToolbox::IsParallelOrOpposite | |
378 (isOpposite, slice.GetNormal(), geometry_.GetAxisX())) | |
379 { | |
1170
1644de437a7b
fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
380 // plane is constant X => Sagittal view (remember that in the |
1644de437a7b
fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
381 // sagittal projection, the normal must be swapped) |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
382 |
1170
1644de437a7b
fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1162
diff
changeset
|
383 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
384 /* |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
385 Please read the comments in the section above, by taking into account |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
386 the fact that, in this case, the plane has a constant X, not Y (in |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
387 polygon geometry_ coordinates) |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
388 */ |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
389 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
390 if (x < extent_.GetX1() || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
391 x > extent_.GetX2()) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
392 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
393 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
394 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
395 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
396 bool isFirst = true; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
397 double ymin = std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
398 double ymax = -std::numeric_limits<double>::infinity(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
399 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
400 double prevX, prevY; |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
401 geometry_.ProjectPoint2(prevX, prevY, points_[points_.size() - 1]); |
132
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 for (size_t i = 0; i < points_.size(); i++) |
131 | 404 { |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
405 // Reference: ../../Resources/Computations/IntersectSegmentAndVerticalLine.py |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
406 double curX, curY; |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
407 geometry_.ProjectPoint2(curX, curY, points_[i]); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
408 |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
409 if ((prevX < x && curX > x) || |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
410 (prevX > x && curX < x)) |
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 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
|
413 ymin = std::min(ymin, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
414 ymax = std::max(ymax, p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
415 isFirst = false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
416 } |
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 prevX = curX; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
419 prevY = curY; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
420 } |
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 if (isFirst) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
423 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
424 return false; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
425 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
426 else |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
427 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
428 Vector p1 = (geometry_.MapSliceToWorldCoordinates(x, ymin) + |
131 | 429 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
430 Vector p2 = (geometry_.MapSliceToWorldCoordinates(x, ymax) - |
131 | 431 sliceThickness_ / 2.0 * geometry_.GetNormal()); |
432 | |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
433 slice.ProjectPoint2(x1, y1, p1); |
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
434 slice.ProjectPoint2(x2, y2, p2); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
435 |
131 | 436 return true; |
437 } | |
438 } | |
439 else | |
440 { | |
441 // Should not happen | |
442 return false; | |
443 } | |
444 } | |
445 | |
446 | |
0 | 447 const DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) const |
448 { | |
449 if (index >= structures_.size()) | |
450 { | |
125 | 451 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
0 | 452 } |
453 | |
454 return structures_[index]; | |
455 } | |
456 | |
457 | |
125 | 458 DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) |
0 | 459 { |
125 | 460 if (index >= structures_.size()) |
461 { | |
462 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
0 | 463 } |
464 | |
465 return structures_[index]; | |
466 } | |
467 | |
1504 | 468 void DicomStructureSet::Setup(const IDicomDataset& tags) |
0 | 469 { |
1504 | 470 DicomDatasetReader reader(tags); |
32 | 471 |
472 size_t count, tmp; | |
1571 | 473 if (!tags.GetSequenceSize(count, DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE)) || |
474 !tags.GetSequenceSize(tmp, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE)) || | |
32 | 475 tmp != count || |
1571 | 476 !tags.GetSequenceSize(tmp, DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE)) || |
32 | 477 tmp != count) |
0 | 478 { |
479 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
480 } | |
481 | |
32 | 482 structures_.resize(count); |
483 for (size_t i = 0; i < count; i++) | |
484 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
485 structures_[i].interpretation_ = reader.GetStringValue |
1504 | 486 (DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE, i, |
487 DICOM_TAG_RT_ROI_INTERPRETED_TYPE), | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
488 "No interpretation"); |
0 | 489 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
490 structures_[i].name_ = reader.GetStringValue |
1504 | 491 (DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE, i, |
492 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
|
493 "No name"); |
0 | 494 |
495 Vector color; | |
1504 | 496 if (ParseVector(color, tags, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
497 DICOM_TAG_ROI_DISPLAY_COLOR)) && | |
32 | 498 color.size() == 3) |
0 | 499 { |
32 | 500 structures_[i].red_ = ConvertColor(color[0]); |
501 structures_[i].green_ = ConvertColor(color[1]); | |
502 structures_[i].blue_ = ConvertColor(color[2]); | |
503 } | |
504 else | |
505 { | |
506 structures_[i].red_ = 255; | |
507 structures_[i].green_ = 0; | |
508 structures_[i].blue_ = 0; | |
0 | 509 } |
510 | |
32 | 511 size_t countSlices; |
1504 | 512 if (!tags.GetSequenceSize(countSlices, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
513 DICOM_TAG_CONTOUR_SEQUENCE))) | |
32 | 514 { |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
515 countSlices = 0; |
32 | 516 } |
0 | 517 |
841
266e2b0b9abc
better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents:
804
diff
changeset
|
518 LOG(INFO) << "New RT structure: \"" << structures_[i].name_ |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
519 << "\" with interpretation \"" << structures_[i].interpretation_ |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
520 << "\" containing " << countSlices << " slices (color: " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
521 << static_cast<int>(structures_[i].red_) << "," |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
522 << static_cast<int>(structures_[i].green_) << "," |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
523 << static_cast<int>(structures_[i].blue_) << ")"; |
0 | 524 |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
525 // These temporary variables avoid allocating many vectors in the loop below |
1504 | 526 DicomPath countPointsPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
527 DICOM_TAG_CONTOUR_SEQUENCE, 0, | |
528 DICOM_TAG_NUMBER_OF_CONTOUR_POINTS); | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
529 |
1504 | 530 DicomPath geometricTypePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
531 DICOM_TAG_CONTOUR_SEQUENCE, 0, | |
532 DICOM_TAG_CONTOUR_GEOMETRIC_TYPE); | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
533 |
1504 | 534 DicomPath imageSequencePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
535 DICOM_TAG_CONTOUR_SEQUENCE, 0, | |
536 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE); | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
537 |
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
|
538 // (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155) |
1504 | 539 DicomPath referencedInstancePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
540 DICOM_TAG_CONTOUR_SEQUENCE, 0, | |
541 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0, | |
542 DICOM_TAG_REFERENCED_SOP_INSTANCE_UID); | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
543 |
1504 | 544 DicomPath contourDataPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i, |
545 DICOM_TAG_CONTOUR_SEQUENCE, 0, | |
546 DICOM_TAG_CONTOUR_DATA); | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
547 |
32 | 548 for (size_t j = 0; j < countSlices; j++) |
0 | 549 { |
32 | 550 unsigned int countPoints; |
0 | 551 |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
552 countPointsPath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
553 if (!reader.GetUnsignedIntegerValue(countPoints, countPointsPath)) |
32 | 554 { |
555 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
556 } | |
557 | |
121
e66b2c757790
displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
118
diff
changeset
|
558 //LOG(INFO) << "Parsing slice containing " << countPoints << " vertices"; |
0 | 559 |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
560 geometricTypePath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
561 std::string type = reader.GetMandatoryStringValue(geometricTypePath); |
32 | 562 if (type != "CLOSED_PLANAR") |
0 | 563 { |
173
6b0411ac843a
fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
159
diff
changeset
|
564 LOG(WARNING) << "Ignoring contour with geometry type: " << type; |
6b0411ac843a
fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
159
diff
changeset
|
565 continue; |
0 | 566 } |
567 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
568 size_t size; |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
569 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
570 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
|
571 if (!tags.GetSequenceSize(size, imageSequencePath) || size != 1) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
572 { |
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
|
573 LOG(ERROR) << "The ContourImageSequence sequence (tag 3006,0016) must be present and contain one entry."; |
0 | 574 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
575 } | |
576 | |
786
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
577 referencedInstancePath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
578 std::string sopInstanceUid = reader.GetMandatoryStringValue(referencedInstancePath); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
579 |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
580 contourDataPath.SetPrefixIndex(1, j); |
5aa728500586
optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
738
diff
changeset
|
581 std::string slicesData = reader.GetMandatoryStringValue(contourDataPath); |
0 | 582 |
583 Vector points; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
584 if (!LinearAlgebra::ParseVector(points, slicesData) || |
32 | 585 points.size() != 3 * countPoints) |
0 | 586 { |
587 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
588 } | |
589 | |
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
|
590 // 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
|
591 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
|
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 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
|
594 } |
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
|
595 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
596 Polygon polygon(sopInstanceUid); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
597 polygon.Reserve(countPoints); |
0 | 598 |
32 | 599 for (size_t k = 0; k < countPoints; k++) |
0 | 600 { |
601 Vector v(3); | |
602 v[0] = points[3 * k]; | |
603 v[1] = points[3 * k + 1]; | |
604 v[2] = points[3 * k + 2]; | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
605 polygon.AddPoint(v); |
0 | 606 } |
607 | |
608 structures_[i].polygons_.push_back(polygon); | |
609 } | |
610 } | |
611 } | |
612 | |
613 | |
1180
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
614 #if ORTHANC_ENABLE_DCMTK == 1 |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
615 DicomStructureSet::DicomStructureSet(Orthanc::ParsedDicomFile& instance) |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
616 { |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
617 ParsedDicomDataset dataset(instance); |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
618 Setup(dataset); |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
619 } |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
620 #endif |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
621 |
9c8f557ea799
ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1178
diff
changeset
|
622 |
0 | 623 Vector DicomStructureSet::GetStructureCenter(size_t index) const |
624 { | |
625 const Structure& structure = GetStructure(index); | |
626 | |
627 Vector center; | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
628 LinearAlgebra::AssignVector(center, 0, 0, 0); |
0 | 629 if (structure.polygons_.empty()) |
630 { | |
631 return center; | |
632 } | |
633 | |
634 double n = static_cast<double>(structure.polygons_.size()); | |
635 | |
636 for (Polygons::const_iterator polygon = structure.polygons_.begin(); | |
637 polygon != structure.polygons_.end(); ++polygon) | |
638 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
639 if (!polygon->GetPoints().empty()) |
0 | 640 { |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
641 center += polygon->GetPoints().front() / n; |
0 | 642 } |
643 } | |
644 | |
645 return center; | |
646 } | |
647 | |
648 | |
649 const std::string& DicomStructureSet::GetStructureName(size_t index) const | |
650 { | |
651 return GetStructure(index).name_; | |
652 } | |
653 | |
654 | |
655 const std::string& DicomStructureSet::GetStructureInterpretation(size_t index) const | |
656 { | |
657 return GetStructure(index).interpretation_; | |
658 } | |
659 | |
660 | |
804
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
661 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
|
662 { |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
663 const Structure& s = GetStructure(index); |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
664 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
|
665 } |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
666 |
61ba4b504e9a
PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
794
diff
changeset
|
667 |
0 | 668 void DicomStructureSet::GetStructureColor(uint8_t& red, |
669 uint8_t& green, | |
670 uint8_t& blue, | |
671 size_t index) const | |
672 { | |
673 const Structure& s = GetStructure(index); | |
674 red = s.red_; | |
675 green = s.green_; | |
676 blue = s.blue_; | |
677 } | |
678 | |
679 | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
680 void DicomStructureSet::GetReferencedInstances(std::set<std::string>& instances) |
0 | 681 { |
682 for (Structures::const_iterator structure = structures_.begin(); | |
683 structure != structures_.end(); ++structure) | |
684 { | |
685 for (Polygons::const_iterator polygon = structure->polygons_.begin(); | |
686 polygon != structure->polygons_.end(); ++polygon) | |
687 { | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
688 instances.insert(polygon->GetSopInstanceUid()); |
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 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
691 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
692 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
693 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
694 void DicomStructureSet::AddReferencedSlice(const std::string& sopInstanceUid, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
695 const std::string& seriesInstanceUid, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
696 const CoordinateSystem3D& geometry, |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
697 double thickness) |
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 if (referencedSlices_.find(sopInstanceUid) != referencedSlices_.end()) |
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 // 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
|
702 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
|
703 |
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
|
704 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
122
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 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
707 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
708 if (thickness < 0) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
709 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
710 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
711 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
712 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
713 if (!referencedSlices_.empty()) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
714 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
715 const ReferencedSlice& reference = referencedSlices_.begin()->second; |
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 if (reference.seriesInstanceUid_ != seriesInstanceUid) |
0 | 718 { |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
719 LOG(ERROR) << "This RT-STRUCT refers to several different series"; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
720 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
721 } |
0 | 722 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
723 if (!GeometryToolbox::IsParallel(reference.geometry_.GetNormal(), geometry.GetNormal())) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
724 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
725 LOG(ERROR) << "The slices in this RT-STRUCT are not parallel"; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
726 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
727 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
728 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
729 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
730 referencedSlices_[sopInstanceUid] = ReferencedSlice(seriesInstanceUid, geometry, thickness); |
0 | 731 |
131 | 732 for (Structures::iterator structure = structures_.begin(); |
733 structure != structures_.end(); ++structure) | |
734 { | |
735 for (Polygons::iterator polygon = structure->polygons_.begin(); | |
736 polygon != structure->polygons_.end(); ++polygon) | |
737 { | |
738 polygon->UpdateReferencedSlice(referencedSlices_); | |
739 } | |
740 } | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
741 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
742 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
743 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
744 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
745 void DicomStructureSet::AddReferencedSlice(const Orthanc::DicomMap& dataset) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
746 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
747 CoordinateSystem3D slice(dataset); |
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 double thickness = 1; // 1 mm by default |
0 | 750 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
751 std::string s; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
752 Vector v; |
994
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
988
diff
changeset
|
753 if (dataset.LookupStringValue(s, Orthanc::DICOM_TAG_SLICE_THICKNESS, false) && |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
754 LinearAlgebra::ParseVector(v, s) && |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
755 v.size() > 0) |
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 thickness = v[0]; |
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 std::string instance, series; |
994
1f74bc3459ba
fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
988
diff
changeset
|
761 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
|
762 dataset.LookupStringValue(series, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false)) |
122
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 AddReferencedSlice(instance, series, slice, thickness); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
765 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
766 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
767 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
768 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); |
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 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
771 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
772 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
773 void DicomStructureSet::CheckReferencedSlices() |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
774 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
775 for (Structures::iterator structure = structures_.begin(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
776 structure != structures_.end(); ++structure) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
777 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
778 for (Polygons::iterator polygon = structure->polygons_.begin(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
779 polygon != structure->polygons_.end(); ++polygon) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
780 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
781 if (!polygon->UpdateReferencedSlice(referencedSlices_)) |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
782 { |
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
|
783 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
|
784 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
|
785 { |
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
|
786 LOG(ERROR) << "DicomStructureSet::CheckReferencedSlices(): " |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
787 << " missing information about referenced instance " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
788 << "(sopInstanceUid is empty!)"; |
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
|
789 } |
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
|
790 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
|
791 { |
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
|
792 LOG(ERROR) << "DicomStructureSet::CheckReferencedSlices(): " |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
793 << " missing information about referenced instance " |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
794 << "(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
|
795 } |
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
|
796 //throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
0 | 797 } |
798 } | |
799 } | |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
800 } |
0 | 801 |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
802 |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
803 Vector DicomStructureSet::GetNormal() const |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
804 { |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
805 if (referencedSlices_.empty()) |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
806 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
807 Vector v; |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
137
diff
changeset
|
808 LinearAlgebra::AssignVector(v, 0, 0, 1); |
122
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
809 return v; |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
810 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
811 else |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
812 { |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
813 return referencedSlices_.begin()->second.geometry_.GetNormal(); |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
814 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
815 } |
e3433dabfb8d
refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
121
diff
changeset
|
816 |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
817 bool DicomStructureSet::ProjectStructure( |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
818 #if USE_BOOST_UNION_FOR_POLYGONS == 1 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
819 std::vector< std::vector<Point2D> >& polygons, |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
820 #else |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
821 std::vector< std::pair<Point2D, Point2D> >& segments, |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
822 #endif |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
823 const Structure& structure, |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
824 const CoordinateSystem3D& sourceSlice) const |
125 | 825 { |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
826 const CoordinateSystem3D slice = CoordinateSystem3D::NormalizeCuttingPlane(sourceSlice); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
827 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
828 #if USE_BOOST_UNION_FOR_POLYGONS == 1 |
125 | 829 polygons.clear(); |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
830 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
831 segments.clear(); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
832 #endif |
125 | 833 |
834 Vector normal = GetNormal(); | |
835 | |
836 bool isOpposite; | |
837 if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetNormal())) | |
838 { | |
839 // This is an axial projection | |
840 | |
794 | 841 for (Polygons::const_iterator polygon = structure.polygons_.begin(); |
125 | 842 polygon != structure.polygons_.end(); ++polygon) |
843 { | |
844 if (polygon->IsOnSlice(slice)) | |
845 { | |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
846 #if USE_BOOST_UNION_FOR_POLYGONS == 1 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
847 polygons.push_back(std::vector<Point2D>()); |
125 | 848 |
849 for (Points::const_iterator p = polygon->GetPoints().begin(); | |
850 p != polygon->GetPoints().end(); ++p) | |
851 { | |
852 double x, y; | |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
853 slice.ProjectPoint2(x, y, *p); |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
854 polygons.back().push_back(Point2D(x, y)); |
125 | 855 } |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
856 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
857 // 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
|
858 const std::vector<Vector>& points3D = polygon->GetPoints(); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
859 if (points3D.size() >= 3) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
860 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
861 Point2D prev2D; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
862 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
863 Vector prev = points3D[0]; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
864 double prevX, prevY; |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
865 slice.ProjectPoint2(prevX, prevY, prev); |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
866 prev2D = Point2D(prevX, prevY); |
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 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
869 size_t pointCount = points3D.size(); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
870 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
|
871 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
872 Vector next = points3D[ipt]; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
873 double nextX, nextY; |
1013
53cc787bd7bc
- Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents:
1006
diff
changeset
|
874 slice.ProjectPoint2(nextX, nextY, next); |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
875 Point2D next2D(nextX, nextY); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
876 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
|
877 prev2D = next2D; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
878 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
879 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
880 else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
881 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
882 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
|
883 // !!! |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
884 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
885 #endif |
125 | 886 } |
887 } | |
888 | |
889 return true; | |
890 } | |
891 else if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisX()) || | |
892 GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisY())) | |
893 { | |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
894 #if 1 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
895 // Sagittal or coronal projection |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
896 |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
897 #if USE_BOOST_UNION_FOR_POLYGONS == 1 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
898 std::vector<BoostPolygon> projected; |
1162
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
899 |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
900 for (Polygons::const_iterator polygon = structure.polygons_.begin(); |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
901 polygon != structure.polygons_.end(); ++polygon) |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
902 { |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
903 double x1, y1, x2, y2; |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
904 |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
905 if (polygon->Project(x1, y1, x2, y2, slice)) |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
906 { |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
907 projected.push_back(CreateRectangle(x1, y1, x2, y2)); |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
908 } |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
909 } |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
910 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
911 // 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
|
912 // 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
|
913 // (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
|
914 // (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
|
915 std::vector<std::pair<RtStructRectangleInSlab, double> > projected; |
1162
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
916 |
794 | 917 for (Polygons::const_iterator polygon = structure.polygons_.begin(); |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
918 polygon != structure.polygons_.end(); ++polygon) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
919 { |
131 | 920 double x1, y1, x2, y2; |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
921 |
131 | 922 if (polygon->Project(x1, y1, x2, y2, slice)) |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
923 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
924 double curZ = polygon->GetGeometryOrigin()[2]; |
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 // 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
|
927 // geometry) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
928 projected.push_back(std::make_pair(CreateRectangle( |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
929 static_cast<float>(x1), |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
930 static_cast<float>(y1), |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
931 static_cast<float>(x2), |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
932 static_cast<float>(y2)),curZ)); |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
933 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
934 } |
1162
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
935 #endif |
709aa65aca17
recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1013
diff
changeset
|
936 |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
937 #if USE_BOOST_UNION_FOR_POLYGONS != 1 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
938 // 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
|
939 // corners (x1,y1,x2,y2) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
940 // we need to merge them |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
941 // each slab yields ONE polygon! |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
942 |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
943 // 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
|
944 // 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
|
945 // sort it. |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
946 std::sort(projected.begin(), projected.end(), CompareRectanglesForProjection); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
947 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
948 std::vector<RtStructRectanglesInSlab> rectanglesForEachSlab; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
949 rectanglesForEachSlab.reserve(projected.size()); |
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 double curZ = 0; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
952 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
|
953 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
954 #if 0 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
955 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
956 #else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
957 if (i == 0) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
958 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
959 curZ = projected[i].second; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
960 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
961 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
962 else |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
963 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
964 // 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
|
965 // 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
|
966 if (!LinearAlgebra::IsNear(curZ, projected[i].second)) |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
967 { |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
968 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
969 curZ = projected[i].second; |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
970 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
971 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
972 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
973 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
974 rectanglesForEachSlab.back().push_back(projected[i].first); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
975 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
976 // 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
|
977 // 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
|
978 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
979 //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
|
980 } |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
981 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
982 // 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
|
983 std::sort(rectanglesForEachSlab.begin(), rectanglesForEachSlab.end(), CompareSlabsY); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
984 |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
985 ConvertListOfSlabsToSegments(segments, rectanglesForEachSlab, projected.size()); |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
986 #else |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
987 BoostMultiPolygon merged; |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
988 Union(merged, projected); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
989 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
990 polygons.resize(merged.size()); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
991 for (size_t i = 0; i < merged.size(); i++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
992 { |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
993 const std::vector<BoostPoint>& outer = merged[i].outer(); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
994 |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
995 polygons[i].resize(outer.size()); |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
996 for (size_t j = 0; j < outer.size(); j++) |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
997 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
998 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
|
999 } |
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
1000 } |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
1001 #endif |
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
1002 |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1003 #else |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1004 for (Polygons::iterator polygon = structure.polygons_.begin(); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1005 polygon != structure.polygons_.end(); ++polygon) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1006 { |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1007 double x1, y1, x2, y2; |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1008 if (polygon->Project(x1, y1, x2, y2, slice)) |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1009 { |
1000
50e5acf5553b
changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents:
994
diff
changeset
|
1010 std::vector<Point2D> p(4); |
132
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1011 p[0] = std::make_pair(x1, y1); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1012 p[1] = std::make_pair(x2, y1); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1013 p[2] = std::make_pair(x2, y2); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1014 p[3] = std::make_pair(x1, y2); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1015 polygons.push_back(p); |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1016 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1017 } |
35c2b85836ce
fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
131
diff
changeset
|
1018 #endif |
125 | 1019 |
126
c9e88e7935a4
rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
125
diff
changeset
|
1020 return true; |
125 | 1021 } |
1022 else | |
1023 { | |
1024 return false; | |
1025 } | |
0 | 1026 } |
1178
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1027 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1028 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1029 void DicomStructureSet::ProjectOntoLayer(PolylineSceneLayer& layer, |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1030 const CoordinateSystem3D& plane, |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1031 size_t structureIndex, |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1032 const Color& color) const |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1033 { |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1034 #if USE_BOOST_UNION_FOR_POLYGONS == 1 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1035 std::vector< std::vector<Point2D> > polygons; |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1036 if (ProjectStructure(polygons, structureIndex, plane)) |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1037 { |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1038 for (size_t j = 0; j < polygons.size(); j++) |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1039 { |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1040 std::vector<ScenePoint2D> chain; |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1041 chain.reserve(polygons[j].size()); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1042 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1043 for (size_t k = 0; k < polygons[j].size(); k++) |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1044 { |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1045 chain.push_back(ScenePoint2D(polygons[j][k].x, polygons[j][k].y)); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1046 } |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1047 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1048 layer.AddChain(chain, true, color.GetRed(), color.GetGreen(), color.GetBlue()); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1049 } |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1050 } |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1051 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1052 #else |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1053 std::vector< std::pair<Point2D, Point2D> > segments; |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1054 |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1055 if (ProjectStructure(segments, structureIndex, plane)) |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1056 { |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1057 for (size_t j = 0; j < segments.size(); j++) |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1058 { |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1059 std::vector<ScenePoint2D> chain(2); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1060 chain[0] = ScenePoint2D(segments[j].first.x, segments[j].first.y); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1061 chain[1] = ScenePoint2D(segments[j].second.x, segments[j].second.y); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1062 layer.AddChain(chain, false, color.GetRed(), color.GetGreen(), color.GetBlue()); |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1063 } |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1064 } |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1065 #endif |
3c7cdbf32e2a
DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1170
diff
changeset
|
1066 } |
0 | 1067 } |