Mercurial > hg > orthanc-stone
annotate OrthancStone/Sources/Scene2D/AnnotationsSceneLayer.cpp @ 1886:ca89fec8c48f
test
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 14 Jan 2022 19:10:30 +0100 |
parents | 7053b8a0aaec |
children | 9c0adcc8feec |
rev | line source |
---|---|
1804 | 1 /** |
2 * Stone of Orthanc | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
1871
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
7053b8a0aaec
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1870
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1804 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Lesser General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Lesser General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Lesser General Public | |
19 * License along with this program. If not, see | |
20 * <http://www.gnu.org/licenses/>. | |
21 **/ | |
22 | |
23 | |
24 #include "AnnotationsSceneLayer.h" | |
25 | |
26 #include "MacroSceneLayer.h" | |
27 #include "PolylineSceneLayer.h" | |
28 #include "TextSceneLayer.h" | |
29 | |
30 #include <OrthancException.h> | |
31 | |
32 #include <boost/math/constants/constants.hpp> | |
33 #include <list> | |
34 | |
35 static const double HANDLE_SIZE = 10.0; | |
36 static const double PI = boost::math::constants::pi<double>(); | |
37 | |
38 static const char* const KEY_ANNOTATIONS = "annotations"; | |
39 static const char* const KEY_TYPE = "type"; | |
40 static const char* const KEY_X1 = "x1"; | |
41 static const char* const KEY_Y1 = "y1"; | |
42 static const char* const KEY_X2 = "x2"; | |
43 static const char* const KEY_Y2 = "y2"; | |
44 static const char* const KEY_X3 = "x3"; | |
45 static const char* const KEY_Y3 = "y3"; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
46 static const char* const KEY_UNITS = "units"; |
1804 | 47 |
48 static const char* const VALUE_ANGLE = "angle"; | |
49 static const char* const VALUE_CIRCLE = "circle"; | |
50 static const char* const VALUE_SEGMENT = "segment"; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
51 static const char* const VALUE_MILLIMETERS = "millimeters"; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
52 static const char* const VALUE_PIXELS = "pixels"; |
1804 | 53 |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
54 #if 0 |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
55 static OrthancStone::Color COLOR_PRIMITIVES(192, 192, 192); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
56 static OrthancStone::Color COLOR_HOVER(0, 255, 0); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
57 static OrthancStone::Color COLOR_TEXT(255, 0, 0); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
58 #else |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
59 static OrthancStone::Color COLOR_PRIMITIVES(0x40, 0x82, 0xad); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
60 static OrthancStone::Color COLOR_HOVER(0x40, 0xad, 0x79); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
61 static OrthancStone::Color COLOR_TEXT(0x4e, 0xde, 0x99); |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
62 #endif |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
63 |
1804 | 64 |
65 namespace OrthancStone | |
66 { | |
67 class AnnotationsSceneLayer::GeometricPrimitive : public boost::noncopyable | |
68 { | |
69 private: | |
70 bool modified_; | |
71 Annotation& parentAnnotation_; | |
72 Color color_; | |
73 Color hoverColor_; | |
74 bool isHover_; | |
75 int depth_; | |
76 | |
77 public: | |
78 GeometricPrimitive(Annotation& parentAnnotation, | |
79 int depth) : | |
80 modified_(true), | |
81 parentAnnotation_(parentAnnotation), | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
82 color_(COLOR_PRIMITIVES), |
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
83 hoverColor_(COLOR_HOVER), |
1804 | 84 isHover_(false), |
85 depth_(depth) | |
86 { | |
87 } | |
88 | |
89 virtual ~GeometricPrimitive() | |
90 { | |
91 } | |
92 | |
93 Annotation& GetParentAnnotation() const | |
94 { | |
95 return parentAnnotation_; | |
96 } | |
97 | |
98 int GetDepth() const | |
99 { | |
100 return depth_; | |
101 } | |
102 | |
103 void SetHover(bool hover) | |
104 { | |
105 if (hover != isHover_) | |
106 { | |
107 isHover_ = hover; | |
108 modified_ = true; | |
109 } | |
110 } | |
111 | |
112 bool IsHover() const | |
113 { | |
114 return isHover_; | |
115 } | |
116 | |
117 void SetModified(bool modified) | |
118 { | |
119 modified_ = modified; | |
120 } | |
121 | |
122 bool IsModified() const | |
123 { | |
124 return modified_; | |
125 } | |
126 | |
127 void SetColor(const Color& color) | |
128 { | |
129 SetModified(true); | |
130 color_ = color; | |
131 } | |
132 | |
133 void SetHoverColor(const Color& color) | |
134 { | |
135 SetModified(true); | |
136 hoverColor_ = color; | |
137 } | |
138 | |
139 const Color& GetColor() const | |
140 { | |
141 return color_; | |
142 } | |
143 | |
144 const Color& GetHoverColor() const | |
145 { | |
146 return hoverColor_; | |
147 } | |
148 | |
149 virtual bool IsHit(const ScenePoint2D& p, | |
150 const Scene2D& scene) const = 0; | |
151 | |
152 // Always called, even if not modified | |
153 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
154 const Scene2D& scene) = 0; | |
155 | |
156 // Only called if modified | |
157 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
158 const Scene2D& scene) = 0; | |
159 | |
160 virtual void MovePreview(const ScenePoint2D& delta) = 0; | |
161 | |
162 virtual void MoveDone(const ScenePoint2D& delta) = 0; | |
163 }; | |
164 | |
165 | |
166 class AnnotationsSceneLayer::Annotation : public boost::noncopyable | |
167 { | |
168 private: | |
169 typedef std::list<GeometricPrimitive*> GeometricPrimitives; | |
170 | |
171 AnnotationsSceneLayer& that_; | |
172 GeometricPrimitives primitives_; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
173 Units units_; |
1804 | 174 |
175 public: | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
176 explicit Annotation(AnnotationsSceneLayer& that, |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
177 Units units) : |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
178 that_(that), |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
179 units_(units) |
1804 | 180 { |
181 that.AddAnnotation(this); | |
182 } | |
183 | |
184 virtual ~Annotation() | |
185 { | |
186 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
187 { | |
188 that_.DeletePrimitive(*it); | |
189 } | |
190 } | |
191 | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
192 Units GetUnits() const |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
193 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
194 return units_; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
195 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
196 |
1804 | 197 GeometricPrimitive* AddPrimitive(GeometricPrimitive* primitive) |
198 { | |
199 if (primitive == NULL) | |
200 { | |
201 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
202 } | |
203 else | |
204 { | |
205 assert(that_.primitives_.find(primitive) == that_.primitives_.end()); | |
206 primitives_.push_back(primitive); // For automated deallocation | |
207 that_.primitives_.insert(primitive); | |
208 return primitive; | |
209 } | |
210 } | |
211 | |
212 template <typename T> | |
213 T& AddTypedPrimitive(T* primitive) | |
214 { | |
215 AddPrimitive(primitive); | |
216 return *primitive; | |
217 } | |
218 | |
219 virtual void SignalMove(GeometricPrimitive& primitive) = 0; | |
220 | |
221 virtual void Serialize(Json::Value& target) = 0; | |
222 }; | |
223 | |
224 | |
225 class AnnotationsSceneLayer::Handle : public GeometricPrimitive | |
226 { | |
227 private: | |
228 ScenePoint2D center_; | |
229 ScenePoint2D delta_; | |
230 | |
231 public: | |
232 explicit Handle(Annotation& parentAnnotation, | |
233 const ScenePoint2D& center) : | |
234 GeometricPrimitive(parentAnnotation, 0), // Highest priority | |
235 center_(center), | |
236 delta_(0, 0) | |
237 { | |
238 } | |
239 | |
240 void SetSize(unsigned int size) | |
241 { | |
242 SetModified(true); | |
243 } | |
244 | |
245 void SetCenter(const ScenePoint2D& center) | |
246 { | |
247 SetModified(true); | |
248 center_ = center; | |
249 delta_ = ScenePoint2D(0, 0); | |
250 } | |
251 | |
252 ScenePoint2D GetCenter() const | |
253 { | |
254 return center_ + delta_; | |
255 } | |
256 | |
257 virtual bool IsHit(const ScenePoint2D& p, | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
258 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 259 { |
260 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); | |
261 | |
262 double dx = (center_.GetX() + delta_.GetX() - p.GetX()) * zoom; | |
263 double dy = (center_.GetY() + delta_.GetY() - p.GetY()) * zoom; | |
264 | |
265 return (std::abs(dx) <= HANDLE_SIZE / 2.0 && | |
266 std::abs(dy) <= HANDLE_SIZE / 2.0); | |
267 } | |
268 | |
269 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
270 const Scene2D& scene) ORTHANC_OVERRIDE | |
271 { | |
272 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); | |
273 | |
274 // TODO: take DPI into account | |
275 double x1 = center_.GetX() + delta_.GetX() - (HANDLE_SIZE / 2.0) / zoom; | |
276 double y1 = center_.GetY() + delta_.GetY() - (HANDLE_SIZE / 2.0) / zoom; | |
277 double x2 = center_.GetX() + delta_.GetX() + (HANDLE_SIZE / 2.0) / zoom; | |
278 double y2 = center_.GetY() + delta_.GetY() + (HANDLE_SIZE / 2.0) / zoom; | |
279 | |
280 PolylineSceneLayer::Chain chain; | |
281 chain.reserve(4); | |
282 chain.push_back(ScenePoint2D(x1, y1)); | |
283 chain.push_back(ScenePoint2D(x2, y1)); | |
284 chain.push_back(ScenePoint2D(x2, y2)); | |
285 chain.push_back(ScenePoint2D(x1, y2)); | |
286 | |
287 if (IsHover()) | |
288 { | |
289 polyline.AddChain(chain, true /* closed */, GetHoverColor()); | |
290 } | |
291 else | |
292 { | |
293 polyline.AddChain(chain, true /* closed */, GetColor()); | |
294 } | |
295 } | |
296 | |
297 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
298 const Scene2D& scene) ORTHANC_OVERRIDE | |
299 { | |
300 } | |
301 | |
302 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
303 { | |
304 SetModified(true); | |
305 delta_ = delta; | |
306 GetParentAnnotation().SignalMove(*this); | |
307 } | |
308 | |
309 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
310 { | |
311 SetModified(true); | |
312 center_ = center_ + delta; | |
313 delta_ = ScenePoint2D(0, 0); | |
314 GetParentAnnotation().SignalMove(*this); | |
315 } | |
316 }; | |
317 | |
318 | |
319 class AnnotationsSceneLayer::Segment : public GeometricPrimitive | |
320 { | |
321 private: | |
322 ScenePoint2D p1_; | |
323 ScenePoint2D p2_; | |
324 ScenePoint2D delta_; | |
325 | |
326 public: | |
327 Segment(Annotation& parentAnnotation, | |
328 const ScenePoint2D& p1, | |
329 const ScenePoint2D& p2) : | |
330 GeometricPrimitive(parentAnnotation, 1), // Can only be selected if no handle matches | |
331 p1_(p1), | |
332 p2_(p2), | |
333 delta_(0, 0) | |
334 { | |
335 } | |
336 | |
337 void SetPosition(const ScenePoint2D& p1, | |
338 const ScenePoint2D& p2) | |
339 { | |
340 SetModified(true); | |
341 p1_ = p1; | |
342 p2_ = p2; | |
343 delta_ = ScenePoint2D(0, 0); | |
344 } | |
345 | |
346 ScenePoint2D GetPosition1() const | |
347 { | |
348 return p1_ + delta_; | |
349 } | |
350 | |
351 ScenePoint2D GetPosition2() const | |
352 { | |
353 return p2_ + delta_; | |
354 } | |
355 | |
356 virtual bool IsHit(const ScenePoint2D& p, | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
357 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 358 { |
359 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); | |
360 return (ScenePoint2D::SquaredDistancePtSegment(p1_ + delta_, p2_ + delta_, p) * zoom * zoom <= | |
361 (HANDLE_SIZE / 2.0) * (HANDLE_SIZE / 2.0)); | |
362 } | |
363 | |
364 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
365 const Scene2D& scene) ORTHANC_OVERRIDE | |
366 { | |
367 PolylineSceneLayer::Chain chain; | |
368 chain.reserve(2); | |
369 chain.push_back(p1_ + delta_); | |
370 chain.push_back(p2_ + delta_); | |
371 | |
372 if (IsHover()) | |
373 { | |
374 polyline.AddChain(chain, false /* closed */, GetHoverColor()); | |
375 } | |
376 else | |
377 { | |
378 polyline.AddChain(chain, false /* closed */, GetColor()); | |
379 } | |
380 } | |
381 | |
382 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
383 const Scene2D& scene) ORTHANC_OVERRIDE | |
384 { | |
385 } | |
386 | |
387 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
388 { | |
389 SetModified(true); | |
390 delta_ = delta; | |
391 GetParentAnnotation().SignalMove(*this); | |
392 } | |
393 | |
394 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
395 { | |
396 SetModified(true); | |
397 p1_ = p1_ + delta; | |
398 p2_ = p2_ + delta; | |
399 delta_ = ScenePoint2D(0, 0); | |
400 GetParentAnnotation().SignalMove(*this); | |
401 } | |
402 }; | |
403 | |
404 | |
405 class AnnotationsSceneLayer::Circle : public GeometricPrimitive | |
406 { | |
407 private: | |
408 ScenePoint2D p1_; | |
409 ScenePoint2D p2_; | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
410 ScenePoint2D delta_; |
1804 | 411 |
412 public: | |
413 Circle(Annotation& parentAnnotation, | |
414 const ScenePoint2D& p1, | |
415 const ScenePoint2D& p2) : | |
416 GeometricPrimitive(parentAnnotation, 2), | |
417 p1_(p1), | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
418 p2_(p2), |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
419 delta_(0, 0) |
1804 | 420 { |
421 } | |
422 | |
423 void SetPosition(const ScenePoint2D& p1, | |
424 const ScenePoint2D& p2) | |
425 { | |
426 SetModified(true); | |
427 p1_ = p1; | |
428 p2_ = p2; | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
429 delta_ = ScenePoint2D(0, 0); |
1804 | 430 } |
431 | |
432 ScenePoint2D GetPosition1() const | |
433 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
434 return p1_ + delta_; |
1804 | 435 } |
436 | |
437 ScenePoint2D GetPosition2() const | |
438 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
439 return p2_ + delta_; |
1804 | 440 } |
441 | |
442 virtual bool IsHit(const ScenePoint2D& p, | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
443 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 444 { |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
445 const double zoom = scene.GetSceneToCanvasTransform().ComputeZoom(); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
446 |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
447 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0, |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
448 (p1_.GetY() + p2_.GetY()) / 2.0); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
449 |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
450 const double radius = ScenePoint2D::DistancePtPt(middle, p1_); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
451 const double distance = ScenePoint2D::DistancePtPt(middle, p - delta_); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
452 |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
453 return std::abs(radius - distance) * zoom <= HANDLE_SIZE / 2.0; |
1804 | 454 } |
455 | |
456 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
457 const Scene2D& scene) ORTHANC_OVERRIDE | |
458 { | |
459 static unsigned int NUM_SEGMENTS = 128; | |
460 | |
461 ScenePoint2D middle((p1_.GetX() + p2_.GetX()) / 2.0, | |
462 (p1_.GetY() + p2_.GetY()) / 2.0); | |
463 | |
464 const double radius = ScenePoint2D::DistancePtPt(middle, p1_); | |
465 | |
466 double increment = 2.0 * PI / static_cast<double>(NUM_SEGMENTS - 1); | |
467 | |
468 PolylineSceneLayer::Chain chain; | |
469 chain.reserve(NUM_SEGMENTS); | |
470 | |
471 double theta = 0; | |
472 for (unsigned int i = 0; i < NUM_SEGMENTS; i++) | |
473 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
474 chain.push_back(ScenePoint2D(delta_.GetX() + middle.GetX() + radius * cos(theta), |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
475 delta_.GetY() + middle.GetY() + radius * sin(theta))); |
1804 | 476 theta += increment; |
477 } | |
478 | |
479 if (IsHover()) | |
480 { | |
481 polyline.AddChain(chain, false /* closed */, GetHoverColor()); | |
482 } | |
483 else | |
484 { | |
485 polyline.AddChain(chain, false /* closed */, GetColor()); | |
486 } | |
487 } | |
488 | |
489 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
490 const Scene2D& scene) ORTHANC_OVERRIDE | |
491 { | |
492 } | |
493 | |
494 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
495 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
496 SetModified(true); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
497 delta_ = delta; |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
498 GetParentAnnotation().SignalMove(*this); |
1804 | 499 } |
500 | |
501 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
502 { | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
503 SetModified(true); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
504 p1_ = p1_ + delta; |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
505 p2_ = p2_ + delta; |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
506 delta_ = ScenePoint2D(0, 0); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
507 GetParentAnnotation().SignalMove(*this); |
1804 | 508 } |
509 }; | |
510 | |
511 | |
512 class AnnotationsSceneLayer::Arc : public GeometricPrimitive | |
513 { | |
514 private: | |
515 ScenePoint2D start_; | |
516 ScenePoint2D middle_; | |
517 ScenePoint2D end_; | |
518 double radius_; // in pixels | |
519 | |
520 void ComputeAngles(double& fullAngle, | |
521 double& startAngle, | |
522 double& endAngle) const | |
523 { | |
524 const double x1 = start_.GetX(); | |
525 const double y1 = start_.GetY(); | |
526 const double xc = middle_.GetX(); | |
527 const double yc = middle_.GetY(); | |
528 const double x2 = end_.GetX(); | |
529 const double y2 = end_.GetY(); | |
530 | |
531 startAngle = atan2(y1 - yc, x1 - xc); | |
532 endAngle = atan2(y2 - yc, x2 - xc); | |
533 | |
534 fullAngle = endAngle - startAngle; | |
535 | |
536 while (fullAngle < -PI) | |
537 { | |
538 fullAngle += 2.0 * PI; | |
539 } | |
540 | |
541 while (fullAngle >= PI) | |
542 { | |
543 fullAngle -= 2.0 * PI; | |
544 } | |
545 } | |
546 | |
547 public: | |
548 Arc(Annotation& parentAnnotation, | |
549 const ScenePoint2D& start, | |
550 const ScenePoint2D& middle, | |
551 const ScenePoint2D& end) : | |
552 GeometricPrimitive(parentAnnotation, 2), | |
553 start_(start), | |
554 middle_(middle), | |
555 end_(end), | |
556 radius_(20) | |
557 { | |
558 } | |
559 | |
560 double GetAngle() const | |
561 { | |
562 double fullAngle, startAngle, endAngle; | |
563 ComputeAngles(fullAngle, startAngle, endAngle); | |
564 return fullAngle; | |
565 } | |
566 | |
567 void SetStart(const ScenePoint2D& p) | |
568 { | |
569 SetModified(true); | |
570 start_ = p; | |
571 } | |
572 | |
573 void SetMiddle(const ScenePoint2D& p) | |
574 { | |
575 SetModified(true); | |
576 middle_ = p; | |
577 } | |
578 | |
579 void SetEnd(const ScenePoint2D& p) | |
580 { | |
581 SetModified(true); | |
582 end_ = p; | |
583 } | |
584 | |
585 virtual bool IsHit(const ScenePoint2D& p, | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
586 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 587 { |
588 return false; | |
589 } | |
590 | |
591 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
592 const Scene2D& scene) ORTHANC_OVERRIDE | |
593 { | |
594 static unsigned int NUM_SEGMENTS = 64; | |
595 | |
596 const double radius = radius_ / scene.GetSceneToCanvasTransform().ComputeZoom(); | |
597 | |
598 double fullAngle, startAngle, endAngle; | |
599 ComputeAngles(fullAngle, startAngle, endAngle); | |
600 | |
601 double increment = fullAngle / static_cast<double>(NUM_SEGMENTS - 1); | |
602 | |
603 PolylineSceneLayer::Chain chain; | |
604 chain.reserve(NUM_SEGMENTS); | |
605 | |
606 double theta = startAngle; | |
607 for (unsigned int i = 0; i < NUM_SEGMENTS; i++) | |
608 { | |
609 chain.push_back(ScenePoint2D(middle_.GetX() + radius * cos(theta), | |
610 middle_.GetY() + radius * sin(theta))); | |
611 theta += increment; | |
612 } | |
613 | |
614 if (IsHover()) | |
615 { | |
616 polyline.AddChain(chain, false /* closed */, GetHoverColor()); | |
617 } | |
618 else | |
619 { | |
620 polyline.AddChain(chain, false /* closed */, GetColor()); | |
621 } | |
622 } | |
623 | |
624 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
625 const Scene2D& scene) ORTHANC_OVERRIDE | |
626 { | |
627 } | |
628 | |
629 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
630 { | |
631 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
632 } | |
633 | |
634 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
635 { | |
636 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
637 } | |
638 }; | |
639 | |
640 | |
641 class AnnotationsSceneLayer::Text : public GeometricPrimitive | |
642 { | |
643 private: | |
644 AnnotationsSceneLayer& that_; | |
645 bool first_; | |
646 size_t subLayer_; | |
647 std::unique_ptr<TextSceneLayer> content_; | |
648 | |
649 public: | |
650 Text(AnnotationsSceneLayer& that, | |
651 Annotation& parentAnnotation) : | |
652 GeometricPrimitive(parentAnnotation, 2), | |
653 that_(that), | |
1817 | 654 first_(true), |
655 subLayer_(0) // dummy initialization | |
1804 | 656 { |
657 } | |
658 | |
659 virtual ~Text() | |
660 { | |
661 if (!first_) | |
662 { | |
663 that_.TagSubLayerToRemove(subLayer_); | |
664 } | |
665 } | |
666 | |
667 void SetContent(const TextSceneLayer& content) | |
668 { | |
669 SetModified(true); | |
670 content_.reset(dynamic_cast<TextSceneLayer*>(content.Clone())); | |
671 } | |
672 | |
673 virtual bool IsHit(const ScenePoint2D& p, | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
674 const Scene2D& scene) const ORTHANC_OVERRIDE |
1804 | 675 { |
676 return false; | |
677 } | |
678 | |
679 virtual void RenderPolylineLayer(PolylineSceneLayer& polyline, | |
680 const Scene2D& scene) ORTHANC_OVERRIDE | |
681 { | |
682 } | |
683 | |
684 virtual void RenderOtherLayers(MacroSceneLayer& macro, | |
685 const Scene2D& scene) ORTHANC_OVERRIDE | |
686 { | |
687 if (content_.get() != NULL) | |
688 { | |
689 std::unique_ptr<TextSceneLayer> layer(reinterpret_cast<TextSceneLayer*>(content_->Clone())); | |
690 | |
691 layer->SetColor(IsHover() ? GetHoverColor() : GetColor()); | |
692 | |
693 if (first_) | |
694 { | |
695 subLayer_ = macro.AddLayer(layer.release()); | |
696 first_ = false; | |
697 } | |
698 else | |
699 { | |
700 macro.UpdateLayer(subLayer_, layer.release()); | |
701 } | |
702 } | |
703 } | |
704 | |
705 virtual void MovePreview(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
706 { | |
707 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
708 } | |
709 | |
710 virtual void MoveDone(const ScenePoint2D& delta) ORTHANC_OVERRIDE | |
711 { | |
712 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); // No hit is possible | |
713 } | |
714 }; | |
715 | |
716 | |
717 class AnnotationsSceneLayer::EditPrimitiveTracker : public IFlexiblePointerTracker | |
718 { | |
719 private: | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
720 AnnotationsSceneLayer& that_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
721 GeometricPrimitive& primitive_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
722 ScenePoint2D sceneClick_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
723 AffineTransform2D canvasToScene_; |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
724 bool alive_; |
1804 | 725 |
726 public: | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
727 EditPrimitiveTracker(AnnotationsSceneLayer& that, |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
728 GeometricPrimitive& primitive, |
1804 | 729 const ScenePoint2D& sceneClick, |
730 const AffineTransform2D& canvasToScene) : | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
731 that_(that), |
1804 | 732 primitive_(primitive), |
733 sceneClick_(sceneClick), | |
734 canvasToScene_(canvasToScene), | |
735 alive_(true) | |
736 { | |
737 } | |
738 | |
739 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE | |
740 { | |
741 primitive_.MovePreview(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_); | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
742 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 743 } |
744 | |
745 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE | |
746 { | |
747 primitive_.MoveDone(event.GetMainPosition().Apply(canvasToScene_) - sceneClick_); | |
748 alive_ = false; | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
749 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 750 } |
751 | |
752 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE | |
753 { | |
754 } | |
755 | |
756 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
757 { | |
758 return alive_; | |
759 } | |
760 | |
761 virtual void Cancel() ORTHANC_OVERRIDE | |
762 { | |
763 primitive_.MoveDone(ScenePoint2D(0, 0)); | |
764 } | |
765 }; | |
766 | |
767 | |
768 class AnnotationsSceneLayer::SegmentAnnotation : public Annotation | |
769 { | |
770 private: | |
771 bool showLabel_; | |
772 Handle& handle1_; | |
773 Handle& handle2_; | |
774 Segment& segment_; | |
775 Text& label_; | |
776 | |
777 void UpdateLabel() | |
778 { | |
779 if (showLabel_) | |
780 { | |
781 TextSceneLayer content; | |
782 | |
783 double x1 = handle1_.GetCenter().GetX(); | |
784 double y1 = handle1_.GetCenter().GetY(); | |
785 double x2 = handle2_.GetCenter().GetX(); | |
786 double y2 = handle2_.GetCenter().GetY(); | |
787 | |
788 // Put the label to the right of the right-most handle | |
789 if (x1 < x2) | |
790 { | |
791 content.SetPosition(x2, y2); | |
792 } | |
793 else | |
794 { | |
795 content.SetPosition(x1, y1); | |
796 } | |
797 | |
798 content.SetAnchor(BitmapAnchor_CenterLeft); | |
799 content.SetBorder(10); | |
800 | |
801 double dx = x1 - x2; | |
802 double dy = y1 - y2; | |
803 char buf[32]; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
804 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
805 switch (GetUnits()) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
806 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
807 case Units_Millimeters: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
808 sprintf(buf, "%0.2f cm", sqrt(dx * dx + dy * dy) / 10.0); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
809 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
810 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
811 case Units_Pixels: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
812 sprintf(buf, "%0.1f px", sqrt(dx * dx + dy * dy)); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
813 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
814 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
815 default: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
816 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
817 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
818 |
1804 | 819 content.SetText(buf); |
820 | |
821 label_.SetContent(content); | |
822 } | |
823 } | |
824 | |
825 public: | |
826 SegmentAnnotation(AnnotationsSceneLayer& that, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
827 Units units, |
1804 | 828 bool showLabel, |
829 const ScenePoint2D& p1, | |
830 const ScenePoint2D& p2) : | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
831 Annotation(that, units), |
1804 | 832 showLabel_(showLabel), |
833 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, p1))), | |
834 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, p2))), | |
835 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))), | |
836 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | |
837 { | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
838 label_.SetColor(COLOR_TEXT); |
1804 | 839 UpdateLabel(); |
840 } | |
841 | |
842 Handle& GetHandle1() const | |
843 { | |
844 return handle1_; | |
845 } | |
846 | |
847 Handle& GetHandle2() const | |
848 { | |
849 return handle2_; | |
850 } | |
851 | |
852 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE | |
853 { | |
854 if (&primitive == &handle1_ || | |
855 &primitive == &handle2_) | |
856 { | |
857 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | |
858 } | |
859 else if (&primitive == &segment_) | |
860 { | |
861 handle1_.SetCenter(segment_.GetPosition1()); | |
862 handle2_.SetCenter(segment_.GetPosition2()); | |
863 } | |
864 | |
865 UpdateLabel(); | |
866 } | |
867 | |
868 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE | |
869 { | |
870 target = Json::objectValue; | |
871 target[KEY_TYPE] = VALUE_SEGMENT; | |
872 target[KEY_X1] = handle1_.GetCenter().GetX(); | |
873 target[KEY_Y1] = handle1_.GetCenter().GetY(); | |
874 target[KEY_X2] = handle2_.GetCenter().GetX(); | |
875 target[KEY_Y2] = handle2_.GetCenter().GetY(); | |
876 } | |
877 | |
878 static void Unserialize(AnnotationsSceneLayer& target, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
879 Units units, |
1804 | 880 const Json::Value& source) |
881 { | |
882 if (source.isMember(KEY_X1) && | |
883 source.isMember(KEY_Y1) && | |
884 source.isMember(KEY_X2) && | |
885 source.isMember(KEY_Y2) && | |
886 source[KEY_X1].isNumeric() && | |
887 source[KEY_Y1].isNumeric() && | |
888 source[KEY_X2].isNumeric() && | |
889 source[KEY_Y2].isNumeric()) | |
890 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
891 new SegmentAnnotation(target, units, true, |
1804 | 892 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
893 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); | |
894 } | |
895 else | |
896 { | |
897 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an segment annotation"); | |
898 } | |
899 } | |
900 }; | |
901 | |
902 | |
903 class AnnotationsSceneLayer::AngleAnnotation : public Annotation | |
904 { | |
905 private: | |
906 Handle& startHandle_; | |
907 Handle& middleHandle_; | |
908 Handle& endHandle_; | |
909 Segment& segment1_; | |
910 Segment& segment2_; | |
911 Arc& arc_; | |
912 Text& label_; | |
913 | |
914 void UpdateLabel() | |
915 { | |
916 TextSceneLayer content; | |
917 | |
918 const double x1 = startHandle_.GetCenter().GetX(); | |
919 const double x2 = middleHandle_.GetCenter().GetX(); | |
920 const double y2 = middleHandle_.GetCenter().GetY(); | |
921 const double x3 = endHandle_.GetCenter().GetX(); | |
922 | |
923 if (x2 < x1 && | |
924 x2 < x3) | |
925 { | |
926 content.SetAnchor(BitmapAnchor_CenterRight); | |
927 } | |
928 else | |
929 { | |
930 content.SetAnchor(BitmapAnchor_CenterLeft); | |
931 } | |
932 | |
933 content.SetPosition(x2, y2); | |
934 content.SetBorder(10); | |
935 | |
936 char buf[32]; | |
937 sprintf(buf, "%.01f%c%c", std::abs(arc_.GetAngle()) / PI * 180.0, | |
938 0xc2, 0xb0 /* two bytes corresponding to degree symbol in UTF-8 */); | |
939 content.SetText(buf); | |
940 | |
941 label_.SetContent(content); | |
942 } | |
943 | |
944 public: | |
945 AngleAnnotation(AnnotationsSceneLayer& that, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
946 Units units, |
1804 | 947 const ScenePoint2D& start, |
948 const ScenePoint2D& middle, | |
949 const ScenePoint2D& end) : | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
950 Annotation(that, units), |
1804 | 951 startHandle_(AddTypedPrimitive<Handle>(new Handle(*this, start))), |
952 middleHandle_(AddTypedPrimitive<Handle>(new Handle(*this, middle))), | |
953 endHandle_(AddTypedPrimitive<Handle>(new Handle(*this, end))), | |
954 segment1_(AddTypedPrimitive<Segment>(new Segment(*this, start, middle))), | |
955 segment2_(AddTypedPrimitive<Segment>(new Segment(*this, middle, end))), | |
956 arc_(AddTypedPrimitive<Arc>(new Arc(*this, start, middle, end))), | |
957 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | |
958 { | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
959 label_.SetColor(COLOR_TEXT); |
1804 | 960 UpdateLabel(); |
961 } | |
962 | |
963 Handle& GetEndHandle() const | |
964 { | |
965 return endHandle_; | |
966 } | |
967 | |
968 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE | |
969 { | |
970 if (&primitive == &startHandle_) | |
971 { | |
972 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter()); | |
973 arc_.SetStart(startHandle_.GetCenter()); | |
974 } | |
975 else if (&primitive == &middleHandle_) | |
976 { | |
977 segment1_.SetPosition(startHandle_.GetCenter(), middleHandle_.GetCenter()); | |
978 segment2_.SetPosition(middleHandle_.GetCenter(), endHandle_.GetCenter()); | |
979 arc_.SetMiddle(middleHandle_.GetCenter()); | |
980 } | |
981 else if (&primitive == &endHandle_) | |
982 { | |
983 segment2_.SetPosition(middleHandle_.GetCenter(), endHandle_.GetCenter()); | |
984 arc_.SetEnd(endHandle_.GetCenter()); | |
985 } | |
986 else if (&primitive == &segment1_) | |
987 { | |
988 startHandle_.SetCenter(segment1_.GetPosition1()); | |
989 middleHandle_.SetCenter(segment1_.GetPosition2()); | |
990 segment2_.SetPosition(segment1_.GetPosition2(), segment2_.GetPosition2()); | |
991 arc_.SetStart(segment1_.GetPosition1()); | |
992 arc_.SetMiddle(segment1_.GetPosition2()); | |
993 } | |
994 else if (&primitive == &segment2_) | |
995 { | |
996 middleHandle_.SetCenter(segment2_.GetPosition1()); | |
997 endHandle_.SetCenter(segment2_.GetPosition2()); | |
998 segment1_.SetPosition(segment1_.GetPosition1(), segment2_.GetPosition1()); | |
999 arc_.SetMiddle(segment2_.GetPosition1()); | |
1000 arc_.SetEnd(segment2_.GetPosition2()); | |
1001 } | |
1002 | |
1003 UpdateLabel(); | |
1004 } | |
1005 | |
1006 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE | |
1007 { | |
1008 target = Json::objectValue; | |
1009 target[KEY_TYPE] = VALUE_ANGLE; | |
1010 target[KEY_X1] = startHandle_.GetCenter().GetX(); | |
1011 target[KEY_Y1] = startHandle_.GetCenter().GetY(); | |
1012 target[KEY_X2] = middleHandle_.GetCenter().GetX(); | |
1013 target[KEY_Y2] = middleHandle_.GetCenter().GetY(); | |
1014 target[KEY_X3] = endHandle_.GetCenter().GetX(); | |
1015 target[KEY_Y3] = endHandle_.GetCenter().GetY(); | |
1016 } | |
1017 | |
1018 static void Unserialize(AnnotationsSceneLayer& target, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1019 Units units, |
1804 | 1020 const Json::Value& source) |
1021 { | |
1022 if (source.isMember(KEY_X1) && | |
1023 source.isMember(KEY_Y1) && | |
1024 source.isMember(KEY_X2) && | |
1025 source.isMember(KEY_Y2) && | |
1026 source.isMember(KEY_X3) && | |
1027 source.isMember(KEY_Y3) && | |
1028 source[KEY_X1].isNumeric() && | |
1029 source[KEY_Y1].isNumeric() && | |
1030 source[KEY_X2].isNumeric() && | |
1031 source[KEY_Y2].isNumeric() && | |
1032 source[KEY_X3].isNumeric() && | |
1033 source[KEY_Y3].isNumeric()) | |
1034 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1035 new AngleAnnotation(target, units, |
1804 | 1036 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
1037 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble()), | |
1038 ScenePoint2D(source[KEY_X3].asDouble(), source[KEY_Y3].asDouble())); | |
1039 } | |
1040 else | |
1041 { | |
1042 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an angle annotation"); | |
1043 } | |
1044 } | |
1045 }; | |
1046 | |
1047 | |
1048 class AnnotationsSceneLayer::CircleAnnotation : public Annotation | |
1049 { | |
1050 private: | |
1051 Handle& handle1_; | |
1052 Handle& handle2_; | |
1053 Segment& segment_; | |
1054 Circle& circle_; | |
1055 Text& label_; | |
1056 | |
1057 void UpdateLabel() | |
1058 { | |
1059 TextSceneLayer content; | |
1060 | |
1061 double x1 = handle1_.GetCenter().GetX(); | |
1062 double y1 = handle1_.GetCenter().GetY(); | |
1063 double x2 = handle2_.GetCenter().GetX(); | |
1064 double y2 = handle2_.GetCenter().GetY(); | |
1065 | |
1066 // Put the label to the right of the right-most handle | |
1067 if (x1 < x2) | |
1068 { | |
1069 content.SetPosition(x2, y2); | |
1070 } | |
1071 else | |
1072 { | |
1073 content.SetPosition(x1, y1); | |
1074 } | |
1075 | |
1076 content.SetAnchor(BitmapAnchor_CenterLeft); | |
1077 content.SetBorder(10); | |
1078 | |
1079 double dx = x1 - x2; | |
1080 double dy = y1 - y2; | |
1081 double diameter = sqrt(dx * dx + dy * dy); // in millimeters | |
1082 | |
1083 double area = PI * diameter * diameter / 4.0; | |
1084 | |
1085 char buf[32]; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1086 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1087 switch (GetUnits()) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1088 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1089 case Units_Millimeters: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1090 sprintf(buf, "%0.2f cm\n%0.2f cm%c%c", |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1091 diameter / 10.0, |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1092 area / 100.0, |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1093 0xc2, 0xb2 /* two bytes corresponding to two power in UTF-8 */); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1094 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1095 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1096 case Units_Pixels: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1097 // Don't report area (pixel-times-pixel is a strange unit) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1098 sprintf(buf, "%0.1f px", diameter); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1099 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1100 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1101 default: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1102 throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1103 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1104 |
1804 | 1105 content.SetText(buf); |
1106 | |
1107 label_.SetContent(content); | |
1108 } | |
1109 | |
1110 public: | |
1111 CircleAnnotation(AnnotationsSceneLayer& that, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1112 Units units, |
1804 | 1113 const ScenePoint2D& p1, |
1114 const ScenePoint2D& p2) : | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1115 Annotation(that, units), |
1804 | 1116 handle1_(AddTypedPrimitive<Handle>(new Handle(*this, p1))), |
1117 handle2_(AddTypedPrimitive<Handle>(new Handle(*this, p2))), | |
1118 segment_(AddTypedPrimitive<Segment>(new Segment(*this, p1, p2))), | |
1119 circle_(AddTypedPrimitive<Circle>(new Circle(*this, p1, p2))), | |
1120 label_(AddTypedPrimitive<Text>(new Text(that, *this))) | |
1121 { | |
1819
fe402c678d18
improved color theme for annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1817
diff
changeset
|
1122 label_.SetColor(COLOR_TEXT); |
1804 | 1123 UpdateLabel(); |
1124 } | |
1125 | |
1126 Handle& GetHandle2() const | |
1127 { | |
1128 return handle2_; | |
1129 } | |
1130 | |
1131 virtual void SignalMove(GeometricPrimitive& primitive) ORTHANC_OVERRIDE | |
1132 { | |
1133 if (&primitive == &handle1_ || | |
1134 &primitive == &handle2_) | |
1135 { | |
1136 segment_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | |
1137 circle_.SetPosition(handle1_.GetCenter(), handle2_.GetCenter()); | |
1138 } | |
1139 else if (&primitive == &segment_) | |
1140 { | |
1141 handle1_.SetCenter(segment_.GetPosition1()); | |
1142 handle2_.SetCenter(segment_.GetPosition2()); | |
1143 circle_.SetPosition(segment_.GetPosition1(), segment_.GetPosition2()); | |
1144 } | |
1823
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1145 else if (&primitive == &circle_) |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1146 { |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1147 handle1_.SetCenter(circle_.GetPosition1()); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1148 handle2_.SetCenter(circle_.GetPosition2()); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1149 segment_.SetPosition(circle_.GetPosition1(), circle_.GetPosition2()); |
781e9fc8925e
dragging circle annotations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1821
diff
changeset
|
1150 } |
1804 | 1151 |
1152 UpdateLabel(); | |
1153 } | |
1154 | |
1155 virtual void Serialize(Json::Value& target) ORTHANC_OVERRIDE | |
1156 { | |
1157 target = Json::objectValue; | |
1158 target[KEY_TYPE] = VALUE_CIRCLE; | |
1159 target[KEY_X1] = handle1_.GetCenter().GetX(); | |
1160 target[KEY_Y1] = handle1_.GetCenter().GetY(); | |
1161 target[KEY_X2] = handle2_.GetCenter().GetX(); | |
1162 target[KEY_Y2] = handle2_.GetCenter().GetY(); | |
1163 } | |
1164 | |
1165 static void Unserialize(AnnotationsSceneLayer& target, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1166 Units units, |
1804 | 1167 const Json::Value& source) |
1168 { | |
1169 if (source.isMember(KEY_X1) && | |
1170 source.isMember(KEY_Y1) && | |
1171 source.isMember(KEY_X2) && | |
1172 source.isMember(KEY_Y2) && | |
1173 source[KEY_X1].isNumeric() && | |
1174 source[KEY_Y1].isNumeric() && | |
1175 source[KEY_X2].isNumeric() && | |
1176 source[KEY_Y2].isNumeric()) | |
1177 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1178 new CircleAnnotation(target, units, |
1804 | 1179 ScenePoint2D(source[KEY_X1].asDouble(), source[KEY_Y1].asDouble()), |
1180 ScenePoint2D(source[KEY_X2].asDouble(), source[KEY_Y2].asDouble())); | |
1181 } | |
1182 else | |
1183 { | |
1184 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize an circle annotation"); | |
1185 } | |
1186 } | |
1187 }; | |
1188 | |
1189 | |
1190 class AnnotationsSceneLayer::CreateSegmentOrCircleTracker : public IFlexiblePointerTracker | |
1191 { | |
1192 private: | |
1193 AnnotationsSceneLayer& that_; | |
1194 Annotation* annotation_; | |
1195 AffineTransform2D canvasToScene_; | |
1196 Handle* handle2_; | |
1197 | |
1198 public: | |
1199 CreateSegmentOrCircleTracker(AnnotationsSceneLayer& that, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1200 Units units, |
1804 | 1201 bool isCircle, |
1202 const ScenePoint2D& sceneClick, | |
1203 const AffineTransform2D& canvasToScene) : | |
1204 that_(that), | |
1205 annotation_(NULL), | |
1206 canvasToScene_(canvasToScene), | |
1207 handle2_(NULL) | |
1208 { | |
1209 if (isCircle) | |
1210 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1211 annotation_ = new CircleAnnotation(that, units, sceneClick, sceneClick); |
1804 | 1212 handle2_ = &dynamic_cast<CircleAnnotation*>(annotation_)->GetHandle2(); |
1213 } | |
1214 else | |
1215 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1216 annotation_ = new SegmentAnnotation(that, units, true /* show label */, sceneClick, sceneClick); |
1804 | 1217 handle2_ = &dynamic_cast<SegmentAnnotation*>(annotation_)->GetHandle2(); |
1218 } | |
1219 | |
1220 assert(annotation_ != NULL && | |
1221 handle2_ != NULL); | |
1222 } | |
1223 | |
1224 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE | |
1225 { | |
1226 if (annotation_ != NULL) | |
1227 { | |
1228 assert(handle2_ != NULL); | |
1229 handle2_->SetCenter(event.GetMainPosition().Apply(canvasToScene_)); | |
1230 annotation_->SignalMove(*handle2_); | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1231 |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1232 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 1233 } |
1234 } | |
1235 | |
1236 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE | |
1237 { | |
1238 annotation_ = NULL; // IsAlive() becomes false | |
1239 | |
1240 that_.BroadcastMessage(AnnotationAddedMessage(that_)); | |
1241 } | |
1242 | |
1243 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE | |
1244 { | |
1245 } | |
1246 | |
1247 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
1248 { | |
1249 return (annotation_ != NULL); | |
1250 } | |
1251 | |
1252 virtual void Cancel() ORTHANC_OVERRIDE | |
1253 { | |
1254 if (annotation_ != NULL) | |
1255 { | |
1256 that_.DeleteAnnotation(annotation_); | |
1257 annotation_ = NULL; | |
1258 } | |
1259 } | |
1260 }; | |
1261 | |
1262 | |
1263 class AnnotationsSceneLayer::CreateAngleTracker : public IFlexiblePointerTracker | |
1264 { | |
1265 private: | |
1266 AnnotationsSceneLayer& that_; | |
1267 SegmentAnnotation* segment_; | |
1268 AngleAnnotation* angle_; | |
1269 AffineTransform2D canvasToScene_; | |
1270 | |
1271 public: | |
1272 CreateAngleTracker(AnnotationsSceneLayer& that, | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1273 Units units, |
1804 | 1274 const ScenePoint2D& sceneClick, |
1275 const AffineTransform2D& canvasToScene) : | |
1276 that_(that), | |
1277 segment_(NULL), | |
1278 angle_(NULL), | |
1279 canvasToScene_(canvasToScene) | |
1280 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1281 segment_ = new SegmentAnnotation(that, units, false /* no length label */, sceneClick, sceneClick); |
1804 | 1282 } |
1283 | |
1284 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE | |
1285 { | |
1286 if (segment_ != NULL) | |
1287 { | |
1288 segment_->GetHandle2().SetCenter(event.GetMainPosition().Apply(canvasToScene_)); | |
1289 segment_->SignalMove(segment_->GetHandle2()); | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1290 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 1291 } |
1292 | |
1293 if (angle_ != NULL) | |
1294 { | |
1295 angle_->GetEndHandle().SetCenter(event.GetMainPosition().Apply(canvasToScene_)); | |
1296 angle_->SignalMove(angle_->GetEndHandle()); | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1297 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 1298 } |
1299 } | |
1300 | |
1301 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE | |
1302 { | |
1303 if (segment_ != NULL) | |
1304 { | |
1305 // End of first step: The first segment is available, now create the angle | |
1306 | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1307 angle_ = new AngleAnnotation(that_, segment_->GetUnits(), segment_->GetHandle1().GetCenter(), |
1804 | 1308 segment_->GetHandle2().GetCenter(), |
1309 segment_->GetHandle2().GetCenter()); | |
1310 | |
1311 that_.DeleteAnnotation(segment_); | |
1312 segment_ = NULL; | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1313 |
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1314 that_.BroadcastMessage(AnnotationChangedMessage(that_)); |
1804 | 1315 } |
1316 else | |
1317 { | |
1318 angle_ = NULL; // IsAlive() becomes false | |
1319 | |
1320 that_.BroadcastMessage(AnnotationAddedMessage(that_)); | |
1321 } | |
1322 } | |
1323 | |
1324 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE | |
1325 { | |
1326 } | |
1327 | |
1328 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
1329 { | |
1330 return (segment_ != NULL || | |
1331 angle_ != NULL); | |
1332 } | |
1333 | |
1334 virtual void Cancel() ORTHANC_OVERRIDE | |
1335 { | |
1336 if (segment_ != NULL) | |
1337 { | |
1338 that_.DeleteAnnotation(segment_); | |
1339 segment_ = NULL; | |
1340 } | |
1341 | |
1342 if (angle_ != NULL) | |
1343 { | |
1344 that_.DeleteAnnotation(angle_); | |
1345 angle_ = NULL; | |
1346 } | |
1347 } | |
1348 }; | |
1349 | |
1350 | |
1351 // Dummy tracker that is only used for deletion, in order to warn | |
1352 // the caller that the mouse action was taken into consideration | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1353 class AnnotationsSceneLayer::RemoveTracker : public IFlexiblePointerTracker |
1804 | 1354 { |
1355 public: | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1356 RemoveTracker() |
1804 | 1357 { |
1358 } | |
1359 | |
1360 virtual void PointerMove(const PointerEvent& event) ORTHANC_OVERRIDE | |
1361 { | |
1362 } | |
1363 | |
1364 virtual void PointerUp(const PointerEvent& event) ORTHANC_OVERRIDE | |
1365 { | |
1366 } | |
1367 | |
1368 virtual void PointerDown(const PointerEvent& event) ORTHANC_OVERRIDE | |
1369 { | |
1370 } | |
1371 | |
1372 virtual bool IsAlive() const ORTHANC_OVERRIDE | |
1373 { | |
1374 return false; | |
1375 } | |
1376 | |
1377 virtual void Cancel() ORTHANC_OVERRIDE | |
1378 { | |
1379 } | |
1380 }; | |
1381 | |
1382 | |
1383 void AnnotationsSceneLayer::AddAnnotation(Annotation* annotation) | |
1384 { | |
1385 assert(annotation != NULL); | |
1386 assert(annotations_.find(annotation) == annotations_.end()); | |
1387 annotations_.insert(annotation); | |
1388 } | |
1389 | |
1390 | |
1391 void AnnotationsSceneLayer::DeleteAnnotation(Annotation* annotation) | |
1392 { | |
1393 if (annotation != NULL) | |
1394 { | |
1395 assert(annotations_.find(annotation) != annotations_.end()); | |
1396 annotations_.erase(annotation); | |
1397 delete annotation; | |
1398 } | |
1399 } | |
1400 | |
1401 | |
1402 void AnnotationsSceneLayer::DeletePrimitive(GeometricPrimitive* primitive) | |
1403 { | |
1404 if (primitive != NULL) | |
1405 { | |
1406 assert(primitives_.find(primitive) != primitives_.end()); | |
1407 primitives_.erase(primitive); | |
1408 delete primitive; | |
1409 } | |
1410 } | |
1411 | |
1412 | |
1413 void AnnotationsSceneLayer::TagSubLayerToRemove(size_t subLayerIndex) | |
1414 { | |
1415 assert(subLayersToRemove_.find(subLayerIndex) == subLayersToRemove_.end()); | |
1416 subLayersToRemove_.insert(subLayerIndex); | |
1417 } | |
1418 | |
1419 | |
1420 AnnotationsSceneLayer::AnnotationsSceneLayer(size_t macroLayerIndex) : | |
1421 activeTool_(Tool_Edit), | |
1422 macroLayerIndex_(macroLayerIndex), | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1423 polylineSubLayer_(0), // dummy initialization |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1424 units_(Units_Pixels) |
1804 | 1425 { |
1426 } | |
1427 | |
1428 | |
1429 void AnnotationsSceneLayer::Clear() | |
1430 { | |
1431 for (Annotations::iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
1432 { | |
1433 assert(*it != NULL); | |
1434 delete *it; | |
1435 } | |
1436 | |
1437 annotations_.clear(); | |
1812
db341679dc9f
ViewerViewport::StoneAnnotationsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1809
diff
changeset
|
1438 |
db341679dc9f
ViewerViewport::StoneAnnotationsRegistry
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1809
diff
changeset
|
1439 ClearHover(); |
1804 | 1440 } |
1441 | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1442 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1443 void AnnotationsSceneLayer::SetUnits(Units units) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1444 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1445 if (units_ != units) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1446 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1447 Clear(); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1448 units_ = units; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1449 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1450 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1451 |
1804 | 1452 |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1453 void AnnotationsSceneLayer::AddSegmentAnnotation(const ScenePoint2D& p1, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1454 const ScenePoint2D& p2) |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1455 { |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1456 annotations_.insert(new SegmentAnnotation(*this, units_, true /* show label */, p1, p2)); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1457 } |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1458 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1459 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1460 void AnnotationsSceneLayer::AddCircleAnnotation(const ScenePoint2D& p1, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1461 const ScenePoint2D& p2) |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1462 { |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1463 annotations_.insert(new CircleAnnotation(*this, units_, p1, p2)); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1464 } |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1465 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1466 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1467 void AnnotationsSceneLayer::AddAngleAnnotation(const ScenePoint2D& p1, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1468 const ScenePoint2D& p2, |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1469 const ScenePoint2D& p3) |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1470 { |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1471 annotations_.insert(new AngleAnnotation(*this, units_, p1, p2, p3)); |
1806
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1472 } |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1473 |
0840a25c6d41
removed hard-coded test in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1804
diff
changeset
|
1474 |
1804 | 1475 void AnnotationsSceneLayer::Render(Scene2D& scene) |
1476 { | |
1477 MacroSceneLayer* macro = NULL; | |
1478 | |
1479 if (scene.HasLayer(macroLayerIndex_)) | |
1480 { | |
1481 macro = &dynamic_cast<MacroSceneLayer&>(scene.GetLayer(macroLayerIndex_)); | |
1482 } | |
1483 else | |
1484 { | |
1485 macro = &dynamic_cast<MacroSceneLayer&>(scene.SetLayer(macroLayerIndex_, new MacroSceneLayer)); | |
1486 polylineSubLayer_ = macro->AddLayer(new PolylineSceneLayer); | |
1487 } | |
1488 | |
1489 for (SubLayers::const_iterator it = subLayersToRemove_.begin(); it != subLayersToRemove_.end(); ++it) | |
1490 { | |
1491 assert(macro->HasLayer(*it)); | |
1492 macro->DeleteLayer(*it); | |
1493 } | |
1494 | |
1495 subLayersToRemove_.clear(); | |
1496 | |
1497 std::unique_ptr<PolylineSceneLayer> polyline(new PolylineSceneLayer); | |
1498 | |
1499 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
1500 { | |
1501 assert(*it != NULL); | |
1502 GeometricPrimitive& primitive = **it; | |
1503 | |
1504 primitive.RenderPolylineLayer(*polyline, scene); | |
1505 | |
1506 if (primitive.IsModified()) | |
1507 { | |
1508 primitive.RenderOtherLayers(*macro, scene); | |
1509 primitive.SetModified(false); | |
1510 } | |
1511 } | |
1512 | |
1513 macro->UpdateLayer(polylineSubLayer_, polyline.release()); | |
1514 } | |
1515 | |
1516 | |
1517 bool AnnotationsSceneLayer::ClearHover() | |
1518 { | |
1519 bool needsRefresh = false; | |
1520 | |
1521 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
1522 { | |
1523 assert(*it != NULL); | |
1524 if ((*it)->IsHover()) | |
1525 { | |
1526 (*it)->SetHover(false); | |
1527 needsRefresh = true; | |
1528 } | |
1529 } | |
1530 | |
1531 return needsRefresh; | |
1532 } | |
1533 | |
1534 | |
1535 bool AnnotationsSceneLayer::SetMouseHover(const ScenePoint2D& p, | |
1536 const Scene2D& scene) | |
1537 { | |
1538 if (activeTool_ == Tool_None) | |
1539 { | |
1540 return ClearHover(); | |
1541 } | |
1542 else | |
1543 { | |
1544 bool needsRefresh = false; | |
1545 | |
1546 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); | |
1547 | |
1548 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
1549 { | |
1550 assert(*it != NULL); | |
1551 bool hover = (*it)->IsHit(s, scene); | |
1552 | |
1553 if ((*it)->IsHover() != hover) | |
1554 { | |
1555 needsRefresh = true; | |
1556 } | |
1557 | |
1558 (*it)->SetHover(hover); | |
1559 } | |
1560 | |
1561 return needsRefresh; | |
1562 } | |
1563 } | |
1564 | |
1565 | |
1566 IFlexiblePointerTracker* AnnotationsSceneLayer::CreateTracker(const ScenePoint2D& p, | |
1567 const Scene2D& scene) | |
1568 { | |
1569 if (activeTool_ == Tool_None) | |
1570 { | |
1571 return NULL; | |
1572 } | |
1573 else | |
1574 { | |
1575 const ScenePoint2D s = p.Apply(scene.GetCanvasToSceneTransform()); | |
1576 | |
1577 GeometricPrimitive* bestHit = NULL; | |
1578 | |
1579 for (GeometricPrimitives::iterator it = primitives_.begin(); it != primitives_.end(); ++it) | |
1580 { | |
1581 assert(*it != NULL); | |
1582 if ((*it)->IsHit(s, scene)) | |
1583 { | |
1584 if (bestHit == NULL || | |
1585 bestHit->GetDepth() > (*it)->GetDepth()) | |
1586 { | |
1587 bestHit = *it; | |
1588 } | |
1589 } | |
1590 } | |
1591 | |
1592 if (bestHit != NULL) | |
1593 { | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1594 if (activeTool_ == Tool_Remove) |
1804 | 1595 { |
1596 DeleteAnnotation(&bestHit->GetParentAnnotation()); | |
1597 BroadcastMessage(AnnotationRemovedMessage(*this)); | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1598 return new RemoveTracker; |
1804 | 1599 } |
1600 else | |
1601 { | |
1809
79a5838739a6
starting the integration of AnnotationsSceneLayer into Stone Web viewer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1806
diff
changeset
|
1602 return new EditPrimitiveTracker(*this, *bestHit, s, scene.GetCanvasToSceneTransform()); |
1804 | 1603 } |
1604 } | |
1605 else | |
1606 { | |
1607 switch (activeTool_) | |
1608 { | |
1609 case Tool_Segment: | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1610 return new CreateSegmentOrCircleTracker(*this, units_, false /* segment */, s, scene.GetCanvasToSceneTransform()); |
1804 | 1611 |
1612 case Tool_Circle: | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1613 return new CreateSegmentOrCircleTracker(*this, units_, true /* circle */, s, scene.GetCanvasToSceneTransform()); |
1804 | 1614 |
1615 case Tool_Angle: | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1616 return new CreateAngleTracker(*this, units_, s, scene.GetCanvasToSceneTransform()); |
1804 | 1617 |
1618 default: | |
1619 return NULL; | |
1620 } | |
1621 } | |
1622 } | |
1623 } | |
1624 | |
1625 | |
1626 void AnnotationsSceneLayer::Serialize(Json::Value& target) const | |
1627 { | |
1628 Json::Value annotations = Json::arrayValue; | |
1629 | |
1630 for (Annotations::const_iterator it = annotations_.begin(); it != annotations_.end(); ++it) | |
1631 { | |
1632 assert(*it != NULL); | |
1633 | |
1634 Json::Value item; | |
1635 (*it)->Serialize(item); | |
1636 annotations.append(item); | |
1637 } | |
1638 | |
1639 target = Json::objectValue; | |
1640 target[KEY_ANNOTATIONS] = annotations; | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1641 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1642 switch (units_) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1643 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1644 case Units_Millimeters: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1645 target[KEY_UNITS] = VALUE_MILLIMETERS; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1646 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1647 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1648 case Units_Pixels: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1649 target[KEY_UNITS] = VALUE_PIXELS; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1650 break; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1651 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1652 default: |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1653 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1654 } |
1804 | 1655 } |
1656 | |
1657 | |
1658 void AnnotationsSceneLayer::Unserialize(const Json::Value& serialized) | |
1659 { | |
1660 Clear(); | |
1661 | |
1662 if (serialized.type() != Json::objectValue || | |
1663 !serialized.isMember(KEY_ANNOTATIONS) || | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1664 !serialized.isMember(KEY_UNITS) || |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1665 serialized[KEY_ANNOTATIONS].type() != Json::arrayValue || |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1666 serialized[KEY_UNITS].type() != Json::stringValue) |
1804 | 1667 { |
1668 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Cannot unserialize a set of annotations"); | |
1669 } | |
1670 | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1671 const std::string& u = serialized[KEY_UNITS].asString(); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1672 |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1673 if (u == VALUE_MILLIMETERS) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1674 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1675 units_ = Units_Millimeters; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1676 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1677 else if (u == VALUE_PIXELS) |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1678 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1679 units_ = Units_Pixels; |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1680 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1681 else |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1682 { |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1683 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat, "Unknown units: " + u); |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1684 } |
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1685 |
1804 | 1686 const Json::Value& annotations = serialized[KEY_ANNOTATIONS]; |
1687 | |
1688 for (Json::Value::ArrayIndex i = 0; i < annotations.size(); i++) | |
1689 { | |
1690 if (annotations[i].type() != Json::objectValue || | |
1691 !annotations[i].isMember(KEY_TYPE) || | |
1692 annotations[i][KEY_TYPE].type() != Json::stringValue) | |
1693 { | |
1694 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadFileFormat); | |
1695 } | |
1696 | |
1697 const std::string& type = annotations[i][KEY_TYPE].asString(); | |
1698 | |
1699 if (type == VALUE_ANGLE) | |
1700 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1701 AngleAnnotation::Unserialize(*this, units_, annotations[i]); |
1804 | 1702 } |
1703 else if (type == VALUE_CIRCLE) | |
1704 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1705 CircleAnnotation::Unserialize(*this, units_, annotations[i]); |
1804 | 1706 } |
1707 else if (type == VALUE_SEGMENT) | |
1708 { | |
1821
36430d73e36c
introducing measure units in AnnotationsSceneLayer
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1819
diff
changeset
|
1709 SegmentAnnotation::Unserialize(*this, units_, annotations[i]); |
1804 | 1710 } |
1711 else | |
1712 { | |
1713 LOG(ERROR) << "Cannot unserialize unknown type of annotation: " << type; | |
1714 } | |
1715 } | |
1716 } | |
1717 } |