annotate Framework/Toolbox/DicomStructureSet.cpp @ 920:5ca418d6579e refactor-viewport-controller

Close branch refactor-viewport-controller.
author Alain Mazy <am@osimis.io>
date Fri, 19 Jul 2019 14:15:49 +0000
parents 11fa6f00e33c
children 8e31b174ab26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /**
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 * Stone of Orthanc
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4 * Department, University Hospital of Liege, Belgium
439
b70e9be013e4 preparing for 2019
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 212
diff changeset
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 * This program is free software: you can redistribute it and/or
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
8 * modify it under the terms of the GNU Affero General Public License
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
9 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 * This program is distributed in the hope that it will be useful, but
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
15 * Affero General Public License for more details.
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
16 *
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
17 * You should have received a copy of the GNU Affero General Public License
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 **/
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 #include "DicomStructureSet.h"
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
159
0a73d76333db populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 158
diff changeset
24 #include "../Toolbox/GeometryToolbox.h"
35
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 34
diff changeset
25 #include "../Toolbox/MessagingToolbox.h"
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
212
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
27 #include <Core/Logging.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
28 #include <Core/OrthancException.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
29 #include <Plugins/Samples/Common/FullOrthancDataset.h>
5412adf19980 resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 201
diff changeset
30 #include <Plugins/Samples/Common/DicomDatasetReader.h>
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
31
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
32 #include <limits>
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 #include <stdio.h>
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 #include <boost/lexical_cast.hpp>
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
35 #include <boost/geometry.hpp>
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
36 #include <boost/geometry/geometries/point_xy.hpp>
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
37 #include <boost/geometry/geometries/polygon.hpp>
137
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
38 #include <boost/geometry/multi/geometries/multi_polygon.hpp>
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
39
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
40 typedef boost::geometry::model::d2::point_xy<double> BoostPoint;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
41 typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
42 typedef boost::geometry::model::multi_polygon<BoostPolygon> BoostMultiPolygon;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
43
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
44
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
45 static void Union(BoostMultiPolygon& output,
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
46 std::vector<BoostPolygon>& input)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
47 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
48 for (size_t i = 0; i < input.size(); i++)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
49 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
50 boost::geometry::correct(input[i]);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
51 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
52
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
53 if (input.size() == 0)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
54 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
55 output.clear();
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 else if (input.size() == 1)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
58 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
59 output.resize(1);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
60 output[0] = input[0];
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
61 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
62 else
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
63 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
64 boost::geometry::union_(input[0], input[1], output);
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 for (size_t i = 0; i < input.size(); i++)
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 BoostMultiPolygon tmp;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
69 boost::geometry::union_(output, input[i], tmp);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
70 output = tmp;
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 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
73 }
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
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
76 static BoostPolygon CreateRectangle(float x1, float y1,
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
77 float x2, float y2)
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 BoostPolygon r;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
80 boost::geometry::append(r, BoostPoint(x1, y1));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
81 boost::geometry::append(r, BoostPoint(x1, y2));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
82 boost::geometry::append(r, BoostPoint(x2, y2));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
83 boost::geometry::append(r, BoostPoint(x2, y1));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
84 return r;
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
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 namespace OrthancStone
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
91 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_GEOMETRIC_TYPE(0x3006, 0x0042);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
92 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_IMAGE_SEQUENCE(0x3006, 0x0016);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
93 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_SEQUENCE(0x3006, 0x0040);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
94 static const OrthancPlugins::DicomTag DICOM_TAG_CONTOUR_DATA(0x3006, 0x0050);
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
95 static const OrthancPlugins::DicomTag DICOM_TAG_NUMBER_OF_CONTOUR_POINTS(0x3006, 0x0046);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
96 static const OrthancPlugins::DicomTag DICOM_TAG_REFERENCED_SOP_INSTANCE_UID(0x0008, 0x1155);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
97 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_CONTOUR_SEQUENCE(0x3006, 0x0039);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
98 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_DISPLAY_COLOR(0x3006, 0x002a);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
99 static const OrthancPlugins::DicomTag DICOM_TAG_ROI_NAME(0x3006, 0x0026);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
100 static const OrthancPlugins::DicomTag DICOM_TAG_RT_ROI_INTERPRETED_TYPE(0x3006, 0x00a4);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
101 static const OrthancPlugins::DicomTag DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE(0x3006, 0x0080);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
102 static const OrthancPlugins::DicomTag DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE(0x3006, 0x0020);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 static uint8_t ConvertColor(double v)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 if (v < 0)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 return 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111 else if (v >= 255)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113 return 255;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 else
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 return static_cast<uint8_t>(v);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
122 static bool ParseVector(Vector& target,
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
123 const OrthancPlugins::IDicomDataset& dataset,
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
124 const OrthancPlugins::DicomPath& tag)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 {
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
126 std::string value;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
127 return (dataset.GetStringValue(value, tag) &&
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
128 LinearAlgebra::ParseVector(target, value));
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
129 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
132 void DicomStructureSet::Polygon::CheckPoint(const Vector& v)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
133 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
134 if (hasSlice_)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 {
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
136 if (!LinearAlgebra::IsNear(GeometryToolbox::ProjectAlongNormal(v, geometry_.GetNormal()),
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
137 projectionAlongNormal_,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
138 sliceThickness_ / 2.0 /* in mm */))
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
139 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
140 LOG(ERROR) << "This RT-STRUCT contains a point that is off the slice of its instance";
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
141 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
142 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
144 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
147 void DicomStructureSet::Polygon::AddPoint(const Vector& v)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
148 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
149 CheckPoint(v);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
150 points_.push_back(v);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
151 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
152
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
153
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
154 bool DicomStructureSet::Polygon::UpdateReferencedSlice(const ReferencedSlices& slices)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
155 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
156 if (hasSlice_)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
158 return true;
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
159 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
160 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
161 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
162 ReferencedSlices::const_iterator it = slices.find(sopInstanceUid_);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
163
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
164 if (it == slices.end())
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
165 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
166 return false;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
167 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
168 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
169 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
170 const CoordinateSystem3D& geometry = it->second.geometry_;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
171
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
172 hasSlice_ = true;
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
173 geometry_ = geometry;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
174 projectionAlongNormal_ = GeometryToolbox::ProjectAlongNormal(geometry.GetOrigin(), geometry.GetNormal());
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
175 sliceThickness_ = it->second.thickness_;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
177 extent_.Reset();
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
178
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
179 for (Points::const_iterator it = points_.begin(); it != points_.end(); ++it)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
180 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
181 CheckPoint(*it);
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
182
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
183 double x, y;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
184 geometry.ProjectPoint(x, y, *it);
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
185 extent_.AddPoint(x, y);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
186 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
187
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
188 return true;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
189 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
194 bool DicomStructureSet::Polygon::IsOnSlice(const CoordinateSystem3D& slice) const
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
195 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
196 bool isOpposite;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
197
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
198 if (points_.empty() ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
199 !hasSlice_ ||
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
200 !GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), geometry_.GetNormal()))
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
201 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
202 return false;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
203 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
204
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
205 double d = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), geometry_.GetNormal());
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
206
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
207 return (LinearAlgebra::IsNear(d, projectionAlongNormal_,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
208 sliceThickness_ / 2.0));
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
209 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
210
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
211
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
212 bool DicomStructureSet::Polygon::Project(double& x1,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
213 double& y1,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
214 double& x2,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
215 double& y2,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
216 const CoordinateSystem3D& slice) const
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
217 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
218 // TODO Optimize this method using a sweep-line algorithm for polygons
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
219
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
220 if (!hasSlice_ ||
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
221 points_.size() <= 1)
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
222 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
223 return false;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
224 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
225
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
226 double x, y;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
227 geometry_.ProjectPoint(x, y, slice.GetOrigin());
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
228
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
229 bool isOpposite;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
230 if (GeometryToolbox::IsParallelOrOpposite
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
231 (isOpposite, slice.GetNormal(), geometry_.GetAxisY()))
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
232 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
233 if (y < extent_.GetY1() ||
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
234 y > extent_.GetY2())
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
235 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
236 // The polygon does not intersect the input slice
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
237 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
238 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
239
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
240 bool isFirst = true;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
241 double xmin = std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
242 double xmax = -std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
243
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
244 double prevX, prevY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
245 geometry_.ProjectPoint(prevX, prevY, points_[points_.size() - 1]);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
246
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
247 for (size_t i = 0; i < points_.size(); i++)
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
248 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
249 // Reference: ../../Resources/Computations/IntersectSegmentAndHorizontalLine.py
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
250 double curX, curY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
251 geometry_.ProjectPoint(curX, curY, points_[i]);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
252
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
253 if ((prevY < y && curY > y) ||
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
254 (prevY > y && curY < y))
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
255 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
256 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
257 xmin = std::min(xmin, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
258 xmax = std::max(xmax, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
259 isFirst = false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
260 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
261
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
262 prevX = curX;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
263 prevY = curY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
264 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
265
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
266 if (isFirst)
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
267 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
268 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
269 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
270 else
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
271 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
272 Vector p1 = (geometry_.MapSliceToWorldCoordinates(xmin, y) +
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
273 sliceThickness_ / 2.0 * geometry_.GetNormal());
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
274 Vector p2 = (geometry_.MapSliceToWorldCoordinates(xmax, y) -
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
275 sliceThickness_ / 2.0 * geometry_.GetNormal());
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
276
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
277 slice.ProjectPoint(x1, y1, p1);
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
278 slice.ProjectPoint(x2, y2, p2);
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
279 return true;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
280 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
281 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
282 else if (GeometryToolbox::IsParallelOrOpposite
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
283 (isOpposite, slice.GetNormal(), geometry_.GetAxisX()))
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
284 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
285 if (x < extent_.GetX1() ||
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
286 x > extent_.GetX2())
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
287 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
288 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
289 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
290
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
291 bool isFirst = true;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
292 double ymin = std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
293 double ymax = -std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
294
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
295 double prevX, prevY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
296 geometry_.ProjectPoint(prevX, prevY, points_[points_.size() - 1]);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
297
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
298 for (size_t i = 0; i < points_.size(); i++)
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
299 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
300 // Reference: ../../Resources/Computations/IntersectSegmentAndVerticalLine.py
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
301 double curX, curY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
302 geometry_.ProjectPoint(curX, curY, points_[i]);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
303
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
304 if ((prevX < x && curX > x) ||
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
305 (prevX > x && curX < x))
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
306 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
307 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
308 ymin = std::min(ymin, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
309 ymax = std::max(ymax, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
310 isFirst = false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
311 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
312
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
313 prevX = curX;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
314 prevY = curY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
315 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
316
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
317 if (isFirst)
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 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
320 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
321 else
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 Vector p1 = (geometry_.MapSliceToWorldCoordinates(x, ymin) +
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
324 sliceThickness_ / 2.0 * geometry_.GetNormal());
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
325 Vector p2 = (geometry_.MapSliceToWorldCoordinates(x, ymax) -
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
326 sliceThickness_ / 2.0 * geometry_.GetNormal());
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
327
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
328 slice.ProjectPoint(x1, y1, p1);
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
329 slice.ProjectPoint(x2, y2, p2);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
330
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
331 // TODO WHY THIS???
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
332 y1 = -y1;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
333 y2 = -y2;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
334
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
335 return true;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
336 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
337 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
338 else
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
339 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
340 // Should not happen
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
341 return false;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
342 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
343 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
344
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
345
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346 const DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348 if (index >= structures_.size())
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 {
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
350 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 return structures_[index];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
357 DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 {
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
359 if (index >= structures_.size())
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
360 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
361 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 return structures_[index];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
368 DicomStructureSet::DicomStructureSet(const OrthancPlugins::FullOrthancDataset& tags)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
370 using namespace OrthancPlugins;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
372 DicomDatasetReader reader(tags);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
373
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
374 size_t count, tmp;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
375 if (!tags.GetSequenceSize(count, DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
376 !tags.GetSequenceSize(tmp, DICOM_TAG_ROI_CONTOUR_SEQUENCE) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
377 tmp != count ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
378 !tags.GetSequenceSize(tmp, DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE) ||
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
379 tmp != count)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
384 structures_.resize(count);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
385 for (size_t i = 0; i < count; i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
386 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
387 structures_[i].interpretation_ = reader.GetStringValue
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
388 (DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
389 DICOM_TAG_RT_ROI_INTERPRETED_TYPE),
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
390 "No interpretation");
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
392 structures_[i].name_ = reader.GetStringValue
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
393 (DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
394 DICOM_TAG_ROI_NAME),
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
395 "No interpretation");
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 Vector color;
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
398 if (ParseVector(color, tags, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
399 DICOM_TAG_ROI_DISPLAY_COLOR)) &&
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
400 color.size() == 3)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
402 structures_[i].red_ = ConvertColor(color[0]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
403 structures_[i].green_ = ConvertColor(color[1]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
404 structures_[i].blue_ = ConvertColor(color[2]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
405 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
406 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
407 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
408 structures_[i].red_ = 255;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
409 structures_[i].green_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
410 structures_[i].blue_ = 0;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
413 size_t countSlices;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
414 if (!tags.GetSequenceSize(countSlices, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
415 DICOM_TAG_CONTOUR_SEQUENCE)))
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
416 {
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
417 countSlices = 0;
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
418 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 LOG(WARNING) << "New RT structure: \"" << structures_[i].name_
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 << "\" with interpretation \"" << structures_[i].interpretation_
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
422 << "\" containing " << countSlices << " slices (color: "
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 << static_cast<int>(structures_[i].red_) << ","
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424 << static_cast<int>(structures_[i].green_) << ","
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425 << static_cast<int>(structures_[i].blue_) << ")";
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
427 for (size_t j = 0; j < countSlices; j++)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
429 unsigned int countPoints;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
431 if (!reader.GetUnsignedIntegerValue
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
432 (countPoints, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
433 DICOM_TAG_CONTOUR_SEQUENCE, j,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
434 DICOM_TAG_NUMBER_OF_CONTOUR_POINTS)))
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
435 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
436 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
437 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
438
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
439 //LOG(INFO) << "Parsing slice containing " << countPoints << " vertices";
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
441 std::string type = reader.GetMandatoryStringValue
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
442 (DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
443 DICOM_TAG_CONTOUR_SEQUENCE, j,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
444 DICOM_TAG_CONTOUR_GEOMETRIC_TYPE));
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
445 if (type != "CLOSED_PLANAR")
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446 {
173
6b0411ac843a fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
447 LOG(WARNING) << "Ignoring contour with geometry type: " << type;
6b0411ac843a fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
448 continue;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
451 size_t size;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
452 if (!tags.GetSequenceSize(size, DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
453 DICOM_TAG_CONTOUR_SEQUENCE, j,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
454 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE)) ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
455 size != 1)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
456 {
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
460 std::string sopInstanceUid = reader.GetMandatoryStringValue
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
461 (DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
462 DICOM_TAG_CONTOUR_SEQUENCE, j,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
463 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
464 DICOM_TAG_REFERENCED_SOP_INSTANCE_UID));
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
465
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
466 std::string slicesData = reader.GetMandatoryStringValue
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
467 (DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
468 DICOM_TAG_CONTOUR_SEQUENCE, j,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
469 DICOM_TAG_CONTOUR_DATA));
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 Vector points;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
472 if (!LinearAlgebra::ParseVector(points, slicesData) ||
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
473 points.size() != 3 * countPoints)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
478 Polygon polygon(sopInstanceUid);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
479 polygon.Reserve(countPoints);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
481 for (size_t k = 0; k < countPoints; k++)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 Vector v(3);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 v[0] = points[3 * k];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 v[1] = points[3 * k + 1];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 v[2] = points[3 * k + 2];
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
487 polygon.AddPoint(v);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490 structures_[i].polygons_.push_back(polygon);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496 Vector DicomStructureSet::GetStructureCenter(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 const Structure& structure = GetStructure(index);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500 Vector center;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
501 LinearAlgebra::AssignVector(center, 0, 0, 0);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 if (structure.polygons_.empty())
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 return center;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 double n = static_cast<double>(structure.polygons_.size());
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 for (Polygons::const_iterator polygon = structure.polygons_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 polygon != structure.polygons_.end(); ++polygon)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
512 if (!polygon->GetPoints().empty())
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
514 center += polygon->GetPoints().front() / n;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 return center;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 const std::string& DicomStructureSet::GetStructureName(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 return GetStructure(index).name_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528 const std::string& DicomStructureSet::GetStructureInterpretation(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 return GetStructure(index).interpretation_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 void DicomStructureSet::GetStructureColor(uint8_t& red,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535 uint8_t& green,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 uint8_t& blue,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 const Structure& s = GetStructure(index);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 red = s.red_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541 green = s.green_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 blue = s.blue_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
546 void DicomStructureSet::GetReferencedInstances(std::set<std::string>& instances)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 for (Structures::const_iterator structure = structures_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 structure != structures_.end(); ++structure)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551 for (Polygons::const_iterator polygon = structure->polygons_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 polygon != structure->polygons_.end(); ++polygon)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
554 instances.insert(polygon->GetSopInstanceUid());
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
555 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
556 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
557 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
558
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
559
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
560 void DicomStructureSet::AddReferencedSlice(const std::string& sopInstanceUid,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
561 const std::string& seriesInstanceUid,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
562 const CoordinateSystem3D& geometry,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
563 double thickness)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
564 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
565 if (referencedSlices_.find(sopInstanceUid) != referencedSlices_.end())
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
566 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
567 // This geometry is already known
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
568 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
569 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
570 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
571 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
572 if (thickness < 0)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
573 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
574 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
575 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
576
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
577 if (!referencedSlices_.empty())
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
578 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
579 const ReferencedSlice& reference = referencedSlices_.begin()->second;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
580
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
581 if (reference.seriesInstanceUid_ != seriesInstanceUid)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
583 LOG(ERROR) << "This RT-STRUCT refers to several different series";
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
584 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
585 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
587 if (!GeometryToolbox::IsParallel(reference.geometry_.GetNormal(), geometry.GetNormal()))
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
588 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
589 LOG(ERROR) << "The slices in this RT-STRUCT are not parallel";
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
590 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
591 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
592 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
593
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
594 referencedSlices_[sopInstanceUid] = ReferencedSlice(seriesInstanceUid, geometry, thickness);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
596 for (Structures::iterator structure = structures_.begin();
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
597 structure != structures_.end(); ++structure)
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
598 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
599 for (Polygons::iterator polygon = structure->polygons_.begin();
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
600 polygon != structure->polygons_.end(); ++polygon)
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
601 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
602 polygon->UpdateReferencedSlice(referencedSlices_);
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
603 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
604 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
605 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
606 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
607
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
608
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
609 void DicomStructureSet::AddReferencedSlice(const Orthanc::DicomMap& dataset)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
610 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
611 CoordinateSystem3D slice(dataset);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
612
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
613 double thickness = 1; // 1 mm by default
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
615 std::string s;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
616 Vector v;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
617 if (dataset.CopyToString(s, Orthanc::DICOM_TAG_SLICE_THICKNESS, false) &&
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
618 LinearAlgebra::ParseVector(v, s) &&
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
619 v.size() > 0)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
620 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
621 thickness = v[0];
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
622 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
623
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
624 std::string instance, series;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
625 if (dataset.CopyToString(instance, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false) &&
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
626 dataset.CopyToString(series, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false))
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
627 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
628 AddReferencedSlice(instance, series, slice, thickness);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
629 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
630 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
631 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
632 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
633 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
634 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
635
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
636
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
637 void DicomStructureSet::CheckReferencedSlices()
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
638 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
639 for (Structures::iterator structure = structures_.begin();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
640 structure != structures_.end(); ++structure)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
641 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
642 for (Polygons::iterator polygon = structure->polygons_.begin();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
643 polygon != structure->polygons_.end(); ++polygon)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
644 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
645 if (!polygon->UpdateReferencedSlice(referencedSlices_))
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
646 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
647 LOG(ERROR) << "Missing information about referenced instance: "
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
648 << polygon->GetSopInstanceUid();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
649 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
653 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
655
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
656 Vector DicomStructureSet::GetNormal() const
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
657 {
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
658 if (referencedSlices_.empty())
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
659 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
660 Vector v;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
661 LinearAlgebra::AssignVector(v, 0, 0, 1);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
662 return v;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
663 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
664 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
665 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
666 return referencedSlices_.begin()->second.geometry_.GetNormal();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
667 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
668 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
669
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
670
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
671 DicomStructureSet* DicomStructureSet::SynchronousLoad(OrthancPlugins::IOrthancConnection& orthanc,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
672 const std::string& instanceId)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
673 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
674 const std::string uri = "/instances/" + instanceId + "/tags?ignore-length=3006-0050";
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
675 OrthancPlugins::FullOrthancDataset dataset(orthanc, uri);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
676
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
677 std::auto_ptr<DicomStructureSet> result(new DicomStructureSet(dataset));
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
678
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
679 std::set<std::string> instances;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
680 result->GetReferencedInstances(instances);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
681
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
682 for (std::set<std::string>::const_iterator it = instances.begin();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
683 it != instances.end(); ++it)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
684 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
685 Json::Value lookup;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
686 MessagingToolbox::RestApiPost(lookup, orthanc, "/tools/lookup", *it);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
687
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
688 if (lookup.type() != Json::arrayValue ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
689 lookup.size() != 1 ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
690 !lookup[0].isMember("Type") ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
691 !lookup[0].isMember("Path") ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
692 lookup[0]["Type"].type() != Json::stringValue ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
693 lookup[0]["ID"].type() != Json::stringValue ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
694 lookup[0]["Type"].asString() != "Instance")
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
695 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
696 throw Orthanc::OrthancException(Orthanc::ErrorCode_UnknownResource);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
697 }
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 OrthancPlugins::FullOrthancDataset slice
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
700 (orthanc, "/instances/" + lookup[0]["ID"].asString() + "/tags");
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
701 Orthanc::DicomMap m;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
702 MessagingToolbox::ConvertDataset(m, slice);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
703 result->AddReferencedSlice(m);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
704 }
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 result->CheckReferencedSlices();
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 return result.release();
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
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
711
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
712 bool DicomStructureSet::ProjectStructure(std::vector< std::vector<PolygonPoint> >& polygons,
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
713 Structure& structure,
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
714 const CoordinateSystem3D& slice)
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
715 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
716 polygons.clear();
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
717
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
718 Vector normal = GetNormal();
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
719
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
720 bool isOpposite;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
721 if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetNormal()))
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
722 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
723 // This is an axial projection
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
724
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
725 for (Polygons::iterator polygon = structure.polygons_.begin();
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
726 polygon != structure.polygons_.end(); ++polygon)
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
727 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
728 if (polygon->IsOnSlice(slice))
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
729 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
730 polygons.push_back(std::vector<PolygonPoint>());
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
731
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
732 for (Points::const_iterator p = polygon->GetPoints().begin();
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
733 p != polygon->GetPoints().end(); ++p)
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
734 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
735 double x, y;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
736 slice.ProjectPoint(x, y, *p);
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
737 polygons.back().push_back(std::make_pair(x, y));
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
738 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
739 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
740 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
741
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
742 return true;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
743 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
744 else if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisX()) ||
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
745 GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisY()))
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
746 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
747 #if 1
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
748 // Sagittal or coronal projection
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
749 std::vector<BoostPolygon> projected;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
750
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
751 for (Polygons::iterator polygon = structure.polygons_.begin();
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
752 polygon != structure.polygons_.end(); ++polygon)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
753 {
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
754 double x1, y1, x2, y2;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
755 if (polygon->Project(x1, y1, x2, y2, slice))
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
756 {
516
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
757 projected.push_back(CreateRectangle(
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
758 static_cast<float>(x1),
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
759 static_cast<float>(y1),
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
760 static_cast<float>(x2),
11fa6f00e33c Dummy changes (warnings, dummy dtor to check proper deletion, line wrapping) +
Benjamin Golinvaux <bgo@osimis.io>
parents: 439
diff changeset
761 static_cast<float>(y2)));
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
762 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
763 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
764
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
765 BoostMultiPolygon merged;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
766 Union(merged, projected);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
767
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
768 polygons.resize(merged.size());
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
769 for (size_t i = 0; i < merged.size(); i++)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
770 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
771 const std::vector<BoostPoint>& outer = merged[i].outer();
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
772
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
773 polygons[i].resize(outer.size());
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
774 for (size_t j = 0; j < outer.size(); j++)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
775 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
776 polygons[i][j] = std::make_pair(outer[j].x(), outer[j].y());
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
777 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
778 }
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
779 #else
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
780 for (Polygons::iterator polygon = structure.polygons_.begin();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
781 polygon != structure.polygons_.end(); ++polygon)
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
782 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
783 double x1, y1, x2, y2;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
784 if (polygon->Project(x1, y1, x2, y2, slice))
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
785 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
786 std::vector<PolygonPoint> p(4);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
787 p[0] = std::make_pair(x1, y1);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
788 p[1] = std::make_pair(x2, y1);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
789 p[2] = std::make_pair(x2, y2);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
790 p[3] = std::make_pair(x1, y2);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
791 polygons.push_back(p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
792 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
793 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
794 #endif
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
795
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
796 return true;
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
797 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
798 else
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
799 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
800 return false;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
801 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 }