annotate OrthancStone/Sources/Toolbox/DicomStructureSet.cpp @ 1892:cdf91ad891a5

estimated geometry of rt-struct
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 19 Jan 2022 13:50:28 +0100
parents 6ce81914f7e4
children 90b5e116a5f9
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
1871
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium
7053b8a0aaec upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1870
diff changeset
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 * This program is free software: you can redistribute it and/or
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
9 * modify it under the terms of the GNU Lesser General Public License
47
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
10 * as published by the Free Software Foundation, either version 3 of
28956ed68280 agpl license
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 40
diff changeset
11 * the License, or (at your option) any later version.
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 *
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 * 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
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
16 * Lesser General Public License for more details.
1596
4fb8fdf03314 removed annoying whitespace
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1571
diff changeset
17 *
1598
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
19 * License along with this program. If not, see
8563ea5d8ae4 relicensing some files, cf. osimis bm26 and chu agreement on 2020-05-20
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1596
diff changeset
20 * <http://www.gnu.org/licenses/>.
0
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
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24 #include "DicomStructureSet.h"
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
25 #include "DicomStructureSetUtils.h"
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
27 #include "GeometryToolbox.h"
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
28 #include "GenericToolbox.h"
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
29
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
30 #include "OrthancDatasets/DicomDatasetReader.h"
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
32 #include "BucketAccumulator2D.h"
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
33
1455
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
34 #include <Logging.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
35 #include <OrthancException.h>
30deba7bc8e2 simplifying include_directories
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1279
diff changeset
36 #include <Toolbox.h>
113
2eca030792aa using the Orthanc Framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 110
diff changeset
37
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
38 #if defined(_MSC_VER)
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
39 # pragma warning(push)
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
40 # pragma warning(disable:4244)
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
41 #endif
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
42
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
43 #if STONE_TIME_BLOCKING_OPS
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
44 # include <boost/date_time/posix_time/posix_time.hpp>
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
45 #endif
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
46
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
47 #include <limits>
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48 #include <stdio.h>
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
49 #include <boost/math/constants/constants.hpp>
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
50 #include <boost/geometry.hpp>
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
51 #include <boost/geometry/geometries/point_xy.hpp>
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
52 #include <boost/geometry/geometries/polygon.hpp>
137
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 135
diff changeset
53 #include <boost/geometry/multi/geometries/multi_polygon.hpp>
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
54
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
55 #if defined(_MSC_VER)
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
56 # pragma warning(pop)
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
57 #endif
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
58
1180
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
59 #if ORTHANC_ENABLE_DCMTK == 1
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
60 # include "ParsedDicomDataset.h"
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
61 #endif
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
62
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
63
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
64 typedef boost::geometry::model::d2::point_xy<double> BoostPoint;
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
65 typedef boost::geometry::model::polygon<BoostPoint> BoostPolygon;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
66 typedef boost::geometry::model::multi_polygon<BoostPolygon> BoostMultiPolygon;
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
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
69 static void Union(BoostMultiPolygon& output,
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
70 std::vector<BoostPolygon>& input)
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 for (size_t i = 0; i < input.size(); i++)
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 boost::geometry::correct(input[i]);
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
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
77 if (input.size() == 0)
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 output.clear();
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
80 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
81 else if (input.size() == 1)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
82 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
83 output.resize(1);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
84 output[0] = input[0];
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 else
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
87 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
88 boost::geometry::union_(input[0], input[1], output);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
89
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
90 for (size_t i = 0; i < input.size(); i++)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
91 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
92 BoostMultiPolygon tmp;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
93 boost::geometry::union_(output, input[i], tmp);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
94 output = tmp;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
95 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
96 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
97 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
98
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
99 #if USE_BOOST_UNION_FOR_POLYGONS == 1
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
100
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
101 static BoostPolygon CreateRectangle(float x1, float y1,
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
102 float x2, float y2)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
103 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
104 BoostPolygon r;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
105 boost::geometry::append(r, BoostPoint(x1, y1));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
106 boost::geometry::append(r, BoostPoint(x1, y2));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
107 boost::geometry::append(r, BoostPoint(x2, y2));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
108 boost::geometry::append(r, BoostPoint(x2, y1));
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
109 return r;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
110 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
111
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
112 #else
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
113
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
114 namespace OrthancStone
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
115 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
116 static RtStructRectangleInSlab CreateRectangle(float x1, float y1,
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
117 float x2, float y2)
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
118 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
119 RtStructRectangleInSlab rect;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
120 rect.xmin = std::min(x1, x2);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
121 rect.xmax = std::max(x1, x2);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
122 rect.ymin = std::min(y1, y2);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
123 rect.ymax = std::max(y1, y2);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
124 return rect;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
125 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
126
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
127 bool CompareRectanglesForProjection(const std::pair<RtStructRectangleInSlab,double>& r1, const std::pair<RtStructRectangleInSlab, double>& r2)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
128 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
129 return r1.second < r2.second;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
130 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
131
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
132 bool CompareSlabsY(const RtStructRectanglesInSlab& r1, const RtStructRectanglesInSlab& r2)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
133 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
134 if ((r1.size() == 0) || (r2.size() == 0))
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
135 return false;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
136
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
137 return r1[0].ymax < r2[0].ymax;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
138 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
139 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
140
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
141 #endif
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 namespace OrthancStone
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 {
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
145 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_GEOMETRIC_TYPE(0x3006, 0x0042);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
146 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_IMAGE_SEQUENCE(0x3006, 0x0016);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
147 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_SEQUENCE(0x3006, 0x0040);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
148 static const Orthanc::DicomTag DICOM_TAG_CONTOUR_DATA(0x3006, 0x0050);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
149 static const Orthanc::DicomTag DICOM_TAG_NUMBER_OF_CONTOUR_POINTS(0x3006, 0x0046);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
150 static const Orthanc::DicomTag DICOM_TAG_REFERENCED_SOP_INSTANCE_UID(0x0008, 0x1155);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
151 static const Orthanc::DicomTag DICOM_TAG_ROI_CONTOUR_SEQUENCE(0x3006, 0x0039);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
152 static const Orthanc::DicomTag DICOM_TAG_ROI_DISPLAY_COLOR(0x3006, 0x002a);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
153 static const Orthanc::DicomTag DICOM_TAG_ROI_NAME(0x3006, 0x0026);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
154 static const Orthanc::DicomTag DICOM_TAG_RT_ROI_INTERPRETED_TYPE(0x3006, 0x00a4);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
155 static const Orthanc::DicomTag DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE(0x3006, 0x0080);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
156 static const Orthanc::DicomTag DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE(0x3006, 0x0020);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 static uint8_t ConvertColor(double v)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 if (v < 0)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 return 0;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 else if (v >= 255)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 return 255;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 else
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 return static_cast<uint8_t>(v);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
176 static bool FastParseVector(Vector& target,
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
177 const IDicomDataset& dataset,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
178 const Orthanc::DicomPath& tag)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 {
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
180 std::string value;
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
181 return (dataset.GetStringValue(value, tag) &&
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
182 GenericToolbox::FastParseVector(target, value));
118
a4d0b6c82b29 using Orthanc::DicomMap instead of OrthancPlugins::DicomDatasetReader
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 113
diff changeset
183 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
185 void DicomStructureSet::Polygon::CheckPointIsOnSlice(const Vector& v) const
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 if (hasSlice_)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
189 double magnitude =
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
190 GeometryToolbox::ProjectAlongNormal(v, geometry_.GetNormal());
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
191 if(!LinearAlgebra::IsNear(
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
192 magnitude,
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
193 projectionAlongNormal_,
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
194 sliceThickness_ / 2.0 /* in mm */ ))
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
195 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
196 LOG(ERROR) << "This RT-STRUCT contains a point that is off the "
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
197 << "slice of its instance | "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
198 << "magnitude = " << magnitude << " | "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
199 << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
200 << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0);
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
201
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
202 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
203 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
205 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206
988
4c9b4c4de814 Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents: 981
diff changeset
207 bool DicomStructureSet::Polygon::IsPointOnSliceIfAny(const Vector& v) const
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
208 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
209 if (hasSlice_)
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
210 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
211 double magnitude =
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
212 GeometryToolbox::ProjectAlongNormal(v, geometry_.GetNormal());
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
213 bool onSlice = LinearAlgebra::IsNear(
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
214 magnitude,
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
215 projectionAlongNormal_,
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
216 sliceThickness_ / 2.0 /* in mm */);
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
217 if (!onSlice)
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
218 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
219 LOG(WARNING) << "This RT-STRUCT contains a point that is off the "
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
220 << "slice of its instance | "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
221 << "magnitude = " << magnitude << " | "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
222 << "projectionAlongNormal_ = " << projectionAlongNormal_ << " | "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
223 << "tolerance (sliceThickness_ / 2.0) = " << (sliceThickness_ / 2.0);
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
224 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
225 return onSlice;
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
226 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
227 else
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
228 {
988
4c9b4c4de814 Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents: 981
diff changeset
229 return true;
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
230 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
231 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
233 void DicomStructureSet::Polygon::AddPoint(const Vector& v)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
234 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
235 #if 1
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
236 // BGO 2019-09-03
988
4c9b4c4de814 Fixed bug in DicomStructureSet that prevented points from being added to polygons
Benjamin Golinvaux <bgo@osimis.io>
parents: 981
diff changeset
237 if (IsPointOnSliceIfAny(v))
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
238 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
239 points_.push_back(v);
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
240 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
241 #else
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
242 CheckPoint(v);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
243 points_.push_back(v);
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
244 #endif
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
245 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
246
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
247
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
248 bool DicomStructureSet::Polygon::UpdateReferencedSlice(const ReferencedSlices& slices)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
249 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
250 if (hasSlice_)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
252 return true;
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
253 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
254 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
255 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
256 ReferencedSlices::const_iterator it = slices.find(sopInstanceUid_);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
257
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
258 if (it == slices.end())
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
259 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
260 return false;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
261 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
262 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
263 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
264 const CoordinateSystem3D& geometry = it->second.geometry_;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
265
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
266 hasSlice_ = true;
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
267 geometry_ = geometry;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
268 projectionAlongNormal_ = GeometryToolbox::ProjectAlongNormal(geometry.GetOrigin(), geometry.GetNormal());
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
269 sliceThickness_ = it->second.thickness_;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270
1610
b7630b1a0253 ISceneLayer::GetBoundingBox() returns void
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1598
diff changeset
271 extent_.Clear();
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
272
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
273 for (Points::const_iterator it2 = points_.begin(); it2 != points_.end(); ++it2)
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
274 {
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
275 if (IsPointOnSliceIfAny(*it2))
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
276 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
277 double x, y;
1571
85e117739eca cppcheck
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1512
diff changeset
278 geometry.ProjectPoint2(x, y, *it2);
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
279 extent_.AddPoint(x, y);
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
280 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
281 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
282 return true;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
283 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
287 bool DicomStructureSet::Polygon::IsOnSlice(const CoordinateSystem3D& slice) const
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
288 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
289 bool isOpposite = false;
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
290
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
291 if (points_.empty() ||
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
292 !hasSlice_ ||
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
293 !GeometryToolbox::IsParallelOrOpposite(isOpposite, slice.GetNormal(), geometry_.GetNormal()))
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
294 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
295 return false;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
296 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
297
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
298 double d = GeometryToolbox::ProjectAlongNormal(slice.GetOrigin(), geometry_.GetNormal());
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
299
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
300 return (LinearAlgebra::IsNear(d, projectionAlongNormal_,
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
301 sliceThickness_ / 2.0));
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
302 }
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
303
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
304 bool DicomStructureSet::Polygon::Project(double& x1,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
305 double& y1,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
306 double& x2,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
307 double& y2,
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
308 const CoordinateSystem3D& slice) const
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
309 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
310 // TODO: optimize this method using a sweep-line algorithm for polygons
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
311
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
312 if (!hasSlice_ ||
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
313 points_.size() <= 1)
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
314 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
315 return false;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
316 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
317
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
318 double x, y;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
319 geometry_.ProjectPoint2(x, y, slice.GetOrigin());
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
320
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
321 bool isOpposite;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
322 if (GeometryToolbox::IsParallelOrOpposite
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
323 (isOpposite, slice.GetNormal(), geometry_.GetAxisY()))
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
324 {
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
325 // plane is constant Y
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
326
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
327 if (y < extent_.GetY1() ||
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
328 y > extent_.GetY2())
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
329 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
330 // The polygon does not intersect the input slice
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
331 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
332 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
333
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
334 bool isFirst = true;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
335 double xmin = std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
336 double xmax = -std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
337
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
338 double prevX, prevY;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
339 geometry_.ProjectPoint2(prevX, prevY, points_[points_.size() - 1]);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
340
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
341 for (size_t i = 0; i < points_.size(); i++)
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
342 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
343 // Reference: ../../Resources/Computations/IntersectSegmentAndHorizontalLine.py
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
344 double curX, curY;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
345 geometry_.ProjectPoint2(curX, curY, points_[i]);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
346
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
347 // if prev* and cur* are on opposite sides of y, this means that the
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
348 // segment intersects the plane.
1838
80e029f8ec91 fix wrong display of RTStruct when an RTStruct point has exactly the same X or Y coordinates as the origin
Alain Mazy <alain@mazy.be>
parents: 1834
diff changeset
349 if ((prevY <= y && curY >= y) ||
80e029f8ec91 fix wrong display of RTStruct when an RTStruct point has exactly the same X or Y coordinates as the origin
Alain Mazy <alain@mazy.be>
parents: 1834
diff changeset
350 (prevY >= y && curY <= y))
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
351 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
352 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
353 xmin = std::min(xmin, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
354 xmax = std::max(xmax, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
355 isFirst = false;
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
356
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
357 // xmin and xmax represent the extent of the rectangle along the
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
358 // intersection between the plane and the polygon geometry
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
359
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
360 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
361
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
362 prevX = curX;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
363 prevY = curY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
364 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
365
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
366 // if NO segment intersects the plane
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
367 if (isFirst)
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
368 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
369 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
370 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
371 else
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
372 {
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
373 // y is the plane y coord in the polygon geometry
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
374 // xmin and xmax are ALSO expressed in the polygon geometry
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
375
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
376 // let's convert them to 3D world geometry...
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
377 Vector p1 = (geometry_.MapSliceToWorldCoordinates(xmin, y) +
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
378 sliceThickness_ / 2.0 * geometry_.GetNormal());
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
379 Vector p2 = (geometry_.MapSliceToWorldCoordinates(xmax, y) -
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
380 sliceThickness_ / 2.0 * geometry_.GetNormal());
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
381
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
382 // then to the cutting plane geometry...
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
383 slice.ProjectPoint2(x1, y1, p1);
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
384 slice.ProjectPoint2(x2, y2, p2);
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
385 return true;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
386 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
387 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
388 else if (GeometryToolbox::IsParallelOrOpposite
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
389 (isOpposite, slice.GetNormal(), geometry_.GetAxisX()))
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
390 {
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1162
diff changeset
391 // plane is constant X => Sagittal view (remember that in the
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1162
diff changeset
392 // sagittal projection, the normal must be swapped)
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
393
1170
1644de437a7b fixes related to swapped normal in sagittal geometry
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1162
diff changeset
394
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
395 /*
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
396 Please read the comments in the section above, by taking into account
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
397 the fact that, in this case, the plane has a constant X, not Y (in
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
398 polygon geometry_ coordinates)
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
399 */
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
400
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
401 if (x < extent_.GetX1() ||
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
402 x > extent_.GetX2())
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
403 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
404 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
405 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
406
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
407 bool isFirst = true;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
408 double ymin = std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
409 double ymax = -std::numeric_limits<double>::infinity();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
410
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
411 double prevX, prevY;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
412 geometry_.ProjectPoint2(prevX, prevY, points_[points_.size() - 1]);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
413
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
414 for (size_t i = 0; i < points_.size(); i++)
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
415 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
416 // Reference: ../../Resources/Computations/IntersectSegmentAndVerticalLine.py
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
417 double curX, curY;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
418 geometry_.ProjectPoint2(curX, curY, points_[i]);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
419
1838
80e029f8ec91 fix wrong display of RTStruct when an RTStruct point has exactly the same X or Y coordinates as the origin
Alain Mazy <alain@mazy.be>
parents: 1834
diff changeset
420 if ((prevX <= x && curX >= x) ||
80e029f8ec91 fix wrong display of RTStruct when an RTStruct point has exactly the same X or Y coordinates as the origin
Alain Mazy <alain@mazy.be>
parents: 1834
diff changeset
421 (prevX >= x && curX <= x))
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
422 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
423 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
424 ymin = std::min(ymin, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
425 ymax = std::max(ymax, p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
426 isFirst = false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
427 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
428
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
429 prevX = curX;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
430 prevY = curY;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
431 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
432
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
433 if (isFirst)
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
434 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
435 return false;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
436 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
437 else
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
438 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
439 Vector p1 = (geometry_.MapSliceToWorldCoordinates(x, ymin) +
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
440 sliceThickness_ / 2.0 * geometry_.GetNormal());
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
441 Vector p2 = (geometry_.MapSliceToWorldCoordinates(x, ymax) -
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
442 sliceThickness_ / 2.0 * geometry_.GetNormal());
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
443
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
444 slice.ProjectPoint2(x1, y1, p1);
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
445 slice.ProjectPoint2(x2, y2, p2);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
446
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
447 return true;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
448 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
449 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
450 else
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
451 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
452 // Should not happen
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
453 return false;
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
454 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
455 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
456
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
457
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458 const DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 if (index >= structures_.size())
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 {
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
462 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 return structures_[index];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
469 DicomStructureSet::Structure& DicomStructureSet::GetStructure(size_t index)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470 {
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
471 if (index >= structures_.size())
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
472 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
473 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
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
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 return structures_[index];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
479 void DicomStructureSet::Setup(const IDicomDataset& tags)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 {
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
481 #if STONE_TIME_BLOCKING_OPS
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
482 boost::posix_time::ptime timerStart = boost::posix_time::microsec_clock::universal_time();
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
483 #endif
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
484
1504
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1455
diff changeset
485 DicomDatasetReader reader(tags);
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
486
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
487 size_t count, tmp;
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
488 if (!tags.GetSequenceSize(count, Orthanc::DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE)) ||
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
489 !tags.GetSequenceSize(tmp, Orthanc::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE)) ||
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
490 tmp != count ||
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
491 !tags.GetSequenceSize(tmp, Orthanc::DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE)) ||
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
492 tmp != count)
0
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 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
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
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
497 structures_.resize(count);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
498 for (size_t i = 0; i < count; i++)
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
499 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
500 structures_[i].interpretation_ = reader.GetStringValue
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
501 (Orthanc::DicomPath(DICOM_TAG_RT_ROI_OBSERVATIONS_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
502 DICOM_TAG_RT_ROI_INTERPRETED_TYPE),
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
503 "No interpretation");
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
505 structures_[i].name_ = reader.GetStringValue
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
506 (Orthanc::DicomPath(DICOM_TAG_STRUCTURE_SET_ROI_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
507 DICOM_TAG_ROI_NAME),
949
32eaf4929b08 OrthancMultiframeVolumeLoader and OrthancSeriesVolumeProgressiveLoader now implement IGeometryProvider so that the geometry reference can be switched (CT or DOSE, for instance) + VolumeImageGeometry::SetSize renamed to VolumeImageGeometry::SetSizeInVoxels + prevent text layer update if text or properties do not change + a few stream operator<< for debug (Vector, Matrix,...) + fixed memory access aligment issues in ImageBuffer3D::ExtractSagittalSlice + fix for wrong screen Y offset of mpr slices in DicomVolumeImageMPRSlicer.
Benjamin Golinvaux <bgo@osimis.io>
parents: 841
diff changeset
508 "No name");
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 Vector color;
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
511 if (FastParseVector(color, tags, Orthanc::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
512 DICOM_TAG_ROI_DISPLAY_COLOR)) &&
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
513 color.size() == 3)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
515 structures_[i].red_ = ConvertColor(color[0]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
516 structures_[i].green_ = ConvertColor(color[1]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
517 structures_[i].blue_ = ConvertColor(color[2]);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
518 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
519 else
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
520 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
521 structures_[i].red_ = 255;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
522 structures_[i].green_ = 0;
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
523 structures_[i].blue_ = 0;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
526 size_t countSlices;
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
527 if (!tags.GetSequenceSize(countSlices, Orthanc::DicomPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
528 DICOM_TAG_CONTOUR_SEQUENCE)))
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
529 {
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
530 countSlices = 0;
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
531 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532
841
266e2b0b9abc better error reporting in DicomStructureSetLoader + fixed POST request logic
Benjamin Golinvaux <bgo@osimis.io>
parents: 804
diff changeset
533 LOG(INFO) << "New RT structure: \"" << structures_[i].name_
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
534 << "\" with interpretation \"" << structures_[i].interpretation_
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
535 << "\" containing " << countSlices << " slices (color: "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
536 << static_cast<int>(structures_[i].red_) << ","
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
537 << static_cast<int>(structures_[i].green_) << ","
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
538 << static_cast<int>(structures_[i].blue_) << ")";
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
540 /**
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
541 * These temporary variables avoid allocating many vectors in
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
542 * the loop below (indeed, "Orthanc::DicomPath" handles a
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
543 * "std::vector<PrefixItem>")
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
544 **/
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
545 Orthanc::DicomPath countPointsPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
546 DICOM_TAG_CONTOUR_SEQUENCE, 0,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
547 DICOM_TAG_NUMBER_OF_CONTOUR_POINTS);
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
548
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
549 Orthanc::DicomPath geometricTypePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
550 DICOM_TAG_CONTOUR_SEQUENCE, 0,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
551 DICOM_TAG_CONTOUR_GEOMETRIC_TYPE);
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
552
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
553 Orthanc::DicomPath imageSequencePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
554 DICOM_TAG_CONTOUR_SEQUENCE, 0,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
555 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE);
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
556
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
557 // (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
558 Orthanc::DicomPath referencedInstancePath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
559 DICOM_TAG_CONTOUR_SEQUENCE, 0,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
560 DICOM_TAG_CONTOUR_IMAGE_SEQUENCE, 0,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
561 DICOM_TAG_REFERENCED_SOP_INSTANCE_UID);
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
562
1834
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
563 Orthanc::DicomPath contourDataPath(DICOM_TAG_ROI_CONTOUR_SEQUENCE, i,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
564 DICOM_TAG_CONTOUR_SEQUENCE, 0,
126522623e20 replaced OrthancStone::DicomPath by new class Orthanc::DicomPath from orthanc framework
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1754
diff changeset
565 DICOM_TAG_CONTOUR_DATA);
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
566
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
567 for (size_t j = 0; j < countSlices; j++)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 {
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
569 unsigned int countPoints;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
571 countPointsPath.SetPrefixIndex(1, j);
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
572 if (!reader.GetUnsignedIntegerValue(countPoints, countPointsPath))
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
573 {
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
574 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
575 }
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
576
121
e66b2c757790 displaying rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 118
diff changeset
577 //LOG(INFO) << "Parsing slice containing " << countPoints << " vertices";
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
579 geometricTypePath.SetPrefixIndex(1, j);
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
580 std::string type = reader.GetMandatoryStringValue(geometricTypePath);
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
581 if (type != "CLOSED_PLANAR")
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 {
173
6b0411ac843a fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
583 LOG(WARNING) << "Ignoring contour with geometry type: " << type;
6b0411ac843a fix captain rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 159
diff changeset
584 continue;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 }
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 size_t size;
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
588
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
589 imageSequencePath.SetPrefixIndex(1, j);
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
590 if (!tags.GetSequenceSize(size, imageSequencePath) || size != 1)
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
591 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
592 LOG(ERROR) << "The ContourImageSequence sequence (tag 3006,0016) must be present and contain one entry.";
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595
786
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
596 referencedInstancePath.SetPrefixIndex(1, j);
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
597 std::string sopInstanceUid = reader.GetMandatoryStringValue(referencedInstancePath);
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
598
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
599 contourDataPath.SetPrefixIndex(1, j);
5aa728500586 optimizing constructor of DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 738
diff changeset
600 std::string slicesData = reader.GetMandatoryStringValue(contourDataPath);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 Vector points;
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
603
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
604 if (!GenericToolbox::FastParseVector(points, slicesData) ||
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
605 points.size() != 3 * countPoints)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
610 // seen in real world
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
611 if(Orthanc::Toolbox::StripSpaces(sopInstanceUid) == "")
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
612 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
613 LOG(ERROR) << "WARNING. The following Dicom tag (Referenced SOP Instance UID) contains an empty value : // (3006,0039)[" << i << "] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)";
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
614 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
615
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
616 Polygon polygon(sopInstanceUid);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
617 polygon.Reserve(countPoints);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618
32
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 31
diff changeset
619 for (size_t k = 0; k < countPoints; k++)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 Vector v(3);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 v[0] = points[3 * k];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 v[1] = points[3 * k + 1];
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 v[2] = points[3 * k + 2];
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
625 polygon.AddPoint(v);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 structures_[i].polygons_.push_back(polygon);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 }
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
631
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
632 EstimateGeometry();
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
633
1751
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
634 #if STONE_TIME_BLOCKING_OPS
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
635 boost::posix_time::ptime timerEnd = boost::posix_time::microsec_clock::universal_time();
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
636 boost::posix_time::time_duration duration = timerEnd - timerStart;
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
637 int64_t durationMs = duration.total_milliseconds();
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
638 LOG(WARNING) << "DicomStructureSet::Setup took " << durationMs << " ms";
946eb7200b82 FastParseVector usage + timing instrumentation guarded by STONE_TIME_BLOCKING_OPS
Benjamin Golinvaux <bgo@osimis.io>
parents: 1739
diff changeset
639 #endif
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642
1180
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
643 #if ORTHANC_ENABLE_DCMTK == 1
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
644 DicomStructureSet::DicomStructureSet(Orthanc::ParsedDicomFile& instance)
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
645 {
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
646 ParsedDicomDataset dataset(instance);
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
647 Setup(dataset);
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
648 }
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
649 #endif
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
650
9c8f557ea799 ParsedDicomDataset to speed up loading RT-STRUCT from parsed DICOM files
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1178
diff changeset
651
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 Vector DicomStructureSet::GetStructureCenter(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 const Structure& structure = GetStructure(index);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 Vector center;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
657 LinearAlgebra::AssignVector(center, 0, 0, 0);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 if (structure.polygons_.empty())
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 return center;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663 double n = static_cast<double>(structure.polygons_.size());
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 for (Polygons::const_iterator polygon = structure.polygons_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 polygon != structure.polygons_.end(); ++polygon)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
668 if (!polygon->GetPoints().empty())
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
670 center += polygon->GetPoints().front() / n;
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674 return center;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 const std::string& DicomStructureSet::GetStructureName(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 return GetStructure(index).name_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 const std::string& DicomStructureSet::GetStructureInterpretation(size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 return GetStructure(index).interpretation_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
804
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
690 Color DicomStructureSet::GetStructureColor(size_t index) const
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
691 {
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
692 const Structure& s = GetStructure(index);
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
693 return Color(s.red_, s.green_, s.blue_);
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
694 }
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
695
61ba4b504e9a PolylineSceneLayer now has one color per chain
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 794
diff changeset
696
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697 void DicomStructureSet::GetStructureColor(uint8_t& red,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 uint8_t& green,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 uint8_t& blue,
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 size_t index) const
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 const Structure& s = GetStructure(index);
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 red = s.red_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 green = s.green_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705 blue = s.blue_;
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708
1885
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
709 void DicomStructureSet::GetReferencedInstances(std::set<std::string>& instances) const
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 for (Structures::const_iterator structure = structures_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 structure != structures_.end(); ++structure)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713 {
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 for (Polygons::const_iterator polygon = structure->polygons_.begin();
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 polygon != structure->polygons_.end(); ++polygon)
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
717 instances.insert(polygon->GetSopInstanceUid());
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
718 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
719 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
720 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
721
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
722
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
723 void DicomStructureSet::AddReferencedSlice(const std::string& sopInstanceUid,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
724 const std::string& seriesInstanceUid,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
725 const CoordinateSystem3D& geometry,
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
726 double thickness)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
727 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
728 if (referencedSlices_.find(sopInstanceUid) != referencedSlices_.end())
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
729 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
730 // This geometry is already known
956
a7351ad54960 Made IsContextLost automatically set the flag by checking with the emscripten
Benjamin Golinvaux <bgo@osimis.io>
parents: 949
diff changeset
731 LOG(ERROR) << "DicomStructureSet::AddReferencedSlice(): (referencedSlices_.find(sopInstanceUid) != referencedSlices_.end()). sopInstanceUid = " << sopInstanceUid;
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
732
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
733 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
734 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
735 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
736 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
737 if (thickness < 0)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
738 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
739 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
740 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
741
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
742 if (!referencedSlices_.empty())
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
743 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
744 const ReferencedSlice& reference = referencedSlices_.begin()->second;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
745
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
746 if (reference.seriesInstanceUid_ != seriesInstanceUid)
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747 {
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
748 LOG(ERROR) << "This RT-STRUCT refers to several different series";
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
749 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
750 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
752 if (!GeometryToolbox::IsParallel(reference.geometry_.GetNormal(), geometry.GetNormal()))
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
753 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
754 LOG(ERROR) << "The slices in this RT-STRUCT are not parallel";
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
755 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
756 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
757 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
758
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
759 referencedSlices_[sopInstanceUid] = ReferencedSlice(seriesInstanceUid, geometry, thickness);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
761 for (Structures::iterator structure = structures_.begin();
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
762 structure != structures_.end(); ++structure)
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
763 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
764 for (Polygons::iterator polygon = structure->polygons_.begin();
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
765 polygon != structure->polygons_.end(); ++polygon)
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
766 {
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
767 polygon->UpdateReferencedSlice(referencedSlices_);
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
768 }
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
769 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
770 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
771 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
772
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
773
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
774 void DicomStructureSet::AddReferencedSlice(const Orthanc::DicomMap& dataset)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
775 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
776 CoordinateSystem3D slice(dataset);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
777
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
778 double thickness = 1; // 1 mm by default
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
780 std::string s;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
781 Vector v;
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 988
diff changeset
782 if (dataset.LookupStringValue(s, Orthanc::DICOM_TAG_SLICE_THICKNESS, false) &&
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
783 LinearAlgebra::ParseVector(v, s) &&
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
784 v.size() > 0)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
785 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
786 thickness = v[0];
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
787 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
788
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
789 std::string instance, series;
994
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 988
diff changeset
790 if (dataset.LookupStringValue(instance, Orthanc::DICOM_TAG_SOP_INSTANCE_UID, false) &&
1f74bc3459ba fix build due to rename in Orthanc::DicomMap
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 988
diff changeset
791 dataset.LookupStringValue(series, Orthanc::DICOM_TAG_SERIES_INSTANCE_UID, false))
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
792 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
793 AddReferencedSlice(instance, series, slice, thickness);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
794 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
795 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
796 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
797 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat);
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
798 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
799 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
800
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
801
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
802 void DicomStructureSet::CheckReferencedSlices()
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
803 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
804 for (Structures::iterator structure = structures_.begin();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
805 structure != structures_.end(); ++structure)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
806 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
807 for (Polygons::iterator polygon = structure->polygons_.begin();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
808 polygon != structure->polygons_.end(); ++polygon)
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
809 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
810 if (!polygon->UpdateReferencedSlice(referencedSlices_))
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
811 {
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
812 std::string sopInstanceUid = polygon->GetSopInstanceUid();
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
813 if (Orthanc::Toolbox::StripSpaces(sopInstanceUid) == "")
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
814 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
815 LOG(ERROR) << "DicomStructureSet::CheckReferencedSlices(): "
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
816 << " missing information about referenced instance "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
817 << "(sopInstanceUid is empty!)";
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
818 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
819 else
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
820 {
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
821 LOG(ERROR) << "DicomStructureSet::CheckReferencedSlices(): "
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
822 << " missing information about referenced instance "
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
823 << "(sopInstanceUid = " << sopInstanceUid << ")";
981
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
824 }
c20dbaab360c Ability to cope with empty "Referenced SOP Instance UID" (dicom path (3006,0039)[i] / (0x3006, 0x0040)[0] / (0x3006, 0x0016)[0] / (0x0008, 0x1155)) + better logs + code formating
Benjamin Golinvaux <bgo@osimis.io>
parents: 959
diff changeset
825 //throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827 }
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 }
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
829 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
831
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
832 Vector DicomStructureSet::GetNormal() const
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
833 {
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
834 if (referencedSlices_.empty())
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
835 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
836 Vector v;
158
a053ca7fa5c6 LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 137
diff changeset
837 LinearAlgebra::AssignVector(v, 0, 0, 1);
122
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
838 return v;
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
839 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
840 else
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
841 {
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
842 return referencedSlices_.begin()->second.geometry_.GetNormal();
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
843 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
844 }
e3433dabfb8d refactoring DicomStructureSet
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 121
diff changeset
845
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
846 bool DicomStructureSet::ProjectStructure(
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
847 #if USE_BOOST_UNION_FOR_POLYGONS == 1
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
848 std::vector< std::vector<Point2D> >& polygons,
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
849 #else
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
850 std::vector< std::pair<Point2D, Point2D> >& segments,
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
851 #endif
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
852 const Structure& structure,
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
853 const CoordinateSystem3D& sourceSlice) const
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
854 {
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
855 const CoordinateSystem3D slice = CoordinateSystem3D::NormalizeCuttingPlane(sourceSlice);
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
856
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
857 #if USE_BOOST_UNION_FOR_POLYGONS == 1
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
858 polygons.clear();
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
859 #else
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
860 segments.clear();
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
861 #endif
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
862
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
863 Vector normal = GetNormal();
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
864
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
865 bool isOpposite;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
866 if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetNormal()))
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
867 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
868 // This is an axial projection
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
869
794
04f518ebd132 LoaderStateMachine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
870 for (Polygons::const_iterator polygon = structure.polygons_.begin();
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
871 polygon != structure.polygons_.end(); ++polygon)
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
872 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
873 if (polygon->IsOnSlice(slice))
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
874 {
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
875 #if USE_BOOST_UNION_FOR_POLYGONS == 1
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
876 polygons.push_back(std::vector<Point2D>());
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
877
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
878 for (Points::const_iterator p = polygon->GetPoints().begin();
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
879 p != polygon->GetPoints().end(); ++p)
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
880 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
881 double x, y;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
882 slice.ProjectPoint2(x, y, *p);
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
883 polygons.back().push_back(Point2D(x, y));
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
884 }
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
885 #else
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
886 // we need to add all the segments corresponding to this polygon
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
887 const std::vector<Vector>& points3D = polygon->GetPoints();
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
888 if (points3D.size() >= 3)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
889 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
890 Point2D prev2D;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
891 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
892 Vector prev = points3D[0];
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
893 double prevX, prevY;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
894 slice.ProjectPoint2(prevX, prevY, prev);
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
895 prev2D = Point2D(prevX, prevY);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
896 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
897
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
898 size_t pointCount = points3D.size();
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
899 for (size_t ipt = 1; ipt < pointCount; ++ipt)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
900 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
901 Vector next = points3D[ipt];
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
902 double nextX, nextY;
1013
53cc787bd7bc - Added an optimized ProjectPoint2 to CoordinateSystem3D. It has *not* replaced
Benjamin Golinvaux <bgo@osimis.io>
parents: 1006
diff changeset
903 slice.ProjectPoint2(nextX, nextY, next);
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
904 Point2D next2D(nextX, nextY);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
905 segments.push_back(std::pair<Point2D, Point2D>(prev2D, next2D));
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
906 prev2D = next2D;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
907 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
908 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
909 else
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
910 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
911 LOG(ERROR) << "Contour with less than 3 points!";
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
912 // !!!
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
913 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
914 #endif
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
915 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
916 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
917
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
918 return true;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
919 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
920 else if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisX()) ||
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
921 GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, slice.GetAxisY()))
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
922 {
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
923 #if 1
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
924 // Sagittal or coronal projection
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
925
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
926 #if USE_BOOST_UNION_FOR_POLYGONS == 1
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
927 std::vector<BoostPolygon> projected;
1162
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
928
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
929 for (Polygons::const_iterator polygon = structure.polygons_.begin();
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
930 polygon != structure.polygons_.end(); ++polygon)
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
931 {
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
932 double x1, y1, x2, y2;
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
933
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
934 if (polygon->Project(x1, y1, x2, y2, slice))
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
935 {
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
936 projected.push_back(CreateRectangle(x1, y1, x2, y2));
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
937 }
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
938 }
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
939 #else
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
940 // this will contain the intersection of the polygon slab with
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
941 // the cutting plane, projected on the cutting plane coord system
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
942 // (that yields a rectangle) + the Z coordinate of the polygon
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
943 // (this is required to group polygons with the same Z later)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
944 std::vector<std::pair<RtStructRectangleInSlab, double> > projected;
1162
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
945
794
04f518ebd132 LoaderStateMachine
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 792
diff changeset
946 for (Polygons::const_iterator polygon = structure.polygons_.begin();
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
947 polygon != structure.polygons_.end(); ++polygon)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
948 {
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
949 double x1, y1, x2, y2;
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
950
131
3e6163a53b16 optimization
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 126
diff changeset
951 if (polygon->Project(x1, y1, x2, y2, slice))
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
952 {
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
953 double curZ = polygon->GetGeometryOrigin()[2];
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
954
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
955 // x1,y1 and x2,y2 are in "slice" coordinates (the cutting plane
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
956 // geometry)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
957 projected.push_back(std::make_pair(CreateRectangle(
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
958 static_cast<float>(x1),
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
959 static_cast<float>(y1),
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
960 static_cast<float>(x2),
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
961 static_cast<float>(y2)),curZ));
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
962 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
963 }
1162
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
964 #endif
709aa65aca17 recovery of USE_BOOST_UNION_FOR_POLYGONS
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1013
diff changeset
965
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
966 #if USE_BOOST_UNION_FOR_POLYGONS != 1
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
967 // projected contains a set of rectangles specified by two opposite
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
968 // corners (x1,y1,x2,y2)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
969 // we need to merge them
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
970 // each slab yields ONE polygon!
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
971
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
972 // we need to sorted all the rectangles that originate from the same Z
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
973 // into lanes. To make sure they are grouped together in the array, we
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
974 // sort it.
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
975 std::sort(projected.begin(), projected.end(), CompareRectanglesForProjection);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
976
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
977 std::vector<RtStructRectanglesInSlab> rectanglesForEachSlab;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
978 rectanglesForEachSlab.reserve(projected.size());
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
979
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
980 double curZ = 0;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
981 for (size_t i = 0; i < projected.size(); ++i)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
982 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
983 #if 0
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
984 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab());
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
985 #else
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
986 if (i == 0)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
987 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
988 curZ = projected[i].second;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
989 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab());
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
990 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
991 else
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
992 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
993 // this check is needed to prevent creating a new slab if
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
994 // the new polygon is at the same Z coord than last one
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
995 if (!LinearAlgebra::IsNear(curZ, projected[i].second))
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
996 {
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
997 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab());
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
998 curZ = projected[i].second;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
999 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1000 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1001 #endif
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1002
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1003 rectanglesForEachSlab.back().push_back(projected[i].first);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1004
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1005 // as long as they have the same y, we should put them into the same lane
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1006 // BUT in Sebastien's code, there is only one polygon per lane.
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1007
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1008 //std::cout << "rect: xmin = " << rect.xmin << " xmax = " << rect.xmax << " ymin = " << rect.ymin << " ymax = " << rect.ymax << std::endl;
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1009 }
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1010
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1011 // now we need to sort the slabs in increasing Y order (see ConvertListOfSlabsToSegments)
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1012 std::sort(rectanglesForEachSlab.begin(), rectanglesForEachSlab.end(), CompareSlabsY);
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1013
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1014 ConvertListOfSlabsToSegments(segments, rectanglesForEachSlab, projected.size());
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1015 #else
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1016 BoostMultiPolygon merged;
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1017 Union(merged, projected);
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1018
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1019 polygons.resize(merged.size());
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1020 for (size_t i = 0; i < merged.size(); i++)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1021 {
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1022 const std::vector<BoostPoint>& outer = merged[i].outer();
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1023
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1024 polygons[i].resize(outer.size());
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1025 for (size_t j = 0; j < outer.size(); j++)
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1026 {
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1027 polygons[i][j] = Point2D(outer[j].x(), outer[j].y());
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1028 }
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1029 }
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1030 #endif
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1031
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1032 #else
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1033 for (Polygons::iterator polygon = structure.polygons_.begin();
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1034 polygon != structure.polygons_.end(); ++polygon)
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1035 {
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1036 double x1, y1, x2, y2;
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1037 if (polygon->Project(x1, y1, x2, y2, slice))
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1038 {
1000
50e5acf5553b changed RTSTRUCT rendering from polygons to segments
Benjamin Golinvaux <bgo@osimis.io>
parents: 994
diff changeset
1039 std::vector<Point2D> p(4);
132
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1040 p[0] = std::make_pair(x1, y1);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1041 p[1] = std::make_pair(x2, y1);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1042 p[2] = std::make_pair(x2, y2);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1043 p[3] = std::make_pair(x1, y2);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1044 polygons.push_back(p);
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1045 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1046 }
35c2b85836ce fix rtstruct projections
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 131
diff changeset
1047 #endif
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
1048
126
c9e88e7935a4 rt-struct projection
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 125
diff changeset
1049 return true;
125
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
1050 }
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
1051 else
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
1052 {
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
1053 return false;
44fc253d4876 refactoring
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 122
diff changeset
1054 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 }
1178
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1056
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1057
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1058 void DicomStructureSet::ProjectOntoLayer(PolylineSceneLayer& layer,
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1059 const CoordinateSystem3D& plane,
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1060 size_t structureIndex,
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1061 const Color& color) const
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1062 {
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1063 #if USE_BOOST_UNION_FOR_POLYGONS == 1
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1064 std::vector< std::vector<Point2D> > polygons;
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1065 if (ProjectStructure(polygons, structureIndex, plane))
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1066 {
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1067 for (size_t j = 0; j < polygons.size(); j++)
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1068 {
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1069 std::vector<ScenePoint2D> chain;
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1070 chain.reserve(polygons[j].size());
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1071
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1072 for (size_t k = 0; k < polygons[j].size(); k++)
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1073 {
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1074 chain.push_back(ScenePoint2D(polygons[j][k].x, polygons[j][k].y));
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1075 }
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1076
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1077 layer.AddChain(chain, true, color.GetRed(), color.GetGreen(), color.GetBlue());
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1078 }
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1079 }
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1080
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1081 #else
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1082 std::vector< std::pair<Point2D, Point2D> > segments;
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1083
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1084 if (ProjectStructure(segments, structureIndex, plane))
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1085 {
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1086 for (size_t j = 0; j < segments.size(); j++)
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1087 {
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1088 std::vector<ScenePoint2D> chain(2);
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1089 chain[0] = ScenePoint2D(segments[j].first.x, segments[j].first.y);
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1090 chain[1] = ScenePoint2D(segments[j].second.x, segments[j].second.y);
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1091 layer.AddChain(chain, false, color.GetRed(), color.GetGreen(), color.GetBlue());
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1092 }
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1093 }
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1094 #endif
3c7cdbf32e2a DicomStructureSet::ProjectOntoLayer()
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1170
diff changeset
1095 }
1885
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1096
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1097
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1098 void DicomStructureSet::GetStructurePoints(std::list< std::vector<Vector> >& target,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1099 size_t structureIndex,
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1100 const std::string& sopInstanceUid) const
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1101 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1102 target.clear();
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1103
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1104 const Structure& structure = GetStructure(structureIndex);
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1105
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1106 // TODO - Could be optimized by adding a multimap on "Structure", mapping
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1107 // from SOP Instance UID to polygons
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1108
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1109 for (Polygons::const_iterator it = structure.polygons_.begin();
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1110 it != structure.polygons_.end(); ++it)
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1111 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1112 if (it->GetSopInstanceUid() == sopInstanceUid)
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1113 {
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1114 target.push_back(it->GetPoints());
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1115 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1116 }
ddaee6b96501 retrieving rt-struct info
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1871
diff changeset
1117 }
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1118
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1119
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1120 void DicomStructureSet::EstimateGeometry()
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1121 {
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1122 static const double PI = boost::math::constants::pi<double>();
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1123
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1124 BucketAccumulator2D accumulator(0, PI, 9, /* for acos() */
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1125 -PI, PI, 9, /* for atan() */
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1126 true /* store values */);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1127
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1128 unsigned int countPolygons = 0;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1129 for (size_t i = 0; i < structures_.size(); i++)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1130 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1131 const Polygons& polygons = structures_[i].polygons_;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1132
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1133 for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++it)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1134 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1135 countPolygons++;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1136
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1137 const Points& points = it->GetPoints();
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1138
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1139 if (points.size() >= 3)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1140 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1141 // Compute the normal of the polygon using 3 successive points
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1142 Vector normal;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1143 bool valid = false;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1144
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1145 for (size_t i = 0; i + 2 < points.size(); i++)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1146 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1147 const Vector& a = points[i];
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1148 const Vector& b = points[i + 1];
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1149 const Vector& c = points[i + 2];
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1150 LinearAlgebra::CrossProduct(normal, b - a, c - a); // (*)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1151 LinearAlgebra::NormalizeVector(normal);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1152
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1153 if (LinearAlgebra::IsNear(boost::numeric::ublas::norm_2(normal), 1.0)) // (**)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1154 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1155 valid = true;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1156 break;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1157 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1158 }
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1159
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1160 if (valid)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1161 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1162 // Check that all the points of the polygon lie in the plane defined by the normal
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1163 double d1 = GeometryToolbox::ProjectAlongNormal(points[0], normal);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1164
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1165 for (size_t i = 1; i < points.size(); i++)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1166 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1167 double d2 = GeometryToolbox::ProjectAlongNormal(points[i], normal);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1168
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1169 if (!LinearAlgebra::IsNear(d1, d2))
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1170 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1171 valid = false;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1172 break;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1173 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1174 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1175 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1176
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1177 if (valid)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1178 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1179 if (normal[2] < 0)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1180 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1181 normal = -normal;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1182 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1183
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1184 // The normal is a non-zero unit vector because of (*) and (**), so "r == 1"
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1185 // https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates#Vector_fields_2
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1186
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1187 const double theta = acos(normal[2]);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1188 const double phi = atan(normal[1]);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1189 accumulator.AddValue(theta, phi);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1190 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1191 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1192 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1193 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1194
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1195 size_t bestX, bestY;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1196 accumulator.FindBestBucket(bestX, bestY);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1197
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1198 if (accumulator.GetBucketContentSize(bestX, bestY) > 0)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1199 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1200 double normalTheta, normalPhi;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1201 accumulator.ComputeBestMedian(normalTheta, normalPhi);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1202
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1203 // Back to (x,y,z) normal, taking "r == 1"
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1204 // https://en.wikipedia.org/wiki/Vector_fields_in_cylindrical_and_spherical_coordinates#Vector_fields_2
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1205 double sinTheta = sin(normalTheta);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1206 estimatedNormal_ = LinearAlgebra::CreateVector(sinTheta * cos(normalPhi), sinTheta * sin(normalPhi), cos(normalTheta));
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1207 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1208
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1209 std::vector<double> polygonsProjection;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1210 polygonsProjection.reserve(countPolygons);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1211
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1212 for (size_t i = 0; i < structures_.size(); i++)
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1213 {
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1214 const Polygons& polygons = structures_[i].polygons_;
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1215
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1216 for (Polygons::const_iterator it = polygons.begin(); it != polygons.end(); ++it)
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1217 {
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1218 const Points& points = it->GetPoints();
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1219 polygonsProjection.push_back(GeometryToolbox::ProjectAlongNormal(points[0], estimatedNormal_));
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1220 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1221 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1222
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1223 std::sort(polygonsProjection.begin(), polygonsProjection.end());
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1224
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1225 std::vector<double> deltas;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1226 deltas.reserve(polygonsProjection.size());
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1227
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1228 for (size_t i = 0; i + 1 < polygonsProjection.size(); i++)
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1229 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1230 if (!LinearAlgebra::IsNear(polygonsProjection[i], polygonsProjection[i + 1]))
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1231 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1232 assert(polygonsProjection[i + 1] > polygonsProjection[i]);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1233 deltas.push_back(polygonsProjection[i + 1] - polygonsProjection[i]);
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1234 }
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1235 }
1892
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1236
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1237 if (deltas.empty())
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1238 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1239 estimatedSliceThickness_ = 1;
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1240 }
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1241 else
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1242 {
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1243 estimatedSliceThickness_ = LinearAlgebra::ComputeMedian(deltas);
cdf91ad891a5 estimated geometry of rt-struct
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1890
diff changeset
1244 }
1890
6ce81914f7e4 added classes BucketAccumulator1D/2D
Sebastien Jodogne <s.jodogne@gmail.com>
parents: 1885
diff changeset
1245 }
0
351ab0da0150 initial commit
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 }