Mercurial > hg > orthanc-stone
annotate Framework/Toolbox/ParallelSlicesCursor.cpp @ 590:5430bcffba57
FloatTextureSceneLayer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 26 Apr 2019 11:33:57 +0200 |
parents | b70e9be013e4 |
children | 9a474e90e832 |
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 | |
439 | 5 * Copyright (C) 2017-2019 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 "ParallelSlicesCursor.h" | |
23 | |
212
5412adf19980
resort to OrthancFramework
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
201
diff
changeset
|
24 #include <Core/OrthancException.h> |
0 | 25 |
26 namespace OrthancStone | |
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 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
54 CoordinateSystem3D ParallelSlicesCursor::GetSlice(size_t slice) |
0 | 55 { |
56 if (slices_.get() == NULL) | |
57 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
58 return CoordinateSystem3D(); |
0 | 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 | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
75 CoordinateSystem3D ParallelSlicesCursor::GetCurrentSlice() |
0 | 76 { |
77 if (slices_.get() != NULL && | |
78 currentSlice_ < slices_->GetSliceCount()) | |
79 { | |
80 return slices_->GetSlice(currentSlice_); | |
81 } | |
82 else | |
83 { | |
110
53025eecbc95
renamed SliceGeometry as CoordinateSystem3D
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
53
diff
changeset
|
84 return CoordinateSystem3D(); // No slice is available, return the canonical geometry |
0 | 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(SliceOffsetMode mode, | |
106 int offset) | |
107 { | |
108 if (slices_.get() == NULL) | |
109 { | |
110 return false; | |
111 } | |
112 | |
113 int count = 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 = currentSlice_; | |
127 } | |
128 | |
129 switch (mode) | |
130 { | |
131 case SliceOffsetMode_Absolute: | |
132 { | |
133 slice = offset; | |
134 break; | |
135 } | |
136 | |
137 case SliceOffsetMode_Relative: | |
138 { | |
139 slice += offset; | |
140 break; | |
141 } | |
142 | |
143 case 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(MouseWheelDirection direction, | |
186 KeyboardModifiers modifiers) | |
187 { | |
188 int offset = (modifiers & KeyboardModifiers_Control ? 10 : 1); | |
189 | |
190 switch (direction) | |
191 { | |
192 case MouseWheelDirection_Down: | |
193 return ApplyOffset(SliceOffsetMode_Relative, -offset); | |
194 | |
195 case MouseWheelDirection_Up: | |
196 return ApplyOffset(SliceOffsetMode_Relative, offset); | |
197 | |
198 default: | |
199 return false; | |
200 } | |
201 } | |
202 | |
203 | |
204 bool ParallelSlicesCursor::LookupSliceContainingPoint(const 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 } |