Mercurial > hg > orthanc-stone
annotate Framework/Deprecated/Toolbox/ParallelSlicesCursor.cpp @ 1290:7def6ab2929f bugs/2020-02-invisible-slice
Removal of debugging logs
author | Benjamin Golinvaux <bgo@osimis.io> |
---|---|
date | Fri, 21 Feb 2020 15:20:29 +0100 |
parents | 2d8ab34c8c91 |
children | 30deba7bc8e2 |
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 | |
1270
2d8ab34c8c91
upgrade to year 2020
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
811
diff
changeset
|
5 * Copyright (C) 2017-2020 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 |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
26 namespace Deprecated |
0 | 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 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
54 OrthancStone::CoordinateSystem3D ParallelSlicesCursor::GetSlice(size_t slice) |
0 | 55 { |
56 if (slices_.get() == NULL) | |
57 { | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
58 return OrthancStone::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 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
75 OrthancStone::CoordinateSystem3D ParallelSlicesCursor::GetCurrentSlice() |
0 | 76 { |
77 if (slices_.get() != NULL && | |
78 currentSlice_ < slices_->GetSliceCount()) | |
79 { | |
80 return slices_->GetSlice(currentSlice_); | |
81 } | |
82 else | |
83 { | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
84 return OrthancStone::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 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
105 bool ParallelSlicesCursor::ApplyOffset(OrthancStone::SliceOffsetMode mode, |
0 | 106 int offset) |
107 { | |
108 if (slices_.get() == NULL) | |
109 { | |
110 return false; | |
111 } | |
112 | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
113 int count = static_cast<int>(slices_->GetSliceCount()); |
0 | 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 { | |
693
9a474e90e832
Fixed a bunch of truncation warnings in various parts of the library
Benjamin Golinvaux <bgo@osimis.io>
parents:
439
diff
changeset
|
126 slice = static_cast<int>(currentSlice_); |
0 | 127 } |
128 | |
129 switch (mode) | |
130 { | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
131 case OrthancStone::SliceOffsetMode_Absolute: |
0 | 132 { |
133 slice = offset; | |
134 break; | |
135 } | |
136 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
137 case OrthancStone::SliceOffsetMode_Relative: |
0 | 138 { |
139 slice += offset; | |
140 break; | |
141 } | |
142 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
143 case OrthancStone::SliceOffsetMode_Loop: |
0 | 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 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
185 bool ParallelSlicesCursor::ApplyWheelEvent(OrthancStone::MouseWheelDirection direction, |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
186 OrthancStone::KeyboardModifiers modifiers) |
0 | 187 { |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
188 int offset = (modifiers & OrthancStone::KeyboardModifiers_Control ? 10 : 1); |
0 | 189 |
190 switch (direction) | |
191 { | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
192 case OrthancStone::MouseWheelDirection_Down: |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
193 return ApplyOffset(OrthancStone::SliceOffsetMode_Relative, -offset); |
0 | 194 |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
195 case OrthancStone::MouseWheelDirection_Up: |
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
196 return ApplyOffset(OrthancStone::SliceOffsetMode_Relative, offset); |
0 | 197 |
198 default: | |
199 return false; | |
200 } | |
201 } | |
202 | |
203 | |
811
ffec76a5f7eb
deprecating ParallelSlices
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
693
diff
changeset
|
204 bool ParallelSlicesCursor::LookupSliceContainingPoint(const OrthancStone::Vector& p) |
0 | 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 } |