comparison Framework/Deprecated/Toolbox/ParallelSlicesCursor.cpp @ 811:ffec76a5f7eb

deprecating ParallelSlices
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 28 May 2019 18:21:00 +0200
parents Framework/Toolbox/ParallelSlicesCursor.cpp@9a474e90e832
children 2d8ab34c8c91
comparison
equal deleted inserted replaced
810:7608e8107aa1 811:ffec76a5f7eb
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2019 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
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.
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
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
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #include "ParallelSlicesCursor.h"
23
24 #include <Core/OrthancException.h>
25
26 namespace Deprecated
27 {
28 size_t ParallelSlicesCursor::GetDefaultSlice()
29 {
30 if (slices_.get() == NULL)
31 {
32 return 0;
33 }
34 else
35 {
36 return slices_->GetSliceCount() / 2;
37 }
38 }
39
40
41 size_t ParallelSlicesCursor::GetSliceCount()
42 {
43 if (slices_.get() == NULL)
44 {
45 return 0;
46 }
47 else
48 {
49 return slices_->GetSliceCount();
50 }
51 }
52
53
54 OrthancStone::CoordinateSystem3D ParallelSlicesCursor::GetSlice(size_t slice)
55 {
56 if (slices_.get() == NULL)
57 {
58 return OrthancStone::CoordinateSystem3D();
59 }
60 else
61 {
62 return slices_->GetSlice(slice);
63 }
64 }
65
66
67 void ParallelSlicesCursor::SetGeometry(const ParallelSlices& slices)
68 {
69 slices_.reset(new ParallelSlices(slices));
70
71 currentSlice_ = GetDefaultSlice();
72 }
73
74
75 OrthancStone::CoordinateSystem3D ParallelSlicesCursor::GetCurrentSlice()
76 {
77 if (slices_.get() != NULL &&
78 currentSlice_ < slices_->GetSliceCount())
79 {
80 return slices_->GetSlice(currentSlice_);
81 }
82 else
83 {
84 return OrthancStone::CoordinateSystem3D(); // No slice is available, return the canonical geometry
85 }
86 }
87
88
89 bool ParallelSlicesCursor::SetDefaultSlice()
90 {
91 size_t slice = GetDefaultSlice();
92
93 if (currentSlice_ != slice)
94 {
95 currentSlice_ = slice;
96 return true;
97 }
98 else
99 {
100 return false;
101 }
102 }
103
104
105 bool ParallelSlicesCursor::ApplyOffset(OrthancStone::SliceOffsetMode mode,
106 int offset)
107 {
108 if (slices_.get() == NULL)
109 {
110 return false;
111 }
112
113 int count = static_cast<int>(slices_->GetSliceCount());
114 if (count == 0)
115 {
116 return false;
117 }
118
119 int slice;
120 if (static_cast<int>(currentSlice_) >= count)
121 {
122 slice = count - 1;
123 }
124 else
125 {
126 slice = static_cast<int>(currentSlice_);
127 }
128
129 switch (mode)
130 {
131 case OrthancStone::SliceOffsetMode_Absolute:
132 {
133 slice = offset;
134 break;
135 }
136
137 case OrthancStone::SliceOffsetMode_Relative:
138 {
139 slice += offset;
140 break;
141 }
142
143 case OrthancStone::SliceOffsetMode_Loop:
144 {
145 slice += offset;
146 while (slice < 0)
147 {
148 slice += count;
149 }
150
151 while (slice >= count)
152 {
153 slice -= count;
154 }
155
156 break;
157 }
158
159 default:
160 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
161 }
162
163 if (slice < 0)
164 {
165 slice = 0;
166 }
167
168 if (slice >= count)
169 {
170 slice = count - 1;
171 }
172
173 if (slice != static_cast<int>(currentSlice_))
174 {
175 currentSlice_ = static_cast<int>(slice);
176 return true;
177 }
178 else
179 {
180 return false;
181 }
182 }
183
184
185 bool ParallelSlicesCursor::ApplyWheelEvent(OrthancStone::MouseWheelDirection direction,
186 OrthancStone::KeyboardModifiers modifiers)
187 {
188 int offset = (modifiers & OrthancStone::KeyboardModifiers_Control ? 10 : 1);
189
190 switch (direction)
191 {
192 case OrthancStone::MouseWheelDirection_Down:
193 return ApplyOffset(OrthancStone::SliceOffsetMode_Relative, -offset);
194
195 case OrthancStone::MouseWheelDirection_Up:
196 return ApplyOffset(OrthancStone::SliceOffsetMode_Relative, offset);
197
198 default:
199 return false;
200 }
201 }
202
203
204 bool ParallelSlicesCursor::LookupSliceContainingPoint(const OrthancStone::Vector& p)
205 {
206 size_t slice;
207 double distance;
208
209 if (slices_.get() != NULL &&
210 slices_->ComputeClosestSlice(slice, distance, p))
211 {
212 if (currentSlice_ != slice)
213 {
214 currentSlice_ = slice;
215 return true;
216 }
217 }
218
219 return false;
220 }
221 }