Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/ParallelSlices.cpp @ 260:c887eddd48f1 am-2
merge
author | am@osimis.io |
---|---|
date | Tue, 17 Jul 2018 14:43:42 +0200 |
parents | 5412adf19980 |
children | b70e9be013e4 |
rev | line source |
---|---|
0 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
134
4cff7b1ed31d
upgrade to year 2018
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium |
0 | 6 * |
7 * This program is free software: you can redistribute it and/or | |
47 | 8 * modify it under the terms of the GNU Affero General Public License |
9 * as published by the Free Software Foundation, either version 3 of | |
10 * the License, or (at your option) any later version. | |
0 | 11 * |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
47 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Affero General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Affero General Public License | |
0 | 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 **/ | |
20 | |
21 | |
22 #include "ParallelSlices.h" | |
23 | |
159
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
24 #include "GeometryToolbox.h" |
0a73d76333db
populating LinearAlgebra
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
158
diff
changeset
|
25 |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
26 #include <Core/Logging.h> |
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
27 #include <Core/OrthancException.h> |
0 | 28 |
29 namespace OrthancStone | |
30 { | |
31 ParallelSlices::ParallelSlices() | |
32 { | |
158
a053ca7fa5c6
LinearAlgebra toolbox
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
135
diff
changeset
|
33 LinearAlgebra::AssignVector(normal_, 0, 0, 1); |
0 | 34 } |
35 | |
36 | |
37 ParallelSlices::ParallelSlices(const ParallelSlices& other) | |
38 { | |
39 normal_ = other.normal_; | |
40 | |
41 slices_.resize(other.slices_.size()); | |
42 | |
43 for (size_t i = 0; i < slices_.size(); i++) | |
44 { | |
45 assert(other.slices_[i] != NULL); | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
46 slices_[i] = new CoordinateSystem3D(*other.slices_[i]); |
0 | 47 } |
48 } | |
49 | |
50 | |
51 ParallelSlices::~ParallelSlices() | |
52 { | |
53 for (size_t i = 0; i < slices_.size(); i++) | |
54 { | |
55 if (slices_[i] != NULL) | |
56 { | |
57 delete slices_[i]; | |
58 slices_[i] = NULL; | |
59 } | |
60 } | |
61 } | |
62 | |
63 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
64 void ParallelSlices::AddSlice(const CoordinateSystem3D& slice) |
0 | 65 { |
66 if (slices_.empty()) | |
67 { | |
68 normal_ = slice.GetNormal(); | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
69 slices_.push_back(new CoordinateSystem3D(slice)); |
0 | 70 } |
71 else if (GeometryToolbox::IsParallel(slice.GetNormal(), normal_)) | |
72 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
73 slices_.push_back(new CoordinateSystem3D(slice)); |
0 | 74 } |
75 else | |
76 { | |
77 LOG(ERROR) << "Trying to add a slice that is not parallel to the previous ones"; | |
78 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); | |
79 } | |
80 } | |
81 | |
82 | |
83 void ParallelSlices::AddSlice(const Vector& origin, | |
84 const Vector& axisX, | |
85 const Vector& axisY) | |
86 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
87 CoordinateSystem3D slice(origin, axisX, axisY); |
0 | 88 AddSlice(slice); |
89 } | |
90 | |
91 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
92 const CoordinateSystem3D& ParallelSlices::GetSlice(size_t index) const |
0 | 93 { |
94 if (index >= slices_.size()) | |
95 { | |
96 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); | |
97 } | |
98 else | |
99 { | |
100 return *slices_[index]; | |
101 } | |
102 } | |
103 | |
104 | |
105 bool ParallelSlices::ComputeClosestSlice(size_t& closestSlice, | |
106 double& closestDistance, | |
107 const Vector& origin) const | |
108 { | |
109 if (slices_.empty()) | |
110 { | |
111 return false; | |
112 } | |
113 | |
114 double reference = boost::numeric::ublas::inner_prod(origin, normal_); | |
115 | |
116 closestSlice = 0; | |
117 closestDistance = std::numeric_limits<double>::infinity(); | |
118 | |
119 for (size_t i = 0; i < slices_.size(); i++) | |
120 { | |
121 double distance = fabs(boost::numeric::ublas::inner_prod(slices_[i]->GetOrigin(), normal_) - reference); | |
122 | |
123 if (distance < closestDistance) | |
124 { | |
125 closestSlice = i; | |
126 closestDistance = distance; | |
127 } | |
128 } | |
129 | |
130 return true; | |
131 } | |
132 | |
133 | |
134 ParallelSlices* ParallelSlices::Reverse() const | |
135 { | |
136 std::auto_ptr<ParallelSlices> reversed(new ParallelSlices); | |
137 | |
138 for (size_t i = slices_.size(); i > 0; i--) | |
139 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
47
diff
changeset
|
140 const CoordinateSystem3D& slice = *slices_[i - 1]; |
0 | 141 |
142 reversed->AddSlice(slice.GetOrigin(), | |
143 -slice.GetAxisX(), | |
144 slice.GetAxisY()); | |
145 } | |
146 | |
147 return reversed.release(); | |
148 } | |
149 } |