Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/DicomStructure2.cpp @ 1200:54cbffabdc45 broker
integration mainline->broker
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 29 Nov 2019 11:03:41 +0100 |
parents | 29f5f2031310 |
children | 2d8ab34c8c91 |
rev | line source |
---|---|
998
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
1 /** |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
2 * Stone of Orthanc |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
6 * |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
7 * This program is free software: you can redistribute it and/or |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Affero General Public License |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
9 * as published by the Free Software Foundation, either version 3 of |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
10 * the License, or (at your option) any later version. |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
11 * |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
12 * This program is distributed in the hope that it will be useful, but |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
13 * WITHOUT ANY WARRANTY; without even the implied warranty of |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
15 * Affero General Public License for more details. |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
16 * |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Affero General Public License |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
19 **/ |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
20 |
1019
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
21 #ifdef BGO_ENABLE_DICOMSTRUCTURESETLOADER2 |
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
22 |
998
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
23 #include "DicomStructure2.h" |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
24 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
25 #include "../Toolbox/GeometryToolbox.h" |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
26 #include "../Toolbox/DisjointDataSet.h" |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
27 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
28 namespace OrthancStone |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
29 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
30 // see header |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
31 //void DicomStructure2::ComputeNormal() |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
32 //{ |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
33 // try |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
34 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
35 // if (polygons_.size() > 0) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
36 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
37 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
38 // // TODO: check all polygons are OK |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
39 // const DicomStructurePolygon2 polygon = polygons_[0]; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
40 // $$$$$$$$$$$$$$$$$ |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
41 // state_ = NormalComputed; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
42 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
43 // else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
44 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
45 // // bogus! no polygons. Let's assign a "nothing here" value |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
46 // LinearAlgebra::AssignVector(normal_, 0, 0, 0); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
47 // state_ = Invalid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
48 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
49 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
50 // catch (const Orthanc::OrthancException& e) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
51 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
52 // state_ = Invalid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
53 // if (e.HasDetails()) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
54 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
55 // LOG(ERROR) << "OrthancException in ComputeNormal: " << e.What() << " Details: " << e.GetDetails(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
56 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
57 // else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
58 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
59 // LOG(ERROR) << "OrthancException in ComputeNormal: " << e.What(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
60 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
61 // throw; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
62 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
63 // catch (const std::exception& e) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
64 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
65 // state_ = Invalid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
66 // LOG(ERROR) << "std::exception in ComputeNormal: " << e.what(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
67 // throw; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
68 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
69 // catch (...) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
70 // { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
71 // state_ = Invalid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
72 // LOG(ERROR) << "Unknown exception in ComputeNormal"; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
73 // throw; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
74 // } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
75 //} |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
76 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
77 void DicomStructure2::ComputeSliceThickness() |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
78 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
79 if (state_ != NormalComputed) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
80 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
81 LOG(ERROR) << "DicomStructure2::ComputeSliceThickness - state must be NormalComputed"; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
82 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
83 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
84 if (polygons_.size() < 2) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
85 { |
1019
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
86 // cannot compute thickness if there are not at least 2 slabs (structures) |
998
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
87 sliceThickness_ = 1.0; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
88 state_ = Invalid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
89 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
90 else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
91 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
92 // normal can be (1,0,0), (0,1,0) or (0,0,1), nothing else. |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
93 // these can be compared with == (exact double representation) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
94 if (normal_[0] == 1) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
95 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
96 // in a single polygon, all the points have the same X |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
97 sliceThickness_ = fabs(polygons_[0].GetPoint(0)[0] - polygons_[1].GetPoint(0)[0]); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
98 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
99 else if (normal_[1] == 1) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
100 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
101 // in a single polygon, all the points have the same X |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
102 sliceThickness_ = fabs(polygons_[0].GetPoint(0)[1] - polygons_[1].GetPoint(0)[1]); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
103 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
104 else if (normal_[2] == 1) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
105 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
106 // in a single polygon, all the points have the same X |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
107 sliceThickness_ = fabs(polygons_[0].GetPoint(0)[2] - polygons_[1].GetPoint(0)[2]); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
108 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
109 else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
110 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
111 ORTHANC_ASSERT(false); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
112 state_ = Invalid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
113 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
114 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
115 state_ = Valid; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
116 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
117 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
118 void DicomStructure2::AddPolygon(const DicomStructurePolygon2& polygon) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
119 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
120 if (state_ != Building) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
121 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
122 LOG(ERROR) << "DicomStructure2::AddPolygon - can only add polygon while building"; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
123 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
124 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
125 polygons_.push_back(polygon); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
126 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
127 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
128 void DicomStructure2::ComputeDependentProperties() |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
129 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
130 if (state_ != Building) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
131 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
132 LOG(ERROR) << "DicomStructure2::ComputeDependentProperties - can only be called once"; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
133 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
134 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
135 for (size_t i = 0; i < polygons_.size(); ++i) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
136 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
137 // "compute" the polygon normal |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
138 polygons_[i].ComputeDependentProperties(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
139 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
140 if (polygons_.size() > 0) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
141 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
142 normal_ = polygons_[0].GetNormal(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
143 state_ = NormalComputed; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
144 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
145 else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
146 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
147 LinearAlgebra::AssignVector(normal_, 0, 0, 0); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
148 state_ = Invalid; // THIS MAY HAPPEN !!! (for instance for instance 72c773ac-5059f2c4-2e6a9120-4fd4bca1-45701661 :) ) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
149 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
150 if (polygons_.size() >= 2) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
151 ComputeSliceThickness(); // this will change state_ from NormalComputed to Valid |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
152 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
153 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
154 OrthancStone::Vector DicomStructure2::GetNormal() const |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
155 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
156 if (state_ != Valid && state_ != Invalid) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
157 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
158 LOG(ERROR) << "DicomStructure2::GetNormal() -- please call ComputeDependentProperties first."; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
159 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
160 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
161 if (state_ == Invalid) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
162 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
163 LOG(ERROR) << "DicomStructure2::GetNormal() -- The Dicom structure is invalid. The normal is set to 0,0,0"; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
164 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
165 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
166 return normal_; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
167 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
168 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
169 const DicomStructurePolygon2* DicomStructure2::GetPolygonClosestToSlice( |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
170 const CoordinateSystem3D& plane) const |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
171 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
172 ORTHANC_ASSERT(state_ == Valid); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
173 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
174 // we assume 0,0,1 for now |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
175 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[0], 0.0)); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
176 ORTHANC_ASSERT(LinearAlgebra::IsNear(plane.GetNormal()[1], 0.0)); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
177 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
178 for (size_t i = 0; i < polygons_.size(); ++i) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
179 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
180 const DicomStructurePolygon2& polygon = polygons_[i]; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
181 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
182 // "height" of cutting plane |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
183 double cutZ = plane.GetOrigin()[2]; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
184 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
185 if (LinearAlgebra::IsNear( |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
186 cutZ, polygon.GetZ(), |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
187 sliceThickness_ / 2.0 /* in mm */)) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
188 return &polygon; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
189 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
190 return NULL; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
191 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
192 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
193 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
194 bool DicomStructure2::Project(std::vector< std::pair<Point2D, Point2D> > & segments, const CoordinateSystem3D & plane) const |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
195 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
196 segments.clear(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
197 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
198 Vector normal = GetNormal(); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
199 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
200 size_t totalRectCount = 0; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
201 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
202 // dummy var |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
203 bool isOpposite = false; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
204 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
205 // This is an axial projection |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
206 if (GeometryToolbox::IsParallelOrOpposite(isOpposite, normal, plane.GetNormal())) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
207 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
208 const DicomStructurePolygon2* polygon = GetPolygonClosestToSlice(plane); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
209 if (polygon) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
210 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
211 polygon->ProjectOnParallelPlane(segments, plane); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
212 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
213 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
214 else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
215 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
216 // let's compute the dot product of the plane normal and the polygons |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
217 // normal. |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
218 double dot = LinearAlgebra::DotProduct(plane.GetNormal(), normal); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
219 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
220 if (LinearAlgebra::IsNear(dot, 0)) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
221 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
222 // Coronal or sagittal projection |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
223 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
224 // vector of vector of rectangles that will be merged in a single big contour: |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
225 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
226 // each polygon slab cut by a perpendicular plane yields 0..* rectangles |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
227 std::vector< RtStructRectanglesInSlab > rectanglesForEachSlab; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
228 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
229 for (size_t i = 0; i < polygons_.size(); ++i) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
230 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
231 // book an entry for this slab |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
232 rectanglesForEachSlab.push_back(RtStructRectanglesInSlab()); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
233 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
234 // let's compute the intersection between the polygon and the plane |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
235 // intersections are in plane coords |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
236 std::vector<Point2D> intersections; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
237 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
238 polygons_[i].ProjectOnConstantPlane(intersections, plane); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
239 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
240 // for each pair of intersections, we add a rectangle. |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
241 if ((intersections.size() % 2) != 0) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
242 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
243 LOG(WARNING) << "Odd number of intersections between structure " |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
244 << name_ << ", polygon # " << i |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
245 << " and plane where X axis is parallel to polygon normal vector"; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
246 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
247 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
248 size_t numRects = intersections.size() / 2; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
249 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
250 // we keep count of the total number of rects for vector pre-allocations |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
251 totalRectCount += numRects; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
252 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
253 for (size_t iRect = 0; iRect < numRects; ++iRect) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
254 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
255 RtStructRectangleInSlab rectangle; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
256 ORTHANC_ASSERT(LinearAlgebra::IsNear(intersections[2 * iRect].y, intersections[2 * iRect + 1].y)); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
257 ORTHANC_ASSERT((2 * iRect + 1) < intersections.size()); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
258 double x1 = intersections[2 * iRect].x; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
259 double x2 = intersections[2 * iRect + 1].x; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
260 double y1 = intersections[2 * iRect].y - sliceThickness_ * 0.5; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
261 double y2 = intersections[2 * iRect].y + sliceThickness_ * 0.5; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
262 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
263 rectangle.xmin = std::min(x1, x2); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
264 rectangle.xmax = std::max(x1, x2); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
265 rectangle.ymin = std::min(y1, y2); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
266 rectangle.ymax = std::max(y1, y2); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
267 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
268 // TODO: keep them sorted!!!! |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
269 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
270 rectanglesForEachSlab.back().push_back(rectangle); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
271 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
272 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
273 // now we need to merge all the slabs into a set of polygons (1 or more) |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
274 ConvertListOfSlabsToSegments(segments, rectanglesForEachSlab, totalRectCount); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
275 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
276 else |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
277 { |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
278 // plane is not perpendicular to the polygons |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
279 // 180.0 / [Math]::Pi = 57.2957795130823 |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
280 double acDot = 57.2957795130823 * acos(dot); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
281 LOG(ERROR) << "DicomStructure2::Project -- cutting plane must be " |
1019
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
282 << "perpendicular to the structures, but dot product is: " |
998
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
283 << dot << " and (180/pi)*acos(dot) = " << acDot; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
284 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
285 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
286 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
287 return segments.size() != 0; |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
288 } |
38b6bb0bdd72
added a new set of classes that correctly handle non-convex polygons (not
Benjamin Golinvaux <bgo@osimis.io>
parents:
diff
changeset
|
289 } |
1019
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
290 |
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
291 #endif |
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
292 // BGO_ENABLE_DICOMSTRUCTURESETLOADER2 |
29f5f2031310
Added a way to specificy which structures are to be initially displayed (the
Benjamin Golinvaux <bgo@osimis.io>
parents:
998
diff
changeset
|
293 |